From owner-freebsd-hackers Sat Aug 25 5:45:56 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from segfault.kiev.ua (segfault.kiev.ua [193.193.193.4]) by hub.freebsd.org (Postfix) with ESMTP id 10C3D37B40A; Sat, 25 Aug 2001 05:45:44 -0700 (PDT) (envelope-from netch@iv.nn.kiev.ua) Received: (from uucp@localhost) by segfault.kiev.ua (8) with UUCP id PRN66402; Sat, 25 Aug 2001 15:45:33 +0300 (EEST) (envelope-from netch@iv.nn.kiev.ua) Received: (from netch@localhost) by iv.nn.kiev.ua (8.11.5/8.11.5) id f7PCiRI01110; Sat, 25 Aug 2001 15:44:27 +0300 (EEST) (envelope-from netch) Date: Sat, 25 Aug 2001 15:44:27 +0300 From: Valentin Nechayev To: John Baldwin Cc: "David O'Brien" , freebsd-hackers@FreeBSD.ORG, Steve Roome Subject: Re: function calls/rets in assembly Message-ID: <20010825154427.B761@iv.nn.kiev.ua> References: <20010824110805.C88259@dragon.nuxi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ; from jhb@FreeBSD.ORG on Fri, Aug 24, 2001 at 11:36:45AM -0700 X-42: On Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Fri, Aug 24, 2001 at 11:36:45, jhb (John Baldwin) wrote about "Re: function calls/rets in assembly": > > printasint: > > pushl %ebp > > movl %esp,%ebp > > subl $8,%esp > > addl $-8,%esp [...] > Because this code is broken and obfuscated? :) > > We save %esp in %ebp (the only thing that keeps it from breaking) then > for some > reason allocate two quadwords on the stack unnecessarily, one using an add > instruction, one using a sub. Because gcc has `-mpreferred-stack-boundary=4' default. Please read info gcc to realize what this option means. If you want to avoid this, compile with `-mpreferred-stack-boundary=2', as FreeBSD kernel is compiled. The only illogical thing here is that it doesn't gather two %esp moving instructions (one for frame of this function, one for frame for called function) to single one. > printasint: > pushl %ebp > movl %ebp, %esp > pushl 8(%ebp) > pushl $.LC0 > call printf > addl $8,%esp > leave > ret After reducing preferred stack boundary to 2**2: printasint: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax pushl %eax pushl $.LC0 call printf addl $8,%esp .L6: leave ret Well, unnesesary stack pointer shiftings disappeared. After calling with additional -O1: printasint: pushl %ebp movl %esp,%ebp pushl 8(%ebp) pushl $.LC0 call printf leave ret You can simply see that this assembly output is fully identical to one you requested. Well, now you should add wanted options to /etc/make.conf and avoid seeing of such nightmares. > Note that with hand optimizing, you could axe the addl after the call since > leave will clean up after that anyways. Also, you don't really need a frame > here anyways. In that case, you could just push 8(%esp) as your first > instruction and axe the leave (but leave the addl). /netch To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message