Bug 23818 - Symbols from discarded section in IR object leaked into final executable
Summary: Symbols from discarded section in IR object leaked into final executable
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: 2.32
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-24 22:19 UTC by H.J. Lu
Modified: 2018-11-06 16:08 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2018-10-24 22:19:52 UTC
[hjl@gnu-efi-2 pr87698]$ cat test.c
void
foo ()
{
}
[hjl@gnu-efi-2 pr87698]$ cat test2.c
void foo (void);

void
bar (void)
{
  foo ();
}
[hjl@gnu-efi-2 pr87698]$ cat x.t
{
  local: *;
};
[hjl@gnu-efi-2 pr87698]$ make
gcc -flto -ffat-lto-objects -fPIC -O2 -g   -c -o test.o test.c
gcc -flto -ffat-lto-objects -fPIC -O2 -g   -c -o test2.o test2.c
gcc -shared  -o x.so test.o test2.o -Wl,--version-script,x.t
readelf -sW x.so | grep foo
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  ABS foo
[hjl@gnu-efi-2 pr87698]$
Comment 1 Sourceware Commits 2018-10-25 01:14:59 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=0a640d719684f25bdb88ae60148c6978e6131701

commit 0a640d719684f25bdb88ae60148c6978e6131701
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Oct 24 18:08:13 2018 -0700

    ELF: Hide symbols defined in discarded input sections
    
    When assigning symbol version, we should hide debug symbols defined in
    discarded sections from IR objects so that they can be removed later.
    
    bfd/
    
    	PR ld/23818
    	* elflink.c (_bfd_elf_link_assign_sym_version): Hide symbols
    	defined in discarded input sections.
    
    ld/
    
    	PR ld/23818
    	* testsuite/ld-plugin/lto.exp: Run PR ld/23818 test.
    	* testsuite/ld-plugin/pr23818.d: New file.
    	* testsuite/ld-plugin/pr23818.t: Likewise.
    	* testsuite/ld-plugin/pr23818a.c: Likewise.
    	* testsuite/ld-plugin/pr23818b.c: Likewise.
Comment 2 H.J. Lu 2018-10-25 01:16:08 UTC
Fixed for 2.32.
Comment 3 Romain Geissler 2018-10-25 04:56:30 UTC
Thanks, I will check that this indeed fixes my case with libssh2.

I understand this problem is not really wide and might actually affect just me since I don't expect that using -ffat-lto-objects is very common, but do you think this commit deserves to be backported on branch 2.31, or do you prefer I patch it manually on my side until 2.32 is out ?

Cheers,
Romain
Comment 4 H.J. Lu 2018-10-25 05:47:05 UTC
(In reply to Romain Geissler from comment #3)
> Thanks, I will check that this indeed fixes my case with libssh2.
> 
> I understand this problem is not really wide and might actually affect just
> me since I don't expect that using -ffat-lto-objects is very common, but do
> you think this commit deserves to be backported on branch 2.31, or do you
> prefer I patch it manually on my side until 2.32 is out ?

Please verify that it does fix your problem first.
Comment 5 Romain Geissler 2018-10-26 11:23:30 UTC
After rebuilding libssh2 and a few other open source libraries, now indeed I don't see any more these odd absolute relocations, and now ld.lld happily accepts them as valid input .so files.

So it looks like you fixed it ;)

Is it ok to backport in release branch 2.31 ?

Cheers,
Romain
Comment 6 H.J. Lu 2018-10-26 11:54:58 UTC
(In reply to Romain Geissler from comment #5)
> Is it ok to backport in release branch 2.31 ?

Please request backport on the binutils mailing list.
Comment 7 Sourceware Commits 2018-11-06 16:08:43 UTC
The binutils-2_31-branch branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=84fdbf1a2c901965414eafc96e3bd15fc72ac123

commit 84fdbf1a2c901965414eafc96e3bd15fc72ac123
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Nov 6 16:06:52 2018 +0000

    When assigning symbol version, we should hide debug symbols defined in discarded sections from IR objects so that they can be removed later.
    
    bfd 	PR ld/23818
     	* elflink.c (_bfd_elf_link_assign_sym_version): Hide symbols
     	defined in discarded input sections.
    
    ld 	* testsuite/ld-plugin/lto.exp: Run PR ld/23818 test.
     	* testsuite/ld-plugin/pr23818.d: New file.
     	* testsuite/ld-plugin/pr23818.t: Likewise.
     	* testsuite/ld-plugin/pr23818a.c: Likewise.
     	* testsuite/ld-plugin/pr23818b.c: Likewise.