https://sourceware.org/bugzilla/show_bug.cgi?id=20512
Bug ID: 20512 Summary: Assertion failure with relocation against symbol #0 Product: binutils Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: gold Assignee: ccoutant at gmail dot com Reporter: aabel at google dot com CC: ian at airs dot com Target Milestone: --- Here is a minimal example: bug.c: ----------------------------------------------------------------- extern int __a; static int __attribute__((__used__)) A (void) { return &__a>(int*)1; } ----------------------------------------------------------------- bug.lds: ----------------------------------------------------------------- OUTPUT_FORMAT("elf64-x86-64") SECTIONS { __a = .; } ---------------------------------------------------------------- Commands: $ gcc -fPIC -O2 -c -o bug_1.o bug.c $ ld -r -o bug_2.o -T bug.lds bug_1.o $ objcopy bug_2.o bug_3.o $ ld -shared -o libbug.so bug_3.o If the program is compiled like this, the assertion "this->local_sym_index_ != 0" in line 1144 in output.cc fails. If we use bug_2.o instead of bug_3.o in the last step, the problem does not occur. One difference between bug_2.o and bug_3.o is the following: readelf -r bug_2.o: Relocation section '.rela.text' at offset 0xe8 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000000005 000500000009 R_X86_64_GOTPCREL 0000000000000000 __a - 5 readelf -r bug_3.o: Relocation section '.rela.text' at offset 0x570 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000000005 000000000009 R_X86_64_GOTPCREL -5 So objcopy changes the relocation from a relocation against symbol #5 (which is __a, and has the value 0) to a relocation against symbol #0 (which is required to be a symbol with value 0). According to https://sourceware.org/ml/binutils/2004-03/msg00020.html "a reloc against that symbol is well-defined." When gold tries to write out this relocation against symbol 0 (i.e., local_sym_index_==0), the assertion mentioned above fails. -- 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