https://sourceware.org/bugzilla/show_bug.cgi?id=32854
Bug ID: 32854 Summary: Default versioned symbol in shared library is ignored with LTO Product: binutils Version: 2.45 (HEAD) Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: hjl.tools at gmail dot com Target Milestone: --- when a shared library defines 'foo@@FOO' (default version), a static archive defines 'foo', the shared lib comes in front of the archive and under effect of --as-needed, and the requesting object file uses LTO, then the link editor was wrongly including the definition from the static archive. It must use the one from the shared lib, like in the non-LTO or the --no-as-needed case. [hjl@gnu-tgl-3 lto-6]$ cat lto-20a.c extern int foo (); int main () { return foo (); } [hjl@gnu-tgl-3 lto-6]$ cat lto-20b.c extern int printf (const char *, ...); int foo () { #ifdef SHARED printf ("PASS\n"); return 0; #else printf ("FAIL\n"); return 1; #endif } [hjl@gnu-tgl-3 lto-6]$ cat lto-20.ver FOO { global: foo; }; [hjl@gnu-tgl-3 lto-6]$ make gcc -B./ -O2 -flto -c -o lto-20a.o lto-20a.c gcc -B./ -c -DSHARED -fPIC -O2 -o lto-20b-shared.o lto-20b.c ld -shared -o liblto-20.so --version-script=lto-20.ver lto-20b-shared.o gcc -B./ -c -fPIC -O2 -o lto-20b-static.o lto-20b.c ar -rv liblto-20_static.a lto-20b-static.o ar: creating liblto-20_static.a a - lto-20b-static.o gcc -B./ -O2 -Wl,--as-needed,-R,. -o x lto-20a.o liblto-20.so liblto-20_static.a -Wl,--no-as-needed ./x FAIL make: *** [Makefile:8: all] Error 1 [hjl@gnu-tgl-3 lto-6]$ -- You are receiving this mail because: You are on the CC list for the bug.