Created attachment 10638 [details] Reproducer for failure to incrementally link an executable with LTO Hi, Commit 5c3261b0e834647cf9eb555320e20871b7854f98 in binutils broke the ability to redefine a weak function in an LTO incrementally-linked executable. Reproducer is attached to this bug report. Running ./reproducer.sh shows the following error: test-intermediate: In function `main': /home/thopre01/issues/sjp/weak_lto_incremental_link/test-weak.c:8: undefined reference to `foobar' collect2: error: ld returned 1 exit status Best regards, Thomas
A simpler way to reproduce: [hjl@gnu-6 pr22502]$ make gcc -g -O2 -c -o test-weak.o test-weak.c gcc -g -O2 -flto -c -o test.o test.c gcc -g -O2 -o y test-weak.o test.o test-weak.o: In function `main': /export/home/hjl/bugs/binutils/pr22502/test-weak.c:8: undefined reference to `foobar' collect2: error: ld returned 1 exit status make: *** [Makefile:16: y] Error 1 [hjl@gnu-6 pr22502]$
A patch is posted at https://sourceware.org/ml/binutils/2017-11/msg00501.html
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a83ef4d139c377e0e87d105977d85c6ef9fbb162 commit a83ef4d139c377e0e87d105977d85c6ef9fbb162 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Nov 28 03:48:25 2017 -0800 ld: Set non_ir_ref_regular on symbols referenced in regular objects If linker plugin is enabled, set non_ir_ref_regular on symbols referenced in regular objects so that linker plugin will get the correct symbol resolution. bfd/ PR ld/22502 * elflink.c (_bfd_elf_merge_symbol): Also skip definition from an IR object. (elf_link_add_object_symbols): If linker plugin is enabled, set non_ir_ref_regular on symbols referenced in regular objects so that linker plugin will get the correct symbol resolution. ld/ PR ld/22502 * testsuite/ld-plugin/lto.exp: Run PR ld/22502 test. * testsuite/ld-plugin/pr22502a.c: New file. * testsuite/ld-plugin/pr22502b.c: Likewise.
Fixed.