https://sourceware.org/bugzilla/show_bug.cgi?id=19704
Bug ID: 19704 Summary: Missing dynamic relocation against undefined weak symbol Product: binutils Version: 2.27 (HEAD) Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: hjl.tools at gmail dot com Target Milestone: --- 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. GNU ABI should be extended to: When creating executable, if dynamic relocation is available at run-time, the link editor should generate dynamic relocations against unresolved weak symbols so that their values will be resolved at run-time. -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils