Bug 16530 - --dynamic-list does not protect symbols from being garbage collected
Summary: --dynamic-list does not protect symbols from being garbage collected
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-05 09:13 UTC by Evgeniy Stepanov
Modified: 2014-06-12 16:35 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 Evgeniy Stepanov 2014-02-05 09:13:20 UTC
$ cat z.cc
extern "C" void f() {}
int main() { return 0; }
$ cat z.syms 
{
  f;
};
$ g++ z.cc -o z -Wl,--dynamic-list,z.syms -Wl,--gc-sections -ffunction-sections
$ objdump -T z

With Gold linker (today's trunk), f is not exported from the executable. With BFD linker, it is exported as a local(?) symbol.
Comment 1 Sourceware Commits 2014-02-06 02:03:21 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  fd834e57ffce2f5dbe3443f034e68cebd63ee89a (commit)
      from  ee1e2d4fb692736c754b42b69eb88c1f436c5f15 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

commit fd834e57ffce2f5dbe3443f034e68cebd63ee89a
Author: Cary Coutant <ccoutant@google.com>
Date:   Wed Feb 5 14:01:52 2014 -0800

    Fix problems with the --dynamic-list option.
    
    PR gold/13577 complains that even though symbols listed in
    the --dynamic-list script are exported, they are still bound symbolically
    if -Bsymbolic is also used. There are two underlying problems here.
    First, -Bsymbolic should be overridden by --dynamic-list, since the
    dynamic list provides an explicit list of symbols that are not bound
    within the library, and if we go ahead and set DT_SYMBOLIC, then the
    dynamic loader will bind it within the library anyway. Second, gold
    did not properly identify the symbols listed in the file as preemptible.
    
    PR gold/16530 complains that symbols listed in the --dynamic-list script
    can still be garbage collected. I've fixed this by checking the symbols
    as they're added to the symbol table. (Unlike the --export-dynamic-symbol
    option, we can't iterate over the list, because the --dynamic-list script
    can have wildcards in it.)
    
    gold/
    
    2014-02-05  Cary Coutant  <ccoutant@google.com>
    
    	PR gold/13577
    	* options.cc (General_options::parse_dynamic_list):
    	Set have_dynamic_list_.
    	(General_options::General_options): Initialize have_dynamic_list_.
    	(General_options::finalize): Turn off -Bsymbolic and
    	-Bsymbolic-functions if --dynamic-list provided.
    	* options.h (General_options::have_dynamic_list): New function.
    	(General_options::have_dynamic_list_): New data member.
    	* symtab.h (Symbol::is_preemptible): Handle --dynamic-list
    	correctly.
    
    	PR gold/16530
    	* symtab.cc (Symbol_table::add_from_relobj): If symbol is named
    	in --dynamic-list, mark it.
    
    	* testsuite/Makefile.am (gc_dynamic_list_test.sh): New test case.
    	(dynamic_list_2): New test case.
    	* testsuite/Makefile.in: Regenerate.
    	* testsuite/dynamic_list_2.cc: New file.
    	* testsuite/dynamic_list_2.t: New file.
    	* testsuite/dynamic_list_lib1.cc: New file.
    	* testsuite/dynamic_list_lib2.cc: New file.
    	* testsuite/gc_dynamic_list_test.c: New file.
    	* testsuite/gc_dynamic_list_test.sh: New file.
    	* testsuite/gc_dynamic_list_test.t: New file.

-----------------------------------------------------------------------

Summary of changes:
 gold/options.cc                        |    9 ++++++
 gold/options.h                         |    7 ++++
 gold/symtab.cc                         |    3 +-
 gold/symtab.h                          |   10 +++++-
 gold/testsuite/Makefile.am             |   26 +++++++++++++++++
 gold/testsuite/Makefile.in             |   47 ++++++++++++++++++++++++++++--
 gold/testsuite/dynamic_list_2.cc       |   40 ++++++++++++++++++++++++++
 gold/testsuite/dynamic_list_2.t        |   27 +++++++++++++++++
 gold/testsuite/dynamic_list_lib1.cc    |   37 ++++++++++++++++++++++++
 gold/testsuite/dynamic_list_lib2.cc    |   49 ++++++++++++++++++++++++++++++++
 gold/testsuite/gc_dynamic_list_test.c  |   34 ++++++++++++++++++++++
 gold/testsuite/gc_dynamic_list_test.sh |   39 +++++++++++++++++++++++++
 gold/testsuite/gc_dynamic_list_test.t  |   25 ++++++++++++++++
 13 files changed, 347 insertions(+), 6 deletions(-)
 create mode 100644 gold/testsuite/dynamic_list_2.cc
 create mode 100644 gold/testsuite/dynamic_list_2.t
 create mode 100644 gold/testsuite/dynamic_list_lib1.cc
 create mode 100644 gold/testsuite/dynamic_list_lib2.cc
 create mode 100644 gold/testsuite/gc_dynamic_list_test.c
 create mode 100755 gold/testsuite/gc_dynamic_list_test.sh
 create mode 100644 gold/testsuite/gc_dynamic_list_test.t
Comment 2 Cary Coutant 2014-02-06 02:05:57 UTC
Fixed on trunk.
Comment 3 Sourceware Commits 2014-02-10 16:11:33 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  d6f6f455778b10037503bcc39352b5174bba5e45 (commit)
      from  8577303939d47fc3dd433ed31f78ee47c6ad0aa8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

commit d6f6f455778b10037503bcc39352b5174bba5e45
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 6 09:44:25 2014 -0800

    Mark symbol in executables if it matches dynamic_list
    
    bfd/
    
    	PR gold/16530
    	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark symbol in
    	executables if it matches dynamic_list.
    
    ld/testsuite/
    
    	PR gold/16530
    	* ld-elf/dynamic-1.c: New file.
    	* ld-elf/dynamic-1.rd: Likewise.
    	* ld-elf/dynamic-1.syms: Likewise.
    
    	* ld-elf/shared.exp (build_tests): Add dynamic-1.

-----------------------------------------------------------------------

Summary of changes:
 bfd/ChangeLog                      |    6 ++++++
 bfd/elflink.c                      |    6 +++++-
 ld/testsuite/ChangeLog             |    9 +++++++++
 ld/testsuite/ld-elf/dynamic-1.c    |   10 ++++++++++
 ld/testsuite/ld-elf/dynamic-1.rd   |    5 +++++
 ld/testsuite/ld-elf/dynamic-1.syms |    3 +++
 ld/testsuite/ld-elf/shared.exp     |    3 +++
 7 files changed, 41 insertions(+), 1 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/dynamic-1.c
 create mode 100644 ld/testsuite/ld-elf/dynamic-1.rd
 create mode 100644 ld/testsuite/ld-elf/dynamic-1.syms
Comment 4 Sourceware Commits 2014-06-12 15:31:01 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, binutils-2_24-branch has been updated
       via  6c8d8bfdad7a36b97efa887bb2e6ec69c2fb61a9 (commit)
      from  9da92c3812d5b5ddca09b4732939f1645d89bc59 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

commit 6c8d8bfdad7a36b97efa887bb2e6ec69c2fb61a9
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 6 09:44:25 2014 -0800

    Mark symbol in executables if it matches dynamic_list
    
    bfd/
    
    	PR gold/16530
    	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark symbol in
    	executables if it matches dynamic_list.
    
    ld/testsuite/
    
    	PR gold/16530
    	* ld-elf/dynamic-1.c: New file.
    	* ld-elf/dynamic-1.rd: Likewise.
    	* ld-elf/dynamic-1.syms: Likewise.
    
    	* ld-elf/shared.exp (build_tests): Add dynamic-1.

-----------------------------------------------------------------------

Summary of changes:
 bfd/ChangeLog                      |    5 +++++
 bfd/elflink.c                      |    6 +++++-
 ld/testsuite/ChangeLog             |   10 ++++++++++
 ld/testsuite/ld-elf/dynamic-1.c    |   10 ++++++++++
 ld/testsuite/ld-elf/dynamic-1.rd   |    5 +++++
 ld/testsuite/ld-elf/dynamic-1.syms |    3 +++
 ld/testsuite/ld-elf/shared.exp     |    3 +++
 7 files changed, 41 insertions(+), 1 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/dynamic-1.c
 create mode 100644 ld/testsuite/ld-elf/dynamic-1.rd
 create mode 100644 ld/testsuite/ld-elf/dynamic-1.syms
Comment 5 Cary Coutant 2014-06-12 16:35:33 UTC
The following commit was mistakenly marked for the PR 15530 instead of this one:

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

commit f17706ea1111ab537a33ad6f13a094f18c1acaea
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Feb 12 21:08:01 2014 +1030

    PR15530, mark symbol in executables if it matches dynamic_list
    
    For powerpc64 as HJ did earlier for other ELF targets, and a tidy.
    
    	PR gold/15530
    	* elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Support
    	--export-dynamic and --dynamic-list marking of symbols.
    	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Reorder
    	cheap tests first.

-----------------------------------------------------------------------

Summary of changes:
 bfd/ChangeLog   |    7 +++++++
 bfd/elf64-ppc.c |    9 +++++++--
 bfd/elflink.c   |   11 ++++++-----
 3 files changed, 20 insertions(+), 7 deletions(-)