Bug 22502 - Unable to redefine weak function in LTO incrementally-linked executable
Summary: Unable to redefine weak function in LTO incrementally-linked executable
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: 2.30
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-27 13:27 UTC by Thomas Preud'homme
Modified: 2017-11-28 12:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Reproducer for failure to incrementally link an executable with LTO (487 bytes, application/x-xz)
2017-11-27 13:27 UTC, Thomas Preud'homme
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Preud'homme 2017-11-27 13:27:31 UTC
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
Comment 1 H.J. Lu 2017-11-27 17:10:10 UTC
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]$
Comment 2 H.J. Lu 2017-11-27 19:44:06 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2017-11/msg00501.html
Comment 3 Sourceware Commits 2017-11-28 11:49:42 UTC
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.
Comment 4 H.J. Lu 2017-11-28 12:13:12 UTC
Fixed.