Skip to content

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

Open

Description

@certik

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.

Activity

  1. 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[/+] on May 1, 2015
  2. certik commented on May 1, 2015

    @certik
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions