Bug 11434 - ld resolves relocations against STB_GNU_UNIQUE in DT_SYMBOLIC libraries
Summary: ld resolves relocations against STB_GNU_UNIQUE in DT_SYMBOLIC libraries
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-26 07:15 UTC by Jakub Jelinek
Modified: 2010-04-09 22:01 UTC (History)
2 users (show)

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


Attachments
A patch (608 bytes, patch)
2010-03-26 13:36 UTC, H.J. Lu
Details | Diff
An updated patch (329 bytes, patch)
2010-03-26 13:42 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2010-03-26 07:15:18 UTC
int i;
static int * g(void)
{
  return &i;
}
struct S {
  static int * f(void)
  {
    static int *p = g();
    return p;
  }
};

int * wrap2_f (void)
{
  return S::f();
}

g++ -O2 -fpic -shared -o lib.so lib.cc -Wl,-Bsymbolic
(assuming gcc has been configured to use STB_GNU_UNIQUE).
There are no relocations against _ZZN1S1fEvE1p (STB_GNU_UNIQUE) symbol defined
in this library.  While for non-STB_GNU_UNIQUE symbols that's desirable, the
symbol will always resolve to the containing library, for STB_GNU_UNIQUE it
causes the symbol to be no longer unique in the whole program.
Comment 1 H.J. Lu 2010-03-26 13:36:21 UTC
Created attachment 4682 [details]
A patch

Please try this patch.
Comment 2 H.J. Lu 2010-03-26 13:42:10 UTC
Created attachment 4683 [details]
An updated patch

We don't need to check unique_global for ifunc symbols.
Comment 3 H.J. Lu 2010-03-26 15:02:59 UTC
A patch with a testcase is posted at

http://sourceware.org/ml/binutils/2010-03/msg00395.html
Comment 4 Sourceware Commits 2010-04-07 02:41:54 UTC
Subject: Bug 11434

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2010-04-07 02:41:35

Modified files:
	bfd            : ChangeLog elf-bfd.h 
	ld             : ChangeLog 
	ld/testsuite/ld-x86-64: x86-64.exp 
Added files:
	ld/testsuite/ld-x86-64: unique1.d unique1.s 

Log message:
	Don't bind unique symbol locally.
	
	bfd/
	
	2010-04-06  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/11434
	* elf-bfd.h (SYMBOLIC_BIND): Don't bind unique symbol locally.
	
	ld/testsuite/
	
	2010-04-06  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/11434
	* ld/testsuite/ld-x86-64/unique1.d: New.
	* ld/testsuite/ld-x86-64/unique1.s: Likewise.
	
	* ld-x86-64/x86-64.exp: Run unique1.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4980&r2=1.4981
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-bfd.h.diff?cvsroot=src&r1=1.301&r2=1.302
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2130&r2=1.2131
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/unique1.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/unique1.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/x86-64.exp.diff?cvsroot=src&r1=1.15&r2=1.16

Comment 5 H.J. Lu 2010-04-09 22:01:24 UTC
Fixed.