$ cat simpleif.c
#include <stdio.h>
extern unsigned int debug_enabled_abc;
int main(int argc, char** argv) {
        if (debug_enabled_abc)
                printf("Hello World!\n");
        return 0;
}
$ cat simple-debug.c
unsigned int debug_enabled_abc = 1;
$gcc -c simpleif.c -o simpleif.o -g -O3 -fPIC -fomit-frame-pointer
-march=nocona
$gcc -c simple-debug.c -o simple-debug.o -g -O3 -fPIC -fomit-frame-pointer
-march=nocona
$gcc simpleif.o simple-debug.o -o test -O3 -g -fPIC -fomit-frame-pointer
-march=nocona
$objdump  -d test | grep '<main>' -A10
00000000004004e8 <main>:
  4004e8:       48 83 ec 08             sub    $0x8,%rsp
  4004ec:       48 8b 05 8d 03 20 00    mov    0x20038d(%rip),%rax        #
600880 <_DYNAMIC+0x1a8>
  4004f3:       8b 00                   mov    (%rax),%eax
  4004f5:       85 c0                   test   %eax,%eax
  4004f7:       74 0c                   je     400505 <main+0x1d>
  4004f9:       48 8d 3d f8 00 00 00    lea    0xf8(%rip),%rdi        # 4005f8
<_IO_stdin_used+0x4>
  400500:       e8 0b ff ff ff          callq  400410 <[EMAIL PROTECTED]>
  400505:       31 c0                   xor    %eax,%eax
  400507:       48 83 c4 08             add    $0x8,%rsp
  40050b:       c3                      retq

Notice the 4004ec loads an 8 byte value, when it is specified as int.

$ gcc -c simpleif.c -o simpleif.o -g -O3  -fomit-frame-pointer -march=nocona
$ gcc simpleif.o simple-debug.o -o test -O3 -g -fPIC -fomit-frame-pointer
-march=nocona
$ objdump  -d test | grep '<main>' -A10
0000000000400498 <main>:
  400498:       48 83 ec 08             sub    $0x8,%rsp
  40049c:       8b 05 e6 03 20 00       mov    0x2003e6(%rip),%eax        #
600888 <debug_enabled_abc>
  4004a2:       85 c0                   test   %eax,%eax
  4004a4:       74 0a                   je     4004b0 <main+0x18>
  4004a6:       bf a8 05 40 00          mov    $0x4005a8,%edi
  4004ab:       e8 10 ff ff ff          callq  4003c0 <[EMAIL PROTECTED]>
  4004b0:       31 c0                   xor    %eax,%eax
  4004b2:       48 83 c4 08             add    $0x8,%rsp
  4004b6:       c3                      retq
  4004b7:       90                      nop


-- 
           Summary: Sub optimal code generated in -fPIC mode
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: davh at davh dot dk
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34593

Reply via email to