diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-10-15 22:13:20 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-10-15 22:18:31 +0200 |
commit | a356a103460d1b97428108431f7e73e7eda9ee85 (patch) | |
tree | d62d140286f85d32eececda71d0aab0c67afa8d0 /numpy/core/setup_common.py | |
parent | e2218a6984b756a1806041f8fb6869f63365ad10 (diff) | |
download | numpy-a356a103460d1b97428108431f7e73e7eda9ee85.tar.gz |
BLD: try linking a file if compile long double repr detection fails
When compiler uses link time optimization it will not emit the binary
representation of the long double during linking. This prevents building
numpy with -flto.
To avoid this try linking the object when the compile detection failed.
With this change numpy can be built with link time optimization with 4 worker
processes using following command:
CC='gcc -fno-fat-lto-objects -flto=4 -fuse-linker-plugin -O3' \
LDSHARED='gcc -fno-fat-lto-objects -flto=4 -fuse-linker-plugin -shared
-O3' AR=gcc-ar \
python setup.py build_ext
See also:
https://www.mail-archive.com/numpy-discussion@scipy.org/msg45535.html
Should also work with icc's -ipo switch (probably closes gh-4992)
Diffstat (limited to 'numpy/core/setup_common.py')
-rw-r--r-- | numpy/core/setup_common.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py index 3dc1cecf5..e51797c03 100644 --- a/numpy/core/setup_common.py +++ b/numpy/core/setup_common.py @@ -172,10 +172,20 @@ def check_long_double_representation(cmd): body = LONG_DOUBLE_REPRESENTATION_SRC % {'type': 'long double'} # We need to use _compile because we need the object filename - src, object = cmd._compile(body, None, None, 'c') + src, obj = cmd._compile(body, None, None, 'c') try: - type = long_double_representation(pyod(object)) - return type + ltype = long_double_representation(pyod(obj)) + return ltype + except ValueError: + # try linking to support CC="gcc -flto" or icc -ipo + # struct needs to be volatile so it isn't optimized away + body = body.replace('struct', 'volatile struct') + body += "int main(void) { return 0; }\n" + src, obj = cmd._compile(body, None, None, 'c') + cmd.temp_files.append("_configtest") + cmd.compiler.link_executable([obj], "_configtest") + ltype = long_double_representation(pyod("_configtest")) + return ltype finally: cmd._clean() |