Bug 33144 - -march=native does not work on darwin
Summary: -march=native does not work on darwin
Status: RESOLVED DUPLICATE of bug 33115
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2007-08-22 05:05 UTC by Matt Fago
Modified: 2007-08-22 10:03 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Matt Fago 2007-08-22 05:05:38 UTC
This works:
/usr/local/bin/gcc -O3 -mtune=native -c Weapon.c

This does not:
/usr/local/bin/gcc -march=native Weapon.c -c -O3
Weapon.c:1: error: bad value (native) for -march= switch
Weapon.c:1: error: bad value (native) for -mtune= switch

gcc -v yields:
Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: ../gcc-4.2.1/configure --disable-checking --enable-
languages=c,c++,fortran --with-arch=nocona
Thread model: posix
gcc version 4.2.1

Per a suggestion from Ian Lance Taylor:

/usr/local/bin/gcc -v -c -O3 -march=native Weapon.c

  /usr/local/libexec/gcc/i386-apple-darwin8.10.1/4.2.1/cc1 -quiet -v -
D__DYNAMIC__ Weapon.c -fPIC -quiet -dumpbase Weapon.c -march=native -
auxbase Weapon -O3 -version -o /var/tmp//ccSVG0aD.s

To which he replied with the issue:

The problem is that the driver code is not working, and the bug is
that gcc doesn't handle that correctly.  There is some code in gcc to
handle the driver code failing, and it works for -mtune=native, but
not for -march=native.

The driver code is supposed to change the -march=native to be
-march=XXX for your CPU.  The code is in

OK, I see the problem.  The code in gcc/config/i386/linux.h looks like

#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"

gcc/config/i386/darwin.h looks like this:

#define CC1_SPEC "%{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
  %{!mmacosx-version-min=*:-mmacosx-version-min=%(darwin_minversion)} \
  %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"

The version in darwin.h is missing the %(cc1_cpu).

So there are two bugs: the darwin.h code does not invoke the driver
code for -march=native or -mtune=native, and the i386.c code does not
correctly handle -march=native.  The effect of the first bug is that
neither -march=native nor -mtune=native work on Darwin.  The effect of
the second bug is that -march=native actually gives an error, rather
than being equivalent to -march=generic.
Comment 1 Andrew Pinski 2007-08-22 10:03:19 UTC
I just fixed this for 4.3.0 (this is not a regression so it will not be fixed in 4.2.0).

*** This bug has been marked as a duplicate of 33115 ***