Unable to disable `-march=native`

Building software with clang and gcc force -march=native apparently, no matter what I do:

$ clang a.c -march=x86-64 -mtune=generic -o a_clang 

$ gcc a.c -march=x86-64 -mtune=generic -o a_gcc    

$ readelf -n a_clang a_gcc

File: a_clang

Displaying notes found in: .note.gnu.property
  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0
      Properties: x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4

File: a_gcc

Displaying notes found in: .note.gnu.property
  Owner                Data size        Description
  GNU                  0x00000030       NT_GNU_PROPERTY_TYPE_0
      Properties: x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4
        x86 feature used: x86
        x86 ISA used: x86-64-baseline

When trying to run the program on an older CPU, I get

CPU ISA level is lower than required

This is also the case with golang, which gives me

This program can only be run on AMD64 processors with v4 microarchitecture support.

However in case of golang Iā€™m able to successfully override it with GOAMD64=v1

1 Like

Seems like something is telling the linker to add that section, and lld is the only linker that seems to disregard it and not add the section.

1 Like

The culprit turned out to be glibc, linking with an x86-64-v4 version of it is making it add that section.

1 Like

The solution is not installing core/glibc from the arch repo, because it gets overwritten by the optimized package in the next update. We need the static linked files pacman -Ql glibc | grep '\.[oa]$' to be opted out of optimizations for this problem to be properly fixed.