[MDEV-23900] x86_32 fail to build on innodb crc32q Created: 2020-10-06  Updated: 2020-11-09  Resolved: 2020-11-09

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Daniel Black Assignee: Marko Mäkelä
Resolution: Incomplete Votes: 0
Labels: need_feedback, not-10.1, not-10.5
Environment:

x86_32


Issue Links:
Relates
relates to MDEV-19935 Create unified CRC-32 interface Closed
relates to MDEV-20386 Replace inline asm with compiler-buil... Closed
relates to MDEV-22669 InnoDB lacks CRC-32C acceleration on ... Closed

 Description   

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=970662

storage/innobase/ut/ut0crc32.cc is gone from the 10.5.5 branch now

bug marked as not effecting 10.4 might just be them hitting the MSAN path
I
Downstream patch:

https://salsa.debian.org/mariadb-team/mariadb-10.5/-/commit/2920d282168f0986430f2feb65273af04ecb2240



 Comments   
Comment by Marko Mäkelä [ 2020-10-07 ]

Indeed, related to MDEV-20386, in 10.5 I replaced the inline assembler code with equivalent wrapper functions, and in MDEV-19935 the code was refactored further.

The patch suggests to replace the generic (register or memory) operand "%0" with "%q0". GCC documentation does not cover the x32 mode of AMD64 very well. I cannot even find a separate section for AMD64; it seems to be covered by the x86 section, which documents the suggested q prefix as follows:

Any register accessible as 'Rl'. In 32-bit mode, 'a', 'b', 'c', and 'd'; in 64-bit mode, any integer register.

As far as I understand, replacing the "%0" with "%q0" would no longer allow the operand to be a memory address.

Let us try to understand what the original code does:

  asm("crc32q %1, %0" : "+r" (crc) : "rm" (data));

First, this is AT&T syntax, and hence the target operand ("%0" is an alias for the read-modify-write register constraint "+r" holding the variable crc) is specified last, and the q suffix explicitly specifies 64-bit operand size. In Intel syntax (quoting the Intel® SSE4 Programming Reference, July 2007, page 61), this should match the following instruction:

CRC32 r64, r/m64

Most notably, all variants specified on that page specify the target operand (first operand in Intel syntax, corresponding to the second operand "%0" above) as a register.

All in all, it would seem to be perfectly OK to specify "%q0" instead of "%0" as the target operand on AMD64 or its ABI subset x32:

  • It remains 'any integer register'.
  • The SSE4.2 CRC32 instructions never allowed the read-modify-write operand to be memory, only a register.

It might not be equivalent to specify "%q0" for IA-32 mode (if any other registers than eax,ebx,ecx,edx were possible in the first place), but the patch (against an older 10.5 version) was not suggesting that.

Comment by Marko Mäkelä [ 2020-10-07 ]

Debian does package MariaDB Server 10.3, and apparently, only starting with the current Debian Sid (unstable), for x32: https://packages.debian.org/sid/mariadb-server-10.3

An x32 package seems to be available. Does it include a similar patch? The linked patch was only applicable to an earlier release in the 10.5 branch. Let me check:

apt source mariadb-server-10.3
cd mariadb-10.3-10.3.24
grep -lrwi x32

This seems to return mostly irrelevant matches:

mariadb-10.3-10.3.24 files referencing x32

debian/rules
debian/changelog
extra/yassl/taocrypt/test/test.cpp
libmariadb/unittest/libmariadb/dyncol.c
unittest/mysys/aes-t.c
storage/connect/mysql-test/connect/std_data/JdbcMariaDB.jar
storage/mroonga/vendor/groonga/benchmark/fixtures/geo-select/13_2010.CSV.xz
storage/mroonga/vendor/groonga/lib/nfkc50.c
storage/mroonga/vendor/groonga/lib/str.c
storage/tokudb/PerconaFT/third_party/xz-4.999.9beta/m4/libtool.m4
storage/tokudb/PerconaFT/third_party/xz-4.999.9beta/configure
storage/tokudb/PerconaFT/third_party/snappy-1.1.2/aclocal.m4
storage/tokudb/PerconaFT/third_party/snappy-1.1.2/configure
storage/rocksdb/rocksdb/util/hash_test.cc

I think that only the two matches in debian could be relevant. Let us look closer:

grep -rwi x32 debian

debian/rules:# Skipped on the x32 ABI too; untested, but unlikely to work given i386 is not
debian/changelog:    platforms: alpha, powerpc, and x32

The CRC-32C code was improved several times in 10.5. Before MDEV-22669 in MariaDB Server 10.5.4, the SSE4.2 CRC-32C acceleration was only available on AMD64, not IA-32 (except on Microsoft Windows since MariaDB Server 10.2.11).

danblack, do we really have to do something? 10.3 apparently seems to compile just fine on x32. It looks like we could technically add the "%q0" constraint in 10.2, 10.3, 10.4, but is it necessary?

Generated at Thu Feb 08 09:25:54 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.