Commit Graph

5396 Commits

Author SHA1 Message Date
Palmer Dabbelt 10ddfe62f8 Don't use "_gp" on RISC-V, use "_global_pointer$" instead
"_gp" could conflict with ABI-complient code.  While it's probably OK
because MIPS uses this name, we figured it'd be good to clean this up
before a release with RISC-V in it.

ld/ChangeLog:

2017-02-13  Palmer Dabbelt  <palmer@dabbelt.com>

        * emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Change
        _gp to __global_pointer$.

bfd/ChangeLog:

2017-02-13  Palmer Dabbelt  <palmer@dabbelt.com>

        * elfnn-riscv.c (riscv_global_pointer_value): Change _gp to
        __global_pointer$.
2017-02-13 09:53:54 -08:00
Andrew Burgess d7488716ee ld/arc: Change default linker emulation for nps400
If we are configuring for an arc/linux target, and --with-cpu=nps400 is
used at configure time then change the default linker emulation to the
nps specific version.  All of the alternative linker emulations are
still available using the -mNAME option for ld.

ld/ChangeLog:

	* configure.tgt (arc*-*-linux*): Change the default linker
	emulation based on --with-cpu selection.
	* NEWS: Mention new configuration option.
2017-02-08 23:47:43 +00:00
Jiong Wang 65f90e8259 [ld, testsuite] Don't print to stdout for "readelf -w" to avoid buffer overflow
ld/
	* testsuite/ld-elf/compress.exp: Don't print to stdout for all
	"readelf -w".
2017-02-06 15:25:18 +00:00
Maciej W. Rozycki fa93e3d347 CRIS/LD/testsuite: tls-err-20x.d: Fix a typo, s/n/\n/
ld/
	* testsuite/ld-cris/tls-err-20x.d: Fix a typo, s/n/\n/.
2017-02-02 22:31:57 +00:00
Maciej W. Rozycki 2e9af2d0de LD/testsuite: ld-lib.exp: Fix a typo, s/regexp/regex/
Match `$check_ld(source)' against "regex" rather than "regexp" in
reporting, correcting test framework diagnostics, e.g.:

tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
failed with: <tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'>, no expected output
tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
PASS: MIPS undefined reference

(current) vs:

tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
failed with: <tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'>, expected: <\A[^\n]*\.o: In function `foo':\n\(\.text\+0x0\): undefined reference to `bar'\Z>
tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
PASS: MIPS undefined reference

(corrected).  No functional change.

	ld/
	* ld/testsuite/lib/ld-lib.exp (run_dump_test): Fix a typo,
	s/regexp/regex/.
2017-02-02 22:30:55 +00:00
Jiong Wang fd121c5c45 [ld, testsuite] Restrict dl1*main and dl6*main tests on platforms which have libdl support
ld/
	* testsuite/lib/ld-lib.exp (check_libdl_available): New function.
	* testsuite/ld-elf/shared.exp (run_tests): Split tests which require
	dlopen support into "dlopen_run_tests".  These tests include dl1*main
	and dl6*main.
	(dlopen_run_tests): New and only run it when check_libdl_available
	returns true.  XFAIL on *-*-netbsdelf*.
2017-02-02 09:57:26 +00:00
Maciej W. Rozycki c0c237fcdd MIPS/LD/testsuite: Correct relocation addends in VxWorks tests
Fix commit 171191bac5 ("Add support for STT_IFUNC"),
<https://sourceware.org/ml/binutils/2008-12/msg00052.html>, commit
e04d7088af ("PR ld/14088: Always display addend as signed hex
number"), <https://sourceware.org/ml/binutils/2012-05/msg00123.html> and
commit 343dbc36ff ("Print addend as signed in objdump"),
<https://sourceware.org/ml/binutils/2012-05/msg00163.html> regressions:

FAIL: VxWorks executable test 1 (dynamic)
FAIL: ld-mips-elf/vxworks-forced-local-1

seen with `mips-vxworks' and `mipsel-vxworks' targets and adjust dump
patterns according to changes made to the presentation of relocation
addends in `readelf -r' and `objdump -r' output.

	ld/
	* testsuite/ld-mips-elf/vxworks-forced-local-1.d: Correct the
	presentation of relocation addends.
	* testsuite/ld-mips-elf/vxworks1-lib.rd: Likewise.
	* testsuite/ld-mips-elf/vxworks1.dd: Likewise.
	* testsuite/ld-mips-elf/vxworks1.rd: Likewise.
2017-02-01 22:17:33 +00:00
Maciej W. Rozycki 5139cfdb55 MIPS/LD/testsuite: Fix a `tls-multi-got-1-1.s' build failure
Correct a commit ec9ab52c32 ("gas: consistently emit diagnostics for
non-zero data emission to .bss/.struct"),
<https://sourceware.org/ml/binutils/2015-12/msg00073.html> regression:

.../ld/testsuite/ld-mips-elf/tls-multi-got-1-1.s: Assembler messages:
.../ld/testsuite/ld-mips-elf/tls-multi-got-1-1.s:39: Error: attempt to store non-zero value in section `.tbss'
ERROR: -EB -march=mips1 -32 -KPIC .../ld/testsuite/ld-mips-elf/tls-multi-got-1-1.s: assembly failed
UNRESOLVED: Shared library with multiple GOTs and TLS

in MIPS target testing and move `tlsvar_ld' to `.tdata' section, in line
with the remaining local dynamic definitions introduced with the set of
tests added with commit f4e584bd00 ("TLS support for MIPS"),
<https://sourceware.org/ml/binutils/2005-02/msg00607.html>.

	ld/
	* testsuite/ld-mips-elf/tls-multi-got-1-1.s: Place `tlsvar_ld'
	in `.tdata' section.
	* testsuite/ld-mips-elf/tls-multi-got-1.got: Adjust accordingly.
	* testsuite/ld-mips-elf/tls-multi-got-1.r: Likewise.
2017-02-01 22:15:32 +00:00
Jiong Wang ce7903706d [ld, testsuite] Append $board_cflags in one more place in ld-unique/unique.exp
ld/
	* testsuite/ld-unique/unique.exp (Could not link a dynamic executable):
	Append $board_cflags to link commands.
2017-02-01 12:57:25 +00:00
Senthil Kumar Selvaraj 067869b677 Fix failing print-memory-usage-1 on Windows
ld/

2017-01-31  Senthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>

	* testsuite/ld-scripts/print-memory-usage-1.l: Relax
	check for digit in second decimal place.
2017-02-01 11:55:19 +05:30
Maciej W. Rozycki 15a00b13ae PR ld/20828: LD/testsuite: Correct indentation
ld/
	PR ld/20828
	* testsuite/ld-elf/shared.exp: Correct PR ld/20828 test
	indentation.
2017-02-01 00:21:53 +00:00
Nick Clifton 1273da0414 Fix buffer overflows in ld when printing translated strings.
ld	* ldmain.c (add_archive_element): Eliminate string buffer.
	* ldlang.c (lang_print_asneeded): Likewise.
2017-01-31 12:07:04 +00:00
Maciej W. Rozycki 8b10b0b3e1 MIPS: Add options to control branch ISA checks
Complement commit 9d862524f6 ("MIPS: Verify the ISA mode and alignment
of branch and jump targets") and add GAS and LD options to control the
checks for invalid branches between ISA modes introduced there, to help
with some handwritten code lacking `.insn' annotation for labels used as
branch targets and code produced by older versions of GCC which suffers
from the issue with branches to code that has been optimized away,
addressed with GCC commit 242424 ("MIPS/GCC: Mark trailing labels with
`.insn'"), <https://gcc.gnu.org/ml/gcc-patches/2016-11/msg01061.html>.

	bfd/
	* elfxx-mips.h (_bfd_mips_elf_insn32): Rename prototype to...
	(_bfd_mips_elf_linker_flags): ... this.  Add another parameter.
	* elfxx-mips.c (mips_elf_link_hash_table): Add
	`ignore_branch_isa' member.
	(mips_elf_perform_relocation): Do not treat an ISA mode mismatch
	in branch relocation calculation as an error if
	`ignore_branch_isa' has been set.
	(_bfd_mips_elf_insn32): Rename to...
	(_bfd_mips_elf_linker_flags): ... this.  Rename the `on'
	parameter to `insn32' and add an `ignore_branch_isa' parameter.
	Handle the new parameter.

	gas/
	* config/tc-mips.c (mips_ignore_branch_isa): New variable.
	(options): Add OPTION_IGNORE_BRANCH_ISA and
	OPTION_NO_IGNORE_BRANCH_ISA enum values.
	(md_longopts): Add "mignore-branch-isa" and
	"mno-ignore-branch-isa" options.
	(md_parse_option): Handle OPTION_IGNORE_BRANCH_ISA and
	OPTION_NO_IGNORE_BRANCH_ISA.
	(fix_bad_cross_mode_branch_p): Return FALSE if
	`mips_ignore_branch_isa' has been set.
	(md_show_usage): Add `-mignore-branch-isa' and
	`-mno-ignore-branch-isa'.

	* doc/as.texinfo (Target MIPS options): Add
	`-mignore-branch-isa' and `-mno-ignore-branch-isa' options.
	(-mignore-branch-isa, -mno-ignore-branch-isa): New options.
	* doc/c-mips.texi (MIPS Options): Add `-mignore-branch-isa' and
	`-mno-ignore-branch-isa' options.

	* testsuite/gas/mips/branch-local-ignore-2.d: New test.
	* testsuite/gas/mips/branch-local-ignore-3.d: New test.
	* testsuite/gas/mips/branch-local-ignore-n32-2.d: New test.
	* testsuite/gas/mips/branch-local-ignore-n32-3.d: New test.
	* testsuite/gas/mips/branch-local-ignore-n64-2.d: New test.
	* testsuite/gas/mips/branch-local-ignore-n64-3.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* emultempl/mipself.em (ignore_branch_isa): New variable.
	(mips_create_output_section_statements): Rename
	`_bfd_mips_elf_insn32' called to `_bfd_mips_elf_linker_flags',
	add `ignore_branch_isa' argument.
	(PARSE_AND_LIST_PROLOGUE): Add OPTION_IGNORE_BRANCH_ISA and
	OPTION_NO_IGNORE_BRANCH_ISA enum values.
	(PARSE_AND_LIST_LONGOPTS): Add "ignore-branch-isa" and
	"no-ignore-branch-isa" options.
	(PARSE_AND_LIST_OPTIONS): Add `--ignore-branch-isa' and
	`--no-ignore-branch-isa'.
	(PARSE_AND_LIST_ARGS_CASES): Handle OPTION_IGNORE_BRANCH_ISA and
	OPTION_NO_IGNORE_BRANCH_ISA.

	* ld.texinfo (Options specific to MIPS targets): Add
	`--ignore-branch-isa' and `--no-ignore-branch-isa' options.
	(ld and the MIPS family): Likewise.

	* testsuite/ld-mips-elf/bal-jalx-pic-ignore.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic-ignore-n32.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic-ignore-n64.d: New test.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-r6-1: New test.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-mips16: New
	test.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-micromips: New
	test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-01-30 17:16:01 +00:00
Hans-Peter Nilsson ce6366f9ab Fix another typo in the last ChangeLog entry.
Gah!  Though this time I blame autocompletion.
2017-01-29 16:15:16 +01:00
Hans-Peter Nilsson 8dcdd12d21 Fix typo in ChangeLog 2017-01-29 14:18:13 +01:00
Hans-Peter Nilsson c1d4523838 PR binutils/19935
Fix long-standing buglet and fallout from now-default initfini-array.
	* emulparams/criself.sh (USER_LABEL_PREFIX): Define.
	(OTHER_READONLY_SECTIONS, ENTRY): Delete now-redunant defines.
2017-01-29 14:13:38 +01:00
Hans-Peter Nilsson bf382b306a Fix long-standing buglet and fallout from now-default initfini-array.
* emulparams/criself.sh (USER_LABEL_PREFIX): Define.
	(OTHER_READONLY_SECTIONS, ENTRY): Delete now-redunant defines.
2017-01-29 13:53:58 +01:00
Jiong Wang 4471a46f6f [ld, testsuite] XFAIL "pr20995-2", "Build pr20995-2.so" on arm*-*-eabi*
ld/
	* testsuite/ld-elf/elf.exp ("pr20995-2", "Build pr20995-2.so"): XFAIL on
	arm*-*-eabi*.

Some technical discussions about the reason of this XFAIL are available at

  https://sourceware.org/ml/binutils/2017-01/msg00441.html
2017-01-27 23:06:28 +00:00
Dilyan Palauzov 387dd77738 Update description of the -plugin option used by the linker, ar and nm.
PR 20343
ld	* ld.texinfo (Options): Extend documentation of the --plugin
	option.  Include a description of where the plugins should be
	located.

binutils* doc/binutils.texi (ar): Extend documentation of the --plugin
	option.  Include a description of where the plugins should be
	located.
	(nm): Likewise.
2017-01-27 13:20:24 +00:00
Nick Clifton 0348d4be16 Add Serbian translation for the LD directory.
ld	* po/sr.po: New Serbian translation.
	* configure.ac (ALL_LINGUAS): Add sr.
	* configure: Regenerate.
2017-01-27 11:27:50 +00:00
Sebastian Huber c75b4ebd4f Move RTEMS target configuration to ELF sections
bfd/
	* config.bfd (powerpcle-*-rtems*): Do not mark as removed.
	(arm-*-rtems*): Move to (arm*-*-eabi*).
	(i[3-7]86-*-rtems*): Move to (i[3-7]86-*-elf*).
	(m68-*-rtems*): Move to (m68*-*-elf*).
ld/
	* configure.tgt (arm-*-rtems*): Move to (arm*-*-eabi*).
	(bfin-*-rtems*): Move to (bfin*-*-elf*).
	(i[3-7]86-*-rtems*): Move to (i[3-7]86*-*-elf*).
	(m68*-*-rtems*): Move to (m68*-*-elf*).
	(mips*-*-rtems*): Move to (mips*-*-elf*).
	(or1k*-*-rtems*): Move to (or1k*-*-elf*).
	(powerpc*-*-rtems*): Move to (powerpc*-*-elf*).
	(sparc*-*-rtems*): Move to (sparc*-*-elf*).
	(sparc64*-*-rtems*): Move to (sparc64*-*-elf*).
2017-01-25 17:55:57 +10:30
Sebastian Huber 850d84f6a4 Remove all RTEMS COFF targets
bfd/
	* config.bfd (*-*-rtemscoff*): Mark as removed.
gas/
	* configure.tgt (sh-*-rtemscoff*): Remove.
ld/
	* configure.tgt (h8300-*-rtemscoff*): Remove.
	(i960-*-rtems*): Likewise.
	(m68*-*-rtemscoff*): Likewise.
	(sh-*-rtemscoff*): Likewise.
2017-01-25 17:52:27 +10:30
Maciej W. Rozycki 1a792e1c00 Solaris2/LD: Fix anonymous version script acceptance bug
Correct a bug in Solaris 2 linker emulation code triggered by a test
introduced with commit 81ff47b3a5 ("PR ld/20828: Fix linker script
symbols wrongly forced local with section GC") and only create implicit
version nodes if versioning is actually introduced with a version script
(or VERSION command) rather than only global vs local symbol visibility
selected, fixing an:

ld: anonymous version tag cannot be combined with other version tags

linker error produced whenever a version script (or VERSION command) is
used that does not assign symbol versions, such as:

{ global: foo; bar; local: *; };

and consequently removing a:

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

test suite failure with the `x86_64-solaris2' target.

	ld/
	* emultempl/solaris2.em (elf_solaris2_before_allocation): Do not
	add implicit version nodes if an anonymous version tag is being
	used.
2017-01-24 12:53:52 +00:00
Jiong Wang 077c11e867 [ld, testsuite] Always assemble those intermeidate .o files used later
ld/
	* testsuite/ld-plugin/lto.exp (lto_link_elf_tests): Move "Compile 7",
	"Compile 8a", "Compile 8b"...
	(lto_compile_elf_tests): ...to here.  Always run these tests.
	(lto_run_elf_tests): Move "LTO 7"...
	(lto_run_elf_shared_tests): ...to here.  Restrict these tests on
	environment where share library is supported.
2017-01-24 09:33:00 +00:00
Alan Modra f0158f4416 PowerPC dynamic relocations
This patch fixes a number of issues with powerpc dynamic relocations.

1) Both ppc and ppc64 were emitting more dynamic symbols and
relocations than necessary, due to not supporting static linker
resolution of tls_index entries for __tls_get_addr_opt.  This meant
that any @got@tlsgd or @got@tlsld reloc needed to make their symbols
dynamic and generate dptmod and dtprel relocs for the dynamic linker.
That would have been passable, but what happened was that practically
all @got relocations resulted in their symbols being made dynamic and
dynamic relocations emitted against the GOT entries.  (Mostly visible
on ppc32 executables since ppc64 gcc really only uses @got style
relocs for TLS.)

2) The PowerOpen syntax was not supported with __tls_get_addr_opt.
DTPMOD/DTPREL relocs on tls_index TOC entries did not use the trick of
forcing dynamic symbols and relocations so those entries always
resulted in the full __tls_get_addr processing.  gcc doesn't use the
PowerOpen syntax for TLS, and normally such code would be optimized to
TLS IE or LE so the impact of missing this support was minimal.

3) In an executable, relocations against GNU indirect functions always
used the value of their PLT stub.   While this is correct, it is
better in some cases to use a dynamic relocation.  An extra dynamic
relocation can mean that calls via function pointers need not bounce
through the PLT stub at runtime.

The patch also tidies the PLT handling code in ppc32
allocate_dynrelocs.  Allocating PLT entries after other dynamic relocs
allows the PLT loop to omit special handling for undefined weak
symbols, and that in turn allows the loop to be simplified.

bfd/
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Merge two cases
	where dynamic relocs are preferable.  Allow ifunc too.
	(ensure_undefweak_dynamic): New function.
	(allocate_dynrelocs): Use it here.  Move plt handling last and
	don't make symbols dynamic, simplifying loop.  Only make undef
	weak symbols with GOT entries dynamic.  Correct condition
	for GOT relocs.  Handle dynamic relocs on ifuncs.  Correct
	comments.  Remove goto.
	(ppc_elf_relocate_section): Correct test for using dynamic
	symbol on GOT relocs.  Rearrange test for emitting GOT relocs
	to suit.  Set up explicit tls_index entries and implicit GOT
	tls_index entries resolvable at link time for
	__tls_get_addr_opt.  Simplify test to clear mem for prelink.
	* elf64-ppc.c (allocate_got): Correct condition for GOT relocs.
	(ensure_undefweak_dynamic): New function.
	(allocate_dynrelocs): Use it here.  Only make undef weak symbols
	with GOT entries dynamic.  Remove unnecessary test of
	WILL_CALL_FINISH_DYNAMIC_SYMBOL in PLT handling.
	(ppc64_elf_relocate_section): Correct test for using dynamic
	symbol on GOT relocs.  Rearrange test for emitting GOT relocs
	to suit.  Set up explicit tls_index entries and implicit GOT
	tls_index entries resolvable at link time for __tls_get_addr_opt.
	Simplify expression to clear mem for prelink.
ld/
	* testsuite/ld-powerpc/tlsexe.r: Update for fewer dynamic relocs
	and symbols.
	* testsuite/ld-powerpc/tlsexe.d: Likewise.
	* testsuite/ld-powerpc/tlsexe.g: Likewise.
2017-01-24 12:15:54 +10:30
Yury Norov 2d0ca82411 Fix AArch64 relocation handling in ILP32 mode.
bfd	* elfnn-aarch64.c: Fix relaxations for ILP32 mode.

ld	* testsuite/ld-aarch64/aarch64-elf.exp: Run new tests.
	* testsuite/ld-aarch64/tls-desc-ie-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-all-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-gd-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-gdesc-le-2-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-gdesc-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-ie-le-2-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-ie-le-3-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-ie-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-desc-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-gd-le-ilp32.d: New test.
2017-01-23 17:07:13 +00:00
Nick Clifton 8069955ee0 Updated Irish translation for ld and Swedish translation for gas. 2017-01-23 13:32:12 +00:00
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 adcbdc63e5 PR ld/20828: Relax symbol ordering in tests
Complement commit 81ff47b3a5 ("PR ld/20828: Fix linker script symbols
wrongly forced local with section GC") and make tests check for the
presence of global `_fdata' and `_edata' symbols separately, removing
any dependency on symbol table ordering for tests to succeed and
removing:

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

failures with the `x86_64-solaris2' target, which has additional
intervening entries:

Symbol table '.dynsym' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    1 _fdata
     2: 0000000000000000     0 OBJECT  GLOBAL DEFAULT    1 _DYNAMIC
     3: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS _PROCEDURE_LINKAGE_TABLE_
     4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    1 _edata
     5: 00000000000001b8     0 OBJECT  GLOBAL DEFAULT    4 _GLOBAL_OFFSET_TABLE_

Rename dump pattern files accordingly for consistency.

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828-1.sd: Remove test.
	* testsuite/ld-elf/pr20828-a.sd: New test.
	* testsuite/ld-elf/pr20828-2a.sd: Rename test to...
	* testsuite/ld-elf/pr20828-b.sd: ... this.
	* testsuite/ld-elf/pr20828-2b.sd: Rename test to...
	* testsuite/ld-elf/pr20828-c.sd: ... this.
	* testsuite/ld-elf/shared.exp: Adjust accordingly.
2017-01-23 11:24:21 +00:00
Jiong Wang 9966f7eece [ld, testsuite] Honor cflags when GCC used as linker driver
ld/
	* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Append
	board_cflags as gcc is used as linker driver.
	* testsuite/ld-unique/unique.exp: Likewise
2017-01-23 09:59:10 +00:00
Jiong Wang 7f784814df [AArch64] Optimize .gnu.hash table size for executable
bfd/
	* elfnn-aarch64.c (elf_aarch64_hash_symbol): New function.
	(elf_backend_hash_symbol): Define.

ld/
	* testsuite/ld-aarch64/aarch64-elf.exp (aarch64elflinktests): New tests.
	* testsuite/ld-aarch64/func-in-so.s: New test source file.
	* testsuite/ld-aarch64/func-sym-hash-opt.s: Likewise.
	* testsuite/ld-aarch64/func-sym-hash-opt.d: New expected test result.
2017-01-20 13:30:32 +00:00
Andrew Burgess 1737c64030 objdump: Better objdump section headers in wide mode
When displaying the section headers table using objdump (-h), the column
containing the section header name is currently fixed at 13 characters.
A section name that is longer than 13 characters will overflow the
column causing the table to become miss-aligned.

In this commit I change the behaviour so that _in wide mode_ (-w -h) the
section name column is dynamically resized to fit the longest section
name we plan to display.  In wide mode the column still retains a
minimum width of 13 characters.

In non-wide more the behaviour is completely unchanged.

While I was changing the dump_headers function I have unified the two
printf lines that handled the different address widths into a single
printf, the address width is now passed into printf using the '*' field
width format character.

binutils/ChangeLog:

	* objdump.c (dump_section_header): Extract max section name length
	from data parameter, use this when formatting output.
	(find_longest_section_name): New function.
	(dump_headers): Calculate longest section name when in wide mode,
	reformat to unify printing of header line.

ld/ChangeLog:

	* testsuite/ld-elf/eh-frame-hdr.d: Update expected results.
2017-01-20 09:05:41 +00:00
Maciej W. Rozycki 6984613a53 PR ld/20995: MIPS: Set GAS flags correctly for tests
Complement commit 9acc85a62e ("Use dynrelro for symbols in relro
sections too").

	ld/
	PR ld/20995
	* testsuite/ld-elf/elf.exp: Set GAS flags correctly for the
	`mips*-*-*' target and `pr20995' and `pr20995-2' tests.
2017-01-18 23:19:07 +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
Maciej W. Rozycki 9e009953a5 PR gas/20649: MIPS: Fix GOT16/LO16 reloc pairing with comdat sections
Correct a regression from commit 8614eeee67 ("Traditional MIPS
patches"), <https://sourceware.org/ml/binutils/2000-07/msg00018.html>,
which caused symbols in linkonce or what is these days known as comdat
sections to be treated as external for the purpose of PIC relocation
generation even if their binding remains STB_LOCAL.  This in turn
disabled GOT16/LO16 relocation pairing with references to such symbols,
as no complementing LO16 relocation is expected for external GOT16
references in the o32 ABI, which ultimately leads to link errors, e.g.:

ld: comdat-reloc.o: Can't find matching LO16 reloc against `foo' for R_MIPS_GOT16 at 0x24 in section `.text.bar[bar]'

as with the LD test case included with this change.

Revert the special case for symbols in comdat sections then, making code
actually match `adjust_reloc_syms' as indicated in its explanatory
comment, and adjust calling code accordingly.  Also bring back the
corresponding description of what now is `s_is_linkonce', lost with
commit 5f0fe04bc5 ("Improved MIPS16/MIPS32 code intermixing for
gas."), <https://www.sourceware.org/ml/binutils/2006-07/msg00039.html>.

	gas/
	PR gas/20649
	* config/tc-mips.c (pic_need_relax): Don't check for linkonce
	symbols, remove the `segtype' parameter.
	(mips_frob_file, md_estimate_size_before_relax): Adjust
	accordingly.
	(s_is_linkonce): Add an explanatory comment.
	* testsuite/gas/mips/comdat-reloc.d: New test.
	* testsuite/gas/mips/comdat-reloc.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new test.

	ld/
	PR gas/20649
	* testsuite/ld-mips-elf/mips-elf.exp: Add PIC comdat GOT16/LO16
	relocation pairing link test.
2017-01-18 18:24:08 +00:00
Dimitar Dimitrov 319b82e47d Skip linker tests for unique symbols in shared libraries if the target does not support building shared libraries.
ld	* testsuite/ld-unique/unique.exp: Filter shared lib cases in
	uniqeue.exp, as not all targets have such support.
2017-01-18 12:23:19 +00:00
Nick Clifton 6aa1df2d44 Updated Swedish translations for GAS and LD subdirectories.
gas	* po/sv.po: Updated Swedish translation.
ld	* po/sv.po: Updated Swedish translation.
2017-01-16 10:59:23 +00:00
H.J. Lu 8361ed4d6b x86-64: Also generate unwind info for .plt.bnd
Also generate unwind info for the .plt.bnd section.  Sine it is the same
as unwind info for the .plt.got section, we use unwind info for the
.plt.got section to cover the the .plt.bnd section.

bfd/

	PR ld/21038
	* elf64-x86-64.c (elf_x86_64_link_hash_table): Add
	plt_bnd_eh_frame.
	(elf_x86_64_check_relocs): Create .eh_frame section for the
	.plt.bnd section.
	(elf_x86_64_size_dynamic_sections): Allocate and initialize
	.eh_frame section for the .plt.bnd section.
	(elf_x86_64_finish_dynamic_sections): Adjust .eh_frame section
	for the .plt.bnd section.

ld/

	PR ld/21038
	* testsuite/ld-x86-64/pr21038b.d: Updated.
	* testsuite/ld-x86-64/pr21038c.d: New file.
	* testsuite/ld-x86-64/pr21038c.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr21038c.
2017-01-12 10:32:17 -08:00
H.J. Lu 9e65917652 x86-64: Correct unwind info for the BND PLT
Since the BND PLT has

 230:	68 00 00 00 00       	pushq  $0x0
 235:	f2 e9 e5 ff ff ff    	bnd jmpq 220 <.plt>
 23b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)

instead of

 230:	ff 25 e2 0d 20 00    	jmpq   *0x200de2(%rip)        # 201018
<func>
 236:	68 00 00 00 00       	pushq  $0x0
 23b:	e9 e0 ff ff ff       	jmpq   220 <.plt>

its unwind info should be

DW_CFA_def_cfa_expression (DW_OP_breg7 (rsp): 8; DW_OP_breg16 (rip): 0;
DW_OP_lit15; DW_OP_and; DW_OP_lit5; DW_OP_ge; DW_OP_lit3; DW_OP_shl;
DW_OP_plus)

bfd/

	PR ld/21038
	* elf64-x86-64.c (elf_x86_64_eh_frame_bnd_plt): New.
	(elf_x86_64_bnd_arch_bed): Use elf_x86_64_eh_frame_bnd_plt and
	elf_x86_64_eh_frame_plt_got.
	(elf_x86_64_size_dynamic_sections): Get unwind info from
	elf_x86_64_bnd_arch_bed for the BND PLT.

ld/

	PR ld/21038
	* testsuite/ld-x86-64/pr21038a.d: New file.
	* testsuite/ld-x86-64/pr21038a.s: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr21038a and pr21038b.
2017-01-11 09:17:05 -08:00
Jeremy Soller f2e2d2f54b Add support for x86/64 redox target.
bfd	* config.bfd: Add entries for i686-redox and x86_64-redox.

gas	* configure.tgt: Add entry for i386-redox.

ld	* configure.tgt: Add entries for x86-redox and x86_64-redox.
2017-01-11 15:05:53 +00:00
H.J. Lu 52b232b366 i386/x32: Align .eh_frame section to 4 bytes
.eh_frame section covering PLT sections should be aligned to 4 bytes
for i386 and x32.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Align .eh_frame section
	to 4 bytes.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Align
	.eh_frame section to 4 bytes for x32.
	(elf_x86_64_check_relocs): Likewise.

ld/

	* testsuite/ld-x86-64/pr20830b.d: Updated.
2017-01-10 14:21:21 -08:00
H.J. Lu 59a1e29d9e X32: Place .plt.got section after .plt section
This patch places .plt.got section after .plt section for x32.

	* emulparams/elf32_x86_64.sh (TINY_READONLY_SECTION): New.
	* testsuite/ld-x86-64/pr20830.d: Renamed to ...
	* testsuite/ld-x86-64/pr20830a.d: This.  Updated.
	* testsuite/ld-x86-64/pr20830b.d: New file.
	* testsuite/ld-x86-64/x86-64.exp: Rename pr20830 to pr20830a.
	Run pr20830b.
2017-01-10 13:57:39 -08:00
H.J. Lu fff53daefb i386/x86-64: Add unwind info for .plt.got section
When there are both PLT and GOT references to the same function symbol,
linker combines GOTPLT and GOT slots into a single GOT slot and create
an entry in .plt.got section for PLT access via the GOT slot.  This
patch adds unwind info for .plt.got section.

bfd/

	PR ld/20830
	* elf32-i386.c (elf_i386_eh_frame_plt_got): New.
	(PLT_GOT_FDE_LENGTH): Likewise.
	(elf_i386_plt_layout): Add eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_i386_plt): Updated.
	(elf_i386_link_hash_table): Add plt_got_eh_frame.
	(elf_i386_check_relocs): Create .eh_frame section for .plt.got.
	(elf_i386_size_dynamic_sections): Allocate and initialize
	.eh_frame section for .plt.got.
	(elf_i386_finish_dynamic_sections): Adjust .eh_frame section for
	.plt.got.
	(elf_i386_nacl_plt): Add FIXME for eh_frame_plt_got and
	eh_frame_plt_got_size.
	* elf64-x86-64.c (elf_x86_64_eh_frame_plt_got): New.
	(PLT_GOT_FDE_LENGTH): Likewise.
	(elf_x86_64_backend_data): Add eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_x86_64_arch_bed): Updated.
	(elf_x86_64_bnd_arch_bed): Add FIXME for eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_x86_64_nacl_arch_bed): Likewise.
	(elf_x86_64_link_hash_table): Add plt_got_eh_frame.
	(elf_x86_64_check_relocs): Create .eh_frame section for .plt.got.
	(elf_x86_64_size_dynamic_sections): Allocate and initialize
	.eh_frame section for .plt.got.
	(elf_x86_64_finish_dynamic_sections): Adjust .eh_frame section
	for .plt.got.

ld/

	PR ld/20830
	* testsuite/ld-i386/i386.exp: Run pr20830.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr20830.d: New file.
	* testsuite/ld-i386/pr20830.s: Likewise.
	* testsuite/ld-x86-64/pr20830.d: Likewise.
	* testsuite/ld-x86-64/pr20830.s: Likewise.
2017-01-10 13:31:59 -08:00
H.J. Lu e92372274e i386: Pass -Wl,-R,tmpdir/-Wl --as-needed to $CC
Since linker tests were changed to use $CC, instead of $LD, we need
to pass -Wl,-R,tmpdir and -Wl,--as-needed to $CC.

	* testsuite/ld-i386/i386.exp: Pass -Wl,-R,tmpdir to GCC driver.
	* testsuite/ld-i386/tls.exp: Likewise.
2017-01-10 10:58:51 -08:00
Nick Clifton 07e8e62387 Updated Swedish translations for GAS and LD 2017-01-10 11:28:36 +00:00
Graham Markall 07ccf83cf5 [ARC] Add new linker emulation for nps
The arc700 nps variant uses some specific named sections to
facilitate its CMEM based instructions, which operate on memory
regions fixed at specific addresses.

This commit adds the arclinux_nps emulation, which is based on the
arclinux emulation. The new emulation uses the OTHER_SECTIONS
variable in the emulation parameters script to provide symbols
mapping to various locations in the CMEM space on nps.

The accompanying test ensures that all symbols are provided at the
correct address in the linker script.

ld/ChangeLog:

  * Makefile.am: Add earclinux_nps.c target and add to
  ALL_EMULATION_SOURCES.
  * Makefile.in: Likewise, regenerated.
  * configure.tgt: Add arclinux_nps as an extra emulation for
  arc*-*-elf* and arc*-*-linux*.
  * emulparams/arc-nps.sh: New file.
  * emulparams/arclinux_nps.sh: New file.
  * testsuite/ld-arc/arclinux-nps.d,
  * testsuite/ld-arc/arclinux-nps.s: New test.
2017-01-10 10:55:13 +00:00
Palmer Dabbelt 6ec11ab97a Remove some custom sections from RISC-V's default linker scripts
This was added so compressed loads could have smaller offsets for
accessing the data section, but the result was that writable sections
ended up in INITIAL_READONLY_SECTIONS.  This is a bad idea.  The fix is
to just remove this micro-optimization.

Thanks to Alan Morda for finding the problem!

ld/ChangeLog

2017-01-09  Palmer Dabbelt <palmer@dabbelt.com>
            Kito Cheng <kito.cheng@gmail.com>

        * emulparams/elf32lriscv-defs.sh (INITIAL_READONLY_SECTIONS):
        Removed.
        (SDATA_START_SYMBOLS): Likewise.
2017-01-09 09:12:20 -08:00
Dilan Palauzov b055631694 Use noyywrap option in lex files.
ld	PR 20958
	* ldlex.l (option): Add noyywrap
	(yywrap): Delete.
	* ldlex.h (yywrap): Delete prototype.

binutils
	PR 20958
	* syslex.l (option): Add noyywrap
	(yywrap): Delete.
2017-01-04 16:05:22 +00:00
Alan Modra 47523653a3 Check for shared lib support before running ld tests with -shared
Another fix now that we run these tests non-native.

	* testsuite/ld-elf/audit.exp: Check for shared lib support.
	* testsuite/ld-elf/compress.exp: Likewise.
	* testsuite/ld-elf/dwarf.exp: Likewise.
	* testsuite/ld-elf/shared.exp: Likewise.
	* testsuite/ld-elf/wrap.exp: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Check $CXX exists.
2017-01-04 09:39:12 +10:30