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>
---
tools/objtool/Makefile | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index f0651eac06e6..bbf8ec440430 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -2,11 +2,6 @@
include ../scripts/Makefile.include
include ../scripts/Makefile.arch
-# always use the host compiler
-AR = $(HOSTAR)
-CC = $(HOSTCC)
-LD = $(HOSTLD)
-
ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
@@ -34,13 +29,18 @@ INCLUDES := -I$(srctree)/tools/include \
-I$(srctree)/tools/objtool/include \
-I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
-I$(LIBSUBCMD_OUTPUT)/include
+# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
+# is passed here to match a legacy behavior.
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
-CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
-LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
+OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
+OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
# Allow old libelf to be used:
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
-CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
+OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
+
+# Always want host compilation.
+HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
AWK = awk
MKDIR = mkdir
@@ -63,10 +63,12 @@ include $(srctree)/tools/build/Makefile.include
$(OBJTOOL_IN): fixdep FORCE
$(Q)$(CONFIG_SHELL) ./sync-check.sh
- $(Q)$(MAKE) $(build)=objtool
+ $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
+ LDFLAGS="$(OBJTOOL_LDFLAGS)"
+
$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
- $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
+ $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
$(LIBSUBCMD_OUTPUT):
@@ -75,6 +77,7 @@ $(LIBSUBCMD_OUTPUT):
$(LIBSUBCMD): fixdep FORCE $(LIBSUBCMD_OUTPUT)
$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
+ $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
$@ install_headers
$(LIBSUBCMD)-clean:
--
2.39.1.456.gfc5497dd1b-goog
Could this patch be backported to LTS branches? Entire build fails if KBUILD_HOSTCFLAGS has flags that would make the libsubcmd incompatible with the built objtool, since those flags were not passed to libsubcmd before this patch. One example is that the AOSP GKI builds fail since they set a custom sysroot using that variable. For the Google devs, issue b/335829879 is relevant.
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 93eacc15687a491a9cf829f94b6891bf544084f3
Gitweb: https://git.kernel.org/tip/93eacc15687a491a9cf829f94b6891bf544084f3
Author: Ian Rogers <irogers@google.com>
AuthorDate: Thu, 26 Jan 2023 11:06:06 -08:00
Committer: Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Mon, 30 Jan 2023 16:28:18 -08:00
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>
---
tools/objtool/Makefile | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index d54b669..29a8cd7 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -2,11 +2,6 @@
include ../scripts/Makefile.include
include ../scripts/Makefile.arch
-# always use the host compiler
-AR = $(HOSTAR)
-CC = $(HOSTCC)
-LD = $(HOSTLD)
-
ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
@@ -34,13 +29,18 @@ INCLUDES := -I$(srctree)/tools/include \
-I$(srctree)/tools/objtool/include \
-I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
-I$(LIBSUBCMD_OUTPUT)/include
+# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
+# is passed here to match a legacy behavior.
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
-CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
-LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
+OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
+OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
# Allow old libelf to be used:
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
-CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
+OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
+
+# Always want host compilation.
+HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
AWK = awk
MKDIR = mkdir
@@ -61,12 +61,14 @@ export BUILD_ORC
export srctree OUTPUT CFLAGS SRCARCH AWK
include $(srctree)/tools/build/Makefile.include
-$(OBJTOOL_IN): fixdep FORCE
+$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
$(Q)$(CONFIG_SHELL) ./sync-check.sh
- $(Q)$(MAKE) $(build)=objtool
+ $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
+ LDFLAGS="$(OBJTOOL_LDFLAGS)"
+
$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
- $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
+ $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
$(LIBSUBCMD_OUTPUT):
@@ -75,6 +77,7 @@ $(LIBSUBCMD_OUTPUT):
$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
+ $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
$@ install_headers
$(LIBSUBCMD)-clean:
Hi, I just spotted this breaks cross-compiling; details below. On Wed, Feb 01, 2023 at 04:26:34PM -0000, tip-bot2 for Ian Rogers wrote: > The following commit has been merged into the objtool/core branch of tip: > > Commit-ID: 93eacc15687a491a9cf829f94b6891bf544084f3 > Gitweb: https://git.kernel.org/tip/93eacc15687a491a9cf829f94b6891bf544084f3 > Author: Ian Rogers <irogers@google.com> > AuthorDate: Thu, 26 Jan 2023 11:06:06 -08:00 > Committer: Josh Poimboeuf <jpoimboe@kernel.org> > CommitterDate: Mon, 30 Jan 2023 16:28:18 -08:00 > > 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> > --- > tools/objtool/Makefile | 25 ++++++++++++++----------- > 1 file changed, 14 insertions(+), 11 deletions(-) > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > index d54b669..29a8cd7 100644 > --- a/tools/objtool/Makefile > +++ b/tools/objtool/Makefile > @@ -2,11 +2,6 @@ > include ../scripts/Makefile.include > include ../scripts/Makefile.arch > > -# always use the host compiler > -AR = $(HOSTAR) > -CC = $(HOSTCC) > -LD = $(HOSTLD) So as of this change, CC is now the cross-compiler CC .... > - > ifeq ($(srctree),) > srctree := $(patsubst %/,%,$(dir $(CURDIR))) > srctree := $(patsubst %/,%,$(dir $(srctree))) > @@ -34,13 +29,18 @@ INCLUDES := -I$(srctree)/tools/include \ > -I$(srctree)/tools/objtool/include \ > -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ > -I$(LIBSUBCMD_OUTPUT)/include > +# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it > +# is passed here to match a legacy behavior. > WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs > -CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) > -LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > +OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) > +OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > > # Allow old libelf to be used: > elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr) ... and so as of this patch, this check uses the cross-compiler CC rather than the HOSTCC (and IIUC the wrong CFLAGS too). So that probably wants to be `$(HOSTCC) $(OBJTOOL_CFLAGS)` ? The cross CC might not even have libelf in its header path ... > -CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) > +OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) ... which means that we might end up setting DLIBELF_USE_DEPRECATED when we didn't mean to. I saw this blowing up in some experiments with an arm64 objtool built on x86_64, and I believe the reverse can also occur (i.e. building for x86_64 on arm64). As of this patch, I get a splat: | [mark@lakrids:~/src/linux]% usekorg 12.1.0 make ARCH=arm64 CROSS_COMPILE=aarch64-linux- tools/objtool/elf.o | CALL scripts/checksyscalls.sh | DESCEND objtool | <stdin>:1:10: fatal error: libelf.h: No such file or directory | compilation terminated. | INSTALL libsubcmd_headers | CC /home/mark/src/linux/tools/objtool/elf.o | elf.c: In function ‘read_sections’: | elf.c:273:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations] | 273 | if (elf_getshdrnum(elf->elf, §ions_nr)) { | | ^~ | In file included from /usr/include/gelf.h:32, | from /home/mark/src/linux/tools/objtool/include/objtool/elf.h:10, | from elf.c:22: | /usr/include/libelf.h:310:12: note: declared here | 310 | extern int elf_getshnum (Elf *__elf, size_t *__dst) | | ^~~~~~~~~~~~ | elf.c:278:2: error: ‘elf_getshstrndx’ is deprecated [-Werror=deprecated-declarations] | 278 | if (elf_getshdrstrndx(elf->elf, &shstrndx)) { | | ^~ | In file included from /usr/include/gelf.h:32, | from /home/mark/src/linux/tools/objtool/include/objtool/elf.h:10, | from elf.c:22: | /usr/include/libelf.h:322:12: note: declared here | 322 | extern int elf_getshstrndx (Elf *__elf, size_t *__dst) | | ^~~~~~~~~~~~~~~ | cc1: all warnings being treated as errors | make[3]: *** [/home/mark/src/linux/tools/build/Makefile.build:97: /home/mark/src/linux/tools/objtool/elf.o] Error 1 | make[2]: *** [Makefile:66: /home/mark/src/linux/tools/objtool/objtool-in.o] Error 2 | make[1]: *** [Makefile:73: objtool] Error 2 | make: *** [Makefile:1439: tools/objtool] Error 2 Thanks, Mark. > + > +# Always want host compilation. > +HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" > > AWK = awk > MKDIR = mkdir > @@ -61,12 +61,14 @@ export BUILD_ORC > export srctree OUTPUT CFLAGS SRCARCH AWK > include $(srctree)/tools/build/Makefile.include > > -$(OBJTOOL_IN): fixdep FORCE > +$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE > $(Q)$(CONFIG_SHELL) ./sync-check.sh > - $(Q)$(MAKE) $(build)=objtool > + $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \ > + LDFLAGS="$(OBJTOOL_LDFLAGS)" > + > > $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) > - $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ > + $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@ > > > $(LIBSUBCMD_OUTPUT): > @@ -75,6 +77,7 @@ $(LIBSUBCMD_OUTPUT): > $(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE > $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \ > DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \ > + $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ > $@ install_headers > > $(LIBSUBCMD)-clean:
On Wed, Feb 01, 2023 at 05:02:16PM +0000, Mark Rutland wrote: > Hi, > > I just spotted this breaks cross-compiling; details below. Thanks, we'll fix it up with diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 29a8cd7449bf..83b100c1e7f6 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -36,7 +36,7 @@ OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBE OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) # Allow old libelf to be used: -elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr) +elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr) OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) # Always want host compilation.
On Wed, Feb 01, 2023 at 09:36:37AM -0800, Josh Poimboeuf wrote: > On Wed, Feb 01, 2023 at 05:02:16PM +0000, Mark Rutland wrote: > > Hi, > > > > I just spotted this breaks cross-compiling; details below. > > Thanks, we'll fix it up with > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > index 29a8cd7449bf..83b100c1e7f6 100644 > --- a/tools/objtool/Makefile > +++ b/tools/objtool/Makefile > @@ -36,7 +36,7 @@ OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBE > OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > > # Allow old libelf to be used: > -elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr) > +elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr) > OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) > > # Always want host compilation. Profiting off of the occasion to point out that cross-compiling with CONFIG_DEBUG_INFO_BTF=y is also broken (it builds the resolve_btfids tool): I source this script when cross-compiling, which has worked up until now: #!/bin/bash export TOPDIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd) export PATH="${TOPDIR}/bin:$PATH" export ARCH="arm64" export CROSS_COMPILE="aarch64-none-linux-gnu-" export SYSROOT="${TOPDIR}/sysroot" export CC="aarch64-none-linux-gnu-gcc" export CXX="aarch64-none-linux-gnu-g++" export LDFLAGS="-L${SYSROOT}/usr/lib -L${SYSROOT}/usr/local/lib" export CFLAGS="-I${SYSROOT}/usr/include -I${SYSROOT}/usr/local/include" export CFLAGS="${CFLAGS} -Wno-format-nonliteral" export KBUILD_OUTPUT="output-arm64" Before reverting this patch, the build fails like this: $ make -j 8 Image.gz dtbs modules W=1 C=1 make[1]: Entering directory '/opt/net-next/output-arm64' SYNC include/config/auto.conf.cmd GEN Makefile GEN Makefile DESCEND bpf/resolve_btfids CC scripts/mod/empty.o CC scripts/mod/devicetable-offsets.s CHECK ../scripts/mod/empty.c INSTALL libsubcmd_headers MKELF scripts/mod/elfconfig.h HOSTCC scripts/mod/modpost.o HOSTCC scripts/mod/file2alias.o HOSTCC scripts/mod/sumversion.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/main.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/rbtree.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/string.o In file included from /opt/net-next/tools/include/linux/rbtree_augmented.h:19, from ../../lib/rbtree.c:12: /opt/net-next/tools/include/linux/rbtree.h: In function ‘rb_link_node’: /opt/net-next/tools/include/linux/rbtree.h:70:42: error: ‘NULL’ undeclared (first use in this function) 70 | node->rb_left = node->rb_right = NULL; | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:21:1: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? 20 | #include <linux/kernel.h> +++ |+#include <stddef.h> 21 | #include <linux/stddef.h> /opt/net-next/tools/include/linux/rbtree.h:70:42: note: each undeclared identifier is reported only once for each function it appears in 70 | node->rb_left = node->rb_right = NULL; | ^~~~ /opt/net-next/tools/include/linux/rbtree.h: At top level: /opt/net-next/tools/include/linux/rbtree.h:131:43: error: unknown type name ‘bool’ 131 | bool leftmost) | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:21:1: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? 20 | #include <linux/kernel.h> +++ |+#include <stdbool.h> 21 | #include <linux/stddef.h> /opt/net-next/tools/include/linux/rbtree.h:179:15: error: unknown type name ‘bool’ 179 | bool (*less)(struct rb_node *, const struct rb_node *)) | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:179:15: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? /opt/net-next/tools/include/linux/rbtree.h:207:8: error: unknown type name ‘bool’ 207 | bool (*less)(struct rb_node *, const struct rb_node *)) | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:207:8: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? /opt/net-next/tools/include/linux/rbtree.h: In function ‘rb_find_add’: /opt/net-next/tools/include/linux/rbtree.h:238:34: error: ‘NULL’ undeclared (first use in this function) 238 | struct rb_node *parent = NULL; | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:238:34: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? /opt/net-next/tools/include/linux/rbtree.h: In function ‘rb_find’: /opt/net-next/tools/include/linux/rbtree.h:283:16: error: ‘NULL’ undeclared (first use in this function) 283 | return NULL; | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:283:16: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? /opt/net-next/tools/include/linux/rbtree.h: In function ‘rb_find_first’: /opt/net-next/tools/include/linux/rbtree.h:299:33: error: ‘NULL’ undeclared (first use in this function) 299 | struct rb_node *match = NULL; | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:299:33: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? /opt/net-next/tools/include/linux/rbtree.h: In function ‘rb_next_match’: /opt/net-next/tools/include/linux/rbtree.h:330:24: error: ‘NULL’ undeclared (first use in this function) 330 | node = NULL; | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:330:24: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? In file included from ../../lib/rbtree.c:12: /opt/net-next/tools/include/linux/rbtree_augmented.h: At top level: /opt/net-next/tools/include/linux/rbtree_augmented.h:57:57: error: unknown type name ‘bool’ 57 | struct rb_root_cached *root, bool newleft, | ^~~~ /opt/net-next/tools/include/linux/rbtree_augmented.h:20:1: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? 19 | #include <linux/rbtree.h> +++ |+#include <stdbool.h> 20 | /opt/net-next/tools/include/linux/rbtree_augmented.h: In function ‘__rb_erase_augmented’: /opt/net-next/tools/include/linux/rbtree_augmented.h:208:37: error: ‘NULL’ undeclared (first use in this function) 208 | rebalance = NULL; | ^~~~ /opt/net-next/tools/include/linux/rbtree_augmented.h:20:1: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? 19 | #include <linux/rbtree.h> +++ |+#include <stddef.h> 20 | ../../lib/rbtree.c: In function ‘__rb_insert’: ../../lib/rbtree.c:90:16: error: ‘true’ undeclared (first use in this function) 90 | while (true) { | ^~~~ ../../lib/rbtree.c:14:1: note: ‘true’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? 13 | #include <linux/export.h> +++ |+#include <stdbool.h> 14 | ../../lib/rbtree.c:100:51: error: ‘NULL’ undeclared (first use in this function) 100 | rb_set_parent_color(node, NULL, RB_BLACK); | ^~~~ ../../lib/rbtree.c:14:1: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? 13 | #include <linux/export.h> +++ |+#include <stddef.h> 14 | ../../lib/rbtree.c: In function ‘____rb_erase_color’: ../../lib/rbtree.c:230:32: error: ‘NULL’ undeclared (first use in this function) 230 | struct rb_node *node = NULL, *sibling, *tmp1, *tmp2; | ^~~~ ../../lib/rbtree.c:230:32: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? ../../lib/rbtree.c:232:16: error: ‘true’ undeclared (first use in this function) 232 | while (true) { | ^~~~ ../../lib/rbtree.c:232:16: note: ‘true’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? ../../lib/rbtree.c: In function ‘rb_first’: ../../lib/rbtree.c:468:24: error: ‘NULL’ undeclared (first use in this function) 468 | return NULL; | ^~~~ ../../lib/rbtree.c:468:24: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? ../../lib/rbtree.c: In function ‘rb_last’: ../../lib/rbtree.c:480:24: error: ‘NULL’ undeclared (first use in this function) 480 | return NULL; | ^~~~ ../../lib/rbtree.c:480:24: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? ../../lib/rbtree.c: In function ‘rb_next’: ../../lib/rbtree.c:491:24: error: ‘NULL’ undeclared (first use in this function) 491 | return NULL; | ^~~~ ../../lib/rbtree.c:491:24: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? ../../lib/rbtree.c: In function ‘rb_prev’: ../../lib/rbtree.c:522:24: error: ‘NULL’ undeclared (first use in this function) 522 | return NULL; | ^~~~ ../../lib/rbtree.c:522:24: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? ../../lib/rbtree.c: In function ‘rb_next_postorder’: ../../lib/rbtree.c:577:24: error: ‘NULL’ undeclared (first use in this function) 577 | return NULL; | ^~~~ ../../lib/rbtree.c:577:24: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? ../../lib/rbtree.c: In function ‘rb_first_postorder’: ../../lib/rbtree.c:594:24: error: ‘NULL’ undeclared (first use in this function) 594 | return NULL; | ^~~~ ../../lib/rbtree.c:594:24: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’? ../../lib/string.c:48:30: error: unknown type name ‘bool’ 48 | int strtobool(const char *s, bool *res) | ^~~~ ../../lib/string.c:21:1: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? 20 | #include <linux/ctype.h> +++ |+#include <stdbool.h> 21 | #include <linux/compiler.h> ../../lib/string.c:172:33: error: unknown type name ‘u8’ 172 | static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) | ^~ ../../lib/string.c:172:44: error: unknown type name ‘u8’ 172 | static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) | ^~ ../../lib/string.c: In function ‘memchr_inv’: ../../lib/string.c:194:9: error: unknown type name ‘u8’ 194 | u8 value = c; | ^~ ../../lib/string.c:195:9: error: unknown type name ‘u64’ 195 | u64 value64; | ^~~ ../../lib/string.c:199:24: warning: implicit declaration of function ‘check_bytes8’ [-Wimplicit-function-declaration] 199 | return check_bytes8(start, value, bytes); | ^~~~~~~~~~~~ ../../lib/string.c:199:24: warning: returning ‘int’ from a function with return type ‘void *’ makes pointer from integer without a cast [-Wint-conversion] 199 | return check_bytes8(start, value, bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../lib/string.c:204:28: warning: left shift count >= width of type [-Wshift-count-overflow] 204 | value64 |= value64 << 32; | ^~ ../../lib/string.c:208:17: error: unknown type name ‘u8’ 208 | u8 *r; | ^~ ../../lib/string.c:211:19: warning: assignment to ‘int *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 211 | r = check_bytes8(start, value, prefix); | ^ ../../lib/string.c:221:23: error: ‘u64’ undeclared (first use in this function) 221 | if (*(u64 *)start != value64) | ^~~ ../../lib/string.c:221:23: note: each undeclared identifier is reported only once for each function it appears in ../../lib/string.c:221:28: error: expected expression before ‘)’ token 221 | if (*(u64 *)start != value64) | ^ ../../lib/string.c:222:32: warning: returning ‘int’ from a function with return type ‘void *’ makes pointer from integer without a cast [-Wint-conversion] 222 | return check_bytes8(start, value, 8); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../lib/string.c:227:16: warning: returning ‘int’ from a function with return type ‘void *’ makes pointer from integer without a cast [-Wint-conversion] 227 | return check_bytes8(start, value, bytes % 8); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[4]: *** [Build:9: /opt/net-next/output-arm64/tools/bpf/resolve_btfids/rbtree.o] Error 1 make[4]: *** Waiting for unfinished jobs.... make[4]: *** [Build:9: /opt/net-next/output-arm64/tools/bpf/resolve_btfids/string.o] Error 1 In file included from main.c:73: /opt/net-next/tools/include/linux/rbtree.h:131:43: error: unknown type name ‘bool’ 131 | bool leftmost) | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:21:1: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? 20 | #include <linux/kernel.h> +++ |+#include <stdbool.h> 21 | #include <linux/stddef.h> /opt/net-next/tools/include/linux/rbtree.h:179:15: error: unknown type name ‘bool’ 179 | bool (*less)(struct rb_node *, const struct rb_node *)) | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:179:15: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? /opt/net-next/tools/include/linux/rbtree.h:207:8: error: unknown type name ‘bool’ 207 | bool (*less)(struct rb_node *, const struct rb_node *)) | ^~~~ /opt/net-next/tools/include/linux/rbtree.h:207:8: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’? In file included from main.c:75: /opt/net-next/tools/include/linux/err.h:35:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ERR_PTR’ 35 | static inline void * __must_check ERR_PTR(long error_) | ^~~~~~~ /opt/net-next/tools/include/linux/err.h:40:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_ERR’ 40 | static inline long __must_check PTR_ERR(__force const void *ptr) | ^~~~~~~ /opt/net-next/tools/include/linux/err.h:45:15: error: unknown type name ‘bool’ 45 | static inline bool __must_check IS_ERR(__force const void *ptr) | ^~~~ /opt/net-next/tools/include/linux/err.h:45:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘IS_ERR’ 45 | static inline bool __must_check IS_ERR(__force const void *ptr) | ^~~~~~ /opt/net-next/tools/include/linux/err.h:50:15: error: unknown type name ‘bool’ 50 | static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr) | ^~~~ /opt/net-next/tools/include/linux/err.h:50:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘IS_ERR_OR_NULL’ 50 | static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr) | ^~~~~~~~~~~~~~ /opt/net-next/tools/include/linux/err.h:55:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_ERR_OR_ZERO’ 55 | static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr) | ^~~~~~~~~~~~~~~ /opt/net-next/tools/include/linux/err.h:70:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ERR_CAST’ 70 | static inline void * __must_check ERR_CAST(__force const void *ptr) | ^~~~~~~~ In file included from main.c:76: /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/btf.h:208:35: warning: ‘enum btf_func_linkage’ declared inside parameter list will not be visible outside of this definition or declaration 208 | enum btf_func_linkage linkage, int proto_type_id); | ^~~~~~~~~~~~~~~~ /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/btf.h: In function ‘btf_kflag’: /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/btf.h:332:16: warning: implicit declaration of function ‘BTF_INFO_KFLAG’; did you mean ‘BTF_INFO_KIND’? [-Wimplicit-function -declaration] 332 | return BTF_INFO_KFLAG(t->info); | ^~~~~~~~~~~~~~ | BTF_INFO_KIND /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/btf.h: In function ‘btf_member_bit_offset’: /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/btf.h:534:24: warning: implicit declaration of function ‘BTF_MEMBER_BIT_OFFSET’ [-Wimplicit-function-declaration] 534 | return kflag ? BTF_MEMBER_BIT_OFFSET(m->offset) : m->offset; | ^~~~~~~~~~~~~~~~~~~~~ /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/btf.h: In function ‘btf_member_bitfield_size’: /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/btf.h:546:24: warning: implicit declaration of function ‘BTF_MEMBER_BITFIELD_SIZE’ [-Wimplicit-function-declaration] 546 | return kflag ? BTF_MEMBER_BITFIELD_SIZE(m->offset) : 0; | ^~~~~~~~~~~~~~~~~~~~~~~~ In file included from main.c:77: /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/libbpf.h: At top level: /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/sysroot/usr/include/bpf/libbpf.h:70:54: warning: ‘enum bpf_link_type’ declared inside parameter list will not be visible outside of this definition or declaration 70 | LIBBPF_API const char *libbpf_bpf_link_type_str(enum bpf_link_type t); | ^~~~~~~~~~~~~ In file included from main.c:73: main.c: In function ‘btf_id__find’: /opt/net-next/tools/include/linux/rbtree.h:37:37: warning: implicit declaration of function ‘container_of’ [-Wimplicit-function-declaration] 37 | #define rb_entry(ptr, type, member) container_of(ptr, type, member) | ^~~~~~~~~~~~ main.c:174:22: note: in expansion of macro ‘rb_entry’ 174 | id = rb_entry(p, struct btf_id, rb_node); | ^~~~~~~~ main.c:174:34: error: expected expression before ‘struct’ 174 | id = rb_entry(p, struct btf_id, rb_node); | ^~~~~~ /opt/net-next/tools/include/linux/rbtree.h:37:55: note: in definition of macro ‘rb_entry’ 37 | #define rb_entry(ptr, type, member) container_of(ptr, type, member) | ^~~~ main.c: In function ‘btf_id__add’: main.c:196:39: error: expected expression before ‘struct’ 196 | id = rb_entry(parent, struct btf_id, rb_node); | ^~~~~~ /opt/net-next/tools/include/linux/rbtree.h:37:55: note: in definition of macro ‘rb_entry’ 37 | #define rb_entry(ptr, type, member) container_of(ptr, type, member) | ^~~~ main.c: In function ‘__symbols_patch’: main.c:632:37: error: expected expression before ‘struct’ 632 | id = rb_entry(next, struct btf_id, rb_node); | ^~~~~~ /opt/net-next/tools/include/linux/rbtree.h:37:55: note: in definition of macro ‘rb_entry’ 37 | #define rb_entry(ptr, type, member) container_of(ptr, type, member) | ^~~~ main.c: In function ‘sets_patch’: main.c:662:39: error: expected expression before ‘struct’ 662 | id = rb_entry(next, struct btf_id, rb_node); | ^~~~~~ /opt/net-next/tools/include/linux/rbtree.h:37:55: note: in definition of macro ‘rb_entry’ 37 | #define rb_entry(ptr, type, member) container_of(ptr, type, member) | ^~~~ In file included from main.c:78: main.c: In function ‘main’: /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/include/subcmd/parse-options.h:118:32: warning: implicit declaration of function ‘BUILD_BUG_ON_ZERO’ [-Wimplicit-function-declaration] 118 | #define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) | ^~~~~~~~~~~~~~~~~ /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/include/subcmd/parse-options.h:131:106: note: in expansion of macro ‘check_vtype’ 131 | #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } | ^~~~~~~~~~~ main.c:736:17: note: in expansion of macro ‘OPT_INCR’ 736 | OPT_INCR('v', "verbose", &verbose, | ^~~~~~~~ make[4]: *** [/opt/net-next/tools/build/Makefile.build:97: /opt/net-next/output-arm64/tools/bpf/resolve_btfids/main.o] Error 1 make[3]: *** [Makefile:80: /opt/net-next/output-arm64/tools/bpf/resolve_btfids//resolve_btfids-in.o] Error 2 make[2]: *** [Makefile:76: bpf/resolve_btfids] Error 2 make[1]: *** [/opt/net-next/Makefile:1451: tools/bpf/resolve_btfids] Error 2 make[1]: *** Waiting for unfinished jobs.... HOSTLD scripts/mod/modpost CC kernel/bounds.s CC arch/arm64/kernel/asm-offsets.s CALL ../scripts/checksyscalls.sh make[1]: Leaving directory '/opt/net-next/output-arm64' make: *** [Makefile:242: __sub-make] Error 2 After reverting: make -j 8 Image.gz dtbs modules W=1 C=1 make[1]: Entering directory '/opt/net-next/output-arm64' GEN Makefile DESCEND bpf/resolve_btfids CALL ../scripts/checksyscalls.sh INSTALL libsubcmd_headers CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/exec-cmd.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/help.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/pager.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/parse-options.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/run-command.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/sigchain.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/subcmd-config.o LDS arch/arm64/kernel/vdso/vdso.lds CC arch/arm64/kernel/vdso/vgettimeofday.o AS arch/arm64/kernel/vdso/note.o AS arch/arm64/kernel/vdso/sigreturn.o CHECK ../arch/arm64/kernel/vdso/vgettimeofday.c ../arch/arm64/kernel/vdso/vgettimeofday.c:9:5: warning: symbol '__kernel_clock_gettime' was not declared. Should it be static? ../arch/arm64/kernel/vdso/vgettimeofday.c:15:5: warning: symbol '__kernel_gettimeofday' was not declared. Should it be static? ../arch/arm64/kernel/vdso/vgettimeofday.c:21:5: warning: symbol '__kernel_clock_getres' was not declared. Should it be static? LD arch/arm64/kernel/vdso/vdso.so.dbg VDSOSYM include/generated/vdso-offsets.h OBJCOPY arch/arm64/kernel/vdso/vdso.so LD /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/libsubcmd-in.o AR /opt/net-next/output-arm64/tools/bpf/resolve_btfids/libsubcmd/libsubcmd.a CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/main.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/rbtree.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/zalloc.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/string.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/ctype.o CC /opt/net-next/output-arm64/tools/bpf/resolve_btfids/str_error_r.o LD /opt/net-next/output-arm64/tools/bpf/resolve_btfids/resolve_btfids-in.o LINK resolve_btfids (...) Sadly idk how to fix it. I put this print in tools/bpf/resolve_btfids/Makefile if it helps: $(error CC $(CC) HOSTCC $(HOSTCC) HOSTCFLAGS $(HOSTCFLAGS) KBUILD_HOSTCFLAGS $(KBUILD_HOSTLDFLAGS)) which outputs: Makefile:24: *** CC aarch64-none-linux-gnu-gcc HOSTCC gcc HOSTCFLAGS KBUILD_HOSTCFLAGS . Stop.
On Fri, Feb 03, 2023 at 08:25:40PM +0200, Vladimir Oltean wrote: > On Wed, Feb 01, 2023 at 09:36:37AM -0800, Josh Poimboeuf wrote: > > On Wed, Feb 01, 2023 at 05:02:16PM +0000, Mark Rutland wrote: > > > Hi, > > > > > > I just spotted this breaks cross-compiling; details below. > > > > Thanks, we'll fix it up with > > > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > > index 29a8cd7449bf..83b100c1e7f6 100644 > > --- a/tools/objtool/Makefile > > +++ b/tools/objtool/Makefile > > @@ -36,7 +36,7 @@ OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBE > > OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > > > > # Allow old libelf to be used: > > -elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr) > > +elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr) > > OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) > > > > # Always want host compilation. > > Profiting off of the occasion to point out that cross-compiling with > CONFIG_DEBUG_INFO_BTF=y is also broken (it builds the resolve_btfids > tool): The above patch was for objtool, though I'm guessing you were bitten by a similar patch for bpf: 13e07691a16f ("tools/resolve_btfids: Alter how HOSTCC is forced") It looks like it might have a similar problem we had for objtool. Does this fix it? diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile index daed388aa5d7..fff84cd914cd 100644 --- a/tools/bpf/resolve_btfids/Makefile +++ b/tools/bpf/resolve_btfids/Makefile @@ -18,8 +18,8 @@ else endif # always use the host compiler -HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \ - EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" +HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" +BTF_CFLAGS := $(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS) RM ?= rm CROSS_COMPILE = @@ -53,23 +53,25 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ - DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ + $(HOST_OVERRIDES) EXTRA_CFLAGS="$(BTF_CFLAGS)" \ + DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \ $(abspath $@) install_headers $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT) $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \ - DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ + $(HOST_OVERRIDES) EXTRA_CFLAGS="$(BTF_CFLAGS)" \ + DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \ $(abspath $@) install_headers LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) -CFLAGS += -g \ - -I$(srctree)/tools/include \ - -I$(srctree)/tools/include/uapi \ - -I$(LIBBPF_INCLUDE) \ - -I$(SUBCMD_INCLUDE) \ - $(LIBELF_FLAGS) +BTF_CFLAGS += -g \ + -I$(srctree)/tools/include \ + -I$(srctree)/tools/include/uapi \ + -I$(LIBBPF_INCLUDE) \ + -I$(SUBCMD_INCLUDE) \ + $(LIBELF_FLAGS) LIBS = $(LIBELF_LIBS) -lz @@ -77,7 +79,7 @@ export srctree OUTPUT CFLAGS Q include $(srctree)/tools/build/Makefile.include $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) - $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) CFLAGS="$(BTF_CFLAGS)" $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) $(call msg,LINK,$@)
On Sat, Feb 4, 2023 at 9:05 AM Josh Poimboeuf <jpoimboe@kernel.org> wrote: > > On Fri, Feb 03, 2023 at 08:25:40PM +0200, Vladimir Oltean wrote: > > On Wed, Feb 01, 2023 at 09:36:37AM -0800, Josh Poimboeuf wrote: > > > On Wed, Feb 01, 2023 at 05:02:16PM +0000, Mark Rutland wrote: > > > > Hi, > > > > > > > > I just spotted this breaks cross-compiling; details below. > > > > > > Thanks, we'll fix it up with > > > > > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > > > index 29a8cd7449bf..83b100c1e7f6 100644 > > > --- a/tools/objtool/Makefile > > > +++ b/tools/objtool/Makefile > > > @@ -36,7 +36,7 @@ OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBE > > > OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > > > > > > # Allow old libelf to be used: > > > -elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr) > > > +elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr) > > > OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) > > > > > > # Always want host compilation. > > > > Profiting off of the occasion to point out that cross-compiling with > > CONFIG_DEBUG_INFO_BTF=y is also broken (it builds the resolve_btfids > > tool): > > The above patch was for objtool, though I'm guessing you were bitten by > a similar patch for bpf: > > 13e07691a16f ("tools/resolve_btfids: Alter how HOSTCC is forced") > > It looks like it might have a similar problem we had for objtool. Does > this fix it? Jiri Olsa has been exploring switching to using hostprogs (we need a hostlibs notion), his patch is: https://lore.kernel.org/bpf/20230202112839.1131892-1-jolsa@kernel.org/ With this thread giving context: https://lore.kernel.org/lkml/20230201015015.359535-1-irogers@google.com/ If we have hostprogs and hostlibs then objtool should move to this approach as changing CC leads to broken CFLAGS and the like. Thanks, Ian > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > index daed388aa5d7..fff84cd914cd 100644 > --- a/tools/bpf/resolve_btfids/Makefile > +++ b/tools/bpf/resolve_btfids/Makefile > @@ -18,8 +18,8 @@ else > endif > > # always use the host compiler > -HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \ > - EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" > +HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" > +BTF_CFLAGS := $(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS) > > RM ?= rm > CROSS_COMPILE = > @@ -53,23 +53,25 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): > > $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd > $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ > - DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ > + $(HOST_OVERRIDES) EXTRA_CFLAGS="$(BTF_CFLAGS)" \ > + DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \ > $(abspath $@) install_headers > > $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT) > $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \ > - DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ > + $(HOST_OVERRIDES) EXTRA_CFLAGS="$(BTF_CFLAGS)" \ > + DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \ > $(abspath $@) install_headers > > LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) > LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) > > -CFLAGS += -g \ > - -I$(srctree)/tools/include \ > - -I$(srctree)/tools/include/uapi \ > - -I$(LIBBPF_INCLUDE) \ > - -I$(SUBCMD_INCLUDE) \ > - $(LIBELF_FLAGS) > +BTF_CFLAGS += -g \ > + -I$(srctree)/tools/include \ > + -I$(srctree)/tools/include/uapi \ > + -I$(LIBBPF_INCLUDE) \ > + -I$(SUBCMD_INCLUDE) \ > + $(LIBELF_FLAGS) > > LIBS = $(LIBELF_LIBS) -lz > > @@ -77,7 +79,7 @@ export srctree OUTPUT CFLAGS Q > include $(srctree)/tools/build/Makefile.include > > $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) > - $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) > + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) CFLAGS="$(BTF_CFLAGS)" > > $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) > $(call msg,LINK,$@)
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: cd955bdd6aa5ec54cdef622a142f8899a64b5446
Gitweb: https://git.kernel.org/tip/cd955bdd6aa5ec54cdef622a142f8899a64b5446
Author: Ian Rogers <irogers@google.com>
AuthorDate: Thu, 26 Jan 2023 11:06:06 -08:00
Committer: Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Wed, 01 Feb 2023 09:15:18 -08:00
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>
---
tools/objtool/Makefile | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index d54b669..83b100c 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -2,11 +2,6 @@
include ../scripts/Makefile.include
include ../scripts/Makefile.arch
-# always use the host compiler
-AR = $(HOSTAR)
-CC = $(HOSTCC)
-LD = $(HOSTLD)
-
ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
@@ -34,13 +29,18 @@ INCLUDES := -I$(srctree)/tools/include \
-I$(srctree)/tools/objtool/include \
-I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
-I$(LIBSUBCMD_OUTPUT)/include
+# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
+# is passed here to match a legacy behavior.
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
-CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
-LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
+OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
+OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
# Allow old libelf to be used:
-elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
-CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
+elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
+OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
+
+# Always want host compilation.
+HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
AWK = awk
MKDIR = mkdir
@@ -61,12 +61,14 @@ export BUILD_ORC
export srctree OUTPUT CFLAGS SRCARCH AWK
include $(srctree)/tools/build/Makefile.include
-$(OBJTOOL_IN): fixdep FORCE
+$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
$(Q)$(CONFIG_SHELL) ./sync-check.sh
- $(Q)$(MAKE) $(build)=objtool
+ $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
+ LDFLAGS="$(OBJTOOL_LDFLAGS)"
+
$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
- $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
+ $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
$(LIBSUBCMD_OUTPUT):
@@ -75,6 +77,7 @@ $(LIBSUBCMD_OUTPUT):
$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
+ $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
$@ install_headers
$(LIBSUBCMD)-clean:
© 2016 - 2025 Red Hat, Inc.