Message ID | 20230116215751.633675-2-irogers@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1423777wrn; Mon, 16 Jan 2023 14:08:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXs/Se8PkMsMzoC1pYToui/dFFY3MAZ+PEF0lcDcARcl7oHct+xPJqlqMAMnrn7mKerlqq6R X-Received: by 2002:a17:907:a506:b0:85b:9540:4ca7 with SMTP id vr6-20020a170907a50600b0085b95404ca7mr624868ejc.30.1673906894222; Mon, 16 Jan 2023 14:08:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673906894; cv=none; d=google.com; s=arc-20160816; b=N85WMkvEi7JZ9eYPSH3QUPIjeq/nnDRxzUQtuaLyIa90WupQ8/EnW2oWc/V2xXTcpQ 5kIEZg7V3y0w5imExtqUi5wd1ZKswllzKPaSIjFA3T0q8sAw9dXJMAauoya39j7Soj1X DU54RcG4yy8XteGtcXPGQG637qF+q1JBXw7fiL4sbjgVyYJR8wVg0SVV6PDVjlgXaDTb E7vVQkHkrd+HCsglK9g1vunxmDMEsKRwRSNoAqBDjRB2c6iMhNJDWCBGKYom6Sdf3fQY 4Byg3yowG/MaAFrbsf6tBgKU5qgR9HfBn2aGz1C/Huq8NUWIL1rZfOp5BxdH9EAd/b6k uFLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=im4HZCj7jcJlp9Gtkw1K/6eYSSab6dr0jizMwUKesmY=; b=oablweghx3HfUfyWSbX1PXStMrr4qZRSHy6LjytNDwIJrnwVPX8xBT6HCiSM3lcyOf y1QmJboen75is6KS86/L7HdcJhLnXWm2eozN7VBdIHp/K8zF6320CxmhYk8/6+HxK7Q5 MvP7+WVtTITZdWFBY7mRccTeM8krk/fsp/H8FZZzbF3o7Lz+UXjlhfS523olAri6Rylw EdOFRfyQCtBCgZO4sqO54BzfpQb966Vq5v2ah4NLgFbAYPx7hmNH29O0AeeFAkp3QfUm J2mCLPgwKdm61Hg1FPeSvIaGZ9CrigloblveumWNufPQXA03VzaomvA/U0YAvR1sNXf/ rcLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mFNK+1IL; 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 ae1-20020a17090725c100b007c4f78e610asi2286ejc.442.2023.01.16.14.07.50; Mon, 16 Jan 2023 14:08:14 -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=mFNK+1IL; 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 S234945AbjAPV6V (ORCPT <rfc822;stefanalexe802@gmail.com> + 99 others); Mon, 16 Jan 2023 16:58:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232686AbjAPV6T (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 16 Jan 2023 16:58:19 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DB842529A for <linux-kernel@vger.kernel.org>; Mon, 16 Jan 2023 13:58:18 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id f15-20020a62380f000000b0058db55a8d7aso1145183pfa.21 for <linux-kernel@vger.kernel.org>; Mon, 16 Jan 2023 13:58:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=im4HZCj7jcJlp9Gtkw1K/6eYSSab6dr0jizMwUKesmY=; b=mFNK+1ILDrtb/vjVJyN/aZBKd7qUO6uZIXxu8LzzcKGw5Ri7j+QgXk9p/PCz4MorJl EVMHWFmDbMz3lnAIez05n6KoU+vt1PA1OFfclqx2r5xJiiiy3D6noqryXHDQK4v1HAt4 VQciOtUsTwLOG3/WtnkGd+t4i4A2JNaA4xf9yK6RHDdCSMpQp0lxB4zgyP0BWz8QuPVl pPvriRmmAX+7PMhRdm7KgJibuKxi4ncRPl+T9e4VrToftfJfa2FTHjSWf00FtXH23slH 1HRnZBQUTZmWlQMGRADtdnzUH31FFhVQDHed3cdHNzAA4vRE/m/50h2bRr8hQ1wrPaU1 YRvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=im4HZCj7jcJlp9Gtkw1K/6eYSSab6dr0jizMwUKesmY=; b=tX77RIsIuZgLwPHcu2z1JL2zt8u0/3nwhBAK5YlukiZ226+9HYbo4nBYbCewA4KDHL NcmDZ86EkXB7uFGD08wPZlPWd/43GZvvm+z2mjmsKntb+42ckWwkbcLuzgiC82VTYseW r8NDY7S7wJa2hyVEOw91mZ9Y7vzecTyUMM2BMlzqAIVeycCa0PokHfyHi5Z/xi8LcKQU WFy3pemixX3q9MsWrNmE/mrkE8WcD6cAnZOMDOHediJYSH90kQ5jtxqUn6pS8otKeVzM dFAfCqA/eVEa46TeSBoxwkhixzFAMLrm4S+wC2suw2o4tYVRyLz9Mm2C5+IdnAv2gkU7 Y5uA== X-Gm-Message-State: AFqh2krOZ1rbQ2E0RCfcRXIXKqtrnbQ1/TLeEgbWQlS1jJ8G2Oov7ROv pKt/8xn9zFuBpf7bq+j3UXnLpg3ZjAuM X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5088:3695:f3a5:d639]) (user=irogers job=sendgmr) by 2002:a17:90a:408e:b0:229:2296:4be3 with SMTP id l14-20020a17090a408e00b0022922964be3mr81847pjg.5.1673906297579; Mon, 16 Jan 2023 13:58:17 -0800 (PST) Date: Mon, 16 Jan 2023 13:57:51 -0800 In-Reply-To: <20230116215751.633675-1-irogers@google.com> Message-Id: <20230116215751.633675-2-irogers@google.com> Mime-Version: 1.0 References: <20230116215751.633675-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v2 2/2] tools/resolve_btfids: Alter how HOSTCC is forced From: Ian Rogers <irogers@google.com> To: Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, Connor OBrien <connoro@google.com>, Nathan Chancellor <nathan@kernel.org>, Ian Rogers <irogers@google.com>, Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org, linux-kernel@vger.kernel.org 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?1755218595104021430?= X-GMAIL-MSGID: =?utf-8?q?1755218595104021430?= |
Series |
[v2,1/2] tools/resolve_btfids: Install subcmd headers
|
|
Commit Message
Ian Rogers
Jan. 16, 2023, 9:57 p.m. UTC
HOSTCC is always wanted when building. 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.
Also, clear the passed subdir as otherwise an outer build may break by
inadvertently passing an inappropriate value.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/bpf/resolve_btfids/Makefile | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
Comments
On Mon, Jan 16, 2023 at 01:57:51PM -0800, Ian Rogers wrote: > HOSTCC is always wanted when building. 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. > > Also, clear the passed subdir as otherwise an outer build may break by > inadvertently passing an inappropriate value. > > Signed-off-by: Ian Rogers <irogers@google.com> lgtm did you try cross build and build with clang? jirka > --- > tools/bpf/resolve_btfids/Makefile | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > index 76b737b2560d..515d87b32fb8 100644 > --- a/tools/bpf/resolve_btfids/Makefile > +++ b/tools/bpf/resolve_btfids/Makefile > @@ -18,14 +18,11 @@ else > endif > > # always use the host compiler > -AR = $(HOSTAR) > -CC = $(HOSTCC) > -LD = $(HOSTLD) > -ARCH = $(HOSTARCH) > +HOST_OVERRIDES := AR=$(HOSTAR) CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ > + ARCH=$(HOSTARCH) EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" > + > RM ?= rm > CROSS_COMPILE = > -CFLAGS := $(KBUILD_HOSTCFLAGS) > -LDFLAGS := $(KBUILD_HOSTLDFLAGS) > > OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ > > @@ -56,12 +53,12 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): > > $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd > $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ > - DESTDIR=$(SUBCMD_DESTDIR) prefix= \ > + DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) 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) prefix= EXTRA_CFLAGS="$(CFLAGS)" \ > + DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ > $(abspath $@) install_headers > > CFLAGS += -g \ > @@ -76,11 +73,11 @@ export srctree OUTPUT CFLAGS Q > include $(srctree)/tools/build/Makefile.include > > $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) > - $(Q)$(MAKE) $(build)=resolve_btfids > + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) > > $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) > $(call msg,LINK,$@) > - $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > + $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > clean_objects := $(wildcard $(OUTPUT)/*.o \ > $(OUTPUT)/.*.o.cmd \ > -- > 2.39.0.314.g84b9a713c41-goog >
On Tue, Jan 17, 2023 at 2:07 PM Jiri Olsa <olsajiri@gmail.com> wrote: > > On Mon, Jan 16, 2023 at 01:57:51PM -0800, Ian Rogers wrote: > > HOSTCC is always wanted when building. 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. > > > > Also, clear the passed subdir as otherwise an outer build may break by > > inadvertently passing an inappropriate value. > > > > Signed-off-by: Ian Rogers <irogers@google.com> > > lgtm did you try cross build and build with clang? Hmm.. I don't have a cross build but I checked clang. Any chance you could check the cross build? Thanks, Ian > jirka > > > --- > > tools/bpf/resolve_btfids/Makefile | 17 +++++++---------- > > 1 file changed, 7 insertions(+), 10 deletions(-) > > > > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > > index 76b737b2560d..515d87b32fb8 100644 > > --- a/tools/bpf/resolve_btfids/Makefile > > +++ b/tools/bpf/resolve_btfids/Makefile > > @@ -18,14 +18,11 @@ else > > endif > > > > # always use the host compiler > > -AR = $(HOSTAR) > > -CC = $(HOSTCC) > > -LD = $(HOSTLD) > > -ARCH = $(HOSTARCH) > > +HOST_OVERRIDES := AR=$(HOSTAR) CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ > > + ARCH=$(HOSTARCH) EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" > > + > > RM ?= rm > > CROSS_COMPILE = > > -CFLAGS := $(KBUILD_HOSTCFLAGS) > > -LDFLAGS := $(KBUILD_HOSTLDFLAGS) > > > > OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ > > > > @@ -56,12 +53,12 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): > > > > $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd > > $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ > > - DESTDIR=$(SUBCMD_DESTDIR) prefix= \ > > + DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) 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) prefix= EXTRA_CFLAGS="$(CFLAGS)" \ > > + DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ > > $(abspath $@) install_headers > > > > CFLAGS += -g \ > > @@ -76,11 +73,11 @@ export srctree OUTPUT CFLAGS Q > > include $(srctree)/tools/build/Makefile.include > > > > $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) > > - $(Q)$(MAKE) $(build)=resolve_btfids > > + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) > > > > $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) > > $(call msg,LINK,$@) > > - $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > + $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > > > clean_objects := $(wildcard $(OUTPUT)/*.o \ > > $(OUTPUT)/.*.o.cmd \ > > -- > > 2.39.0.314.g84b9a713c41-goog > >
On Tue, Jan 17, 2023 at 03:20:38PM -0800, Ian Rogers wrote: > On Tue, Jan 17, 2023 at 2:07 PM Jiri Olsa <olsajiri@gmail.com> wrote: > > > > On Mon, Jan 16, 2023 at 01:57:51PM -0800, Ian Rogers wrote: > > > HOSTCC is always wanted when building. 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. > > > > > > Also, clear the passed subdir as otherwise an outer build may break by > > > inadvertently passing an inappropriate value. > > > > > > Signed-off-by: Ian Rogers <irogers@google.com> > > > > lgtm did you try cross build and build with clang? > > Hmm.. I don't have a cross build but I checked clang. Any chance you > could check the cross build? ok, I'll try tomorrow jirka > > Thanks, > Ian > > > jirka > > > > > --- > > > tools/bpf/resolve_btfids/Makefile | 17 +++++++---------- > > > 1 file changed, 7 insertions(+), 10 deletions(-) > > > > > > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > > > index 76b737b2560d..515d87b32fb8 100644 > > > --- a/tools/bpf/resolve_btfids/Makefile > > > +++ b/tools/bpf/resolve_btfids/Makefile > > > @@ -18,14 +18,11 @@ else > > > endif > > > > > > # always use the host compiler > > > -AR = $(HOSTAR) > > > -CC = $(HOSTCC) > > > -LD = $(HOSTLD) > > > -ARCH = $(HOSTARCH) > > > +HOST_OVERRIDES := AR=$(HOSTAR) CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ > > > + ARCH=$(HOSTARCH) EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" > > > + > > > RM ?= rm > > > CROSS_COMPILE = > > > -CFLAGS := $(KBUILD_HOSTCFLAGS) > > > -LDFLAGS := $(KBUILD_HOSTLDFLAGS) > > > > > > OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ > > > > > > @@ -56,12 +53,12 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): > > > > > > $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd > > > $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ > > > - DESTDIR=$(SUBCMD_DESTDIR) prefix= \ > > > + DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) 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) prefix= EXTRA_CFLAGS="$(CFLAGS)" \ > > > + DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ > > > $(abspath $@) install_headers > > > > > > CFLAGS += -g \ > > > @@ -76,11 +73,11 @@ export srctree OUTPUT CFLAGS Q > > > include $(srctree)/tools/build/Makefile.include > > > > > > $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) > > > - $(Q)$(MAKE) $(build)=resolve_btfids > > > + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) > > > > > > $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) > > > $(call msg,LINK,$@) > > > - $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > > + $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > > > > > clean_objects := $(wildcard $(OUTPUT)/*.o \ > > > $(OUTPUT)/.*.o.cmd \ > > > -- > > > 2.39.0.314.g84b9a713c41-goog > > >
On Mon, Jan 16, 2023 at 01:57:51PM -0800, Ian Rogers wrote: > HOSTCC is always wanted when building. 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. > > Also, clear the passed subdir as otherwise an outer build may break by > inadvertently passing an inappropriate value. I tested with cross builds for s390/ppc/arm64 and it was ok some comments below thanks, jirka > > Signed-off-by: Ian Rogers <irogers@google.com> > --- > tools/bpf/resolve_btfids/Makefile | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > index 76b737b2560d..515d87b32fb8 100644 > --- a/tools/bpf/resolve_btfids/Makefile > +++ b/tools/bpf/resolve_btfids/Makefile > @@ -18,14 +18,11 @@ else > endif > > # always use the host compiler > -AR = $(HOSTAR) > -CC = $(HOSTCC) > -LD = $(HOSTLD) > -ARCH = $(HOSTARCH) I wonder all the tools should use HOSTCC in the first place? seems more clear than forcing it from other makefiles subcmd even has: CC ?= $(CROSS_COMPILE)gcc LD ?= $(CROSS_COMPILE)ld AR ?= $(CROSS_COMPILE)ar which seems wrong unless I'm missing something.. should be always the host compiler, right? > +HOST_OVERRIDES := AR=$(HOSTAR) CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ > + ARCH=$(HOSTARCH) EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" there's extra AR set and ARCH value is not in "" > + > RM ?= rm > CROSS_COMPILE = > -CFLAGS := $(KBUILD_HOSTCFLAGS) > -LDFLAGS := $(KBUILD_HOSTLDFLAGS) > > OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ > > @@ -56,12 +53,12 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): > > $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd > $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ > - DESTDIR=$(SUBCMD_DESTDIR) prefix= \ > + DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) 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) prefix= EXTRA_CFLAGS="$(CFLAGS)" \ > + DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ > $(abspath $@) install_headers > > CFLAGS += -g \ > @@ -76,11 +73,11 @@ export srctree OUTPUT CFLAGS Q > include $(srctree)/tools/build/Makefile.include > > $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) > - $(Q)$(MAKE) $(build)=resolve_btfids > + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) > > $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) > $(call msg,LINK,$@) > - $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > + $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > clean_objects := $(wildcard $(OUTPUT)/*.o \ > $(OUTPUT)/.*.o.cmd \ > -- > 2.39.0.314.g84b9a713c41-goog >
On Thu, Jan 19, 2023 at 6:51 AM Jiri Olsa <olsajiri@gmail.com> wrote: > > On Mon, Jan 16, 2023 at 01:57:51PM -0800, Ian Rogers wrote: > > HOSTCC is always wanted when building. 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. > > > > Also, clear the passed subdir as otherwise an outer build may break by > > inadvertently passing an inappropriate value. > > I tested with cross builds for s390/ppc/arm64 and it was ok > > some comments below > > thanks, > jirka > > > > > > Signed-off-by: Ian Rogers <irogers@google.com> > > --- > > tools/bpf/resolve_btfids/Makefile | 17 +++++++---------- > > 1 file changed, 7 insertions(+), 10 deletions(-) > > > > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > > index 76b737b2560d..515d87b32fb8 100644 > > --- a/tools/bpf/resolve_btfids/Makefile > > +++ b/tools/bpf/resolve_btfids/Makefile > > @@ -18,14 +18,11 @@ else > > endif > > > > # always use the host compiler > > -AR = $(HOSTAR) > > -CC = $(HOSTCC) > > -LD = $(HOSTLD) > > -ARCH = $(HOSTARCH) > > I wonder all the tools should use HOSTCC in the first place? > seems more clear than forcing it from other makefiles > > subcmd even has: > > CC ?= $(CROSS_COMPILE)gcc > LD ?= $(CROSS_COMPILE)ld > AR ?= $(CROSS_COMPILE)ar > > which seems wrong unless I'm missing something.. should be always > the host compiler, right? Hmm.. it seems like a feature to be able to cross compile things like the perf tool. I agree the way this is all done is muddling and we should try to keep the way it is done consistent. The pattern of always early including Makefile.include, that sets flags based on CC, but then overriding CC was what I was after cleaning up here. Let's work on migrating to something better. > > +HOST_OVERRIDES := AR=$(HOSTAR) CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ > > + ARCH=$(HOSTARCH) EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" > > there's extra AR set and ARCH value is not in "" Ack. Will fix in v3. Thanks, Ian > > + > > RM ?= rm > > CROSS_COMPILE = > > -CFLAGS := $(KBUILD_HOSTCFLAGS) > > -LDFLAGS := $(KBUILD_HOSTLDFLAGS) > > > > OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ > > > > @@ -56,12 +53,12 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): > > > > $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd > > $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ > > - DESTDIR=$(SUBCMD_DESTDIR) prefix= \ > > + DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) 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) prefix= EXTRA_CFLAGS="$(CFLAGS)" \ > > + DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ > > $(abspath $@) install_headers > > > > CFLAGS += -g \ > > @@ -76,11 +73,11 @@ export srctree OUTPUT CFLAGS Q > > include $(srctree)/tools/build/Makefile.include > > > > $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) > > - $(Q)$(MAKE) $(build)=resolve_btfids > > + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) > > > > $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) > > $(call msg,LINK,$@) > > - $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > + $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) > > > > clean_objects := $(wildcard $(OUTPUT)/*.o \ > > $(OUTPUT)/.*.o.cmd \ > > -- > > 2.39.0.314.g84b9a713c41-goog > >
diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile index 76b737b2560d..515d87b32fb8 100644 --- a/tools/bpf/resolve_btfids/Makefile +++ b/tools/bpf/resolve_btfids/Makefile @@ -18,14 +18,11 @@ else endif # always use the host compiler -AR = $(HOSTAR) -CC = $(HOSTCC) -LD = $(HOSTLD) -ARCH = $(HOSTARCH) +HOST_OVERRIDES := AR=$(HOSTAR) CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ + ARCH=$(HOSTARCH) EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)" + RM ?= rm CROSS_COMPILE = -CFLAGS := $(KBUILD_HOSTCFLAGS) -LDFLAGS := $(KBUILD_HOSTLDFLAGS) OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ @@ -56,12 +53,12 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ - DESTDIR=$(SUBCMD_DESTDIR) prefix= \ + DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) 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) prefix= EXTRA_CFLAGS="$(CFLAGS)" \ + DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ $(abspath $@) install_headers CFLAGS += -g \ @@ -76,11 +73,11 @@ export srctree OUTPUT CFLAGS Q include $(srctree)/tools/build/Makefile.include $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) - $(Q)$(MAKE) $(build)=resolve_btfids + $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES) $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) $(call msg,LINK,$@) - $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) + $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) clean_objects := $(wildcard $(OUTPUT)/*.o \ $(OUTPUT)/.*.o.cmd \