Bug 584 - Invalid relocation to protected symbol
Summary: Invalid relocation to protected symbol
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.15
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-26 13:50 UTC by Andreas Schwab
Modified: 2005-02-22 23:52 UTC (History)
1 user (show)

See Also:
Host:
Target: x86-64-*-*
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Schwab 2004-11-26 13:50:09 UTC
A call to a protected symbols is generating a R_X86_64_PC32 relocation
even though the linker cannot resolve that when generating a shared
library.

$ cat protected.c
void __attribute__ ((visibility ("protected"))) foo (void) {}
void bar (void) { return foo (); }
$ gcc -fPIC protected.c
$ objdump -r protected.o

protected.o:     file format elf64-x86-64

RELOCATION RECORDS FOR [.text]:
OFFSET           TYPE              VALUE 
000000000000000b R_X86_64_PC32     foo+0xfffffffffffffffc


RELOCATION RECORDS FOR [.eh_frame]:
OFFSET           TYPE              VALUE 
0000000000000020 R_X86_64_PC32     .text
0000000000000040 R_X86_64_PC32     .text+0x0000000000000006


$ gcc -shared protected.o
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.4/../../../../x86_64-suse-linux/bin/ld: protected.o: relocation R_X86_64_PC32 against `foo' can not be used when making a shared object; recompile with -fPIC
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.4/../../../../x86_64-suse-linux/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
Comment 1 Alan Modra 2004-11-26 21:54:57 UTC
The error message is wrong.  I don't see anything wrong with an input file
having an R_X86_64_PC32 to a protected symbol.  The linker should resolve this
without emitting a dynamic relocation to the shared lib.
Comment 2 H.J. Lu 2005-01-19 01:49:59 UTC
It is too bad that you can't tell if a relocation is for branch or for
load/store.