https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92904
Bug ID: 92904 Summary: GCC generates movdqa instructions to unaligned memory Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: jesse.huard at dellteam dot com Target Milestone: --- Created attachment 47467 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47467&action=edit Preprocessed test source file for reproducing the issue. Compiling the attached test program on x86_64 with optimisations enabled produces code which segfaults in a movdqa instruction accessing unaligned memory. This was observed in code which passes an unsigned __int128 as a variadic function argument when we attempt to retrieve the argument with va_arg(). movdqa is expecting a 16-byte aligned memory location, but instead we get an unaligned address on the stack pointing to our variadic argument within the va_list's reg_save_area. This results in a segmentation fault. 12 b = va_arg(args, unsigned __int128); 0x000055555555517b <+50>: movl $0x18,(%rsp) => 0x0000555555555182 <+57>: movdqa 0x28(%rsp),%xmm0 # segfault here! 0x0000555555555188 <+63>: movaps %xmm0,0x2ec1(%rip) # 0x555555558050 <b> (gdb) p $rsp+0x28 $1 = (void *) 0x7fffffffe2d8 (gdb) p args $2 = {{gp_offset = 24, fp_offset = 0, overflow_arg_area = 0x7fffffffe310, reg_save_area = 0x7fffffffe2d0}} Compiler invocation: gcc -g -O1 test.c -o test GCC information: $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc Thread model: posix gcc version 9.2.0 (GCC) libc information: $ /usr/lib/libc.so.6 GNU C Library (GNU libc) stable release version 2.30. Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 9.2.0. libc ABIs: UNIQUE IFUNC ABSOLUTE