Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp217473rdb; Thu, 2 Nov 2023 01:14:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCKmnHpyQx1d7V4YoXYl+6w6Q8ZKes4RpGSQqI9BrV6I4YISfjke7KxTcolOTBMQkYc65z X-Received: by 2002:a17:903:22cc:b0:1cc:6acc:8fa0 with SMTP id y12-20020a17090322cc00b001cc6acc8fa0mr8144975plg.34.1698912894440; Thu, 02 Nov 2023 01:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698912894; cv=none; d=google.com; s=arc-20160816; b=dBnrQrJXPOelvaumicxAdM3SUV9j99SEUNH3QA/oeWFQcXvjgvr6UsAs5wJMb4mpxe NSP0IW3K/GGGQF3aQuZOOMAd87yMIkuNhiPwhfWisaFXb+fowIwyBoY0ajpQ9bXnmHcA m8JfTYgt/JMmAQxq2qTmtfWBjSbkr9I1cBjq1TqTE5d6NO0o446BlG4zrLzg2ejoEvbW aW9AQp4XAijTnsYBj7ZnySmU90ux6gfSH5JnhH/2226Vdh2g7yIh+hz8E4CsO9gLKPya U38vA5gErsRPSn+CRhiL9PF34RA1ujtVJhlUCVZhAnty1/Lcr5AKW/4FfBb5MFpjraZN QdBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pv/u/VY8koj0/SavWgJd9y0AOXSVXh6czN+ADLVaU8A=; fh=q/tduS2xRvPhRWto0R0CECR58FYg6pu7PnNDCwNOTeY=; b=sy8SeMr1dulIP0g0tbEoa4RefegxD2TxqEfMmfsA6qGNugpR4ME3UtUbLni7sdNokT 42ztj4hB8ZLMrVSrrj/i4HYBCWGNT9m/mQWtAEtWC5Ls05hugs1dze766Wf2YOxKkuH/ Q+Piejw9AcgHDk2KI0/hgEcTTNA/QvbJ5kmINk+76hJwNV0mWJe8cijrjOnqLDgF7Zux QZIyf8+JPj3Q9lMdMpqwxP16t6lVpUNwUvSNdmFqA2QBw8CrPLmy57ZPKjJjWr9OH5Kb x2pWEAnAVUOHwqLUaXgSN1OZ6QTb9IzMdbinmuDSmSo8WBOhnK7RblsQo57wsUpqBENQ LbRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i0fWTcXq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u14-20020a170903124e00b001cc385b457asi1068683plh.284.2023.11.02.01.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 01:14:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i0fWTcXq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 843558206D40; Thu, 2 Nov 2023 01:14:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234692AbjKBIOw (ORCPT + 99 others); Thu, 2 Nov 2023 04:14:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjKBIOv (ORCPT ); Thu, 2 Nov 2023 04:14:51 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C98F111 for ; Thu, 2 Nov 2023 01:14:48 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 803BBC433C7; Thu, 2 Nov 2023 08:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698912887; bh=tiXEfTZttWH1SdiJ40AhKXNpvZdi+JYLQ+nsEljGkoY=; h=From:To:Cc:Subject:Date:From; b=i0fWTcXqs2ifq5uASjhrMQKnyMRZwOvqHkc8kPB2wkvMze3aA/SDGIJqeIbFpxJRD hlsijQnIlQggyDVYYpLtwV5OYLzr59q0jNxEPCK9itOX/ilKJX7m9/uNYmy8iRjkHT vy9sOcvX6jTEonUFKeyNWGzEHxXba/zA6lcW+BD9eIuZiSnEtD/VnKaheCiF1xq0lu 0NaKPdECxEzCx+/XE3Fdwv0JcHxTxd5c+zI/kN4PHFE4FsB3TBp6RqcN4727Dl/PGL rAY3bt7lSAUD/pVjNvy6i5IMInxG8QcXPr+3o1MJNkeu+/nykLWzZYEFctOqHXdGuF 7CmXPaHRQSpzA== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: Arnaldo Carvalho de Melo , Jean-Philippe Brucker , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Nathan Chancellor , Nick Desaulniers , Tom Rix , bpf@vger.kernel.org, Anders Roxell , llvm@lists.linux.dev Subject: [PATCH] tools/build: Add clang cross-compilation flags to feature detection Date: Thu, 2 Nov 2023 09:14:41 +0100 Message-Id: <20231102081441.240280-1-bjorn@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 02 Nov 2023 01:14:53 -0700 (PDT) From: Björn Töpel When a tool cross-build has LLVM=1 set, the clang cross-compilation flags are not passed to the feature detection build system. This results in the host's features are detected instead of the targets. E.g, triggering a cross-build of bpftool: cd tools/bpf/bpftool make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- LLVM=1 would report the host's, and not the target's features. Correct the issue by passing the CLANG_CROSS_FLAGS variable to the feature detection makefile. Fixes: cebdb7374577 ("tools: Help cross-building with clang") Signed-off-by: Björn Töpel --- tools/build/Makefile.feature | 2 +- tools/build/feature/Makefile | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 934e2777a2db..25b009a6c05f 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -8,7 +8,7 @@ endif feature_check = $(eval $(feature_check_code)) define feature_check_code - feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CC="$(CC)" CXX="$(CXX)" CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" CXXFLAGS="$(EXTRA_CXXFLAGS) $(FEATURE_CHECK_CXXFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0) + feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CC="$(CC)" CXX="$(CXX)" CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" CXXFLAGS="$(EXTRA_CXXFLAGS) $(FEATURE_CHECK_CXXFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" CLANG_CROSS_FLAGS="$(CLANG_CROSS_FLAGS)" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0) endef feature_set = $(eval $(feature_set_code)) diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index dad79ede4e0a..0231a53024c7 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -84,12 +84,12 @@ PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config all: $(FILES) -__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) +__BUILD = $(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma -lzstd -lcap -__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) +__BUILDXX = $(CXX) $(CXXFLAGS) $(CLANG_CROSS_FLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 ############################### @@ -259,10 +259,10 @@ $(OUTPUT)test-reallocarray.bin: $(BUILD) $(OUTPUT)test-libbfd-liberty.bin: - $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty + $(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty $(OUTPUT)test-libbfd-liberty-z.bin: - $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz + $(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz $(OUTPUT)test-cplus-demangle.bin: $(BUILD) -liberty base-commit: 21e80f3841c01aeaf32d7aee7bbc87b3db1aa0c6 -- 2.40.1