Commit Graph

5762 Commits

Author SHA1 Message Date
Alan Modra ba52cbb9d0 Reduce excessive .eh_frame alignment for powerpc
PowerPC64 .cfi directives use DW_EH_PE_sdata4 encoding for .eh_frame,
so there is no real reason why .eh_frame should be 8 byte aligned.

gas/
	* config/tc-ppc.h (EH_FRAME_ALIGNMENT): Define.
ld/
	* testsuite/ld-powerpc/tlsopt5.wf: Update for reduced alignment.
2017-09-21 23:17:44 +09:30
Maciej W. Rozycki b7f54058d9 MIPS/LD: Add OpenBSD/mips64 support
Complement commit 26eebcf553 ("Update OpenBSD/mips64 support"),
<https://sourceware.org/ml/binutils/2005-04/msg00382.html>, which added
OpenBSD/mips64 support to GAS, and also add it to LD, avoiding a build
failure at the configuration stage, like:

*** ld does not support target mips64-unknown-openbsd
*** see ld/configure.tgt for supported targets
make[1]: *** [configure-ld] Error 1

As per OS support only include n64 MIPS emulations, and use the
traditional ones, matching the choice already made with the addition of
GAS support.

	ld/
	* configure.tgt <mips64el-*-openbsd*, mips64-*-openbsd*>: New
	targets.
2017-09-19 15:20:41 +01:00
Alan Modra 8fd138c43b PR22118, Incorrectly-capitalized regexp
PR 22118
	* testsuite/ld-aarch64/erratum843419.d: Correct regexp.
2017-09-15 20:21:42 +09:30
H.J. Lu 79254a5260 globalaudit.rd: Allow additional bits in DT_FLAGS_1
With -PIE on x86-64, we get

 0x000000006ffffffb (FLAGS_1)            Flags: GLOBAUDIT PIE

We should allow additional bits in DT_FLAGS_1.

	PR ld/22139
	* testsuite/ld-elf/globalaudit.rd: Allow additional bits in
	DT_FLAGS_1.
2017-09-14 12:45:18 -07:00
H.J. Lu 5e5e02aeca x86: Cache section contents and relocations
bfd/

	PR ld/22135
	* elf32-i386.c (elf_i386_convert_load_reloc): Add an argument
	to indicate if conversion is performed.
	(elf_i386_check_relocs): Cache section contents and relocations
	if conversion is performed.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Cache section
	contents and relocations if conversion is performed.

ld/

	PR ld/22135
	* testsuite/ld-i386/i386.exp: Run pr22135.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22135.d: New file.
	* testsuite/ld-i386/pr22135.s: Likewise.
	* testsuite/ld-x86-64/pr22135.d: Likewise.
	* testsuite/ld-x86-64/pr22135.s: Likewise.
2017-09-14 12:29:29 -07:00
Alan Modra 2420fff633 PowerPC64 --plt-align
This changes the PowerPC64 --plt-align option to perform the usual
alignment of code as suggested by its name, as well as the previous
behaviour of padding so as to reduce boundary crossing.  The old
behaviour is had by using a negative parameter.

The default is also changed to align plt stub code by default to 32
byte boundaries, the point being to get better bctr branch prediction
on power8 and power9 hardware.

bfd/
	* elf64-ppp.c (plt_stub_pad): Handle positive and negative
	plt_stub_align.
ld/
	* ld.texinfo (--plt-align): Describe new behaviour of option.
	* emultempl/ppc64elf.em (params): Default plt_stub_align to 5.
	* testsuite/ld-powerpc/powerpc.exp: Pass --no-plt-align for
	selected tests.
	* testsuite/ld-powerpc/relbrlt.d: Pass --no-plt-align.
	* testsuite/ld-powerpc/elfv2so.d: Adjust expected output.
2017-09-10 01:55:16 +09:30
H.J. Lu 0a27fed72d x86: Properly handle __ehdr_start
After _bfd_i386_elf_convert_load and _bfd_x86_64_elf_convert_load are
removed, elf_i386_convert_load_reloc and elf_x86_64_convert_load_reloc
see __ehdr_start as an undefined symbol when they are called from
check_relocs to convert GOT relocations against local symbols.  But
__ehdr_start will be defined as a hidden symbol by linker at the later
stage if it is referenced.  This patch marks __ehdr_start as a defined
local symbol at the start of check_relocs if it is referenced and not
defined.

bfd/

	PR ld/22115
	* elf32-i386.c (elf_i386_convert_load_reloc): Check linker_def.
	Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Check
	linker_def.  Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set local_ref
	and linker_def on __ehdr_start if it is referenced and not
	defined.
	(_bfd_x86_elf_link_symbol_references_local): Also set local_ref
	and return TRUE when building executable, if a symbol has
	non-GOT/non-PLT relocations in text section or there is no
	dynamic linker.
	* elfxx-x86.h (elf_x86_link_hash_entry): Add linker_def.

ld/

	PR ld/22115
	* ld-i386/i386.exp: Run PR ld/22115 tests,
	* ld/testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22115-1.s: New file.
	* testsuite/ld-i386/pr22115-1a.d: Likewise.
	* testsuite/ld-i386/pr22115-1b.d: Likewise.
	* testsuite/ld-i386/pr22115-1c.d: Likewise.
	* testsuite/ld-i386/pr22115-1d.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1.s: Likewise.
	* testsuite/ld-x86-64/pr22115-1a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1a.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1b.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1c.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1d.d: Likewise.
2017-09-09 05:05:29 -07:00
H.J. Lu 78984959cb x86-64: Add R_X86_64_converted_reloc_bit
Add R_X86_64_converted_reloc_bit to relocation type to indicate if a
relocation is converted from a GOTPCREL relocation.  Linker now generates

failed to convert GOTPCREL relocation; relink with --no-relax

for all cases, including relocations against local symbols.

bfd/

	* elf64-x86-64.c (R_X86_64_converted_reloc_bit): New.
	(elf_x86_64_info_to_howto): Get the real relocation type by
	masking out R_X86_64_converted_reloc_bit.
	(elf_x86_64_check_tls_transition): Get the real relocation type
	by masking out R_X86_64_converted_reloc_bit.
	(elf_x86_64_convert_load_reloc): Set R_X86_64_converted_reloc_bit
	instead of setting converted_reloc.
	(elf_x86_64_relocate_section): Check R_X86_64_converted_reloc_bit
	instead of converted_reloc. Get the real relocation type by
	masking out R_X86_64_converted_reloc_bit.
	(elf_x86_64_link_setup_gnu_properties): Verify that the value of
	R_X86_64_converted_reloc_bit is valid.
	* elfxx-x86.h (converted_reloc): Removed.

ld/

	* testsuite/ld-x86-64/pr19609-2a.d: Updated.
	* testsuite/ld-x86-64/pr19609-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4c.d: Likewise.
2017-09-06 05:06:35 -07:00
H.J. Lu dc08907213 x86-64: Properly set converted_reloc
Linker now generates

failed to convert GOTPCREL relocation; relink with --no-relax

for more cases.

bfd/

	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Properly set
	converted_reloc.

ld/

	* testsuite/ld-x86-64/pr19609-5d.d: Updated.
	* testsuite/ld-x86-64/pr19609-7a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7c.d: Likewise.
2017-09-05 13:43:02 -07:00
H.J. Lu 8b43e45688 x86-64: Improve GOTPCREL relocation conversion
When GOTPCREL relocation conversion leads to relocation overflow, we
may get a mysterious linker message, like

relocation truncated to fit: R_X86_64_32S against symbol `foo'

This patch changes the linker message to

failed to convert GOTPCREL relocation; relink with --no-relax

bfd/

	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Remove the sec
	argument.  Don't check relocation overflow.  Avoid relocation
	overflow if --no-relax is used.  Set converted_reloc on symbol
	if a GOTPCREL relocation is converted.
	(elf_x86_64_relocate_section): Issue a fatal error and suggest
	--no-relax if GOTPCREL relocation conversion leads to relocation
	overflow.
	* elfxx-x86.h (elf_x86_link_hash_entry): Add converted_reloc.

ld/

	* testsuite/ld-x86-64/pr19609-4e.d: Updated.
	* testsuite/ld-x86-64/pr19609-6a.d: Likewise.
2017-09-05 11:24:14 -07:00
H.J. Lu 0e30d99180 x86-64: Set tlsdesc_plt if GOT_TLS_GDESC_P is true
We need to set tlsdesc_plt for x86-64 if GOT_TLS_GDESC_P is true when
allocating dynamic relocations so that _bfd_x86_elf_size_dynamic_sections
will generate TLSDESC_PLT and TLSDESC_GOT in x86-64 output.

bfd/

	PR ld/22071
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Set tlsdesc_plt
	for x86-64 if GOT_TLS_GDESC_P is true.

ld/

	PR ld/22071
	* testsuite/ld-x86-64/pr22071.d: New file.
	* testsuite/ld-x86-64/pr22071.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr22071.
2017-09-03 10:18:38 -07:00
Alan Modra 1fa4ec6ae7 LTO rescan archives
ld ought to be more clever about where it puts LTO recompiled objects.
Ideally the recompiled objects ought to be ordered to the same place
their IR objects were, and files extracted from archives on the second
pass ought to go in the same place as they would if extracted on the
first pass.  This patch addresses the archive problem.  Without this
fix, objects extracted from archives might be placed after the crt
files intended to go at the end of an executable or shared library,
possibly causing exception handling failures.

	* ldlang.h (lang_input_statement_type): Expand comments.
	(LANG_FOR_EACH_INPUT_STATEMENT): Rewrite without casts.
	* ldlang.c (lang_for_each_input_file): Likewise.
	(load_symbols): Set usrdata for archives.
	(find_rescan_insertion): New function.
	(lang_process): Trim off and reinsert entries added to file chain
	when rescanning archives for LTO.
	* ldmain.c (add_archive_element): Set my_archive input_statement
	next pointer to last element added.
2017-09-02 17:39:04 +09:30
H.J. Lu ad71ce8de7 x86-64: Check ELF_COMMON_DEF_P for common symbols
bfd/

	PR ld/22064
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Check
	ELF_COMMON_DEF_P for common symbols.

ld/

	PR ld/22064
	* testsuite/ld-x86-64/pr22064a.S: New file.
	* testsuite/ld-x86-64/pr22064b.c: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/22064 test.
2017-09-01 18:55:55 -07:00
Alan Modra 96d01d93c4 -Og warning fixes
Found when building with gcc 4.9.4 using -Og.

bfd/
	* elf-eh-frame.c (offset_adjust): Avoid false positive gcc warning.
	* elflink.c (bfd_elf_size_dynsym_hash_dynstr): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
ld/
	* emultempl/msp430.em (eval_upper_either_sections): Make base_sec_name
	a const char*.
	(eval_lower_either_sections): Likewise.
	(msp430_elf_after_allocation): Likewise, and don't needlessly concat
	and free.  Warning fix.
2017-09-02 11:00:02 +09:30
H.J. Lu e10c9c620c x86: Correct unwind information for the second PLT
For i386, generate unwind information for the second PLT.  For x32,
correct alignment of .eh_frame section for the second PLT.

bfd/

	PR ld/22061
	* elf32-i386.c (elf_i386_link_setup_gnu_properties): Create
	.eh_frame section for the second PLT.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Correct
	alignment of .eh_frame section for the second PLT.

ld/

	PR ld/22061
	* testsuite/ld-i386/ibt-plt-1.d: Updated.
	* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2b.d: Pass --hash-style=sysv to ld
	and dump unwind information.
	* testsuite/ld-i386/ibt-plt-2d.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3d.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2b-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2d-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2d.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3b-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3d-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3d.d: Likewise.
2017-09-01 06:12:06 -07:00
H.J. Lu d7de64088c Add a test for PR ld/22048
PR ld/22048
	* testsuite/ld-x86-64/pr22048.d: New file.
	* testsuite/ld-x86-64/pr22048a.s: Likewise.
	* testsuite/ld-x86-64/pr22048b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr22048.
2017-08-31 03:54:01 -07:00
Alan Modra 9866ffe25a Remove .eh_frame zero terminators
The machinery to do this was there, but not enabled if the terminator
was the only thing in the section.

bfd/
	* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Don't exit early
	for a section containing just a terminator.  Allow multiple
	terminators at end of section.
	* elflink.c (bfd_elf_discard_info): Iterate over .eh_frame
	sections when not adding alignment.  Assert on terminator in
	the middle of FDEs.
ld/
	* testsuite/ld-elf/eh3.d: Update.
	* testsuite/ld-elf/eh4.d: Update.
2017-08-31 19:40:35 +09:30
Maciej W. Rozycki 5dda32094f LD/testsuite: Also discard `.MIPS.options' in orphan tests
Complement commit 5b5f4e6f8c ("ld: Early detection of orphans we know
will be discarded") and add `.MIPS.options' to the list of sections
discarded with orphan tests, removing failures like:

./ld-new: error: unplaced orphan section `.MIPS.options' from `tmpdir/orphan-11.o'.
FAIL: ld-elf/orphan-11

and:

./ld-new: error: unplaced orphan section `.MIPS.options' from `tmpdir/orphan-12.o'.
FAIL: ld-elf/orphan-12

from n64 MIPS testing.

	ld/
	* testsuite/ld-elf/orphan-11.ld: Also discard `.MIPS.options'
	sections.
2017-08-30 22:55:14 +01:00
Maciej W. Rozycki 70e65ca8e5 MIPS/BFD: Correct microMIPS cross-mode BAL to JALX relaxation
Fix a bug in commit a6ebf6169a ("MIPS: Convert cross-mode BAL to
JALX") and in BFD linker relaxation correct the microMIPS interpretation
of the branch offset, which is supposed to be shifted by 1 bit, rather
than 2 as in the regular MIPS case.

	bfd/
	* elfxx-mips.c (mips_elf_perform_relocation): Correct microMIPS
	branch offset interpretation.

	gas/
	* testsuite/gas/mips/branch-addend-micromips.d: New test.
	* testsuite/gas/mips/branch-addend-micromips-n32.d: New test.
	* testsuite/gas/mips/branch-addend-micromips-n64.d: New test.
	* testsuite/gas/mips/branch-addend-micromips.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/bal-jalx-addend-micromips.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-addend-micromips-n32.d: New
	test.
	* testsuite/ld-mips-elf/bal-jalx-addend-micromips-n64.d: New
	test.
	* testsuite/ld-mips-elf/bal-jalx-local-micromips.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-local-micromips-n32.d: New
	test.
	* testsuite/ld-mips-elf/bal-jalx-local-micromips-n64.d: New
	test.
	* testsuite/ld-mips-elf/bal-jalx-pic-micromips.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic-micromips-n32.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic-micromips-n64.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips.d: New
	test.
	* testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n32.d: New
	test.
	* testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n64.d: New
	test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-08-30 16:07:45 +01:00
Alan Modra 9a23f96e91 PowerPC TPREL16_HA/LO reloc optimization
In the TLS GD/LD to LE optimization, ld replaces a sequence like

 addi 3,2,x@got@tlsgd		R_PPC64_GOT_TLSGD16	x
 bl __tls_get_addr(x@tlsgd)	R_PPC64_TLSGD		x
				R_PPC64_REL24		__tls_get_addr
 nop

with

 addis 3,13,x@tprel@ha		R_PPC64_TPREL16_HA	x
 addi 3,3,x@tprel@l		R_PPC64_TPREL16_LO	x
 nop

When the tprel offset is small, this can be further optimized to

 nop
 addi 3,13,x@tprel
 nop

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add do_tls_opt.
	(ppc64_elf_tls_optimize): Set it.
	(ppc64_elf_relocate_section): Nop addis on TPREL16_HA, and convert
	insn on TPREL16_LO and TPREL16_LO_DS relocs to use r13 when
	addis would add zero.
	* elf32-ppc.c (struct ppc_elf_link_hash_table): Add do_tls_opt.
	(ppc_elf_tls_optimize): Set it.
	(ppc_elf_relocate_section): Nop addis on TPREL16_HA, and convert
	insn on TPREL16_LO relocs to use r2 when addis would add zero.
gold/
	* powerpc.cc (Target_powerpc::Relocate::relocate): Nop addis on
	TPREL16_HA, and convert insn on TPREL16_LO and TPREL16_LO_DS
	relocs to use r2/r13 when addis would add zero.
ld/
	* testsuite/ld-powerpc/tls.s: Add calls with tls markers.
	* testsuite/ld-powerpc/tls32.s: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Run tls marker tests.
	* testsuite/ld-powerpc/tls.d: Adjust for TPREL16_HA/LO optimization.
	* testsuite/ld-powerpc/tlsexe.d: Likewise.
	* testsuite/ld-powerpc/tlsexetoc.d: Likewise.
	* testsuite/ld-powerpc/tlsld.d: Likewise.
	* testsuite/ld-powerpc/tlsmark.d: Likewise.
	* testsuite/ld-powerpc/tlsopt4.d: Likewise.
	* testsuite/ld-powerpc/tlstoc.d: Likewise.
2017-08-30 20:43:31 +09:30
Alan Modra b9f04fe0df PowerPC64 __tls_get_addr sequence optimization
There isn't a good reason for ld.bfd to behave differently from gold
in the code generated by TLS GD/LD to LE optimization.

bfd/
	* elf64-ppc.c (ppc64_elf_relocate_section): When optimizing
	__tls_get_addr call sequences to LE, don't move the addi down
	to the nop.  Replace the bl with addi and leave the nop alone.
ld/
	* testsuite/ld-powerpc/tls.d: Update.
	* testsuite/ld-powerpc/tlsexe.d: Update.
	* testsuite/ld-powerpc/tlsexetoc.d: Update.
	* testsuite/ld-powerpc/tlsld.d: Update.
	* testsuite/ld-powerpc/tlsmark.d: Update.
	* testsuite/ld-powerpc/tlsopt4.d: Update.
	* testsuite/ld-powerpc/tlstoc.d: Update.
2017-08-30 20:35:09 +09:30
Hans-Peter Nilsson c7dffc390c testsuite/ld-cris various files: Run ld with --hash-style=sysv.
* testsuite/ld-cris/dso-pltdis1.d: Run ld with --hash-style=sysv.
	* testsuite/ld-cris/dso-pltdis2.d,
	testsuite/ld-cris/dso12-pltdis.d, testsuite/ld-cris/expdyn1.d,
	testsuite/ld-cris/expdyn5.d, testsuite/ld-cris/expdyn6.d,
	testsuite/ld-cris/expdyn7.d, testsuite/ld-cris/gotplt1.d,
	testsuite/ld-cris/gotplt2.d, testsuite/ld-cris/gotplt3.d,
	testsuite/ld-cris/hiddef1.d, testsuite/ld-cris/libdso-11.d,
	testsuite/ld-cris/libdso-12.d, testsuite/ld-cris/libdso-12b.d,
	testsuite/ld-cris/libdso-12c.d, testsuite/ld-cris/libdso-13.d,
	testsuite/ld-cris/libdso-13b.d, testsuite/ld-cris/libdso-14.d,
	testsuite/ld-cris/libdso-15.d, testsuite/ld-cris/libdso-15b.d,
	testsuite/ld-cris/libdso-1b.d, testsuite/ld-cris/libdso-1c.d,
	testsuite/ld-cris/libdso-1d.d, testsuite/ld-cris/libdso-4.d,
	testsuite/ld-cris/pr16044.d, testsuite/ld-cris/pv32-1.d,
	testsuite/ld-cris/tls-dso-dtpoffd2.d,
	testsuite/ld-cris/tls-dso-dtpoffd4.d,
	testsuite/ld-cris/tls-dso-tpoffgotcomm1.d,
	testsuite/ld-cris/tls-dso-x1x2-1.d, testsuite/ld-cris/tls-gc-71.d,
	testsuite/ld-cris/tls-ie-78.d, testsuite/ld-cris/tls-js1.d,
	testsuite/ld-cris/tls-ldgdex-14.d,
	testsuite/ld-cris/tls-ldgdex-15.d,
	testsuite/ld-cris/tls-legdx-16.d,
	testsuite/ld-cris/tls-legdx-17.d,
	testsuite/ld-cris/tls-local-63.d,
	testsuite/ld-cris/tls-local-64.d, testsuite/ld-cris/tls-ok-30.d,
	testsuite/ld-cris/tls-ok-32.d, testsuite/ld-cris/tls-ok-34.d,
	testsuite/ld-cris/tls-und-38.d, testsuite/ld-cris/tls-und-42.d,
	testsuite/ld-cris/tls-und-46.d, testsuite/ld-cris/tls-und-50.d,
	testsuite/ld-cris/weakref2.d, testsuite/ld-cris/weakref3.d,
	testsuite/ld-cris/weakref4.d: Likewise.
2017-08-30 02:27:14 +02:00
Jozef Lawrynowicz 7ef3addbe1 Improve MSP430 section placement.
ld	* emultempl/msp430.em (change_output_section): New function.
	(move_prefixed_section): New function.
	(add_region_prefix): New function.
	(msp430_elf_after_open): New function.
	(gld${EMULATION_NAME}_add_options): Implement.
	(gld${EMULATION_NAME}_list_options): Implement.
	(gld${EMULATION_NAME}_handle_option): Implement.
	* ld.texinfo: Document new options.
	* testsuite/ld-msp430-elf/main-bss-lower.d: New.
	* testsuite/ld-msp430-elf/main-bss-upper.d: New.
	* testsuite/ld-msp430-elf/main-const-lower.d: New.
	* testsuite/ld-msp430-elf/main-const-upper.d: New.
	* testsuite/ld-msp430-elf/main-text-lower.d: New.
	* testsuite/ld-msp430-elf/main-text-upper.d: New.
	* testsuite/ld-msp430-elf/main-var-lower.d: New.
	* testsuite/ld-msp430-elf/main-var-upper.d: New.
	* testsuite/ld-msp430-elf/main-with-data-bss-unique-sec.s: New.
	* testsuite/ld-msp430-elf/main-with-data-bss.s: New.
	* testsuite/ld-msp430-elf/main-with-text-rodata-unique-sec.s: New.
	* testsuite/ld-msp430-elf/main-with-text-rodata.s: New.
	* testsuite/ld-msp430-elf/msp430-elf.exp: New.
	* testsuite/ld-msp430-elf/msp430-no-lower.ld: New.
	* testsuite/ld-msp430-elf/msp430.ld: New.
	* emultempl/msp430.em (data_statement_size): New.
	(eval_upper_either_sections): New.
	(eval_lower_either_sections): New.
	(intermediate_relax_sections): New.
	(msp430_elf_after_allocation): New.
	* emultempl/msp430.em (gld${EMULATION_NAME}_place_orphan): Always
	place sections in the lower region.

gas	* config/tc-msp430.c (md_parse_option): Define high data and high
	bss symbols if -mdata-region is passed.
	Define -mdata-region open.
	* doc/c-msp430.texi: Document -mdata-region.
	* testsuite/gas/msp430/high-data-bss-sym.d: New test.
	* testsuite/gas/msp430/high-data-bss-sym.s: New.
	* testsuite/gas/msp430/msp430.exp: Add -mdata-region tests.
2017-08-29 17:18:43 +01:00
H.J. Lu a5b4ee9451 Disallow copy relocation against protected data symbol
We shpouldn't generate copy relocation to resolve reference to protected
data symbol defined in shared object with the NO_COPY_ON_PROTECTED
property.  This patch adds a bit to elf_obj_tdata as well as
elf_i386_link_hash_entry and elf_x86_64_link_hash_entry to track the bfd
with the NO_COPY_ON_PROTECTED property as well as protected symbol
defined in shared object.  extern_protected_data is set to FALSE if any
input relocatable file contains the NO_COPY_ON_PROTECTED property.

bfd/

	PR ld/21997
	* elf-bfd.h (elf_obj_tdata): Use ENUM_BITFIELD on object_id,
	dyn_lib_class and has_gnu_symbols.  Change bad_symtab to bitfield.
	Add a has_no_copy_on_protected bitfield.
	(elf_has_no_copy_on_protected): New.
	* elf-properties.c (_bfd_elf_parse_gnu_properties): Set
	elf_has_no_copy_on_protected for GNU_PROPERTY_NO_COPY_ON_PROTECTED.
	(elf_merge_gnu_property_list): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Set extern_protected_data
	to FALSE for elf_has_no_copy_on_protected.
	* elf32-i386.c (SYMBOL_NO_COPYRELOC): New.
	(elf_i386_link_hash_entry): Add def_protected.
	(elf_i386_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC
	when checking info->nocopyreloc.
	(elf_i386_link_setup_gnu_properties): Don't set
	extern_protected_data here.
	(elf_i386_merge_symbol_attribute): New function.
	(elf_backend_merge_symbol_attribute): New.
	* elf64-x86-64.c (SYMBOL_NO_COPYRELOC): New.
	(elf_x86_64_link_hash_entry): Add def_protected.
	(elf_x86_64_need_pic): Report protected symbol for def_protected.
	(elf_x86_64_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC
	when checking info->nocopyreloc.
	(elf_x86_64_relocate_section): Also check for R_X86_64_PC32
	relocation run-time overflow and unresolvable R_X86_64_32S
	relocation against protected data symbol defined in shared object
	with GNU_PROPERTY_NO_COPY_ON_PROTECTED.
	(elf_x86_64_link_setup_gnu_properties): Don't set
	extern_protected_data here.
	(elf_x86_64_merge_symbol_attribute): New function.
	(elf_backend_merge_symbol_attribute): New.

ld/

	PR ld/21997
	* testsuite/ld-i386/i386.exp: Run PR ld/21997 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr21997-1a.S: New file.
	* testsuite/ld-i386/pr21997-1b.c: Likewise.
	* testsuite/ld-i386/pr21997-1c.S: Likewise.
	* testsuite/ld-x86-64/pr21997-1a.S: Likewise.
	* testsuite/ld-x86-64/pr21997-1a.err: Likewise.
	* testsuite/ld-x86-64/pr21997-1b.c: Likewise.
	* testsuite/ld-x86-64/pr21997-1b.err: Likewise.
	* testsuite/ld-x86-64/pr21997-1c.c: Likewise.
2017-08-26 19:26:21 -07:00
H.J. Lu 176047c9f2 ld: Add "--" after regexp
Add "--" after regexp to support dejagnu 1.4.4.

	* testsuite/ld-elf/pr21903c.d: Remove '\' before --.
	* testsuite/ld-elf/pr21903d.d: Likewise.
	* testsuite/ld-elf/pr21903e.d: Likewise.
	* testsuite/lib/ld-lib.exp (run_dump_test): Add "--" after
	regexp.
2017-08-24 17:45:24 -07:00
H.J. Lu 074f606684 ld: Replace regexp with string match
Replace regexp with string match to workaround dejagnu 1.4.4 which
complains:

ERROR: bad switch "-fPIE": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --

	* testsuite/ld-i386/i386.exp (undefined_weak): Replace regexp
	with string match.
	* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Likewise.
2017-08-24 08:33:16 -07:00
H.J. Lu 28e6a46bcb x86-64: Run pr22001-1b on x32
Run pr22001-1b on x32 since R_X86_64_32S relocation can be turned into
dynamic R_X86_64_32 relocation which won't overflow on x32.

	* testsuite/ld-x86-64/x86-64.exp: Run pr22001-1b on x32.
2017-08-24 08:00:08 -07:00
H.J. Lu 7073b5b9ed x86-64: Check relocations with -z nocopyreloc
On x86-64, when -z nocopyreloc is used to build executable, relocations
may overflow at run-time or may not be resolved without PIC.  This patch
checks these conditions and issues an error with suggestion for -fPIC.

bfd/

	PR ld/22001
	* elf64-x86-64.c (elf_x86_64_relocate_section): Check for
	R_X86_64_PC32 relocation run-time overflow and unresolvable
	R_X86_64_32S relocation with -z nocopyreloc.

ld/

	PR ld/22001
	* testsuite/ld-i386/i386.exp: Run -z nocopyreloc tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* ld/testsuite/ld-i386/pr22001-1a.c: New file.
	* ld/testsuite/ld-i386/pr22001-1b.c: Likewise.
	* ld/testsuite/ld-i386/pr22001-1c.S: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1a.c: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1a.err: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1b.c: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1b.err: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1c.c: Likewise.
2017-08-24 06:34:38 -07:00
Andrew Burgess 5b5f4e6f8c ld: Early detection of orphans we know will be discarded
When processing an orphan section we first call lang_place_orphans, this
function handles a few sections for which the behaviour is known COMMON
sections, or sections marked as SEC_EXCLUDE.

Any orphans that are not handled in lang_place_orphans are passed on to
ldlang_place_orphan, this is where we decide where to put the orphan,
and then call lang_add_section to perform the actual orphan placement.

We previously had a larger set of checks at the start of the function
lang_add_section to discard some sections that we _knew_ should not be
added into the output file, this was where .group sections (in a final
link) and .debug* sections (with --strip-debug) were dropped.

The problem with dropping these sections at the lang_add_section stage
is that a user might also be using --orphan-handling=error to prevent
orphans.  If they are then they should not be get errors about sections
that we know will be discarded, and which are not mentioned in the
linker script.

The solution proposed in this patch is to move the "will this section be
discarded" check into a separate function, and use this in
lang_place_orphans to have the early discard phase discard sections that
we know should not be included in the output file.

ld/ChangeLog:

	PR 21961
	* ldlang.c (lang_discard_section_p): New function.
	(lang_add_section): Checks moved out into new function, which is
	now called.
	(lang_place_orphans): Call lang_discard_section_p instead of
	duplicating some of the checks from lang_add_section.
	* testsuite/ld-elf/orphan-11.d: New file.
	* testsuite/ld-elf/orphan-11.ld: New file.
	* testsuite/ld-elf/orphan-11.s: New file.
	* testsuite/ld-elf/orphan-12.d: New file.
	* testsuite/ld-elf/orphan-12.s: New file.
2017-08-24 12:41:34 +01:00
Alan Modra 647d4de92e Test undefined symbols in shared libraries
git commit 46434633f9 said
    Make undefined symbols in allocate_dynrelocs dynamic

    ..if they have dynamic relocs.  An undefined symbol in a PIC object
    that finds no definition ought to become dynamic in order to support
    --allow-shlib-undefined, but there is nothing in the generic ELF
    linker code to do this if the reference isn't via the GOT or PLT.  (An
    initialized function pointer is an example.)  So it falls to backend
    code to ensure the symbol is made dynamic.

The above isn't true.  Undefined symbols are indeed made dynamic for
shared libraries.  Undefined symbols are not automatically made
dynamic in executables, and it was the PIE case that triggered an
internal consistency assertion on powerpc64.  I guess I could have
jumped the other way when fixing PR21988, and not created a dynamic
reloc.  Either way, it doesn't matter a great deal.  We're going to
get an error on strong undefined symbols in an executable anyway, and
broken binaries if you try to use --unresolved-symbols=ignore-all to
disable the error.

	* testsuite/ld-undefined/fundef.s: New test.
	* testsuite/ld-undefined/undefined.exp: Test that undefined
	symbols in shared libraries are made dynamic.
2017-08-24 16:43:39 +09:30
H.J. Lu 49263c56bb Update PR ld/21903 tests for dejagnu 1.4.4
Add '\' before -- to workaround dejagnu 1.4.4 which complains:

ERROR: bad switch "--no-define-common may not be used without -shared":...

	* testsuite/ld-elf/pr21903c.d: Add '\' before --.
	* testsuite/ld-elf/pr21903d.d: Likewise.
	* testsuite/ld-elf/pr21903e.d: Likewise.
2017-08-23 16:01:22 -07:00
H.J. Lu aab921adcb x86-64: Properly report output type when PIC is needed
-fPIC may be needed to compile PIE or PDE objects, not just shared
object.

bfd/

	* elf64-x86-64.c (elf_x86_64_need_pic): Add an argument for
	bfd_link_info.  Report shared, PIE or PDE object based on
	bfd_link_info.
	(elf_x86_64_check_relocs): Update elf_x86_64_need_pic call.
	(elf_x86_64_relocate_section): Likewise.

ld/

	* testsuite/ld-x86-64/pie2.d: Updated.
	* testsuite/ld-x86-64/pr19719.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19969.d: Likewise.
2017-08-23 13:43:45 -07:00
H.J. Lu 73784fa565 x86: Clear extern_protected_data for GNU_PROPERTY_NO_COPY_ON_PROTECTED
When GNU_PROPERTY_NO_COPY_ON_PROTECTED is set, it indicates that there
are no copy relocations against protected data symbols.  When linker
sees GNU_PROPERTY_NO_COPY_ON_PROTECTED on any input relocatable file,
it sets extern_protected_data to FALSE.

bfd/

	* elf32-i386.c (elf_i386_link_setup_gnu_properties): Set
	extern_protected_data to FALSE if GNU_PROPERTY_NO_COPY_ON_PROTECTED
	is set on any input relocatable file.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Run protected7.
	* testsuite/ld-i386/protected7.d: New file.
	* testsuite/ld-i386/protected7.s: Likewise.
	* testsuite/ld-x86-64/protected8.d: Likewise.
	* testsuite/ld-x86-64/protected8.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run protected8.
2017-08-23 10:15:58 -07:00
Alan Modra 9d3420f5df Remove pr19161 test hppa xfail
* testsuite/ld-gc/pr19161.d: Don't xfail hppa.
2017-08-23 08:58:42 +09:30
H.J. Lu 8dfb7cbf84 Update PR ld/21964 tests
* testsuite/ld-elf/pr21964-1a.c (foo): Renamed to ...
	(foo1): This.
	* testsuite/ld-elf/pr21964-1b.c: Rewrite.
	* testsuite/ld-elf/pr21964-1c.c: New file.
	* testsuite/ld-elf/pr21964-2c.c: Likewise.
	* testsuite/ld-elf/pr21964-2a.c (foo): Renamed to ...
	(foo1): This.
	* testsuite/ld-elf/pr21964-2b.c: Rewrite.
	* testsuite/ld-elf/shared.exp: Update PR ld/21964 tests.
2017-08-22 09:41:43 -07:00
Alan Modra 487b6440da Make __start/__stop symbols protected visibility
They can't be hidden visibility since apparently people use dlsym to
look them up.

bfd/
	PR ld/21964
	* elf-bfd.h (SYMBOLIC_BIND): Return TRUE for __start/__stop symbols.
	* elflink.c (bfd_elf_define_start_stop): Rewrite.
ld/
	PR ld/21964
	* testsuite/ld-elf/pr21562a.d: Update for changed start/stop symbols.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/sizeofa.d: Likewise.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
	* testsuite/ld-gc/pr20022.d: Likewise.
	* testsuite/ld-gc/start.d: Likewise.
	* testsuite/ld-elf/pr21964-1a.c: New file.
	* testsuite/ld-elf/pr21964-1b.c: New file.
	* testsuite/ld-elf/pr21964-2a.c: New file.
	* testsuite/ld-elf/pr21964-2b.c: New file.
	* testsuite/ld-elf/shared.exp: Run PR ld/21964 tests.
2017-08-21 23:29:29 +09:30
Hans-Peter Nilsson 284d826d9f PR ld/20125, MMIX weak symbols
Weak undefineds with PUSHJ relocs were "lost", causing internal
inconsistencies and an abort.
2017-08-21 03:43:35 +02:00
H.J. Lu 7f3d21db92 Update testsuite/ld-x86-64/plt-main-bnd.dd
2017-08-20  A. Wilcox  <awilfox@adelielinux.org>

	PR ld/21976
	* testsuite/ld-x86-64/plt-main-bnd.dd: Accept '_' in symbol
	name.
2017-08-20 06:28:37 -07:00
Nick Clifton 12601963cf Add new Brazilian Portuguese translation for the ld subdirectory.
* po/pt_BR.po: New Brazilian Portuguese translation.
	* configure.ac (ALL_LINGUAS): Add pt_BR.
	* configure: Regenerate.
2017-08-17 12:13:28 +01:00
Alan Modra 79a94a2ad1 PR21441, Unnecessary padding of .eh_frame section
Until all .eh_frame sections have been edited we don't know their
sizes.  So it isn't possible to properly decide whether a non-empty
.eh_frame section follows a given section until editing is complete.

bfd/
	PR 21441
	* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't add
	alignment padding here.
	* elflink.c (bfd_elf_discard_info): Add .eh_frame padding here
	in a reverse pass over sections.
ld/
	PR 21441
	* testsuite/ld-x86-64/pr21038a.d: Adjust.
	* testsuite/ld-x86-64/pr21038a-now.d: Adjust.
2017-08-14 09:25:17 +09:30
H.J. Lu 34c4758cc2 ld: Restore linker scripts in PR ld/21884 tests
OUTPUT_FORMAT in linker script of PR ld/21884 tests is needed to trigger
PR ld/21884.  Restore linker scripts and add nacl versions of the same
tests.

	* testsuite/ld-i386/i386.exp: Run pr21884-nacl.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr21884.d: Don't run on nacl targets.
	* testsuite/ld-x86-64/pr21884.d: Likewise.
	* testsuite/ld-i386/pr21884.t: Revert the last change.
	* testsuite/ld-x86-64/pr21884.t: Likewise.
	* testsuite/ld-i386/pr21884-nacl.d: New file.
	* testsuite/ld-i386/pr21884-nacl.t: Likewise.
	* testsuite/ld-x86-64/pr21884-nacl.d: Likewise.
	* testsuite/ld-x86-64/pr21884-nacl.t: Likewise.
2017-08-13 05:41:37 -07:00
Alan Modra 6d545e31f5 Fix i686-nacl and x86_64-nacl pr21884 failures
OUTPUT_FORMAT in the script results in "./ld-new: target elf32-i386
not found" and similarly for the x86_64 test.

	* testsuite/ld-i386/pr21884.t: Remove unneeded format, arch and entry.
	* testsuite/ld-x86-64/pr21884.t: Likewise.
2017-08-13 12:36:52 +09:30
Nick Clifton 93ab9c0de7 Add -z globalaudit linker command line option to set the DF_GLOBALAUDIT flag bit in the dynamic tags.
* emultempl/elf32.em (handle_option): Accept the -z globalaudit
	command line option.
	* lexsup.c (elf_static_list_options): Add -z globalaudit.
	* ld.texinfo: Document the support for the new command line
	option.
	* NEWS: Mention the new feature.
	* testsuite/ld-elf/audit.exp: Add a test of the -z globalaudit
	command line option.
	* testsuite/ld-elf/globalaudit.rd: New file: Expected output from
	readelf.
2017-08-11 16:36:28 +01:00
H.J. Lu 9593aade74 Add 2 more tests for PR ld/21884
PR ld/21884
	* testsuite/ld-i386/i386.exp: Run pr21884.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr21884.d: New file.
	* testsuite/ld-i386/pr21884.t: Likewise.
	* testsuite/ld-x86-64/pr21884.d: Likewise.
	* testsuite/ld-x86-64/pr21884.t: Likewise.
2017-08-11 08:05:00 -07:00
Nick Clifton ca6f2be7f6 Add support for PE startup files that want to define their own constructor and desctructor sequencing.
* scripttempl/pep.sc: Enclose __CTOR_LIST__, ___CTOR_LIST__,
	__DTOR_LIST__ and ___DTOR_LIST__ in PROVIDE statements so that
	they can be overrridden by crt input files.
	* scripttempl/pe.sc: Likewise.
2017-08-10 13:17:12 +01:00
H.J. Lu 7ed1dab994 LD_CLASS: Check .libs/ld-new for linker first
When --enable-shared is used, ./ld-new may be a shell script and the
real linker is .libs/ld-new.  We should check .libs/ld-new first.

	* testsuite/config/default.exp (LD_CLASS): Check .libs/ld-new
	for linker first.
2017-08-09 16:38:09 -07:00
H.J. Lu 978c05401b Run PR ld/17618 test only with 64-bit ELF linker
PR ld/17618 test requires 64-bit linker to run.  Set LD_CLASS to "64bit"
for 64-bit ELF linker and run PR ld/17618 test only if $LD_CLASS is
"64bit".  More checks can be added to support 64-bit linkers in non-ELF
format.

	* testsuite/config/default.exp (LD_CLASS): New.  Set to "64bit"
	for 64-bit ELF linker.
	* testsuite/ld-x86-64/pr17618.d (#notarget): Removed.
	* testsuite/ld-x86-64/x86-64.exp: Run pr17618 only for 64-bit
	linker.
2017-08-09 15:04:05 -07:00
H.J. Lu 25d28c91b8 ld: Require GCC 5 or above for 3 x86 tests
Require GCC 5 or above for 3 x86 tests which fail with GCC 4.9.3.

	PR ld/21924
	* testsuite/ld-i386/i386.exp: Require GCC 5 or above for
	"weakundef1 with PIE" test.
	* testsuite/ld-x86-64/tls.exp: Require GCC 5 or above for
	"tlsdesc1" and "tlsdesc1 with PIE" tests.
2017-08-08 20:20:43 -07:00
H.J. Lu 9165f4548b ld: Add a ',' after -Wl,--rpath
* configure.ac (TESTBFDLIB): Add a ',' after -Wl,--rpath.
	* configure: Regenerated.
2017-08-08 20:01:28 -07:00
H.J. Lu fe22cbc418 ld: Replace --rpath with -Wl,--rpath
"--rpath ../bfd/.libs ../bfd/.libs/libbfd.so" isn't a valid compiler
command-line option.  We should use -Wl,--rpath instead of --rpath.

	PR ld/21923
	* configure.ac (TESTBFDLIB): Replace --rpath with -Wl,--rpath
	for --disable-static.
	* configure: Regenerated.
2017-08-08 14:16:02 -07:00
Romain Geissler 2760f24c49 Add configure flag to enable gnu hash style by default.
ld/
	* configure.ac: Add --enable-default-hash-style option.
	* ldmain.c (main): Set link_info.emit_hash to DEFAULT_EMIT_SYSV_HASH.
	Set link_info.emit_gnu_hash to DEFAULT_EMIT_GNU_HASH.
	* configure: Regenerate.
	* config.in: Regenerate.

gold/
	* configure.ac: Add --enable-default-hash-style option.
	* options.h (hash_style): Use DEFAULT_HASH_STYLE as default value.
	* configure: Regenerate.
	* config.in: Regenerate.
2017-08-08 07:25:39 +09:30
Alan Modra 8f5e83fb73 More support for ld --hash-style in the ld testsuite
These were discovered when running --hash-style=gnu as default, the
previous batch being --hash-style=both.

	* testsuite/ld-aarch64/ifunc-1-local.d: Run ld with --hash-style=sysv.
	* testsuite/ld-aarch64/ifunc-2-local.d: Likewise.
	* testsuite/ld-aarch64/ifunc-3a.d: Likewise.
	* testsuite/ld-frv/fdpic-pie-1.d: Likewise.
	* testsuite/ld-frv/fdpic-pie-2.d: Likewise.
	* testsuite/ld-frv/fdpic-pie-7.d: Likewise.
	* testsuite/ld-frv/fdpic-pie-8.d: Likewise.
	* testsuite/ld-arm/arm-elf.exp: Add --hash-style=sysv to "Using
	Thumb lib by another lib" test's ld options.
	* testsuite/ld-elf/note-3.l: Match .gnu.hash.
	* testsuite/ld-elf/note-3.t: Add .gnu.hash output section.
2017-08-08 07:22:36 +09:30
H.J. Lu 2980ccad59 Move common symbol check after bed->common_definition
bfd/

	* elflink.c (elf_link_add_object_symbols): Move common symbol
	check after bed->common_definition.

ld/

	* testsuite/ld-elf/pr21903.s (start): Removed.
	(_start): Likewise.
	(__start): Likewise.
	(main): Likewise.
	(bar): New.
2017-08-07 08:02:29 -07:00
Alan Modra bab55c0522 Support different ld --hash-style in the ld testsuite
When ld is running with something other than --hash-style=sysv by
default, numerous tests need tweaking.  Most of the changes just add
--hash-style=sysv.  I didn't want to make --hash-style=sysv global as
that means --hash-style=gnu isn't well tested.

	* testsuite/ld-alpha/alpha.exp: Add --hash-style=sysv to various
	test's ld options.
	* testsuite/ld-arm/arm-elf.exp: Likewise.
	* testsuite/ld-elf/elf.exp: Likewise.
	* testsuite/ld-elf/readelf.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-i386/i386.exp: Likewise.
	* testsuite/ld-ia64/ia64.exp: Likewise.
	* testsuite/ld-m68k/m68k.exp: Likewise.
	* testsuite/ld-metag/metag.exp: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Likewise.
	* testsuite/ld-s390/s390.exp: Likewise.
	* testsuite/ld-sh/sh-vxworks.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-sparc/sparc.exp: Likewise.
	* testsuite/ld-tic6x/tic6x.exp: Likewise.
	* testsuite/ld-vax-elf/vax-elf.exp: Likewise.
	* testsuite/ld-x86-64/mpx.exp: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-xtensa/xtensa.exp: Likewise.

	* testsuite/ld-elf/comm-data2.ld: Add .gnu.hash output section.
	* testsuite/ld-elf/pr20828-v.ld: Likewise.
	* testsuite/ld-elf/pr20828.ld: Likewise.
	* testsuite/ld-elf/pr21233.ld: Likewise.
	* testsuite/ld-elf/pr21384.ld: Likewise.
	* testsuite/ld-elf/provide-hidden-1.ld: Likewise.
	* testsuite/ld-elf/provide-hidden-2.ld: Likewise.
	* testsuite/ld-elf/provide-hidden-s.ld: Likewise.
	* testsuite/ld-scripts/cross1.t: Likewise.

	* testsuite/ld-elf/stab.d: Adjust allowed section indices.

	* testsuite/ld-i386/pie1.d: Don't match addresses.
	* testsuite/ld-i386/plt-pic2.dd: Likewise.
	* testsuite/ld-i386/pr19636-1d.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-powerpc/elfv2so.d: Likewise.
	* testsuite/ld-powerpc/tlsopt5.d: Likewise.
	* testsuite/ld-powerpc/tlsopt5.wf: Likewise.
	* testsuite/ld-powerpc/tlsopt5_32.d: Likewise.

	* testsuite/ld-i386/pr19636-2b.d: Don't match _start.

	* testsuite/ld-powerpc/ambiguousv1.d: Relax symbol count, index
	and address match.
	* testsuite/ld-powerpc/ambiguousv1b.d: Likewise.
	* testsuite/ld-powerpc/ambiguousv2.d: Likewise.
	* testsuite/ld-powerpc/ambiguousv2b.d: Likewise.

	* testsuite/ld-aarch64/gc-plt-relocs.d: Run ld with --hash-style=sysv.
	* testsuite/ld-aarch64/ifunc-1.d: Likewise.
	* testsuite/ld-aarch64/ifunc-2.d: Likewise.
	* testsuite/ld-aarch64/ifunc-21.d: Likewise.
	* testsuite/ld-aarch64/relasz.d: Likewise.
	* testsuite/ld-aarch64/tls-small-ld.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-ld.d: Likewise.
	* testsuite/ld-arc/tls_gd-01.d: Likewise.
	* testsuite/ld-cris/libdso-10.d: Likewise.
	* testsuite/ld-cris/libdso-2.d: Likewise.
	* testsuite/ld-cris/pic-gc-72.d: Likewise.
	* testsuite/ld-cris/pic-gc-73.d: Likewise.
	* testsuite/ld-cris/tls-gd-1.d: Likewise.
	* testsuite/ld-cris/tls-gd-1h.d: Likewise.
	* testsuite/ld-cris/tls-gd-2.d: Likewise.
	* testsuite/ld-cris/tls-gd-2h.d: Likewise.
	* testsuite/ld-cris/tls-ie-10.d: Likewise.
	* testsuite/ld-cris/tls-ie-11.d: Likewise.
	* testsuite/ld-cris/tls-ie-8.d: Likewise.
	* testsuite/ld-cris/tls-ie-9.d: Likewise.
	* testsuite/ld-cris/tls-ld-4.d: Likewise.
	* testsuite/ld-cris/tls-ld-5.d: Likewise.
	* testsuite/ld-cris/tls-ld-6.d: Likewise.
	* testsuite/ld-cris/tls-ld-7.d: Likewise.
	* testsuite/ld-cris/tls-ldgd-14.d: Likewise.
	* testsuite/ld-cris/tls-ldgd-15.d: Likewise.
	* testsuite/ld-cris/tls-ldgdx-14.d: Likewise.
	* testsuite/ld-cris/tls-ldgdx-15.d: Likewise.
	* testsuite/ld-cris/tls-local-54.d: Likewise.
	* testsuite/ld-cris/tls-local-60.d: Likewise.
	* testsuite/ld-cris/tls-local-61.d: Likewise.
	* testsuite/ld-cris/weakhiddso.d: Likewise.
	* testsuite/ld-elf/linkinfo1a.d: Likewise.
	* testsuite/ld-elf/linkinfo1b.d: Likewise.
	* testsuite/ld-elf/pr19617a.d: Likewise.
	* testsuite/ld-elfvsb/hidden2.d: Likewise.
	* testsuite/ld-frv/fdpic-pie-6.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-2.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-5.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-6.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-8.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-local-2.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-local-8.d: Likewise.
	* testsuite/ld-frv/tls-dynamic-2.d: Likewise.
	* testsuite/ld-i386/ibt-plt-1.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
	* testsuite/ld-i386/pr20830.d: Likewise.
	* testsuite/ld-ia64/merge1.d: Likewise.
	* testsuite/ld-ia64/merge2.d: Likewise.
	* testsuite/ld-ia64/merge3.d: Likewise.
	* testsuite/ld-ia64/merge4.d: Likewise.
	* testsuite/ld-ia64/merge5.d: Likewise.
	* testsuite/ld-ifunc/ifunc-1-local-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-1-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-3a-x86.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64.d: Likewise.
	* testsuite/ld-m68k/got-1.d: Likewise.
	* testsuite/ld-m68k/got-multigot-12-13-14-34-35-ok.d: Likewise.
	* testsuite/ld-m68k/got-multigot-14-ok.d: Likewise.
	* testsuite/ld-m68k/got-multigot-15-er.d: Likewise.
	* testsuite/ld-m68k/got-negative-12-13-14-34-ok.d: Likewise.
	* testsuite/ld-m68k/got-negative-12-13-14-35-er.d: Likewise.
	* testsuite/ld-m68k/got-negative-14-ok.d: Likewise.
	* testsuite/ld-m68k/got-negative-15-er.d: Likewise.
	* testsuite/ld-m68k/got-single-12-ok.d: Likewise.
	* testsuite/ld-m68k/got-single-13-er.d: Likewise.
	* testsuite/ld-m68k/got-xgot-12-13-14-15-34-35-ok.d: Likewise.
	* testsuite/ld-m68k/got-xgot-15-ok.d: Likewise.
	* testsuite/ld-m68k/tls-gd-1.d: Likewise.
	* testsuite/ld-m68k/tls-gd-2.d: Likewise.
	* testsuite/ld-m68k/tls-gd-ie-1.d: Likewise.
	* testsuite/ld-m68k/tls-ie-1.d: Likewise.
	* testsuite/ld-m68k/tls-ld-1.d: Likewise.
	* testsuite/ld-m68k/tls-ld-2.d: Likewise.
	* testsuite/ld-sh/shared-2.d: Likewise.
	* testsuite/ld-sh/tlsbin-2.d: Likewise.
	* testsuite/ld-sh/tlspic-2.d: Likewise.
	* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-1.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/ilp32-4-nacl.d: Likewise.
	* testsuite/ld-x86-64/ilp32-4.d: Likewise.
	* testsuite/ld-x86-64/load1c-nacl.d: Likewise.
	* testsuite/ld-x86-64/load1c.d: Likewise.
	* testsuite/ld-x86-64/load1d-nacl.d: Likewise.
	* testsuite/ld-x86-64/load1d.d: Likewise.
	* testsuite/ld-x86-64/pie3-nacl.d: Likewise.
	* testsuite/ld-x86-64/pie3.d: Likewise.
	* testsuite/ld-x86-64/pr14207.d: Likewise.
	* testsuite/ld-x86-64/pr19162.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1j.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1l.d: Likewise.
	* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830a.d: Likewise.
	* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830b.d: Likewise.
	* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038a.d: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
2017-08-07 22:10:51 +09:30
H.J. Lu a4819f54c0 Treat common symbol as undefined for --no-define-common
When --no-define-common is used to build shared library, treat common
symbol as undefined so that common symbols that are referenced from a
shared library to be assigned addresses only in the main program.  This
eliminates the unused duplicate space in the shared library, and also
prevents any possible confusion over resolving to the wrong duplicate
when there are many dynamic modules with specialized search paths for
runtime symbol resolution.

--no-define-common is only allowed when building a shared library.

bfd/

	PR ld/21903:
	* elflink.c (elf_link_add_object_symbols): Treat common symbol
	as undefined for --no-define-common.

include/

	PR ld/21903:
	* bfdlink.h (bfd_link_info): Add inhibit_common_definition.

ld/

	PR ld/21903:
	* ld.h (command_line): Remove inhibit_common_definition.
	* ldgram.y: Replace command_line.inhibit_common_definition with
	link_info.inhibit_common_definition.
	* ldlang.c (lang_common): Likewise.
	* lexsup.c (parse_args): Likewise.
	* ldmain.c (main): Only allow --no-define-common with -shared.
	* testsuite/ld-elf/pr21903.s: New file.
	* testsuite/ld-elf/pr21903a.d: Likewise.
	* testsuite/ld-elf/pr21903b.d: Likewise.
	* testsuite/ld-elf/pr21903c.d: Likewise.
	* testsuite/ld-elf/pr21903d.d: Likewise.
	* testsuite/ld-elf/pr21903e.d: Likewise.
2017-08-06 08:19:04 -07:00
Alan Modra 55ef6584ca Don't fail in elf32_hppa_set_gp
The base bfd_link_hash_table works fine here, the only thing to watch
out for is to only set elf_gp if the output is ELF.

bfd/
	* elf32-hppa.c (elf32_hppa_set_gp): Don't require an
	hppa_link_hash_table.
ld/
	* testsuite/ld-unique/pr21529.d: Don't xfail hppa.
2017-08-05 23:28:21 +09:30
H.J. Lu 9f06dab1e3 Add a testcase for "ld -d"
"ld -d" assigns space to common symbols even if a relocatable output
file is specified (with '-r').

	PR ld/21904
	* testsuite/ld-elf/pr21904.d: New file.
	* testsuite/ld-elf/pr21904.s: Likewise.
2017-08-04 05:39:56 -07:00
Nick Clifton fd9770d81f Add more targets to the list of architectures not supporting format changing during linking. Fix seg-faults triggered when this is attempted.
PR ld/21884
	* testsuite/ld-elf/pr21884.d: Add AVR, HPPA, IA64, M68HC1x and
	SCORE to list of targets not supporting file format changes during
	linking.
	* testsuite/ld-unique/pr21529.d: Likewise.
	* emultempl/avrelf.em (_before_allocation): Skip for non-ELF
	output formats.
	(avr_elf_create_output_section_statements): Fail if the output
	format is not ELF.
	(avr_finish): Do not access the ELF header in non-ELF format
	output bfds.
	* emultempl/m68hc1xelf.em (_before_allocation): Skip for non-ELF
	output formats.
	(m68hc11elf_create_output_section_statements): Fail if the putput
	format is not ELF.
	(m68hc11elf_after_allocation): Skip for non-ELF output formats.
2017-08-03 11:59:32 +01:00
Alan Modra 2e9246e077 ELF checks for orphan placement
The loop checking for previous orphan placement should run even when
the output is non-ELF.

	PR ld/21884
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Revert
	last change.  Rename iself to elfinput.  Expand comments.  Condition
	ELF checks on having both input and output ELF files.  Extract..
	(elf_orphan_compatible): ..this new function.
2017-08-03 14:40:49 +09:30
H.J. Lu db99ecc08f Check ELF section header only for ELF output
When placing an orphan input section, check ELF section header only for
ELF output.

	PR ld/21884
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Check
	ELF section header only for ELF output.
	* testsuite/ld-elf/pr21884.d: New test.
	* testsuite/ld-elf/pr21884.t: Likewise.
	* testsuite/ld-elf/pr21884a.s: Likewise.
	* testsuite/ld-elf/pr21884b.s: Likewise.
2017-08-02 05:10:48 -07:00
H.J. Lu b8f4abd342 Revert the last change to emultempl/elf32.em
It will be replaced by a different fix.

	* emultempl/elf32.em (_place_orphan): Revert the last change.
2017-08-02 05:09:25 -07:00
Max Filippov 73d5923e48 Fix assertion failure for xtensa linker.
* emultempl/xtensaelf.em (xtensa_wild_group_interleave_callback):
	Only check for by_name sorting.
2017-08-02 11:48:07 +01:00
Nick Clifton ddff3d84be Fix seg-fault when trying to place non-ELF orphan sections.
PR 21884
	* emultempl/elf32.em (_place_orphan): Skip non-ELF binaries when
	looking for sections to merge.
2017-08-02 11:45:05 +01:00
Alan Modra d44c746aed PR 21847, PowerPC64 --plt-localentry again
This makes ld warn about --plt-localentry if a version of glibc
without the necessary ld.so checks is detected, and revises the
documentation.

bfd/
	* elf64-ppc.c (ppc64_elf_tls_setup): Warn on --plt-localentry
	without ld.so checks.
gold/
	* powerpc.cc (Target_powerpc::scan_relocs): Warn on --plt-localentry
	without ld.so checks.
ld/
	* ld.texinfo (plt-localentry): Revise.
2017-07-31 13:20:44 +09:30
Alan Modra 8b5f1ed877 PR 21847, Don't default PowerPC64 to --plt-localentry
The big comment in ppc64_elf_tls_setup says why.  I've also added some
code to the bfd linker that catches the -lpthread -lc symbol
differences and disable generation of optimized call stubs even when
--plt-localentry is activated.  Gold doesn't yet have that.

	PR 21847
bfd/
	* elf64-ppc.c (struct ppc_link_hash_entry): Add non_zero_localentry.
	(ppc64_elf_merge_symbol): Set non_zero_localentry.
	(is_elfv2_localentry0): Test non_zero_localentry.
	(ppc64_elf_tls_setup): Default to --no-plt-localentry.
gold/
	* powerpc.cc (Target_powerpc::scan_relocs): Default to
	--no-plt-localentry.
ld/
	* ld.texinfo (plt-localentry): Document.
2017-07-29 13:02:27 +09:30
Andrew Burgess 2b94abd48a Make some improvements to how SORT_* specifiers and EXCLUDE_FILE specifiers are handled in the linker script grammar.
* ldgram.y (ldgram_had_keep): Make static.
	(ldgram_vers_current_lang): Likewise.
	(filename_spec): New rule.
	(input_section_spec_no_keep): Use filename_spec.
	(wildcard_maybe_exclude): New rule.
	(wildcard_spec): Rename to...
	(section_name_spec): ...this.
	(section_NAME_list): Rename to...
	(section_name_list): ...this.
	(section_name_spec): Simplifiy and use wildcard_maybe_exclude.
	* ldlang.c (placed_commons): Delete.
	(lang_add_wild): No longer set placed_commons.
	(print_wild_statement): Use full names for SORT specifiers.
	* testsuite/ld-scripts/align.exp: Run new tests.
	* testsuite/ld-scripts/align3.d: New file.
	* testsuite/ld-scripts/align3.t: New file.
	* testsuite/ld-scripts/align4.d: New file.
	* testsuite/ld-scripts/align4.t: New file.
	* testsuite/ld-scripts/align5.d: New file.
	* testsuite/ld-scripts/align5.t: New file.
	* testsuite/ld-scripts/exclude-file-5.d: New file.
	* testsuite/ld-scripts/exclude-file-5.map: New file.
	* testsuite/ld-scripts/exclude-file-5.t: New file.
	* testsuite/ld-scripts/exclude-file-6.d: New file.
	* testsuite/ld-scripts/exclude-file-6.map: New file.
	* testsuite/ld-scripts/exclude-file-6.t: New file.
	* NEWS: Mention the changes.
2017-07-28 13:01:10 +01:00
Georg-Johann Lay f726cc1cb6 Move AVR .promemx.* sections into higher memory.
PR ld/21849
	* scripttempl/avr.sc: Split .progmemx.* from .progmem.* and locate
	former at a higher address.
2017-07-27 14:17:14 +01:00
Alan Modra d4aaa2a074 __tls_get_addr_opt stub eh_frame info
Since the __tls_get_addr_opt stub saves LR and makes a call, eh_frame
info should be generated to describe how to unwind through the stub.

The patch also changes the way the backend iterates over stubs, from
looking at all sections in stub_bfd to which all dynamic sections are
attached as well, to iterating over the group list, which gets just
the stub sections.  Most binaries will have just one or two stub
groups, so this is a little faster.

bfd/
	* elf64-ppc.c (struct map_stub): Add tls_get_addr_opt_bctrl.
	(stub_eh_frame_size): New function.
	(ppc_size_one_stub): Set group tls_get_addr_opt_bctrl.
	(group_sections): Init group tls_get_addr_opt_bctrl.
	(ppc64_elf_size_stubs): Update sizing and initialization of
	.eh_frame.  Iteration over stubs via group list.
	(ppc64_elf_build_stubs): Iterate over stubs via group list.
	(ppc64_elf_finish_dynamic_sections): Update finalization of
	.eh_frame.
ld/
	* testsuite/ld-powerpc/tlsopt5.s: Add cfi.
	* testsuite/ld-powerpc/tlsopt5.d: Update.
	* testsuite/ld-powerpc/tlsopt5.wf: New file.
	* testsuite/ld-powerpc/powerpc.exp: Perform new tlsopt5 test.
2017-07-25 15:14:39 +09:30
claziss 645b280027 [ARC] Fix big-endian ld tests errors.
A set of small patches that are fixing big-endian observed errors.

ld/
2017-07-24  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/ld-arc/jli-overflow.d: Force testing for little
	endian.
	* testsuite/ld-arc/tls_gd-01.d: Fix string to match bigendian
	systems.
	* testsuite/ld-arc/tls_ie-01.d: Fix test for bigendian systems.
2017-07-24 10:10:21 +02:00
Alexandre Oliva ba8826a82a This patch introduces support for specifing views in .loc directives, so that the compiler can use the assembler to generate line number information and have the assembler determine view numbers to multiple views at the same program counter.
binutils* dwarf.c (struct State_Machine_Registers): Add view field.
	(reset_state_machine): Reset view.
	(process_extended_line_op): Reset view when appropriate.
	(display_debug_lines_raw): Increment or reset view when appropriate.
	Print nonzero views.  Support print view resets, disabled by default.
	(display_debug_lines_decoded): Likewise.  Disambiguate op_code tests,
	enabling printing of end_sequence.
	* testsuite/binutils-all/dw2-1.W: Add nonzero views.
	* testsuite/binutils-all/dw2-3.W: Likewise.
	* testsuite/binutils-all/dw2-3gabi.W: Likewise.
	* testsuite/binutils-all/dw5.W: Add end sequence lines.
	* testsuite/binutils-all/i386/compressed-1a.d: Add nonzero views.
	* testsuite/binutils-all/libdw2-compressedgabi.out: Likewise.
	* testsuite/binutils-all/objdump.W: Likewise.
	* testsuite/binutils-all/objdump.WL: Add end sequence lines.
	* testsuite/binutils-all/x86-64/compressed-1a.d: Add nonzero views.

gas	* doc/as.texinfo (.loc): Document view support.
	* dwarf2dbg.c (unused): Check offset of next in struct line_entry.
	(current): Initialize view.
	(force_reset_view, view_assert_failed): New variables.
	(reverse_line_entry_list): New function.
	(set_or_check_view): Likewise.
	(dwarf2_gen_line_info_1): Call it.
	(dwarf2_where): Set view to NULL.
	(dwarf2_emit_insn): Return early when called before first file.
	(dwarf2_directive_loc): Add view support.  Emit insn
	immediately when view option is given.
	(process_entries): Avoid set_address to reset view when a known
	address change already implies the view reset.
	(dwarf2dbg_final_check): New function.
	* dwarf2dbg.h (struct dwarf2_line_info): Add view.
	(dwarf2dbg_final_check): Declare.
	* read.c (s_leb128): Parse expression as deferred.
	* testsuite/gas/all/gas.exp: Run sleb128-9.
	* testsuite/gas/all/sleb128-9.d: New.
	* testsuite/gas/all/sleb128-9.l: New.
	* testsuite/gas/all/sleb128-9.s: New.
	* testsuite/gas/elf/dwarf2-1.d: Add nonzero views.
	* testsuite/gas/elf/dwarf2-2.d: Likewise.
	* testsuite/gas/elf/dwarf2-5.d: New.
	* testsuite/gas/elf/dwarf2-5.s: New.
	* testsuite/gas/elf/dwarf2-6.d: New.
	* testsuite/gas/elf/dwarf2-6.s: New.
	* testsuite/gas/elf/dwarf2-7.d: New.
	* testsuite/gas/elf/dwarf2-7.s: New.
	* testsuite/gas/elf/dwarf2-8.d: New.
	* testsuite/gas/elf/dwarf2-8.l: New.
	* testsuite/gas/elf/dwarf2-8.s: New.
	* testsuite/gas/elf/dwarf2-9.d: New.
	* testsuite/gas/elf/dwarf2-9.l: New.
	* testsuite/gas/elf/dwarf2-9.s: New.
	* testsuite/gas/elf/dwarf2-10.d: New.
	* testsuite/gas/elf/dwarf2-10.l: New.
	* testsuite/gas/elf/dwarf2-10.s: New.
	* testsuite/gas/elf/dwarf2-11.d: New.
	* testsuite/gas/elf/dwarf2-11.s: New.
	* testsuite/gas/elf/dwarf2-12.d: New.
	* testsuite/gas/elf/dwarf2-12.s: New.
	* testsuite/gas/elf/dwarf2-13.d: New.
	* testsuite/gas/elf/dwarf2-13.s: New.
	* testsuite/gas/elf/dwarf2-14.d: New.
	* testsuite/gas/elf/dwarf2-14.s: New.
	* testsuite/gas/elf/dwarf2-15.d: New.
	* testsuite/gas/elf/dwarf2-15.s: New.
	* testsuite/gas/elf/dwarf2-16.d: New.
	* testsuite/gas/elf/dwarf2-16.s: New.
	* testsuite/gas/elf/dwarf2-17.d: New.
	* testsuite/gas/elf/dwarf2-17.s: New.
	* testsuite/gas/elf/dwarf2-18.d: New.
	* testsuite/gas/elf/dwarf2-18.s: New.
	* testsuite/gas/elf/elf.exp: Run dwarf2-5..18 tests.
	* testsuite/gas/i386/dw2-compress-1.d: Add nonzero views.
	* testsuite/gas/i386/dw2-compressed-1.d: Likewise.
	* testsuite/gas/i386/ilp32/lns/lns-duplicate.d: Likewise.
	* testsuite/gas/lns/lns-big-delta.d: Likewise.
	* testsuite/gas/lns/lns-duplicate.d: Likewise.
	* testsuite/gas/mips/loc-swap-2.d: Likewise.
	* testsuite/gas/mips/loc-swap-3.d: Likewise.
	* testsuite/gas/mips/loc-swap.d: Likewise.
	* testsuite/gas/mips/micromips@loc-swap-2.d: Likewise.
	* testsuite/gas/mips/micromips@loc-swap.d: Likewise.
	* testsuite/gas/mips/mips16@loc-swap-2.d: Likewise.
	* testsuite/gas/mips/mips16@loc-swap.d: Likewise.
	* testsuite/gas/mips/mips16e@loc-swap.d: Likewise.
	* write.c (write_object_file): Check pending view asserts.
	(cvt_frag_to_fill): Complain about undefined leb128 operand.
2017-07-21 10:13:18 +01:00
Maciej W. Rozycki 2018ef80ae PR ld/16656: Add missing annotation to the relevant ChangeLog entries
Add PR ld/16656 annotation to ChangeLog entries for commit 9a0f1d5099
("LD/testsuite: Conditionalize the placement of `.dynamic' in
GNU_RELRO") and commit ("LD/testsuite: Conditionalize the placement of
`.got' in GNU_RELRO").
2017-07-20 00:39:57 +01:00
Maciej W. Rozycki 62a5222fda LD/testsuite: Add 2**4 section alignment FILL script statement test
Complement commit ffe54b3798 ("Pad sections according to current
script FILL.") and add a FILL script statement test for targets that
impose the minimum alignment of more than 2**2 for the `.text' section.
These targets include IA-64 targets, MIPS targets other than bare-metal
ELF and VxWorks, TILE-Gx targets, TILEPro targets and X86-64 PE targets.

Use the `notarget' tag for configuration triplets that are incompatible
with the new test, but are supported by the existing FILL test, and
`xfail' for ones that have issues due to section alignment or padding
with both tests.  Make a complementary change to the existing FILL test,
removing the following test issues:

arm-epoc-pe  -FAIL: ld-scripts/fill
mips-elf  -XPASS: ld-scripts/fill
mips-img-elf  -XPASS: ld-scripts/fill
mips-mti-elf  -XPASS: ld-scripts/fill
mips-sde-elf  -XPASS: ld-scripts/fill
mips-vxworks  -XPASS: ld-scripts/fill
mipsel-elf  -XPASS: ld-scripts/fill
mipsel-img-elf  -XPASS: ld-scripts/fill
mipsel-mti-elf  -XPASS: ld-scripts/fill
mipsel-vxworks  -XPASS: ld-scripts/fill
mipsisa32-elf  -XPASS: ld-scripts/fill
mipsisa32el-elf  -XPASS: ld-scripts/fill
mipsisa64-elf  -XPASS: ld-scripts/fill
mipsisa64el-elf  -XPASS: ld-scripts/fill
tilegx-linux  -FAIL: ld-scripts/fill
tilepro-elf  -FAIL: ld-scripts/fill
tx39-elf  -XPASS: ld-scripts/fill

	ld/
	* testsuite/ld-scripts/fill.d: Adjust `xfail' entries.  Add
	`notarget' entries.  Update comments.
	* testsuite/ld-scripts/fill16.d: New test.
	* testsuite/ld-scripts/fill16_0.s: New test source.
	* testsuite/ld-scripts/fill16_1.s: New test source.
	* testsuite/ld-scripts/fill16_2.s: New test source.
	* testsuite/ld-scripts/data.exp: Run the new test.
2017-07-19 13:11:59 +01:00
John Eric Martin 684d5a10b1 [ARC] Add JLI support.
The following relocation types were added to GCC/binutils:

ARC_JLI_SECTOFF is a relocation type in Metaware that is now used by
GCC as well to adjust the index of function calls to functions with
attribute jli_call_always.

bfd/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elf32-arc.c (JLI): Define.
	* reloc.c: Add JLI relocations.

gas/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/gas/arc/jli-1.d: New file.
	* testsuite/gas/arc/jli-1.s: Likewise.
	* testsuite/gas/arc/taux.d: Update for jli_base.

include/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* elf/arc-reloc.def: Add JLI relocs howto.
	* opcode/arc-func.h (replace_jli): New function.

ld/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* emulparams/arcelf.sh (JLI_START_TABLE): Define.
	* scripttempl/elfarc.sc: Handle jlitab section.
	* scripttempl/elfarcv2.sc: Likewise.
	* testsuite/ld-arc/arc.exp: Add JLI test.
	* testsuite/ld-arc/jli-script.ld: New file.
	* testsuite/ld-arc/jli-simple.dd: Likewise.
	* testsuite/ld-arc/jli-simple.rd: Likewise.
	* testsuite/ld-arc/jli-simple.s: Likewise.
	* testsuite/ld/testsuite/ld-arc/jli-overflow.s: Likewise.
	* testsuite/ld/testsuite/ld-arc/jli-overflow.d: Likewise.
	* testsuite/ld/testsuite/ld-arc/jli-overflow.err: Likewise.

opcode/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* arc-opc.c (UIMM10_6_S_JLIOFF): Define.
	(UIMM3_23): Adjust accordingly.
	* arc-regs.h: Add/correct jli_base register.
	* arc-tbl.h (jli_s): Likewise.
2017-07-19 09:56:55 +02:00
Tristan Gingold e4943f2c75 Remove datasize measurements based on sbrk()
binutils/
	* nm.c (show_stats): Remove variable.
	(long_options): Remove --stats option.
	(main): Remove handling of --stats.

ld/
	* ldmain.c (main): Remove display of data size.

gas/
	* as.c (start_sbrk): Remove.
	(main): Remove assignment.
	(dump_statistics): Remove display of data size.
2017-07-19 09:55:12 +02:00
Maciej W. Rozycki 927960f053 LD/testsuite: Conditionalize the placement of `.got' in GNU_RELRO
Complement commit d345186d05 ("Check if GNU_RELRO segment is is
generated") and exclude the presence of a `.got' section from implying
the creation of a GNU_RELRO segment for targets which place the section
along with small data, and therefore as it stands cannot have the
section assigned to GNU_RELRO.  This is because we currently only
support a single GNU_RELRO segment and we place it at the beginning of
regular data which is then separated from small data by read-write data.

Currently the list of such targets consists of Alpha, Linux HPPA, NetBSD
HPPA, OpenBSD HPPA, Meta, MIPS, Nios II, OpenRISC 1000, RISC-V, SH and
X86-64, as determined by examining default linker scripts produced in a
`--enable-targets=all' build for those that have DATA_SEGMENT_RELRO_END
set and `.got' placed beyond.  These targets do not set NO_SMALL_DATA or
DATA_GOT in their respective files in ld/emulparams/*, hovever checking
for the absence of these settings on its own is not very feasible due to
the structure of these files and the lack of support for GNU_RELRO by
some targets in the first place.

Add a separate control for `.got.plt' which does get placed in GNU_RELRO
on MIPS targets even though `.got' does not.

	ld/
	* testsuite/ld-elf/binutils.exp (binutils_test): Make the
	expectation for `.got' in GNU_RELRO segment target-specific.
	Handle `.got.plt' separately.
2017-07-18 17:20:30 +01:00
Maciej W. Rozycki 9a0f1d5099 LD/testsuite: Conditionalize the placement of `.dynamic' in GNU_RELRO
Complement commit d345186d05 ("Check if GNU_RELRO segment is is
generated") and exclude the presence of a `.dynamic' section from
implying the creation of a GNU_RELRO segment for targets which place the
section in the (read-only) text segment, and therefore cannot have the
section assigned to GNU_RELRO and neither it would make sense.

Currently the list of such targets consists of 64-bit HPPA and
non-VxWorks MIPS targets, as determined by looking for TEXT_DYNAMIC
being set across ld/emulparams/* and then verified by examining default
linker scripts produced in a `--enable-targets=all' build.

	ld/
	* testsuite/ld-elf/binutils.exp (binutils_test): Make the
	expectation for `.dynamic' in GNU_RELRO segment target-specific.
2017-07-18 17:20:30 +01:00
Yuri Chornovian de194d8575 Fix spelling typos. 2017-07-18 16:58:14 +01:00
H.J. Lu 89d249d2f2 i386: Add tests for PIE with undefined weak symbol
* testsuite/ld-i386/i386.exp: Run pie1 and pie1-nacl.
	* testsuite/ld-i386/pie1-nacl.d: New file.
	* testsuite/ld-i386/pie1.d: Likewise.
	* testsuite/ld-i386/pie1.s: Likewise.
2017-07-17 12:42:32 -07:00
H.J. Lu 8e85f840e1 Add missing ChangeLog entries for PR ld/21782 fix 2017-07-17 12:40:57 -07:00
H.J. Lu c5bb8910e8 x86-64: Limit PIC check to shared library build
When building an executable, undefined symbols are error and undefined
weak symbols are resolved to zero.  We only need to check PIC for
building a shared library.

bfd/

	PR ld/21782
	* elf64-x86-64.c (elf_x86_64_relocate_section): Limit PIC check
	to shared library.

ld/

	PR ld/21782
	* testsuite/ld-x86-64/pie3-nacl.d: New file.
	* testsuite/ld-x86-64/pie3.d: Likewise.
	* testsuite/ld-x86-64/pie3.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pie3 and pie3-nacl.
2017-07-17 12:17:59 -07:00
Alan Modra 86038de0d8 ppc32 tlsopt tests
These all were odd in that they used r13 as the GOT pointer.  That
didn't matter for the purpose of testing, but would never occur in
practice.  Also, the tlsopt5 tests could have their global dynamic
sequences optimized to initial exec, so link with -shared.

	* testsuite/ld-powerpc/powerpc.exp: Add -shared to tlsop5 tests.
	* testsuite/ld-powerpc/tlsopt5.d: Adjust.
	* testsuite/ld-powerpc/tlsopt1_32.s: Use r30 as GOT pointer.
	* testsuite/ld-powerpc/tlsopt2_32.s: Likewise.
	* testsuite/ld-powerpc/tlsopt3_32.s: Likewise.
	* testsuite/ld-powerpc/tlsopt4_32.s: Likewise.
	* testsuite/ld-powerpc/tlsopt5_32.s: Rewrite.
	* testsuite/ld-powerpc/tlsopt1_32.d: Adjust.
	* testsuite/ld-powerpc/tlsopt2_32.d: Adjust.
	* testsuite/ld-powerpc/tlsopt3_32.d: Adjust.
	* testsuite/ld-powerpc/tlsopt5_32.d: Adjust.
2017-07-14 22:51:01 +09:30
Maciej W. Rozycki 211b0bed95 PR ld/21529: Use a linker script to limit output with the test case
Complement commit d940949881 ("Add a testcase for PR ld/21529") and
use a linker script to prevent an inter-segment gap arranged by the
default linker script associated with some targets such as `rx-elf':

$ ld -e main -o tmpdir/dump-elf tmpdir/pr21529.o
$ readelf -l tmpdir/dump-elf
Elf file type is EXEC (Executable file)
Entry point 0x10000004
There are 2 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0x10000000 0x10000000 0x00008 0x00008 R E 0x1000
  LOAD           0x001ffc 0xbffffffc 0xbffffffc 0x00004 0x00004 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .text
   01     .stack
$

and converted to padding with the use of the binary BFD for output from
producing unreasonably large files.

	ld/
	* testsuite/ld-unique/pr21529.ld: New test linker script.
	* testsuite/ld-unique/pr21529.d: Use it.
2017-07-14 11:53:08 +01:00
Alan Modra 429d795d50 Update PO files
bfd/
	* po/es.po: Update from translationproject.org/latest/bfd/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/ja.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/hr.po: New file from translationproject.org.
	* configure.ac (ALL_LINGUAS): Add hr.  Sort.
	* configure: Regenerate.

binutils/
	* po/bg.po: Update from translationproject.org/latest/binutils/.
	* po/ca.po: Likewise.
	* po/da.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/hr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sk.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/zh_TW.po: Likewise.

gas/
	* po/es.po: Update from translationproject.org/latest/gas/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/ja.po: Likewise.
	* po/ru.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/zh_CN.po: Likewise.

gold/
	* po/es.po: Update from translationproject.org/latest/gold/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/ja.po: New file from translationproject.org.
	* po/sv.po: Likewise.
	* po/uk.po: Likewise.

gprof/
	* po/bg.po: Update from translationproject.org/latest/gprof/.
	* po/da.po: Likewise.
	* po/de.po: Likewise.
	* po/eo.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/ga.po: Likewise.
	* po/hu.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/ms.po: Likewise.
	* po/nl.po: Likewise.
	* po/pt_BR.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.

ld/
	* po/bg.po: Update from translationproject.org/latest/ld/.
	* po/da.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/zh_TW.po: Likewise.
	* po/de.po: New file from translationproject.org.
	* po/ru.po: Likewise.
	* configure.ac (ALL_LINGUAS): Add de, ru.  Sort.
	* configure: Regenerate.

opcodes/
	* po/da.po: Update from translationproject.org/latest/opcodes/.
	* po/de.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/nl.po: Likewise.
	* po/pt_BR.po: Likewise.
	* po/ro.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
2017-07-12 23:08:59 +09:30
Alan Modra 2fe40b6792 rs6000 testsuite update
* testsuite/ld-scripts/align.exp: Exclude powerpc*-*-aix*.
	* testsuite/ld-scripts/assign-loc.d: Likewise.
	* testsuite/ld-scripts/defined3.d: Likewise.
	* testsuite/ld-scripts/defined4.d: Likewise.
	* testsuite/ld-scripts/defined5.d: Likewise.
	* testsuite/ld-scripts/expr2.d: Likewise.
	* testsuite/ld-scripts/provide.exp: Likewise.
	* testsuite/ld-scripts/sane1.d: Likewise.
	* testsuite/ld-scripts/size.exp: Likewise.
	* testsuite/ld-scripts/defined2.d: Don't xfail rs6000-*-aix*.
2017-07-12 19:31:26 +09:30
Alan Modra d42c267e9b bfd_error_handler bfd_vma and bfd_size_type args
This patch uses the new %L _bfd_error_handler support for printing
bfd_vma arguments, and fixes a many other format and/or argument
errors in error messages.

bfd/
	* binary.c (binary_set_section_contents): Don't print filepos in
	error message.
	(coff_write_object_contents): Cast size_t for error message.
	(coff_slurp_line_table): Don't use bfd_vma symndx.
	(coff_slurp_reloc_table): Remove unneeded cast.
	* dwarf2.c (read_section): Cast bfd_int64_t to long long for
	error message.
	(find_abstract_instance_name): Likewise.
	* elf32-arm.c (arm_type_of_stub): Correct error arg order.
	(bfd_elf32_arm_stm32l4xx_erratum_scan): Don't cast error arg.
	(elf32_arm_check_relocs): Make r_symndx an int.
	* elf32-cris.c (cris_elf_check_relocs): Delete extraneous %s in
	format string.
	* elf32-metag.c (elf_metag_relocate_section): Delete extra error
	message arg.
	* elf32-nds32.c (nds32_elf_ex9_build_hash_table): Rewrite bogus
	error message.
	* elf32-i386.c (elf_i386_check_relocs): Make r_symndx an int.
	* elf32-s390.c (elf_s390_check_relocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_check_relocs): Likewise.
	* elf32-tilepro.c (tilepro_elf_check_relocs): Likewise.
	* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
	* elf64-s390.c (elf_s390_check_relocs): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Likewise.
	* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
	* elfxx-tilegx.c (tilegx_elf_check_relocs): Likewise.
	* elf64-mmix.c (_bfd_mmix_after_linker_allocation): Cast size_t args
	and use %lu for error message.
	* elflink.c (elf_link_adjust_relocs): Delete extra error message arg.
	* mmo.c (mmo_scan): Make stab_loc a file_ptr.  Cast expression for
	error message.

	* elf32-arm.c (elf32_arm_tls_relax): Correct format string and args
	in error message.
	(elf32_arm_final_link_relocate): Likewise.
	* coff-arm.c (bfd_arm_process_before_allocation): Likewise.
	* coffcode.h (styp_to_sec_flags): Likewise.
	* cofflink.c (_bfd_coff_write_global_sym): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_symbol_table): Likewise.
	* elf32-arc.c (arc_elf_merge_private_bfd_data): Likewise.
	* elf32-bfin.c (bfinfdpic_check_relocs): Likewise.
	(elf32_bfin_merge_private_bfd_data): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-frv.c (frv_elf_merge_private_bfd_data): Likewise.
	* elf32-i370.c (i370_elf_merge_private_bfd_data): Likewise.
	(i370_elf_relocate_section): Likewise.
	* elf32-iq2000.c (iq2000_elf_merge_private_bfd_data): Likewise.
	* elf32-m32c.c (m32c_elf_merge_private_bfd_data): Likewise.
	* elf32-m68hc1x.c (_bfd_m68hc11_elf_merge_private_bfd_data): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-mep.c (mep_elf_merge_private_bfd_data): Likewise.
	* elf32-mt.c (mt_elf_merge_private_bfd_data): Likewise.
	* elf64-sparc.c (elf64_sparc_merge_private_bfd_data): Likewise.
	* elfxx-mips.c (mips_elf_merge_obj_e_flags): Likewise.
	(_bfd_mips_elf_merge_private_bfd_data): Likewise.
	* ieee.c (ieee_write_id, read_id): Likewise.
	* mach-o.c (bfd_mach_o_write_contents): Likewise.
	(bfd_mach_o_layout_commands, bfd_mach_o_read_section_32): Likewise.
	(bfd_mach_o_read_section_64, bfd_mach_o_read_symtab_symbol): Likewise.
	(bfd_mach_o_read_command, bfd_mach_o_header_p): Likewise.
	* peXXigen.c (_bfd_XXi_swap_aouthdr_in): Likewise.
	* stabs.c (_bfd_link_section_stabs): Likewise.

	* coff-arm.c (coff_arm_relocate_section): Use L modifier in error
	format.
	* coff-mcore.c (coff_mcore_relocate_section): Likewise.
	* coff-ppc.c (coff_ppc_relocate_section): Likewise.
	* coff-rs6000.c (xcoff_reloc_type_toc): Likewise.
	* coff-sh.c (sh_relax_section): Likewise.
	(sh_relax_delete_bytes, sh_swap_insns): Likewise.
	* coff-tic80.c (coff_tic80_relocate_section): Likewise.
	* coffcode.h (coff_slurp_reloc_table): Likewise.
	* coffgen.c (_bfd_coff_get_external_symbols): Likewise.
	(_bfd_coff_read_string_table): Likewise.
	* cofflink.c (_bfd_coff_generic_relocate_section): Likewise.
	* compress.c (bfd_get_full_section_contents): Likewise.
	* dwarf2.c (read_formatted_entries, decode_line_info): Likewise.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf.c (bfd_elf_string_from_elf_section): Likewise.
	* elf32-arc.c (arc_special_overflow_checks): Likewise.
	* elf32-arm.c (elf32_arm_tls_relax): Likewise.
	(elf32_arm_final_link_relocate, elf32_arm_relocate_section): Likewise.
	(elf32_arm_write_section): Likewise.
	* elf32-bfin.c (bfin_relocate_section): Likewise.
	(bfinfdpic_relocate_section): Likewise.
	* elf32-hppa.c (hppa_build_one_stub): Likewise.
	(final_link_relocate, elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_tls_transition): Likewise.
	(elf_i386_relocate_section): Likewise.
	* elf32-ip2k.c (ip2k_final_link_relocate): Likewise.
	* elf32-lm32.c (lm32_elf_finish_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-metag.c (elf_metag_relocate_section): Likewise.
	* elf32-nds32.c (unrecognized_reloc_msg): Likewise.
	(nds32_elf_relax_longcall1, nds32_elf_relax_longcall2): Likewise.
	(nds32_elf_relax_longcall3, nds32_elf_relax_longjump1): Likewise.
	(nds32_elf_relax_longjump2, nds32_elf_relax_longjump3): Likewise.
	(nds32_elf_relax_longcall4, nds32_elf_relax_longcall5): Likewise.
	(nds32_elf_relax_longcall6, nds32_elf_relax_longjump4): Likewise.
	(nds32_elf_relax_longjump5, nds32_elf_relax_longjump6): Likewise.
	(nds32_elf_relax_longjump7, nds32_elf_relax_loadstore): Likewise.
	(nds32_elf_relax_ptr, nds32_elf_ex9_build_hash_table): Likewise.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-rx.c (UNSAFE_FOR_PID): Likewise.
	* elf32-s390.c (invalid_tls_insn, elf_s390_relocate_section): Likewise.
	* elf32-score.c (s3_bfd_score_elf_check_relocs): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_relax_section): Likewise.
	(sh_elf_relax_delete_bytes, sh_elf_swap_insns): Likewise.
	(sh_elf_relocate_section): Likewise.
	* elf32-sh64.c (shmedia_prepare_reloc): Likewise.
	* elf32-spu.c (spu_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-v850.c (v850_elf_relax_section): Likewise.
	* elf32-vax.c (elf_vax_check_relocs): Likewise.
	(elf_vax_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	(extend_ebb_bounds_forward, extend_ebb_bounds_backward): Likewise.
	(compute_text_actions, compute_ebb_proposed_actions): Likewise.
	(do_fix_for_relocatable_link): Likewise.
	* elf64-alpha.c (elf64_alpha_relax_got_load): Likewise.
	(elf64_alpha_relax_with_lituse): Likewise.
	* elf64-hppa.c (elf64_hppa_finish_dynamic_symbol): Likewise.
	(elf_hppa_final_link_relocate): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_relax_section): Likewise.
	(elf64_ia64_choose_gp, elf64_ia64_relocate_section): Likewise.
	(elf64_vms_link_add_object_symbols): Likewise.
	* elf64-mmix.c (mmix_elf_perform_relocation): Likewise.
	(mmix_final_link_relocate): Likewise.
	* elf64-s390.c (invalid_tls_insn): Likewise.
	(elf_s390_relocate_section): Likewise.
	* elf64-sh64.c (sh_elf64_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
	(elf_x86_64_relocate_section): Likewise.
	* elfcode.h (elf_slurp_symbol_table): Likewise.
	* elfcore.h (elf_core_file_p): Likewise.
	* elflink.c (elf_link_read_relocs_from_section): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	(elfNN_aarch64_relocate_section): Likewise.
	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
	(elfNN_ia64_choose_gp, elfNN_ia64_relocate_section): Likewise.
	* elfnn-riscv.c (riscv_elf_relocate_section): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
	(_bfd_mips_elf_relocate_section): Likewise.
	(_bfd_mips_elf_finish_dynamic_symbol, mips_finish_exec_plt): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
	* ieee.c (ieee_slurp_external_symbols): Likewise.
	* ihex.c (ihex_write_object_content): Likewise.
	* mach-o.c (bfd_mach_o_build_exec_seg_command): Likewise.
	* merge.c (_bfd_merged_section_offset): Likewise.
	* mmo.c (mmo_write_loc_chunk): Likewise.
	(mmo_write_object_contents): Likewise.
	* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Likewise.
	* stabs.c (_bfd_link_section_stabs): Likewise.
	* xcofflink.c (xcoff_link_add_symbols, xcoff_find_tc0): Likewise.
ld/
	* testsuite/ld-arc/nps-1b.err: Update.
	* testsuite/ld-x86-64/ilp32-11.d: Update.
2017-07-12 14:03:48 +09:30
H.J. Lu 61a0857c0f Support single digit GCC version
On Fedora 26, "g++ -dumpversion" displays "7", instead of "7.1.1".
Update selective.exp to support single digit GCC version.  Also
remove duplicated [4-9] version check.

	* testsuite/ld-selective/selective.exp: Support single digit
	GCC version.
2017-07-11 08:41:22 -07:00
Jiong Wang 70391b29cf [AArch64] Use "#pass" instead of "#..." to filter multiple lines
ld/
	* testsuite/ld-aarch64/dt_textrel.d: Use "#pass" instead of ".*" to
	filter out remaining lines.
2017-07-11 11:29:51 +01:00
Maciej W. Rozycki e54cb31aa3 MIPS/LD: Fix a segfault from ELF `e_flags' access with non-ELF output BFD
Fix a commit 861fb55ab5 ("Defer allocation of R_MIPS_REL32 GOT
slots"), <https://sourceware.org/ml/binutils/2008-08/msg00096.html>,
regression and a more recent:

FAIL: ld-unique/pr21529

new LD test case failure, observed with all the relevant MIPS targets
whenever the linker is invoked with one or more ELF inputs and the
output format set to `binary'.

The culprit is a segmentation fault caused in `mips_before_allocation'
by a null pointer dereference, where an attempt is made to access the
ELF file header's `e_flags' member, for the purpose of determining
whether to produce a PLT and copy relocations, without first checking
that the output BFD is ELF.  The `e_flags' member is stored in BFD's
private data pointed to by `tdep', which in the case of the `binary' BFD
is null, causing the segmentation fault.  With other non-ELF BFDs such
as SREC `tdep' is not null and consequently no crash may happen and in
that case random data will be interpreted as it was `e_flags'.

Disable the access to `e_flags' then and all the associated checks and
consequently never produce a PLT and copy relocations if output is not a
MIPS ELF BFD, matching `_bfd_mips_elf_merge_private_bfd_data' that does
not process `e_flags' in that case either and therefore does not let us
decide here anyway if all the input objects included in the link are
suitable for use with a PLT and copy relocations.

	ld/
	* emultempl/mipself.em (mips_before_allocation): Avoid ELF
	processing if not MIPS ELF.
	* testsuite/ld-mips-elf/binary.d: New test.
	* testsuite/ld-mips-elf/binary.ld: New test linker script.
	* testsuite/ld-mips-elf/binary.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2017-07-07 17:58:03 +01:00
Alan Modra c620a2b547 Make ppc476 testcases more robust
* testsuite/ld-powerpc/ppc476-shared.lnk: Align .bss.
	* testsuite/ld-powerpc/ppc476-shared.d: Adjust.
	* testsuite/ld-powerpc/ppc476-shared2.d: Adjust.
2017-07-07 23:53:18 +09:30
Alan Modra aff6079bc7 Apply ld/Makefile.in patch to the correct file
Makefile.in is generated.

	* Makefile.am (eelf64_s390.c): Depend on emultempl/s390.em.
2017-07-07 10:35:31 +09:30
Tristan Gingold 0d702cfe5d Regenerate configure.
bfd/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* version.m4: Bump version to 2.29.51
	* configure: Regenerate.

binutils/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

gas/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

gprof/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

ld/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

opcodes/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.
2017-07-04 11:15:33 +02:00
Tristan Gingold 55a09eb6df Add markers.
binutils/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.29.

gas/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.29.

ld/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.29.
2017-07-04 11:07:03 +02:00
Tristan Gingold 15e6ed8cbf Regenerate pot files. 2017-07-03 17:02:01 +02:00
Maciej W. Rozycki 9f00292e69 MIPS/GAS: Use non-zero frag offset directly in PIC branch relaxation
Use frag symbols with a non-zero offset directly in `fix_new_exp' calls
made in PIC branch relaxation.  There is no need here to make a helper
symbol to hold the result of a `symbol+offset' calculation requested as
only branches to local symbols are relaxed and in this case the LO16
part of the PIC address load sequence will have the offset accounted for
in calculation against the local GOT entry retrieved as the GOT16 high
part.  Consequently actual code produed is identical whether a helper
symbol is used or the original `symbol+offset' expression used directly.
Verify that this is indeed the case with GAS and LD tests.

	gas/
	* config/tc-mips.c (md_convert_frag): Don't make a helper
	expression symbol for `fix_new_exp' called with a non-zero
	offset.
	* testsuite/gas/mips/relax-offset.d: New test.
	* testsuite/gas/mips/mips1@relax-offset.d: New test.
	* testsuite/gas/mips/r3000@relax-offset.d: New test.
	* testsuite/gas/mips/r3900@relax-offset.d: New test.
	* testsuite/gas/mips/micromips@relax-offset.d: New test.
	* testsuite/gas/mips/relax-offset.l: New stderr output.
	* testsuite/gas/mips/relax-offset.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/relax-offset.dd: New test.
	* testsuite/ld-mips-elf/relax-offset.gd: New test.
	* testsuite/ld-mips-elf/relax-offset-umips.dd: New test.
	* testsuite/ld-mips-elf/relax-offset-umips.gd: New test.
	* testsuite/ld-mips-elf/relax-offset.ld: New test linker script.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
	(prune_warnings): New temporary procedure.
2017-07-01 00:42:19 +01:00
Maciej W. Rozycki 819e1f8697 MIPS: Add new Imagination interAptiv MR2 GAS and LD tests
Add GAS tests to verify Imagination interAptiv MR2 instruction assembly,
disassembly and ELF object file flags.

Add LD tests to verify Imagination interAptiv MR2 ELF object file
link-time compatibility and flag merging/propagation.  Use the framework
enhancement added with commit 7575e6a752 ("MIPS/LD/testsuite:
mips-elf-flags: Add MIPS ABI Flags handling").

	gas/
	* testsuite/gas/mips/elf_mach_interaptiv-mr2.d: New test.
	* testsuite/gas/mips/save-err.d: New test.
	* testsuite/gas/mips/save-sub.d: New test.
	* testsuite/gas/mips/interaptiv-mr2@save.d: New test.
	* testsuite/gas/mips/mips1@save-sub.d: New test.
	* testsuite/gas/mips/mips2@save-sub.d: New test.
	* testsuite/gas/mips/mips3@save-sub.d: New test.
	* testsuite/gas/mips/mips4@save-sub.d: New test.
	* testsuite/gas/mips/mips5@save-sub.d: New test.
	* testsuite/gas/mips/mips32@save-sub.d: New test.
	* testsuite/gas/mips/mips64@save-sub.d: New test.
	* testsuite/gas/mips/mips16@save-sub.d: New test.
	* testsuite/gas/mips/mips16e@save-sub.d: New test.
	* testsuite/gas/mips/r3000@save-sub.d: New test.
	* testsuite/gas/mips/r3900@save-sub.d: New test.
	* testsuite/gas/mips/r4000@save-sub.d: New test.
	* testsuite/gas/mips/vr5400@save-sub.d: New test.
	* testsuite/gas/mips/interaptiv-mr2@save-sub.d: New test.
	* testsuite/gas/mips/sb1@save-sub.d: New test.
	* testsuite/gas/mips/octeon2@save-sub.d: New test.
	* testsuite/gas/mips/octeon3@save-sub.d: New test.
	* testsuite/gas/mips/xlr@save-sub.d: New test.
	* testsuite/gas/mips/r5900@save-sub.d: New test.
	* testsuite/gas/mips/mips16e2-copy.d: New test.
	* testsuite/gas/mips/mips16e2-copy-err.d: New test.
	* testsuite/gas/mips/save.d: Remove `MIPS16e' from the `name'
	option.  Adjust for trailing padding change.
	* testsuite/gas/mips/mips16e2-copy-err.l: New stderr output.
	* testsuite/gas/mips/save-sub.s: New test source.
	* testsuite/gas/mips/mips16e2-copy.s: New test source.
	* testsuite/gas/mips/mips16e2-copy-err.s: New test source.
	* testsuite/gas/mips/save.s: Update description, change trailing
	padding and remove trailing white space.
	* testsuite/gas/mips/mips.exp: Expand `save' and `save-err'
	tests across the regular MIPS interAptiv MR2 architecture.  Run
	the new tests.

	ld/
	* testsuite/ld-mips-elf/mips-elf-flags.exp: Add interAptiv MR2
	tests.
2017-06-28 02:07:36 +01:00
Senthil Kumar Selvaraj 6806377956 Fix PR 13402
Fix incorrect adjustment of diff relocs when relaxing, and thus the
resulting source line to address mismatch.

Fix two issues when adjusting diff relocs to account for
deleted bytes.

1. Don't adjust the difference if the end address is the shrinked
insn's address i.e. use < instead of <=. The relaxation code deletes
count bytes from or after shrinked_insn_address, so the difference
between start_address and end_address should remain unchanged in this
case.

2. Adjust the reloc addend if the difference is to be adjusted and
symval + reloc addend is past the shrinked insn address. This is
because for a typical sym1 - sym2 diff reloc, sym1 is .text +
irel->r_addend, and the addend should be reduced to account for the
shrinked insn.

For example, assume the reloc value is .text + 0x8 with .text = 0, the
diff value in the object file = 0x4, and shrinked_insn_address = 0x4
with count = 0x2. Then the existing code writes 0x2 into the object
file to account for the deleted bytes, as shrinked_insn_address lies
between 0x8 and 0x8 - 0x4 = 0x4, but leaves the addend as is. The next
time the reloc is looked at, the code sees if a shrinked_insn_address
lies between 0x8 and 0x8 - 0x2 = 0x6, instead of 0x6 and 0x4. If there
happens to be one, then the diff value in the object file ends up
getting reduced again.

bfd/

2017-06-27  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/13402
	* elf32-avr.c (elf32_avr_adjust_diff_reloc_value): Adjust
	reloc addend if necessary. Adjust diff only if
	shrinked_insn_address < end_address.

ld/

2017-06-27  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/13402
	* testsuite/ld-avr/pr13402.d: New test.
	* testsuite/ld-avr/pr13402.s: New test.
2017-06-27 14:47:02 +05:30
Maciej W. Rozycki 7575e6a752 MIPS/LD/testsuite: mips-elf-flags: Add MIPS ABI Flags handling
Complement commit 351cdf24d2 ("[MIPS] Implement O32 FPXX, FP64 and
FP64A ABI extensions") and add optional MIPS ABI Flags handling to
`good_combination' in the `mips-elf-flags.exp' test script.  This lets
callers of this procedure request to examine MIPS ABI Flags in addition
to the `e_flags' member of the ELF file header so as to verify that
flags are merged correctly by LD.  The presence of further arguments
triggers this verification, in which case `readelf' is called with the
`-A' option additionally specified and the ISA member, the ISA Extension
member and the ASEs member will be examined as per the arguments.

Unlike with `readelf -h' output consider a failure to retrieve the
member requested a test case failure rather than an unresolved result.
This is because unlike with the `e_flags' member of the ELF file header
which is always there in any valid ELF file the MIPS ABI Flags structure
is optional in LD output and the absence of this structure when expected
is surely a bug in LD.

	ld/
	* testsuite/ld-mips-elf/mips-elf-flags.exp (good_combination):
	Add an `args' final argument and examination code for `readelf
	-A' output.  Update procedure description accordingly.
2017-06-27 02:58:27 +01:00
Maciej W. Rozycki 1284e99a6c MIPS/LD/testsuite: mips-elf-flags: Use `remote_exec' to call `readelf'
For ELF file header flag verification done in `good_combination' in the
`mips-elf-flags.exp' test script the version of `readelf' built along
with the rest of binutils has to be used rather than any such executable
already present on the build system, so that flags recognized by the
tool match those supported by LD being tested.  Use `remote_exec' as
elsewhere in the LD test framework and also with GAS and LD used here,
getting and arranging for extra reporting of `readelf' calls included in
test logs on this occasion as well.

	ld/
	* testsuite/ld-mips-elf/mips-elf-flags.exp (good_combination):
	Use `remote_exec' to call `readelf'.  Log the command issued.
2017-06-27 02:58:27 +01:00
Maciej W. Rozycki b1a2d7a0e5 MIPS/LD/testsuite: mips-elf-flags: Use `-h' only with `readelf'
For the purpose of link-time object compatibility handling verification
code in the `good_combination' procedure from the `mips-elf-flags.exp'
test script only examines the `e_flags' member of the ELF file header
and ignores data from any ELF program or section headers present.  Use
`readelf -h' rather than `readelf --headers' then to obtain data for
examination, avoiding unnecessary processing to extract this extraneous
information.

	ld/
	* testsuite/ld-mips-elf/mips-elf-flags.exp (good_combination):
	Use `readelf -h' rather than `readelf --headers'.
2017-06-27 02:58:27 +01:00
Maciej W. Rozycki b417536f23 MIPS/BFD: Consistently mark the LSI CW4010 as a MIPS II processor
Make BFD agree with GAS and mark the LSI MiniRISC CW4010 processor core
(for an odd reason referred to as LSI R4010 across our code base) as a
MIPS II processor in BFD as well, fixing a bug that has been there since
forever and addressing linker warnings like:

$ as -m4010 empty.s -o 4010.o
$ ld -r 4010.o -o 4010-r.o
ld: 4010.o: warning: Inconsistent ISA between e_flags and .MIPS.abiflags
$

due to the ISA level being recorded as MIPS III in ELF file header's
`e_flags' vs MIPS II in the MIPS ABI Flags section:

$ readelf -Ah 4010.o
ELF Header:
  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, big endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          348 (bytes into file)
  Flags:                             0x20821000, 4010, o32, mips3
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         11
  Section header string table index: 10
Attribute Section: gnu
File Attributes
  Tag_GNU_MIPS_ABI_FP: Hard float (double precision)

MIPS ABI Flags Version: 0

ISA: MIPS2
GPR size: 32
CPR1 size: 32
CPR2 size: 0
FP ABI: Hard float (double precision)
ISA Extension: LSI R4010
ASEs:
	None
FLAGS 1: 00000000
FLAGS 2: 00000000
$

Available documentation[1][2] clearly indicates the LSI CW4010 processor
is only backwards compatible with the MIPS R4000 processor as far as the
latter's 32-bit instructions are concerned and consequently can only be
considered a MIPS II ISA implementation (with vendor extensions).

This fixes an LD testsuite failure:

FAIL: MIPS incompatible objects:  "-march=r4010 -32"      "-march=r4650 -32"

triggered for the `mips-sgi-irix5' and `mips-sgi-irix6' targets.

References:

[1] Paul Cobb, Bob Caulk, Joe Cesana, "The MiniRISC CW4010: A
    Superscalar MIPS Processor ASIC Core", LSI Logic, July 1995,
    presented at Hot Chips VII, Stanford University, Stanford,
    California, August 1995

[2] "MiniRISC MR4010 Superscalar Microprocessor Reference Device", LSI
    Logic, November 1996, Doc. No. DB09-000028-00, Order No. C15017

	bfd/
	* cpu-mips.c (arch_info_struct): Mark the 4010 32-bit.
	* elfxx-mips.c (mips_set_isa_flags) <bfd_mach_mips4010>: Set
	E_MIPS_ARCH_2 rather than E_MIPS_ARCH_3 in `e_flags'.
	(mips_mach_extensions): Mark `bfd_mach_mips4010' as extending
	`bfd_mach_mips6000' rather than `bfd_mach_mips4000'.

	ld/
	* testsuite/ld-mips-elf/lsi-4010-isa.d: New test.
	* ld/testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2017-06-26 19:27:14 +01:00
Maciej W. Rozycki 515a446417 LD: Fix .startof.SECNAME/.sizeof.SECNAME tests for MIPS/IRIX
Correct .startof.SECNAME/.sizeof.SECNAME tests for MIPS/IRIX targets,
complementing commit dc74becf49 ("ld: Add tests for -Ur") and commit
da614360f5 ("ld: Add tests for .startof.SECNAME/.sizeof.SECNAME") with
subsequent updates, and in reference to commit cbd0eecf26 ("Always
define referenced __start_SECNAME/__stop_SECNAME") and commit
7dba9362c1 ("Rewrite __start and __stop symbol handling").

These targets set the STT_OBJECT type for non-function symbol
references, according to `elf_frob_symbol' code in gas/config/obj-elf.c:

  /* The Irix 5 and 6 assemblers set the type of any common symbol and
     any undefined non-function symbol to STT_OBJECT.  We try to be
     compatible, since newer Irix 5 and 6 linkers care.  However, we
     only set undefined symbols to be STT_OBJECT if we are on Irix,
     because that is the only time gcc will generate the necessary
     .global directives to mark functions.  */

  if (S_IS_COMMON (symp))
    symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;

  if (strstr (TARGET_OS, "irix") != NULL
      && ! S_IS_DEFINED (symp)
      && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0)
    symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;

and consequently entries in the symbol table listing from `readelf'
produced with these tests do not match the NOTYPE pattern expected,
causing test suite failures:

FAIL: ld-elf/sizeofa
FAIL: ld-elf/sizeofc
FAIL: ld-elf/startofa
FAIL: ld-elf/startofc

specifically with the `mips-sgi-irix5' and `mips-sgi-irix6' targets.

Given that it does not matter for the feature covered by these tests
whether the type of the symbols produced is STT_NOTYPE or STT_OBJECT
adjust the problematic cases to accept either type, removing the
failures observed.

	ld/
	* testsuite/ld-elf/sizeofa.d: Also accept the OBJECT type for
	the symbols examined.
	* testsuite/ld-elf/sizeofc.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofc.d: Likewise.
2017-06-26 16:15:15 +01:00
Andreas Krebbel fd52715cfa Add pgste marker changelog 2017-06-26 11:07:17 +02:00
Alan Modra 57963c05b9 Don't attach linker created section to --just-syms bfd
All sections on a --just-syms bfd are discarded from the output, so
attaching linker created sections to such a bfd results in errors.
In other cases, like the .note.GNU-stack check, it's wrong to have a
--just-syms object potentially affect the output.

bfd/
	* elflink.c (_bfd_elf_link_create_dynstrtab): Don't make dynobj
	a --just-syms bfd.
	(_bfd_elf_size_group_sections): Skip --just-syms bfds.
	(bfd_elf_size_dynamic_sections): Ignore .note.GNU-stack and
	.preinit_array on --just-syms bfds.
	(_bfd_elf_gc_mark_extra_sections): Skip --just-syms bfds.
	(elf_gc_sweep, bfd_elf_parse_eh_frame_entries): Likewise.
	(bfd_elf_gc_sections, bfd_elf_discard_info): Likewise.
ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Skip
	--just-syms bfds when looking for a place to attach .note.gnu.build-id
	and .eh_frame_hdr sections.  Delete dead code.
2017-06-26 09:10:22 +09:30
Thomas Preud'homme bff0500d7a [ARM] Add linker support for ARMv8-R
=== Context ===

This patch is part of a patch series to add support for ARMv8-R
architecture. Its purpose is to add support for ARMv8-R in the linker.

=== Patch description ===

This patch is composed of 3 changes:

1) The main change is the addition of the logic for merging a file whose
Tag_CPU_arch build attribute is 15 (ARMv8-R). Namely, all pre-ARMv8 are
merged into ARMv8-R as well as ARMv8-R itself. ARMv8-A (14) merges into
ARMv8-A. ARMv8-M Baseline (16) and Mainline (17) are not allowed to
merge merge with ARMv8-R. Note that merging only occurs if the two
profiles are identical or one is S (Application or Realtime) and the
other is R.

2) using_thumb_only, using_thumb2_bl, using_thumb2 and arch_has_arm_nop
are updated according to capabilities of ARMv8-R and their BFD_ASSERT
updated to reflect that the logic is valid for ARMv8-R.

3) 2 build attribute merging tests are added to test the first change.

2017-06-24  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (using_thumb_only): Update list of architectures in
	BFD_ASSERT for which the logic is valid.
	(using_thumb2_bl): Likewise.
	(using_thumb2): Likewise and return true for ARMv8-R.
	(arch_has_arm_nop): Likewise.
	(tag_cpu_arch_combine): New v8r table for ARMv8-R Tag_CPU_arch
	merging logic.  Update commentis for value 15 of v8m_baseline,
	v8m_mainline and v4t_plus_v6_m arrays.  Use v8r array to decide
	merging of value 15 of Tag_CPU_arch.

ld/
	* testsuite/ld-arm/arm-elf.exp (EABI attribute merging 11): New test.
	(EABI attribute merging 12): Likewise.
	* testsuite/ld-arm/attr-merge-11a.s: New file.
	* testsuite/ld-arm/attr-merge-11b.s: New file.
	* testsuite/ld-arm/attr-merge-11.attr: New file.
	* testsuite/ld-arm/attr-merge-12a.s: New file.
	* testsuite/ld-arm/attr-merge-12b.s: New file.
	* testsuite/ld-arm/attr-merge-12.attr: New file.
2017-06-24 10:48:08 +01:00
Andreas Krebbel b4cbbe8f72 S/390: Add support for pgste marker
This patch adds a new S/390 specific segment type: PT_S390_PGSTE.  For
binaries marked with that segment the kernel will allocate 4k page
tables.  The only user so far will be qemu.

ld/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* Makefile.in: Add s390.em as build dependency.
	* emulparams/elf64_s390.sh (EXTRA_EM_FILE): Add s390.em.
	* emultempl/s390.em: New file.
	* gen-doc.texi: Add documentation for --s390-pgste option.
	* ld.texinfo: Likewise.

include/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf/s390.h (PT_S390_PGSTE): Define macro.

binutils/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* readelf.c (get_s390_segment_type): Add support for the new
	segment type PT_S390_PGSTE.
	(get_segment_type): Call get_s390_segment_type.

elfcpp/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elfcpp.h (enum PT): Add PT_S390_PGSTE to enum.

bfd/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf-s390.h: New file.
	* elf64-s390.c (struct elf_s390_link_hash_table): Add params
	field.
	(elf_s390_additional_program_headers): New function.
	(elf_s390_modify_segment_map): New function.
	(bfd_elf_s390_set_options): New function.
	(elf_backend_additional_program_headers)
	(elf_backend_modify_segment_map): Add macro definitions.
2017-06-23 08:00:46 +02:00
H.J. Lu 0056441823 i386: Add hidden weak undefined tests
* testsuite/ld-i386/i386.exp: Run weakundef1 tests.
	* testsuite/ld-i386/weakundef1.c: New file.
2017-06-22 15:13:15 -07:00
H.J. Lu 922109c718 Pass $NOPIE_CFLAGS to ELF visibility tests
PR ld/21090
	* testsuite/ld-elfvsb/elfvsb.exp (visibility_run): Pass
	$NOPIE_CFLAGS if non-PIE is required.
2017-06-22 12:53:39 -07:00
H.J. Lu 329b5ba137 Pass $NOPIE_CFLAGS/$NOPIE_LDFLAGS to "Run pr19031"
PR ld/21090
	* testsuite/ld-i386/i386.exp: Pass $NOPIE_CFLAGS and
	$NOPIE_LDFLAGS to "Run pr19031".
2017-06-22 10:07:53 -07:00
H.J. Lu 9d1c54ed7f Pass $NOPIE_CFLAGS and $NOPIE_LDFLAGS to more ELF tests
PR ld/21090
	* testsuite/ld-gc/gc.ex: Compile tmpdir/pr14265.o with
	$NOPIE_CFLAGS.
	* testsuite/ld-i386/i386.exp: Pass $NOPIE_CFLAGS and
	$NOPIE_LDFLAGS if non-PIE is required.
	* testsuite/ld-i386/no-plt.exp (NOPIE_CFLAGS): New.
	(NOPIE_LDFLAGS): Likewise.
	Pass $NOPIE_LDFLAGS if non-PIE is required.
	* testsuite/ld-shared/shared.exp: Compile tmpdir/sh1np.o with
	$NOPIE_CFLAGS.
2017-06-22 09:53:33 -07:00
H.J. Lu 48580982ef x86: Support Intel Shadow Stack with SHSTK property
To support Intel Shadow Stack (SHSTK) in Intel Control-flow Enforcement
Technology (CET) instructions:

https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf

 #define GNU_PROPERTY_X86_FEATURE_1_SHSTK (1U << 1)

is added to GNU program properties to indicate that all executable sections
are compatible with SHSTK where return address popped from shadow stack
always matches return address popped from normal stack.

GNU_PROPERTY_X86_FEATURE_1_SHSTK is set on output only if it is set on all
relocatable inputs.

bfd/

	* elf32-i386.c (elf_i386_merge_gnu_properties): If info->shstk
	is set, turn on GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	(elf_i386_link_setup_gnu_properties): If info->shstk is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.
	* elf64-x86-64.c (elf_x86_64_merge_gnu_properties): If
	info->shstk is set, turn on GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	(elf_x86_64_link_setup_gnu_properties): If info->shstk is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.

binutils/

	* readelf.c (decode_x86_feature): Decode
	GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	* testsuite/binutils-all/i386/shstk.d: New file.
	* testsuite/binutils-all/i386/shstk.s: Likewise.
	* testsuite/binutils-all/x86-64/shstk-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk.s: Likewise.

include/

	* bfdlink.h (bfd_link_info): Add shstk.
	* elf/common.h (GNU_PROPERTY_X86_FEATURE_1_SHSTK): New.

ld/

	* NEWS: Mention -z shstk and GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	* emulparams/cet.sh (PARSE_AND_LIST_OPTIONS_CET): Add "-z shstk".
	(PARSE_AND_LIST_ARGS_CASE_Z_CET): Support "-z shstk".
	* ld.texinfo: Document -z shstk.
	* testsuite/ld-i386/i386.exp: Run SHSTK tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/property-x86-shstk.s: New file.
	* testsuite/ld-i386/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk2.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk4.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk.s: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5.d: Likewise.
2017-06-22 05:50:31 -07:00
H.J. Lu ee2fdd6f36 x86: Support Intel IBT with IBT property and IBT-enable PLT
To support IBT in Intel Control-flow Enforcement Technology (CET)
instructions:

https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf

 #define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002

 #define GNU_PROPERTY_X86_FEATURE_1_IBT (1U << 0)

are added to GNU program properties to indicate that all executable
sections are compatible with IBT when ENDBR instruction starts each
valid target where an indirect branch instruction can land.

GNU_PROPERTY_X86_FEATURE_1_IBT is set on output only if it is set on
all relocatable inputs.

The followings changes are made to the Procedure Linkage Table (PLT):

1. For 64-bit x86-64,  PLT is changed to

PLT0:  push       GOT[1]
       bnd jmp    *GOT[2]
       nop
...
PLTn:  endbr64
       push       namen_reloc_index
       bnd jmp    PLT0

together with the second PLT section:

PLTn:  endbr64
       bnd jmp   *GOT[namen_index]
       nop

BND prefix is also added so that IBT-enabled PLT is compatible with MPX.

2. For 32-bit x86-64 (x32) and i386,  PLT is changed to

PLT0:  push       GOT[1]
       jmp        *GOT[2]
       nop
...
PLTn:  endbr64                                 # endbr32 for i386.
       push       namen_reloc_index
       jmp        PLT0

together with the second PLT section:

PLTn:  endbr64                                 # endbr32 for i386.
       jmp       *GOT[namen_index]
       nop

BND prefix isn't used since MPX isn't supported on x32 and BND registers
aren't used in parameter passing on i386.

GOT is an array of addresses.  Initially, GOT[namen_index] is filled
with the address of the ENDBR instruction of the corresponding entry
in the first PLT section.  The function, namen, is called via the
ENDBR instruction in the second PLT entry.  GOT[namen_index] is updated
to the actual address of the function, namen, at run-time.

2 linker command line options are added:

1. -z ibtplt: Generate IBT-enabled PLT.
2. -z ibt: Generate GNU_PROPERTY_X86_FEATURE_1_IBT in GNU program
properties as well as IBT-enabled PLT.

bfd/

	* elf32-i386.c (elf_i386_lazy_ibt_plt0_entry): New.
	(elf_i386_lazy_ibt_plt_entry): Likewise.
	(elf_i386_pic_lazy_ibt_plt0_entry): Likewise.
	(elf_i386_non_lazy_ibt_plt_entry): Likewise.
	(elf_i386_pic_non_lazy_ibt_plt_entry): Likewise.
	(elf_i386_eh_frame_lazy_ibt_plt): Likewise.
	(elf_i386_lazy_plt_layout): Likewise.
	(elf_i386_non_lazy_plt_layout): Likewise.
	(elf_i386_link_hash_entry): Add plt_second.
	(elf_i386_link_hash_table): Add plt_second and
	plt_second_eh_frame.
	(elf_i386_allocate_dynrelocs): Use the second PLT if needed.
	(elf_i386_size_dynamic_sections): Use .plt.got unwind info for
	the second PLT.  Check the second PLT.
	(elf_i386_relocate_section): Use the second PLT to resolve
	PLT reference if needed.
	(elf_i386_finish_dynamic_symbol): Fill and use the second PLT if
	needed.
	(elf_i386_finish_dynamic_sections): Set sh_entsize on the
	second PLT.  Generate unwind info for the second PLT.
	(elf_i386_plt_type): Add plt_second.
	(elf_i386_get_synthetic_symtab): Support the second PLT.
	(elf_i386_parse_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.
	(elf_i386_merge_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.  If info->ibt is set, turn
	on GNU_PROPERTY_X86_FEATURE_1_IBT
	(elf_i386_link_setup_gnu_properties): If info->ibt is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.  Use IBT-enabled PLT
	for info->ibtplt, info->ibt or GNU_PROPERTY_X86_FEATURE_1_IBT
	is set on all relocatable inputs.
	* elf64-x86-64.c (elf_x86_64_lazy_ibt_plt_entry): New.
	(elf_x32_lazy_ibt_plt_entry): Likewise.
	(elf_x86_64_non_lazy_ibt_plt_entry): Likewise.
	(elf_x32_non_lazy_ibt_plt_entry): Likewise.
	(elf_x86_64_eh_frame_lazy_ibt_plt): Likewise.
	(elf_x32_eh_frame_lazy_ibt_plt): Likewise.
	(elf_x86_64_lazy_ibt_plt): Likewise.
	(elf_x32_lazy_ibt_plt): Likewise.
	(elf_x86_64_non_lazy_ibt_plt): Likewise.
	(elf_x32_non_lazy_ibt_plt): Likewise.
	(elf_x86_64_get_synthetic_symtab): Support the second PLT.
	(elf_x86_64_parse_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.
	(elf_x86_64_merge_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.  If info->ibt is set, turn
	on GNU_PROPERTY_X86_FEATURE_1_IBT
	(elf_x86_64_link_setup_gnu_properties): If info->ibt is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.  Use IBT-enabled PLT
	for info->ibtplt, info->ibt or GNU_PROPERTY_X86_FEATURE_1_IBT
	is set on all relocatable inputs.

binutils/

	* readelf.c (decode_x86_feature): New.
	(print_gnu_property_note): Call decode_x86_feature on
	GNU_PROPERTY_X86_FEATURE_1_AND.
	* testsuite/binutils-all/i386/empty.d: New file.
	* testsuite/binutils-all/i386/empty.s: Likewise.
	* testsuite/binutils-all/i386/ibt.d: Likewise.
	* testsuite/binutils-all/i386/ibt.s: Likewise.
	* testsuite/binutils-all/x86-64/empty-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/empty.d: Likewise.
	* testsuite/binutils-all/x86-64/empty.s: Likewise.
	* testsuite/binutils-all/x86-64/ibt-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt.s: Likewise.

include/

	* bfdlink.h (bfd_link_info): Add ibtplt and ibt.
	* elf/common.h (GNU_PROPERTY_X86_FEATURE_1_AND): New.
	(GNU_PROPERTY_X86_FEATURE_1_IBT): Likewise.

ld/

	* Makefile.am (ELF_X86_DEPS): Add $(srcdir)/emulparams/cet.sh.
	* Makefile.in: Regenerated.
	* NEWS: Mention GNU_PROPERTY_X86_FEATURE_1_IBT, -z ibtplt
	and -z ibt.
	* emulparams/cet.sh: New file.
	* testsuite/ld-i386/ibt-plt-1.d: Likewise.
	* testsuite/ld-i386/ibt-plt-1.s: Likewise.
	* testsuite/ld-i386/ibt-plt-2.s: Likewise.
	* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2d.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3.s: Likewise.
	* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3d.d: Likewise.
	* testsuite/ld-i386/plt-main-ibt.dd: Likewise.
	* testsuite/ld-i386/plt-pie-ibt.dd: Likewise.
	* testsuite/ld-i386/property-x86-empty.s: Likewise.
	* testsuite/ld-i386/property-x86-ibt.s: Likewise.
	* testsuite/ld-i386/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt2.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt4.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt5.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.s: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2.s: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2b-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2d-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2d.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3.s: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3b-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3d-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3d.d: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt-now.rd: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt-x32.dd: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt.dd: Likewise.
	* testsuite/ld-x86-64/property-x86-empty.s: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt.s: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5.d: Likewise.
	* emulparams/elf32_x86_64.sh: Source emulparams/cet.sh.
	(TINY_READONLY_SECTION): Add .plt.sec.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_x86_64.sh: Source emulparams/cet.sh.
	* ld.texinfo: Document -z ibtplt and -z ibt.
	* testsuite/ld-i386/i386.exp: Run IBT and IBT PLT tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-x86-64/pr21481b.S (check): Updated for x32.
2017-06-22 05:44:53 -07:00
H.J. Lu 6b73737088 Pass $NOPIE_CFLAGS and $NOPIE_LDFLAGS to some ELF tests
Some ELF tests will fail when PIE is used.

	PR ld/21090
	* testsuite/ld-elf/shared.exp: Pass $NOPIE_CFLAGS and
	$NOPIE_LDFLAGS if non-PIE is required.
2017-06-21 15:22:05 -07:00
H.J. Lu e5c89b096d Pass $NOPIE_CFLAGS to NOCROSSREFS tests
PR ld/21090
	* testsuite/ld-scripts/crossref.exp: Also pass $NOPIE_CFLAGS
	to CC.
2017-06-21 14:57:53 -07:00
H.J. Lu 127d08c03f Add missing ChangeLog entries 2017-06-21 14:49:30 -07:00
H.J. Lu 68193357e8 Pass $NOPIE_LDFLAGS size tests
PR ld/21090
	* testsuite/ld-size/size.exp: Pass $NOPIE_LDFLAGS to size-4a,
	size-4b, size-5a, size-5b, size-6 and size-8 tests.
2017-06-21 14:45:57 -07:00
Alan Modra 81209eff90 PowerPC64 tocsave testcases
* testsuite/ld-powerpc/powerpc.exp: Run TOCSAVE tests.
	* testsuite/ld-powerpc/tocsave1.s,
	* testsuite/ld-powerpc/tocsave1a.d,
	* testsuite/ld-powerpc/tocsave1s.d,
	* testsuite/ld-powerpc/tocsave2.s,
	* testsuite/ld-powerpc/tocsave2a.d,
	* testsuite/ld-powerpc/tocsave2s.d,
	* testsuite/ld-powerpc/tocsavelib.s: New files.
2017-06-21 22:45:15 +09:30
H.J. Lu abfa390dac Check the DYNAMIC bit for input shared objects
Since the BFD section count may not be cleared for shared objects during
linking, we should check the DYNAMIC bit for input shared objects.

bfd/

	PR ld/21626
	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Check
	the DYNAMIC bit instead of bfd_count_sections.

ld/

	PR ld/21626
	* testsuite/ld-i386/i386.exp: Run ld/21626 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2017-06-19 20:30:20 -07:00
Alan Modra bdd32e03c5 is_underscore_target for ld-elf tests
and correct targ_underscore in config.bfd

bfd/
	* config.bfd: Correct targ_underscore for epiphany, ip2k,
	m32c, mn10200, pru, rl78, rx, crisv32 and v850.
ld/
	* testsuite/lib/ld-lib.exp (is_underscore_target): New.
	* testsuite/ld-elf/elf.exp (ASFLAGS): Define UNDERSCORE.
	* testsuite/ld-elf/pr21562a.s: If UNDERSCORE defined,
	reference sym with prefix.
	* testsuite/ld-elf/pr21562b.s: Likewise.
	* testsuite/ld-elf/sizeof.s: Likewise.
	* testsuite/ld-elf/startof.s: Likewise.
	* testsuite/ld-elf/pr14156a.d: Adjust for extra symbols.
	* testsuite/ld-elf/pr21562a.d: Remove underscore target from
	xfails, and match prefixed symbol.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/sizeofa.d: Likewise.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/sizeofc.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
	* testsuite/ld-elf/startofc.d: Likewise.
2017-06-18 11:56:19 +09:30
Alan Modra 7dba9362c1 Rewrite __start and __stop symbol handling
This arranges for __start and __stop symbols to be defined before
garbage collection, for all target formats.  That should allow the
COFF and PE --gc-sections to keep a singleton orphan input section,
a feature lost by 2017-06-13 commit cbd0eecf26.  The fancier ELF
treatment of keeping all input sections associated with a __start or
__stop symbol, from 2015-10-23 commit 1cce69b9dc, is retained.

.startof. and .sizeof. symbols are deliberately not defined before
garbage collection, so these won't affect garbage collection of
sections.

The patch also ensures __start, __stop, .startof. and .sizeof. symbols
are defined before target size_dynamic_sections is called, albeit
with a preliminary value, so that target code doesn't need to cope
with a symbol changing from undefined at size_dynamic_sections to
defined at relocate_section.

Also, a number of problems with the testcases have been fixed.

	PR ld/20022
	PR ld/21557
	PR ld/21562
	PR ld/21571
include/
	* bfdlink.h (struct bfd_link_hash_entry): Delete undef.section.
bfd/
	* targets.c (struct bfd_target): Add _bfd_define_start_stop.
	(BFD_JUMP_TABLE_LINK): Likewise.
	* elf-bfd.h (bfd_elf_define_start_stop): Declare.
	* elflink.c (_bfd_elf_gc_mark_rsec): Update comment.
	(bfd_elf_define_start_stop): New function.
	* linker.c (bfd_generic_define_start_stop): New function.
	* coff64-rs6000.c (rs6000_xcoff64_vec, rs6000_xcoff64_aix_vec): Init
	new field.
	* aout-adobe.c (aout_32_bfd_define_start_stop): Define.
	* aout-target.h (MY_bfd_define_start_stop): Define.
	* aout-tic30.c (MY_bfd_define_start_stop): Define.
	* binary.c (binary_bfd_define_start_stop): Define.
	* bout.c (b_out_bfd_define_start_stop): Define.
	* coff-alpha.c (_bfd_ecoff_bfd_define_start_stop): Define.
	* coff-mips.c (_bfd_ecoff_bfd_define_start_stop): Define.
	* coff-rs6000.c (_bfd_xcoff_bfd_define_start_stop): Define.
	* coffcode.h (coff_bfd_define_start_stop): Define.
	* elfxx-target.h (bfd_elfNN_bfd_define_start_stop): Define.
	* i386msdos.c (msdos_bfd_define_start_stop): Define.
	* i386os9k.c (os9k_bfd_define_start_stop): Define.
	* ieee.c (ieee_bfd_define_start_stop): Define.
	* ihex.c (ihex_bfd_define_start_stop): Define.
	* libbfd-in.h (_bfd_nolink_bfd_define_start_stop): Define.
	* mach-o-target.c (bfd_mach_o_bfd_define_start_stop): Define.
	* mmo.c (mmo_bfd_define_start_stop): Define.
	* nlm-target.h (nlm_bfd_define_start_stop): Define.
	* oasys.c (oasys_bfd_define_start_stop): Define.
	* pef.c (bfd_pef_bfd_define_start_stop): Define.
	* plugin.c (bfd_plugin_bfd_define_start_stop): Define.
	* ppcboot.c (ppcboot_bfd_define_start_stop): Define.
	* som.c (som_bfd_define_start_stop): Define.
	* srec.c (srec_bfd_define_start_stop): Define.
	* tekhex.c (tekhex_bfd_define_start_stop): Define.
	* versados.c (versados_bfd_define_start_stop): Define.
	* vms-alpha.c (vms_bfd_define_start_stop): Define.
	(alpha_vms_bfd_define_start_stop): Define.
	* xsym.c (bfd_sym_bfd_define_start_stop): Define.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Don't set
	__start/__stop syms here.
	* ldlang.c (lang_set_startof): Delete.
	(start_stop_syms, start_stop_count, start_stop_alloc): New vars.
	(lang_define_start_stop, lang_init_start_stop, foreach_start_stop,
	undef_start_stop, lang_undef_start_stop, lang_init_startof_sizeof,
	set_start_stop, lang_finalize_start_stop): New functions.
	(lang_process): Call _start_stop functions.
	* testsuite/ld-elf/pr21562a.d: Use xfail rather than notarget.
	Correct typos and list of xfail targets.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/sizeofa.d: Likewise.  Adjust to pass for generic ELF.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
2017-06-16 23:38:28 +09:30
Jiong Wang d68f19767d [AArch64] Use SYMBOL_REFERENCES_LOCAL in one symbol check
For some pc-relative relocations we want to allow them under PIC mode while
a normal global symbol defined in the same dynamic object can still bind
externally through copy relocation.  So, we should not allow pc-relative
relocation against such symbol.

SYMBOL_REFERENCES_LOCAL should be used and is more accurate than the original
individual checks.

bfd/
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Use
	SYMBOL_REFERENCES_LOCAL.
ld/
	* testsuite/ld-aarch64/aarch64-elf.exp: Update test name
	* testsuite/ld-aarch64/pcrel.s: Add new testcases.
	* testsuite/ld-aarch64/pcrel_pic_undefined.d: Update the expected
	warnings.
	* testsuite/ld-aarch64/pcrel_pic_defined_local.d: Rename ...
	* testsuite/ld-aarch64/pcrel_pic_defined.d: ... to this.
	Update expected warnings.
2017-06-16 14:20:38 +01:00
H.J. Lu 75e06f9753 Correct "ld --help" to display "-z stack-size=SIZE"
ELF Linker command line option to set stack size is "-z stack-size=SIZE",
not "-z stacksize=SIZE".

	* exsup.c (elf_shlib_list_options): Display "-z stack-size=SIZE"
	instead of "-z stacksize=SIZE".
2017-06-15 12:30:53 -07:00
Jiong Wang 6353d82b8f [AArch64] Allow COPY relocation elimination
As discussed at the PR, this patch tries to avoid COPY relocation generation
and propagate the original relocation into runtime if it was relocating on
writable section.  The ELIMINATE_COPY_RELOCS has been set to true and it's
underlying infrastructure has been improved so that the COPY reloc elimination
at least working on absoluate relocations (ABS64) on AArch64.

  BFD linker copy relocation elimination framwork requires the backend to always
allocate dynrelocs for all those relocation types that are possible to introduce
copy relocations.  This is for adjust_dynamic_symbol hook to be able to get all
symbol reference information.  Should one symbol is referenced by more than one
relocations, if there is any of them needs copy relocation then linker should
generate it.

bfd/
	PR ld/21532
	* elfnn-aarch64.c (ELIMINATE_COPY_RELOCS): Set to 1.
	(elfNN_aarch64_final_link_relocate): Also propagate relocations to
	runtime for if there needs copy relocation elimination.
	(need_copy_relocation_p): New function.  Return true for symbol with
	pc-relative references and if it's against read-only sections.
	(elfNN_aarch64_adjust_dynamic_symbol): Use need_copy_relocation_p.
	(elfNN_aarch64_check_relocs): Allocate dynrelocs for relocation types
	that are related with accessing external objects.
	(elfNN_aarch64_gc_sweep_hook): Sync the relocation types with the change
	in elfNN_aarch64_check_relocs.

ld/
	* testsuite/ld-aarch64/copy-reloc-exe-2.s: New test source file.
	* testsuite/ld-aarch64/copy-reloc-2.d: New test.
	* testsuite/ld-aarch64/copy-reloc-exe-eliminate.s: New test source file.
	* testsuite/ld-aarch64/copy-reloc-eliminate.d: New test.
	* testsuite/ld-aarch64/copy-reloc-so.s: Define new global objects.
	* testsuite/ld-aarch64/aarch64-elf.exp: Run new tests.
2017-06-15 17:04:04 +01:00
Nick Clifton ae87f7e73e Fix address violation when disassembling a corrupt binary.
PR binutils/21580
binutils * objdump.c (disassemble_bytes): Check for buffer overrun when
	printing out rae insns.

ld	* testsuite/ld-nds32/diff.d: Adjust expected output.
2017-06-14 16:50:03 +01:00
H.J. Lu 99031bafd6 xfail pr20022.d on targets without dynamic relocs in .text
ld-gc/pr20022.d requires support for dynamic relocations in .text
section.

	PR ld/20022
	* testsuite/ld-gc/pr20022.d: Skip on targets without dynamic
	relocations in .text section.
2017-06-14 06:12:00 -07:00
H.J. Lu 8eca1095d9 Skip PR ld/21562 tests on targets with leading char or without --gc-sections
Symbol lookup in linker will always fail on targets with leading char
in symbol name since __start_SECNAME and __stop_SECNAME in C may be
___start_SECNAME and ___stop_SECNAME in assembly.  Also tests with
--gc-sections always fails on targets without --gc-sections support.

	* testsuite/ld-elf/pr21562a.d: Skip on targets with leading char
	in in symbol name or without --gc-sections.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Skip on targets with leading char
	in symbol name.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
2017-06-14 06:07:20 -07:00
H.J. Lu f78d1b3ae1 Add size to bar in ld-gc/pr20022a.s
Some linker backends require size info on dynamic symbols.

	* testsuite/ld-gc/pr20022a.s: Add size to bar.
2017-06-14 05:52:12 -07:00
H.J. Lu b6947a7f08 Skip sizeof/startof tests on targets with leading char
Symbol lookup in linker will always fail on targets with leading char
in symbol name since __start_SECNAME and __stop_SECNAME in C may be
___start_SECNAME and ___stop_SECNAME in assembly.

	* testsuite/ld-elf/sizeofa.d: Skip on targets with leading char
	in symbol name.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
2017-06-14 05:49:24 -07:00
Georg-Johann Lay 4c0b797e0d Move location of .jumptables section and add .hightext section to AVR linker script.
PR ld/21583
	* scripttempl/avr.sc (.jumptables): Move down in text section.
	(.hightext): New in text.
2017-06-14 12:23:39 +01:00
Sebastian Huber 319c2dbe24 Accept more epiphany targets
In particular this adds support for the epiphany-rtems target.

bfd/
	* config.bfd (epiphany-*-elf): Accept epiphany-*-*.

ld/
	* configure.tgt (epiphany-*-elf): Accept epiphany-*-*.
2017-06-14 06:59:37 +02:00
H.J. Lu b27685f201 ld: Don't define __start_SECNAME/__stop_SECNAME for -r
__start_SECNAME and __stop_SECNAME shouldn't be defined for "ld -r".

	* ldlang.c (lang_set_startof): Skip if config.build_constructors
	is FALSE.
	* testsuite/ld-elf/sizeofc.d: New file.
	* testsuite/ld-elf/startofc.d: Likewise.
2017-06-13 13:04:56 -07:00
H.J. Lu da614360f5 ld: Add tests for .startof.SECNAME/.sizeof.SECNAME
* testsuite/ld-elf/sizeof.d: Renamed to ...
	* testsuite/ld-elf/sizeofa.d: This.  Updated.
	* testsuite/ld-elf/startof.d: Renamed to ...
	* testsuite/ld-elf/startofa.d: This.  Updated.
	* testsuite/ld-elf/sizeofb.d: New file.
	* testsuite/ld-elf/startofb.d: Likewise.
2017-06-13 12:03:40 -07:00
H.J. Lu cbd0eecf26 Always define referenced __start_SECNAME/__stop_SECNAME
Currently, linker will define __start_SECNAME and __stop_SECNAME symbols
only for orphaned sections.

However, during garbage collection, ELF linker marks all sections with
references to __start_SECNAME and __stop_SECNAME symbols as used even
when section SECNAME isn't an orphaned section and linker won't define
__start_SECNAME nor __stop_SECNAME.  And ELF linker stores the first
input section whose name matches __start_SECNAME or __stop_SECNAME in
u.undef.section for garbage collection.  If these symbols are provided
in linker script, u.undef.section is set to the section where they will
defined by linker script, which leads to the incorrect output.

This patch changes linker to always define referenced __start_SECNAME and
__stop_SECNAME if the input section name is the same as the output section
name, which is always true for orphaned sections, and SECNAME is a C
identifier.  Also __start_SECNAME and __stop_SECNAME symbols are marked
as hidden by ELF linker so that __start_SECNAME and __stop_SECNAME symbols
for section SECNAME in different modules are unique.  For garbage
collection, ELF linker stores the first matched input section in the
unused vtable field.

bfd/

	PR ld/20022
	PR ld/21557
	PR ld/21562
	PR ld/21571
	* elf-bfd.h (elf_link_hash_entry): Add start_stop.  Change the
	vtable field to a union.
	(_bfd_elf_is_start_stop): Removed.
	* elf32-i386.c (elf_i386_convert_load_reloc): Also check for
	__start_SECNAME and __stop_SECNAME symbols.
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise.
	* elflink.c (_bfd_elf_is_start_stop): Removed.
	(_bfd_elf_gc_mark_rsec): Check start_stop instead of calling
	_bfd_elf_is_start_stop.
	(elf_gc_propagate_vtable_entries_used): Skip __start_SECNAME and
	__stop_SECNAME symbols.  Updated.
	(elf_gc_smash_unused_vtentry_relocs): Likewise.
	(bfd_elf_gc_record_vtinherit): Likewise.
	(bfd_elf_gc_record_vtentry): Likewise.

ld/

	PR ld/20022
	PR ld/21557
	PR ld/21562
	PR ld/21571
	* ld.texinfo: Update __start_SECNAME/__stop_SECNAME symbols.
	* ldlang.c (lang_insert_orphan): Move handling of __start_SECNAME
	and __stop_SECNAME symbols to ...
	(lang_set_startof): Here.  Also define __start_SECNAME and
	__stop_SECNAME for -Ur.
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Mark
	referenced __start_SECNAME and __stop_SECNAME symbols as hidden
	and set start_stop for garbage collection.
	* testsuite/ld-elf/pr21562a.d: New file.
	* testsuite/ld-elf/pr21562a.s: Likewise.
	* testsuite/ld-elf/pr21562a.t: Likewise.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562b.s: Likewise.
	* testsuite/ld-elf/pr21562b.t: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562c.t: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562d.t: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-gc/pr20022.d: Likewise.
	* testsuite/ld-gc/pr20022a.s: Likewise.
	* testsuite/ld-gc/pr20022b.s: Likewise.
	* testsuite/ld-gc/gc.exp: Run PR ld/20022 tests.
	* testsuite/ld-gc/pr19161.d: Also accept local __start_SECNAME
	symbol.
	* testsuite/ld-gc/start.d: Likewise.
	* testsuite/ld-x86-64/lea1a.d: Updated.
	* testsuite/ld-x86-64/lea1b.d: Updated.
	* testsuite/ld-x86-64/lea1d.d: Updated.
	* testsuite/ld-x86-64/lea1e.d: Likewise.
2017-06-13 08:53:22 -07:00
Georg-Johann Lay 6490dc678b Replace multiple AVR scripts with a single, customizable linker script.
PR ld/21569
        * scripttempl/avrtiny.sc: Remove file.
	* Makefile.am (eavrtiny.c): Depend on avr.sc, no more on avrtiny.sc.
	* Makefile.in: Regenerate.
	* emulparams/avrtiny.sh (SCRIPT_NAME): Set var to "avr".
	(TEXT_ORIGIN): Remove var.
	(FUSE_NAME, FUSE_LENGTH, LOCK_LENGTH, SIGNATURE_LENGTH)
	(RODATA_PM_OFFSET): Set new vars.
	* emulparams/avr1.sh (FUSE_NAME, EEPROM_LENGTH, FUSE_LENGTH)
	(LOCK_LENGTH, SIGNATURE_LENGTH, USER_SIGNATURE_LENGTH): Set new vars.
	* emulparams/avr2.sh: Same.
	* emulparams/avr25.sh: Same.
	* emulparams/avr3.sh: Same.
	* emulparams/avr31.sh: Same.
	* emulparams/avr35.sh: Same.
	* emulparams/avr4.sh: Same.
	* emulparams/avr5.sh: Same.
	* emulparams/avr51.sh: Same.
	* emulparams/avr6.sh: Same.
	* emulparams/avrxmega1.sh: Same.
	* emulparams/avrxmega2.sh: Same.
	* emulparams/avrxmega3.sh: Same.
	* emulparams/avrxmega4.sh: Same.
	* emulparams/avrxmega5.sh: Same.
	* emulparams/avrxmega6.sh: Same.
	* emulparams/avrxmega7.sh: Same.
	* scripttempl/avr.sc (__EEPROM_REGION_LENGTH__): Only define
	if EEPROM_LENGTH is set.
	(MEMORY) [eeprom]: Same.
	(SECTIONS) [.eeprom]: Same for output section.
	(__USER_SIGNATURE_REGION_LENGTH__): Only define if
	USER_SIGNATURE_LENGTH is set.
	(MEMORY) [user_signatures]: Same.
	(SECTIONS) [.fuse]: Only define output section if FUSE_NAME = fuse.
	(SECTIONS) [.config]: Only define output section if FUSE_NAME = config.
2017-06-13 16:50:26 +01:00
H.J. Lu dc74becf49 ld: Add tests for -Ur
Test -Ur with __start_SECNAME, __stop_SECNAME, .startof.SECNAME and
.sizeof.SECNAME.  __start_SECNAME and __stop_SECNAME should be defined
to the start and the end of section SECNAME.  .startof.SECNAME and
.sizeof.SECNAME should be undefined.

	* testsuite/ld-elf/sizeof.d: New file.
	* testsuite/ld-elf/sizeof.s: Likewise.
	* testsuite/ld-elf/startof.d: Likewise.
	* testsuite/ld-elf/startof.s: Likewise.
2017-06-13 08:22:10 -07:00
Renlin Li 8569cfa78c [LD][Testsuite] Add --no-dynamic-linker option to dynamic-1 rdynamic-1 test case.
arm-none-eabi-ld supports shared libraries. However, the toolchain may be
configured to generate statically linked executable by default.

It is required to have --no-dynamic-linker option before adding dynamic symbol
to static executable.
For dynamically linked executable, the behavior won't change.

ld/ChangeLog
2017-06-13  Renlin Li  <renlin.li@arm.com>

	* testsuite/ld-elf/shared.exp (build_tests): Add --no-dynamic-linker
	option to rdynamic-1 and dynamic-1 tests.
2017-06-13 14:35:01 +01:00
H.J. Lu 654f3b6a2a x86-64: Add some x32 ELF property tests
* testsuite/ld-x86-64/property-x86-3-x32.d: New file.
	* testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-3.d: Also pass
	-defsym __64_bit__=1 to asssembler.
	* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-3.s: Align to 4 bytes if
	__64_bit__ isn't defined.
	* testsuite/ld-x86-64/property-x86-4a.s: Likewise.
	* testsuite/ld-x86-64/property-x86-4b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run property-x86-3-x32,
	property-x86-4a-x32 and property-x86-4b-x32.
2017-06-09 10:43:43 -07:00
Jiong Wang dbb2bcd005 Revert "[AArch64] Allow COPY relocation elimination"
This reverts commit bc327528fd.

This patch can only be committed after PC-relative relocation types
support on copy relocation elimination is also completed.
2017-06-09 12:04:44 +01:00
Cupertino Miranda a0abe74332 [ARC] Fixed TLS for IE model.
In the case of static relocation, the GOT entries are fixed at link time
and are set by the linker.
In order to compute the right TLS offset it is necessary to add TCB_SIZE
to the offset, just in case the dynamic linker is not expected to be
executed (static linked case).
This problem does appear in dynamic linked applications, as the dynamic
linker is adding this TCB_SIZE by operating the TCB block structure.

Problem revealed in GLIBC with static linking.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	arc-got.h (relocate_fix_got_relocs_for_got_info): Added TCB_SIZE to
	patched section contents for TLS IE reloc.
	elf32-arc.c: Remove TCB_SIZE preprocessor macro.

Rebase to 0006
2017-06-08 19:00:36 +02:00
H.J. Lu 6322e5c5cb x86: Dump local IFUNC functions in the map file
Dump local IFUNC functions in the map file when generating IRELATIVE
relocations if -Map is used.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Set local IFUNC symbol
	name.  Use local IFUNC symbol name string to report unsupported
	non-PIC call to IFUNC function.
	(elf_i386_relocate_section): Dump local IFUNC name with minfo
	when generating R_386_IRELATIVE relocation.
	(elf_i386_finish_dynamic_symbol): Likewise.
	* elf_x86_64_check_relocs (elf_x86_64_check_relocs): Set local
	IFUNC symbol name.
	(elf_x86_64_relocate_section): Dump local IFUNC name with minfo
	when generating R_X86_64_IRELATIVE relocation.
	(elf_x86_64_finish_dynamic_symbol): Likewise.

ld/

	* testsuite/ld-ifunc/ifunc-1-local-x86.d: Pass
	"-Map tmpdir/ifunc-1-local-x86.map" to ld and check
	ifunc-1-local-x86.map.
	* testsuite/ld-ifunc/ifunc-1-x86.d: Pass
	"-Map tmpdir/ifunc-1-x86.map" to ld and check ifunc-1-x86.map.
	* testsuite/ld-ifunc/ifunc-1-local-x86.map: New file.
	* testsuite/ld-ifunc/ifunc-1-x86.map: Likewise.
2017-06-08 03:53:43 -07:00
H.J. Lu 51fa2693ad cl 2017-06-08 03:53:43 -07:00
Jiong Wang bc327528fd [AArch64] Allow COPY relocation elimination
As discussed at the PR, this patch tries to avoid COPY relocation generation
and propagate the original relocation into runtime if it was relocating on
writable section.  The ELIMINATE_COPY_RELOCS has been set to true and it's
underlying infrastructure has been improved so that the COPY reloc elimination
at least working on absoluate relocations (ABS64) after this patch.

bfd/
        PR ld/21532
        * elfnn-aarch64.c (ELIMINATE_COPY_RELOCS): Set to 1.
        (elfNN_aarch64_final_link_relocate): Also propagate relocations to
        runtime for copy relocation elimination cases.
        (alias_readonly_dynrelocs): New function.
        (elfNN_aarch64_adjust_dynamic_symbol): Keep the dynamic relocs instead
        of generating copy relocation if it is not against read-only sections.
        (elfNN_aarch64_check_relocs): Likewise.

ld/
        * testsuite/ld-aarch64/copy-reloc-eliminate.d: New test.
        * testsuite/ld-aarch64/copy-reloc-exe-eliminate.s: New test source file.
        * testsuite/ld-aarch64/aarch64-elf.exp: Run new testcase.
2017-06-08 09:43:39 +01:00
Alan Modra 4936f23592 Fix a number of pr21529 testcase failures
Various targets fail this testcase due to ld not supporting binary output.

	* testsuite/ld-unique/pr21529.d: xfail aarch64, arm, hppa, ia64,
	nds32, and score.  Match any output.
2017-06-07 17:56:46 +09:30
Andrew Burgess 670b1a1335 ld: Fix spelling mistake in comment.
ld/ChangeLog:

	* ld.h (struct args_type): Fix typo in comment.
2017-06-06 10:15:27 +01:00
Andrew Burgess 7bdf4127c3 ld: Allow section groups to be resolved as part of a relocatable link
This commit adds a new linker feature: the ability to resolve section
groups as part of a relocatable link.

Currently section groups are automatically resolved when performing a
final link, and are carried through when performing a relocatable link.
By carried through this means that one copy of each section group (from
all the copies that might be found in all the input files) is placed
into the output file.  Sections that are part of a section group will
not match input section specifiers within a linker script and are
forcibly kept as separate sections.

There is a slight resemblance between section groups and common
section.  Like section groups, common sections are carried through when
performing a relocatable link, and resolved (allocated actual space)
only at final link time.

However, with common sections there is an ability to force the linker to
allocate space for the common sections when performing a relocatable
link, there's currently no such ability for section groups.

This commit adds such a mechanism.  This new facility can be accessed in
two ways, first there's a command line switch --force-group-allocation,
second, there's a new linker script command FORCE_GROUP_ALLOCATION.  If
one of these is used when performing a relocatable link then the linker
will resolve the section groups as though it were performing a final
link, the section group will be deleted, and the members of the group
will be placed like normal input sections.  If there are multiple copies
of the group (from multiple input files) then only one copy of the group
members will be placed, the duplicate copies will be discarded.

Unlike common sections that have the --no-define-common command line
flag, and INHIBIT_COMMON_ALLOCATION linker script command there is no
way to prevent group resolution during a final link, this is because the
ELF gABI specifically prohibits the presence of SHT_GROUP sections in a
fully linked executable.  However, the code as written should make
adding such a feature trivial, setting the new resolve_section_groups
flag to false during a final link should work as you'd expect.

bfd/ChangeLog:

	* elf.c (_bfd_elf_make_section_from_shdr): Don't initially mark
	SEC_GROUP sections as SEC_EXCLUDE.
	(bfd_elf_set_group_contents): Replace use of abort with an assert.
	(assign_section_numbers): Use resolve_section_groups flag instead
	of relocatable link type.
	(_bfd_elf_init_private_section_data): Use resolve_section_groups
	flag instead of checking the final_link flag for part of the
	checks in here.  Fix white space as a result.
	* elflink.c (elf_link_input_bfd): Use resolve_section_groups flag
	instead of relocatable link type.
	(bfd_elf_final_link): Likewise.

include/ChangeLog:

	* bfdlink.h (struct bfd_link_info): Add new resolve_section_groups
	flag.

ld/ChangeLog:

	* ld.h (struct args_type): Add force_group_allocation field.
	* ldgram.y: Add support for FORCE_GROUP_ALLOCATION.
	* ldlex.h: Likewise.
	* ldlex.l: Likewise.
	* lexsup.c: Likewise.
	* ldlang.c (unique_section_p): Check resolve_section_groups flag
	not the relaxable link flag.
	(lang_add_section): Discard section groups when we're resolving
	groups.  Clear the SEC_LINK_ONCE flag if we're resolving section
	groups.
	* ldmain.c (main): Initialise resolve_section_groups flag in
	link_info based on command line flags.
	* testsuite/ld-elf/group11.d: New file.
	* testsuite/ld-elf/group12.d: New file.
	* testsuite/ld-elf/group12.ld: New file.
	* NEWS: Mention new features.
	* ld.texinfo (Options): Document --force-group-allocation.
	(Miscellaneous Commands): Document FORCE_GROUP_ALLOCATION.
2017-06-06 09:53:38 +01:00
H.J. Lu d940949881 Add a testcase for PR ld/21529
PR ld/21529
	* testsuite/ld-unique/pr21529.d: New file.
	* testsuite/ld-unique/pr21529.s: Likewise.
	* testsuite/ld-unique/unique.exp: Run *.d.
2017-06-05 14:54:12 -07:00
Alan Modra 91001320a2 Fix --enable-new-dtags config support
and testsuite when configured with --enable-new-dtags.

	* ldmain.c (main): Correct setting of link_indo.new_dtags.
	* testsuite/ld-elf/now-3.d: Pass --disable-new-dtags to ld
	* testsuite/ld-elf/now-4.d: Likewise.
	* testsuite/ld-elf/rpath-1.d: Likewise.
	* testsuite/ld-elf/rpath-2.d: Likewise.
2017-06-05 14:58:12 +09:30
Slava Barinov 6734f10ae9 Introduce --enable-new-dtags configure option.
This option switches on ld.bfd --enable-new-dtags by default.

	* configure.ac: Add --enable-new-dtags option.
	* ldmain.c: Set link_info.new_dtags to 1 if when --enable-new-dtags is
	switched on.
	* configure: Regenerate.
	* config.in: Regenerate.
2017-06-05 09:58:05 +09:30
H.J. Lu 4a4a4a27ba x86: Remove linker option: -z prefix-nop
Since it is incorrect to convert

	bnd call *foo@GOTPCREL(%rip)

to

	bnd nop
	call foo

this patch removes the "-z prefix-nop" option from x86 linker.

	* emulparams/call_nop.sh: Remove -z prefix-nop.
	* ld.texinfo: Likewise.
	* testsuite/ld-i386/call3c.d: Check for linker error.
	* testsuite/ld-x86-64/call1c.d: Likewise.
2017-06-02 14:49:37 -07:00
Alan Modra f378ab099d PPC64_OPT_LOCALENTRY
ELFv2 functions with localentry:0 are those with a single entry point,
ie. global entry == local entry, and that have no requirement on r2 or
r12, and guarantee r2 is unchanged on return.  Such an external
function can be called via the PLT without saving r2 or restoring it
on return, avoiding a common load-hit-store for small functions.   The
optimization is attractive.  The TOC pointer load-hit-store is a major
reason why calls to small functions that need no register saves, or
with shrink-wrap, no register saves on a fast path, are slow on
powerpc64le.

To be safe, this optimization needs ld.so support to check that the
run-time matches link-time function implementation.  If a function
in a shared library with st_other localentry non-zero is called
without saving and restoring r2, r2 will be trashed on return, leading
to segfaults.  For that reason the optimization does not happen for
weak functions since a weak definition is a fairly solid hint that the
function will likely be overridden.  I'm also not enabling the
optimization by default unless glibc-2.26 is detected, which should
have the ld.so checks implemented.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add has_plt_localentry0.
	(ppc64_elf_merge_symbol_attribute): Merge localentry bits from
	dynamic objects.
	(is_elfv2_localentry0): New function.
	(ppc64_elf_tls_setup): Default params->plt_localentry0.
	(plt_stub_size): Adjust size for tls_get_addr_opt stub.
	(build_tls_get_addr_stub): Use a simpler stub when r2 is not saved.
	(ppc64_elf_size_stubs): Leave stub_type as ppc_stub_plt_call for
	optimized localentry:0 stubs.
	(ppc64_elf_build_stubs): Save r2 in ELFv2 __glink_PLTresolve.
	(ppc64_elf_relocate_section): Leave nop unchanged for optimized
	localentry:0 stubs.
	(ppc64_elf_finish_dynamic_sections): Set PPC64_OPT_LOCALENTRY in
	DT_PPC64_OPT.
	* elf64-ppc.h (struct ppc64_elf_params): Add plt_localentry0.
include/
	* elf/ppc64.h (PPC64_OPT_LOCALENTRY): Define.
ld/
	* emultempl/ppc64elf.em (params): Init plt_localentry0 field.
	(enum ppc64_opt): New, replacing OPTION_* defines.  Add
	OPTION_PLT_LOCALENTRY, and OPTION_NO_PLT_LOCALENTRY.
	(PARSE_AND_LIST_*): Support --plt-localentry and --no-plt-localentry.
	* testsuite/ld-powerpc/elfv2so.d: Update.
	* testsuite/ld-powerpc/powerpc.exp (TLS opt 5): Use --no-plt-localentry.
	* testsuite/ld-powerpc/tlsopt5.d: Update.
2017-06-01 22:47:32 +09:30
Alan Modra ab12fca390 PowerPC64 ld help quoting
* emultempl/ppc64elf.em (plt-static-chain help): Fix quoting.
2017-05-31 22:49:21 +09:30