From patchwork Thu Nov 17 22:03:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 21962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp650157wrr; Thu, 17 Nov 2022 14:17:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf6TWnhEl9GLAfj376ZS0TUcCVPznbezgi2lqPu3zXSuAPViZ4tQtb3DSvHSEHxKTGirX7dO X-Received: by 2002:aa7:d358:0:b0:467:6847:1ea7 with SMTP id m24-20020aa7d358000000b0046768471ea7mr3857479edr.237.1668723478122; Thu, 17 Nov 2022 14:17:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668723478; cv=none; d=google.com; s=arc-20160816; b=GLwP4Kdi2+h5/2ZEf2KZ0yICh6nAWI0aRhS851Q4E72F/96Qo5X3qBbtFBYAioBkOe vJyHEdj9eOfLwRMc+civGEGznql46VfTBvUkQWbwBr/O4l/63Vc7umd2n6dxPeIvZYuj 9q/hI4tKhM/aYTFKkiE0erRyDm2V/IebhAEXehVA+9K+y/osO0NsNAycB/EsuoNsiADV cg/9hd+c7IgwMFFqr+G6ycU+a7uIVOmD5RLHFwa5OgLASmIJ+FLk4yd8voOKOfwmoAOA dFoTY2NtynjWWa/gD75TGDc5opLH12/DUdozx1qLdaIZrBG9pWI/kPeC7eg29pMaS0+t GhIg== 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=E/8tcV65NVEwS5qyaLKJ1YnmWVyteYUi8du6gRZPUlk=; b=NIXhns52+o7nq07kHS3qHiuK2DZZ7C49TbIxDdIhSEG8oBckW65zRmD+N0BOswGVCj QiXKxuXEOSxnzw8h+jk5jpjxLD9h5bVwQPoWF8NS+drdcXRQ1OokYg0ZDjbHkuEXkYy4 eeWyxQJNJ6OiOMsCA/mTG137BgkoqHBpq/ngpnDNyKuk8BUf/mnU4NMu0aBvMbEtUs0m oxqWyao06NfbdDzct90lovd82zo+kQyDfL1P5E38igdWJ2rPtcw4DwNu7jDbibjOfmDc FLIrRrdUF4AZibfF3DJVJJ5Rw1tu2ztDM7q8GLSULRCjFpeKTEyMvm2jc5Iw4MYHMNeY jgaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Kgx6EoNM; 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 be1-20020a1709070a4100b0078def5c29e3si1681774ejc.596.2022.11.17.14.17.28; Thu, 17 Nov 2022 14:17:58 -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=Kgx6EoNM; 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 S241062AbiKQWF6 (ORCPT + 99 others); Thu, 17 Nov 2022 17:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235118AbiKQWFX (ORCPT ); Thu, 17 Nov 2022 17:05:23 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B03D7211D for ; Thu, 17 Nov 2022 14:04:12 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id f126-20020a255184000000b006cb2aebd124so2788001ybb.11 for ; Thu, 17 Nov 2022 14:04: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=E/8tcV65NVEwS5qyaLKJ1YnmWVyteYUi8du6gRZPUlk=; b=Kgx6EoNMCudu+OzIdeTfFZaqIVftUAqRW1zo0L+decJ8pEy4/MJC04RnVF7B3KaSZ0 9DK6SxFeAkYNS2w805K2pZXeMVzoTc9+n6i2fomVEFwYh2ahmKGbpB2ptalb+xwgnM+v 1ylGsq+GKD4GqKY+1TF2ywPbbApmanEIDMq5tcF3WNAgugTiNNfif10EuJfPJgvXpQ6G 7DeyxMVQCZjmmpaJM90lNPVsHLhy/uLYINj6B+GbWvdd6u1xI+83ksDlrJ5xrJCL4O8O iQDbVQKNrBr/EN9pK3y4nLsiMZ4yZ/q7eFSymuqkuEkcNrP8HCciHbuAMrDf+BvQnlM4 /3AA== 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=E/8tcV65NVEwS5qyaLKJ1YnmWVyteYUi8du6gRZPUlk=; b=n8o8BDgVKTDWb2dUfxAvYCpOXe6MGUYEfofVjrKRjoN+2PTsRNPGXu7+6G7WlrbmVa P9CMj1UFqOz0PrIa/MyFwmPgf8O5ZsRPsNdrMCpQ37r0Zm958ViPN23BWuG1f/PsziRg Z2z/OpUIRf2/h/vGdPV7YuZhYbMxjYHQwW1dynA2hKVW9NPj4XQmGjruFmF9chiHh0i1 WGXaT6bGbYaPrfCRAorL+NWTRsm1It8HBQcdYxSAxCb8M0MxmExEVLxeZuvMaYG0Xqcd BVH3Lx4wwDFPgIqYD+9b0hEdDSWkYP1uSjtgyMVGqroKhHjG44znTDTWniSmvFcLxQJD o8Eg== X-Gm-Message-State: ANoB5pn2fo6HeOYhKfYJhHf946+ikm9e5APyrTrMcK0CF41TjtH3tmMQ S+hyRx0dJcC2M6GujVfxtz2lyu8kFcyu X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3f1e:c462:d6b8:fba8]) (user=irogers job=sendgmr) by 2002:a81:5d5:0:b0:36a:d4df:c6b6 with SMTP id 204-20020a8105d5000000b0036ad4dfc6b6mr3879537ywf.18.1668722651796; Thu, 17 Nov 2022 14:04:11 -0800 (PST) Date: Thu, 17 Nov 2022 14:03:39 -0800 In-Reply-To: <20221117220339.341290-1-irogers@google.com> Message-Id: <20221117220339.341290-4-irogers@google.com> Mime-Version: 1.0 References: <20221117220339.341290-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Subject: [PATCH v1 3/3] objtool: Alter how HOSTCC is forced From: Ian Rogers To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Cc: Stephane Eranian , Andrii Nakryiko , Jiri Olsa , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749783389999591782?= X-GMAIL-MSGID: =?utf-8?q?1749783389999591782?= 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 --- tools/objtool/Makefile | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 6b6c20ba5160..c9992d73617f 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 ' | $(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= \ + $(HOST_OVERRIDES) \ $@ install_headers $(LIBSUBCMD)-clean: