Message ID | 20230105090155.357604-4-irogers@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp200894wrt; Thu, 5 Jan 2023 01:05:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRSZ79wKHMA/uvfY9fw/a5G4BkbCMzUo7aSQuEan0/SSTfLoR9Z4KVwz+oyBHoDJQXn7Bj X-Received: by 2002:a05:6402:5293:b0:494:eb9:54c4 with SMTP id en19-20020a056402529300b004940eb954c4mr209311edb.19.1672909518274; Thu, 05 Jan 2023 01:05:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672909518; cv=none; d=google.com; s=arc-20160816; b=KoqfcwCRNm2ueU3M3nYQl6UGYgWTzo9VUP9VV7/4d4bP5HtWJhGPebFvoBd0QVGbow j1BBbrPc2eApqJBjpNtb4WROoqswdcWUzlCjWwc4UoVyy6AkmDKYeMuBFpdRIWKMRuQq R68ANOocTxoojwyExN2iFniOEoGk/i/i2etZbs9Xs/lIV2RorVDuhmW0dSsFUuUCbagF 15Zn96Q4ebp0lWZObWLTccpPuL5uffvOzPCZLj94ipckkzI7J8/mbPqhs1++dgK6jvPu 6UmpPDXS22WH6h5kA1DCnapOzS2TMw4ZGIM4PfEliNZzhK1JMSyRavXwGvHoTrGe1tgU vmew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=gVMnA3Yba2vBCG/rrA8tRkVdPMnJ5tlbhWykIgv9gDY=; b=aVNqJlnTEbdcXmKnbBSikF2GI9aPqbFlBd+THKxUwRKG9uVsa5W8OKDcvwFAI5u7KN ruxbf9OO3SJ2qphldrNk7qtRVjw+kHQTQbC2ysS2qFIt4qskWno9MF0G5Ok0+Q0a5AdE ggONtW/OCVJn8rqUWK06lh6mm4ABqqYD8iGTHcQfDB+zZ5OpXvjvBXejdYE7vQfw0hRl GPlh0kabBeJyeOgOq5aICUBPM5h+t/z/pFVhVEuH0me/gULIN1AEAVVM2ewGIQU1Z5Qr p4Pk/TjI8nLBwWI3L4lfKuTv8Z15PC/VGJRyhqiTZo+LJ9jAsYg+/UEe7ZCehS7WL8qF BaRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cyUVgkg2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020aa7c902000000b00484f68b784csi24319387edt.329.2023.01.05.01.04.54; Thu, 05 Jan 2023 01:05:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cyUVgkg2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231985AbjAEJDJ (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Thu, 5 Jan 2023 04:03:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231910AbjAEJCd (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 5 Jan 2023 04:02:33 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9593250066 for <linux-kernel@vger.kernel.org>; Thu, 5 Jan 2023 01:02:32 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 195-20020a2505cc000000b0071163981d18so36469508ybf.13 for <linux-kernel@vger.kernel.org>; Thu, 05 Jan 2023 01:02:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gVMnA3Yba2vBCG/rrA8tRkVdPMnJ5tlbhWykIgv9gDY=; b=cyUVgkg2LrWNWl0sdLVkr39/f4zMFUDi5twbEV0MjD8DMoZTIXLIJeh+o8WC/FcLfM OOF3VoiMBL/u+++aQU870Rb1fy+avLKjOnXakh+mWWaoJUWJN+ghT2bv+O3nNk4q5gEw HB2mSh8dMXbqWTL9plMEWe+z/gyL4dKQR406hAPac7K2Btu67B2qCP0HPja5AUjx/pPi dzF/2urVtfo/CQxRUrG7NTETNCka/FED1iOA2erccE5ljW7qgbi+sGSFzrFCm5m1cXui UvVhE58brTFs4adT5qGngtBGxG7zX7c+rG04jkGbZqrN1UaYAE7CFcb2KjT+oxMuwM7t 4ngA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gVMnA3Yba2vBCG/rrA8tRkVdPMnJ5tlbhWykIgv9gDY=; b=cbGirZtkR81aM8KuEWlUqKAw6wGI/LLJTGLgD5Hwh8UrnLxX1w2PNQX9SQkIdj3al9 tGZPAxlTUnGhBkoyIuwlvJU1oNOyCoZxLMoAih2MIaYuiXScQ3S/Loj9mxEYue2baJ6X B4vy0X7F1DEpObAt/XszgzHSxWbHuwiWTOpMZk8xbvC+z+M1wh5P7oKW6mH+iQF0PHrL QEtKaSmOCioTQFPU0AoDlQ8zBrCVoDBKmaPOJ3vjWe0hM2DagBc1j5B0OeZN8KSARb2N P59cQD4I5fIncDShZtzJVofULUTwnibjgvLE/IbqcaLV+wP/gFy6VDJzoGz7pZkDZT/h 2NUg== X-Gm-Message-State: AFqh2kpw3pAc8fwrU/sHsZB1r5O7ZF/aHNdcgsJvmA7zY9CgYdVjiHO/ juBsFIXhQH5xYY2fCThAht+cTaEBxeFd X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8775:c864:37e:2f9b]) (user=irogers job=sendgmr) by 2002:a81:6954:0:b0:4b2:fa7c:8836 with SMTP id e81-20020a816954000000b004b2fa7c8836mr910044ywc.195.1672909351913; Thu, 05 Jan 2023 01:02:31 -0800 (PST) Date: Thu, 5 Jan 2023 01:01:55 -0800 In-Reply-To: <20230105090155.357604-1-irogers@google.com> Message-Id: <20230105090155.357604-4-irogers@google.com> Mime-Version: 1.0 References: <20230105090155.357604-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v3 3/3] objtool: Alter how HOSTCC is forced From: Ian Rogers <irogers@google.com> To: Josh Poimboeuf <jpoimboe@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, Masahiro Yamada <masahiroy@kernel.org>, Nicolas Schier <nicolas@fjasle.eu>, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Cc: Stephane Eranian <eranian@google.com>, Andrii Nakryiko <andrii@kernel.org>, Jiri Olsa <jolsa@kernel.org>, Arnaldo Carvalho de Melo <acme@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754172770889836620?= X-GMAIL-MSGID: =?utf-8?q?1754172770889836620?= |
Series |
objtool build improvements
|
|
Commit Message
Ian Rogers
Jan. 5, 2023, 9:01 a.m. UTC
HOSTCC is always wanted when building objtool. Setting CC to HOSTCC
happens after tools/scripts/Makefile.include is included, meaning
flags 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 CC to HOSTCC, just pass CC as HOSTCC to Makefile.build, the
libsubcmd builds and the linkage step. This means the Makefiles don't
see things like CC changing and tool flag determination, and similar,
work properly. To avoid mixing CFLAGS from different compilers just
the objtool CFLAGS are determined with the exception of
EXTRA_WARNINGS. HOSTCFLAGS is added to these so that command line
flags can add to the CFLAGS.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/objtool/Makefile | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
Comments
On Thu, Jan 5, 2023 at 1:02 AM Ian Rogers <irogers@google.com> wrote: > > HOSTCC is always wanted when building objtool. Setting CC to HOSTCC > happens after tools/scripts/Makefile.include is included, meaning > flags 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 CC to HOSTCC, just pass CC as HOSTCC to Makefile.build, the > libsubcmd builds and the linkage step. This means the Makefiles don't > see things like CC changing and tool flag determination, and similar, > work properly. To avoid mixing CFLAGS from different compilers just > the objtool CFLAGS are determined with the exception of > EXTRA_WARNINGS. HOSTCFLAGS is added to these so that command line > flags can add to the CFLAGS. > > Signed-off-by: Ian Rogers <irogers@google.com> Thanks Ian, and happy new year! Sorry for delays reviewing this; I'm just getting back online today. Assuming Peter and Josh may be too, otherwise can Peter or Josh PTAL? Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> (I'm happy that this allows me to now pass HOSTCFLAGS on to objtool successfully) > --- > tools/objtool/Makefile | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > index 61a00b7acae9..49956f4f58b9 100644 > --- a/tools/objtool/Makefile > +++ b/tools/objtool/Makefile > @@ -2,16 +2,12 @@ > 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))) > endif > > +MAKE = make -S > LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/ > ifneq ($(OUTPUT),) > LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd > @@ -37,12 +33,19 @@ INCLUDES := -I$(srctree)/tools/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) > +OBJTOOL_CFLAGS := -Werror $(WARNINGS) -g $(INCLUDES) $(LIBELF_FLAGS) $(HOSTCFLAGS) > +OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) > > # 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)" EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ > + LD="$(HOSTLD)" AR="$(HOSTAR)" > +BUILD_HOST_OVERRIDES := CC="$(HOSTCC)" CFLAGS="$(OBJTOOL_CFLAGS)" \ > + LD="$(HOSTLD)" LDFLAGS="$(OBJTOOL_LDFLAGS)" \ > + AR="$(HOSTAR)" > > AWK = awk > MKDIR = mkdir > @@ -65,10 +68,11 @@ include $(srctree)/tools/build/Makefile.include > > $(OBJTOOL_IN): fixdep FORCE > $(Q)$(CONFIG_SHELL) ./sync-check.sh > - $(Q)$(MAKE) $(build)=objtool > + $(Q)$(MAKE) $(build)=objtool $(BUILD_HOST_OVERRIDES) > + > > $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) > - $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ > + $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(KBUILD_HOSTLDFLAGS) $(OBJTOOL_LDFLAGS) -o $@ > > > $(LIBSUBCMD_OUTPUT): > @@ -77,6 +81,7 @@ $(LIBSUBCMD_OUTPUT): > $(LIBSUBCMD): fixdep FORCE $(LIBSUBCMD_OUTPUT) > $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \ > DESTDIR=$(LIBSUBCMD_DESTDIR) prefix= subdir= \ > + $(HOST_OVERRIDES) \ > $@ install_headers > > $(LIBSUBCMD)-clean: > -- > 2.39.0.314.g84b9a713c41-goog >
On Thu, Jan 05, 2023 at 01:01:55AM -0800 Ian Rogers wrote: > HOSTCC is always wanted when building objtool. Setting CC to HOSTCC > happens after tools/scripts/Makefile.include is included, meaning > flags 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 CC to HOSTCC, just pass CC as HOSTCC to Makefile.build, the > libsubcmd builds and the linkage step. This means the Makefiles don't > see things like CC changing and tool flag determination, and similar, > work properly. To avoid mixing CFLAGS from different compilers just > the objtool CFLAGS are determined with the exception of > EXTRA_WARNINGS. HOSTCFLAGS is added to these so that command line > flags can add to the CFLAGS. > > Signed-off-by: Ian Rogers <irogers@google.com> > --- > tools/objtool/Makefile | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
On Thu, Jan 05, 2023 at 01:01:55AM -0800, Ian Rogers wrote: > HOSTCC is always wanted when building objtool. Setting CC to HOSTCC > happens after tools/scripts/Makefile.include is included, meaning > flags 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 CC to HOSTCC, just pass CC as HOSTCC to Makefile.build, the > libsubcmd builds and the linkage step. This means the Makefiles don't > see things like CC changing and tool flag determination, and similar, > work properly. I'm having trouble parsing this last sentence, can you rephrase or restructure it? > To avoid mixing CFLAGS from different compilers just > the objtool CFLAGS are determined with the exception of > EXTRA_WARNINGS. I'm not really sure what this one means either. > HOSTCFLAGS is added to these so that command line > flags can add to the CFLAGS. Overall this patch description is a big wall of dense text which I found hard to decipher. Please split it up into paragraphs and make it more legible and logical. For example, un-jumble the ordering, with the background first, then the problem(s), then the fix(es). (At least three paragraphs) If possible, the subject should describe the end result for the user, something like objtool: Fix HOSTCFLAGS cmdline support ... unless I'm misunderstanding the point of the patch. HOSTCFLAGS from the cmdline *used* to work, a git bisect shows it stopped working with 96f14fe738b6 ("kbuild: Rename HOSTCFLAGS to KBUILD_HOSTCFLAGS") ... so please add a "Fixes" tag for that commit. > +MAKE = make -S Why? > LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/ > ifneq ($(OUTPUT),) > LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd > @@ -37,12 +33,19 @@ INCLUDES := -I$(srctree)/tools/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) > +OBJTOOL_CFLAGS := -Werror $(WARNINGS) -g $(INCLUDES) $(LIBELF_FLAGS) $(HOSTCFLAGS) I *think* I understand the reason for the switch from KBUILD_HOSTCFLAGS to HOSTCFLAGS -- because KBUILD_HOSTCFLAGS is defined in the top-level kernel Makefile which isn't included here so it's undefined? -- but regardless that should be called out more explicitly as a problem being fixed in the commit log. This issue really has me scratching my head, as I could have sworn objtool was being built with -O2. > +OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) Is there a reason to not include $(HOSTLDFLAGS) here? > # 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)" EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ > + LD="$(HOSTLD)" AR="$(HOSTAR)" > +BUILD_HOST_OVERRIDES := CC="$(HOSTCC)" CFLAGS="$(OBJTOOL_CFLAGS)" \ > + LD="$(HOSTLD)" LDFLAGS="$(OBJTOOL_LDFLAGS)" \ > + AR="$(HOSTAR)" Maybe it depends on your perspective, but I'm thinking that some of these aren't really overrides, but rather normal expected flags. And the distinction between these two variables is muddy: it's not only Build vs non-Build, but also objtool vs libsubcmd. How about just HOST_OVERRIDES := CC="$(HOSTCC) "LD="$(HOSTLD)" AR="$(HOSTAR)" And then specifying the {EXTRA_}CFLAGS and LDFLAGS below where needed. > AWK = awk > MKDIR = mkdir > @@ -65,10 +68,11 @@ include $(srctree)/tools/build/Makefile.include > > $(OBJTOOL_IN): fixdep FORCE > $(Q)$(CONFIG_SHELL) ./sync-check.sh > - $(Q)$(MAKE) $(build)=objtool > + $(Q)$(MAKE) $(build)=objtool $(BUILD_HOST_OVERRIDES) > + > > $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) > - $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ > + $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(KBUILD_HOSTLDFLAGS) $(OBJTOOL_LDFLAGS) -o $@ Does KBUILD_HOSTLDFLAGS even work here?
On Wed, Jan 25, 2023 at 5:49 PM Josh Poimboeuf <jpoimboe@kernel.org> wrote: > > On Thu, Jan 05, 2023 at 01:01:55AM -0800, Ian Rogers wrote: > > HOSTCC is always wanted when building objtool. Setting CC to HOSTCC > > happens after tools/scripts/Makefile.include is included, meaning > > flags 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 CC to HOSTCC, just pass CC as HOSTCC to Makefile.build, the > > libsubcmd builds and the linkage step. This means the Makefiles don't > > see things like CC changing and tool flag determination, and similar, > > work properly. > > I'm having trouble parsing this last sentence, can you rephrase or > restructure it? It was restating what was happening, deleted. > > To avoid mixing CFLAGS from different compilers just > > the objtool CFLAGS are determined with the exception of > > EXTRA_WARNINGS. > > I'm not really sure what this one means either. Moved to an inline comment. > > HOSTCFLAGS is added to these so that command line > > flags can add to the CFLAGS. > > Overall this patch description is a big wall of dense text which I found > hard to decipher. Please split it up into paragraphs and make it more > legible and logical. Yes, I've deleted most of the text now. I'd been adding to it as v1 went to v2 and so on. > For example, un-jumble the ordering, with the background first, then the > problem(s), then the fix(es). (At least three paragraphs) > > If possible, the subject should describe the end result for the user, > something like > > objtool: Fix HOSTCFLAGS cmdline support > > ... unless I'm misunderstanding the point of the patch. The patch is trying to fix the Makefile. Setting "CC=$(HOSTCC)" was just wrong as apparent from looking at the behavior of tools/scripts/Makefile.include. Some of that persists after this change with WARNINGS, as now noted in a comment. A side effect of fixing the Makefile is to make HOSTCFLAGS work, but I suspect with the variable renames this may not be working. I'll leave that for yourself and Nick. I told Nick I'd take a look at this as I saw the wrong use of libsubcmd's headers and that was something I wanted to clean up having done similar in tools/perf, along with the whole removal of tools/lib/traceevent from Linux 6.2. > HOSTCFLAGS from the cmdline *used* to work, a git bisect shows it > stopped working with > > 96f14fe738b6 ("kbuild: Rename HOSTCFLAGS to KBUILD_HOSTCFLAGS") > > ... so please add a "Fixes" tag for that commit. Left off, see later. > > +MAKE = make -S > > Why? Cruft, removed. > > LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/ > > ifneq ($(OUTPUT),) > > LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd > > @@ -37,12 +33,19 @@ INCLUDES := -I$(srctree)/tools/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) > > +OBJTOOL_CFLAGS := -Werror $(WARNINGS) -g $(INCLUDES) $(LIBELF_FLAGS) $(HOSTCFLAGS) > > I *think* I understand the reason for the switch from KBUILD_HOSTCFLAGS > to HOSTCFLAGS -- because KBUILD_HOSTCFLAGS is defined in the top-level > kernel Makefile which isn't included here so it's undefined? -- but > regardless that should be called out more explicitly as a problem being > fixed in the commit log. I was matching tools/perf, I've switched back to KBUILD_HOSTCFLAGS in v4. There's some higher logic at play with these variable names and I'm not aware of it so I'll leave it to be fixed if necessary later. > This issue really has me scratching my head, as I could have sworn > objtool was being built with -O2. > > > +OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) > > Is there a reason to not include $(HOSTLDFLAGS) here? Done as KBUILD_HOSTLDFLAGS as I don't see HOSTLDFLAGS set anywhere. > > # 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)" EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ > > + LD="$(HOSTLD)" AR="$(HOSTAR)" > > +BUILD_HOST_OVERRIDES := CC="$(HOSTCC)" CFLAGS="$(OBJTOOL_CFLAGS)" \ > > + LD="$(HOSTLD)" LDFLAGS="$(OBJTOOL_LDFLAGS)" \ > > + AR="$(HOSTAR)" > > Maybe it depends on your perspective, but I'm thinking that some of > these aren't really overrides, but rather normal expected flags. And > the distinction between these two variables is muddy: it's not only > Build vs non-Build, but also objtool vs libsubcmd. > > How about just > > HOST_OVERRIDES := CC="$(HOSTCC) "LD="$(HOSTLD)" AR="$(HOSTAR)" > > And then specifying the {EXTRA_}CFLAGS and LDFLAGS below where needed. Done. > > AWK = awk > > MKDIR = mkdir > > @@ -65,10 +68,11 @@ include $(srctree)/tools/build/Makefile.include > > > > $(OBJTOOL_IN): fixdep FORCE > > $(Q)$(CONFIG_SHELL) ./sync-check.sh > > - $(Q)$(MAKE) $(build)=objtool > > + $(Q)$(MAKE) $(build)=objtool $(BUILD_HOST_OVERRIDES) > > + > > > > $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) > > - $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ > > + $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(KBUILD_HOSTLDFLAGS) $(OBJTOOL_LDFLAGS) -o $@ > > Does KBUILD_HOSTLDFLAGS even work here? Removed, albeit now to be part of OBJTOOL_LDFLAGS as your earlier comment requested. Thanks, Ian > -- > Josh
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 61a00b7acae9..49956f4f58b9 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -2,16 +2,12 @@ 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))) endif +MAKE = make -S LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/ ifneq ($(OUTPUT),) LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd @@ -37,12 +33,19 @@ INCLUDES := -I$(srctree)/tools/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) +OBJTOOL_CFLAGS := -Werror $(WARNINGS) -g $(INCLUDES) $(LIBELF_FLAGS) $(HOSTCFLAGS) +OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) # 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)" EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \ + LD="$(HOSTLD)" AR="$(HOSTAR)" +BUILD_HOST_OVERRIDES := CC="$(HOSTCC)" CFLAGS="$(OBJTOOL_CFLAGS)" \ + LD="$(HOSTLD)" LDFLAGS="$(OBJTOOL_LDFLAGS)" \ + AR="$(HOSTAR)" AWK = awk MKDIR = mkdir @@ -65,10 +68,11 @@ include $(srctree)/tools/build/Makefile.include $(OBJTOOL_IN): fixdep FORCE $(Q)$(CONFIG_SHELL) ./sync-check.sh - $(Q)$(MAKE) $(build)=objtool + $(Q)$(MAKE) $(build)=objtool $(BUILD_HOST_OVERRIDES) + $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) - $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ + $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(KBUILD_HOSTLDFLAGS) $(OBJTOOL_LDFLAGS) -o $@ $(LIBSUBCMD_OUTPUT): @@ -77,6 +81,7 @@ $(LIBSUBCMD_OUTPUT): $(LIBSUBCMD): fixdep FORCE $(LIBSUBCMD_OUTPUT) $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \ DESTDIR=$(LIBSUBCMD_DESTDIR) prefix= subdir= \ + $(HOST_OVERRIDES) \ $@ install_headers $(LIBSUBCMD)-clean: