Skip to contentSkip to conversation

perf build: Don't leave a.out file when building with clang

PATCH Superseded Ian Rogers 2 participants 3 messages Oct 6, 2025 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf build: Don't leave a.out file when building with clang

Testing clang features doesn't specify a "-o" option so an a.out file is created and left in the make directory (not the output). Fix this by specifying a "-o" of "/dev/null". Reorganize the code a little to help with readability.

---
 tools/perf/util/setup.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/setup.py +10 -2
index dd289d15acfd..6caf2126b1cd 100644
@@ -22,8 +22,16 @@ assert srctree, "Environment variable srctree, for the Linux sources, not set"
 src_feature_tests  = f'{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()
-    return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o) or (b"unknown warning option" in o))] == [ ]
+    error_substrings = (
+        b"unknown argument",
+        b"is not supported",
+        b"unknown warning option"
+    )
+    clang_command = [cc, cc_options + option,
+                     "-o", "/dev/null",
+                     path.join(src_feature_tests, "test-hello.c") ]
+    cc_output = Popen(clang_command, stderr=PIPE).stderr.readlines()
+    return not any(any(error in line for error in error_substrings) for line in cc_output)
 
 if cc_is_clang:
     from sysconfig import get_config_vars
Signature · 1 line
2.51.0.618.g983fd99d29-goog
author reviewer
#1 lore raw
Quoted 7 lines · Ian Rogers

Testing clang features doesn't specify a "-o" option so an a.out file is created and left in the make directory (not the output). Fix this by specifying a "-o" of "/dev/null". Reorganize the code a little to help with readability.

Maybe a fixes tag of:

Fixes 5508672d7f49 perf python: Remove -mcet and -fcf-protection when

building with clang

Thanks,
Ian

Quoted 30 lines
---
 tools/perf/util/setup.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/setup.py +10 -3
index dd289d15acfd..6caf2126b1cd 100644
@@ -22,8 +22,16 @@ assert srctree, "Environment variable srctree, for the Linux sources, not set"
 src_feature_tests  = f'{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()
-    return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o) or (b"unknown warning option" in o))] == [ ]
+    error_substrings = (
+        b"unknown argument",
+        b"is not supported",
+        b"unknown warning option"
+    )
+    clang_command = [cc, cc_options + option,
+                     "-o", "/dev/null",
+                     path.join(src_feature_tests, "test-hello.c") ]
+    cc_output = Popen(clang_command, stderr=PIPE).stderr.readlines()
+    return not any(any(error in line for error in error_substrings) for line in cc_output)
 
 if cc_is_clang:
     from sysconfig import get_config_vars
--

2.51.0.618.g983fd99d29-goog

Tested-by on v1 1/1
#2 lore raw
In reply to Ian Rogers

Hi,

Quoted 6 lines · Ian Rogers

Testing clang features doesn't specify a "-o" option so an a.out file is created and left in the make directory (not the output). Fix this by specifying a "-o" of "/dev/null". Reorganize the code a little to help with readability.

Quoted 31 lines
---
 tools/perf/util/setup.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/setup.py +10 -2
index dd289d15acfd..6caf2126b1cd 100644
@@ -22,8 +22,16 @@ assert srctree, "Environment variable srctree, for the Linux sources, not set"
 src_feature_tests  = f'{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()
-    return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o) or (b"unknown warning option" in o))] == [ ]
+    error_substrings = (
+        b"unknown argument",
+        b"is not supported",
+        b"unknown warning option"
+    )
+    clang_command = [cc, cc_options + option,
+                     "-o", "/dev/null",
+                     path.join(src_feature_tests, "test-hello.c") ]
+    cc_output = Popen(clang_command, stderr=PIPE).stderr.readlines()
+    return not any(any(error in line for error in error_substrings) for line in cc_output)
 
 if cc_is_clang:
     from sysconfig import get_config_vars
Signature · 1 line
2.51.0.618.g983fd99d29-goog

Thanks
Justin