site_utils: improve compiler checking
Look at the output of the preprocessor rather than producing an ELF in
a hardcoded location (like /tmp/a.out). If the file is owned by someone
else, the tests will fail to detect things properly. So avoid that by
not using a temp file at all.
BUG=None
TEST=running iotools.py by hand with diff compilers showed pie patch being applied as needed
TEST=running piglit.py by hand with diff compilers showed x86 being detected correctly
Change-Id: Ieb4541e2d79e90a08390ae110ab4cb681325e6b3
Reviewed-on: https://gerrit.chromium.org/gerrit/18388
Reviewed-by: asharif <asharif@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
diff --git a/client/bin/site_utils.py b/client/bin/site_utils.py
index 5e3e42e..7bff3d6 100644
--- a/client/bin/site_utils.py
+++ b/client/bin/site_utils.py
@@ -185,24 +185,23 @@
return '\n'.join(rv)
-def target_is_x86_pie():
- """Returns whether the toolchain produces an x86 PIE (position independent
+def target_is_pie():
+ """Returns whether the toolchain produces a PIE (position independent
executable) by default.
Arguments:
None
Returns:
- True if the target toolchain produces an x86 PIE by default.
+ True if the target toolchain produces a PIE by default.
False otherwise.
"""
- command = "echo \"int main(){return 0;}\" | ${CC} -o /tmp/a.out -xc -"
- command += "&& file /tmp/a.out"
+ command = 'echo | ${CC} -E -dD -P - | grep -i pie'
result = utils.system_output(command, retain_output=True,
ignore_status=True)
- if re.search("80\d86", result) and re.search("shared object", result):
+ if re.search('#define __PIE__', result):
return True
else:
return False
@@ -219,11 +218,10 @@
"""
- command = "echo \"int main(){return 0;}\" | ${CC} -o /tmp/a.out -xc -"
- command += "&& file /tmp/a.out"
+ command = 'echo | ${CC} -E -dD -P - | grep -i 86'
result = utils.system_output(command, retain_output=True,
ignore_status=True)
- if re.search("80\d86", result) or re.search("x86-64", result):
+ if re.search('__i386__', result) or re.search('__x86_64__', result):
return True
else:
return False