Skip to contentSkip to conversation

kbuild: improve libelf detection

PATCH In review Alistair Delva 2 participants 2 messages Jan 12, 2021 – Jan 13, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: improve libelf detection

When `pkg-config --libs' wasn't used or didn't return anything useful, the test for libelf would fail even if the headers and libraries were available to kbuild via KBUILD_HOSTCFLAGS and KBUILD_HOSTLDFLAGS.

This makes the check in the core Makefile match the check that is done in tools/objtool/Makefile. Specifically, the C compiler is passed the full KBUILD_HOSTCFLAGS and KBUILD_HOSTLDFLAGS, which may have set up additional sysroot/include/library search paths to find libelf.

---
 Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Makefile +3 -2
index 9e73f82e0d86..3269e155fbe4 100644
@@ -1074,8 +1074,9 @@ export mod_sign_cmd
 
 HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
 
-has_libelf = $(call try-run,\
-               echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0)
+has_libelf := $(call try-run,\
+                echo "int main() {}" | \
+                $(HOSTCC) $(KBUILD_HOSTCFLAGS) -xc -o /dev/null $(KBUILD_HOSTLDFLAGS) $(HOST_LIBELF_LIBS) -,1,0)
 
 ifdef CONFIG_STACK_VALIDATION
   ifeq ($(has_libelf),1)
Signature · 1 line
2.29.2
#1 lore raw

Am Dienstag, 12. Januar 2021, 20:00:10 CET schrieb Alistair Delva:

Quoted 8 lines

When `pkg-config --libs' wasn't used or didn't return anything useful, the test for libelf would fail even if the headers and libraries were available to kbuild via KBUILD_HOSTCFLAGS and KBUILD_HOSTLDFLAGS.

This makes the check in the core Makefile match the check that is done in tools/objtool/Makefile. Specifically, the C compiler is passed the full KBUILD_HOSTCFLAGS and KBUILD_HOSTLDFLAGS, which may have set up additional sysroot/include/library search paths to find libelf.

Sounds plausible.

Signature · 7 lines
Rolf Eike Beer, emlix GmbH, http://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11
Gothaer Platz 3, 37083 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055

emlix - smart embedded open source