[PATCH v3] Makefile.flags: fix the OS detection for libresolv

Martin Kaiser lists at kaiser.cx
Fri Jan 22 21:24:05 UTC 2021


From: Martin Kaiser <martin at kaiser.cx>

054493350 ("Do not add -lresolv on non-Linux systems") adds a condition
to link with libresolv only on linux systems.

The check requires that CONFIG_UNAME_OSNAME equals Linux. This works only
if the uname applet is enabled. Otherwise, CONFIG_UNAME_OSNAME is empty,
regardless of the platform.

By default, CONFIG_UNAME_OSNAME is the output of uname -o. For most
linux systems, uname -o returns "GNU/Linux" and the check fails. In this
case, linking a static busybox fails because of missing symbols from
libresolv.

networking/lib.a(nslookup.o): In function `add_query':
nslookup.c:789: undefined reference to `__res_mkquery'
networking/lib.a(nslookup.o): In function `parse_reply':
nslookup.c:355: undefined reference to `ns_initparse'
nslookup.c:361: undefined reference to `ns_parserr'
nslookup.c:404: undefined reference to `ns_name_uncompress'
nslookup.c:418: undefined reference to `ns_get16'
nslookup.c:419: undefined reference to `ns_name_uncompress'
..
nslookup.c:456: undefined reference to `ns_get16'
...
nslookup.c:469: undefined reference to `ns_name_uncompress'
...
nslookup.c:489: undefined reference to `ns_get32'
...
collect2: error: ld returned 1 exit status

This patch uses the output of $CC -dumpmachine to detect the target platform
for which we compile. Both gcc and clang support -dumpmachine. Like the
original patch, we link against libresolv only if our target platform is
linux-based.

Fixes: 054493350 ("Do not add -lresolv on non-Linux systems")
Signed-off-by: Martin Kaiser <martin at kaiser.cx>
---
changes in v3
- use $CC -dumpmachine to detect the target platform in a portable way
- show that the current master is causing problems

changes in v2
- findstring must be inside $(...)
- fix the order ot the two parameters

 Makefile.flags | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.flags b/Makefile.flags
index 5673bc48a..8cf25554c 100644
--- a/Makefile.flags
+++ b/Makefile.flags
@@ -181,7 +181,7 @@ LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%
 endif
 
 ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
-ifeq ($(CONFIG_UNAME_OSNAME),Linux)
+ifneq (,$(findstring linux,$(shell $(CC) -dumpmachine)))
 LDLIBS += resolv
 endif
 endif
-- 
2.20.1



More information about the busybox mailing list