binutils-gdb/ld/testsuite
Maciej W. Rozycki 1f599d0e7b ELF/LD: Avoid producing hidden and internal dynamic symbols
Always turn hidden and internal symbols which have a dynamic index into
local ones.  This is required by the the ELF gABI[1]:

"A hidden symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object."

"An internal symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object."

The ELF linker usually respects this requirement, however in the case
where a dynamic symbol has been preallocated due to a reference of the
default export class aka visibility from the object being linked, and
then merged with a hidden or internal symbol definition from within the
same object, then the original export class is carried over to the
output dynamic symbol table, because while merging the generic ELF
linker only converts affected dynamic symbols to local when they are
defined or referenced by the object being linked and a dynamic object
involved in the link both at a time.

The dynamic symbol produced confuses then the dynamic loader at the run
time -- the hidden or internal export class is ignored and the symbol
follows preemption rules as with the default export class.

In the MIPS target it happens when `mips_elf_record_global_got_symbol'
creates a dynamic symbol when a call relocation is encountered.
Additionally if the undefined symbol referred by such a relocation does
specify the intended export class, then a local dynamic symbol is
created instead, which is harmless and allowed, but useless.  Normally
no local dynamic symbols are created, except for a single dummy one at
the beginning.

Correct the problem by removing the extra check for a dynamic symbol
being defined or referenced by the object being linked and a dynamic
object involved in the link both at a time.  The test cases included
cover the internal and hidden symbol cases, as well as a protected
symbol for a reference, the handling of which is unchanged by this fix.
Both cases described above are covered, that is where an internal or
hidden dynamic symbol is produced and where a local one is.

NB this change affects CRIS results where some symbols in the static
table produced in a final link are now converted from STV_HIDDEN to
STB_LOCAL.  This happens whenever the `elf_backend_hide_symbol' handler
is called, so the affected symbols must have been chosen for entering
into the dynamic symbol table, except in these test cases no such symbol
table is produced.  In fully linked binaries the static symbol table is
only used for debugging though, so such a change is fine.

References:

[1] "System V Application Binary Interface - DRAFT - 24 April 2001",
    The Santa Cruz Operation, Inc., "Symbol Table",
    <http://www.sco.com/developers/gabi/2001-04-24/ch4.symtab.html>

	bfd/
	PR ld/19908
	* elflink.c (elf_link_add_object_symbols): Always turn hidden
	and internal symbols which have a dynamic index into local
	ones.

	ld/
	PR ld/19908
	* testsuite/ld-cris/tls-e-20.d: Adjust for hidden symbol
	handling fix.
	* testsuite/ld-cris/tls-e-20a.d: Likewise.
	* testsuite/ld-cris/tls-e-21.d: Likewise.
	* testsuite/ld-cris/tls-e-23.d: Likewise.
	* testsuite/ld-cris/tls-e-80.d: Likewise.
	* testsuite/ld-cris/tls-gd-3h.d: Likewise.
	* testsuite/ld-cris/tls-leie-19.d: Likewise.
	* testsuite/ld-mips-elf/export-class-ref-lib.sd: New test.
	* testsuite/ld-mips-elf/export-hidden-ref.sd: New test.
	* testsuite/ld-mips-elf/export-internal-ref.sd: New test.
	* testsuite/ld-mips-elf/export-protected-ref.sd: New test.
	* testsuite/ld-mips-elf/export-class-ref-f0.s: New test source.
	* testsuite/ld-mips-elf/export-class-ref-f1.s: New test source.
	* testsuite/ld-mips-elf/export-class-ref-f2.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-04-05 15:14:54 +01:00
..
config Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-aarch64 [AArch64] Create .got section if _GLOBAL_OFFSET_TABLE_ referenced 2016-03-07 15:40:50 +00:00
ld-alpha Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-arm PR gas/19744: Thumb-1 pcrop relocations don't work on Thumb-2 targets 2016-03-10 17:06:35 +01:00
ld-auto-import Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-avr Fix possible failure in the AVR linker tests. 2016-03-18 09:51:47 +00:00
ld-bootstrap Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-cdtest Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-checks Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-cris ELF/LD: Avoid producing hidden and internal dynamic symbols 2016-04-05 15:14:54 +01:00
ld-crx Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-cygwin Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-d10v Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-discard [ARC] Fix ld testsuite failures. 2016-04-05 13:46:44 +02:00
ld-elf [ARC] Fix ld testsuite failures. 2016-04-05 13:46:44 +02:00
ld-elfcomm Properly implement STT_COMMON 2016-02-26 05:01:34 -08:00
ld-elfvers Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-elfvsb Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-elfweak Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-fastcall Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-frv Make linker assigned symbol dynamic only for shared object 2016-02-23 05:19:03 -08:00
ld-gc Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-h8300 Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-i386 Add missing pr19827-nacl.rd for i386/x86-64 NaCl 2016-04-04 20:50:19 -07:00
ld-ia64 Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-ifunc Handle local IFUNC symbols in shared object 2016-03-08 09:42:16 -08:00
ld-libs Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-linkonce Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-m68hc11 Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-m68k Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-mep Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-metag Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-mips-elf ELF/LD: Avoid producing hidden and internal dynamic symbols 2016-04-05 15:14:54 +01:00
ld-misc Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-mmix Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-mn10300 Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-nds32 Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-nios2 Add Nios II arch flags and compatibility tests 2015-07-01 15:55:28 -07:00
ld-pe Improve COFF/PE linker garbage collection by preventing the removal of sections containing exported symbols. 2016-03-22 12:25:08 +00:00
ld-pie Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-plugin Update PR ld/12365 test for GCC 6 2016-03-01 12:45:18 -08:00
ld-powerpc Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-s390 Enhance GAS's .section directive so that it can take numeric values for the flags and type fields. (ELF only) 2016-02-15 11:11:46 +00:00
ld-scripts [ARC] Fix ld testsuite failures. 2016-04-05 13:46:44 +02:00
ld-selective Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-sh Enhance GAS's .section directive so that it can take numeric values for the flags and type fields. (ELF only) 2016-02-15 11:11:46 +00:00
ld-shared Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-size Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-sparc Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-spu Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-srec [ARC] Fix ld testsuite failures. 2016-04-05 13:46:44 +02:00
ld-tic6x Enhance GAS's .section directive so that it can take numeric values for the flags and type fields. (ELF only) 2016-02-15 11:11:46 +00:00
ld-tilegx Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-tilepro Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-undefined Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-unique Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-v850 Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-vax-elf Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-versados Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-visium Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-vxworks Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-x86-64 Add missing pr19827-nacl.rd for i386/x86-64 NaCl 2016-04-04 20:50:19 -07:00
ld-xc16x Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-xstormy16 Copyright update for binutils 2016-01-01 23:00:01 +10:30
ld-xtensa Enhance GAS's .section directive so that it can take numeric values for the flags and type fields. (ELF only) 2016-02-15 11:11:46 +00:00
lib ld/testing: Fix error and warning checks in run_dump_test 2016-03-30 17:58:05 +01:00
ChangeLog-2004 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2005 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2006 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2007 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2008 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2009 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2010 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2011 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2012 Rotate binutils ChangeLog for 2013 2013-01-02 17:06:32 +00:00
ChangeLog-2013 New Year - binutils ChangeLog rotation 2014-01-08 05:32:12 -08:00
ChangeLog-2014 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
ChangeLog-2015 binutils ChangeLog rotation 2016-01-01 22:59:17 +10:30
ChangeLog-9303 Add copyright notices 2012-12-10 12:48:03 +00:00