linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/3] objtool build improvements
@ 2023-01-26 19:06 Ian Rogers
  2023-01-26 19:06 ` [PATCH v4 1/3] objtool: Install libsubcmd in build Ian Rogers
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Ian Rogers @ 2023-01-26 19:06 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, Masahiro Yamada, Nicolas Schier,
	linux-kernel, llvm
  Cc: Stephane Eranian, Andrii Nakryiko, Jiri Olsa,
	Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers

Install libsubcmd and then get headers from there, this avoids
inadvertent dependencies on things in tools/lib. Fix V=1
support. Clean up how HOSTCC is used to override CC to avoid CFLAGS
being set for say gcc, and then CC being overridden to clang.

v4. Rebase and look to address review comments from Josh Poimboeuf
    <jpoimboe@kernel.org>. Removes the reviewed-by/tested-by given
    the scope of changes.
v3. Is a rebase that removes the merged "tools lib subcmd: Add install
    target" patch. In:
https://lore.kernel.org/lkml/CAKwvOd=kgXmpfbVa1wiEvwL0tX3gu+dDTGi-HEiRXSojwCLRrg@mail.gmail.com/
    Nick rightly points out that:
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
    became:
WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
    losing the EXTRA_WARNINGS which v3 now adds back in. Previous
    testing had added the warnings to the end rather than the
    beginning, thereby causing unexpected build issues that aren't present in v3.
v2. Include required "tools lib subcmd: Add install target" that is
    already in Arnaldo's tree:
https://lore.kernel.org/lkml/20221109184914.1357295-3-irogers@google.com/
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=630ae80ea1dd253609cb50cff87f3248f901aca3
    When building libsubcmd.a from objtool's Makefile, clear the
    subdir to avoid it being appended onto OUTPUT and breaking the
    build.

Ian Rogers (3):
  objtool: Install libsubcmd in build
  objtool: Properly support make V=1
  objtool: Alter how HOSTCC is forced

 tools/objtool/.gitignore |  1 +
 tools/objtool/Build      |  2 --
 tools/objtool/Makefile   | 62 ++++++++++++++++++++++++++++------------
 3 files changed, 44 insertions(+), 21 deletions(-)

-- 
2.39.1.456.gfc5497dd1b-goog


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v4 1/3] objtool: Install libsubcmd in build
  2023-01-26 19:06 [PATCH v4 0/3] objtool build improvements Ian Rogers
@ 2023-01-26 19:06 ` Ian Rogers
  2023-02-01 16:26   ` [tip: objtool/core] " tip-bot2 for Ian Rogers
  2023-01-26 19:06 ` [PATCH v4 2/3] objtool: Properly support make V=1 Ian Rogers
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Ian Rogers @ 2023-01-26 19:06 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, Masahiro Yamada, Nicolas Schier,
	linux-kernel, llvm
  Cc: Stephane Eranian, Andrii Nakryiko, Jiri Olsa,
	Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers

Including from tools/lib can create inadvertent dependencies. Install
libsubcmd in the objtool build and then include the headers from
there.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/objtool/.gitignore |  1 +
 tools/objtool/Build      |  2 --
 tools/objtool/Makefile   | 31 +++++++++++++++++++++++--------
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore
index 14236db3677f..4faa4dd72f35 100644
--- a/tools/objtool/.gitignore
+++ b/tools/objtool/.gitignore
@@ -2,3 +2,4 @@
 arch/x86/lib/inat-tables.c
 /objtool
 fixdep
+libsubcmd/
diff --git a/tools/objtool/Build b/tools/objtool/Build
index 33f2ee5a46d3..a3cdf8af6635 100644
--- a/tools/objtool/Build
+++ b/tools/objtool/Build
@@ -16,8 +16,6 @@ objtool-y += libctype.o
 objtool-y += str_error_r.o
 objtool-y += librbtree.o
 
-CFLAGS += -I$(srctree)/tools/lib
-
 $(OUTPUT)libstring.o: ../lib/string.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index a3a9cc24e0e3..0bfdb9da8729 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -12,9 +12,13 @@ srctree := $(patsubst %/,%,$(dir $(CURDIR)))
 srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
-SUBCMD_SRCDIR		= $(srctree)/tools/lib/subcmd/
-LIBSUBCMD_OUTPUT	= $(or $(OUTPUT),$(CURDIR)/)
-LIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
+LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
+ifneq ($(OUTPUT),)
+  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
+else
+  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
+endif
+LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
 
 OBJTOOL    := $(OUTPUT)objtool
 OBJTOOL_IN := $(OBJTOOL)-in.o
@@ -28,7 +32,8 @@ INCLUDES := -I$(srctree)/tools/include \
 	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
 	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
 	    -I$(srctree)/tools/objtool/include \
-	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include
+	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
+	    -I$(LIBSUBCMD_OUTPUT)/include
 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)
@@ -38,6 +43,7 @@ elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E -
 CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
 
 AWK = awk
+MKDIR = mkdir
 
 BUILD_ORC := n
 
@@ -57,13 +63,22 @@ $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
 	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
 
 
-$(LIBSUBCMD): fixdep FORCE
-	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
+$(LIBSUBCMD_OUTPUT):
+	@$(MKDIR) -p $@
+
+$(LIBSUBCMD): fixdep FORCE $(LIBSUBCMD_OUTPUT)
+	@$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
+		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
+		$@ install_headers
+
+$(LIBSUBCMD)-clean:
+	$(call QUIET_CLEAN, libsubcmd)
+	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
 
-clean:
+clean: $(LIBSUBCMD)-clean
 	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
 	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
-	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(LIBSUBCMD)
+	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
 
 FORCE:
 
-- 
2.39.1.456.gfc5497dd1b-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 2/3] objtool: Properly support make V=1
  2023-01-26 19:06 [PATCH v4 0/3] objtool build improvements Ian Rogers
  2023-01-26 19:06 ` [PATCH v4 1/3] objtool: Install libsubcmd in build Ian Rogers
@ 2023-01-26 19:06 ` Ian Rogers
  2023-02-01 16:26   ` [tip: objtool/core] " tip-bot2 for Ian Rogers
  2023-01-26 19:06 ` [PATCH v4 3/3] objtool: Alter how HOSTCC is forced Ian Rogers
  2023-01-26 19:34 ` [PATCH v4 0/3] objtool build improvements Josh Poimboeuf
  3 siblings, 1 reply; 16+ messages in thread
From: Ian Rogers @ 2023-01-26 19:06 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, Masahiro Yamada, Nicolas Schier,
	linux-kernel, llvm
  Cc: Stephane Eranian, Andrii Nakryiko, Jiri Olsa,
	Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers

The Q variable was being used but never correctly set up. Add the
setting up and use in place of @.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/objtool/Makefile | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 0bfdb9da8729..f0651eac06e6 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -45,6 +45,12 @@ CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
 AWK = awk
 MKDIR = mkdir
 
+ifeq ($(V),1)
+  Q =
+else
+  Q = @
+endif
+
 BUILD_ORC := n
 
 ifeq ($(SRCARCH),x86)
@@ -56,18 +62,18 @@ export srctree OUTPUT CFLAGS SRCARCH AWK
 include $(srctree)/tools/build/Makefile.include
 
 $(OBJTOOL_IN): fixdep FORCE
-	@$(CONFIG_SHELL) ./sync-check.sh
-	@$(MAKE) $(build)=objtool
+	$(Q)$(CONFIG_SHELL) ./sync-check.sh
+	$(Q)$(MAKE) $(build)=objtool
 
 $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
 	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
 
 
 $(LIBSUBCMD_OUTPUT):
-	@$(MKDIR) -p $@
+	$(Q)$(MKDIR) -p $@
 
 $(LIBSUBCMD): fixdep FORCE $(LIBSUBCMD_OUTPUT)
-	@$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
+	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
 		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
 		$@ install_headers
 
-- 
2.39.1.456.gfc5497dd1b-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 3/3] objtool: Alter how HOSTCC is forced
  2023-01-26 19:06 [PATCH v4 0/3] objtool build improvements Ian Rogers
  2023-01-26 19:06 ` [PATCH v4 1/3] objtool: Install libsubcmd in build Ian Rogers
  2023-01-26 19:06 ` [PATCH v4 2/3] objtool: Properly support make V=1 Ian Rogers
@ 2023-01-26 19:06 ` Ian Rogers
  2023-02-01 16:26   ` [tip: objtool/core] objtool: Fix HOSTCC flag usage tip-bot2 for Ian Rogers
  2023-02-04 10:17   ` tip-bot2 for Ian Rogers
  2023-01-26 19:34 ` [PATCH v4 0/3] objtool build improvements Josh Poimboeuf
  3 siblings, 2 replies; 16+ messages in thread
From: Ian Rogers @ 2023-01-26 19:06 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, Masahiro Yamada, Nicolas Schier,
	linux-kernel, llvm
  Cc: Stephane Eranian, Andrii Nakryiko, Jiri Olsa,
	Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers

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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/3] objtool build improvements
  2023-01-26 19:06 [PATCH v4 0/3] objtool build improvements Ian Rogers
                   ` (2 preceding siblings ...)
  2023-01-26 19:06 ` [PATCH v4 3/3] objtool: Alter how HOSTCC is forced Ian Rogers
@ 2023-01-26 19:34 ` Josh Poimboeuf
  2023-01-31  0:25   ` Josh Poimboeuf
  3 siblings, 1 reply; 16+ messages in thread
From: Josh Poimboeuf @ 2023-01-26 19:34 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	Masahiro Yamada, Nicolas Schier, linux-kernel, llvm,
	Stephane Eranian, Andrii Nakryiko, Jiri Olsa,
	Arnaldo Carvalho de Melo, Namhyung Kim

On Thu, Jan 26, 2023 at 11:06:03AM -0800, Ian Rogers wrote:
> Install libsubcmd and then get headers from there, this avoids
> inadvertent dependencies on things in tools/lib. Fix V=1
> support. Clean up how HOSTCC is used to override CC to avoid CFLAGS
> being set for say gcc, and then CC being overridden to clang.
> 
> v4. Rebase and look to address review comments from Josh Poimboeuf
>     <jpoimboe@kernel.org>. Removes the reviewed-by/tested-by given
>     the scope of changes.
> v3. Is a rebase that removes the merged "tools lib subcmd: Add install
>     target" patch. In:
> https://lore.kernel.org/lkml/CAKwvOd=kgXmpfbVa1wiEvwL0tX3gu+dDTGi-HEiRXSojwCLRrg@mail.gmail.com/
>     Nick rightly points out that:
> WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
>     became:
> WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
>     losing the EXTRA_WARNINGS which v3 now adds back in. Previous
>     testing had added the warnings to the end rather than the
>     beginning, thereby causing unexpected build issues that aren't present in v3.
> v2. Include required "tools lib subcmd: Add install target" that is
>     already in Arnaldo's tree:
> https://lore.kernel.org/lkml/20221109184914.1357295-3-irogers@google.com/
> https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=630ae80ea1dd253609cb50cff87f3248f901aca3
>     When building libsubcmd.a from objtool's Makefile, clear the
>     subdir to avoid it being appended onto OUTPUT and breaking the
>     build.
> 
> Ian Rogers (3):
>   objtool: Install libsubcmd in build
>   objtool: Properly support make V=1
>   objtool: Alter how HOSTCC is forced

Thanks, this looks pretty good.  I might tweak the patch subjects to
describe what's being fixed from a user's perspective.

I'll wait a few days for any more reviews before merging.

Independently from this patch set, I discovered that HOSTCFLAGS (and
KBUILD_HOSTCFLAGS which includes -O2 and some other flags) don't work
when building objtool directly from tools/objtool.  But they do work
(for me at least) when building from the top-level Makefile.  So I'm not
sure what Nick's issue is.

-- 
Josh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/3] objtool build improvements
  2023-01-26 19:34 ` [PATCH v4 0/3] objtool build improvements Josh Poimboeuf
@ 2023-01-31  0:25   ` Josh Poimboeuf
  2023-01-31  0:31     ` Ian Rogers
  0 siblings, 1 reply; 16+ messages in thread
From: Josh Poimboeuf @ 2023-01-31  0:25 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	Masahiro Yamada, Nicolas Schier, linux-kernel, llvm,
	Stephane Eranian, Andrii Nakryiko, Jiri Olsa,
	Arnaldo Carvalho de Melo, Namhyung Kim

On Thu, Jan 26, 2023 at 11:34:28AM -0800, Josh Poimboeuf wrote:
> On Thu, Jan 26, 2023 at 11:06:03AM -0800, Ian Rogers wrote:
> > Install libsubcmd and then get headers from there, this avoids
> > inadvertent dependencies on things in tools/lib. Fix V=1
> > support. Clean up how HOSTCC is used to override CC to avoid CFLAGS
> > being set for say gcc, and then CC being overridden to clang.
> > 
> > v4. Rebase and look to address review comments from Josh Poimboeuf
> >     <jpoimboe@kernel.org>. Removes the reviewed-by/tested-by given
> >     the scope of changes.
> > v3. Is a rebase that removes the merged "tools lib subcmd: Add install
> >     target" patch. In:
> > https://lore.kernel.org/lkml/CAKwvOd=kgXmpfbVa1wiEvwL0tX3gu+dDTGi-HEiRXSojwCLRrg@mail.gmail.com/
> >     Nick rightly points out that:
> > WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
> >     became:
> > WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
> >     losing the EXTRA_WARNINGS which v3 now adds back in. Previous
> >     testing had added the warnings to the end rather than the
> >     beginning, thereby causing unexpected build issues that aren't present in v3.
> > v2. Include required "tools lib subcmd: Add install target" that is
> >     already in Arnaldo's tree:
> > https://lore.kernel.org/lkml/20221109184914.1357295-3-irogers@google.com/
> > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=630ae80ea1dd253609cb50cff87f3248f901aca3
> >     When building libsubcmd.a from objtool's Makefile, clear the
> >     subdir to avoid it being appended onto OUTPUT and breaking the
> >     build.
> > 
> > Ian Rogers (3):
> >   objtool: Install libsubcmd in build
> >   objtool: Properly support make V=1
> >   objtool: Alter how HOSTCC is forced
> 
> Thanks, this looks pretty good.  I might tweak the patch subjects to
> describe what's being fixed from a user's perspective.
> 
> I'll wait a few days for any more reviews before merging.
> 
> Independently from this patch set, I discovered that HOSTCFLAGS (and
> KBUILD_HOSTCFLAGS which includes -O2 and some other flags) don't work
> when building objtool directly from tools/objtool.  But they do work
> (for me at least) when building from the top-level Makefile.  So I'm not
> sure what Nick's issue is.

The objtool build is failing intermittently with a clean output tree:

    HOSTCC  /home/jpoimboe/tmp/a/tools/objtool/fixdep.o
    HOSTLD  /home/jpoimboe/tmp/a/tools/objtool/fixdep-in.o
    LINK    /home/jpoimboe/tmp/a/tools/objtool/fixdep
    INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/exec-cmd.h
    CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/exec-cmd.o
    MKDIR   /home/jpoimboe/tmp/a/tools/objtool/arch/x86/
    CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/help.o
    CC      /home/jpoimboe/tmp/a/tools/objtool/arch/x86/special.o
    HOSTLD  arch/x86/tools/relocs
  In file included from arch/x86/special.c:5:
  /home/jpoimboe/git/linux/tools/objtool/include/objtool/builtin.h:8:10: fatal error: subcmd/parse-options.h: No such file or directory
      8 | #include <subcmd/parse-options.h>
        |          ^~~~~~~~~~~~~~~~~~~~~~~~
  compilation terminated.
  make[5]: *** [/home/jpoimboe/git/linux/tools/build/Makefile.build:97: /home/jpoimboe/tmp/a/tools/objtool/arch/x86/special.o] Error 1
  make[4]: *** [/home/jpoimboe/git/linux/tools/build/Makefile.build:139: arch/x86] Error 2
  make[3]: *** [Makefile:66: /home/jpoimboe/tmp/a/tools/objtool/objtool-in.o] Error 2
  make[3]: *** Waiting for unfinished jobs....
    INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/help.h
    INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/pager.h
    CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/pager.o
    CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/parse-options.o
    INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/parse-options.h
    CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/run-command.o
    CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/sigchain.o
    CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/subcmd-config.o
    INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/run-command.h

The libsubcmd header files need to be installed before any of the
objtool files gets compiled, so objtool-in.o needs a dependency on
$(LIBSUBCMD).  I'll fold in the following fix:

diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index bbf8ec440430..1e90dad0b23b 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -61,7 +61,7 @@ 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 $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
 		LDFLAGS="$(OBJTOOL_LDFLAGS)"


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/3] objtool build improvements
  2023-01-31  0:25   ` Josh Poimboeuf
@ 2023-01-31  0:31     ` Ian Rogers
  0 siblings, 0 replies; 16+ messages in thread
From: Ian Rogers @ 2023-01-31  0:31 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	Masahiro Yamada, Nicolas Schier, linux-kernel, llvm,
	Stephane Eranian, Andrii Nakryiko, Jiri Olsa,
	Arnaldo Carvalho de Melo, Namhyung Kim

On Mon, Jan 30, 2023 at 4:25 PM Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>
> On Thu, Jan 26, 2023 at 11:34:28AM -0800, Josh Poimboeuf wrote:
> > On Thu, Jan 26, 2023 at 11:06:03AM -0800, Ian Rogers wrote:
> > > Install libsubcmd and then get headers from there, this avoids
> > > inadvertent dependencies on things in tools/lib. Fix V=1
> > > support. Clean up how HOSTCC is used to override CC to avoid CFLAGS
> > > being set for say gcc, and then CC being overridden to clang.
> > >
> > > v4. Rebase and look to address review comments from Josh Poimboeuf
> > >     <jpoimboe@kernel.org>. Removes the reviewed-by/tested-by given
> > >     the scope of changes.
> > > v3. Is a rebase that removes the merged "tools lib subcmd: Add install
> > >     target" patch. In:
> > > https://lore.kernel.org/lkml/CAKwvOd=kgXmpfbVa1wiEvwL0tX3gu+dDTGi-HEiRXSojwCLRrg@mail.gmail.com/
> > >     Nick rightly points out that:
> > > WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
> > >     became:
> > > WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
> > >     losing the EXTRA_WARNINGS which v3 now adds back in. Previous
> > >     testing had added the warnings to the end rather than the
> > >     beginning, thereby causing unexpected build issues that aren't present in v3.
> > > v2. Include required "tools lib subcmd: Add install target" that is
> > >     already in Arnaldo's tree:
> > > https://lore.kernel.org/lkml/20221109184914.1357295-3-irogers@google.com/
> > > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=630ae80ea1dd253609cb50cff87f3248f901aca3
> > >     When building libsubcmd.a from objtool's Makefile, clear the
> > >     subdir to avoid it being appended onto OUTPUT and breaking the
> > >     build.
> > >
> > > Ian Rogers (3):
> > >   objtool: Install libsubcmd in build
> > >   objtool: Properly support make V=1
> > >   objtool: Alter how HOSTCC is forced
> >
> > Thanks, this looks pretty good.  I might tweak the patch subjects to
> > describe what's being fixed from a user's perspective.
> >
> > I'll wait a few days for any more reviews before merging.
> >
> > Independently from this patch set, I discovered that HOSTCFLAGS (and
> > KBUILD_HOSTCFLAGS which includes -O2 and some other flags) don't work
> > when building objtool directly from tools/objtool.  But they do work
> > (for me at least) when building from the top-level Makefile.  So I'm not
> > sure what Nick's issue is.
>
> The objtool build is failing intermittently with a clean output tree:
>
>     HOSTCC  /home/jpoimboe/tmp/a/tools/objtool/fixdep.o
>     HOSTLD  /home/jpoimboe/tmp/a/tools/objtool/fixdep-in.o
>     LINK    /home/jpoimboe/tmp/a/tools/objtool/fixdep
>     INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/exec-cmd.h
>     CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/exec-cmd.o
>     MKDIR   /home/jpoimboe/tmp/a/tools/objtool/arch/x86/
>     CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/help.o
>     CC      /home/jpoimboe/tmp/a/tools/objtool/arch/x86/special.o
>     HOSTLD  arch/x86/tools/relocs
>   In file included from arch/x86/special.c:5:
>   /home/jpoimboe/git/linux/tools/objtool/include/objtool/builtin.h:8:10: fatal error: subcmd/parse-options.h: No such file or directory
>       8 | #include <subcmd/parse-options.h>
>         |          ^~~~~~~~~~~~~~~~~~~~~~~~
>   compilation terminated.
>   make[5]: *** [/home/jpoimboe/git/linux/tools/build/Makefile.build:97: /home/jpoimboe/tmp/a/tools/objtool/arch/x86/special.o] Error 1
>   make[4]: *** [/home/jpoimboe/git/linux/tools/build/Makefile.build:139: arch/x86] Error 2
>   make[3]: *** [Makefile:66: /home/jpoimboe/tmp/a/tools/objtool/objtool-in.o] Error 2
>   make[3]: *** Waiting for unfinished jobs....
>     INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/help.h
>     INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/pager.h
>     CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/pager.o
>     CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/parse-options.o
>     INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/parse-options.h
>     CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/run-command.o
>     CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/sigchain.o
>     CC      /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/subcmd-config.o
>     INSTALL /home/jpoimboe/tmp/a/tools/objtool/libsubcmd/include/subcmd/run-command.h
>
> The libsubcmd header files need to be installed before any of the
> objtool files gets compiled, so objtool-in.o needs a dependency on
> $(LIBSUBCMD).  I'll fold in the following fix:

Right, sorry for that. We fix this elsewhere (not just in perf) with a
phony target called "prepare":
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/Makefile.perf?h=perf/core#n672
The prepare target has a list of dependencies that must be built
first, such as installing header files.

Thanks and apologies again,
Ian

> diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
> index bbf8ec440430..1e90dad0b23b 100644
> --- a/tools/objtool/Makefile
> +++ b/tools/objtool/Makefile
> @@ -61,7 +61,7 @@ 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 $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
>                 LDFLAGS="$(OBJTOOL_LDFLAGS)"
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [tip: objtool/core] objtool: Fix HOSTCC flag usage
  2023-01-26 19:06 ` [PATCH v4 3/3] objtool: Alter how HOSTCC is forced Ian Rogers
@ 2023-02-01 16:26   ` tip-bot2 for Ian Rogers
  2023-02-01 17:02     ` Mark Rutland
  2023-02-04 10:17   ` tip-bot2 for Ian Rogers
  1 sibling, 1 reply; 16+ messages in thread
From: tip-bot2 for Ian Rogers @ 2023-02-01 16:26 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Ian Rogers, Josh Poimboeuf, x86, linux-kernel

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:

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: objtool/core] objtool: Properly support make V=1
  2023-01-26 19:06 ` [PATCH v4 2/3] objtool: Properly support make V=1 Ian Rogers
@ 2023-02-01 16:26   ` tip-bot2 for Ian Rogers
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Ian Rogers @ 2023-02-01 16:26 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Ian Rogers, Josh Poimboeuf, x86, linux-kernel

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     8c4526ca6a45e7ff915c2b33b54db6b773291fac
Gitweb:        https://git.kernel.org/tip/8c4526ca6a45e7ff915c2b33b54db6b773291fac
Author:        Ian Rogers <irogers@google.com>
AuthorDate:    Thu, 26 Jan 2023 11:06:05 -08:00
Committer:     Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Mon, 30 Jan 2023 16:28:16 -08:00

objtool: Properly support make V=1

The Q variable was being used but never correctly set up. Add the
setting up and use in place of @.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20230126190606.40739-3-irogers@google.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/Makefile | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 3505ae4..d54b669 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -45,6 +45,12 @@ CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
 AWK = awk
 MKDIR = mkdir
 
+ifeq ($(V),1)
+  Q =
+else
+  Q = @
+endif
+
 BUILD_ORC := n
 
 ifeq ($(SRCARCH),x86)
@@ -56,18 +62,18 @@ export srctree OUTPUT CFLAGS SRCARCH AWK
 include $(srctree)/tools/build/Makefile.include
 
 $(OBJTOOL_IN): fixdep FORCE
-	@$(CONFIG_SHELL) ./sync-check.sh
-	@$(MAKE) $(build)=objtool
+	$(Q)$(CONFIG_SHELL) ./sync-check.sh
+	$(Q)$(MAKE) $(build)=objtool
 
 $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
 	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
 
 
 $(LIBSUBCMD_OUTPUT):
-	@$(MKDIR) -p $@
+	$(Q)$(MKDIR) -p $@
 
 $(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
-	@$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
+	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
 		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
 		$@ install_headers
 

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: objtool/core] objtool: Install libsubcmd in build
  2023-01-26 19:06 ` [PATCH v4 1/3] objtool: Install libsubcmd in build Ian Rogers
@ 2023-02-01 16:26   ` tip-bot2 for Ian Rogers
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Ian Rogers @ 2023-02-01 16:26 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Ian Rogers, Josh Poimboeuf, x86, linux-kernel

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     bdb8bf7d56afd1d22c12c61455d732d3baff2bde
Gitweb:        https://git.kernel.org/tip/bdb8bf7d56afd1d22c12c61455d732d3baff2bde
Author:        Ian Rogers <irogers@google.com>
AuthorDate:    Thu, 26 Jan 2023 11:06:04 -08:00
Committer:     Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Mon, 30 Jan 2023 16:27:46 -08:00

objtool: Install libsubcmd in build

Including from tools/lib can create inadvertent dependencies. Install
libsubcmd in the objtool build and then include the headers from
there.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20230126190606.40739-2-irogers@google.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/.gitignore |  1 +
 tools/objtool/Build      |  2 --
 tools/objtool/Makefile   | 31 +++++++++++++++++++++++--------
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore
index 14236db..4faa4dd 100644
--- a/tools/objtool/.gitignore
+++ b/tools/objtool/.gitignore
@@ -2,3 +2,4 @@
 arch/x86/lib/inat-tables.c
 /objtool
 fixdep
+libsubcmd/
diff --git a/tools/objtool/Build b/tools/objtool/Build
index 33f2ee5..a3cdf8a 100644
--- a/tools/objtool/Build
+++ b/tools/objtool/Build
@@ -16,8 +16,6 @@ objtool-y += libctype.o
 objtool-y += str_error_r.o
 objtool-y += librbtree.o
 
-CFLAGS += -I$(srctree)/tools/lib
-
 $(OUTPUT)libstring.o: ../lib/string.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index a3a9cc2..3505ae4 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -12,9 +12,13 @@ srctree := $(patsubst %/,%,$(dir $(CURDIR)))
 srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
-SUBCMD_SRCDIR		= $(srctree)/tools/lib/subcmd/
-LIBSUBCMD_OUTPUT	= $(or $(OUTPUT),$(CURDIR)/)
-LIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
+LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
+ifneq ($(OUTPUT),)
+  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
+else
+  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
+endif
+LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
 
 OBJTOOL    := $(OUTPUT)objtool
 OBJTOOL_IN := $(OBJTOOL)-in.o
@@ -28,7 +32,8 @@ INCLUDES := -I$(srctree)/tools/include \
 	    -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
 	    -I$(srctree)/tools/arch/$(SRCARCH)/include	\
 	    -I$(srctree)/tools/objtool/include \
-	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include
+	    -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
+	    -I$(LIBSUBCMD_OUTPUT)/include
 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)
@@ -38,6 +43,7 @@ elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E -
 CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
 
 AWK = awk
+MKDIR = mkdir
 
 BUILD_ORC := n
 
@@ -57,13 +63,22 @@ $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
 	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
 
 
-$(LIBSUBCMD): fixdep FORCE
-	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
+$(LIBSUBCMD_OUTPUT):
+	@$(MKDIR) -p $@
+
+$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
+	@$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
+		DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
+		$@ install_headers
+
+$(LIBSUBCMD)-clean:
+	$(call QUIET_CLEAN, libsubcmd)
+	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
 
-clean:
+clean: $(LIBSUBCMD)-clean
 	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
 	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
-	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(LIBSUBCMD)
+	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
 
 FORCE:
 

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [tip: objtool/core] objtool: Fix HOSTCC flag usage
  2023-02-01 16:26   ` [tip: objtool/core] objtool: Fix HOSTCC flag usage tip-bot2 for Ian Rogers
@ 2023-02-01 17:02     ` Mark Rutland
  2023-02-01 17:36       ` Josh Poimboeuf
  0 siblings, 1 reply; 16+ messages in thread
From: Mark Rutland @ 2023-02-01 17:02 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-tip-commits, Ian Rogers, Josh Poimboeuf, x86

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, &sections_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:

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tip: objtool/core] objtool: Fix HOSTCC flag usage
  2023-02-01 17:02     ` Mark Rutland
@ 2023-02-01 17:36       ` Josh Poimboeuf
  2023-02-03 18:25         ` Vladimir Oltean
  0 siblings, 1 reply; 16+ messages in thread
From: Josh Poimboeuf @ 2023-02-01 17:36 UTC (permalink / raw)
  To: Mark Rutland; +Cc: linux-kernel, linux-tip-commits, Ian Rogers, x86

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.

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [tip: objtool/core] objtool: Fix HOSTCC flag usage
  2023-02-01 17:36       ` Josh Poimboeuf
@ 2023-02-03 18:25         ` Vladimir Oltean
  2023-02-04 17:05           ` Josh Poimboeuf
  0 siblings, 1 reply; 16+ messages in thread
From: Vladimir Oltean @ 2023-02-03 18:25 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Mark Rutland, linux-kernel, linux-tip-commits, Ian Rogers, x86, netdev

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.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [tip: objtool/core] objtool: Fix HOSTCC flag usage
  2023-01-26 19:06 ` [PATCH v4 3/3] objtool: Alter how HOSTCC is forced Ian Rogers
  2023-02-01 16:26   ` [tip: objtool/core] objtool: Fix HOSTCC flag usage tip-bot2 for Ian Rogers
@ 2023-02-04 10:17   ` tip-bot2 for Ian Rogers
  1 sibling, 0 replies; 16+ messages in thread
From: tip-bot2 for Ian Rogers @ 2023-02-04 10:17 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Ian Rogers, Josh Poimboeuf, x86, linux-kernel

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:

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [tip: objtool/core] objtool: Fix HOSTCC flag usage
  2023-02-03 18:25         ` Vladimir Oltean
@ 2023-02-04 17:05           ` Josh Poimboeuf
  2023-02-04 21:21             ` Ian Rogers
  0 siblings, 1 reply; 16+ messages in thread
From: Josh Poimboeuf @ 2023-02-04 17:05 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Mark Rutland, linux-kernel, linux-tip-commits, Ian Rogers, x86, netdev

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,$@)

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [tip: objtool/core] objtool: Fix HOSTCC flag usage
  2023-02-04 17:05           ` Josh Poimboeuf
@ 2023-02-04 21:21             ` Ian Rogers
  0 siblings, 0 replies; 16+ messages in thread
From: Ian Rogers @ 2023-02-04 21:21 UTC (permalink / raw)
  To: Josh Poimboeuf, Jiri Olsa
  Cc: Vladimir Oltean, Mark Rutland, linux-kernel, linux-tip-commits,
	x86, netdev

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,$@)

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-02-04 21:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 19:06 [PATCH v4 0/3] objtool build improvements Ian Rogers
2023-01-26 19:06 ` [PATCH v4 1/3] objtool: Install libsubcmd in build Ian Rogers
2023-02-01 16:26   ` [tip: objtool/core] " tip-bot2 for Ian Rogers
2023-01-26 19:06 ` [PATCH v4 2/3] objtool: Properly support make V=1 Ian Rogers
2023-02-01 16:26   ` [tip: objtool/core] " tip-bot2 for Ian Rogers
2023-01-26 19:06 ` [PATCH v4 3/3] objtool: Alter how HOSTCC is forced Ian Rogers
2023-02-01 16:26   ` [tip: objtool/core] objtool: Fix HOSTCC flag usage tip-bot2 for Ian Rogers
2023-02-01 17:02     ` Mark Rutland
2023-02-01 17:36       ` Josh Poimboeuf
2023-02-03 18:25         ` Vladimir Oltean
2023-02-04 17:05           ` Josh Poimboeuf
2023-02-04 21:21             ` Ian Rogers
2023-02-04 10:17   ` tip-bot2 for Ian Rogers
2023-01-26 19:34 ` [PATCH v4 0/3] objtool build improvements Josh Poimboeuf
2023-01-31  0:25   ` Josh Poimboeuf
2023-01-31  0:31     ` Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).