Skip to contentSkip to conversation

objtool: make use of pkg-config for libelf

PATCH In review Philipp Puschmann 3 participants 3 messages Mar 1, 2018 – Mar 5, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 objtool: make use of pkg-config for libelf

For libelf with non-standard paths make use of pkg-config.

---
 Makefile               | 4 +++-
 tools/objtool/Makefile | 8 ++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
Makefile +3 -1
index 659a7780aeb3..31b296b0e941 100644
@@ -953,8 +953,10 @@ endif
 export mod_sign_cmd
 
 ifdef CONFIG_STACK_VALIDATION
+  LIBELF_LIBS = $(shell pkg-config --libs libelf 2> /dev/null || \
+                        echo -lelf)
   has_libelf := $(call try-run,\
-		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
+		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(LIBELF_LIBS) -,1,0)
   ifeq ($(has_libelf),1)
     objtool_target := tools/objtool FORCE
   else
tools/objtool/Makefile +6 -2
index e6acc281dd37..c565eff8c393 100644
@@ -27,12 +27,16 @@ OBJTOOL_IN := $(OBJTOOL)-in.o
 
 all: $(OBJTOOL)
 
+LIBELF_LIBS     = $(shell pkg-config --libs libelf 2> /dev/null || \
+                        echo -lelf)
+LIBELF_INCLUDES = $(shell pkg-config --cflags libelf 2> /dev/null)
 INCLUDES := -I$(srctree)/tools/include \
 	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
-	    -I$(srctree)/tools/objtool/arch/$(ARCH)/include
+	    -I$(srctree)/tools/objtool/arch/$(ARCH)/include \
+	    $(LIBELF_INCLUDES)
 WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
 CFLAGS   += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
-LDFLAGS  += -lelf $(LIBSUBCMD)
+LDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD)
 
 # Allow old libelf to be used:
 elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
Signature · 1 line
2.16.1
#1 lore raw

[ Adding Robin ]

Robin, does this fix the same issue as your recent patches? If so, I'd prefer this one because it doesn't need any new environment variables.

Quoted 50 lines · Philipp Puschmann

For libelf with non-standard paths make use of pkg-config.

---
 Makefile               | 4 +++-
 tools/objtool/Makefile | 8 ++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
Makefile +3 -1
index 659a7780aeb3..31b296b0e941 100644
@@ -953,8 +953,10 @@ endif
 export mod_sign_cmd
 
 ifdef CONFIG_STACK_VALIDATION
+  LIBELF_LIBS = $(shell pkg-config --libs libelf 2> /dev/null || \
+                        echo -lelf)
   has_libelf := $(call try-run,\
-		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
+		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(LIBELF_LIBS) -,1,0)
   ifeq ($(has_libelf),1)
     objtool_target := tools/objtool FORCE
   else
tools/objtool/Makefile +6 -2
index e6acc281dd37..c565eff8c393 100644
@@ -27,12 +27,16 @@ OBJTOOL_IN := $(OBJTOOL)-in.o
 
 all: $(OBJTOOL)
 
+LIBELF_LIBS     = $(shell pkg-config --libs libelf 2> /dev/null || \
+                        echo -lelf)
+LIBELF_INCLUDES = $(shell pkg-config --cflags libelf 2> /dev/null)
 INCLUDES := -I$(srctree)/tools/include \
 	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
-	    -I$(srctree)/tools/objtool/arch/$(ARCH)/include
+	    -I$(srctree)/tools/objtool/arch/$(ARCH)/include \
+	    $(LIBELF_INCLUDES)
 WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
 CFLAGS   += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
-LDFLAGS  += -lelf $(LIBSUBCMD)
+LDFLAGS  += $(LIBELF_LIBS) $(LIBSUBCMD)
 
 # Allow old libelf to be used:
 elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
Signature · 1 line
2.16.1
Signature · 1 line
Josh
#2 lore raw

2018-03-05, Josh Poimboeuf:

Quoted 4 lines

[ Adding Robin ]

Robin, does this fix the same issue as your recent patches? If so, I'd prefer this one because it doesn't need any new environment variables.

Hi Josh,

this looks like it would work. I need to do proper testing before confirmation. Also, I did not have time to work on a v3. I'll wait a bit to see where this goes first.

Signature · 1 line
Robin