align stack properly for calling global ctors/dtors on x86[_64]
authorRich Felker <dalias@aerifal.cx>
Mon, 3 Jun 2013 21:32:42 +0000 (17:32 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 3 Jun 2013 21:32:42 +0000 (17:32 -0400)
failure to do so was causing crashes on x86_64 when ctors used SSE,
which was first observed when ctors called variadic functions due to
the SSE prologue code inserted into every variadic function.

crt/i386/crti.s
crt/i386/crtn.s
crt/x86_64/crti.s
crt/x86_64/crtn.s

index 2eb23ed..d2682a2 100644 (file)
@@ -1,7 +1,9 @@
 .section .init
 .global _init
 _init:
 .section .init
 .global _init
 _init:
+       sub $12,%esp
 
 .section .fini
 .global _fini
 _fini:
 
 .section .fini
 .global _fini
 _fini:
+       sub $12,%esp
index 055451e..f3b61e0 100644 (file)
@@ -1,5 +1,7 @@
 .section .init
 .section .init
+       add $12,%esp
        ret
 
 .section .fini
        ret
 
 .section .fini
+       add $12,%esp
        ret
        ret
index 2eb23ed..4788968 100644 (file)
@@ -1,7 +1,9 @@
 .section .init
 .global _init
 _init:
 .section .init
 .global _init
 _init:
+       push %rax
 
 .section .fini
 .global _fini
 _fini:
 
 .section .fini
 .global _fini
 _fini:
+       push %rax
index 055451e..29198b7 100644 (file)
@@ -1,5 +1,7 @@
 .section .init
 .section .init
+       pop %rax
        ret
 
 .section .fini
        ret
 
 .section .fini
+       pop %rax
        ret
        ret