Skip to content

Fix gcc -march=native for arm mac#1924

Merged
jeremylt merged 3 commits intoCEED:mainfrom
hughcars:fix-march-native-arm
Feb 6, 2026
Merged

Fix gcc -march=native for arm mac#1924
jeremylt merged 3 commits intoCEED:mainfrom
hughcars:fix-march-native-arm

Conversation

@hughcars
Copy link
Copy Markdown
Contributor

@hughcars hughcars commented Feb 4, 2026

When building with spack on ARM (Apple Silicon), GCC's -march=native fails:

  cc1: error: unknown value 'apple-m1' for '-march'
  cc1: note: valid arguments are: armv8-a armv8.1-a ... native
  cc1: note: did you mean '-mcpu=apple-m1'?

This occurs because spack's compiler wrapper causes -march=native to resolve to CPU names like apple-m1, but GCC's -march doesn't accept CPU names on ARM—only -mcpu does. Fix by detecting architecture via uname -m and using -mcpu=native on non-x86 platforms.

Reproducer with spack on macOS ARM:

mkdir test && cd test
echo 'spack:
  specs:
  - libceed@develop %gcc' > spack.yaml
spack env activate .
spack install

Also changes the macos CI to use gcc/clang from homebrew, as gcc clang are aliases for apple-clang.

@hughcars hughcars force-pushed the fix-march-native-arm branch 2 times, most recently from 7aebc4d to 9de00a7 Compare February 4, 2026 17:13
@hughcars hughcars changed the title Fix gcc -march=native Fix gcc -march=native for arm mac Feb 4, 2026
@hughcars hughcars force-pushed the fix-march-native-arm branch 4 times, most recently from a7d2a66 to c8b366f Compare February 4, 2026 19:40
@jeremylt
Copy link
Copy Markdown
Member

jeremylt commented Feb 4, 2026

Your branch is missing 160 commits - we made some changes to the makefile in those commits so could you update your branch to be in line with our main please?

Comment thread Makefile Outdated
MARCHFLAG.clang := $(MARCHFLAG.gcc)
# GCC: use -march=native only on x86 (where -mcpu doesn't exist); use -mcpu=native elsewhere
MARCHFLAG.gcc := $(if $(filter x86_64 i%86,$(UNAME_M)),-march=native,-mcpu=native)
MARCHFLAG.clang := -march=native
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MARCHFLAG.clang := -march=native
MARCHFLAG.clang := $(MARCHFLAG.gcc)

I believe clang works the same way as gcc in this regard so I think this line should be reverted.

$ clang -E --target=aarch64 -march=apple-m1 -x c /dev/null
clang: error: unsupported argument 'apple-m1' to option '-march='

In contrast, this is successful:

$ clang -E --target=aarch64 -mcpu=apple-m1 -x c /dev/null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wanted to try and figure out the details here before engaging either of you (the PR description isn't even right any more), but thank you for taking an early look. I think you're right, and had undone it, the UNAME_M approach here is I think better than the -c vs -E I originally tried (but broke the powerpc CI).

The "gcc" on macOS is a symlink to Apple Clang, so the existing matrix
was testing Apple Clang twice instead of testing distinct compilers.

Fix by testing three explicit compilers on macOS:
- clang: Apple Clang (system)
- gcc-15: real GCC from Homebrew
- llvm: LLVM 18 from Homebrew

Print compiler version to make the distinction visible in CI output.
On ARM, -march=native resolves to CPU names (e.g., apple-m1) which are
invalid for -march; must use -mcpu=native instead. Use uname -m to detect
architecture and select the appropriate flag. Clang has the same limitation,
so MARCHFLAG.clang follows MARCHFLAG.gcc.
@hughcars hughcars force-pushed the fix-march-native-arm branch from c8b366f to 7247fd9 Compare February 5, 2026 15:32
@hughcars
Copy link
Copy Markdown
Contributor Author

hughcars commented Feb 5, 2026

Your branch is missing 160 commits - we made some changes to the makefile in those commits so could you update your branch to be in line with our main please?

Sorry about that, I made a mistake in starting the branch from my main which hadn't updated in a while, rather than origin main, pulled those in and pushed now.

@hughcars hughcars marked this pull request as ready for review February 5, 2026 17:08
@hughcars
Copy link
Copy Markdown
Contributor Author

hughcars commented Feb 5, 2026

I think the change now is as minimal as i can. There's some risk of cross compiling I think, in that uname is about the current machine, but given I've only reliably been able to make this break in spack, this seems ok. The later cc flag checking is possibly redundant now, but I opted to leave it for defense in depth, and because I've no idea what other edge case build it might be protecting in addition to this change. The CI job might want to be renamed to gcc rather than gcc-15, happy to change that if you'd like.

@jeremylt
Copy link
Copy Markdown
Member

jeremylt commented Feb 5, 2026

The CI job might want to be renamed to gcc rather than gcc-15, happy to change that if you'd like.

That would be very helpful if you don't mind. Thanks for the good fix

Map compiler display names to actual binaries in a step instead of
using matrix include/exclude, so job names stay as gcc/clang. Adds
a separate apple-clang job on macOS to test the system compiler.
@jeremylt jeremylt merged commit 79b8f26 into CEED:main Feb 6, 2026
26 checks passed
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 this pull request may close these issues.

3 participants