Bug 12975 - --gc-sections doesn't remove symbols hidden with version scripts
Summary: --gc-sections doesn't remove symbols hidden with version scripts
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL: http://sourceware.org/ml/binutils/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-08 17:47 UTC by Mike Hommey
Modified: 2011-10-25 03:09 UTC (History)
3 users (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 Mike Hommey 2011-07-08 17:47:55 UTC
(This applies to both ld and gold)

Take the following source code as test.c:
-----8<-----
int foo() { return 42; }

int bar() { return 0; }

#pragma GCC visibility push(hidden)
int baz() { return 1; }
#pragma GCC visibility pop
----->8-----

Take the following version script as ver:
-----8<-----
{
global:
  foo;
local:
  *;
};
----->8-----

Build with:
gcc -o test.so -shared test.c -Wl,--gc-sections -ffunction-sections -Wl,--version-script,ver

The baz function, hidden with visibility, is removed from the resulting test.so, but not bar, as one could expect, since it's effectively hidden through the version script.
Comment 1 H.J. Lu 2011-09-14 21:34:43 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2011-09/msg00079.html
Comment 2 Dmitry Gorbachev 2011-09-14 22:22:16 UTC
(In reply to comment #1)

It would be even better if BFD LD could remove `bar' without --gc-sections but with lto. GOLD does it.
Comment 3 H.J. Lu 2011-09-15 21:30:33 UTC
An updated patch is posted at

http://sourceware.org/ml/binutils/2011-09/msg00089.html
Comment 4 Dmitry Gorbachev 2011-09-16 01:08:53 UTC
(In reply to comment #3)

Thank you!
Comment 5 cvs-commit@gcc.gnu.org 2011-09-16 01:15:23 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2011-09-16 01:15:20

Modified files:
	bfd            : ChangeLog bfd-in.h bfd-in2.h elflink.c linker.c 
	include        : ChangeLog bfdlink.h 
	ld             : ChangeLog ldlang.c ldlang.h pe-dll.c plugin.c 
	ld/emultempl   : elf32.em solaris2.em 
	ld/testsuite   : ChangeLog 
Added files:
	ld/testsuite/ld-elf: pr12975.d pr12975.s pr12975.t 

Log message:
	Check if a symbol is hidden by linker script.
	
	bfd/
	
	2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/12975
	* bfd-in.h (bfd_elf_size_dynamic_sections): Remove pointer
	to struct bfd_elf_version_tree.
	
	* elflink.c (elf_info_failed): Remove verdefs.
	(_bfd_elf_export_symbol): Updated.
	_bfd_elf_link_assign_sym_version): Likewise.
	(bfd_elf_size_dynamic_sections): Remove pointer to struct
	bfd_elf_version_tree.  Updated.
	(bfd_elf_gc_mark_dynamic_ref_symbol): Check if a symbol is hidden
	by linker script.
	
	* linker.c (bfd_hide_sym_by_version): New.
	
	* bfd-in2.h: Regenerated.
	
	include/
	
	2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/12975
	* bfdlink.h (bfd_link_info): Add version_info.
	
	ld/
	
	2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/12975
	* ldlang.c (lang_elf_version_info): Removed.
	(lang_register_vers_node): Replace lang_elf_version_info with
	link_info.version_info.
	(lang_add_vers_depend): Likewise.
	* pe-dll.c (process_def_file_and_drectve): Likewise.
	* emultempl/solaris2.em (elf_solaris2_before_allocation): Likewise.
	
	* ldlang.h (lang_elf_version_info): Removed.
	
	* plugin.c  (is_visible_from_outside): Check if symbol is hidden
	by version script.
	
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_allocation):
	Remove lang_elf_version_info.
	
	ld/testsuite/
	
	2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/12975
	* ld-elf/pr12975.d: New.
	* ld-elf/pr12975.s: Likewise.
	* ld-elf/pr12975.t: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5469&r2=1.5470
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd-in.h.diff?cvsroot=src&r1=1.157&r2=1.158
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd-in2.h.diff?cvsroot=src&r1=1.548&r2=1.549
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.418&r2=1.419
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/linker.c.diff?cvsroot=src&r1=1.89&r2=1.90
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/ChangeLog.diff?cvsroot=src&r1=1.548&r2=1.549
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/bfdlink.h.diff?cvsroot=src&r1=1.91&r2=1.92
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2369&r2=1.2370
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlang.c.diff?cvsroot=src&r1=1.376&r2=1.377
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlang.h.diff?cvsroot=src&r1=1.98&r2=1.99
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/pe-dll.c.diff?cvsroot=src&r1=1.137&r2=1.138
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/plugin.c.diff?cvsroot=src&r1=1.39&r2=1.40
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/emultempl/elf32.em.diff?cvsroot=src&r1=1.222&r2=1.223
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/emultempl/solaris2.em.diff?cvsroot=src&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1457&r2=1.1458
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr12975.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr12975.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr12975.t.diff?cvsroot=src&r1=NONE&r2=1.1
Comment 6 Dmitry Gorbachev 2011-09-16 02:33:10 UTC
I can't reproduce the original issue with recent GOLD (ver. 1.11/2.21.53.20110913) on i686-pc-linux-gnu.

It still fails with BFD LD on i686-pc-mingw32 (with --gc-sections, but not with LTO).
Comment 7 H.J. Lu 2011-09-16 04:27:12 UTC
Fixed.
Comment 8 cvs-commit@gcc.gnu.org 2011-10-17 08:27:54 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2011-10-17 08:27:46

Modified files:
	bfd            : ChangeLog elf64-ppc.c 

Log message:
	PR ld/12975
	PR ld/13195
	* elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Apply 2011-09-15
	and 2011-09-29 bfd_elf_gc_mark_dynamic_ref_symbol changes here too.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5490&r2=1.5491
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-ppc.c.diff?cvsroot=src&r1=1.365&r2=1.366
Comment 9 cvs-commit@gcc.gnu.org 2011-10-25 03:09:40 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_22-branch
Changes by:	amodra@sourceware.org	2011-10-25 03:09:34

Modified files:
	bfd            : ChangeLog elf64-ppc.c 

Log message:
	PR ld/12975
	PR ld/13195
	2011-10-17  Alan Modra  <amodra@gmail.com>
	* elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Apply 2011-09-15
	and 2011-09-29 bfd_elf_gc_mark_dynamic_ref_symbol changes here too.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.5473.2.14&r2=1.5473.2.15
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-ppc.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.363.2.2&r2=1.363.2.3