From a86e931db9089f6b514c9b98b206d0eb2c1a2a34 Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Tue, 23 Jul 2013 21:24:17 +0000 Subject: [PATCH] 3912 crti needs to make sure _init and _fini are 16-byte stack aligned Reviewed by: Bryan Cantrill Reviewed by: Keith M Wesolowski Reviewed by: Adam Leventhal Approved by: Dan McDonald --- usr/src/lib/common/i386/crti.s | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/usr/src/lib/common/i386/crti.s b/usr/src/lib/common/i386/crti.s index a79443315c..af177b8332 100644 --- a/usr/src/lib/common/i386/crti.s +++ b/usr/src/lib/common/i386/crti.s @@ -23,6 +23,9 @@ * Copyright (c) 2001 by Sun Microsystems, Inc. * All rights reserved. */ +/* + * Copyright (c) 2013, Joyent, Inc. All rights reserved. + */ /* * These crt*.o modules are provided as the bare minimum required @@ -34,10 +37,19 @@ * For further details - see bug#4433015 */ - .ident "%Z%%M% %I% %E% SMI" .file "crti.s" /* + * Note that when _init and _fini are called we have 16-byte alignment per the + * ABI. We need to make sure that our asm leaves it such that subsequent calls + * will be aligned. gcc expects stack alignment before the call instruction is + * executed. Specifically if we call function foo(), the stack pointer will be + * 0xc aligned after executing the call instruction and before executing foo's + * prologue. Note that because 16-byte alignment also ensures 4-byte alignment + * we will not be breaking compatibility with older applications. + */ + +/* * _init function prologue */ .section .init,"ax" @@ -47,6 +59,8 @@ _init: pushl %ebp movl %esp, %ebp + andl $-16,%esp + subl $12,%esp pushl %ebx call .L1 .L1: popl %ebx @@ -62,6 +76,8 @@ _init: _fini: pushl %ebp movl %esp, %ebp + andl $-16,%esp + subl $12,%esp pushl %ebx call .L2 .L2: popl %ebx -- 2.11.4.GIT