[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Specify how undefined weak symbol should be resolved in executable
Currently when building executable, undefined weak symbol is resolved
differently, depending on if the relocatable input is compiled with PIC or
not:
hjl@gnu-tools-1 weak-1]$ cat x.c
extern void __attribute__ ((weak)) fun (void);
int main (void)
{
if (&fun != 0)
fun ();
return 0;
}
[hjl@gnu-tools-1 weak-1]$ make
gcc -B./ -O2 -o x x.c
gcc -B./ -O2 -o y x.c -fPIC
readelf -r x
Relocation section '.rela.dyn' at offset 0x328 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000600870 000200000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
Relocation section '.rela.plt' at offset 0x340 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000600890 000100000007 R_X86_64_JUMP_SLO 0000000000000000
__libc_start_main@GLIBC_2.2.5 + 0
There is no dynamic relocation against fun, whose value is
resolved to zero at link-time.
readelf -r y
Relocation section '.rela.dyn' at offset 0x348 contains 2 entries:
Offset Info Type Sym. Value Sym. Name + Addend
0000006008a0 000100000006 R_X86_64_GLOB_DAT 0000000000000000 fun + 0
0000006008a8 000300000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
Relocation section '.rela.plt' at offset 0x378 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
0000006008c8 000200000007 R_X86_64_JUMP_SLO 0000000000000000
__libc_start_main@GLIBC_2.2.5 + 0
[hjl@gnu-tools-1 weak-1]$
There is dynamic relocation against fun, whose value is resolved
at runt-time. We should make it consistent, regardless if input
relocatable file is compiled with PIC or not.
I raised the issue at gABI:
https://groups.google.com/d/msg/generic-abi/Ckq19PfLxyk/eCbXPofkAQAJ
But if gABI change is incompatible with other OSes, we need to
specify it in GNU ABI.
--
H.J.