Message ID | 20221122001125.765003-5-irogers@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1919232wrr; Mon, 21 Nov 2022 16:38:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf5sYfTe6Ce9CTBWiQM6QcgTyDwo3p8pNQvIWMMJQMKv8PLDV1ZZyvzRzIBSQcLFJzciIkxw X-Received: by 2002:a17:906:830d:b0:79e:5ea1:4f83 with SMTP id j13-20020a170906830d00b0079e5ea14f83mr4046507ejx.372.1669077523614; Mon, 21 Nov 2022 16:38:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669077523; cv=none; d=google.com; s=arc-20160816; b=hklneLz8JJvtJhkKgNJajM9b0VBIY92uri0lKFcP7BSuKUF4+cpc0XmohTsNKxyKFo 1B/xRw/FMDJv94dxVSJ1vg1Q81w6ImPjUIfVm+IEHXjslL86ZTPCBQFnLYvhLt/DG4JT CfndAjhJuzbUL3PByIjfkLqVvOQ2h5z5TX7SYXb/HR8Kuc4yJG+oK/sz6OVyYF3Aaeu0 yb4iKgc6B6d+IQyHqhBQuSrmX/yKGBLokBKM2BMXTq2HGsE//4SktBVxPdA/tUqfApWp 6HWA5PHdi2Rwob++xt+wGDkLZKknIR5XllrZ3YsRErXtgmhcC3coRLlQtjMq2uMFLFOy b8uA== 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=f2OEVX8RYPyAcopuDfdaWLt0cg7xaISJPygwT0E0ouc=; b=TXJc6rnA4PESoruya/7HBNWRUjBZgZRpcr/GeWJ68OcBMsAdm5oSr56W/sv42BesX6 p3Iml+eVPNTSmo1Msr0U/iG5BGoi16oFbyQEu8G2gfvehY10Dq9NsnJAVryj4xsrYM0n 6OI8QMJGnZjAWiWOYgwQLlTuPEB4OybGoACElmnngKzfdwJ/4pGGmNsKzcfGw3mVRGKa DZLpufUSr5RfloyZtXa9iAqezn/WF++Dr4/kzgw9SNQPQb4ld5Outc/dSx764m9IRpZP FlEjLhwR+cY4aFDJF144can48ClyeLpxnE8UOOgnGQOcmmT0VJGaSO+nM3BhWcKrK1UG xFgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=c4MiccdF; 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 b6-20020a056402350600b00459f9c3d02bsi11221326edd.22.2022.11.21.16.38.20; Mon, 21 Nov 2022 16:38:43 -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=c4MiccdF; 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 S232131AbiKVAMx (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Mon, 21 Nov 2022 19:12:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232163AbiKVAMP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 21 Nov 2022 19:12:15 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89CD4B7EBA for <linux-kernel@vger.kernel.org>; Mon, 21 Nov 2022 16:12:12 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-352e29ff8c2so128265417b3.21 for <linux-kernel@vger.kernel.org>; Mon, 21 Nov 2022 16:12:12 -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=f2OEVX8RYPyAcopuDfdaWLt0cg7xaISJPygwT0E0ouc=; b=c4MiccdF0m/dJ6gtmkt+leDsOcrSbyKkmprTSa4NTl6g3KAnmRAuF+gGso2easyZsV FnnkY2OmhIJN4f2BPS0ybe5jTSitq97A6wqCQKnrQFSfSYi2zSLGqRV1VY9kDsvqoP2R t7vrJ0f66IXcQXWLOe03yZNMU4fE8eO1zdHeOlGgNEGBe+TNLpWksnss3EZ6dw5crZh1 gZplgnn9sPsj3eomSopOQzM21GLPpdCGWhE8wt8wWd30fGqgGk1Ez78i9ETM/bve4hbZ NYmLcH2qQd6Co5l6aHL5H7Qkns5w5OP9pjxxeoqiSG1Qbl0VgAM0kCgmBYat/D1EGHzn 5h0w== 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=f2OEVX8RYPyAcopuDfdaWLt0cg7xaISJPygwT0E0ouc=; b=rVGn/FUB86yaye5dFFNC3UtWeWgWJRqkwZziSZ/uImmEZKHLLBZog2olLqeh3n3oxH YHGuYVsuXAwiCpMkht0KZ3NnyVIO+bhIb9xH8ZiYw+d0CjiD8UKmSGgLb9IcpQN8oTqF /hRtekxdnTLqJasRzHZII3ruB1iIFfynV3Vk/l/4Qcptb9Au/1pbdcTp6rW3uDeK9wnw PuZBcrFVlTzKnXVdosWSz0/eEHNflQjA+6jW8Iqghu2YBLtObOUrMV8X1qeVU0HrnET3 qDjDqk258HmhAtQU/0zzCrZF7YZX5jXSGO4I+IwEXHgZjP19EFhyuoiIG/Pr8NJ6HGKR +v4w== X-Gm-Message-State: ANoB5pnvj/b2AQkFFg9vHnxg/b11tXT//9zOO7FNT3b94TP1EKOeuUQ6 MVPSJi0a2UwbzrB2V6VV8LVEhYkEOy7R X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:2107:a1f5:8582:5608]) (user=irogers job=sendgmr) by 2002:a81:25d8:0:b0:373:4467:e0c6 with SMTP id l207-20020a8125d8000000b003734467e0c6mr1500249ywl.340.1669075931876; Mon, 21 Nov 2022 16:12:11 -0800 (PST) Date: Mon, 21 Nov 2022 16:11:25 -0800 In-Reply-To: <20221122001125.765003-1-irogers@google.com> Message-Id: <20221122001125.765003-5-irogers@google.com> Mime-Version: 1.0 References: <20221122001125.765003-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Subject: [PATCH v2 4/4] 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?1750154633500836350?= X-GMAIL-MSGID: =?utf-8?q?1750154633500836350?= |
Series |
objtool build improvements
|
|
Commit Message
Ian Rogers
Nov. 22, 2022, 12:11 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. 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 | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
Comments
On Mon, Nov 21, 2022 at 4:12 PM 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. 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 | 27 ++++++++++++++++----------- > 1 file changed, 16 insertions(+), 11 deletions(-) > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > index 61a00b7acae9..e550a98e2dd9 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 > @@ -36,13 +32,20 @@ INCLUDES := -I$(srctree)/tools/include \ > -I$(srctree)/tools/objtool/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 Looking closer at the V=1 diff in meld, I think this is dropping EXTRA_WARNINGS. I think you want to add those back to OBJTOOL_CFLAGS. > -CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) > -LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > +WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs > +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.38.1.584.g0f3c55d4c2-goog >
On Fri, Dec 9, 2022 at 10:26 AM Nick Desaulniers <ndesaulniers@google.com> wrote: > > On Mon, Nov 21, 2022 at 4:12 PM 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. 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 | 27 ++++++++++++++++----------- > > 1 file changed, 16 insertions(+), 11 deletions(-) > > > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > > index 61a00b7acae9..e550a98e2dd9 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 > > @@ -36,13 +32,20 @@ INCLUDES := -I$(srctree)/tools/include \ > > -I$(srctree)/tools/objtool/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 > > Looking closer at the V=1 diff in meld, I think this is dropping > EXTRA_WARNINGS. I think you want to add those back to OBJTOOL_CFLAGS. Thanks Nick! When I try this it causes new build failures. Specifically EXTRA_WARNINGS includes things like -Wswitch-enum that trigger: ``` check.c:1312:10: error: 14 enumeration values not explicitly handled in switch: 'INSN_JUMP_DYNAMIC', 'INSN_JUMP_DYNAMIC_CONDITIONAL', 'INSN_CALL_DYNAMIC'... [-Werror,-Wswitch-enum] switch (insn->type) { ^~~~~~~~~~ check.c:2620:11: error: enumeration value 'OP_SRC_CONST' not explicitly handled in switch [-Werror,- Wswitch-enum] switch (op->src.type) { ^~~~~~~~~~~~ check.c:3447:11: error: 5 enumeration values not explicitly handled in switch: 'INSN_BUG', 'INSN_NOP ', 'INSN_TRAP'... [-Werror,-Wswitch-enum] switch (insn->type) { ^~~~~~~~~~ check.c:3647:11: error: 9 enumeration values not explicitly handled in switch: 'INSN_CONTEXT_SWITCH' , 'INSN_BUG', 'INSN_STAC'... [-Werror,-Wswitch-enum] switch (insn->type) { ^~~~~~~~~~ check.c:4008:10: error: 9 enumeration values not explicitly handled in switch: 'INSN_CONTEXT_SWITCH' , 'INSN_BUG', 'INSN_STAC'... [-Werror,-Wswitch-enum] switch (insn->type) { ^~~~~~~~~~ check.c:4173:11: error: 15 enumeration values not explicitly handled in switch: 'INSN_JUMP_CONDITION AL', 'INSN_JUMP_UNCONDITIONAL', 'INSN_JUMP_DYNAMIC_CONDITIONAL'... [-Werror,-Wswitch-enum] switch (insn->type) { ^~~~~~~~~~ 6 errors generated. ``` What should the next step be? Land this or add EXTRA_WARNINGS and fix all the issues? Thanks, Ian > > -CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) > > -LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > > +WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs > > +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.38.1.584.g0f3c55d4c2-goog > > > > > -- > Thanks, > ~Nick Desaulniers
On Wed, Dec 14, 2022 at 10:25 AM Ian Rogers <irogers@google.com> wrote: > > On Fri, Dec 9, 2022 at 10:26 AM Nick Desaulniers > <ndesaulniers@google.com> wrote: > > > > On Mon, Nov 21, 2022 at 4:12 PM 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. 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 | 27 ++++++++++++++++----------- > > > 1 file changed, 16 insertions(+), 11 deletions(-) > > > > > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > > > index 61a00b7acae9..e550a98e2dd9 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 > > > @@ -36,13 +32,20 @@ INCLUDES := -I$(srctree)/tools/include \ > > > -I$(srctree)/tools/objtool/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 > > > > Looking closer at the V=1 diff in meld, I think this is dropping > > EXTRA_WARNINGS. I think you want to add those back to OBJTOOL_CFLAGS. > > Thanks Nick! When I try this it causes new build failures. > Specifically EXTRA_WARNINGS includes things like -Wswitch-enum that > trigger: That's...unexpected. These warnings didn't exist when EXTRA_WARNINGS was being passed to the compiler for these...unless that wasn't the case? > > ``` > check.c:1312:10: error: 14 enumeration values not explicitly handled > in switch: 'INSN_JUMP_DYNAMIC', > 'INSN_JUMP_DYNAMIC_CONDITIONAL', 'INSN_CALL_DYNAMIC'... [-Werror,-Wswitch-enum] > switch (insn->type) { > ^~~~~~~~~~ > check.c:2620:11: error: enumeration value 'OP_SRC_CONST' not > explicitly handled in switch [-Werror,- > Wswitch-enum] > switch (op->src.type) { > ^~~~~~~~~~~~ > check.c:3447:11: error: 5 enumeration values not explicitly handled in > switch: 'INSN_BUG', 'INSN_NOP > ', 'INSN_TRAP'... [-Werror,-Wswitch-enum] > switch (insn->type) { > ^~~~~~~~~~ > check.c:3647:11: error: 9 enumeration values not explicitly handled in > switch: 'INSN_CONTEXT_SWITCH' > , 'INSN_BUG', 'INSN_STAC'... [-Werror,-Wswitch-enum] > switch (insn->type) { > ^~~~~~~~~~ > check.c:4008:10: error: 9 enumeration values not explicitly handled in > switch: 'INSN_CONTEXT_SWITCH' > , 'INSN_BUG', 'INSN_STAC'... [-Werror,-Wswitch-enum] > switch (insn->type) { > ^~~~~~~~~~ > check.c:4173:11: error: 15 enumeration values not explicitly handled > in switch: 'INSN_JUMP_CONDITION > AL', 'INSN_JUMP_UNCONDITIONAL', 'INSN_JUMP_DYNAMIC_CONDITIONAL'... > [-Werror,-Wswitch-enum] > switch (insn->type) { > ^~~~~~~~~~ > 6 errors generated. > ``` > > What should the next step be? Land this or add EXTRA_WARNINGS and fix > all the issues? Up to Josh. I think the first 3 patches are ready to go. > > Thanks, > Ian > > > > -CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) > > > -LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > > > +WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs > > > +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.38.1.584.g0f3c55d4c2-goog > > > > > > > > > -- > > Thanks, > > ~Nick Desaulniers
On Wed, Dec 14, 2022 at 10:34 AM Nick Desaulniers <ndesaulniers@google.com> wrote: > > On Wed, Dec 14, 2022 at 10:25 AM Ian Rogers <irogers@google.com> wrote: > > > > On Fri, Dec 9, 2022 at 10:26 AM Nick Desaulniers > > <ndesaulniers@google.com> wrote: > > > > > > On Mon, Nov 21, 2022 at 4:12 PM 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. 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 | 27 ++++++++++++++++----------- > > > > 1 file changed, 16 insertions(+), 11 deletions(-) > > > > > > > > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > > > > index 61a00b7acae9..e550a98e2dd9 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 > > > > @@ -36,13 +32,20 @@ INCLUDES := -I$(srctree)/tools/include \ > > > > -I$(srctree)/tools/objtool/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 > > > > > > Looking closer at the V=1 diff in meld, I think this is dropping > > > EXTRA_WARNINGS. I think you want to add those back to OBJTOOL_CFLAGS. > > > > Thanks Nick! When I try this it causes new build failures. > > Specifically EXTRA_WARNINGS includes things like -Wswitch-enum that > > trigger: > > That's...unexpected. These warnings didn't exist when EXTRA_WARNINGS > was being passed to the compiler for these...unless that wasn't the > case? I wasn't adding EXTRA_WARNINGS but they are set up here: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/tools/scripts/Makefile.include?id=630ae80ea1dd253609cb50cff87f3248f901aca3#n23 I've avoided in these changes passing through values from Makefile.include to the subprocesses, like Makefile.build, as Makefile.include makes choices based on the current flags like clang and llvm, not those we override. > > > > ``` > > check.c:1312:10: error: 14 enumeration values not explicitly handled > > in switch: 'INSN_JUMP_DYNAMIC', > > 'INSN_JUMP_DYNAMIC_CONDITIONAL', 'INSN_CALL_DYNAMIC'... [-Werror,-Wswitch-enum] > > switch (insn->type) { > > ^~~~~~~~~~ > > check.c:2620:11: error: enumeration value 'OP_SRC_CONST' not > > explicitly handled in switch [-Werror,- > > Wswitch-enum] > > switch (op->src.type) { > > ^~~~~~~~~~~~ > > check.c:3447:11: error: 5 enumeration values not explicitly handled in > > switch: 'INSN_BUG', 'INSN_NOP > > ', 'INSN_TRAP'... [-Werror,-Wswitch-enum] > > switch (insn->type) { > > ^~~~~~~~~~ > > check.c:3647:11: error: 9 enumeration values not explicitly handled in > > switch: 'INSN_CONTEXT_SWITCH' > > , 'INSN_BUG', 'INSN_STAC'... [-Werror,-Wswitch-enum] > > switch (insn->type) { > > ^~~~~~~~~~ > > check.c:4008:10: error: 9 enumeration values not explicitly handled in > > switch: 'INSN_CONTEXT_SWITCH' > > , 'INSN_BUG', 'INSN_STAC'... [-Werror,-Wswitch-enum] > > switch (insn->type) { > > ^~~~~~~~~~ > > check.c:4173:11: error: 15 enumeration values not explicitly handled > > in switch: 'INSN_JUMP_CONDITION > > AL', 'INSN_JUMP_UNCONDITIONAL', 'INSN_JUMP_DYNAMIC_CONDITIONAL'... > > [-Werror,-Wswitch-enum] > > switch (insn->type) { > > ^~~~~~~~~~ > > 6 errors generated. > > ``` > > > > What should the next step be? Land this or add EXTRA_WARNINGS and fix > > all the issues? > > Up to Josh. I think the first 3 patches are ready to go. Note, the first patch is already in Arnaldo's tree: https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=630ae80ea1dd253609cb50cff87f3248f901aca3 and shows up in linux-next: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/tools/lib/subcmd/Makefile?id=630ae80ea1dd253609cb50cff87f3248f901aca3 Thanks, Ian > > > > Thanks, > > Ian > > > > > > -CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) > > > > -LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) > > > > +WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs > > > > +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.38.1.584.g0f3c55d4c2-goog > > > > > > > > > > > > > -- > > > Thanks, > > > ~Nick Desaulniers > > > > -- > Thanks, > ~Nick Desaulniers
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 61a00b7acae9..e550a98e2dd9 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 @@ -36,13 +32,20 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/objtool/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) +WARNINGS := -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs +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: