Skip to contentSkip to conversation

perf python: Remove -mcet and -fcf-protection when building with clang

tip:perf/urgent tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Aug 18, 2018 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  5508672d7f4949f15c316ffd947228f130498534
Gitweb:     https://git.kernel.org/tip/5508672d7f4949f15c316ffd947228f130498534
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 14 Aug 2018 18:00:40 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 14 Aug 2018 18:50:20 -0300

perf python: Remove -mcet and -fcf-protection when building with clang

These options are not present in older clang versions, so when we build for a distro that has a gcc new enough to have these options and that the distro python build config settings use them but clang doesn't support, b00m.

This is the case with fedora 28 and rawhide, so check if clang has the options and remove the missing ones from CFLAGS.

---
 tools/perf/util/setup.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/perf/util/setup.py +9 -1
index 001be4f9d3b9..97efbcad076e 100644
@@ -1,12 +1,20 @@
 #!/usr/bin/python
 
 from os import getenv
+from subprocess import Popen, PIPE
+from re import sub
+
+def clang_has_option(option):
+    return [o for o in Popen(['clang', option], stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ]
 
 cc = getenv("CC")
 if cc == "clang":
     from _sysconfigdata import build_time_vars
-    from re import sub
     build_time_vars["CFLAGS"] = sub("-specs=[^ ]+", "", build_time_vars["CFLAGS"])
+    if not clang_has_option("-mcet"):
+        build_time_vars["CFLAGS"] = sub("-mcet", "", build_time_vars["CFLAGS"])
+    if not clang_has_option("-fcf-protection"):
+        build_time_vars["CFLAGS"] = sub("-fcf-protection", "", build_time_vars["CFLAGS"])
 
 from distutils.core import setup, Extension