Bug #87298 main.func_bitwise_ops dies with unaligned access
Submitted: 3 Aug 2017 8:42 Modified: 6 Sep 2017 17:58
Reporter: Steinar Gunderson Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[3 Aug 2017 8:42] Steinar Gunderson
On GCC 7, main.func_bitwise_ops dies with

/srv/sesse/mysql/obj/runtime_output_directory/mysqld(String* Item_func_bit_two_param::eval_str_op<std::bit_and<char>, std::bit_and<unsigned long long> >(String*, std::bit_and<char>, std::bit_and<unsigned long long>)+0x322) [0x5555563f2712]
/srv/sesse/mysql/obj/runtime_output_directory/mysqld(Item_func_bit_and::str_op(String*)+0xd) [0x5555562ad5fd]
/srv/sesse/mysql/obj/runtime_output_directory/mysqld(Item_func_hex::val_str_ascii(String*)+0x79) [0x555556408909]

The base problem is that the compiler has managed to vectorize the two ANDs:

   0x00005555563f270a <+794>:   movdqa %xmm1,%xmm2
   0x00005555563f270e <+798>:   add    $0x1,%rdx
=> 0x00005555563f2712 <+802>:   pand   (%r11,%rax,1),%xmm0
   0x00005555563f2718 <+808>:   paddq  %xmm3,%xmm2
   0x00005555563f271c <+812>:   movups %xmm0,(%rcx,%rax,1)

and PAND, unlike regular loads and stores, cannot take unaligned addresses on x86.

How to repeat:
Run the test.

Suggested fix:
uint8korr() should be corrected to explicitly to an unaligned load, instead of just doing a load and hoping that's fine.
[6 Sep 2017 17:58] Paul DuBois
Posted by developer:
Fixed in 8.0.3.

uint8korr() and related macros were fixed so that they explicitly do
unaligned accesses, even on x86.