After upgrading gcc from 9.3.0-r2 to 10.2.0-r5, mariadb is miscompiled. It crashes with illegal instruction immediately. CPU is Pentium III-based Celeron (= without SSE2). "objdump -d | grep xmm" on the binaries confirms that they contain SSE2 instructions. Seems that mariadb build is broken - uses -msse4.2 flag when it's supported by the compiler, not the CPU. Reproducible: Always Steps to Reproduce: 1. Compile mariadb with gcc 10.2 on x86 2. Run mariadb on a CPU without SSE2 Actual Results: Crashes with illegal instruction Expected Results: Run, not crash # emerge --info Portage 3.0.17 (python 3.8.8-final-0, default/linux/x86/17.0, gcc-10.2.0, glibc-2.32-r7, 5.10.27-gentoo-main i686) ================================================================= System uname: Linux-5.10.27-gentoo-main-i686-Intel-R-_Celeron-TM-_CPU_1300MHz-with-glibc2.1.3 KiB Mem: 512200 total, 41748 free KiB Swap: 1012920 total, 887004 free Timestamp of repository gentoo: Wed, 14 Apr 2021 01:00:01 +0000 Head commit of repository gentoo: cb2ffeb383f06bc5957f6c3c0ee888359d65381c sh bash 5.0_p18 ld GNU ld (Gentoo 2.35.2 p1) 2.35.2 app-shells/bash: 5.0_p18::gentoo dev-lang/perl: 5.30.3::gentoo dev-lang/python: 3.8.8_p1::gentoo, 3.9.2_p1::gentoo dev-util/cmake: 3.18.5::gentoo dev-util/pkgconfig: 0.29.2::gentoo sys-apps/baselayout: 2.7::gentoo sys-apps/openrc: 0.42.1-r1::gentoo sys-apps/sandbox: 2.20::gentoo sys-devel/autoconf: 2.69-r5::gentoo sys-devel/automake: 1.16.2-r1::gentoo sys-devel/binutils: 2.35.2::gentoo sys-devel/gcc: 9.3.0-r2::gentoo, 10.2.0-r5::gentoo sys-devel/gcc-config: 2.4::gentoo sys-devel/libtool: 2.4.6-r6::gentoo sys-devel/make: 4.3::gentoo sys-kernel/linux-headers: 5.10::gentoo (virtual/os-headers) sys-libs/glibc: 2.32-r7::gentoo Repositories: gentoo location: /usr/portage sync-type: rsync sync-uri: rsync://rsync.gentoo.org/gentoo-portage priority: -1000 sync-rsync-verify-jobs: 1 sync-rsync-verify-max-age: 24 sync-rsync-extra-opts: --exclude-from=/etc/portage/sync.exclude sync-rsync-verify-metamanifest: no ACCEPT_KEYWORDS="x86" ACCEPT_LICENSE="* -@EULA" CBUILD="i686-pc-linux-gnu" CFLAGS="-O3 -march=i686 -fomit-frame-pointer" CHOST="i686-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt /var/bind" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.4/ext-active/ /etc/php/cgi-php7.4/ext-active/ /etc/php/cli-php7.4/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo" CXXFLAGS="-O3 -march=i686 -fomit-frame-pointer" DISTDIR="/usr/portage/distfiles" EMERGE_DEFAULT_OPTS="--with-bdeps y" ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR" FCFLAGS="-O2 -march=i686 -pipe" FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg collision-protect config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync" FFLAGS="-O2 -march=i686 -pipe" GENTOO_MIRRORS="http://mirror.wheel.sk/gentoo ftp://tux.rainside.sk/gentoo/ ftp://ftp.fi.muni.cz/pub/linux/gentoo/ ftp://gentoo.mirror.web4u.cz/" LANG="en_US.UTF-8" LDFLAGS="-Wl,-O1 -Wl,--as-needed" LINGUAS="en sk" MAKEOPTS="-j1" PKGDIR="/usr/portage/packages" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_EXTRA_OPTS="--exclude-from=/etc/portage/sync.exclude" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git" PORTAGE_TMPDIR="/var/tmp/portage" USE="apache2 bzip2 caps chroot cli crypt dri gmp iconv idn imap ipv6 jpeg libglvnd libtirpc mbox mmx ncurses nls nptl nptlonly pam pcre pdflib png readline seccomp split-usr ssl tcpd truetype unicode urandom x86 xattr zlib" ABI_X86="32" ADA_TARGET="gnat_2018" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="alias auth_basic auth_digest authn_core authn_default authn_file authz_core authz_default authz_groupfile authz_host authz_owner authz_user autoindex cgi dbd deflate dir env expires ext_filter filter headers info log_config logio mime mime_magic negotiation rewrite setenvif socache_shmcb status unixd unique_id usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="pc" INPUT_DEVICES="libinput" KERNEL="linux" L10N="en sk" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_8" PYTHON_TARGETS="python3_8" RUBY_TARGETS="ruby26" USERLAND="GNU" VIDEO_CARDS="amdgpu fbdev intel nouveau radeon radeonsi vesa dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account" Unset: CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, RUSTFLAGS
Created attachment 699801 [details] build log partial build log, long enough to produce broken files (e.g. crc32c.cc.o) (full build takes over 4 hours)
Created attachment 699804 [details] build log with gcc 9.3.0 Partial build log with gcc 9.3.0. No differences (except compiler version) according to diff. crc32_x86.c.o contains SSE2 instructions but crc32c.cc.o does not.
Seems that gcc 9.3 correctly ignores -msse4.2 and -mpclmul when used with -march=i686 but gcc 10.2 does not. Testing manually: /var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mariadb-10.5.9_build # /usr/i686-pc-linux-gnu/gcc-bin/9.3.0/i686-pc-linux-gnu-g++ -DDBUG_TRACE -DHAVE_CONFIG_H -DHAVE_PCLMUL -DHAVE_SSE42 -D_FILE_OFFSET_BITS=64 -Iinclude -I/var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mysql/include -I/var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mysql/mysys -O3 -march=i686 -fomit-frame-pointer -felide-constructors -fno-strict-aliasing -pie -fPIC -fstack-protector --param=ssp-buffer-size=4 -DNDEBUG -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 -DDBUG_OFF -Wall -Wextra -Wformat-security -Wno-format-truncation -Wno-init-self -Wno-nonnull-compare -Wno-unused-parameter -Woverloaded-virtual -Wnon-virtual-dtor -Wvla -Wwrite-strings -fPIC -std=gnu++11 -msse4.2 -mpclmul -MD -MT mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o -MF mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o.d -o mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o -c /var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mysql/mysys/crc32/crc32c.cc /var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mariadb-10.5.9_build # objdump -d mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o | grep xmm /var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mariadb-10.5.9_build # /var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mariadb-10.5.9_build # /usr/i686-pc-linux-gnu/gcc-bin/10.2.0/i686-pc-linux-gnu-g++ -DDBUG_TRACE -DHAVE_CONFIG_H -DHAVE_PCLMUL -DHAVE_SSE42 -D_FILE_OFFSET_BITS=64 -Iinclude -I/var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mysql/include -I/var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mysql/mysys -O3 -march=i686 -fomit-frame-pointer -felide-constructors -fno-strict-aliasing -pie -fPIC -fstack-protector --param=ssp-buffer-size=4 -DNDEBUG -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 -DDBUG_OFF -Wall -Wextra -Wformat-security -Wno-format-truncation -Wno-init-self -Wno-nonnull-compare -Wno-unused-parameter -Woverloaded-virtual -Wnon-virtual-dtor -Wvla -Wwrite-strings -fPIC -std=gnu++11 -msse4.2 -mpclmul -MD -MT mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o -MF mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o.d -o mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o -c /var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mysql/mysys/crc32/crc32c.cc /var/tmp/portage/portage/dev-db/mariadb-10.5.9-r4/work/mariadb-10.5.9_build # objdump -d mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o | grep xmm 36: 66 0f 6e 45 e0 movd -0x20(%ebp),%xmm0 3b: 66 0f 3a 22 45 e4 01 pinsrd $0x1,-0x1c(%ebp),%xmm0 55: 66 0f 73 d0 08 psrlq $0x8,%xmm0 6a: 66 0f 6e c9 movd %ecx,%xmm1 6e: 66 0f 3a 22 cb 01 pinsrd $0x1,%ebx,%xmm1 74: 66 0f ef c1 pxor %xmm1,%xmm0 78: 66 0f 7e 45 e0 movd %xmm0,-0x20(%ebp) 7d: 66 0f 3a 16 45 e4 01 pextrd $0x1,%xmm0,-0x1c(%ebp) c6: 66 0f 6e c1 movd %ecx,%xmm0 cc: 66 0f 3a 22 c2 01 pinsrd $0x1,%edx,%xmm0 107: 66 0f 6e c2 movd %edx,%xmm0 110: 66 0f 3a 22 c3 01 pinsrd $0x1,%ebx,%xmm0 135: 66 0f 73 d0 08 psrlq $0x8,%xmm0 14a: 66 0f 6e c9 movd %ecx,%xmm1 14e: 66 0f 3a 22 cb 01 pinsrd $0x1,%ebx,%xmm1 154: 66 0f ef c1 pxor %xmm1,%xmm0 158: 66 0f 7e 45 e0 movd %xmm0,-0x20(%ebp) 15d: 66 0f 3a 16 45 e4 01 pextrd $0x1,%xmm0,-0x1c(%ebp) 1bb: 66 0f 6e 45 e0 movd -0x20(%ebp),%xmm0 1c0: 66 0f 3a 22 45 e4 01 pinsrd $0x1,-0x1c(%ebp),%xmm0 1eb: 66 0f 73 d0 08 psrlq $0x8,%xmm0 1fa: 66 0f 6e c9 movd %ecx,%xmm1 1fe: 66 0f 3a 22 cb 01 pinsrd $0x1,%ebx,%xmm1 204: 66 0f ef c1 pxor %xmm1,%xmm0 208: 66 0f 7e 45 e0 movd %xmm0,-0x20(%ebp) 20d: 66 0f 3a 16 45 e4 01 pextrd $0x1,%xmm0,-0x1c(%ebp) 326: 66 0f 6e c7 movd %edi,%xmm0 32c: 66 0f 3a 22 c3 01 pinsrd $0x1,%ebx,%xmm0 3ee: 66 0f 6e c2 movd %edx,%xmm0 3f4: 66 0f 3a 22 c3 01 pinsrd $0x1,%ebx,%xmm0 42b: 66 0f 73 d0 08 psrlq $0x8,%xmm0 43a: 66 0f 6e c9 movd %ecx,%xmm1 43e: 66 0f 3a 22 cb 01 pinsrd $0x1,%ebx,%xmm1 444: 66 0f ef c1 pxor %xmm1,%xmm0 448: 66 0f 7e 45 e0 movd %xmm0,-0x20(%ebp) 44d: 66 0f 3a 16 45 e4 01 pextrd $0x1,%xmm0,-0x1c(%ebp)
Looks like mariadb developers tried to be smart by always compiling crc32c.cc with -msse4.2 and -mpclmul flags. They probably expected that the compiler will not use SSE2+ instructions by itself, only where the intrinsics are used. mysql/mysys/CMakeLists.txt: ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i386|i686") MY_CHECK_C_COMPILER_FLAG(-msse4.2) MY_CHECK_C_COMPILER_FLAG(-mpclmul) CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H) CHECK_INCLUDE_FILE(x86intrin.h HAVE_X86INTRIN_H) IF(have_C__msse4.2 AND have_C__mpclmul AND HAVE_CPUID_H AND HAVE_X86INTRIN_H) SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c crc32/crc32c.cc PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") ADD_DEFINITIONS(-DHAVE_SSE42 -DHAVE_PCLMUL) ENDIF() This seemed to work until now but it obviously does not work anymore. gcc 10 outsmarted them and optimized Slow_CRC32() using SSE4 instructions: # objdump -d mysys/CMakeFiles/mysys.dir/crc32/crc32c.cc.o ... 00000180 <_ZN15mysys_namespace6crc32c10ExtendImplIXadL_ZNS0_L10Slow_CRC32EPyPPKhEEEEjjPKcj>: ^^^^^^^^^^ 180: 55 push %ebp 181: 89 e5 mov %esp,%ebp 183: 57 push %edi 184: 56 push %esi 185: 53 push %ebx 186: e8 fc ff ff ff call 187 <_ZN15mysys_namespace6crc32c10ExtendImplIXadL_ZNS0_L10Slow_CRC32EPyPPKhEEEEjjPKcj+0x7> 18b: 81 c7 02 00 00 00 add $0x2,%edi 191: 83 ec 2c sub $0x2c,%esp 194: 8b 45 0c mov 0xc(%ebp),%eax 197: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp) 19e: 8b 5d 10 mov 0x10(%ebp),%ebx 1a1: 8b 4d 08 mov 0x8(%ebp),%ecx 1a4: 8d 50 0f lea 0xf(%eax),%edx 1a7: 89 7d c8 mov %edi,-0x38(%ebp) 1aa: 89 d6 mov %edx,%esi 1ac: 01 c3 add %eax,%ebx 1ae: 89 5d d0 mov %ebx,-0x30(%ebp) 1b1: f7 d1 not %ecx 1b3: 83 e6 f0 and $0xfffffff0,%esi 1b6: 89 4d e0 mov %ecx,-0x20(%ebp) 1b9: 39 f3 cmp %esi,%ebx 1bb: 66 0f 6e 45 e0 movd -0x20(%ebp),%xmm0 1c0: 66 0f 3a 22 45 e4 01 pinsrd $0x1,-0x1c(%ebp),%xmm0 ^^^^^^ ...
This is already scheduled for next release, https://github.com/MariaDB/server/commit/58f184a4cbc98e151fdd9533f3907e73a17fdf51
Great! Hopefully it gets into Gentoo soon.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d0a5513049e8323a50d1798525e677056832e81b commit d0a5513049e8323a50d1798525e677056832e81b Author: Thomas Deutschmann <whissi@gentoo.org> AuthorDate: 2021-04-14 14:46:49 +0000 Commit: Thomas Deutschmann <whissi@gentoo.org> CommitDate: 2021-04-14 14:46:58 +0000 dev-db/mariadb: update patch set Bug: https://bugs.gentoo.org/782703 Bug: https://bugs.gentoo.org/782796 Package-Manager: Portage-3.0.18, Repoman-3.0.3 Signed-off-by: Thomas Deutschmann <whissi@gentoo.org> dev-db/mariadb/Manifest | 1 + dev-db/mariadb/mariadb-10.5.9-r5.ebuild | 1294 +++++++++++++++++++++++++++++++ 2 files changed, 1295 insertions(+)
Could you please confirm if >=dev-db/mariadb-10.5.9-r5 works for you?
mariadb-10.5.9-r5 works fine - thanks you for such a quick fix!