Skip to content

Commit 056d28d

Browse files
DerDakonKAGA-KOKO
authored andcommitted
objtool: Query pkg-config for libelf location
If it is not in the default location, compilation fails at several points. Signed-off-by: Rolf Eike Beer <eb@emlix.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/91a25e992566a7968fedc89ec80e7f4c83ad0548.1553622500.git.jpoimboe@redhat.com
1 parent cfa637c commit 056d28d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,11 @@ mod_sign_cmd = true
950950
endif
951951
export mod_sign_cmd
952952

953+
HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
954+
953955
ifdef CONFIG_STACK_VALIDATION
954956
has_libelf := $(call try-run,\
955-
echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
957+
echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0)
956958
ifeq ($(has_libelf),1)
957959
objtool_target := tools/objtool FORCE
958960
else

tools/objtool/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ LIBSUBCMD = $(LIBSUBCMD_OUTPUT)libsubcmd.a
2525
OBJTOOL := $(OUTPUT)objtool
2626
OBJTOOL_IN := $(OBJTOOL)-in.o
2727

28+
LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null)
29+
LIBELF_LIBS := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
30+
2831
all: $(OBJTOOL)
2932

3033
INCLUDES := -I$(srctree)/tools/include \
3134
-I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
3235
-I$(srctree)/tools/objtool/arch/$(ARCH)/include
3336
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
34-
CFLAGS += -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES)
35-
LDFLAGS += -lelf $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
37+
CFLAGS += -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
38+
LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
3639

3740
# Allow old libelf to be used:
3841
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)

0 commit comments

Comments
 (0)