Skip to contentSkip to conversation

objtool: Fix Makefile to properly see if libelf is supported

PATCH In review Steven Rostedt 3 participants 3 messages Apr 20, 2016 – Apr 22, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 objtool: Fix Makefile to properly see if libelf is supported

When doing a make allmodconfig, I hit the following compile error:

In file included from builtin-check.c:32:0:
elf.h:22:18: fatal error: gelf.h: No such file or directory compilation terminated.
In file included from special.h:22:0,

                 from special.c:26:

elf.h:22:18: fatal error: gelf.h: No such file or directory compilation terminated.
In file included from elf.c:30:0:
elf.h:22:18: fatal error: gelf.h: No such file or directory compilation terminated.
mv: cannot stat 'tools/objtool/.elf.o.tmp': No such file or directory tools/build/Makefile.build:77: recipe for target 'tools/objtool/elf.o' failed make[4]: *** [tools/objtool/elf.o] Error 1
make[4]: *** Waiting for unfinished jobs....

Digging into it, it appears that the $(shell ..) command in the Makefile does not give the proper result when it fails to find -lelf, and continues to compile objtool.

Instead, use the "try-run" makefile macro to perform the test. This gives a proper result for both cases.

Fixes 442f04c34a1a4 ("objtool: Add tool to perform compile-time stack metadata validation")

---

Makefile +2 -1
index 873411873c03..012b7dd3ed24 100644
@@ -1008,7 +1008,8 @@ prepare0: archprepare FORCE
 prepare: prepare0 prepare-objtool
 
 ifdef CONFIG_STACK_VALIDATION
-  has_libelf := $(shell echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf - &> /dev/null && echo 1 || echo 0)
+  has_libelf := $(call try-run,\
+		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
   ifeq ($(has_libelf),1)
     objtool_target := tools/objtool FORCE
   else
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Steven Rostedt

When doing a make allmodconfig, I hit the following compile error:

In file included from builtin-check.c:32:0:
elf.h:22:18: fatal error: gelf.h: No such file or directory compilation terminated.
In file included from special.h:22:0,

                 from special.c:26:

elf.h:22:18: fatal error: gelf.h: No such file or directory compilation terminated.
In file included from elf.c:30:0:
elf.h:22:18: fatal error: gelf.h: No such file or directory compilation terminated.
mv: cannot stat 'tools/objtool/.elf.o.tmp': No such file or directory tools/build/Makefile.build:77: recipe for target 'tools/objtool/elf.o' failed make[4]: *** [tools/objtool/elf.o] Error 1
make[4]: *** Waiting for unfinished jobs....

Digging into it, it appears that the $(shell ..) command in the Makefile does not give the proper result when it fails to find -lelf, and continues to compile objtool.

Quoted 5 lines

Instead, use the "try-run" makefile macro to perform the test. This gives a proper result for both cases.

Fixes 442f04c34a1a4 ("objtool: Add tool to perform compile-time stack metadata validation")

Thanks!

Signature · 1 line
Josh
#2 lore raw
In reply to Steven Rostedt
objtool: Fix Makefile to properly see if libelf is supported
Commit-ID:  c2bb9e32e2315971a8535fee77335c04a739d71d
Gitweb:     http://git.kernel.org/tip/c2bb9e32e2315971a8535fee77335c04a739d71d
Author:     Steven Rostedt <[email protected]>
AuthorDate: Wed, 20 Apr 2016 11:32:35 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 22 Apr 2016 09:00:57 +0200

objtool: Fix Makefile to properly see if libelf is supported

When doing a make allmodconfig, I hit the following compile error:

In file included from builtin-check.c:32:0:
elf.h:22:18: fatal error: gelf.h: No such file or directory compilation terminated.
...

Digging into it, it appears that the $(shell ..) command in the Makefile does not give the proper result when it fails to find -lelf, and continues to compile objtool.

Instead, use the "try-run" makefile macro to perform the test. This gives a proper result for both cases.

Cc Andrew Morton <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Bernd Petrovitsch <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Chris J Arges <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Michal Marek <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Pedro Alves <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 442f04c34a1a4 ("objtool: Add tool to perform compile-time stack metadata validation")
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +2 -1
index 1d0aef0..70ca38e 100644
@@ -1008,7 +1008,8 @@ prepare0: archprepare FORCE
 prepare: prepare0 prepare-objtool
 
 ifdef CONFIG_STACK_VALIDATION
-  has_libelf := $(shell echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf - &> /dev/null && echo 1 || echo 0)
+  has_libelf := $(call try-run,\
+		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
   ifeq ($(has_libelf),1)
     objtool_target := tools/objtool FORCE
   else