Bug 676393 - `gcc -g -O2 -export-dynamic' produces broken objects
Summary: `gcc -g -O2 -export-dynamic' produces broken objects
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-02-09 17:49 UTC by Petr Pisar
Modified: 2011-02-09 18:00 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-02-09 18:00:59 UTC
Type: ---


Attachments (Terms of Use)
Resulting ELF (7.03 KB, application/octet-stream)
2011-02-09 17:51 UTC, Petr Pisar
no flags Details

Description Petr Pisar 2011-02-09 17:49:56 UTC
$ rpm -q gcc binutils
gcc-4.6.0-0.6.fc15.x86_64
binutils-2.21.51.0.5-3.fc15.x86_64

$ cat main.c 
int main (int argc, char **argv) {
  return 0;
}

$ gcc -g -O2 -export-dynamic main.c
/usr/bin/ld: warning: cannot find entry symbol xport-dynamic; defaulting to 0000000000400390

$ ./a.out 
Segmentation fault

$ gdb ./a.out 
GNU gdb (GDB) Fedora (7.2.50.20110206-18.fc15)
[...]
Reading symbols from /tmp/a.out...done.
(gdb) run
Starting program: /tmp/a.out 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000001 in ?? ()
(gdb) bt full
#0  0x0000000000000001 in ?? ()
No symbol table info available.
#1  0x00007fffffffe92e in ?? ()
No symbol table info available.
#2  0x0000000000000000 in ?? ()
No symbol table info available.
(gdb) info registers
rax            0x0      0
rbx            0x0      0
rcx            0xfff    4095
rdx            0x7ffff7dead30   140737351953712
rsi            0x200000 2097152
rdi            0x7ffff7ffe2a8   140737354130088
rbp            0x0      0x0
rsp            0x7fffffffe718   0x7fffffffe718
r8             0x1      1
r9             0x4      4
r10            0x4      4
r11            0x800    2048
r12            0x400390 4195216
r13            0x7fffffffe710   140737488348944
r14            0x0      0
r15            0x0      0
rip            0x1      0x1
eflags         0x10246  [ PF ZF IF RF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0

# cat /proc/$(pidof a.out)/maps
00400000-00401000 r-xp 00000000 fd:00 162013                             /tmp/a.out
00600000-00601000 rw-p 00000000 fd:00 162013                             /tmp/a.out
7ffff7a3f000-7ffff7bd1000 r-xp 00000000 fd:00 145876                     /lib64/libc-2.13.90.so
7ffff7bd1000-7ffff7dd1000 ---p 00192000 fd:00 145876                     /lib64/libc-2.13.90.so
7ffff7dd1000-7ffff7dd5000 r--p 00192000 fd:00 145876                     /lib64/libc-2.13.90.so
7ffff7dd5000-7ffff7dd6000 rw-p 00196000 fd:00 145876                     /lib64/libc-2.13.90.so
7ffff7dd6000-7ffff7ddc000 rw-p 00000000 00:00 0 
7ffff7ddc000-7ffff7dfc000 r-xp 00000000 fd:00 133487                     /lib64/ld-2.13.90.so
7ffff7fec000-7ffff7fef000 rw-p 00000000 00:00 0 
7ffff7ffa000-7ffff7ffb000 rw-p 00000000 00:00 0 
7ffff7ffb000-7ffff7ffc000 r-xp 00000000 00:00 0                          [vdso]
7ffff7ffc000-7ffff7ffd000 r--p 00020000 fd:00 133487                     /lib64/ld-2.13.90.so
7ffff7ffd000-7ffff7ffe000 rw-p 00021000 fd:00 133487                     /lib64/ld-2.13.90.so
7ffff7ffe000-7ffff7fff000 rw-p 00000000 00:00 0 
7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0                          [stack]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]


Compiling as: 
$ gcc -g -O1 -export-dynamic main.c
/usr/bin/ld: warning: cannot find entry symbol xport-dynamic; defaulting to 0000000000400390

warns at linking, but the program does not segfault.

Compiling as:
$ gcc -g -O2  main.c

does not warn and executable does not segfault.

Comment 1 Petr Pisar 2011-02-09 17:51:20 UTC
Created attachment 477875 [details]
Resulting ELF

Comment 2 Petr Pisar 2011-02-09 17:59:59 UTC
Per http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47390 it looks like bad invocation.

Comment 3 Jakub Jelinek 2011-02-09 18:00:59 UTC
User error, -export-dynamic is not a gcc driver option.
Use -rdynamic or -Wl,--export-dynamic or -Wl,-E instead.


Note You need to log in before you can comment on or make changes to this bug.