Skip to content

Commit 70d268f

Browse files
committed
[fix](be) Gate resolv_shim to glibc >= 2.34 to fix CI -Winfinite-recursion
On glibc < 2.34 (e.g. the AlmaLinux 8 / glibc 2.28 CI build image), <resolv.h> #defines res_nsearch as __res_nsearch, so the forwarder body called itself and clang -Werror -Winfinite-recursion broke the BE UT and COMPILE checks. The shim is only needed on glibc >= 2.34 anyway (older glibc still exports __res_nsearch as a default-versioned symbol), so gate it with __GLIBC_PREREQ(2, 34) and keep the translation unit non-empty for -Wpedantic.
1 parent 62880e9 commit 70d268f

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

be/src/glibc-compatibility/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ if (GLIBC_COMPATIBILITY)
5757
# libcalls. Workaround: Use object file so that linker will always take a
5858
# look at its symbol table.
5959
list(REMOVE_ITEM glibc_compatibility_sources musl/getrandom.c)
60-
# NOTE: the OBJECT lib must always provide the resolv_shim symbol; keep it out of the archive.
60+
# NOTE: the OBJECT lib must always provide the resolv_shim symbol where it
61+
# exists (resolv_shim.c is a no-op on glibc < 2.34); keep it out of the archive.
6162
list(REMOVE_ITEM glibc_compatibility_sources resolv_shim.c)
6263
# NOTE(amos): sanitizers might generate memcpy references that are too late to
6364
# refer. Let's also extract memcpy definitions explicitly to avoid UNDEF GLIBC 2.14.

be/src/glibc-compatibility/resolv_shim.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,27 @@
2222
// on Ubuntu 22.04 (glibc 2.35). Provide a thin forwarder to the public
2323
// res_nsearch entry point, which is the identical implementation (same
2424
// symbol address in libc).
25+
//
26+
// The shim must only exist where it is needed: on glibc < 2.34,
27+
// __res_nsearch is still a default-versioned libc symbol, and <resolv.h>
28+
// there #defines res_nsearch as __res_nsearch, which would fold the
29+
// forwarder below into infinite self-recursion (clang -Winfinite-recursion
30+
// errors out under -Werror, e.g. on the AlmaLinux 8 / glibc 2.28 CI image).
2531

2632
#include <resolv.h>
2733
#include <sys/types.h>
2834

35+
#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 34)
36+
2937
int __res_nsearch(res_state statp, const char* dname, int class_, int type,
3038
unsigned char* answer, int anslen) {
3139
return res_nsearch(statp, dname, class_, type, answer, anslen);
3240
}
41+
42+
#else
43+
44+
// Keep the translation unit non-empty (-Wpedantic forbids an empty one);
45+
// no shim is required on glibc < 2.34.
46+
typedef int doris_resolv_shim_unused_t;
47+
48+
#endif

0 commit comments

Comments
 (0)