gcc 6.1 generates movaps for unaligned memory

Justus Schwartz justus@gmx.li
Fri Jun 24 11:41:00 GMT 2016


hi list,

switching to gcc 6.1.0 (on a x86_64 linux machine) we encountered a
crash of one of our binaries. i boiled this down to the following
code:

<code>
#include <cstdint>
struct Base  {
    alignas(16) int64_t mAligned=0;
};

struct Derived : public virtual Base {
public:
    int64_t m1;
    int64_t m2{ 1234 };
    int64_t m3{ 2345 };

  __attribute__ ((noinline)) // or put ctor into different compilation unit
    Derived(){}
};

struct TestBug : public virtual Derived {};


int main() {
    Derived derived; // good
    TestBug testbug; // crashes because of using movaps on unaligned memory
}
</code>

compiling this using -O3 like:
g++ -save-temps -Wall -Wextra -std=c++14  -ggdb -O3 -o /tmp/testbug
/tmp/testbug.cc

this generates the two expected versions for Derived::Derived(), but
both the complete object constructor and the base object constructor
use 'movaps' to write m2 and m3 at once. the problem is that inside of
TestBug m1 is not aligned on a 16byte boundary anymore. therefore this
code segfaults. (this was not the case with 5.3.0)

<assembly view in gdb>
0x4006f0 <Derived::Derived()>           movdqa 0x1d8(%rip),%xmm0
 # 0x4008d0
0x4006f8 <Derived::Derived()+8>         movq   $0x400878,(%rdi)
0x4006ff <Derived::Derived()+15>        movaps %xmm0,0x10(%rdi)
0x400703 <Derived::Derived()+19>        retq
0x400704                                nopw   %cs:0x0(%rax,%rax,1)
0x40070e                                xchg   %ax,%ax
0x400710 <Derived::Derived()>           movdqa 0x1b8(%rip),%xmm0
 # 0x4008d0
0x400718 <Derived::Derived()+8>         movq   $0x0,0x20(%rdi)
0x400720 <Derived::Derived()+16>        movq   $0x400860,(%rdi)
0x400727 <Derived::Derived()+23>        movaps %xmm0,0x10(%rdi)
0x40072b <Derived::Derived()+27>        retq
</assembly view in gdb>

i also checked out svn trunk (Revision: 237730) and this shows the
same behaviour.

could somebody advice me if i should open a bug for this? and if so
which additional information i should provide.

thanks
   /justus



More information about the Gcc-help mailing list