From patchwork Wed Dec 28 01:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ahelenia_Ziemia=C5=84ska?= X-Patchwork-Id: 37093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1687079wrt; Tue, 27 Dec 2022 18:44:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXsfyR0ctlDGFfzf2dAl2vJdVAO4uQH5fhvBzg+brXN25rBOAAyOUnVmX/h4TQ1zsf0r/J3E X-Received: by 2002:a17:907:1385:b0:7c1:6167:7816 with SMTP id vs5-20020a170907138500b007c161677816mr15982484ejb.28.1672195460067; Tue, 27 Dec 2022 18:44:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672195460; cv=none; d=google.com; s=arc-20160816; b=Y6z9CdwOds3kduWWrC6jc2f1HDMRu1QVpx0H316WtRsxLM3qZGWj6iE7PDZWk2BWh4 kUzqT9UM2pr2KZv5OptOgrWdnLDFiqVWjkRZfuI9pH+WFKk8o/p2lRDwM1AATZbDlzU7 /GzHYMh7Ai/2u7M5KhTc5lE9q00bby4eZe1oG3hFoRYBFcnX8SqOrQouZYiRDBKEpKfU bbmjrcafPC9Yp/AcP9+Y9ttjmXGIMhXcZh7CqzFtWZJH22IidM6irEXzhRBR/0SK4OAu S7EvdtYvFIIOiwRqlhoGJVEzG64kAQjgxa3KL2ZsxLBbOVsvB6HfFZXkodEVQzqnldJZ TE2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:from:date :dkim-signature; bh=3lENpsyTCWzTTWbXEM3iLBE00SvPDWGe82blYrbDzRg=; b=FkUZo4VyKxw/fa2q9nIV5eVZU9idyqbRtFGdOkWCOWSwPbFm/IBdYXpi1icu7+eN7p Pu+QYJrz/ftJ6pidyCzf3mEgO7d0rf0eLL6oruaQ9/EfykZ9/Y9uKcI4PXpnCafcaQ+3 sYKRFAFIBtUOwoALKpCxM+x7q8cX5RJUEDdkyMZBiesfOon0Rsu73msmSjCDuYVIxOpS s4f+u+n1YriXb9ACKqU6nrawGTH5hbupABVcJA5ay63DTBFXKBIBu/HO9zNCDgp/2blk ZzoCCJV2B7sAZFPQoiBmYlSFIg76NqLA3b0sMTangKb9poHYmQ1GTEw01d1Uzcye7aah tHUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202211 header.b=IojomR1x; 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=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht11-20020a170907608b00b007c18706010asi13286647ejc.753.2022.12.27.18.43.56; Tue, 27 Dec 2022 18:44:20 -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=@nabijaczleweli.xyz header.s=202211 header.b=IojomR1x; 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=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232506AbiL1B5v (ORCPT + 99 others); Tue, 27 Dec 2022 20:57:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229939AbiL1B5r (ORCPT ); Tue, 27 Dec 2022 20:57:47 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5ECB7BE2; Tue, 27 Dec 2022 17:57:41 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 68ED4456; Wed, 28 Dec 2022 02:57:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1672192659; bh=m02CFbCfLjgB/D/F8c3/1CJMeEw8Hb7kGUUt5zHmh94=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=IojomR1xBGcBofTo9LZmbGRmJ61IoSkBUvhP4FOcjSrLb0gsjuhDNGDzSEwRmlEL/ pq85VA6FAoDBaZzAN0Egm0v0omd0KQ/Kc46F4rSiJKbRJ4cnZp3xi42jUvJi2X0+WY TXzdGZomYZNIjDiHA6G7w/7QJxWDVaDk8YE4g0D1wXG4jw2O5CCog0wQ0EX/6GJMC3 QvGjEAu8VNyROqwGdin7xlGz4kAn4USxWC6Brb9Hw7FqO8Xl15BpW838e9RlKFl2vp k95XKgZPq6Bgb8T6P+mU9RvnHFiVwAkoz3q/eyIffU7wieD6Zk5AU0HkS6+U2Ai2bE jUd5YSbYKZr7g== Date: Wed, 28 Dec 2022 02:57:38 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 1/4] perf python: make clang feature detection work Message-ID: References: <44bb9a29bd7a0385c25ebfd69abd0a41ac2d753b.1672187710.git.nabijaczleweli@nabijaczleweli.xyz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <44bb9a29bd7a0385c25ebfd69abd0a41ac2d753b.1672187710.git.nabijaczleweli@nabijaczleweli.xyz> User-Agent: NeoMutt/20220429 X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, MISSING_HEADERS,PDS_RDNS_DYNAMIC_FP,RDNS_DYNAMIC,SPF_HELO_PASS, SPF_PASS,T_PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) 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?1753424026645829301?= X-GMAIL-MSGID: =?utf-8?q?1753424026645829301?= As it stands, it's /entirely/ broken: cc_options is pasted together with the tested option /as a single argument/. For example, for CC='cc -O3', this will run (the equivalent of) cc "-O3 -mcet" ../build/feature/test-heello.c cc "-O3 -fcf-protection" ../build/feature/test-heello.c .. which, obviously, doesn't work, and has /never/ worked. The commit referenced in Fixes: is just the first one that uses this approach. Instead of emulating shell tokenisation and turning tokens into words badly (well, we barely do it, which is even more alarming. the only way I can foresee this having ever worked for anyone is if it, very literally, returned False for /every/ clang_has_option() invocation with non-single-token $CC, which, I mean, sure, but it means that every clang build like this has all hardening off), just... run these through the shell, like they will be at point-of-use anyway. As a demo, with CC='/tmp/cc -O3' and /tmp/cc consisting of #!/bin/sh echo "$*" | grep -qFe '-mcet' && printf 'CC:"%s"\n' "$@" "" > /dev/tty exec cc "$@" before: AR /mnt/filling/store/nabijaczleweli/code/linux/tools/perf/libsubcmd/libsubcmd.a CC:"-O3 -mcet" CC:"/mnt/filling/store/nabijaczleweli/code/linux/tools/build/feature/test-hello.c" CC:"" CC:"-O3 -mcet" CC:"/mnt/filling/store/nabijaczleweli/code/linux/tools/build/feature/test-hello.c" CC:"" LD /mnt/filling/store/nabijaczleweli/code/linux/tools/perf/libbpf/staticobjs/libbpf-in.o after: GEN python/perf.cpython-39-x86_64-linux-gnu.so CC:"-O3" CC:"-mcet" CC:"/mnt/filling/store/nabijaczleweli/code/linux/tools/build/feature/test-hello.c" CC:"" CC:"-O3" CC:"-mcet" CC:"/mnt/filling/store/nabijaczleweli/code/linux/tools/build/feature/test-hello.c" CC:"" LD /mnt/filling/store/nabijaczleweli/code/linux/tools/perf/libbpf/staticobjs/libbpf-in.o Fixes: commit 3cad53a6f9cdb ("perf python: Account for multiple words in CC") Signed-off-by: Ahelenia ZiemiaƄska --- tools/perf/util/setup.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py index c294db713677..1cee26c63613 100644 --- a/tools/perf/util/setup.py +++ b/tools/perf/util/setup.py @@ -2,21 +2,11 @@ from os import getenv, path from subprocess import Popen, PIPE from re import sub -cc = getenv("CC") - -# Check if CC has options, as is the case in yocto, where it uses CC="cc --sysroot..." -cc_tokens = cc.split() -if len(cc_tokens) > 1: - cc = cc_tokens[0] - cc_options = " ".join([str(e) for e in cc_tokens[1:]]) + " " -else: - cc_options = "" - -cc_is_clang = b"clang version" in Popen([cc, "-v"], stderr=PIPE).stderr.readline() +cc_is_clang = b"clang version" in Popen(["/bin/sh", "-c", "$CC -v"], stderr=PIPE).stderr.readline() src_feature_tests = getenv('srctree') + '/tools/build/feature' def clang_has_option(option): - cc_output = Popen([cc, cc_options + option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines() + cc_output = Popen(["/bin/sh", "-c", '$CC "$@"', "", option, path.join(src_feature_tests, "test-hello.c")], stderr=PIPE).stderr.readlines() return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o))] == [ ] if cc_is_clang: