Commit Graph

3 Commits

Author SHA1 Message Date
Maciej W. Rozycki 1e5f45bb15 PR ld/20828: Work around RISC-V failures
Complement commit 81ff47b3a5 ("PR ld/20828: Fix linker script symbols
wrongly forced local with section GC") and add `.plt' to the list of
output sections created, fixing:

FAIL: PR ld/20828 dynamic symbols with section GC (auxiliary shared library)
FAIL: PR ld/20828 dynamic symbols with section GC (plain)
FAIL: PR ld/20828 dynamic symbols with section GC (version script)

failures with `riscv32-elf', `riscv32-linux', `riscv64-elf' and
`riscv64-linux' targets caused by LD crashing in the absence of such a
section.

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828.ld: Add `.plt'.
2017-01-23 11:27:06 +00:00
Maciej W. Rozycki fda46c417f PR ld/20828: Remove leading `_' from symbols used in tests
Complement commit 81ff47b3a5 ("PR ld/20828: Fix linker script symbols
wrongly forced local with section GC") and remove the leading underscore
from `_fdata' and `_edata' symbols used in tests, fixing a:

FAIL: PR ld/20828 dynamic symbols with section GC (version script)

failure with targets such as: `bfin-elf', `bfin-uclinux', `metag-elf',
`metag-linux' `mn10300-elf', `sh-elf', `sh64-elf', and possibly other
ones, that have `_' set (with `elf_symbol_leading_char') as the leading
character for symbols.  As from commit 93252b1cf4 ("bfd/ld: handle ABI
prefixes in version scripts") these targets strip the leading underscore
before applying version script rules, because the (default) syntax for
symbol names is that of the C language rather than their low-level
symbol table encoding.

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828.ld: Rename `_fdata' and `_edata' to
	`fdata' and `edata' respectively.
	* testsuite/ld-elf/pr20828.ver: Adjust accordingly.
	* testsuite/ld-elf/pr20828-a.sd: Likewise.
	* testsuite/ld-elf/pr20828-b.sd: Likewise.
	* testsuite/ld-elf/pr20828-c.sd: Likewise.
2017-01-23 11:26:06 +00:00
Maciej W. Rozycki 81ff47b3a5 PR ld/20828: Fix linker script symbols wrongly forced local with section GC
Fix a generic ELF linker regression introduced with a chain of changes
made to unused input section garbage collection:

- commit 1a766c6843 ("Also hide symbols without PLT nor GOT
  references."),
  <https://sourceware.org/ml/binutils/2011-09/msg00076.html>,

- commit 1d5316ab67 ("PR ld/13177: garbage collector retains zombie
  references to external libraries"),
  <https://sourceware.org/ml/binutils/2011-10/msg00161.html>,

- commit 6673f753c0 ("Fix PR 12772, garbage collection of dynamic
  syms"), <https://sourceware.org/ml/binutils/2011-12/msg00077.html>,

causing the garbage collection of unused symbols present in a DSO
involved in a link to make identically named symbols ordinarily defined
(i.e. not hidden or PROVIDEd) by a linker script local, even though the
latter symbols are supposed to be global as if no DSO defined them as
well.

This is because linker script assignments are processed very late as
`lang_process' proceeds, down in the call to `ldemul_before_allocation',
which is made after the call to `lang_gc_sections' to do input section
garbage collecting.  Consequently if unused, then any such DSO-defined
symbol has already been garbage-collected and internally marked local.
It would ordinarily be removed from dynamic symbol table output, however
a linker script assignment correctly replaces its original definition
with the new one and enters it into the dynamic symbol table produced as
it is supposed to be exported.  The original local marking is however
retained making the symbol local in the dynamic symbol table and
therefore not available externally.  This also causes a sorting problem
with the MIPS target, which does not expect non-section local dynamic
symbols to be output and produces an invalid binary.

Fix the problem then, by removing the `forced_local' marking for the
offending case and add suitable test cases.  First to verify that unused
symbols ordinarily defined with linker script assignments remain
exported in the context of input section garbage collection whether or
not a DSO defining identically named symbols is present in the link.
Second that a linker version script still correctly retains or removes
such symbols as requested.

	bfd/
	PR ld/20828
	* elflink.c (bfd_elf_record_link_assignment): Clear any
	`forced_local' marking for DSO symbols that are not being
	provided.

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828-1.sd: New test.
	* testsuite/ld-elf/pr20828-2a.sd: New test.
	* testsuite/ld-elf/pr20828-2b.sd: New test.
	* testsuite/ld-elf/pr20828.ld: New test linker script.
	* testsuite/ld-elf/pr20828.ver: New test version script.
	* testsuite/ld-elf/pr20828.s: New test source.
	* testsuite/ld-elf/shared.exp: Run the new test.
2017-01-18 18:30:34 +00:00