Skip to contentSkip to conversation

build/x86: fix support for older compilers

PATCH Superseded Bruce Richardson 4 participants 9 messages Jul 2, 2025 – Jul 3, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build/x86: fix support for older compilers

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX
...

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")
---
 config/x86/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
config/x86/meson.build +6 -1
index e2ccfb6d12..0dcc5ddee4 100644
@@ -71,8 +71,13 @@ avx512_march_flag = '-march=x86-64-v4'
 if not cc.has_argument(avx512_march_flag)
     avx512_march_flag = '-march=skylake-avx512'
 endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: [machine_args, avx512_march_flag]) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
+endif
 cc_avx512_flags = []
-if (binutils_ok and cc.has_argument(avx512_march_flag)
+if (binutils_ok and cc.has_multi_arguments(avx512_march_flag)
         and '-mno-avx512f' not in get_option('c_args'))
     # check if compiler is working with _mm512_extracti64x4_epi64
     # Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82887
Signature · 1 line
2.48.1
#1 lore raw
Quoted 10 lines · Bruce Richardson

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

Quoted 5 lines

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX
...

... and of course the output lines get stripped since they start with '#' for '#define' :-(

Quoted 30 lines

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")
---
 config/x86/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
config/x86/meson.build +6 -1
index e2ccfb6d12..0dcc5ddee4 100644
@@ -71,8 +71,13 @@ avx512_march_flag = '-march=x86-64-v4'
 if not cc.has_argument(avx512_march_flag)
     avx512_march_flag = '-march=skylake-avx512'
 endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: [machine_args, avx512_march_flag]) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
+endif
 cc_avx512_flags = []
-if (binutils_ok and cc.has_argument(avx512_march_flag)
+if (binutils_ok and cc.has_multi_arguments(avx512_march_flag)
         and '-mno-avx512f' not in get_option('c_args'))
     # check if compiler is working with _mm512_extracti64x4_epi64
     # Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82887
Signature · 1 line
2.48.1
#2 lore raw

PATCH v2 1/1 build/x86: fix support for older compilers

In reply to Bruce Richardson

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 0

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 5

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")
---
 config/x86/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
config/x86/meson.build +6 -1
index e2ccfb6d12..0dcc5ddee4 100644
@@ -71,8 +71,13 @@ avx512_march_flag = '-march=x86-64-v4'
 if not cc.has_argument(avx512_march_flag)
     avx512_march_flag = '-march=skylake-avx512'
 endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: [machine_args, avx512_march_flag]) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
+endif
 cc_avx512_flags = []
-if (binutils_ok and cc.has_argument(avx512_march_flag)
+if (binutils_ok and cc.has_multi_arguments(avx512_march_flag)
         and '-mno-avx512f' not in get_option('c_args'))
     # check if compiler is working with _mm512_extracti64x4_epi64
     # Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82887
Signature · 1 line
2.48.1
#3 lore raw
Quoted 29 lines · On Wed, 2 Jul 2025 17:00:45 +0100 Bruce Richardson…

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 0

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 5

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")
---
 config/x86/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
config/x86/meson.build +0 -0
index e2ccfb6d12..0dcc5ddee4 100644

config/x86/meson.build avx512_march_flag = '-march=x86-64-v4' · line 78

Quoted 8 lines
config/x86/meson.build +5 -0
@@ -71,8 +71,13 @@ avx512_march_flag = '-march=x86-64-v4'
 if not cc.has_argument(avx512_march_flag)
     avx512_march_flag = '-march=skylake-avx512'
 endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: [machine_args, avx512_march_flag]) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
+endif

RHEL 8.5 reached end of extended support cycle (EOL). Why are we still supporting it?

#4 lore raw
Quoted 27 lines · Stephen Hemminger
Quoted 24 lines · On Wed, 2 Jul 2025 17:00:45 +0100 Bruce Richardson…

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 0

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 5

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")
---
 config/x86/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 16 lines

config/x86/meson.build avx512_march_flag = '-march=x86-64-v4' · line 78

Quoted 13 lines
config/x86/meson.build +5 -0
index e2ccfb6d12..0dcc5ddee4 100644
@@ -71,8 +71,13 @@ avx512_march_flag = '-march=x86-64-v4'
 if not cc.has_argument(avx512_march_flag)
     avx512_march_flag = '-march=skylake-avx512'
 endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: [machine_args, avx512_march_flag]) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
+endif

RHEL 8.5 reached end of extended support cycle (EOL). Why are we still supporting it?

Folks working for Redhat can answer better than me, but according to [1] it's not EOL yet. Also, we support it in DPDK because users are still using it - we had two separate people report seeing the issue on RHEL 8 on RC2, so likely a reasonable number will be using it with the actual release.

/Bruce

[1] https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux#Version_history_and_timeline

#5 lore raw
Quoted 46 lines · Bruce Richardson
Quoted 27 lines · Stephen Hemminger
Quoted 24 lines · On Wed, 2 Jul 2025 17:00:45 +0100 Bruce Richardson…

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 0

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 5

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")
---
 config/x86/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 16 lines

config/x86/meson.build avx512_march_flag = '-march=x86-64-v4' · line 78

Quoted 13 lines
config/x86/meson.build +5 -0
index e2ccfb6d12..0dcc5ddee4 100644
@@ -71,8 +71,13 @@ avx512_march_flag = '-march=x86-64-v4'
 if not cc.has_argument(avx512_march_flag)
     avx512_march_flag = '-march=skylake-avx512'
 endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: [machine_args, avx512_march_flag]) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
+endif

RHEL 8.5 reached end of extended support cycle (EOL). Why are we still supporting it?

Quoted 2 lines

Folks working for Redhat can answer better than me, but according to [1] it's not EOL yet. Also, we support it in DPDK because users are still using

RHEL 8 is not EOL.

Signature · 1 line
David Marchand
#6 lore raw
Quoted 48 lines · On Thu, 3 Jul 2025 10:12:10 +0200 David Marchand <[email protected]>…
Quoted 46 lines · Bruce Richardson
Quoted 43 lines · Stephen Hemminger
Quoted 29 lines · On Wed, 2 Jul 2025 17:00:45 +0100 Bruce Richardson…

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 0

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 5

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")
---
 config/x86/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
config/x86/meson.build +0 -0
index e2ccfb6d12..0dcc5ddee4 100644

config/x86/meson.build avx512_march_flag = '-march=x86-64-v4' · line 78

Quoted 8 lines
config/x86/meson.build +5 -0
@@ -71,8 +71,13 @@ avx512_march_flag = '-march=x86-64-v4'
 if not cc.has_argument(avx512_march_flag)
     avx512_march_flag = '-march=skylake-avx512'
 endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: [machine_args, avx512_march_flag]) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
+endif  

RHEL 8.5 reached end of extended support cycle (EOL). Why are we still supporting it?

Quoted 6 lines
Quoted 2 lines

Folks working for Redhat can answer better than me, but according to [1] it's not EOL yet. Also, we support it in DPDK because users are still using

RHEL 8 is not EOL.

Right but 8.5 is, did compiler get fixed in later 8.X versions?

#7 lore raw

PATCH v3 1/1 build/x86: fix support for older compilers

In reply to Bruce Richardson

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 0

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 5

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")

---
V3: fix build when using meson 0.57 which doesn't flatten the sub-arrays
V2: fix commit log

---
 config/x86/meson.build | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
config/x86/meson.build +10 -5
index e2ccfb6d12..bd135eb02d 100644
@@ -67,26 +67,31 @@ if is_linux or cc.get_id() == 'gcc'
     endif
 endif
 
-avx512_march_flag = '-march=x86-64-v4'
+avx512_march_flag = ['-march=x86-64-v4']
 if not cc.has_argument(avx512_march_flag)
-    avx512_march_flag = '-march=skylake-avx512'
+    avx512_march_flag = ['-march=skylake-avx512']
+endif
+# workaround for older compilers, e.g. gcc 8.5 on RHEL 8.
+# if march flag overriding doesn't work, explicitly add flags for AVX512.
+if cc.get_define('__AVX512F__', args: machine_args + avx512_march_flag) == ''
+    avx512_march_flag = ['-mavx512f', '-mavx512bw', '-mavx512cd', '-mavx512dq', '-mavx512vl']
 endif
 cc_avx512_flags = []
-if (binutils_ok and cc.has_argument(avx512_march_flag)
+if (binutils_ok and cc.has_multi_arguments(avx512_march_flag)
         and '-mno-avx512f' not in get_option('c_args'))
     # check if compiler is working with _mm512_extracti64x4_epi64
     # Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82887
     code = '''#include <immintrin.h>
     void test(__m512i zmm){
         __m256i ymm = _mm512_extracti64x4_epi64(zmm, 0);}'''
-    result = cc.compiles(code, args : [avx512_march_flag], name : 'AVX512 checking')
+    result = cc.compiles(code, args : avx512_march_flag, name : 'AVX512 checking')
     if result == false
         machine_args += '-mno-avx512f'
         warning('Broken _mm512_extracti64x4_epi64, disabling AVX512 support')
     else
         cc_has_avx512 = true
         if cc.get_define('__AVX512F__', args: machine_args) == ''
-            cc_avx512_flags = [avx512_march_flag]
+            cc_avx512_flags = avx512_march_flag
             if cc.has_argument('-Wno-overriding-option')
                 cc_avx512_flags += '-Wno-overriding-option'
             endif
Signature · 1 line
2.48.1
#8 lore raw

03/07/2025 12:21, Bruce Richardson:

Quoted 13 lines

Some older compilers e.g. gcc 8.5, do not support overriding -march=native with another architecture, leading to build warnings such as reported in Bugzilla (link below). Add a check for that case, and explicitly add the avx512 flags if necessary.

Note: it appears that it is only the "native" flag that isn't overridden, which makes the issue hard to reproduce e.g. using godbolt.org, or on a modern machine. For example, testing with gcc 8.5 on a haswell machine, using 'native' vs explicit 'haswell':

gcc -march=native -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 0

Quoted 7 lines

gcc -march=haswell -march=skylake-avx512 -dM -E - < /dev/null | grep AVX512 | wc -l 5

Bugzilla ID: 1736

Fixes e361ae3f59d3 ("build: reduce use of AVX compiler flags")

Applied, thanks.