From owner-freebsd-hackers Wed Jun 12 11:15: 9 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from warspite.cnchost.com (warspite.concentric.net [207.155.248.9]) by hub.freebsd.org (Postfix) with ESMTP id E6B6F37B405; Wed, 12 Jun 2002 11:15:02 -0700 (PDT) Received: from bitblocks.com (adsl-209-204-185-216.sonic.net [209.204.185.216]) by warspite.cnchost.com id OAA26361; Wed, 12 Jun 2002 14:15:02 -0400 (EDT) [ConcentricHost SMTP Relay 1.14] Message-ID: <200206121815.OAA26361@warspite.cnchost.com> To: hackers@freebsd.org Cc: jdp@freebsd.org Subject: linker bug? Date: Wed, 12 Jun 2002 11:14:59 -0700 From: Bakul Shah 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 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 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