https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81693
--- Comment #24 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> Does gcc.dg/torture/pr25967-2.c pass for both -m32 and -m64?
Nope!
% /opt/gcc/gcc8w/bin/gcc /opt/gcc/work/gcc/testsuite/gcc.dg/torture/pr25967-2.c
-g
% lldb ./a.out
(lldb) target create "./a.out"
Current executable set to './a.out' (x86_64).
(lldb) run
Process 26493 launched: './a.out' (x86_64)
Process 26493 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
(code=EXC_I386_GPFLT)
frame #0: 0x00007fffbcb612fa libdyld.dylib`stack_not_16_byte_aligned_error
libdyld.dylib`stack_not_16_byte_aligned_error:
-> 0x7fffbcb612fa <+0>: movdqa %xmm0, (%rsp)
0x7fffbcb612ff <+5>: int3
libdyld.dylib`_dyld_func_lookup:
0x7fffbcb61300 <+0>: pushq %rbp
0x7fffbcb61301 <+1>: movq %rsp, %rbp
(lldb) b main
Breakpoint 1: where = a.out`main at pr25967-2.c:58, address =
0x0000000100000f50
(lldb) disass -a 0x0000000100000f50
a.out`main:
0x100000f50 <+0>: andq $-0x10, %rsp
0x100000f54 <+4>: pushq $0x12345675 ; imm = 0x12345675
0x100000f59 <+9>: pushq $0x12345674 ; imm = 0x12345674
0x100000f5e <+14>: pushq $0x12345673 ; imm = 0x12345673
0x100000f63 <+19>: pushq $0x12345672 ; imm = 0x12345672
0x100000f68 <+24>: pushq $0x12345671 ; imm = 0x12345671
0x100000f6d <+29>: jmp 0x100000eef ; fn at pr25967-2.c:39
0x100000f72 <+34>: movl $0x0, %eax
0x100000f77 <+39>: retq
Patched with
--- ../_clean/gcc/testsuite/gcc.dg/torture/pr25967-2.c 2017-08-02
13:33:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/torture/pr25967-2.c 2017-09-04 11:54:55.000000000
+0200
@@ -16,6 +16,12 @@ typedef unsigned int uword_t __attribute
#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname)
#define ASMNAME2(prefix, cname) XSTRING (prefix) cname
+#if __LP64__
+# define STACK_POINTER "rsp"
+#else
+# define STACK_POINTER "esp"
+#endif
+
struct interrupt_frame
{
uword_t ip;
@@ -48,7 +54,9 @@ fn (void)
int
main ()
{
- asm ("push $" STRING (SS) "; \
+ /* Align interrupt handler stack to 16 bytes. */
+ asm ("and $-16, %" STACK_POINTER "; \
+ push $" STRING (SS) "; \
push $" STRING (SP) "; \
push $" STRING (FLAGS) "; \
push $" STRING (CS) "; \