Bug 15107 - Reference to GNU_UNIQUE symbol shouldn't create GNU_UNIQUE symbol
Summary: Reference to GNU_UNIQUE symbol shouldn't create GNU_UNIQUE symbol
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.24
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-06 18:11 UTC by Florian Weimer
Modified: 2013-02-08 16:29 UTC (History)
1 user (show)

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


Attachments
unique_shared_ref.s (104 bytes, text/plain)
2013-02-06 18:11 UTC, Florian Weimer
Details
unique_shared.s (59 bytes, text/plain)
2013-02-06 18:16 UTC, Florian Weimer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2013-02-06 18:11:15 UTC
Created attachment 6848 [details]
unique_shared_ref.s

Instructions (as tested on Fedora 18 x86_64):

$ as unique_shared_ref.s -o unique_shared_ref.o
$ as unique_shared.s -o unique_shared.o
$ ld -shared -o unique_shared_ref.so unique_shared_ref.o
$ ld -o unique_shared_ref  unique_shared_ref.o unique_shared.so
$ readelf -s unique_shared_ref | grep UNIQ
     1: 0000000000000000     0 OBJECT  UNIQUE DEFAULT  UND b
    11: 0000000000000000     0 OBJECT  UNIQUE DEFAULT  UND b
$ readelf -h unique_shared_ref  | grep ABI
  OS/ABI:                            UNIX - System V
  ABI Version:                       0

Either the ABI should be set to GNU, or GNU_UNIQUE shouldn't be used for the symbol reference.

See this mailing list thread:
<http://sourceware.org/ml/binutils/2013-01/msg00362.html>
Comment 1 Florian Weimer 2013-02-06 18:16:25 UTC
Created attachment 6849 [details]
unique_shared.s
Comment 2 H.J. Lu 2013-02-06 19:28:17 UTC
Please try this

diff --git a/bfd/elflink.c b/bfd/elflink.c
index d336730..789ae12 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -8868,7 +8868,7 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
       /* Turn off visibility on local symbol.  */
       sym.st_other &= ~ELF_ST_VISIBILITY (-1);
     }
-  else if (h->unique_global)
+  else if (h->unique_global && h->def_regular)
     sym.st_info = ELF_ST_INFO (STB_GNU_UNIQUE, h->type);
   else if (h->root.type == bfd_link_hash_undefweak
      || h->root.type == bfd_link_hash_defweak)
Comment 3 Florian Weimer 2013-02-06 19:36:05 UTC
(In reply to comment #2)
> Please try this

The reference is now GLOBAL instead of LOOS+0/GNU_UNIQUE.  But I don't know if this breaks anything else.
Comment 4 H.J. Lu 2013-02-06 19:38:41 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Please try this
> 
> The reference is now GLOBAL instead of LOOS+0/GNU_UNIQUE.  But I don't know if
> this breaks anything else.

It shouldn't and it is consistent with gold.
Comment 5 cvs-commit@gcc.gnu.org 2013-02-08 01:33:06 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2013-02-08 01:33:01

Modified files:
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-unique: unique_empty.s 
	bfd            : ChangeLog elflink.c 

Log message:
	Set STB_GNU_UNIQUE only if symbol is defined in regular object
	
	bfd/
	
	PR ld/15107
	* elflink.c (elf_link_output_extsym): Set STB_GNU_UNIQUE only if
	symbol is defined in regular object.
	
	ld/testsuite/
	
	PR ld/15107
	* ld-unique/unique_empty.s: Add reference to "b".

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1679&r2=1.1680
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-unique/unique_empty.s.diff?cvsroot=src&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5935&r2=1.5936
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.464&r2=1.465
Comment 6 H.J. Lu 2013-02-08 16:29:16 UTC
Fixed.