https://sourceware.org/bugzilla/show_bug.cgi?id=24462
Bug ID: 24462 Summary: Gold linker does not handle symbol versioning properly Product: binutils Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: gold Assignee: ccoutant at gmail dot com Reporter: olim at ucla dot edu CC: ian at airs dot com Target Milestone: --- The gold linker does not appear to grab the correct symbol version when when using the --wrap option and multiple versions of the same symbol are available. For example, using `--wrap=memcpy` with the following code produces an infinite recursion. ``` #include <string.h> asm (".symver old_memcpy, memcpy@GLIBC_2.2.5"); // hook old_memcpy as memcpy@2.2.5 void *old_memcpy(void *, const void *, size_t ); void *__wrap_memcpy(void *dest, const void *src, size_t n) // then export memcpy { return old_memcpy(dest, src, n); } int main() { int v1 = 1; int v2 = 0; __wrap_memcpy(v1, v2, sizeof(v1)); return 0; } ``` $ gcc -fuse-ld=gold -Wl,--wrap=memcpy main.c $ readelf -a a.out | grep memcpy 5: 0000000000400660 2 FUNC GLOBAL DEFAULT 11 __wrap_memcpy 23: 0000000000400660 2 FUNC GLOBAL DEFAULT 11 __wrap_memcpy Using the BFD linker everything behaves as expected: $ gcc -fuse-ld=bfd -Wl,--wrap=memcpy main.c $ readelf -a a.out | grep memcpy 000000600fe0 000100000007 R_X86_64_JUMP_SLO 0000000000000000 memcpy@GLIBC_2.2.5 + 0 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memcpy@GLIBC_2.2.5 (2) 51: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memcpy@GLIBC_2.2.5 53: 0000000000400710 5 FUNC GLOBAL DEFAULT 13 __wrap_memcpy Using the gold linker again, but replacing asm (".symver old_memcpy, memcpy@GLIBC_2.2.5"); with asm (".symver old_memcpy, __real_memcpy@GLIBC_2.2.5"); avoid the infinite recursion, but links against the wrong version $ readelf -a a.out | grep memcpy 000000401ff0 000200000007 R_X86_64_JUMP_SLO 0000000000000000 memcpy@GLIBC_2.14 + 0 2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memcpy@GLIBC_2.14 (3) 7: 0000000000400790 5 FUNC GLOBAL DEFAULT 13 __wrap_memcpy 23: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memcpy 25: 0000000000400790 5 FUNC GLOBAL DEFAULT 13 __wrap_memcpy Which is linking to the memcpy in GLIBC_2.14 instead of the memcpy in GLIBC_2.2.5. Is there a different symbol versioning syntax needed when using the gold linker? -- 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