Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS X 10.10 using '-march=native' works in clang but breaks in gcc #748

Open
certik opened this issue May 1, 2015 · 1 comment · May be fixed by #774
Open

OS X 10.10 using '-march=native' works in clang but breaks in gcc #748

certik opened this issue May 1, 2015 · 1 comment · May be fixed by #774

Comments

@certik
Copy link
Member

certik commented May 1, 2015

More background e.g. in Homebrew/legacy-homebrew#14204.
The way it breaks in (our compiled) gcc is as follows:

[csympy] Building CXX object src/CMakeFiles/csympy.dir/symbol.cpp.o
[csympy] /var/tmp//ccc4Ii22.s:829:no such instruction: `vzeroupper'
[csympy] /var/tmp//ccc4Ii22.s:847:no such instruction: `vzeroupper'
[csympy] /var/tmp//ccc4Ii22.s:855:no such instruction: `vzeroupper'
...

The linker (which is Apple linker) complains that it doesn't understand the AVX instructions, emitted (correctly) by gcc's -march=native, since my computer supports AVX. A quick workaround is to do

diff --git a/pkgs/csympy.yaml b/pkgs/csympy.yaml
index 5caa557..32bf39d 100644
--- a/pkgs/csympy.yaml
+++ b/pkgs/csympy.yaml
@@ -12,6 +12,12 @@ defaults:
   relocatable: false

 build_stages:
+- name: cxx_flags
+  before: configure
+  handler: bash
+  bash: |
+    export CXXFLAGS="-mno-avx"
+
 - name: configure
   extra: ['-D WITH_PYTHON:BOOL=ON',
           '-D PYTHON_INSTALL_PATH:PATH=$ARTIFACT/{{python_site_packages_rel}}']

But this is not a solution, because you want to be able to use AVX instructions if your processor supports it, and gcc generates them, i.e. you must be able to use -march=native.

The fix is to either make gcc generate AVX instructions so that the Apple's linker can understand, or we need to build our own linker.

@certik certik changed the title OS X 10.10 using '-march=native' in works in clang but breaks in gcc OS X 10.10 using '-march=native' works in clang but breaks in gcc May 1, 2015
@certik
Copy link
Member Author

certik commented May 1, 2015

I think I found an actual solution to this problem here: http://stackoverflow.com/a/19342603

diff --git a/pkgs/csympy.yaml b/pkgs/csympy.yaml
index 5caa557..d12c127 100644
--- a/pkgs/csympy.yaml
+++ b/pkgs/csympy.yaml
@@ -12,6 +12,12 @@ defaults:
   relocatable: false

 build_stages:
+- name: cxx_flags
+  before: configure
+  handler: bash
+  bash: |
+    export CXXFLAGS="-Wa,-q"
+
 - name: configure
   extra: ['-D WITH_PYTHON:BOOL=ON',
           '-D PYTHON_INSTALL_PATH:PATH=$ARTIFACT/{{python_site_packages_rel}}']

This solution forces our gcc to use the clang's assembler, so we still use -march=native and AVX instructions, just a different linker. And all is good.

This CXXFLAGS option should be integrated into all packages on OS X I guess.

@certik certik linked a pull request May 15, 2015 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant