https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116854

            Bug ID: 116854
           Summary: GCC incorrectly assumes all CPUs where -march=native
                    resolves to -march=bdver4 will have RDRND support
           Product: gcc
           Version: 13.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ipsum.te.futue at gmail dot com
  Target Milestone: ---

Summary: GCC enables __haswell__ on certain AMD Excavator CPUs that
'-march=native' resolves to '-march=bdver4 -mno-rdrnd' despite the fact that
RDRND should be checked for and required in order to enable __haswell__.

While investigating segfaults within Qt, compiled with GCC 13.3.1, it has been
discovered that GCC is attempting to compile for RDRND on bdver4 arch CPUs.
Affected users specify -march=native, which resolves to -march=bdver4.

Docs state that bdver4 is a superset of Haswell, which implies the presence of
RDRND:

~ $ gcc -dM -E -march=bdver4 -xc /dev/null | grep RDRND
#define __RDRND__ 1


To quote from this
[https://bugreports.qt.io/browse/QTBUG-129193?focusedId=825891&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-825891]
comment, in the original Qt bug:

"Ok, so the problem is that this CPU is missing the random number generator
instructions, which all Intel CPU have had since Ivy Bridge (2013). That is a
problem, but not our problem here. Our problem here is that we have a mismatch
between what features are required at compile-time to enable __haswell__ and
which ones are checked at runtime for that CPU."

It is important to note that the Gentoo tool `resolve-march-native` returns
'-mno-rdrnd' as part of its resolution for an affected machine, however it
seems that even with this being the case, GCC compiles the affected Qt
libraries expecting RDRND as part of the feature set.

A final quote from the Qt bug:
"Apparently, for AMD Excavator (Bulldozer 4), GCC says that the RDRND ISA
extension is mandatory. That means QtCore assumes it's always present if you
compile with -march=bdver4 and that is likely to crash with SIGILL if you use
that flag."

NB: Affected users compiled with '-march=native' in all documented cases, and
allowed GCC to resolve the CPU arch and features.

~ $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/13/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-13.3.1_p20240614/work/gcc-13-20240614/configure
--host=x86_64-pc-lin
ux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/13 --includedir=/usr/lib/
gcc/x86_64-pc-linux-gnu/13/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/13
--mandir=/usr/share/gcc-data
/x86_64-pc-linux-gnu/13/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/13/info
--with-gxx-include-dir=/usr/li
b/gcc/x86_64-pc-linux-gnu/13/include/g++-v13 --disable-silent-rules
--disable-dependency-tracking --with-python-dir=
/share/gcc-data/x86_64-pc-linux-gnu/13/python --enable-languages=c,c++,fortran
--enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--disable-libunwind-exceptions --enable-
checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo Hardened 13.3.1_p20240614 p17' --w
ith-gcc-major-version-only --enable-libstdcxx-time --enable-lto
--disable-libstdcxx-pch --enable-shared --enable-thr
eads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib
--with-multilib-list=m32,m64 --disable-fixed
-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada
--enable-cet --disable-systemtap --di
sable-valgrind-annotations --disable-vtable-verify --disable-libvtv --with-zstd
--without-isl --enable-default-pie -
-enable-default-ssp --disable-fixincludes --with-build-config='bootstrap-lto
bootstrap-cet'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.3.1 20240614 (Gentoo Hardened 13.3.1_p20240614 p17)

Reply via email to