Bug 23455

Summary: gold: should the discarded version information warning exist?
Product: binutils Reporter: Raphael Kubo da Costa <raphael.kubo.da.costa>
Component: goldAssignee: Cary Coutant <ccoutant>
Status: RESOLVED FIXED    
Severity: normal CC: fweimer, ian, jan
Priority: P2    
Version: 2.31   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Raphael Kubo da Costa 2018-07-26 13:47:44 UTC
I've been trying to build the Chromium browser here, and linking a few shared libraries currently fails due to https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=cea6ffbd06a6ebb5c21cb51e7775b8ebb5e34f38 ("Fix treatment of symbol versions with unused as-needed libraries").

Chromium uses --as-needed by default, and also builds and links all targets with -pthread by default. This leads to failures such as

  g++ -shared -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--as-needed -fuse-ld=gold -B -m64 -Wl,-O2 -Wl,--gc-sections -o "./libEGL.so" -Wl,-soname="libEGL.so" @"./libEGL.so.rsp"
  /usr/bin/ld.gold: warning: discarding version information for __cxa_finalize@GLIBC_2.2.5, defined in unused shared library /usr/lib64/libc.so.6 (linked with --as-needed)
  /usr/bin/ld.gold: error: treating warnings as errors

  g++ -shared -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--as-needed -fuse-ld=gold -B -m64 -Wl,-O2 -Wl,--gc-sections -o "./libVkICD_mock_icd.so" -Wl,-soname="libVkICD_mock_icd.so" @"./libVkICD_mock_icd.so.rsp"
  /usr/bin/ld.gold: warning: discarding version information for __pthread_key_create@GLIBC_2.2.5, defined in unused shared library /usr/lib64/libpthread.so.0 (linked with --as-needed)
  /usr/bin/ld.gold: error: treating warnings as errors

While it could be possible to avoid using -pthread everywhere, avoiding libc itself looks overkill, so I'm wondering if the gold warning is excessive, especially with --fatal-warnings.
Comment 1 Sourceware Commits 2018-08-06 21:11:00 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

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

commit 3a12c78d1491c4877928e7294c8cdbe8171dfeed
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Mon Aug 6 14:08:48 2018 -0700

    Add --warn-drop-version option; by default, do not warn when discarding version info.
    
    gold/
    	PR gold/23455
    	* options.h (General_options): Add --warn-drop-version option.
    	* symtab.cc (Symbol_table::set_dynsym_indexes): Check it.
Comment 2 Sourceware Commits 2018-08-06 21:11:33 UTC
The binutils-2_31-branch branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

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

commit b7991db94c9dabb42a7a0fc5b0a0fb1997d85586
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Mon Aug 6 14:08:48 2018 -0700

    Add --warn-drop-version option; by default, do not warn when discarding version info.
    
    gold/
    	PR gold/23455
    	* options.h (General_options): Add --warn-drop-version option.
    	* symtab.cc (Symbol_table::set_dynsym_indexes): Check it.
Comment 3 Cary Coutant 2018-08-06 21:21:16 UTC
It's still really dangerous to discard the version information.
If the symbol ends up being called, the loader will most likely
bind the call to the base version, and unpredictable things may
happen. In cases where the symbol is merely a canary, like
pthread_key_create, it shouldn't matter unless the pthreads library
ends up being loaded with the application even though it wasn't
linked in.

I think you should always link -lpthread with --no-as-needed.
The GCC driver ought to be fixed to do this automatically.

I'm really not sure why __cxa_finalize triggered the warning --
why would there be a weak reference to it?

I've disabled the warning by default, and added a --warn-drop-version
option for those who want it.

Fixed on trunk and 2.31 branch.
Comment 4 Florian Weimer 2018-11-28 13:52:19 UTC
(In reply to Cary Coutant from comment #3)
> It's still really dangerous to discard the version information.

Why is the link editor discarding the symbol version?  Shouldn't it create a weak symbol with a weak version reference instead?  (Assuming the concern is the strong version reference.)