Skip to content

Commit 09e6f9f

Browse files
committed
perf python: Fix splitting CC into compiler and options
Noticed this build failure on archlinux:base when building with clang: clang-14: error: optimization flag '-ffat-lto-objects' is not supported [-Werror,-Wignored-optimization-argument] In tools/perf/util/setup.py we check if clang supports that option, but since commit 3cad53a ("perf python: Account for multiple words in CC") this got broken as in the common case where CC="clang": >>> cc="clang" >>> print(cc.split()[0]) clang >>> option="-ffat-lto-objects" >>> print(str(cc.split()[1:]) + option) []-ffat-lto-objects >>> And then the Popen will call clang with that bogus option name that in turn will not produce the b"unknown argument" or b"is not supported" that this function uses to detect if the option is not available and thus later on clang will be called with an unknown/unsupported option. Fix it by looking if really there are options in the provided CC variable, and if so override 'cc' with the first token and append the options to the 'option' variable. Fixes: 3cad53a ("perf python: Account for multiple words in CC") Cc: Adrian Hunter <[email protected]> Cc: Fangrui Song <[email protected]> Cc: Florian Fainelli <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Keeping <[email protected]> Cc: Khem Raj <[email protected]> Cc: Leo Yan <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Sedat Dilek <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent f257ba9 commit 09e6f9f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tools/perf/util/setup.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
from re import sub
44

55
cc = getenv("CC")
6-
cc_is_clang = b"clang version" in Popen([cc.split()[0], "-v"], stderr=PIPE).stderr.readline()
6+
7+
# Check if CC has options, as is the case in yocto, where it uses CC="cc --sysroot..."
8+
cc_tokens = cc.split()
9+
if len(cc_tokens) > 1:
10+
cc = cc_tokens[0]
11+
cc_options = " ".join([str(e) for e in cc_tokens[1:]]) + " "
12+
else:
13+
cc_options = ""
14+
15+
cc_is_clang = b"clang version" in Popen([cc, "-v"], stderr=PIPE).stderr.readline()
716
src_feature_tests = getenv('srctree') + '/tools/build/feature'
817

918
def clang_has_option(option):
10-
cc_output = Popen([cc.split()[0], str(cc.split()[1:]) + option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines()
19+
cc_output = Popen([cc, cc_options + option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines()
1120
return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o))] == [ ]
1221

1322
if cc_is_clang:

0 commit comments

Comments
 (0)