changeset 14127:8d9ae184cc0d

3912 crti needs to make sure _init and _fini are 16-byte stack aligned Reviewed by: Bryan Cantrill <bryan@joyent.com> Reviewed by: Keith M Wesolowski <wesolows@foobazco.org> Reviewed by: Adam Leventhal <ahl@delphix.com> Approved by: Dan McDonald <danmcd@nexenta.com>
author Robert Mustacchi <rm@joyent.com>
date Tue, 23 Jul 2013 21:24:17 +0000
parents 62364715172d
children 615580eeb3d8
files usr/src/lib/common/i386/crti.s
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/lib/common/i386/crti.s	Thu Jan 17 00:48:10 2013 +0000
+++ b/usr/src/lib/common/i386/crti.s	Tue Jul 23 21:24:17 2013 +0000
@@ -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 @@
 _fini:
 	pushl	%ebp
 	movl	%esp, %ebp
+	andl	$-16,%esp
+	subl	$12,%esp
 	pushl	%ebx
 	call	.L2
 .L2:	popl	%ebx