Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp257276rdb; Thu, 2 Nov 2023 02:53:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTk4wW4QFnp08KwVw9M3hjVuD9xsMUMS8NQHbbveYpk8ltViZy8y35WV7g5Ysjmu1EZKah X-Received: by 2002:a17:902:8c85:b0:1c9:c0fa:dfb7 with SMTP id t5-20020a1709028c8500b001c9c0fadfb7mr18127895plo.57.1698918809739; Thu, 02 Nov 2023 02:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698918809; cv=none; d=google.com; s=arc-20160816; b=LbjS+5wKOosuZ36obHU9e4mwN+ZitL5izBQyON8AyRkDdr2hpSziMCtWnZvoDlfNqi o49P3kLCZR7+V1kXFXuE9+zcDw612MthdS9ikzSlqjnb3Jm11Uxx+16vHMl2pAfFPk2a jYam+gyClsyj+TIVFazsdBPVzh30XbcXwW7xUJwCRhLElkf46h5fck2yhArj8+uJTIxg M4+94iV1Dwx8Aa+xqNAjMB7ej13u1lyIikm1027lyZyCFOfLv6uSt1nP5W1X0p/UPaP2 yFAEluiY1h1m3Ry6o99Ry/Q3ies0HnJ6+LAyPnRwK3Xa+fS9KpUbbVPu8vIii+Rtf7Ah xN2A== 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:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=oagzdabx0teTkZFHhdwnIs3WgqoD4mVbFM8wlvzMlg8=; fh=E2e6qfa/LKsE/tCd4jI/VocblCNJQkpdN4n1a6XuqRU=; b=mbHMZjaJrdNoXw/PrEue73wANXaegr5zGf6mHMd3C15oP9UlLCjJvA70dOwN3JR7rF TldImsnNHZVXsdu+wR3uqcz1FiZlKRrE91tRhB5wTjO4HHVusPqYvoBOartlnN7nRZ3K K3iA8KQuQ7SnwVzupbmHhGadowKXmUkGPUlS8eGd133ScRXlUj26HfSzkAVYEk9xKYCF F4UgmW6DwAaz+71Dv5o6pqHsdsTWRm4yUCu/jkuC9yGLjGU6VudoZe9PrkctveXfvSDp 6O5jdsq6ZtKK0UQTlE6Em1aCOmGIh5pCnLbc6xuVuFwzHptHs/GjzPowfLOdv7ojjoxT QIZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kd0aPXOH; 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 ja2-20020a170902efc200b001c9ca0a03ecsi4638960plb.2.2023.11.02.02.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 02:53:29 -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=kd0aPXOH; 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 916D481FD9E8; Thu, 2 Nov 2023 02:53:26 -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 S1345740AbjKBJxR (ORCPT + 99 others); Thu, 2 Nov 2023 05:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345500AbjKBJxQ (ORCPT ); Thu, 2 Nov 2023 05:53:16 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6745FF7 for ; Thu, 2 Nov 2023 02:53:13 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51702C433C7; Thu, 2 Nov 2023 09:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698918792; bh=JQ4IzgN1tIeQMye2/+gyuWS8feDEz0F5Fh8il3PCjmc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=kd0aPXOHlZgwv3BGBPZU+dOVFXmi6HrzuGTY02GKMwAzImZvnEta3GSFBX4ObnLWE uCxAh3lfEFEvmyolqD1bS2an+KFlsLC4J3OHhI85xVMwZhOc/YzGMW8MyaA0WuFQT6 GwsirYTDe6q4aXxc+3a6AdsuzToN9yYpaJtIYVzrHG7f5um5hffoYBo4hW4nSInPib 4K3uZ1SAC4q0QrLpe/htwqxltyYhJQ+lAs58n12kDOwa1iIV6tvV0GyyTnEf16dYLj yMXpa7HYIuDSBqf1swD+suQdTvIlOSxjtxzkdC7gdgEfnKJ11OGPmuZgZ/ceApR6xT XSOtymfcbtOug== From: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Jean-Philippe Brucker , linux-kernel@vger.kernel.org, =?utf-8?B?Qmo=?= =?utf-8?B?w7ZybiBUw7ZwZWw=?= , Nathan Chancellor , Nick Desaulniers , Tom Rix , bpf@vger.kernel.org, Anders Roxell , llvm@lists.linux.dev Subject: Re: [PATCH] tools/build: Add clang cross-compilation flags to feature detection In-Reply-To: References: <20231102081441.240280-1-bjorn@kernel.org> Date: Thu, 02 Nov 2023 10:53:09 +0100 Message-ID: <871qd81ny2.fsf@all.your.base.are.belong.to.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 02:53:26 -0700 (PDT) Jiri Olsa writes: > On Thu, Nov 02, 2023 at 09:14:41AM +0100, Bj=C3=B6rn T=C3=B6pel wrote: >> From: Bj=C3=B6rn T=C3=B6pel >>=20 >> When a tool cross-build has LLVM=3D1 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. >>=20 >> E.g, triggering a cross-build of bpftool: >>=20 >> cd tools/bpf/bpftool >> make ARCH=3Driscv CROSS_COMPILE=3Driscv64-linux-gnu- LLVM=3D1 >>=20 >> would report the host's, and not the target's features. >>=20 >> Correct the issue by passing the CLANG_CROSS_FLAGS variable to the >> feature detection makefile. >>=20 >> Fixes: cebdb7374577 ("tools: Help cross-building with clang") >> Signed-off-by: Bj=C3=B6rn T=C3=B6pel >> --- >> tools/build/Makefile.feature | 2 +- >> tools/build/feature/Makefile | 8 ++++---- >> 2 files changed, 5 insertions(+), 5 deletions(-) >>=20 >> 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 >>=20=20 >> feature_check =3D $(eval $(feature_check_code)) >> define feature_check_code >> - feature-$(1) :=3D $(shell $(MAKE) OUTPUT=3D$(OUTPUT_FEATURES) CC=3D"$= (CC)" CXX=3D"$(CXX)" CFLAGS=3D"$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))= " CXXFLAGS=3D"$(EXTRA_CXXFLAGS) $(FEATURE_CHECK_CXXFLAGS-$(1))" LDFLAGS=3D"= $(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATUR= ES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0) >> + feature-$(1) :=3D $(shell $(MAKE) OUTPUT=3D$(OUTPUT_FEATURES) CC=3D"$= (CC)" CXX=3D"$(CXX)" CFLAGS=3D"$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))= " CXXFLAGS=3D"$(EXTRA_CXXFLAGS) $(FEATURE_CHECK_CXXFLAGS-$(1))" LDFLAGS=3D"= $(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" CLANG_CROSS_FLAGS=3D"$(CLANG_CROS= S_FLAGS)" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev= /null && echo 1 || echo 0) >> endef >>=20=20 >> feature_set =3D $(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 ?=3D $(CROSS_COMPILE)pkg-config >>=20=20 >> all: $(FILES) >>=20=20 >> -__BUILD =3D $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.= c,$(@F)) $(LDFLAGS) >> +__BUILD =3D $(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -MD -Wall -Werror -o $= @ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) >> BUILD =3D $(__BUILD) > $(@:.bin=3D.make.output) 2>&1 >> BUILD_BFD =3D $(BUILD) -DPACKAGE=3D'"perf"' -lbfd -ldl >> BUILD_ALL =3D $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=3D= 2 -ldw -lelf -lnuma -lelf -lslang $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED)= -DPACKAGE=3D'"perf"' -lbfd -ldl -lz -llzma -lzstd -lcap >>=20=20 >> -__BUILDXX =3D $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.b= in,%.cpp,$(@F)) $(LDFLAGS) >> +__BUILDXX =3D $(CXX) $(CXXFLAGS) $(CLANG_CROSS_FLAGS) -MD -Wall -Werror= -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) >> BUILDXX =3D $(__BUILDXX) > $(@:.bin=3D.make.output) 2>&1 >>=20=20 >> ############################### >> @@ -259,10 +259,10 @@ $(OUTPUT)test-reallocarray.bin: >> $(BUILD) >>=20=20 >> $(OUTPUT)test-libbfd-liberty.bin: >> - $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE=3D'"perf"'= $(LDFLAGS) -lbfd -ldl -liberty >> + $(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -o $@ test-libbfd.c= -DPACKAGE=3D'"perf"' $(LDFLAGS) -lbfd -ldl -liberty >>=20=20 >> $(OUTPUT)test-libbfd-liberty-z.bin: >> - $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE=3D'"perf"'= $(LDFLAGS) -lbfd -ldl -liberty -lz >> + $(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -o $@ test-libbfd.c= -DPACKAGE=3D'"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz > > should we add this also to test-compile-32.bin/test-compile-x32.bin > targets? Ah, yes! I'll spin a v2 with: diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 0231a53024c7..c4458345e564 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -283,10 +283,10 @@ $(OUTPUT)test-libbabeltrace.bin: $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabe= ltrace) =20 $(OUTPUT)test-compile-32.bin: - $(CC) -m32 -o $@ test-compile.c + $(CC) $(CLANG_CROSS_FLAGS) -m32 -o $@ test-compile.c =20 $(OUTPUT)test-compile-x32.bin: - $(CC) -mx32 -o $@ test-compile.c + $(CC) $(CLANG_CROSS_FLAGS) -mx32 -o $@ test-compile.c =20 $(OUTPUT)test-zlib.bin: $(BUILD) -lz Thanks for having a look, jirka! Bj=C3=B6rn