Bug 10471 - hidden symbol gets added to dynamic symbol table
Summary: hidden symbol gets added to dynamic symbol table
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
Depends on:
Reported: 2009-08-01 00:10 UTC by Silvius Rus
Modified: 2009-11-30 18:48 UTC (History)
3 users (show)

See Also:
Host: x86_64-unknown-linux
Target: x86_64-unknown-linux
Build: x86_64-unknown-linux
Last reconfirmed:

Proposed patch (2.73 KB, patch)
2009-08-07 22:56 UTC, Cary Coutant
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Silvius Rus 2009-08-01 00:10:39 UTC
A hidden symbol gets placed in the dynamic symbol table (as local) if referenced
from a shared library.  The right behavior should be to issue an error.

$ cat foo.c
int foo() __attribute((visibility("hidden")));
int foo () { return 42; }
int main() { return foo(); }

$ cat bar.c 
int bar() { return foo(); }

Linking with gnu ld:
ld: a.out: hidden symbol `foo' in /tmp/cc8PyfIO.o is referenced by DSO

Linking with gold before http://sourceware.org/ml/binutils/2009-02/msg00367.html:
nm -D a.out  | grep foo
000000000040035c T foo

Linking with gold after http://sourceware.org/ml/binutils/2009-02/msg00367.html:
nm -D a.out  | grep foo
000000000040038c t foo
Comment 1 Cary Coutant 2009-08-07 22:56:11 UTC
Created attachment 4123 [details]
Proposed patch

The attached patch is a proposed fix for PR 10471, where gold ends up putting a
local symbol in the dynamic symbol table when a DSO tries to reference a hidden
(or internal) symbol. In this patch, I issue a warning and refuse to resolve
the symbol, but the link completes successfully. For the included test case, we
get these warning messages:

gcctestdir/ld: warning: hidden symbol 'main_hidden' in hidden_test_main.o is
referenced by DSO libhidden.so
gcctestdir/ld: warning: internal symbol 'main_internal' in hidden_test_main.o
is referenced by DSO libhidden.so

I'm not sure whether these should be made errors (along with undefined symbol
errors, we'd want to see them all before terminating the link) or not.

For comparison, gnu ld prints a message (not sure whether it's a warning or an
error) about the first such symbol, then terminates with a mysterious error

/usr/bin/ld: a.out: internal symbol `main_internal' in hidden_test_main.o is
referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
Comment 2 cvs-commit@gcc.gnu.org 2009-08-12 18:30:59 UTC
Subject: Bug 10471

CVSROOT:	/cvs/src
Module name:	src
Changes by:	ccoutant@sourceware.org	2009-08-12 18:30:39

Modified files:
	gold           : ChangeLog resolve.cc 
	gold/testsuite : Makefile.am Makefile.in 
Added files:
	gold/testsuite : hidden_test.sh hidden_test_1.c 

Log message:
	PR 10471
	* resolve.cc (Symbol_table::resolve): Check for references from
	dynamic objects to hidden and internal symbols.
	* testsuite/Makefile.am (hidden_test.sh): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/hidden_test.sh: New script.
	* testsuite/hidden_test_1.c: New test source.
	* testsuite/hidden_test_main.c: New test source.


Comment 3 Michal Nowak 2009-11-30 14:46:50 UTC
Shouldn't we close this one? Looks like changes were committed to CVS.
Comment 4 Cary Coutant 2009-11-30 18:48:47 UTC
Closing now, sorry!