Bug 13195

Summary: -ffunction-sections -Wl,--gc-sections failure with symbol versioning
Product: binutils Reporter: H.J. Lu <hjl.tools>
Component: ldAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: jan.kratochvil
Priority: P2    
Version: 2.24   
Target Milestone: ---   
URL: http://sourceware.org/ml/binutils/2011-09/msg00103.html
Host: Target:
Build: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 13233    

Description H.J. Lu 2011-09-16 22:16:17 UTC
[hjl@gnu-6 tmp]$ cat gcsec1.C
extern "C" void abort (void);

int g = 0;

void raise_exception()
{
  throw 1;
}

void used()
{
  try {
    raise_exception ();
  }
  catch (int) {
    g = 1;
  }
}

void unused()
{
  try {
    raise_exception ();
  }
  catch (int) {
    g = 1;
  }
}

int main()
{
  used ();

  if (g != 1)
    abort ();

  return 0;
}
[hjl@gnu-6 tmp]$ g++ gcsec1.C -ffunction-sections -Wl,--gc-sections 
/usr/local/bin/ld: a.out: local symbol `__tls_get_addr@@GLIBC_2.3' in /lib64/ld-linux-x86-64.so.2 is referenced by DSO
/usr/local/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
[hjl@gnu-6 tmp]$
Comment 1 H.J. Lu 2011-09-16 22:58:28 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2011-09/msg00100.html
Comment 2 H.J. Lu 2011-09-17 20:57:58 UTC
Another bug:

[hjl@gnu-6 pr13195-ver]$ cat x.s
	.section .text.new_foo,"ax",%progbits
	.globl	new_foo
	.type	new_foo, %function
new_foo:
	.byte 0
	.symver new_foo,foo@@VERS_2.0
[hjl@gnu-6 pr13195-ver]$ cat x.t
VERS_2.0 {
global:
  foo;
local:
  *;
};
[hjl@gnu-6 pr13195-ver]$ make
as   -o x.o x.s
./ld -shared --gc-sections -version-script x.t -o x.so x.o
readelf -s -D x.so

Symbol table for image:
  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name
    2   0: 0000000000000000     0 OBJECT  GLOBAL DEFAULT ABS VERS_2.0
[hjl@gnu-6 pr13195-ver]$
Comment 3 H.J. Lu 2011-09-17 22:43:02 UTC
A updated patch is posted at

http://sourceware.org/ml/binutils/2011-09/msg00103.html
Comment 4 H.J. Lu 2011-09-28 18:35:55 UTC
*** Bug 13232 has been marked as a duplicate of this bug. ***
Comment 5 cvs-commit@gcc.gnu.org 2011-09-29 00:13:18 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2011-09-29 00:13:14

Modified files:
	bfd            : elflink.c 
	ld/testsuite/ld-elf: elf.exp 
Added files:
	ld/testsuite/ld-elf: pr13195.c pr13195.d pr13195.s pr13195.t 

Log message:
	Fix --gc-sections failure with symbol versioning.
	
	bfd/
	
	2011-09-28  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/13195
	* elflink.c (_bfd_elf_merge_symbol): Don't set dynamic_def when
	clearing def_dynamic.
	(elf_link_add_object_symbols): Likewise.  Set dynamic_def when
	setting def_dynamic.
	(bfd_elf_gc_mark_dynamic_ref_symbol): Check if a symbol is
	versioned.
	
	ld/testsuite/
	
	2011-09-28  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/13195
	* ld-elf/elf.exp: Add a C link testcase for PR ld/13195.
	
	* ld-elf/pr13195.c: New.
	* ld-elf/pr13195.d: Likewise.
	* ld-elf/pr13195.s: Likewise.
	* ld-elf/pr13195.t: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.420&r2=1.421
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.c.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.t.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/elf.exp.diff?cvsroot=src&r1=1.28&r2=1.29
Comment 6 H.J. Lu 2011-09-29 00:13:45 UTC
Fixed.
Comment 7 Jan Kratochvil 2011-09-29 04:43:56 UTC
Confirming it works now, thanks.
Comment 8 cvs-commit@gcc.gnu.org 2011-10-05 16:40:05 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_22-branch
Changes by:	hjl@sourceware.org	2011-10-05 16:39:56

Modified files:
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-elf: elf.exp 
	bfd            : ChangeLog elflink.c 
Added files:
	ld/testsuite/ld-elf: pr13195.c pr13195.d pr13195.s pr13195.t 

Log message:
	Fix --gc-sections failure with symbol versioning.
	
	bfd/
	
	2011-09-29  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/13195
	* elflink.c (_bfd_elf_merge_symbol): Don't set dynamic_def when
	clearing def_dynamic.
	(elf_link_add_object_symbols): Likewise.  Set dynamic_def when
	setting def_dynamic.
	(bfd_elf_gc_mark_dynamic_ref_symbol): Check if a symbol is
	versioned.
	
	ld/testsuite/
	
	2011-09-29  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/13195
	* ld-elf/elf.exp: Add a C link testcase for PR ld/13195.
	
	* ld-elf/pr13195.c: New.
	* ld-elf/pr13195.d: Likewise.
	* ld-elf/pr13195.s: Likewise.
	* ld-elf/pr13195.t: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.1460&r2=1.1460.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.d.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.s.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13195.t.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/elf.exp.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.28&r2=1.28.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.5473.2.2&r2=1.5473.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.420.2.1&r2=1.420.2.2
Comment 9 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 10 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
Comment 11 Jackie Rosen 2014-02-16 17:47:00 UTC Comment hidden (spam)