Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp276235rdb; Thu, 2 Nov 2023 03:33:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHW8y4nOmuoO2sqVM57g+d3SgSWeILEmmz3d0xbIhfD1EsApR8rcoe80bj3fXjeuUcY/1H7 X-Received: by 2002:a17:902:ab84:b0:1c0:774d:9342 with SMTP id f4-20020a170902ab8400b001c0774d9342mr13951571plr.25.1698921197242; Thu, 02 Nov 2023 03:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698921197; cv=none; d=google.com; s=arc-20160816; b=kOcSwCrbB4aa56gN4Ml5mxpF5aJBqYB2BNpliNYwzWsnx507G/TxQQH45ZbROBk5M4 9sWVVllEri4hxqpX2NobFhxR8HD5FQDRPy0Amu2VuspjXd9xA+1t6MFsonGOOykjMKn2 rUsJHFXabHD5moQWTb5154rtVbAUbC0cHixfqESds1F/3Sko00bTi2ZBm8qiJ0IkXir6 PJqYuLHDgwWY8J8E4JgKnguemhvkC3XM4PEpGw8B6cXjdWyryeS9nGy3OOEQxayrVFxe w4avYmuwubICBt6BhqUqqpIfv88lDX/WUK43RxKXmxISvFB8A2Lz+Aj6gdI2fxD4Giz4 CXIg== 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=cjIoDC1DBs6CPJN1R060BFdGphynyKKba1/84qGZsko=; fh=HAjqErvyQW0dMwseuks5S5bBWK34gyfVfZEp4fz4pWU=; b=O8T4arMyeIzpom2bAv6UbG6AWCTKaxgO8zD4MZDoKYK4+uc3Thm3gRotzmqG7PevCA ptF+24yDYthp4jFwXJkYfBH9tSYLiDmizCu19NS95iOvNSi8zVcCBklvTwSWdJFzYyd8 7qFYqyum0QqVETt06wWy2aqnN/n08Gl8wH2X/ZkunariGU34dV9erPofFC3VvvqDypyA LTY8XO6OpOtPhYUZfKqkn5jtjOsvGmAkg3deYtdWjJZkLjBJsAAYwijy9oOLwgzHtAl4 N8cGKnrDEEesWhNytXgEKoJwW3Z4R/CsOtehxEd93nXFo3hpeNTcV6dwKF7r2HDIR3Vr zVVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZJiNlDs4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id b2-20020a170903228200b001cc31c96c70si5147251plh.330.2023.11.02.03.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 03:33:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZJiNlDs4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 1981880967B0; Thu, 2 Nov 2023 03:33:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346863AbjKBKdD (ORCPT + 99 others); Thu, 2 Nov 2023 06:33:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346832AbjKBKdC (ORCPT ); Thu, 2 Nov 2023 06:33:02 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C430AC2 for ; Thu, 2 Nov 2023 03:32:59 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22382C433C7; Thu, 2 Nov 2023 10:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698921179; bh=vCsEm5kYfVokXfpt6FzUVW6m+28U/AvZkO+g4Ew8jFk=; h=From:To:Cc:Subject:Date:From; b=ZJiNlDs4f9oSJYvvei6uvYrpqZq37TUCwF2TSXFU0cathgxMjUlb4jnlSBN4uWgXY h1C9FNJXF8eXE6TTbyrPdzGPap3ZvqTeBycVZLwtI/OBCUOA+yoZaqgqRt9+AtkZYO 1kJ2hdn88SArB44LpXio9JYg3HVTdQLy/72rTKqAFoB3/hWHcAVdzvxYSVIMHY/pmQ uCnjE2dRoZusENcLrLAjYtjG94rH95ydVkXdor2gNtHsd8Jh5z22QhPIQ3qx+ucgsn Hnsk6XReZPEAH78MSG8NTPZp2RwwvCPMNAXDwhxHJEM2hylphICX3Wg97UUqFLlfiL TC+p/kmOFN+ZA== 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, Jiri Olsa Subject: [PATCH v2] tools/build: Add clang cross-compilation flags to feature detection Date: Thu, 2 Nov 2023 11:32:52 +0100 Message-Id: <20231102103252.247147-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=-1.6 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 03:33:14 -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 | 12 ++++++------ 2 files changed, 7 insertions(+), 7 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..c4458345e564 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 @@ -283,10 +283,10 @@ $(OUTPUT)test-libbabeltrace.bin: $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace) $(OUTPUT)test-compile-32.bin: - $(CC) -m32 -o $@ test-compile.c + $(CC) $(CLANG_CROSS_FLAGS) -m32 -o $@ test-compile.c $(OUTPUT)test-compile-x32.bin: - $(CC) -mx32 -o $@ test-compile.c + $(CC) $(CLANG_CROSS_FLAGS) -mx32 -o $@ test-compile.c $(OUTPUT)test-zlib.bin: $(BUILD) -lz base-commit: 21e80f3841c01aeaf32d7aee7bbc87b3db1aa0c6 -- 2.40.1