Date: Wed, 12 Jun 2002 11:14:59 -0700 From: Bakul Shah <bakul@bitblocks.com> To: hackers@freebsd.org Cc: jdp@freebsd.org Subject: linker bug? Message-ID: <200206121815.OAA26361@warspite.cnchost.com>
next in thread | raw e-mail | index | archive | help
In order to measure call overhead on an Athlon XP system I
compiled and ran the following program and saw some curious
results!
$ cat foo.c
#include <stdlib.h>
void func() { }
void (*funp)() = 0;
int main(int argc, char **argv) {
int i, j;
if (argv[1][0] != '?') /* defeat compile-time optimization */
funp = &func;
i = atoi(argv[1]);
for (j = i; j > 0; --j)
(*funp) ();
}
$ cc -O -fomit-frame-pointer foo.c
$ time a.out 1000000000
a.out 1000000000 4.11s user 0.01s system 97% cpu 4.215 total
Then I did a static link and saw the time increase by 10 seconds!
$ cc -O -fomit-frame-pointer -static foo.c
$ time a.out 1000000000
a.out 1000000000 14.28s user 0.01s system 96% cpu 14.759 total
nm reveals the problem.
$ cc -O -fomit-frame-pointer foo.c && nm a.out |grep func
08048490 T func
$ cc -O -fomit-frame-pointer -static foo.c && nm a.out |grep func
080481c4 T func
Here is what
void func() {}
gets compiled to:
.p2align 2,0x90
.globl func
.type func,@function
func:
ret
This is on a 4.6-RC system with gcc-2.95.3. The fact that
func is aligned on a 16 byte boundary in the -dynamic case is
likely conincidental. gcc-3.1 seems to put it on an 8 byte
with -dynamic and 4 byte boundary with -static.
So the question is: does the linker ignore alignment
altogether or did I miss some magic flag?
-- bakul
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206121815.OAA26361>
