Skip to content

Commit cd955bd

Browse files
captain5050jpoimboe
authored andcommitted
objtool: Fix HOSTCC flag usage
HOSTCC is always wanted when building objtool. Setting CC to HOSTCC happens after tools/scripts/Makefile.include is included, meaning flags (like CFLAGS) are set assuming say CC is gcc, but then it can be later set to HOSTCC which may be clang. tools/scripts/Makefile.include is needed for host set up and common macros in objtool's Makefile. Rather than override the CC variable to HOSTCC, just pass CC as HOSTCC to the sub-makes of Makefile.build, the libsubcmd builds and also to the linkage step. Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20230126190606.40739-4-irogers@google.com Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
1 parent 8c4526c commit cd955bd

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

tools/objtool/Makefile

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
include ../scripts/Makefile.include
33
include ../scripts/Makefile.arch
44

5-
# always use the host compiler
6-
AR = $(HOSTAR)
7-
CC = $(HOSTCC)
8-
LD = $(HOSTLD)
9-
105
ifeq ($(srctree),)
116
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
127
srctree := $(patsubst %/,%,$(dir $(srctree)))
@@ -34,13 +29,18 @@ INCLUDES := -I$(srctree)/tools/include \
3429
-I$(srctree)/tools/objtool/include \
3530
-I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
3631
-I$(LIBSUBCMD_OUTPUT)/include
32+
# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
33+
# is passed here to match a legacy behavior.
3734
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
38-
CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
39-
LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
35+
OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
36+
OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
4037

4138
# Allow old libelf to be used:
42-
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
43-
CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
39+
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
40+
OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
41+
42+
# Always want host compilation.
43+
HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
4444

4545
AWK = awk
4646
MKDIR = mkdir
@@ -61,12 +61,14 @@ export BUILD_ORC
6161
export srctree OUTPUT CFLAGS SRCARCH AWK
6262
include $(srctree)/tools/build/Makefile.include
6363

64-
$(OBJTOOL_IN): fixdep FORCE
64+
$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
6565
$(Q)$(CONFIG_SHELL) ./sync-check.sh
66-
$(Q)$(MAKE) $(build)=objtool
66+
$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
67+
LDFLAGS="$(OBJTOOL_LDFLAGS)"
68+
6769

6870
$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
69-
$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
71+
$(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
7072

7173

7274
$(LIBSUBCMD_OUTPUT):
@@ -75,6 +77,7 @@ $(LIBSUBCMD_OUTPUT):
7577
$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
7678
$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
7779
DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
80+
$(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
7881
$@ install_headers
7982

8083
$(LIBSUBCMD)-clean:

0 commit comments

Comments
 (0)