ANDROID: tools/resolve_btfids: Pass CFLAGS to libsubcmd build via EXTRA_CFLAGS

When building using kleaf on an host distribution with glibc 2.38 or later,
there is a linkage failure when building resolve_btfids:

  ld.lld: error: undefined symbol: __isoc23_strtol
  >>> referenced by stdlib.h:483 (/usr/include/stdlib.h:483)
  >>>               libsubcmd-in.o:(pretty_print_string_list) in archive .../libsubcmd.a
  >>> referenced by stdlib.h:483 (/usr/include/stdlib.h:483)
  >>>               libsubcmd-in.o:(pretty_print_string_list) in archive .../libsubcmd.a
  >>> referenced by stdlib.h:483 (/usr/include/stdlib.h:483)
  >>>               libsubcmd-in.o:(pager_get_columns) in archive .../libsubcmd.a
  >>> referenced 2 more times

  ld.lld: error: undefined symbol: __isoc23_strtoul
  >>> referenced by parse-options.c:314 (.../tools/lib/subcmd/parse-options.c:314)
  >>>               libsubcmd-in.o:(get_value) in archive .../libsubcmd.a

  ld.lld: error: undefined symbol: __isoc23_strtoull
  >>> referenced by parse-options.c:332 (.../tools/lib/subcmd/parse-options.c:332)
  >>>               libsubcmd-in.o:(get_value) in archive .../libsubcmd.a
  clang-17: error: linker command failed with exit code 1 (use -v to see invocation)

These errors imply that the files were build against glibc 2.38 headers
but attempted to be linked with an older glibc version.

Building with '--debug_make_verbosity=D' reveals that the libsubcmd
object files are not built with the additional HOSTCFLAGS the Android
build system provides for a hermetic build (namely '-I' for .c files),
so they build against the system's headers but link against Android's
glibc 2.17, resulting in the error above.

This is not an issue upstream after
commit 13e07691a1 ("tools/resolve_btfids: Alter how HOSTCC is
forced"), as HOST_OVERRIDES (which contains HOSTCFLAGS via EXTRA_CFLAGS)
is passed along to libsubcmd. That change is quite invasive as a
backport for 5.15 and earlier. As a miminal fix, pass CFLAGS (which
contains HOSTCFLAGS via KBUILD_HOSTCFLAGS) to the libsubcmd build via
EXTRA_CFLAGS, which really should have been done upstream in
commit 0e3a1c902f ("tools/resolve_btfids: Build with host flags"),
which is present in this branch as commit 9e332a14f3 ("FROMGIT:
tools/resolve_btfids: Build with host flags").

Bug: 301145081
Change-Id: I91c1c9a8fb8f83118a6b8ec4da6cc33a773f2124
Fixes: 368cd63174 ("FROMGIT: tools/resolve_btfids: Build with host flags")
Link: https://github.com/ClangBuiltLinux/linux/issues/1929
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
This commit is contained in:
Nathan Chancellor
2023-09-07 13:55:49 -07:00
committed by Treehugger Robot
parent 4aee33cbf4
commit a0622550a9

View File

@@ -44,7 +44,7 @@ $(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd:
$(Q)mkdir -p $(@)
$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
$(Q)$(MAKE) -C $(SUBCMD_SRC) EXTRA_CFLAGS="$(CFLAGS)" OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ \