Commit Graph

5762 Commits

Author SHA1 Message Date
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
Jiong Wang 9a6465c207 [AArch64, ld] Support ILP32 triplet aarch64*-linux-gnu_ilp32
This patch allows AArch64 LD defaulting to ILP32 if it is configured with
aarch64*-linux-gnu_ilp32.

ld/
	* configure.tgt: Set "targ_emul" to "aarch64linux32b" for
	aarch64_be-*-linux-gnu_ilp32.  Set "targ_emul" to "aarch64linux32" for
	aarch64-*-linux-gnu_ilp32.
2017-05-22 13:27:56 +01:00
H.J. Lu 92f7d783c1 x86: Add GC testcases with property sections
Verify that debug section is removed by garbage collection when there
is a .note.gnu.property section.

	* testsuite/ld-i386/i386.exp: Run property-x86-4a and
	property-x86-4b.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/property-x86-4a.d: New file.
	* testsuite/ld-i386/property-x86-4a.s: Likewise.
	* testsuite/ld-i386/property-x86-4b.d: Likewise.
	* testsuite/ld-i386/property-x86-4b.s: Likewise.
	* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4a.s: Likewise.
	* testsuite/ld-x86-64/property-x86-4b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4b.s: Likewise.
2017-05-19 08:45:24 -07:00
eorg-Johann Lay f4203b2b88 Update avrxmega3 linker emulation to support avrxmega2 devices with flash memory visible in the SRAM address range.
PR ld/21472
ld  * emulparams/avrxmega3.sh (RODATA_PM_OFFSET): Set to 0x8000.
    * scripttempl/avr.sc
    (__RODATA_PM_OFFSET__) [RODATA_PM_OFFSET]: Use RODATA_PM_OFFSET
    as default if not already defined.
    (.data) [!RODATA_PM_OFFSET]: Don't include .rodata and friends.
    (.rodata) [RODATA_PM_OFFSET]: Put at an offset of
    __RODATA_PM_OFFSET__.

gas * config/tc-avr.c (mcu_types): Add entries for: attiny416,
     attiny417, attiny816, attiny817.
2017-05-19 15:06:33 +01:00
Nick Clifton 3aa2d05a72 Treat a prefix of "$SYSROOT" in the same way as "=" when parsing linker search paths.
PR ld/21251
	* ldfile.c (ldfile_add_library_path): If the path starts with
	$SYSROOT then use the sysroot as the real prefix.
	* ldlang.c (lang_add_input_file): Treat $SYSROOT in the same
	way as =.
	* ldlex.l: Add $SYSROOT as allow prefix for a filename.
	* ld.texinfo (-L): Document that $SYSROOT acts like = when
	prefixing a library search path.
	(INPUT): Likewise.
	* testsuite/ld-scripts/sysroot-prefix.exp: Add $SYSROOT prefix
	tests.
2017-05-18 15:07:59 +01:00
Alan Modra 9d43118ee5 fix changelog typo 2017-05-18 16:52:16 +09:30
Alan Modra 535b785fb0 Don't compare boolean values against TRUE or FALSE
bfd/
	* arc-got.h: Don't compare boolean values against TRUE or FALSE.
	* elf-m10300.c: Likewise.
	* elf.c: Likewise.
	* elf32-arc.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-riscv.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* mach-o.c: Likewise.
	* peXXigen.c: Likewise.
	* vms-alpha.c: Likewise.
	* vms-lib.c: Likewise.
opcodes/
	* aarch64-asm.c: Don't compare boolean values against TRUE or FALSE.
	* aarch64-dis.c: Likewise.
	* aarch64-gen.c: Likewise.
	* aarch64-opc.c: Likewise.
binutils/
	* strings.c: Don't compare boolean values against TRUE or FALSE.
gas/
	* config/tc-aarch64.c: Don't compare booleans against TRUE or FALSE.
	* config/tc-hppa.c: Likewise.
	* config/tc-mips.c: Likewise.
	* config/tc-score7.c: Likewise.
ld/
	* emultempl/elf32.em: Don't compare boolean values against TRUE or FALSE.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
2017-05-18 14:59:33 +09:30
Alan Modra 087ea22225 pr20882 testcase
-gdwarf-sections doesn't work on targets that lack support to emit
address size relative relocs.  The testcase as it was avoided
-gdwarf-sections doing anything by providing a non-empty .debug_line.
It's better to not use -gdwarf-sections.  Also, the testcase failed
to match the output for 16-bit address targets like avr.

	PR ld/20882
	* testsuite/ld-gc/pr20882.d: Don't pass -gdwarf-sections to gas.
	Allow for 16-bit address targets and match expected data fully.
	* testsuite/ld-gc/pr20882a.s: Delete .debug_line section.
	* testsuite/ld-gc/pr20882b.s: Likewise.
	* testsuite/ld-gc/pr20882c.s: Likewise.
2017-05-18 14:28:17 +09:30
H.J. Lu b7c871edcd Mark debug sections referenced by kept debug sections
If a debug section is referenced by a kept debug section, it should
also be kept.

Some targets, like mips, keep input files when there are some special
sections, like .gnu.attributes, even if input file is unused otherwise.
In this case, all debug sections are kept.  The new test will fail on
such targets.  We can either fix those targets or XFAIL the test.

bfd/

	PR ld/20882
	* elflink.c (elf_gc_mark_debug_section): New function.
	(_bfd_elf_gc_mark_extra_sections): Mark any debug sections
	referenced by kept debug sections.

ld/

	PR ld/20882
	* testsuite/ld-gc/gc.exp: Run pr20882.
	* testsuite/ld-gc/pr20882.d: New file.
	* testsuite/ld-gc/pr20882a.s: Likewise.
	* testsuite/ld-gc/pr20882b.s: Likewise.
	* testsuite/ld-gc/pr20882c.s: Likewise.
2017-05-17 07:57:26 -07:00
H.J. Lu 854062337d Fix commit 0a7d38897b 2017-05-16 09:09:20 -07:00
H.J. Lu 0a7d38897b Run PR ld/21481 tests only if IFUNC is supported
PR ld/21481
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/21481 tests only
	if IFUNC is supported by run-time.
2017-05-16 08:52:01 -07:00
Alan Modra bc4e12ded1 Rename non_ir_ref to non_ir_ref_regular
Since the flag is now set only for regular object refs.

include/
	* bfdlink.h (struct bfd_link_hash_entry <non_ir_ref>): Rename to
	non_ir_ref_regular.
bfd/
	* elf-m10300.c: Rename occurrences of non_ir_ref.
	* elf32-arm.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-dlx.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mcore.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-xstormy16.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-mmix.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-sh64.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfnn-riscv.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* linker.c: Likewise.
ld/
	* plugin.c: Rename occurrences of non_ir_ref.
2017-05-16 10:35:02 +09:30
Alan Modra 4070765b1a non_ir_ref_dynamic
dynamic_ref_after_ir_def is a little odd compared to other symbol
flags in that as the name suggests, it is set only for certain
references after a definition.  It turns out that setting a flag for
any non-ir reference from a dynamic object can be used to solve the
problem for which this flag was invented, which I think is a cleaner.
This patch does that, and sets non_ir_ref only for regular object
references.

include/
	* bfdlink.h (struct bfd_link_hash_entry): Update non_ir_ref
	comment.  Rename dynamic_ref_after_ir_def to non_ir_ref_dynamic.
ld/
	* plugin.c (is_visible_from_outside): Use non_ir_ref_dynamic.
	(plugin_notice): Set non_ir_ref for references from regular
	objects, non_ir_ref_dynamic for references from dynamic objects.
bfd/
	* elf64-ppc.c (add_symbol_adjust): Transfer non_ir_ref_dynamic.
	* elflink.c (elf_link_add_object_symbols): Update to use
	non_ir_ref_dynamic.
	(elf_link_input_bfd): Test non_ir_ref_dynamic in addition to
	non_ir_ref.
	* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
2017-05-16 10:35:02 +09:30
Maciej W. Rozycki b32465c97c MIPS16e2: Add new MIPS16e2 relaxation GAS and LD tests
Verify MIPS16 PC-relative instruction relaxation using the MIPS16e2 LUI
instruction rather than an LI/SLL instruction pair.

	gas/
	* testsuite/gas/mips/mips16-pcrel-1.d: Remove `-mips3' from `as'
	flags.
	* testsuite/gas/mips/mips16-pcrel-pic-1.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-n32-0.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-n32-1.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-n64-0.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-n64-1.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-n64-sym32-0.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-n64-sym32-1.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-reloc-4.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-reloc-5.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-reloc-6.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-reloc-7.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-4.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-5.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-6.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-7.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-9.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-pic-9.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-n32-8.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-n32-9.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-sym32-8.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-sym32-9.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-8.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-9.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-2.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-3.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-6.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-7.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-6.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-n32-4.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-n32-6.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-4.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-6.d: Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-sym32-4.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-sym32-6.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n32-4.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n32-6.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-4.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-6.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-sym32-4.d:
	Likewise.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-sym32-6.d:
	Likewise.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-0.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-1.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-2.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-n32-0.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-n32-1.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-n64-sym32-0.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-n64-sym32-1.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-delay-0.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-delay-1.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-reloc-2.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-reloc-3.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-reloc-6.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-reloc-7.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-2.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-3.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-6.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-7.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-8.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-9.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-n32-8.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-n32-9.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-n64-sym32-8.d:
	New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-addend-n64-sym32-9.d:
	New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute.d: New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-1.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-2.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-3.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-4.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-5.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-6.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-7.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-pic-4.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-pic-6.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-n32-4.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-n32-6.d: New
	test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-n64-sym32-4.d:
	New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-n64-sym32-6.d:
	New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-pic-n32-4.d:
	New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-pic-n32-6.d:
	New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-pic-n64-sym32-4.d:
	New test.
	* testsuite/gas/mips/mips16e2@mips16-pcrel-absolute-pic-n64-sym32-6.d:
	New test.
	* testsuite/gas/mips/mips16-pcrel-1.l: Adjust line numbers.
	* testsuite/gas/mips/mips16-pcrel-1.s: Adjust for alignment
	preservation between MIPS16 and MIPS16e2 code.
	* testsuite/gas/mips/mips.exp: Run MIPS16 relaxation tests over
	all MIPS16 architectures.

	ld/
	* testsuite/ld-mips-elf/mips16e2-pcrel-0.d: New test.
	* testsuite/ld-mips-elf/mips16e2-pcrel-1.d: New test.
	* testsuite/ld-mips-elf/mips16e2-pcrel-addend-2.d: New test.
	* testsuite/ld-mips-elf/mips16e2-pcrel-addend-6.d: New test.
	* testsuite/ld-mips-elf/mips16e2-pcrel-n32-0.d: New test.
	* testsuite/ld-mips-elf/mips16e2-pcrel-n32-1.d: New test.
	* testsuite/ld-mips-elf/mips16e2-pcrel-n64-sym32-0.d: New test.
	* testsuite/ld-mips-elf/mips16e2-pcrel-n64-sym32-1.d: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-05-15 14:00:50 +01:00
Nick Clifton 786e3eba79 Add .debug_gdb_scripts section to PE linker scripts.
PR ld/21459
	* scripttempl/pe.sc: Add .debug_gdb_scripts section.
	* scripttempl/pep.sc: Likewise.
2017-05-15 13:12:49 +01:00
H.J. Lu 73caa85d4a x86: Merge X86_ISA_1_USED/X86_ISA_1_NEEDED properties
If there are more than GNU property note in an input, we should merge
X86_ISA_1_USED and X86_ISA_1_NEEDED properties.

bfd/

	* elf32-i386.c (elf_i386_parse_gnu_properties): Merge
	GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED
	properties.
	* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Run property-x86-3.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/property-x86-3.d: New file.
	* testsuite/ld-i386/property-x86-3.s: Likewise.
	* testsuite/ld-x86-64/property-x86-3.d: Likewise.
	* testsuite/ld-x86-64/property-x86-3.s: Likewise.
2017-05-12 08:07:43 -07:00
H.J. Lu f2c29a1692 x86-64: Rename .plt.bnd to .plt.sec
Rename .plt.bnd to .plt.sec to indicate that this is used as the second
PLT section.  There is no change in run-time behavior.  We also scan the
.plt.sec section to synthesize PLT symbols.

bfd/

	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Rename plt_bnd
	to plt_second.
	(elf_x86_64_link_hash_table): Rename plt_bnd/plt_bnd_eh_frame
	to plt_second/plt_second_eh_frame.
	(elf_x86_64_link_hash_newfunc): Updated.
	(elf_x86_64_allocate_dynrelocs): Likewise.
	(elf_x86_64_size_dynamic_sections): Likewise.
	(elf_x86_64_relocate_section): Likewise.
	(elf_x86_64_finish_dynamic_symbol): Likewise.
	(elf_x86_64_finish_dynamic_sections): Likewise.
	(elf_x86_64_plt_type): Rename plt_bnd to plt_second.
	(elf_x86_64_get_synthetic_symtab): Updated.  Also scan the
	.plt.sec section.
	(elf_backend_setup_gnu_properties): Updated.  Create the
	.plt.sec section instead of the .plt.sec section.

ld/

	* emulparams/elf_x86_64.sh (TINY_READONLY_SECTION): Replace
	.plt.bnd with .plt.sec.
	* testsuite/ld-x86-64/bnd-ifunc-1-now.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/mpx3.dd: Likewise.
	* testsuite/ld-x86-64/mpx3n.dd: Likewise.
	* testsuite/ld-x86-64/mpx4.dd: Likewise.
	* testsuite/ld-x86-64/mpx4n.dd: Likewise.
	* testsuite/ld-x86-64/plt-main-bnd-now.rd: 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-05-11 11:28:16 -07:00
H.J. Lu dc2be3d2f6 x86: Generate PLT relocations for -z now
This patch partially reverses:

commit 25070364b0
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat May 16 07:00:21 2015 -0700

    Don't generate PLT relocations for now binding

to support LD_AUDIT and LD_PROFILE with -z now.  If there is an existing
GOT relocation, it is still used to avoid PLT relocation against the same
function symbol.

bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Partially revert
	commit 25070364b0.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewse.

ld/

	* testsuite/ld-i386/plt-pic2.dd: Updated.
	* testsuite/ld-i386/plt2.dd: Likewise.
	* testsuite/ld-i386/plt2.rd: Likewise.
	* testsuite/ld-i386/pr17689now.rd: Likewise.
	* testsuite/ld-ifunc/ifunc-16-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-16-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
	* testsuite/ld-x86-64/plt2.dd: Likewise.
	* testsuite/ld-x86-64/plt2.rd: Likewise.
	* testsuite/ld-x86-64/pr17689now.rd: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
2017-05-11 07:45:59 -07:00
H.J. Lu 5d69120bff i386: Set CHECK_RELOCS_AFTER_OPEN_INPUT to yes
All linker targets based on elf32-i386 should check relocations after
opening all inputs since this is how elf32-i386 works.

	* emulparams/i386lynx.sh (CHECK_RELOCS_AFTER_OPEN_INPUT): Set
	to yes.
	* emulparams/i386moss.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386nw.sh (CHECK_RELOCS_AFTER_OPEN_INPUT): Likewise.
2017-05-10 10:51:35 -07:00
H.J. Lu aab82f4c20 x86-64: Use .plt.bnd for IFUNC function address
When -z bndplt is used, we must use the .plt.bnd entry for IFUNC function
address.

bfd/

	PR ld/21481
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Use .plt.bnd
	for IFUNC function address.

ld/

	PR ld/21481
	* testsuite/ld-x86-64/pr21481a.c: New file.
	* testsuite/ld-x86-64/pr21481b.S: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/21481 tests.
2017-05-10 09:28:28 -07:00
Claudiu Zissulescu 53a346d823 [ARC] Object attributes.
gas/
2017-05-10  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/gas/arc/attr-arc600.d: New file.
	* testsuite/gas/arc/attr-arc600_mul32x16.d: Likewise.
	* testsuite/gas/arc/attr-arc600_norm.d: Likewise.
	* testsuite/gas/arc/attr-arc601.d: Likewise.
	* testsuite/gas/arc/attr-arc601_mul32x16.d: Likewise.
	* testsuite/gas/arc/attr-arc601_mul64.d: Likewise.
	* testsuite/gas/arc/attr-arc601_norm.d: Likewise.
	* testsuite/gas/arc/attr-arc700.d: Likewise.
	* testsuite/gas/arc/attr-arcem.d: Likewise.
	* testsuite/gas/arc/attr-archs.d: Likewise.
	* testsuite/gas/arc/attr-autodetect-1.d: Likewise.
	* testsuite/gas/arc/attr-autodetect-1.s: Likewise.
	* testsuite/gas/arc/attr-cpu-a601.d: Likewise.
	* testsuite/gas/arc/attr-cpu-a601.s: Likewise.
	* testsuite/gas/arc/attr-cpu-a700.d: Likewise.
	* testsuite/gas/arc/attr-cpu-a700.s: Likewise.
	* testsuite/gas/arc/attr-cpu-em.d: Likewise.
	* testsuite/gas/arc/attr-cpu-em.s: Likewise.
	* testsuite/gas/arc/attr-cpu-hs.d: Likewise.
	* testsuite/gas/arc/attr-cpu-hs.s: Likewise.
	* testsuite/gas/arc/attr-em.d: Likewise.
	* testsuite/gas/arc/attr-em4.d: Likewise.
	* testsuite/gas/arc/attr-em4_dmips.d: Likewise.
	* testsuite/gas/arc/attr-em4_fpuda.d: Likewise.
	* testsuite/gas/arc/attr-em4_fpus.d: Likewise.
	* testsuite/gas/arc/attr-hs.d: Likewise.
	* testsuite/gas/arc/attr-hs34.d: Likewise.
	* testsuite/gas/arc/attr-hs38.d: Likewise.
	* testsuite/gas/arc/attr-hs38_linux.d: Likewise.
	* testsuite/gas/arc/attr-mul64.d: Likewise.
	* testsuite/gas/arc/attr-name.d: Likewise.
	* testsuite/gas/arc/attr-name.s: Likewise.
	* testsuite/gas/arc/attr-nps400.d: Likewise.
	* testsuite/gas/arc/attr-override-mcpu.d: Likewise.
	* testsuite/gas/arc/attr-override-mcpu.s
	* testsuite/gas/arc/attr-quarkse_em.d: Likewise.
	* testsuite/gas/arc/blank.s: Likewise.
	* testsuite/gas/elf/section2.e-arc: Likewise.
	* testsuite/gas/arc/cpu-pseudop-1.d: Update test.
	* testsuite/gas/arc/cpu-pseudop-2.d: Likewise.
	* testsuite/gas/arc/nps400-0.d: Likewise.
	* testsuite/gas/elf/elf.exp: Set target_machine for ARC.
	* config/tc-arc.c (opcode/arc-attrs.h): Include.
	(ARC_GET_FLAG, ARC_SET_FLAG, streq): Define.
	(arc_attribute): Declare new function.
	(md_pseudo_table): Add arc_attribute.
	(cpu_types): Rename default cpu features.
	(selected_cpu): Set the default OSABI flag.
	(mpy_option): New variable.
	(pic_option): Likewise.
	(sda_option): Likewise.
	(tls_option): Likewise.
	(feature_type, feature_list): Remove.
	(arc_initial_eflag): Likewise.
	(attributes_set_explicitly): New variable.
	(arc_check_feature): Check also for the conflicting features.
	(arc_select_cpu): Refactor assignment of selected_cpu.eflags.
	(arc_option): Remove setting of private flags and architecture.
	(check_cpu_feature): Refactor feature names.
	(autodetect_attributes): New function.
	(assemble_tokens): Use above function.
	(md_parse_option): Refactor feature names.
	(arc_attribute): New function.
	(arc_set_attribute_int): Likewise.
	(arc_set_attribute_string): Likewise.
	(arc_stralloc): Likewise.
	(arc_set_public_attributes): Likewise.
	(arc_md_end): Likewise.
	(arc_copy_symbol_attributes): Likewise.
	(rc_convert_symbolic_attribute): Likewise.
	* config/tc-arc.h (md_end): Define.
	(CONVERT_SYMBOLIC_ATTRIBUTE): Likewise.
	(TC_COPY_SYMBOL_ATTRIBUTES): Likewise.
	* doc/c-arc.texi: Document ARC object attributes.

binutils/
2017-05-10  Claudiu Zissulescu  <claziss@synopsys.com>

	* readelf.c (decode_ARC_machine_flags): Recognize OSABI v4.
	(get_arc_section_type_name): New function.
	(get_section_type_name): Use the above function.
	(display_arc_attribute): New function.
	(process_arc_specific): Likewise.
	(process_arch_specific): Handle ARC specific information.
	* testsuite/binutils-all/strip-3.d: Consider ARC.attributes
	section.

include/
2017-05-10  Claudiu Zissulescu  <claziss@synopsys.com>

	* elf/arc.h (SHT_ARC_ATTRIBUTES): Define.
	(Tag_ARC_*): Define.
	(E_ARC_OSABI_V4): Define.
	(E_ARC_OSABI_CURRENT): Reassign it.
	(TAG_CPU_*): Define.
	* opcode/arc-attrs.h: New file.
	* opcode/arc.h (insn_subclass_t): Assign enum values.
	(insn_subclass_t): Update enum with QUARKSE1, QUARKSE2, and LL64.
	(ARC_EA, ARC_CD, ARC_LLOCK, ARC_ATOMIC, ARC_MPY, ARC_MULT)
	(ARC_NPS400, ARC_DPFP, ARC_SPFP, ARC_FPU, ARC_FPUDA, ARC_SWAP)
	(ARC_NORM, ARC_BSCAN, ARC_UIX, ARC_TSTAMP, ARC_VBFDW)
	(ARC_BARREL, ARC_DSPA, ARC_SHIFT, ARC_INTR, ARC_DIV, ARC_XMAC)
	(ARC_CRC): Delete.

bfd/
2017-05-10  Claudiu Zissulescu  <claziss@synopsys.com>

	* elf32-arc.c (FEATURE_LIST_NAME): Define.
	(CONFLICT_LIST): Likewise.
	(opcode/arc-attrs.h): Include.
	(arc_elf_print_private_bfd_data): Print OSABI v4 flag.
	(arc_extract_features): New file.
	(arc_stralloc): Likewise.
	(arc_elf_merge_attributes): Likewise.
	(arc_elf_merge_private_bfd_data): Use object attributes.
	(bfd_arc_get_mach_from_attributes): New function.
	(arc_elf_object_p): Use object attributes.
	(arc_elf_final_write_processing): Likewise.
	(elf32_arc_obj_attrs_arg_type): New function.
	(elf32_arc_obj_attrs_handle_unknown): Likewise.
	(elf32_arc_section_from_shdr): Likewise.
	(elf_backend_obj_attrs_vendor): Define.
	(elf_backend_obj_attrs_section): Likewise.
	(elf_backend_obj_attrs_arg_type): Likewise.
	(elf_backend_obj_attrs_section_type): Likewise.
	(elf_backend_obj_attrs_handle_unknown): Likewise.
	(elf_backend_section_from_shdr): Likewise.

ld/
2017-05-10  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/ld-arc/attr-merge-0.d: New file.
	* testsuite/ld-arc/attr-merge-0.s: Likewise.
	* testsuite/ld-arc/attr-merge-0e.s: Likewise.
	* testsuite/ld-arc/attr-merge-1.d: Likewise.
	* testsuite/ld-arc/attr-merge-1.s: Likewise.
	* testsuite/ld-arc/attr-merge-1e.s: Likewise.
	* testsuite/ld-arc/attr-merge-2.d: Likewise.
	* testsuite/ld-arc/attr-merge-2.s: Likewise.
	* testsuite/ld-arc/attr-merge-3.d: Likewise.
	* testsuite/ld-arc/attr-merge-3.s: Likewise.
	* testsuite/ld-arc/attr-merge-3e.s: Likewise.
	* testsuite/ld-arc/attr-merge-4.s: Likewise.
	* testsuite/ld-arc/attr-merge-5.d: Likewise.
	* testsuite/ld-arc/attr-merge-5a.s: Likewise.
	* testsuite/ld-arc/attr-merge-5b.s: Likewise.
	* testsuite/ld-arc/attr-merge-conflict-isa.d: Likewise.
	* testsuite/ld-arc/attr-merge-err-isa.d: Likewise.
	* testsuite/ld-arc/attr-merge-incompatible-cpu.d: Likewise.
	* testsuite/ld-arc/got-01.d: Update test.
	* testsuite/ld-arc/attr-merge-err-quarkse.d: New file.
	* testsuite/ld-arc/attr-quarkse.s: Likewise.
	* testsuite/ld-arc/attr-quarkse2.s: Likewise.

opcodes/
2017-05-10  Claudiu Zissulescu  <claziss@synopsys.com>

	* arc-dis.c (parse_option): Update quarkse_em option..
	* arc-ext-tbl.h (dsp_fp_flt2i, dsp_fp_i2flt): Change subclass to
	QUARKSE1.
	(dsp_fp_div, dsp_fp_cmp): Change subclass to QUARKSE2.
2017-05-10 14:42:22 +02:00
Awson a6da463048 Support pe-bigobj-x86-64 as an output format in 64-bit PE based linkers.
PR ld/21471
	* pe-dll.c (pe_detail_list): Add entry for pe-bigobj-x86-64.
2017-05-09 14:42:43 +01:00
Alan Modra d2732b697f ld.texinfo, use "affects" instead of "effects"
* ld.texinfo (orphan sections): Grammar fix.
2017-05-09 17:12:14 +09:30
H.J. Lu 38b123494b x86-64: Improve PLT generation and synthetic PLT symbols
On x86-64, the procedure linkage table (PLT) is used to

1. Call external function.
2. Call internal IFUNC function.  The best implementation is selected
for the target processor at run-time.
3. Act as the canonical function address.
4. Support LD_AUDIT to audit external function calls.
5. Support LD_PROFILE to profile external function calls.

PLT looks like:

PLT0:  push  GOT[1]
       jmp   *GOT[2]
       nop
PLT1:  jmp   *GOT[name1_index]
       push  name1_reloc_index
       jmp   PLT0

GOT is an array of addresses.  Initially the GOT entry of name1 is
filled with the address of the "push name1_reloc_index" instruction.
The function, name1, is called via "jmp *GOT[name1]" in the PLT entry.
Even when lazy binding is disabled by "-z now", the PLT0 entry may
still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
canonical function address.

When linker is invoked with "-z bndplt", a different PLT layout in .plt
is used:

PLT0:  push     GOT[1]
       bnd jmp  *GOT[2]
       nop
PLT1:  push     name1_reloc_index
       bnd jmp  PLT0
       nop

together with a second PLT section, .pl.bnd:

PLT1:  bnd jmp  *GOT[name1_index]
       nop

where the GOT entry of name1 is filled with the address of the push
instruction of the corresponding entry in .plt.

1. With lazy binding, when the external function, name1, is called the
first time, dynamic linker is called via PLT0 to update GOT[name1_index]
with the actual address of name1 and transfers control to name1
afterwards.
2. PLT is also used to call a local IFUNC function, name1, run-time
loader updates GOT[name1_index] when loading the module.

This patch

1. Remove PLT layout configurations from x86-64 backend_data.
2. Add generic, lay and non-lazy PLT layout configurations to x86-64
link_hash_table.  Generic PLT layout includes the PLT entry templates,
information how to update the first instruction in PLT and PLT eh_frame
informaton, which are initialized in x86-64 setup_gnu_properties, based
on "-z bndplt" and target selection.  PLT section alignment is also set
to PLT entry size for non-NaCl target.
3. Remove elf_x86_64_create_dynamic_sections.  create_dynamic_sections
isn't always called, but GOT relocations need GOT relocations.  Instead,
create all x86-64 specific dynamic sections with alignment to their entry
size  in x86-64 setup_gnu_properties, which initializes elf.dynobj, so
that x86-64 check_relocs can be simplified.
4. Rewrite elf_x86_64_get_synthetic_symtab to check PLT sections against
all dynamic relocations to support both lazy and non-lazy PLTs.

There is no change in PLT.  The only externally visible change is the
improvement of synthetic PLT symbols for .plt.got.

bfd/

	* elf64-x86-64.c (PLT_ENTRY_SIZE): Renamed to ...
	(LAZY_PLT_ENTRY_SIZE): This.
	(NON_LAZY_PLT_ENTRY_SIZE): New.
	(elf_x86_64_plt0_entry): Renamed to ...
	(elf_x86_64_lazy_plt0_entry): This.
	(elf_x86_64_plt_entry): Renamed to ...
	(elf_x86_64_lazy_plt_entry): This.
	(elf_x86_64_bnd_plt0_entry): Renamed to ...
	(elf_x86_64_lazy_bnd_plt0_entry): This.
	(elf_x86_64_legacy_plt_entry): Removed.
	(elf_x86_64_bnd_plt_entry): Renamed to ...
	(elf_x86_64_lazy_bnd_plt_entry): This.
	(elf_x86_64_legacy_plt2_entry): Renamed to ...
	(elf_x86_64_non_lazy_plt_entry): This.
	(elf_x86_64_bnd_plt2_entry): Renamed to ...
	(elf_x86_64_non_lazy_bnd_plt_entry): This.
	(elf_x86_64_eh_frame_plt): Renamed to ...
	(elf_x86_64_eh_frame_lazy_plt): This.
	(elf_x86_64_eh_frame_bnd_plt): Renamed to ...
	(elf_x86_64_eh_frame_lazy_bnd_plt): This.
	(elf_x86_64_eh_frame_plt_got): Renamed to ...
	(elf_x86_64_eh_frame_non_lazy_plt): This.
	(elf_x86_64_lazy_plt_layout): New.
	(elf_x86_64_non_lazy_plt_layout): Likewise.
	(elf_x86_64_plt_layout): Likewise.
	(elf_x86_64_backend_data): Remove PLT layout information.  Add
	os for target system.
	(GET_PLT_ENTRY_SIZE): Removed.
	(elf_x86_64_lazy_plt): New.
	(elf_x86_64_non_lazy_plt): Likewise.
	(elf_x86_64_lazy_bnd_plt): Likewise.
	(elf_x86_64_non_lazy_bnd_plt): Likewise.
	(elf_x86-64_arch_bed): Updated.
	(elf_x86_64_link_hash_table): Add plt, lazy_plt and non_lazy_plt.
	(elf_x86_64_create_dynamic_sections): Removed.
	(elf_x86_64_check_relocs): Don't check elf.dynobj.  Don't call
	_bfd_elf_create_ifunc_sections nor _bfd_elf_create_got_section.
	(elf_x86-64_adjust_dynamic_symbol): Updated.
	(elf_x86_64_allocate_dynrelocs): Updated.  Pass 0 as PLT header
	size to _bfd_elf_allocate_ifunc_dyn_relocs and don't allocate
	size for PLT0 if there is no PLT0.  Get plt_entry_size from
	non_lazy_plt for non-lazy PLT entries.
	(elf_x86_64_size_dynamic_sections): Updated.  Get plt_entry_size
	from non_lazy_plt for non-lazy PLT entries.
	(elf_x86-64_relocate_section): Updated.  Properly get PLT index
	if there is no PLT0.
	(elf_x86_64_finish_dynamic_symbol): Updated.  Fill the first slot
	in the PLT entry with generic PLT layout.  Fill the non-lazy PLT
	entries with non-lazy PLT layout.  Don't fill the second and third
	slots in the PLT entry if there is no PLT0.
	(elf_x86_64_finish_dynamic_sections): Updated.  Don't fill PLT0
	if there is no PLT0.  Set sh_entsize on the .plt.got section.
	(compare_relocs): New.
	(elf_x86_64_plt_type): Likewise.
	(elf_x86_64_plt): Likewise.
	(elf_x86_64_nacl_plt): New. Forward declaration.
	(elf_x86_64_get_plt_sym_val): Removed.
	(elf_x86_64_get_synthetic_symtab): Rewrite to check PLT sections
	against all dynamic relocations.
	(elf_x86_64_link_setup_gnu_properties): New function.
	(elf_backend_create_dynamic_sections): Updated.
	(elf_backend_setup_gnu_properties): New.
	(elf_x86_64_nacl_plt): New.
	(elf_x86_64_nacl_arch_bed): Updated.

ld/

	* testsuite/ld-ifunc/ifunc-16-x86-64-now.d: New file.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.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-2-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
	* testsuite/ld-x86-64/mpx3n.dd: Likewise.
	* testsuite/ld-x86-64/mpx4n.dd: Likewise.
	* testsuite/ld-x86-64/plt-main-bnd-now.rd: Likewise.
	* testsuite/ld-x86-64/plt2.dd: Likewise.
	* testsuite/ld-x86-64/plt2.rd: Likewise.
	* testsuite/ld-x86-64/plt2.s: Likewise.
	* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
	* testsuite/ld-x86-64/load1b-nacl.d: Updated.
	* testsuite/ld-x86-64/load1b.d: Likewise.
	* testsuite/ld-x86-64/plt-main-bnd.dd: Likewise.
	* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
	* testsuite/ld-x86-64/pr20830a.d: Update the .plt.got section
	with func@plt.
	* testsuite/ld-x86-64/pr20830b.d: Likewise.
	* testsuite/ld-x86-64/pr21038a.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
	* testsuite/ld-x86-64/mpx.exp: Add some -z now tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2017-05-08 12:24:29 -07:00
H.J. Lu f604c2a2a5 i386: Improve PLT generation and synthetic PLT symbols
On i386, the procedure linkage table (PLT) is used to

1. Call external function.
2. Call internal IFUNC function.  The best implementation is selected
for the target processor at run-time.
3. Act as the canonical function address.
4. Support LD_AUDIT to audit external function calls.
5. Support LD_PROFILE to profile external function calls.

PLT looks like:

PLT0:  push  GOT[1]
       jmp   *GOT[2]
       nop
PLT1:  jmp   *GOT[name1_index]
       push  name1_reloc_index
       jmp   PLT0

GOT is an array of addresses.  Initially the GOT entry of name1 is
filled with the address of the "push name1_reloc_index" instruction.
The function, name1, is called via "jmp *GOT[name1]" in the PLT entry.
Even when lazy binding is disabled by "-z now", the PLT0 entry may
still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
canonical function address.

1. With lazy binding, when the external function, name1, is called the
first time, dynamic linker is called via PLT0 to update GOT[name1_index]
with the actual address of name1 and transfers control to name1
afterwards.
2. PLT is also used to call a local IFUNC function, name1, run-time
loader updates GOT[name1_index] when loading the module.

This patch

1. Remove PLT layout configurations from i386 backend_data.
2. Add generic, lay and non-lazy PLT layout configurations to i386
link_hash_table.  Generic PLT layout includes the PLT entry templates,
information how to update the first instruction in PLT and PLT eh_frame
informaton, which are initialized in i386 setup_gnu_properties, based
on PIC and target selection.  PLT section alignment is also set to PLT
entry size for non-NaCl/VxWorks target.
3. Remove elf_i386_create_dynamic_sections.  create_dynamic_sections
isn't always called, but GOT relocations need GOT relocations.  Instead,
create all i386 specific dynamic sections in i386 setup_gnu_properties,
which initializes elf.dynobj, so that i386 check_relocs can be simplified.
4. Rewrite elf_i386_get_synthetic_symtab to check PLT sections against
all dynamic relocations to support both lazy and non-lazy PLTs.

bfd/

	* elf32-i386.c (PLT_ENTRY_SIZE): Renamed to ...
	(LAZY_PLT_ENTRY_SIZE): This.
	(NON_LAZY_PLT_ENTRY_SIZE): New.
	(elf_i386_plt0_entry): Renamed to ...
	(elf_i386_lazy_plt0_entry): This.
	(elf_i386_plt_entry): Renamed to ...
	(elf_i386_lazy_plt_entry): This.
	(elf_i386_pic_plt0_entry): Renamed to ...
	(elf_i386_pic_lazy_plt0_entry): This.
	(elf_i386_pic_plt_entry): Renamed to ...
	(elf_i386_pic_lazy_plt_entry): This.
	(elf_i386_got_plt_entry): Renamed to ...
	(elf_i386_non_lazy_plt_entry): This.
	(elf_i386_pic_got_plt_entry): Renamed to ...
	(elf_i386_pic_non_lazy_plt_entry): This.
	(elf_i386_eh_frame_plt): Renamed to ...
	(elf_i386_eh_frame_lazy_plt): This.
	(elf_i386_eh_frame_plt_got): Renamed to ...
	(elf_i386_eh_frame_non_lazy_plt): This.
	(elf_i386_plt_layout): Renamed to ...
	(elf_i386_lazy_plt_layout): This.  Remove eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_i386_non_lazy_plt_layout): New.
	(elf_i386_plt_layout): Likewise.
	(elf_i386_non_lazy_plt): Likewise.
	(GET_PLT_ENTRY_SIZE): Removed.
	(elf_i386_plt): Renamed to ...
	(elf_i386_lazy_plt): This.
	(elf_i386_backend_data): Remove plt.  Rename is_vxworks to os.
	(elf_i386_arch_bed): Updated.
	(elf_i386_link_hash_table): Add plt, lazy_plt and non_lazy_plt.
	(elf_i386_create_dynamic_sections): Removed.
	(elf_i386_check_relocs): Don't check elf.dynobj.  Don't call
	_bfd_elf_create_ifunc_sections nor _bfd_elf_create_got_section.
	(elf_i386_adjust_dynamic_symbol): Updated.
	(elf_i386_allocate_dynrelocs): Updated.  Pass 0 as PLT header
	size to _bfd_elf_allocate_ifunc_dyn_relocs and don't allocate
	size for PLT0 if there is no PLT0.
	(elf_i386_size_dynamic_sections): Updated.  Check whether GOT
	output section is discarded only if GOT isn't empty.
	(elf_i386_relocate_section): Updated.  Properly get PLT index
	if there is no PLT0.
	(elf_i386_finish_dynamic_symbol): Updated.  Don't fill the
	second and third slots in the PLT entry if there is no PLT0.
	(elf_i386_finish_dynamic_sections): Updated.  Don't fill PLT0
	if there is no PLT0.  Set sh_entsize on the .plt.got section.
	(elf_i386_nacl_plt): Forward declaration.
	(elf_i386_get_plt_sym_val): Removed.
	(elf_i386_get_synthetic_symtab): Rewrite to check PLT sections
	against all dynamic relocations.
	(elf_i386_link_setup_gnu_properties): New function.
	(elf_backend_create_dynamic_sections): Updated.
	(elf_backend_setup_gnu_properties): New.
	(elf_i386_nacl_plt): Updated.
	(elf_i386_nacl_arch_bed): Likewise.
	(elf_i386_vxworks_arch_bed): Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Add some -z now tests.
	* testsuite/ld-i386/plt-pic2.dd: New file.
	* testsuite/ld-i386/plt2.dd: Likewise.
	* testsuite/ld-i386/plt2.rd: Likewise.
	* testsuite/ld-i386/plt2.s: Likewise.
	* testsuite/ld-ifunc/ifunc-16-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-i386/pr20830.d: Update the .plt.got section
	with func@plt.
2017-05-08 10:11:32 -07:00
Thomas Preud'homme 046734ff42 Make import libraries relocatable objects
For ELF targets --out-implib currently generates an executable file
(e_type is ET_EXEC) despite the file being expected to be linked against
some other object file to make an executable later. It seems therefore
more sensible to make the import library a relocatable object file
(e_type set to ET_REL).

Incidentally, as dicted by requirement 8 of
"ARM v8-M Security Extensions: Requirements on Development Tools"
(document ARM-ECM-0359818) version 1.0, import libraries generated when
using --cmse-implib *must* be relocatable object file so this commit
also adds an assert there in case the type of ELF import library is
changed again in the future.

2017-05-08  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elflink.c (elf_output_implib): Remove executable flag from import
	library bfd.
	* elf32-arm.c (elf32_arm_filter_implib_symbols): Assert that the import
	library is a relocatable object file.

ld/
	* testsuite/ld-arm/arm-elf.exp
	(Secure gateway import library generation): Check e_type field
	of import library and executable produced.
	* testsuite/ld-arm/cmse-implib.type: Expectations for e_type field.
2017-05-08 15:26:51 +01:00
Senthil Kumar Selvaraj b660e9eb7a Fix PR21404 - assertion fail when calculating symbol size
Fix a host of problems related to adjustment of
symbol values and sizes when relaxing for avr.

1. Adjust symbol size first before adjusting symbol
value. Otherwise, a symbol whose value just got adjusted to the
relaxed address also ends up getting resized. See pr21404-1.s.

2. Reduce symbol sizes only if their span is below an
alignment boundary. Otherwise, the size gets decremented once when the
actual instruction is relaxed and padding bytes are added, and again
when the padding bytes are deleted (if padding ends up being unnecessary).
pr21404-2.s addresses that, and this bug is really the root cause of PR21404.

3. Adjust all symbol values before an alignment boundary.
Previous code did not adjust symbol values if they fell in the
would-be padded area, resulting in incorrect symbol values in some
cases (see pr21404-3.s).

4. Increase symbol sizes if alignment directives require so.
As pr21404-4.s shows
.global nonzero_sym
L1:
    jmp  L1
nonzero_sym:
    nop
    nop
    .p2align 2
.size nonzero_sym, .-nonzero_sym

The two nops satisfy the 4 byte alignment at assembly time and
therefore the size of nonzero_sym is 4. Relaxation shortens
the 4 byte jmp to a 2 byte rjmp, and to satisfy 4 byte alignment
the code places 2 extra padding bytes after the nops, increasing
nonzero_sym's size by 2. This wasn't handled before.

If the assembly code does not have any align directives, then the
boundary is the section size, and symbol values and sizes == boundary
should also get adjusted. To handle that case, add a did_pad variable
and use that to determine whether it should use < boundary or <= boundary.

Also get rid of reloc_toaddr, which is now redundant.  toaddr is now not
adjusted to handle the above case - the newly added
did_pad variable does the job.

pr21404-{5,6,7,8} are the same testcases written for local symbols, as
the code handles them slightly differently.
2017-05-04 10:34:29 +05:30
Maciej W. Rozycki 8507b6e797 MIPS16/GAS: Relax 32-bit non-PIC PC-relative synthetic instructions
Implement the relaxation of MIPS16 PC-relative synthetic LA, DLA, LW and
LD instructions to an equivalent sequence of instructions produced where
the address operand requested is out of range, absolute or requires
linker relocation, for ABIs that use 32-bit addressing and non-PIC code.

The sequence generated uses the register specified for the destination
operand as a temporary and begins with LI to load the high 16-bit part
of the address, then continues with SLL by 16 bits to move that part
into place and finally completes with a suitable operation corresponding
to the synthetic instruction used, one of: 2-argument ADDIU, 2-argument
DADDIU, absolute LW, and absolute LD respectively, providing the low
16-bit part of the address.  All instructions use the extended encoding.
As a special exception accept absolute addresses for relaxation even in
PIC code.

For example:

	la	$2, 0x12345678

produces code as:

	li	$2, 0x1234
	sll	$2, $2, 16
	addiu	$2, 0x5678

would.

Where linker relocation is required emit an R_MIPS16_HI16 relocation on
the initial LI instruction and an R_MIPS16_LO16 relocation on the final
operation.

For example (where `foo' is not local):

	lw	$3, foo

produces code as:

	li	$3, %hi(foo)
	sll	$3, $3, 16
	lw	$3, %lo(foo)($3)

would.

Emit assembly warnings as appropriate where this new relaxation triggers
in the `nomacro' mode or for an instruction manually placed in a branch
delay slot in the `noreorder' mode.  Refrain from relaxation where an
explicit instruction size suffix has been used and in the `noautoextend'
mode.

	gas/
	* config/tc-mips.c (RELAX_MIPS16_ENCODE): Add `pic', `sym32' and
	`nomacro' flags.
	(RELAX_MIPS16_PIC, RELAX_MIPS16_SYM32, RELAX_MIPS16_NOMACRO):
	New macros.
	(RELAX_MIPS16_USER_SMALL, RELAX_MIPS16_USER_EXT)
	(RELAX_MIPS16_DSLOT, RELAX_MIPS16_JAL_DSLOT)
	(RELAX_MIPS16_EXTENDED, RELAX_MIPS16_MARK_EXTENDED)
	(RELAX_MIPS16_CLEAR_EXTENDED, RELAX_MIPS16_ALWAYS_EXTENDED)
	(RELAX_MIPS16_MARK_ALWAYS_EXTENDED)
	(RELAX_MIPS16_CLEAR_ALWAYS_EXTENDED): Shift bits.
	(RELAX_MIPS16_MACRO, RELAX_MIPS16_MARK_MACRO)
	(RELAX_MIPS16_CLEAR_MACRO): New macros.
	(append_insn): Pass `mips_pic', HAVE_32BIT_SYMBOLS and
	`mips_opts.warn_about_macros' settings to RELAX_MIPS16_ENCODE.
	(mips16_macro_frag): New function.
	(md_estimate_size_before_relax): Handle HI16/LO16 relaxation.
	(mips_relax_frag): Likewise.
	(md_convert_frag): Likewise.

	* testsuite/gas/mips/mips16@relax-swap3.d: Remove error output,
	add dump patterns.
	* testsuite/gas/mips/mips16e@relax-swap3.d: New test
	subarchitecture.
	* testsuite/gas/mips/micromips@relax-swap3.d: Remove trailing
	NOP padding.
	* testsuite/gas/mips/mips16-pcrel-reloc-2.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-pcrel-reloc-3.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-pcrel-reloc-6.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-pcrel-reloc-7.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-pcrel-addend-2.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-pcrel-addend-3.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-pcrel-absolute.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-pcrel-absolute-1.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16@relax-swap3.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-reloc-2.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-reloc-3.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-reloc-6.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-reloc-7.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-addend-2.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-addend-3.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-absolute.l: Remove file.
	* testsuite/gas/mips/mips16-pcrel-absolute-1.l: Remove file.
	* testsuite/gas/mips/relax-swap3.s: Adjust trailing padding.

	* testsuite/gas/mips/mips16-pcrel-0.d: New test.
	* testsuite/gas/mips/mips16-pcrel-1.d: New test.
	* testsuite/gas/mips/mips16-pcrel-2.d: New test.
	* testsuite/gas/mips/mips16-pcrel-3.d: New test.
	* testsuite/gas/mips/mips16-pcrel-4.d: New test.
	* testsuite/gas/mips/mips16-pcrel-5.d: New test.
	* testsuite/gas/mips/mips16-pcrel-pic-0.d: New test.
	* testsuite/gas/mips/mips16-pcrel-pic-1.d: New test.
	* testsuite/gas/mips/mips16-pcrel-n32-0.d: New test.
	* testsuite/gas/mips/mips16-pcrel-n32-1.d: New test.
	* testsuite/gas/mips/mips16-pcrel-n64-sym32-0.d: New test.
	* testsuite/gas/mips/mips16-pcrel-n64-sym32-1.d: New test.
	* testsuite/gas/mips/mips16-pcrel-n64-0.d: New test.
	* testsuite/gas/mips/mips16-pcrel-n64-1.d: New test.
	* testsuite/gas/mips/mips16-pcrel-delay-0.d: New test.
	* testsuite/gas/mips/mips16-pcrel-delay-1.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-4.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-5.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-6.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-7.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-8.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-9.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-pic-8.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-pic-9.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-n32-8.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-n32-9.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-sym32-8.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-sym32-9.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-8.d: New test.
	* testsuite/gas/mips/mips16-pcrel-addend-n64-9.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-2.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-3.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-4.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-5.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-6.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-7.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-4.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-6.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-n32-4.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-n32-6.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-4.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-6.d: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-sym32-4.d: New
	test.
	* testsuite/gas/mips/mips16-pcrel-absolute-n64-sym32-6.d: New
	test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n32-4.d: New
	test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n32-6.d: New
	test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-4.d: New
	test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-6.d: New
	test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-sym32-4.d:
	New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-sym32-6.d:
	New test.
	* testsuite/gas/mips/mips16-pcrel-0.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-1.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-2.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-3.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-4.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-5.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-delay-0.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-delay-1.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-addend-8.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-addend-9.l: New stderr output.
	* testsuite/gas/mips/mips16-pcrel-absolute-4.l: New stderr
	output.
	* testsuite/gas/mips/mips16-pcrel-absolute-6.l: New stderr
	output.
	* testsuite/gas/mips/mips16-pcrel-0.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-1.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-2.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-3.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-4.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-5.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-delay-0.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-delay-1.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-addend-4.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-addend-5.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-addend-6.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-addend-7.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-addend-8.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-addend-9.s: New test source.
	* testsuite/gas/mips/mips16-pcrel-absolute-2.s: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-3.s: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-4.s: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-5.s: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-6.s: New test.
	* testsuite/gas/mips/mips16-pcrel-absolute-7.s: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/mips16-pcrel-0.d: New test.
	* testsuite/ld-mips-elf/mips16-pcrel-1.d: New test.
	* testsuite/ld-mips-elf/mips16-pcrel-addend-2.d: New test.
	* testsuite/ld-mips-elf/mips16-pcrel-addend-6.d: New test.
	* testsuite/ld-mips-elf/mips16-pcrel-n32-0.d: New test.
	* testsuite/ld-mips-elf/mips16-pcrel-n32-1.d: New test.
	* testsuite/ld-mips-elf/mips16-pcrel-n64-sym32-0.d: New test.
	* testsuite/ld-mips-elf/mips16-pcrel-n64-sym32-1.d: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-05-03 20:47:40 +01:00
H.J. Lu b22908217d Adjust testsuite/ld-elf/pr21384.d
Adjust testsuite/ld-elf/pr21384.d to accommodate additional dynamic
symbols on some targets.

	* testsuite/ld-elf/pr21384.d: Adjusted to accommodate
	additional dynamic symbols on some targets.
2017-05-03 07:43:50 -07:00
Maciej W. Rozycki 82d808edbc MIPS16/GAS: Fix absolute references with PC-relative synthetic instructions
Complement commit 88a7ef1689 ("MIPS16/GAS: Restore unsupported
relocation diagnostics") and also propagate constant expressions, either
already reduced from absolute symbol references or created from literals
in the first place, used as a PC-relative operand with the MIPS16 LA,
LW, DLA and LD synthetic instructions to relaxation, matching the way
forward absolute symbol references have been handled as from the commit
referred and letting relaxation produce any necessary relocations, if
possible, for the absolute value requested to be reproduced at the run
time.

Call `symbol_append' for any expression symbol created for the purpose
of MIPS16 relaxation as with constant expressions now propagated from
earlier on such symbols may make it through and have R_MIPS16_PC16_S1
relocations emitted against, and therefore need to appear in the symbol
table produced.

	gas/
	* config/tc-mips.c (append_insn): Call `symbol_append' for any
	expression symbol created for MIPS16 relaxation.
	(match_mips16_insn): Don't encode a constant value as an
	immediate with a PC-relative operand.

	* testsuite/gas/mips/mips16-pcrel-absolute-1.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-1.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-2.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-addend-1.d: New
	test.
	* testsuite/gas/mips/mips16-branch-absolute-n32-1.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-n32-2.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n32-1.d: New
	test.
	* testsuite/gas/mips/mips16-branch-absolute-n64-1.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-n64-2.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n64-1.d: New
	test.
	* testsuite/gas/mips/mips16-pcrel-absolute-1.l: New stderr
	output.
	* testsuite/gas/mips/mips16-pcrel-absolute-1.s: New test source.
	* testsuite/gas/mips/mips16-branch-absolute-1.s: New test
	source.
	* testsuite/gas/mips/mips16-branch-absolute-2.s: New test
	source.
	* testsuite/gas/mips/mips16-branch-absolute-addend-1.s: New test
	source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/mips16-branch-absolute-1.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-2.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend-1.d: New
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n32-1.d: New
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n32-2.d: New
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32-1.d:
	New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n64-1.d: New
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n64-2.d: New
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64-1.d:
	New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-05-03 00:15:56 +01:00
H.J. Lu 3d8505928a x86: Add -Wl,--no-as-needed to some TLS tests
* testsuite/ld-i386/tls.exp: Add -Wl,--no-as-needed to
	"TLS without PLT (1)" and "TLS without PLT (3)".
	* testsuite/ld-x86-64/tls.exp: Add -Wl,--no-as-needed to
	to "TLS without PLT (3)".
2017-05-02 16:01:39 -07:00
H.J. Lu 640226f048 Add a test for PR ld/21384
PR ld/21384
	* testsuite/ld-elf/pr21384.d: New file.
	* testsuite/ld-elf/pr21384.dl: Likewise.
	* testsuite/ld-elf/pr21384.ld: Likewise.
	* testsuite/ld-elf/pr21384.s: Likewise.
2017-05-02 13:54:22 -07:00
H.J. Lu 0aae7e72a2 x86: Run GNU2 TLS tests with working GNU2 TLS support
Check if GNU2 TLS really works before running GNU2 TLS tests.

	* testsuite/ld-i386/tls.exp: Run GNU2 TLS tests only if there
	is working GNU2 TLS support.
	* testsuite/ld-x86-64/tls.exp: Likewise.
	* testsuite/lib/ld-lib.exp (check_gnu2_tls_available): New proc.
2017-05-01 11:02:55 -07:00
H.J. Lu 1670f9c154 x86: Add run-time tests for -mtls-dialect=gnu2
* testsuite/config/default.exp (GNU2_CFLAGS): New.  Set
	to -mtls-dialect=gnu2 if target compiler supports it.
	* testsuite/ld-i386/tls.exp: Run -mtls-dialect=gnu2 tests.
	* testsuite/ld-x86-64/tls.exp: Likewise.
	* testsuite/ld-i386/tlsdesc1a.c: New file.
	* testsuite/ld-i386/tlsdesc1b.c: Likewise.
	* testsuite/ld-x86-64/tlsdesc1a.c: Likewise.
	* testsuite/ld-x86-64/tlsdesc1b.c: Likewise.
2017-04-28 12:42:18 -07:00
H.J. Lu d6f48aed23 ELF: Add run-time tests for -z now
* testsuite/ld-elf/shared.exp: Add run-time tests for -z now.
	* testsuite/ld-i386/tls.exp: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Likewise.
	* testsuite/ld-x86-64/tls.exp: Likewise.
2017-04-28 12:35:18 -07:00
H.J. Lu de9a3c4285 x86: Create dynamic sections in create_dynamic_sections
This patch creates dynamic sections in i386/x86-64 create_dynamic_sections
instead of creating them on demend.  Linker will strip them if they are
empty.  It changes order in x86-64 .eh_frame section.  The extra DW_CFA_nop
paddings is due to

https://sourceware.org/bugzilla/show_bug.cgi?id=21441

bfd/

	* elf32-i386.c (elf_i386_create_dynamic_sections): Create the
	.plt.got section here.
	(elf_i386_check_relocs): Don't create the .plt.got section.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Create
	the .plt.got and .plt.bnd sections here.
	(elf_x86_64_check_relocs): Don't create the .plt.got nor
	.plt.bnd sections.

ld/

	* testsuite/ld-x86-64/pr21038a.d: Update DW_CFA_nop paddings
	in .eh_frame section.
	* testsuite/ld-x86-64/pr21038c.d: Update .eh_frame order.
2017-04-27 13:55:48 -07:00
H.J. Lu 97d343d400 x86: Add DT_PLTRELSZ/DT_PLTREL/DT_JMPREL for PLT relocation
x86, PLT relocation may contain R_386_TLS_DESC or R_X86_64_TLSDESC
even though there is no real PLT.  We need to add DT_PLTRELSZ, DT_PLTREL
and DT_JMPREL if there is a .rel.plt/.rela.plt section.

bfd/

	* elf32-i386.c (elf_i386_size_dynamic_sections): Alwasys add
	DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rel.plt section.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Alwasys
	add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rela.plt section.

ld/

	* testsuite/ld-i386/tlsdesc2.d: New test.
	* testsuite/ld-x86-64/tlsdesc2.d: Likewise.
2017-04-26 15:34:00 -07:00
Maciej W. Rozycki 23ec1e32b1 PR ld/21334: Always call `_bfd_elf_link_renumber_dynsyms' if required
Complement commit e17b0c351f ("MIPS/BFD: Respect the ELF gABI dynamic
symbol table sort requirement") and correct an inconsistency in dynamic
symbol accounting data causing an assertion failure in the MIPS backend:

ld: BFD (GNU Binutils) 2.28.51.20170330 assertion fail
../../binutils-gdb/bfd/elfxx-mips.c:3860

in the course of making a GOT entry in a static binary to satisfy a GOT
relocation present in input, due to the local dynamic symbol count not
having been established.

To do so let backends request `_bfd_elf_link_renumber_dynsyms' to be
always called, rather than where a dynamic binary is linked only, and
then make this request in the MIPS backend.

	bfd/
	PR ld/21334
	* elf-bfd.h (elf_backend_data): Add `always_renumber_dynsyms'
	member.
	* elfxx-target.h [!elf_backend_always_renumber_dynsyms]
	(elf_backend_always_renumber_dynsyms): Define.
	(elfNN_bed): Initialize `always_renumber_dynsyms' member.
	* elfxx-mips.h (elf_backend_always_renumber_dynsyms): Define.
	* elflink.c (bfd_elf_size_dynamic_sections): Also call
	`_bfd_elf_link_renumber_dynsyms' if the backend has requested
	it.
	(bfd_elf_size_dynsym_hash_dynstr): Likewise.

	ld/
	PR ld/21334
	* testsuite/ld-mips-elf/pr21334.dd: New test.
	* testsuite/ld-mips-elf/pr21334.gd: New test.
	* testsuite/ld-mips-elf/pr21334.ld: New test linker script.
	* testsuite/ld-mips-elf/pr21334.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-04-26 13:17:07 +01:00
H.J. Lu 9e9821ddd8 x86-64: Force symbol dynamic if it isn't undefined weak
Force symbol dynamic if it isn't undefined weak.  Generate relative
relocation for GOT reference against non-dynamic symbol in PIC to
avoid unnecessary dynamic symbols.

bfd/

	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add
	no_finish_dynamic_symbol.
	(elf_x86_64_link_hash_newfunc): Set no_finish_dynamic_symbol to
	0.
	(elf_x86_64_allocate_dynrelocs): If a symbol isn't undefined
	weak symbol, don't make it dynamic.
	(elf_x86_64_relocate_section): If a symbol isn't dynamic in PIC,
	set no_finish_dynamic_symbol and generate R_X86_64_RELATIVE
	relocation for GOT reference.
	(elf_x86_64_finish_dynamic_symbol): Abort if
	no_finish_dynamic_symbol isn't 0.

ld/

	* testsuite/ld-x86-64/no-plt.exp: Also check no-plt-1e.nd.
	* testsuite/ld-x86-64/no-plt-1e.nd: New file.
2017-04-24 14:37:12 -07:00
H.J. Lu e662f84f5d i386: Skip pr12570 tests for nacl targets
commit f129e49f4d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jan 10 11:30:25 2017 -0800

    Don't use elf_i386_eh_frame_plt directly

fixed i386 PLT eh_frame generation.  Skip pr12570 tests since they are
for non-nacl targets.

	* testsuite/ld-i386/pr12570a.d: Skip for nacl targets.
	* testsuite/ld-i386/pr12570b.d: Likewise.
2017-04-24 09:46:04 -07:00
H.J. Lu 1587442d37 i386: Set ELF_MAXPAGESIZE to 0x1000 for VxWorks
commit a27e437177
Author: Roland McGrath <roland@gnu.org>
Date:   Thu Jul 28 22:35:15 2011 +0000

    BFD vector for elf32-i386-nacl:

changed ELF_MAXPAGESIZE to 0x10000 for VxWorks.  This patch fixes it
and updated testsuite/ld-i386/vxworks2.sd to add space for program
headers.

bfd/

	PR ld/21425
	* elf32-i386.c (ELF_MAXPAGESIZE): Set to 0x1000 for VxWorks.

ld/

	PR ld/20815
	* testsuite/ld-i386/vxworks2.sd: Add space for program headers.
2017-04-24 09:37:10 -07:00
Jose E. Marchesi 8b353c47b7 ld: fix regressions with rett instructions in sparc tests.
A few tests in the ld testsuite were expecting the disassembler to
emit `rett' instructions in V9.  This patch updates the tests to
expect `return' instead.

ld/ChangeLog:

2017-04-24  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* testsuite/ld-sparc/tlssunbin64.dd: Expect `return' instructions
	instead of `rett' in V9.
	* testsuite/ld-sparc/tlssunnopic64.dd: Likewise.
	* testsuite/ld-sparc/tlssunpic64.dd: Likewise.
2017-04-24 05:31:31 -07:00
H.J. Lu e133d00576 i386: Avoid dynamic symbol with GOT reference in PIE
GOT reference to global symbol in PIE will lead to dynamic symbol.  It
becomes a problem when "time" or "times" is defined as a variable in
an executable, clashing with functions of the same name in libc.  If
a symbol isn't undefined weak symbol, don't make it dynamic in PIE and
generate R_386_RELATIVE relocation.

bfd/

	PR ld/21402
	* elf32-i386.c (elf_i386_link_hash_entry): Add
	no_finish_dynamic_symbol.
	(elf_i386_link_hash_newfunc): Set no_finish_dynamic_symbol to 0.
	(elf_i386_allocate_dynrelocs): If a symbol isn't undefined weak
	symbol, don't make it dynamic in PIE.
	(elf_i386_relocate_section): If a symbol isn't dynamic in PIE,
	set no_finish_dynamic_symbol and generate R_386_RELATIVE
	relocation for R_386_GOT32
	(elf_i386_finish_dynamic_symbol): Abort if no_finish_dynamic_symbol
	isn't 0.

ld/

	PR ld/21402
	* testsuite/ld-elf/indirect.exp: Don't skip PIE indirect5 and
	indirect6 tests on i386.
2017-04-21 12:03:26 -07:00
H.J. Lu 3c5fce9bc2 Require --no-dynamic-linker with -static -E/--dynamic-list
When -static -E/--dynamic-list are passed to linker, linker may create
executable with dynamic sections which aren't supported by run-time.
We require --no-dynamic-linker together with -static -E/--dynamic-list
before adding dynamic symbol table to static executable.

bfd/

	PR ld/19617
	PR ld/21086
	* elflink.c (elf_link_add_object_symbols): Require
	--no-dynamic-linker with -E/--dynamic-list when creating
	dynamic sections.

ld/

	PR ld/19617
	PR ld/21086
	* testsuite/ld-elf/pr19617a.d: Pass --no-dynamic-linker to ld.
	* testsuite/ld-elf/pr19617b.d: Likewise.
	* testsuite/ld-elf/pr19617c.d: Likewise.
	*testsuite/ld-i386/pr19636-4d.d: Likewise.
	* testsuite/ld-elf/readelf.exp: Pass --no-dynamic-linker to ld
	with --export-dynamic.
	* testsuite/ld-elf/shared.exp: Pass --no-dynamic-linker to ld
	with -E.
2017-04-21 12:01:05 -07:00
H.J. Lu afe9edbf48 Skip PIE indirect5 and indirect6 tests on i386
On i386, since GOT reference is needed to access global symbols in PIE,
those symbols are made dynamic.  Crash happens when there is a reference
to the same global symbol with a different symbol type in a shared
object.  Since mixing different types of the same symbol doesn't work in
general, this patch skips those tests on i386 as well as compiles non-PIE
indirect5 and indirect6 tests with $NOPIE_LDFLAGS and $NOPIE_CFLAGS.

	PR ld/21402
	* testsuite/ld-elf/indirect.exp: Pass $NOPIE_LDFLAGS and
	$NOPIE_CFLAGS to non-PIE indirect5 and indirect6 tests.  Skip
	PIE indirect5 and indirect6 tests on i386.
2017-04-20 12:40:42 -07:00
Maciej W. Rozycki 31321c8031 MIPS/LD/testsuite: Join `__ehdr_start' tests
Complement commit 3807734dbe ("PR ld/15428: MIPS/LD/testsuite:
Un-KFAIL `__ehdr_start' test 2") and join tests that do not need to be
split anymore.

	ld/
	* testsuite/ld-mips-elf/mips-elf.exp: Join `__ehdr_start' tests.
2017-04-20 16:23:08 +01:00
H.J. Lu 59fa66c538 Handle symbol defined in IR and referenced in DSO
We need to make an IR symbol visible if it is defined in an IR object
and referenced in a dynamic object.  When --as-needed is used, since
linker removes the IR symbol reference of the dynamic object if the
dynamic object isn't needed in the first pass, the IR definition isn't
visible to the dynamic object even if the dynamic object becomes needed
in the second pass.  Add dynamic_ref_after_ir_def to bfd_link_hash_entry
to track IR symbol which is defined in an IR object and later referenced
in a dynamic object.  dynamic_ref_after_ir_def is preserved when restoring
the symbol table for unneeded dynamic object.

bfd/

	PR ld/21382
	* elflink.c (elf_link_add_object_symbols): Preserve
	dynamic_ref_after_ir_def when restoring the symbol table for
	unneeded dynamic object.

include/

	PR ld/21382
	* bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def.

ld/

	PR ld/21382
	* plugin.c (is_visible_from_outside): Symbol may be visible
	from outside if dynamic_ref_after_ir_def is set.
	(plugin_notice): Set dynamic_ref_after_ir_def if the symbol is
	defined in an IR object and referenced in a dynamic object.
	* testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests.
	* testsuite/ld-plugin/pr21382a.c: New file.
	* testsuite/ld-plugin/pr21382b.c: Likewise.
2017-04-20 07:48:35 -07:00
H.J. Lu e492d2f8ac x86-64: Handle undefined IFUNC symbol with -z now
Since undefined IFUNC symbol is treated as normal FUNC symbol, don't
abort on undefined IFUNC symbol in the second PLT.

bfd/

	PR ld/21401
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Don't abort
	on on undefined IFUNC symbol in the second PLT.

ld/

	PR ld/21401
	* testsuite/ld-ifunc/ifunc.exp: Add a libtest-2-now.so test with
	-z now.
2017-04-19 09:59:30 -07:00
Alan Modra 954b63d4c8 Implement -z dynamic-undefined-weak
-z nodynamic-undefined-weak is only implemented for x86.  (The sparc
backend has some support code but doesn't enable the option by
including ld/emulparams/dynamic_undefined_weak.sh, and since the
support looks like it may be broken I haven't enabled it.)  This patch
adds the complementary -z dynamic-undefined-weak, extends both options
to affect building of shared libraries as well as executables, and
adds support for the option on powerpc.

include/
	* bfdlink.h (struct bfd_link_info <dynamic_undefined_weak>):
	Revise comment.
bfd/
	* elflink.c (_bfd_elf_adjust_dynamic_symbol): Hide undefweak
	or make dynamic for info->dynamic_undefined_weak 0 and 1.
	* elf32-ppc.c:Formatting.
	(ensure_undefweak_dynamic): Don't make dynamic when
	info->dynamic_undefined_weak is zero.
	(allocate_dynrelocs): Discard undefweak dyn_relocs for
	info->dynamic_undefined_weak.  Discard undef dyn_relocs when
	not default visibility.  Discard undef and undefweak
	dyn_relocs earlier.
	(ppc_elf_relocate_section): Adjust to suit.
	* elf64-ppc.c: Formatting.
	(ensure_undefweak_dynamic): Don't make dynamic when
	info->dynamic_undefined_weak is zero.
	(allocate_dynrelocs): Discard undefweak dyn_relocs for
	info->dynamic_undefined_weak.  Discard them earlier.
ld/
	* ld.texinfo (dynamic-undefined-weak): Document.
	(nodynamic-undefined-weak): Document that this option now can
	be used with shared libs.
	* emulparams/dynamic_undefined_weak.sh: Support -z
	dynamic-undefined-weak.
	* emulparams/elf32ppccommon.sh: Include dynamic_undefined_weak.sh.
	* testsuite/ld-undefined/weak-undef.exp (undef_weak_so),
	(undef_weak_exe): New.  Use them.  Add -z dynamic-undefined-weak
	and -z nodynamic-undefined-weak tests.
	* Makefile.am: Update powerpc dependencies.
	* Makefile.in: Regenerate.
2017-04-19 20:39:52 +09:30
H.J. Lu e6699019c4 Put soname in the version definition section
commit 902e9fc76a
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Tue Feb 21 01:46:42 2017 +0000

    PR ld/20828: Move symbol version processing ahead of GC symbol sweep

breaks version definition with --version-script --soname.  This patch
fixes it by getting soname index before generating the version definition
section.

bfd/

	PR ld/21389
	* elflink.c (bfd_elf_size_dynamic_sections): Get soname index
	before generating the version definition section.

ld/

	PR ld/21389
	* testsuite/ld-elf/pr21389.map: New file.
	* testsuite/ld-elf/pr21389.s: Likewise.
	* testsuite/ld-elf/pr21389a.d: Likewise.
	* testsuite/ld-elf/pr21389b.d: Likewise.
	* testsuite/ld-elf/pr21389c.d: Likewise.
2017-04-17 07:47:32 -07:00
Alan Modra c5d37467b1 Undo dynamic symbol state after regular object sym type mismatch
We already handle the case of an object file first defining a symbol
that a later shared library also defines where the symbol types are
incompatible.  This patch handles the reverse, when a later object
file defines an incompatible symbol defined by an earlier shared
library.

bfd/
	* elflink.c (_bfd_elf_merge_symbol): Undo dynamic linking
	state when a regular object file defines a symbol with
	incompatible type to that defined by an earlier shared lib.
ld/
	* testsuite/ld-elf/indirect5a.c,
	* testsuite/ld-elf/indirect5b.c,
	* testsuite/ld-elf/indirect5.map,
	* testsuite/ld-elf/indirect5.out: New test.
	* testsuite/ld-elf/indirect6a.c: Likewise.
	* testsuite/ld-elf/indirect.exp (check_dynamic_syms): New proc.
	Run new tests and check dynsyms.
2017-04-17 23:14:37 +09:30
Alan Modra fbea15088d PR 21274, ld segfaults linking PE DLL
Don't use fixed size buffers for symbol names.

	PR 21274
	PR 18466
	* emultempl/pe.em (pe_find_data_imports): Don't use fixed size
	symbol buffer.  Instead, xmalloc max size needed with space for
	prefix.  Wrap overlong lines.  Formatting.  Pass symbol buffer
	copy of name to pe_walk_relocs_of_symbol.
	(make_inport_fixup): Add "name" param, pass to pe_create_import_fixup.
	* emultempl/pe.em (pep_find_data_imports): As for pe_find_data_imports.
	(make_import_fixup): Add "name" param, pass to pep_create_import_fixup.
	Use bfd_get_signed_* and remove unnecessary casts.  Formatting.
	* pe-dll.c (pe_walk_relocs_of_symbol): Add "name" param.  Pass to
	callback.
	(make_import_fixup_mark): Add "name" param.  Make use of prefix
	space rather than xmalloc here.
	(pe_create_import_fixup): Likewise.
	* pe-dll.h (pe_walk_relocs_of_symbol): Update prototype.
	(pe_create_import_fixup): Likewise.
	* pep-dll.h (pep_walk_relocs_of_symbol): Likewise.
	(pep_create_import_fixup): Likewise.
2017-04-11 19:49:13 +09:30
Nick Clifton a70f34c01c Document undocumented linker command line options.
ld 	* ld.texinfo (--strip-discarded): Document.
	(--embedded-relocs): Document.
	(--spare-dynamic-tags): Document.
	(--task-link): Document.
2017-04-10 15:59:59 +01:00
Alan Modra 6f9dbcd42f PR21287, Inconsistent section type for .init_array and .init_array.42
PR21287 notes that .init_array is correctly given a type of
SHT_INIT_ARRAY while .init_array.nnn gets SHT_PROGBITS.  This patch
fixes that problem, and properly drops warnings from the compiler that
would cause the testsuite to fail.  My a44d0bd78 change to check
ld_compile status, necessary to pick up compile errors, also meant
warnings were not ignored.

bfd/
	PR 21287
	* elf.c (special_sections_f): Match .fini_array and .fini_array.*.
	(special_sections_i): Likewise for .init_array.
	(special_sections_p): Likewise for .preinit_array.
ld/
	PR 21287
	* testsuite/ld-elf/init-fini-arrays.d: Match INIT_ARRAY and FINI_ARRAY.
	* testsuite/ld-elf/init-fini-arrays.s: Use %init_array and %fini_array
	section types.
	* testsuite/lib/ld-lib.exp (default_ld_compile): Trim assembler
	warnings about "ignoring incorrect section type".
	(run_ld_link_exec_tests, run_cc_link_tests): Delete old comment.
2017-04-10 15:11:35 +09:30
Alan Modra 37095d07b4 Clean elfvsb files left over from previous runs
My mips-linux and mips64-linux testsuite runs have been failing a
bunch of visibility tests, seemingly randomly.  It turns out the
problem occurs when object files are left over in ld/tmpdir from a
previous run.

	* testsuite/ld-elfvsb/elfvsb.exp (visibility_run): Delete
	sh1p.o, sh2p.o, sh1np.o and sh2np.o before compiling.  Use
	remote_file host exists rather than file exists.
2017-04-10 15:10:58 +09:30
H.J. Lu a7eaf017f9 Use NOPIE_CFLAGS and NOPIE_LDFLAGS to disable PIE
Since not all compilers support -no-pie, NOPIE_CFLAGS and NOPIE_LDFLAGS
should be used to disable PIE.

	PR ld/21090
	* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Use
	NOPIE_CFLAGS and NOPIE_LDFLAGS to disable PIE for the non-pie
	version of the test.
2017-04-07 08:53:43 -07:00
H.J. Lu 8170f7693b ELF: Check ELF_COMMON_DEF_P for common symbols
Since common symbols that are turned into definitions don't have the
DEF_REGULAR flag set, we need to check ELF_COMMON_DEF_P for common
symbols.

bfd/

	PR ld/19579
	PR ld/21306
	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
	ELF_COMMON_DEF_P for common symbols.
	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elflink.c (_bfd_elf_merge_symbol): Revert commits
	202ac193bb and
	07492f668d.

ld/

	PR ld/19579
	PR ld/21306
	* testsuite/ld-elf/pr19579a.c (main): Updated.
2017-04-07 07:40:14 -07:00
Nick Clifton ae3f8c2813 Fix failure in x86_64 linker tests when compiling with a PIE enabled compiler.
PR 21090
	* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Explicitly
	disable PIE for the non-pie version of the test.
2017-04-07 11:48:08 +01:00
Alan Modra 5c1f54ce0b Tweak MBIND ld test for ARM.
* testsuite/ld-elf/mbind2a.s: Don't use @, the ARM comment char.
2017-04-07 18:24:38 +09:30
Tristan Gingold 1fd6d11190 pe/coff: handle weak defined symbol for gc-sections.
bfd/
	* coffgen.c (_bfd_coff_gc_mark_hook): Handle PE weak
	external symbols with a definition.
	(_bfd_coff_gc_mark_extra_sections): Fix typo.

ld/
	* testsuite/ld-pe/pe.exp: New test.
	* testsuite/ld-pe/weakdef-1.s: New test source.
	* testsuite/ld-pe/weakdef-1.d: New test.
2017-04-07 10:03:17 +02:00
Alan Modra 3944e22b46 mbind tests: don't check PT_LOAD headers
On powerpc-linux, the second PT_LOAD header is RWE.  On hppa64-linux,
only one PT_LOAD header is present.  Since the tests are really about
the new GNU_MBIND headers, ignore PT_LOAD and its section mapping.

	* testsuite/ld-elf/mbind1a.d: Remove matches for PT_LOAD segments.
	* testsuite/ld-elf/mbind1b.d: Likewise.
	* testsuite/ld-elf/mbind1c.d: Likewise.
2017-04-07 00:18:33 +09:30
Hans-Peter Nilsson 6ca30fa561 PR ld/21233: change xfails to kfails, fix the indentation issue 2017-04-05 23:12:16 +02:00
Hans-Peter Nilsson 4d5efb852b PR ld/21233: xfail failing test-parts for cris*-*-* 2017-04-05 03:00:40 +02:00
Maciej W. Rozycki 80070c0d34 PR ld/21233: Avoid sweeping forced-undefined symbols in section GC
Complement commit 902e9fc76a ("PR ld/20828: Move symbol version
processing ahead of GC symbol sweep"), commit b531344c34 ("PR
ld/20828: Reorder the symbol sweep stage of section GC") and commit
81ff47b3a5 ("PR ld/20828: Fix linker script symbols wrongly forced
local with section GC"), and prevent symbols forcibly entered in the
output file with the use of the `--undefined=' or `--require-defined='
linker command line options or the EXTERN linker script command from
being swept in section garbage collection and consequently recorded in
the dynamic symbol table as local entries.  This happens in certain
circumstances, where a symbol reference also exists in one of the static
input files, however only in a section which is garbage-collected and
does not make it to the output file, and the symbol is defined in a
dynamic object present in the link.

For example with the `i386-linux' target and the `pr21233.s' and
`pr21233-l.s' sources, and the `pr21233.ld' linker script included with
this change we get:

$ as -o pr21233-l.o pr21233-l.s
$ ld -shared -T pr21233.ld -o libpr21233.so pr21233-l.o
$ as -o pr21233.o pr21233.s
$ ld --gc-sections -e foo --require-defined=bar -T pr21233.ld -o pr21233 pr21233.o libpr21233.so
$ readelf --dyn-syms pr21233

Symbol table '.dynsym' contains 2 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 OBJECT  LOCAL  DEFAULT  UND bar
$

which makes the run-time `bar' dependency of the `pr21233' executable
different from its corresponding link-time dependency, i.e. the presence
of `libpr21233.so' and its `bar' symbol is required at the link time,
however at the run time a copy of `libpr21233.so' without `bar' will do.
Similarly with `--undefined=' and EXTERN which do not actually require
the reference to the symbol requested to be satisfied with a definition
at the link time, however once the definition has been pulled at the
link time, so it should at the dynamic load time.

Additionally with the `mips-linux' target we get:

$ ld --gc-sections -e foo --require-defined=bar -T pr21233.ld -o pr21233 pr21233.o libpr21233.so
ld: BFD (GNU Binutils) 2.28.51.20170324 assertion fail .../bfd/elfxx-mips.c:3861
$

as the target is not prepared to handle such a local dynamic symbol.

With this change in effect we get:

$ readelf --dyn-syms pr21233

Symbol table '.dynsym' contains 2 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 OBJECT  GLOBAL DEFAULT  UND bar
$

instead, for both targets.

	ld/
	PR ld/21233
	* ldlang.c (insert_undefined): Set `mark' for ELF symbols.
	* testsuite/ld-elf/pr21233.sd: New test.
	* testsuite/ld-elf/pr21233-l.sd: New test.
	* testsuite/ld-elf/pr21233.ld: New test linker script.
	* testsuite/ld-elf/pr21233-e.ld: New test linker script.
	* testsuite/ld-elf/pr21233.s: New test source.
	* testsuite/ld-elf/pr21233-l.s: New test source.
	* testsuite/ld-elf/shared.exp: Run the new tests.
2017-04-04 23:21:44 +01:00
H.J. Lu a91e1603af Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX
Mark an ALLOC section, which should be placed in special memory area,
with SHF_GNU_MBIND.  Its sh_info field indicates the special memory
type.  GNU_MBIND section names start with ".mbind" so that they are
placed as orphan sections by linker.  All input GNU_MBIND sections
with the same sh_type, sh_flags and sh_info are placed in one output
GNU_MBIND section.  In executable and shared object, create a
GNU_MBIND segment for each GNU_MBIND section and its segment type is
PT_GNU_MBIND_LO plus the sh_info value.  Each GNU_MBIND segment is
aligned at page boundary.

The assembler syntax:

    .section .mbind.foo,"adx",%progbits
                          ^             0: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.foo,"adx",%progbits,0x1
                          ^             1: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.bar,"adG",%progbits,.foo_group,comdat,0x2
                          ^                               2: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

bfd/

	* elf.c (get_program_header_size): Add a GNU_MBIND segment for
	each GNU_MBIND section and align GNU_MBIND section to page size.
	(_bfd_elf_map_sections_to_segments): Create a GNU_MBIND
	segment for each GNU_MBIND section.
	(_bfd_elf_init_private_section_data): Copy sh_info from input
	for GNU_MBIND section.

binutils/

	* NEWS: Mention support for ELF SHF_GNU_MBIND and
	PT_GNU_MBIND_XXX.
	* readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX.
	(get_elf_section_flags): Handle SHF_GNU_MBIND.
	(process_section_headers): Likewise.
	* testsuite/binutils-all/mbind1.s: New file.
	* testsuite/binutils-all/objcopy.exp: Run readelf test on
	mbind1.s.

gas/

	* NEWS: Mention support for ELF SHF_GNU_MBIND.
	* config/obj-elf.c (section_match): New.
	(get_section): Match both sh_info and group name.
	(obj_elf_change_section): Add argument for sh_info.  Pass both
	sh_info and group name to get_section. Issue an error for
	SHF_GNU_MBIND section without SHF_ALLOC.  Set sh_info.
	(obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'.
	(obj_elf_section): Support SHF_GNU_MBIND section info.
	* config/obj-elf.h (obj_elf_change_section): Add argument for
	sh_info.
	* config/tc-arm.c (start_unwind_section): Pass 0 as sh_info to
	obj_elf_change_section.
	* config/tc-ia64.c (obj_elf_vms_common): Likewise.
	* config/tc-microblaze.c (microblaze_s_data): Likewise.
	(microblaze_s_sdata): Likewise.
	(microblaze_s_rdata): Likewise.
	(microblaze_s_bss): Likewise.
	* config/tc-mips.c (s_change_section): Likewise.
	* config/tc-msp430.c (msp430_profiler): Likewise.
	* config/tc-rx.c (parse_rx_section): Likewise.
	* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
	* doc/as.texinfo: Document 'd' for SHF_GNU_MBIND.
	* testsuite/gas/elf/elf.exp: Run section12a, section12b and
	section13.
	* testsuite/gas/elf/section10.d: Updated.
	* testsuite/gas/elf/section10.s: Likewise.
	* testsuite/gas/elf/section12.s: New file.
	* testsuite/gas/elf/section12a.d: Likewise.
	* testsuite/gas/elf/section12b.d: Likewise.
	* testsuite/gas/elf/section13.l: Likewise.
	* testsuite/gas/elf/section13.d: Likewise.
	* testsuite/gas/elf/section13.s: Likewise.

include/

	* elf/common.h (PT_GNU_MBIND_NUM): New.
	(PT_GNU_MBIND_LO): Likewise.
	(PT_GNU_MBIND_HI): Likewise.
	(SHF_GNU_MBIND): Likewise.

ld/

	* NEWS: Mention support for ELF SHF_GNU_MBIND and
	PT_GNU_MBIND_XXX.
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place
	input GNU_MBIND sections with the same type, attributes and
	sh_info field into a single output GNU_MBIND section.
	* testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b.
	* testsuite/ld-elf/mbind1.s: New file.
	* testsuite/ld-elf/mbind1a.d: Likewise.
	* testsuite/ld-elf/mbind1b.d: Likewise.
	* testsuite/ld-elf/mbind1c.d: Likewise.
	* testsuite/ld-elf/mbind2a.s: Likewise.
	* testsuite/ld-elf/mbind2b.c: Likewise.
2017-04-04 09:06:04 -07:00
Andrew Jenner 2f5f29cada IA16 support
* config.sub: Handle ia16 in $basic_machine.

       bfd/
       * config.bfd: Handle ia16.

       gas/
       * configure.tgt: Handle ia16.

       ld/
       * configure.tgt: Handle ia16.
2017-04-03 09:13:19 -07:00
H.J. Lu 2514e33e01 Correct the ChangeLog entry 2017-04-03 08:25:36 -07:00
H.J. Lu 46bed6796d ld: Support ELF GNU program properties
From .note.gnu.property section in each ELF input, we build a list of
GNU properties if .note.gnu.property section isn't corrupt.  The unknown
properties are ignored.  All property lists in relocatable inputs are
merged into an output property list.  When -z stack-size=N is used and
N isn't 0, the GNU_PROPERTY_STACK_SIZE property will be merged with or
added to the output property list.  .note.gnu.property section is
generated in output from the output property list.

bfd/

	* Makefile.am (BFD32_BACKENDS): Add elf-properties.lo.
	(BFD32_BACKENDS_CFILES): Add elf-properties.c.
	* configure.ac (elf): Add elf-properties.lo.
	* Makefile.in: Regenerated.
	* configure: Likewise.
	* elf-bfd.h (elf_property_kind): New.
	(elf_property): Likewise.
	(elf_property_list): Likewise.
	(elf_properties): Likewise.
	(_bfd_elf_parse_gnu_properties): Likewise.
	(_bfd_elf_get_property): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Likewise.
	(elf_backend_data): Add parse_gnu_properties, merge_gnu_properties
	and setup_gnu_properties.
	(elf_obj_tdata): Add properties.
	* elf-properties.c: New file.
	* elf32-i386.c (elf_i386_parse_gnu_properties): New.
	(elf_i386_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.
	(elf_x86_64_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	* elfxx-target.h (elf_backend_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_setup_gnu_properties): Likewise.
	(elfNN_bed): Add elf_backend_parse_gnu_properties,
	elf_backend_merge_gnu_properties and
	elf_backend_setup_gnu_properties.

ld/

	* ld/NEWS: Mention support for ELF GNU program properties.
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Call
	ELF setup_gnu_properties.
	* testsuite/ld-i386/i386.exp: Run property tests for Linux/i386.
	* testsuite/ld-i386/pass.c: New file.
	* testsuite/ld-i386/property-1.r: Likewise.
	* testsuite/ld-i386/property-2.r: Likewise.
	* testsuite/ld-i386/property-3.r: Likewise.
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-i386/property-6.r: Likewise.
	* testsuite/ld-i386/property-6a.c: Likewise.
	* testsuite/ld-i386/property-6b.c: Likewise.
	* testsuite/ld-i386/property-6c.S: Likewise.
	* testsuite/ld-i386/property-7.r: Likewise.
	* testsuite/ld-i386/property-no-copy.S: Likewise.
	* testsuite/ld-i386/property-stack.S: Likewise.
	* testsuite/ld-i386/property-unsorted-1.S: Likewise.
	* testsuite/ld-i386/property-unsorted-2.S: Likewise.
	* testsuite/ld-i386/property-x86-1.S: Likewise.
	* testsuite/ld-i386/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/pass.c: Likewise.
	* testsuite/ld-x86-64/property-1.r: Likewise.
	* testsuite/ld-x86-64/property-2.r: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: Likewise.
	* testsuite/ld-x86-64/property-6.r: Likewise.
	* testsuite/ld-x86-64/property-6a.c: Likewise.
	* testsuite/ld-x86-64/property-6b.c: Likewise.
	* testsuite/ld-x86-64/property-6c.S: Likewise.
	* testsuite/ld-x86-64/property-7.r: Likewise.
	* testsuite/ld-x86-64/property-no-copy.S: Likewise.
	* testsuite/ld-x86-64/property-stack.S: Likewise.
	* testsuite/ld-x86-64/property-unsorted-1.S: Likewise.
	* testsuite/ld-x86-64/property-unsorted-2.S: Likewise.
	* testsuite/ld-x86-64/property-x86-1.S: Likewise.
	* testsuite/ld-x86-64/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run property tests for
	Linux/x86-64.
2017-04-03 08:08:27 -07:00
Hans-Peter Nilsson 086554e8e6 Fix for PR ld/16044: elf32-cris.c h->plt.refcount inconsistency 2017-03-28 23:43:09 +02:00
Maciej W. Rozycki c72cea5aec readelf: Fix incorrect "Version definition past end of section" message (ChangeLog)
Correct ChangeLog entry for commit c9f02c3e29 ("readelf: Fix incorrect
"Version definition past end of section" message").
2017-03-24 12:25:49 +00:00
Sandra Loosemore 4c8798c992 Disable shared library tests for nios2-*-elf.
The Nios II processor documentation defines relocations for PIC and
shared libraries as part of the GNU/Linux ABI only; GCC rejects -fpic
on bare-metal.

2017-03-21  Sandra Loosemore  <sandra@codesourcery.com>

	ld/
	* testsuite/lib/ld-lib.exp (check_shared_lib_support): Return
	false for nios2-*-elf.
2017-03-21 13:25:09 -07:00
Tristan Gingold 2170171889 ld: check overflow only for allocated sections.
* ldlang.c (lang_check_section_addresses): Check only for
	allocated sections.
2017-03-21 12:00:30 +01:00
Alan Modra 1d3fa25f58 ld sec64k test fix
* testsuite/ld-elf/sec64k.exp: Don't run on h8300 and ip2k.
2017-03-17 19:08:55 +10:30
Tristan Gingold 9494d96366 ld-checks: tweak overflow checks.
* testsuite/ld-checks/checks.exp (overflow_check): Disable for
	non-elf targets.
2017-03-15 10:23:19 +01:00
H.J. Lu 9216a6f335 Use addr_mask to check VMA and LMA
Since BFD64 may be used on 32-bit address, we need to apply addr_mask
to check VMA and LMA.

	* ldlang.c (lang_check_section_addresses): Use addr_mask to
	check VMA and LMA.
2017-03-14 09:09:54 -07:00
Nick Clifton f955cccff3 Rename R_AARCH64_TLSDESC_LD64_LO12_NC to R_AARCH64_TLSDESC_LD64_LO12 and R_AARCH64_TLSDESC_ADD_LO12_NC to R_AARCH64_TLSDESC_ADD_LO12.
PR binutils/21202
include	* elf/aarch64.h (R_AARCH64_TLSDESC_LD64_LO12_NC): Rename to
	R_AARCH64_TLSDESC_LD64_LO12.
	(R_AARCH64_TLSDESC_ADD_LO12_NC): Rename to
	R_AARCH64_TLSDESC_ADD_LO12_NC.

bfd	* reloc.c (BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC): Rename to
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12.
	(BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC): Rename to
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elfnn-aarch64.c (IS_AARCH64_TLS_RELAX_RELOC): Update reloc
	names.
	(IS_AARCH64_TLSDESC_RELOC): Likewise.
	(elfNN_aarch64_howto_table): Likewise.
	(aarch64_tls_transition_without_check): Likewise.
	(aarch64_reloc_got_type): Likewise.
	(elfNN_aarch64_final_link_relocate): Likewise.
	(elfNN_aarch64_tls_relax): Likewise.
	(elfNN_aarch64_relocate_section): Likewise.
	(elfNN_aarch64_gc_sweep_hook): Likewise.
	(elfNN_aarch64_check_relocs): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Likewise.
	(_bfd_aarch64_elf_resolve_relocation): Likewise.

gas	* config/tc-aarch64.c (reloc_table): Rename
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC to
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12.  Rname
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC to
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12.
	(md_apply_fix): Likewise.
	(aarch64_force_relocation): Likewise.
	* testsuite/gas/aarch64/tls.d: Update regexp.

ld	* testsuite/ld-aarch64/ifunc-5r-local.d: Update regexp.
2017-03-13 09:58:04 +00:00
Tristan Gingold d40e34db39 ld: add an error in case of address space overflow.
ld/
	* ldlang.c (lang_check_section_addresses): Check for address space
	overflow.
	* testsuite/ld-checks/checks.exp (overflow_check): New procedure
	* testsuite/ld-checks/over.s: New test source.
	* testsuite/ld-checks/over.d: New test.
	* testsuite/ld-checks/over2.s: New test source.
	* testsuite/ld-checks/over2.d: New test.
2017-03-13 10:41:22 +01:00
Alexey Neyman 4b5900d8b8 PowerPC: incorrect library search order
First, need to match against just the CPU name, not the whole triplet.
Otherwise, the test picks up "*le-*" pattern from x86_64-apple-darwin
triplet.

Second, it should be testing for $target, not $host. Host may be
little endian by default, and the sysroot directory layout shouldn't
depend on whether it is built on LE or BE machine.

	* emulparams/elf32ppccommon.sh (LIBPATH_SUFFIX): Set from target
	cpu, not host.
2017-03-13 17:51:38 +10:30
Alan Modra 118aa6cf39 Add sysroot for ld -rpath search
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Add
	sysroot for -rpath search.
2017-03-11 23:40:21 +10:30
Alan Modra 316a1245fe Rewrite add_sysroot
Relative paths shouldn't have the sysroot prefix added.  The patch
also makes some attempt at supporting DOS paths, and tidies code using
the new add_sysroot.

	* emultempl/elf32.em (gld${EMULATION_NAME}_add_sysroot): Rewrite.
	Only prefix absolute paths with sysroot.  Handle DOS paths.
	(gld${EMULATION_NAME}_check_ld_elf_hints): Constify variable.
	(gld${EMULATION_NAME}_check_ld_so_conf): Likewise.
	(gld${EMULATION_NAME}_after_open): Short-circuit NULL path
	searches.  Rename variable.  Simplify get_runpath search.
2017-03-11 23:40:20 +10:30
Alan Modra bb4287c562 Don't use -rdynamic in ld test
This gcc option isn't well supported, so use the actual linker option
we want to test.

	* testsuite/ld-elf/shared.exp: Use -Wl,-export-dynamic rather
	than -rdynamic.
2017-03-11 11:04:02 +10:30
Alan Modra e299b3551e Don't run new orphan tests on i860 and i960
These targets use the generic ELF support, so don't handle orphans
well.  The patch also updates the orphan doco to reflect this fact,
and deletes some ELF details that don't really add anything.

	* ld.texinfo (Orphan Sections): Mention that not all targets
	handle orphans well.  Delete ELF details.
	* testsuite/ld-elf/orphan-9.d: Don't run for i860 and i960.
	* testsuite/ld-elf/orphan-10.d: Likewise.
2017-03-11 10:51:56 +10:30
Andrew Burgess 14ea2c1b23 ld: Track changes to default region LMA even for empty sections
Given a linker script fragment like this:

   SECTIONS {
     . = 0x1000;
     .text   : AT(0x100) { *(.text)   }
     .data   : AT(0x200) { *(.data)   }
     .rodata : AT(0x300) { *(.rodata) }
   }

and an input file containing sections, '.text', '.data.1', and
'.rodata', then we'd expect the linker to place '.text' and '.rodata' in
the obvious way, and the '.data.1' orphan section would be located after
the '.data' section (assuming similar section properties).

Further, I believe that the expectation would be that the LMA for the
orphan '.data.1' section would start from 0x200 (as there is no '.data'
content).

However, right now, the LMA for '.data.1' would be 0x101, following on
from the '.text' section, this is because the change in LMA for the
'.data' section is not noticed by the linker, if there's no content in
the '.data' section.

What can be even more confusing to a user (though the cause is obvious
once you understand what's going on) is that adding some content to
'.data' will cause the orphan '.data.1' to switch to an LMA based off of
0x200.

This commit changes the behaviour so that an empty section that is in
the default lma region, and sets its lma, will adjust the lma of the
default region, this change will then be reflected in following sections
within the default lma memory region.

There's a new test to cover this issue that passes on a range of
targets, however, some targets generate additional sections, or have
stricter memory region size requirements that make it harder to come
up with a generic pass pattern, that still tests the required
features.  For now I've set the test to ignore these targets.

ld/ChangeLog:

	* ldlang.c (lang_size_sections_1): Shortcut loop only after
	tracking changes to the default regions LMA.
	* testsuite/ld-elf/orphan-9.ld: Extend header comment.
	* testsuite/ld-elf/orphan-10.d: New file.
	* testsuite/ld-elf/orphan-10.s: New file.
	* NEWS: Mention change in behaviour.
2017-03-09 21:11:06 +00:00
Andrew Burgess 77f5e65ecf ld: better handling of lma region for orphan sections
When picking an lma_region for an orphan section we currently create a
new lang_output_section_statement_type and then populate this with the
orphan section.

The problem is that the lang_output_section_statement_type has a prev
pointer that links back to the previous output section.  For non-orphan
output sections, that are created in linker script order, the prev
pointer will point to the output section that appears previous in linker
script order, as you'd probably expect.

The problem is that orphan sections are placed after processing the
linker script, and so, in the case of an output section created for an
orphan input section, the prev pointer actually points to the last
output section created.

This causes some unexpected behaviour when the orphan section is not
placed after the last non-orphan section that was created.

For example, consider this linker script:

  MEMORY {
    TEXT   : ORIGIN = 0x200,  LENGTH = 0x10
    RODATA : ORIGIN = 0x400,  LENGTH = 0x10
  }

  SECTIONS {
    .text   :           {*(.text)    } AT>TEXT
    .data   : AT(0x300) { *(.data)   }
    .rodata :           { *(.rodata) } AT>RODATA
  }

If we are processing an orphan section '.data.1' and decide to place
this after '.data', then the output section created will have a prev
pointer that references the '.rodata' output section.  The result of
this is that '.data.1' will actually be assigned to the RODATA lma
region, which is probably not the expected behaviour.

The reason why '.data.1' is placed into the lma region of the '.rodata'
section is that lma region propagation is done at the time we create the
output section, based on the previous output section pointer, which is
really just a last-output-section-created pointer at that point in time,
though the prev point is fixed up later to reflect the true order of the
output sections.

The solution I propose in this commit is to move the propagation of lma
regions into a separate pass of the linker, rather than performing this
as part of the enter/exit of output sections during linker script
parsing.

During this later phase we have all of the output sections to hand, and
the prev/next points have been fixed up by this point to reflect the
actual placement ordering.

There's a new test to cover this issue that passes on a range of
targets, however, some targets generate additional sections, or have
stricter memory region size requirements that make it harder to come
up with a generic pass pattern, that still tests the required
features.  For now I've set the test to ignore these targets.

ld/ChangeLog:

	* ldlang.c (lang_leave_output_section_statement): Move lma_region
	logic to...
	(lang_propagate_lma_regions): ...this new function.
	(lang_process): Call new function.
	* testsuite/ld-elf/orphan-9.d: New file.
	* testsuite/ld-elf/orphan-9.ld: New file.
	* testsuite/ld-elf/orphan-9.s: New file.
	* NEWS: Mention change in behaviour.
2017-03-09 21:11:05 +00:00
Andrew Burgess a87ded7b88 ld: Orphan section documentation
Make more explicit mention of the fact that orphan sections can cause a
new output section to be created.  Though this information is clearly
implied in the manual it might not be clear enough.

A user _might_ (incorrectly) think that orphan sections can only be
inserted into an existing output section.

ld/ChangeLog:

	* ld.texinfo (Orphan Sections): Add more detail.
2017-03-09 21:10:58 +00:00
Alan Modra d933941d6c Fix ld uninitialized read of script ASSERT data structure
lang_assignment_statement serves both assignments and asserts.

	* ldlang.c (open_input_bfds): Check that lang_assignment_statement
	is not an assert before referencing defsym.
2017-03-07 12:33:28 +10:30
Alan Modra 2e0ce1c84d Align eh_frame FDEs according to their encoding
bfd/
	* elf-bfd.h (struct eh_cie_fde): Add u.cie.per_encoding_aligned8.
	* elf-eh-frame.c (size_of_output_cie_fde): Don't align here.
	(next_cie_fde_offset): New function.
	(_bfd_elf_parse_eh_frame): Set u.cie.per_encoding_aligned8.
	(_bfd_elf_discard_section_eh_frame): Align zero terminator to
	four bytes.  Align CIEs to four or eight bytes depending on
	per_encoding_aligned8.  Align FDEs according to their encoding.
	Pad last FDE to output section alignment.
	(_bfd_elf_write_section_eh_frame): Adjust to suit.  Remove
	assertion.
	* elf64-ppc.c (glink_eh_frame_cie): Delete padding.
	(ppc64_elf_size_stubs): Pad glink eh_frame as per elf-eh-frame.c.
	(ppc64_elf_finish_dynamic_sections): Adjust to suit.
ld/
	* testsuite/ld-elf/eh3.d: Adjust for eh_frame alignment change.
	* testsuite/ld-elf/eh6.d: Likewise.
	* testsuite/ld-alpha/tlsbin.dd: Likewise.
	* testsuite/ld-alpha/tlsbin.td: Likewise.
	* testsuite/ld-alpha/tlsbinr.dd: Likewise.
	* testsuite/ld-alpha/tlspic.dd: Likewise.
	* testsuite/ld-alpha/tlspic.rd: Likewise.
	* testsuite/ld-alpha/tlspic.sd: Likewise.
	* testsuite/ld-alpha/tlspic.td: Likewise.
	* testsuite/ld-mips-elf/eh-frame1-n64.d: Likewise.
	* testsuite/ld-mips-elf/eh-frame2-n64.d: Likewise.
	* testsuite/ld-mips-elf/eh-frame3.d: Likewise.
	* testsuite/ld-x86-64/pr20830a.d: Likewise.
	* testsuite/ld-x86-64/pr21038a.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
2017-03-05 14:49:54 +10:30
Nick Clifton 611a3ca929 Make the linker fail if asked to create more than 1^16 ordinal values for PE targets.
PR 12969
	* pe-dll.c (generate_edata): Fail if the input file(s) require too
	many ordinals.
2017-03-03 11:35:03 +00:00
Alan Modra 199add01b6 Avoid gcc-7 warning killing ld testcases
* testsuite/ld-elf/shared.exp: Pass -ansi when compiling new.cc
	and dl3.cc.
2017-03-02 10:40:06 +10:30
Alan Modra 4ef97a1b45 Nios2 dynobj handling fixes
A number of places in elf32-nios.c created dynamic sections but didn't
set the hash table dynobj.  That meant we could have duplicate dynamic
sections connected to a number of bfds, so size_dynamic_sections
didn't properly discard or allocate contents.

Also, the entire set of dynamic sections was created in check_relocs
on seeing GOT relocs, when only .got related sections are needed,
probably done to hide segfaults later in finish_dynamic_sections.

The patch fixes these issues and makes the assembler emit errors when
nios2 lacks the necessary pc-relative relocs for subtraction
expressions, rather than silently generating bad code.
eg. ld-elf/merge.  I've also tidied uses of elf32_nios2_hash_table and
elf_hash_table.

bfd/
	PR 20995
	* elf32-nios2.c (nios2_elf32_relocate_section): Use htab
	rather than elf32_nios2_hash_table or elf_hash_table.
	(create_got_section): Likewise.
	(nios2_elf32_finish_dynamic_symbol): Likewise.
	(nios2_elf32_adjust_dynamic_symbol): Likewise.
	(nios2_elf32_size_dynamic_sections): Likewise.
	(nios2_elf32_check_relocs): Delete dynobj, sgot, and srelgot
	vars.  Use htab equivalents directly instead.  Don't create
	all dynamic sections on needing just the GOT.  Use a goto
	rather than a fall-through with reloc test.  Ensure
	htab->dynobj is set when making dynamic sreloc section.
	(nios2_elf32_finish_dynamic_sections): Delete dynobj, use htab
	equivalent directly instead.  Don't segfault on looking for
	.dynamic when dynamic sections have not been created.  Don't
	segfault on .got.plt being discarded.
	(nios2_elf32_size_dynamic_sections): Delete plt and got vars.
	Don't set "relocs" on .rela.plt.  Do handle .sbss.  Delete
	fixme and another not so relevant comment.
	(nios2_elf_add_symbol_hook): Delete dynobj var.  If not
	already set, set hash table dynobj on creating .sbss.
gas/
	* config/tc-nios2.h (TC_FORCE_RELOCATION_SUB_LOCAL): Define.
ld/
	* testsuite/ld-elf/merge.d: xfail for nios.
2017-02-28 13:20:21 +10:30
Alan Modra 7ba71655a4 PowerPC addpcis fix
This came up because I was looking at ld/tmpdir/addpcis.o and noticed
the odd addends on REL16DX_HA.  They ought to both be -4.  The error
crept in due REL16DX_HA howto being pc-relative (as indeed it should
be), and code at gas/write.c:1001 after this comment
	      /* Make it pc-relative.  If the back-end code has not
		 selected a pc-relative reloc, cancel the adjustment
		 we do later on all pc-relative relocs.  */
*not* cancelling the pc-relative adjustment.  So I've made a dummy
non-relative split reloc so that the generic code handles this, rather
than attempting to add hacks later in md_apply_fix which would not be
very robust.  Having the new internal reloc also makes it easy to
support

 addpcis rx,sym@ha

as an equivalent to

 addpcis rx,(sym-0f)@ha
0:

The patch also fixes overflow checking, which must test whether the
addi will overflow too since @l relocs don't have any overflow check.

Lastly, since I was poking at md_apply_fix, I arranged to have the
generic gas/write.c code emit errors for subtraction expressions where
we lack reloc support.

include/
	* elf/ppc64.h (R_PPC64_16DX_HA): New.  Expand fake reloc comment.
	* elf/ppc.h (R_PPC_16DX_HA): Likewise.
bfd/
	* reloc.c (BFD_RELOC_PPC_16DX_HA): New.
	* elf64-ppc.c (ppc64_elf_howto_raw <R_PPC64_16DX_HA>): New howto.
	(ppc64_elf_reloc_type_lookup): Translate new bfd reloc.
	(ppc64_elf_ha_reloc): Correct overflow test on REL16DX_HA.
	(ppc64_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_howto_raw <R_PPC_16DX_HA>): New howto.
	(ppc_elf_reloc_type_lookup): Translate new bfd reloc.
	(ppc_elf_check_relocs): Handle R_PPC_16DX_HA to pacify gcc.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-ppc.c (md_assemble): Use BFD_RELOC_PPC_16DX_HA for addpcis.
	(md_apply_fix): Remove fx_subsy check.  Move code converting to
	pcrel reloc earlier and handle BFD_RELOC_PPC_16DX_HA.  Remove code
	emiiting errors on seeing fx_pcrel set on unexpected relocs, as
	that is done now by the generic code via..
	* config/tc-ppc.h (TC_FORCE_RELOCATION_SUB_LOCAL): ..this. Define.
	(TC_VALIDATE_FIX_SUB): Define.
ld/
	* testsuite/ld-powerpc/addpcis.d: Define ext1 and ext2 at
	limits of addpcis range.
2017-02-28 11:59:47 +10:30
Maciej W. Rozycki 0e39210161 MIPS/BFD: Also handle `jalr $0, $25' with R_MIPS_JALR
Interpret the `jalr $0, $25' instruction encoding with an R_MIPS_JALR
relocation attached as an alias to `jr $25' and convert the jump to an
equivalent branch where possible, consequently covering the MIPSr6
architecture for the purpose of this optimization too.

	bfd/
	* elfxx-mips.c (mips_elf_perform_relocation): Also handle the
	`jalr $0, $25' instruction encoding.

	gas/
	* testsuite/gas/mips/jalr4.s: Add `jalr $0, $25' instructions.
	* testsuite/gas/mips/jalr4.d: Adjust accordingly.  Remove MIPSr6
	encoding patterns.
	* testsuite/gas/mips/jalr4-n64.d: Likewise.
	* testsuite/gas/mips/mipsr6@jalr4.d: New test.
	* testsuite/gas/mips/mipsr6@jalr4-n32.d: New test.
	* testsuite/gas/mips/mipsr6@jalr4-n64.d: New test.

	ld/
	* testsuite/ld-mips-elf/jalr4.dd: Adjust for `jalr $0, $25'
	instructions.
	* testsuite/ld-mips-elf/jalr4-r6.dd: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2017-02-28 00:22:36 +00:00
Georg-Johann Lay fbf25dfdfd Place read-only data in the text section on AVR Tiny targets.
PR target/20849
        * scripttempl/avrtiny.sc (__RODATA_PM_OFFSET__): New define.
        (.rodata): New section.
        (.data): Remove .rodata*.
2017-02-27 17:05:53 +00:00
Alan Modra dd803a2430 Testsuite fixes for hppa64-hpux
HPUX has a different .comm syntax, and anything in the first column
is a label.

gas/
	* testsuite/gas/elf/strtab.s: Don't put directives on first
	column or continuation with labels not in first column.
ld/
	* testsuite/ld-elf/elf.exp: Xfail pr20995 tests on hppa64-hpux.
	Set up HPUX defsym.  Run pr14170 tests and build symbol3 objects,
	defining HPUX where necessary.  Define HPUX for implib tests.
	* testsuite/ld-elf/comm-data4.d: Run for hpux.
	* testsuite/ld-elf/endsym.d: Likewise.
	* testsuite/ld-elf/linkoncerdiff.d: Likewise.
	* testsuite/ld-elf/comm-data4.s: Add alternate .comm when HPUX.
	* testsuite/ld-elf/comm-data5.s: Likewise.
	* testsuite/ld-elf/endsym.s: Likewise.
	* testsuite/ld-elf/pr14170c.s: Likewise.
	* testsuite/ld-elf/symbol3.s: Likewise.
	* testsuite/ld-elf/implib.s: Likewise.  Don't start directives
	in first column.
	* testsuite/ld-elf/linkoncerdiff2.s: Don't use numeric labels.
	* testsuite/ld-elf/warn3.d: Run for hpux.
	* testsuite/ld-scripts/rgn-at10.d: Xfail for hpux.
	* testsuite/ld-scripts/rgn-at11.d: Likewise.
	* testsuite/ld-scripts/size-2.d: Remove xfail for hpux.
2017-02-25 19:13:34 +10:30
Maciej W. Rozycki c9f02c3e29 readelf: Fix incorrect "Version definition past end of section" message
Fix a commit 74e1a04b97 ("More fixes for reading corrupt ELF files.")
`readelf --version-info' regression that caused "Version definition past
end of section" to be always printed at the end, even with good section
data.

For example with the `mips-linux' target we get:

$ cat ver_def.s
	.data
	.globl	new_foo
	.type	new_foo, %object
new_foo:
	.symver	new_foo, foo@@ver_foo
$ cat ver_def.ver
{ global: *foo*; local: *; };
$ as -o ver_def.o ver_def.s
$ ld -e 0 --export-dynamic --version-script=ver_def.ver -o ver_def ver_def.o
$ readelf -V ver_def

Version symbols section '.gnu.version' contains 4 entries:
 Addr: 000000000000007e  Offset: 0x01007e  Link: 2 (.dynsym)
  000:   0 (*local*)       2 (ver_foo)       1 (*global*)      2 (ver_foo)

Version definition section '.gnu.version_d' contains 2 entries:
  Addr: 0x0000000000000088  Offset: 0x010088  Link: 3 (.dynstr)
  000000: Rev: 1  Flags: BASE   Index: 1  Cnt: 1  Name: ver_def
  0x001c: Rev: 1  Flags: none  Index: 2  Cnt: 1  Name: ver_foo
  Version definition past end of section
$

The cause is the `if (idx + ent.vd_next <= idx)' condition introduced to
ensure forward progress, which however always triggers for good version
definition section data as the last entry will have its `vd_next' value
set to 0.

Adjust the condition then, to say `if (idx + ent.vd_next < idx)' instead
and to ensure forward progress limit the number of entries processed to
the size of the version definition section, removing the problematic
message from output quoted above, while ensuring the original PR 17531
test case is still handled gracefully.

Add a suitable test case so that we have `readelf --version-info'
coverage; due to the lack of infrastructure needed to run the linker in
the `binutils' test suite and limited justification to implement it add
a new `readelf.exp' script to the `ld' test suite instead, intended to
gather any `readelf' test cases that require the linker to be run.  If
ever we decide to have linker infrastructure added to the `binutils'
test suite, then the script can be moved between the test suites.

	binutils/
	* readelf.c (process_version_sections) <SHT_GNU_verdef>: Limit
	the number of entries processed by the section size.  Don't
	break out of the loop if `ent.vd_next' is 0.

	ld/
	* testsuite/ld-elf/ver_def.d: New test.
	* testsuite/ld-elf/ver_def.ld: New test linker script.
	* testsuite/ld-elf/ver_def.ver: New test version script.
	* testsuite/ld-elf/ver_def.s: New test source.
	* testsuite/ld-elf/readelf.exp: New test script.
2017-02-24 13:48:10 +00:00
Maciej W. Rozycki 5d58c73379 MIPS/BFD: Remove duplicate NewABI JALR relocation handling
Remove separate original NewABI JALR relocation handling, introduced
with commit d06471104a ("relax jalr $t9 [R_MIPS_JALR symbol] to bal
symbol"), <https://sourceware.org/ml/binutils/2003-03/msg00394.html>,
and only used by LD with the `--relax' option specified, and rely solely
on `mips_elf_perform_relocation' code, which has been introduced with
commit 1367d393bb ("On the RM9000 convert jal to bal if in range"),
<https://www.sourceware.org/ml/binutils/2004-12/msg00088.html> and since
made more complete, across all the three ABIs.

Also remove the `--relax' option, now irrelevant, from the tests added
with the former commit.

	bfd/
	* elfxx-mips.h (_bfd_mips_relax_section): Remove prototype.
	* elfxx-mips.c (_bfd_mips_relax_section): Remove function.
	* elf64-mips.c (bfd_elf64_bfd_relax_section): Remove macro.
	* elfn32-mips.c (bfd_elf32_bfd_relax_section): Likewise.

	ld/
	* testsuite/ld-mips-elf/relax-jalr-n32.d: Remove `--relax'
	option.
	* testsuite/ld-mips-elf/relax-jalr-n32-shared.d: Likewise.
	* testsuite/ld-mips-elf/relax-jalr-n64.d: Likewise.
	* testsuite/ld-mips-elf/relax-jalr-n64-shared.d: Likewise.
2017-02-23 23:49:14 +00:00
Maciej W. Rozycki c1556ecd78 MIPS/BFD: Discard ineligible JALR relocations right away
Discard R_MIPS_JALR and R_MICROMIPS_JALR relocations associated with
jumps that cannot be converted to an equivalent branch right away in
`mips_elf_calculate_relocation' rather than letting them through to
`mips_elf_perform_relocation'.  This includes cross-mode jumps which
need to flip the ISA bit or jumps to a misaligned location that cannot
be encoded with a branch, in addition to preemptible symbol references
already handled.

Cross-mode jumps are actually already rejected as the conversion is made
in `mips_elf_perform_relocation', so in this case this change only saves
some processing.  Jumps to a misaligned location are however converted,
with bits causing misalignment lost, making resulting code functionally
different even if the lone effect is avoiding an address error exception
with an instruction fetch at the jump destination requested.

Add test cases suitable, also including GAS verification to confirm that
the JALR relocations explicitly requested have indeed been output in the
intermediate objects used.

	bfd/
	* elfxx-mips.c (mips_elf_calculate_relocation) <R_MIPS_JALR>
	<R_MICROMIPS_JALR>: Discard relocation if `cross_mode_jump_p'
	or misaligned.

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

	ld/
	* testsuite/ld-mips-elf/jalr4.dd: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2017-02-23 23:45:14 +00:00
Alan Modra 5499c7c71c Correct VLE 16D and SDAREL relocations
PR 20744
bfd/
	* elf32-ppc.c (ppc_elf_howto_raw): Correct dst_mask on all VLE
	16D relocations.
	(ppc_elf_vle_split16): Correct field mask and shift for 16D relocs.
	(ppc_elf_relocate_section): Correct calculation for VLE SDAREL
	relocs.
ld/
	* testsuite/ld-powerpc/vle-reloc-2.s: Use r6 for last insn of
	each group.
	* testsuite/ld-powerpc/vle-reloc-2.d: Update for above change
	and sdarel reloc fix.
2017-02-23 12:33:51 +10:30
Maciej W. Rozycki 902e9fc76a PR ld/20828: Move symbol version processing ahead of GC symbol sweep
Complement commit b531344c34 ("PR ld/20828: Reorder the symbol sweep
stage of section GC") and commit 81ff47b3a5 ("PR ld/20828: Fix linker
script symbols wrongly forced local with section GC") and move symbol
version processing ahead of the symbol sweep stage of section GC, all in
`bfd_elf_size_dynamic_sections', so that version symbols created stay in
the global scope and are not output as local symbols to the dynamic
symbol table in the presence of corresponding symbol definitions pulled
from a DSO involved in a link.

Consolidate the whole of symbol version processing into a single block
from all parts scattered across the function and rearranging the local
variables used as necessary, however leaving the setting of dynamic
entries associated with the DT_VERDEF, DT_VERDEFNUM, DT_VERNEED and
DT_VERNEEDNUM tags and the SEC_EXCLUDE flag for unused `.gnu.version'
section in the original places.

With the rearrangement of code blocks `Elf_Internal_Verneed *t' would
shadow the previous definition of `struct bfd_elf_version_tree *t', so
rename the former variable to `vn'.

	bfd/
	PR ld/20828
	* elflink.c (bfd_elf_size_dynamic_sections): Move symbol version
	processing ahead of the call to `elf_gc_sweep_symbol'.

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828-d.sd: New test.
	* testsuite/ld-elf/pr20828-e.sd: New test.
	* testsuite/ld-elf/pr20828-v.od: New test.
	* testsuite/ld-elf/pr20828-v.ver: New test version script.
	* testsuite/ld-elf/pr20828-v.ld: New test linker script.
	* testsuite/ld-elf/pr20828.ld: Add `.gnu.version' and
	`.gnu.version_d'.
	* testsuite/ld-elf/shared.exp: Run the new tests.
2017-02-22 18:16:28 +00:00
Nick Clifton 465197842a Fix compile time warning message in linker testsuite test.
* testsuite/ld-ifunc/pr18808b.c (bar): Fix compile time warning
	about non-void function returning without a result.
2017-02-21 11:00:21 +00:00
Alan Modra c48cfeddf7 PE ld -r script fixes
PR 15041
	* scripttempl/pe.sc: Don't combine sections for ld -r.
	* scripttempl/pep.sc: Likewise.
2017-02-21 00:14:03 +10:30
Alan Modra 246b91226b fix PR number 2017-02-20 21:31:02 +10:30
Alan Modra 74dc9032e7 Move .stack before debug sections
PR 20199
	* emulparams/elf32m32c.sh: Define STACK_ADDR and STACK_SENTINEL
	rather than using OTHER_SECTIONS.
	* emulparams/elf32mt.sh: Likewise.
	* emulparams/elf32rx.sh: Likewise.
	* emulparams/elf32rl78.sh: Likewise.  Use OTHER_SYMBOLS to
	define __rl78_abs__.
	* emulparams/shelf.sh: Define STACK_ADDR and STACK_SENTINEL
	rather than using OTHER_SECTIONS.
	* emulparams/shelf32.sh: Likewise.  Use OTHER_SECTIONS for .cranges.
	* emulparams/shelf64.sh: Unset OTHER_SECTIONS.
	* emulparams/shelf_nbsd.sh: Unset STACK_ADDR not OTHER_SECTIONS.
	* emulparams/shelf_uclinux.sh: Likewise.
	* emulparams/shlsymbian.sh: Unset STACK_ADDR.  Use OTHER_SYMBOLS
	to define _stack, not OTHER_SECTIONS.
	* scripttempl/elf.sc: Move STACK, TINY_DATA_SECTION, and
	TINY_BSS_SECTION before debug sections.  Add STACK_SENTINEL.
	* scripttempl/arclinux.sc: Likewise.
	* scripttempl/elf64hppa.sc: Likewise.
	* scripttempl/elfxtensa.sc: Likewise.
	* scripttempl/nds32elf.sc: Likewise.
	* scripttempl/armbpabi.sc: Move STACK before debug sections.
	* scripttempl/elf_chaos.sc: Likewise.
	* scripttempl/elfarc.sc: Delete STACK.
	* scripttempl/epiphany_4x4.sc: Delete STACK.  Move TINY_DATA_SECTION,
	TINY_BSS_SECTION, and .stack before debug sections.
2017-02-20 19:33:28 +10:30
Nick Clifton 67cecaba5f Fix documentation of the linker's --pop-state command line option.
PR ld/20825
	* ld.texinfo (Options): Add missing @item entry for --pop-state.
2017-02-17 16:31:09 +00:00
Alan Modra 262a40a540 Relax dwarf2 expected error match
* testsuite/ld-elf/dwarf2.err: Accept other errors between the
	multiple definition errors.
2017-02-17 18:02:40 +10:30
Alan Modra 002a5d4e58 Relax dwarf3 expected error match
* testsuite/ld-elf/dwarf2.err: Add missing newline at end.
	* testsuite/ld-elf/dwarf3.err: Likewise.  Allow match without filename.
2017-02-17 17:41:03 +10:30
Andrew Burgess 3239a4231f bfd: Improve lookup of file / line information for errors
When looking up file and line information (used from the linker to
report error messages) if no symbol is passed in, then use the symbol
list to look for a matching symbol.

If a matching symbol is found then use this to look up the file / line
information.

This should improve errors when looking up file / line information for
data sections.  Hopefully we should find a matching data symbol, which
should, in turn (we hope) match a DW_TAG_variable in the DWARF, this
should allow us to give accurate file / line errors for data symbols.

As the hope is to find a matching DW_TAG_variable in the DWARF then we
ignore section symbols, and prefer global symbols to locals.

bfd/ChangeLog:

	* dwarf2.c (_bfd_dwarf2_find_nearest_line): Perform symbol lookup
	before trying to fine matching file and line information.

ld/ChangeLog:

	* testsuite/ld-elf/shared.exp: Update expected results.
	* testsuite/ld-elf/dwarf2.err: Likewise
2017-02-16 13:06:14 +00:00
Andrew Burgess 90ed9b8bc1 bfd/dwarf: Improve use of previously loaded dwarf information
When parsing DWARF data in order to report file/line type error messages
we perform section placement to make section addresses unique within
relocatable object files.

Currently, if we reuse previously loaded (and cached) dwarf data then we
neglect to perform section placement, the result is that the section
addresses will not be unique, and we might, incorrectly associate an
address with the wrong debug information, and so report an incorrect
file and line number.

Further we neglect to check that that bfd for which we are looking up
debug information is actually the bfd for which the previous debug
information was loaded, it is possible that we will reuse previously
loaded debug information for a different bfd.

And finally, due to following of gnu_debuglink links in one bfd to
another, the process of checking that the cached debug information is
valid requires us to track the original bfd in the cached debug
information.  The original debug information here is either the bfd that
we're interested in, not the bfd we finally load the debug information
from.

bfd/ChangeLog:

	* dwarf2.c (struct dwarf2_debug): Add orig_bfd member.
	(_bfd_dwarf2_slurp_debug_info): If stashed debug information does
	not match current bfd, then reload debug information.  Record bfd
	we're loading debug info for in the stash.  If we have debug
	informatin in the cache then perform section placement before
	returning.

ld/ChangeLog:

	* testsuite/ld-elf/dwarf.exp (build_tests): Add new tests.
	* testsuite/ld-elf/dwarf2.err: New file.
	* testsuite/ld-elf/dwarf2a.c: New file.
	* testsuite/ld-elf/dwarf2b.c: New file.
	* testsuite/ld-elf/dwarf3.c: New file.
	* testsuite/ld-elf/dwarf3.err: New file.
2017-02-16 13:06:13 +00:00
Andrew Burgess 2bd7f877af ld: Add additional checking for warnings/errors in testsuite
This commit adds new actions to the run_cc_link_tests mechanism in the
linker testsuite.

Previously this procedure could take a parameter containing a regular
expression that would be matched against warnings from the linker.

After this commit the warnings parameter is removed, instead, the
actions list can contain the actions 'warning', 'error',
'warning_output', or 'error_output'.  The action names are chosen to
match the actions already present in the run_dump_test procedure.

These new actions allow for the current warning checking, but also allow
for checking of errors using a regular expression.  More interestingly,
the *_output actions allow for the warning/error patterns to be placed
in a separate file.

The small number of tests that make use of the warning parameter have
been updated to the new mechanism.  Later commits will make use of the
new features added in this commit.

ld/ChangeLog:

	* testsuite/lib/ld-lib.exp (run_cc_link_tests): Add warning,
	error, warning_output, and error_output actions.  Remove separate
	warnings parameter.
	* testsuite/ld-elf/shared.exp (build_tests): Updated to use
	'warning' action.
	* testsuite/ld-plugin/lto.exp (lto_link_tests): Likewise.
2017-02-16 13:06:12 +00:00
Alan Modra 37d7d56cae ld testsuite function pointer comparisons vs. hppa
ld/testsuite/ld-elf/check-ptr-eq.c fails for hppa, since function
pointers may point at plabels.  It isn't valid to cast two function
pointers to void* and then compare the void pointers.

	* testsuite/ld-elf/check-ptr-eq.c (check_ptr_eq): Change params
	from void pointers to function pointers.
	* testsuite/ld-elf/pr18718.c: Update to suit.
	* testsuite/ld-elf/pr18720a.c: Update to suit.
2017-02-16 23:10:09 +10:30
Alan Modra a8c75b765e hppa -z relro again
I misunderstood the hppa alias problem.  File offsets of segments need
to be such that no page is mapped twice with different permissions.
(Which still seems to me like something the kernel could fix, but
anyhow, this is not so difficult to achieve in ld.)

	PR 21000
bfd/
	* elf-bfd.h (struct elf_backend_data): Add no_page_alias.
	* elfxx-target.h (elf_backend_no_page_alias): Define.
	(elfNN_bed): Init new field.
	* elf.c (assign_file_positions_for_load_sections): If no_page_alias
	ensure PT_LOAD segment starts on a new page.
	* elf32-hppa.c (elf_backend_no_page_alias): Define.
ld/
	* testsuite/ld-elf/loadaddr1.d: Adjust for hppa file offsets.
	* testsuite/ld-elf/loadaddr2.d: Likewise.
	* testsuite/ld-elf/loadaddr3a.d: Likewise.
	* testsuite/ld-scripts/rgn-at5.d: Likewise.
2017-02-16 23:09:38 +10:30
Alan Modra a48cda7f86 Fix more powerpc testsuite source errors
* testsuite/ld-powerpc/vxworks1-lib.s: Correct addi to addic.
	* testsuite/ld-powerpc/vxworks1-lib.dd: Adjust to suit.
2017-02-16 22:39:51 +10:30
H.J. Lu 2a5684011e i386: Allow "lea foo@GOT, %reg" in PIC
"lea foo@GOT, %reg" is OK in PIC since it only loads the GOT offset
into register, which can be used later with a GOT base register to
get the value in the GOT entry.

bfd/

	PR ld/21168
	* elf32-i386.c (elf_i386_relocate_section): Allow
	"lea foo@GOT, %reg" in PIC.

ld/

	PR ld/21168
	* testsuite/ld-i386/i386.exp: Run pr21168.
	* testsuite/ld-i386/pr21168a.c: New file.
	* testsuite/ld-i386/pr21168b.S: Likewise.
2017-02-15 11:39:48 -08:00
H.J. Lu a5def14f1c Add a test for R_386_GOT32/R_386_GOT32X IFUNC reloc error
bfd/

	PR ld/20244
	* elf32-i386.c (elf_i386_relocate_section): Properly get IFUNC
	symbol name when reporting R_386_GOT32/R_386_GOT32X relocation
	error against local IFUNC symbol without a base register for
	PIC.

ld/

	PR ld/20244
	* testsuite/ld-i386/i386.exp: Run pr20244-4a, pr20244-4b and
	pr20244-4c.
	* testsuite/ld-i386/pr20244-4.s: New file.
	* testsuite/ld-i386/pr20244-4a.d: Likewise.
	* testsuite/ld-i386/pr20244-4b.d: Likewise.
	* testsuite/ld-i386/pr20244-4c.d: Likewise.
2017-02-15 11:11:40 -08:00
Maciej W. Rozycki ebf0b03c70 LD: vfinfo: Make clever formatters consistent WRT function name reporting
Remove an inconsistency in linker error message processing causing that
it depends on the ability to infer the name of the originating source
file whether or not the name of the offending function is repeated by
clever formatters for each issue reported within the function.

Taking the `ld/testsuite/ld-powerpc/tocopt7.s' test case source as an
example and the `powerpc-linux' target we have:

$ as -gdwarf2 -o tocopt.o -a64 tocopt.s
$ ld -o tocopt -melf64ppc tocopt.o
tocopt.o: In function `_start':
tocopt.s:35:(.text+0x14): toc optimization is not supported for 0x3fa00000 instruction.
tocopt.s:49:(.text+0x34): toc optimization is not supported for 0x3fa00000 instruction.
$

vs:

$ as -o tocopt.o -a64 tocopt.s
$ ld -o tocopt -melf64ppc tocopt.o
tocopt.o: In function `_start':
(.text+0x14): toc optimization is not supported for 0x3fa00000 instruction.
tocopt.o: In function `_start':
(.text+0x34): toc optimization is not supported for 0x3fa00000 instruction.
$

Similarly with the `mips-linux' target and this source:

$ cat jal-global-multi-overflow.s
	.text
	.set	noreorder
	.space	0x2000

	.align	4
	.globl	foo
	.ent	foo
foo:
	jal	bar
	 nor	$0, $0
	jal	bar
	 nor	$0, $0
	.end	foo

	.space	0x1ff0

	.align	4
	.globl	bar
	.ent	bar
bar:
	jal	foo
	 nor	$0, $0
	jal	foo
	 nor	$0, $0
	.end	bar
$ as -o jal-global-multi-overflow.o jal-global-multi-overflow.s
$ ld -Ttext 0x1fffd000 -e foo -o jal-global-multi-overflow jal-global-multi-overflow.o
jal-global-multi-overflow.o: In function `foo':
(.text+0x2000): relocation truncated to fit: R_MIPS_26 against `bar'
jal-global-multi-overflow.o: In function `foo':
(.text+0x2008): relocation truncated to fit: R_MIPS_26 against `bar'
jal-global-multi-overflow.o: In function `bar':
(.text+0x4000): relocation truncated to fit: R_MIPS_26 against `foo'
jal-global-multi-overflow.o: In function `bar':
(.text+0x4008): relocation truncated to fit: R_MIPS_26 against `foo'
$

Not only this is inconsistent, but it causes output clutter as well with
redundant information.

The cause for this is a check in `vfinfo' the intent of which is to
print the function heading whenever (among others) the name of the
source file has changed, which however does not take into account a
situation where the name couldn't have been established both now and
previously.

Adjust the check then for this situation, yielding:

$ as -o tocopt.o -a64 tocopt.s
$ ld -o tocopt -melf64ppc tocopt.o
tocopt.o: In function `_start':
(.text+0x14): toc optimization is not supported for 0x3fa00000 instruction.
(.text+0x34): toc optimization is not supported for 0x3fa00000 instruction.
$

and:

$ as -o jal-global-multi-overflow.o jal-global-multi-overflow.s
$ ld -Ttext 0x1fffd000 -e foo -o jal-global-multi-overflow jal-global-multi-overflow.o
jal-global-multi-overflow.o: In function `foo':
(.text+0x2000): relocation truncated to fit: R_MIPS_26 against `bar'
(.text+0x2008): relocation truncated to fit: R_MIPS_26 against `bar'
jal-global-multi-overflow.o: In function `bar':
(.text+0x4000): relocation truncated to fit: R_MIPS_26 against `foo'
(.text+0x4008): relocation truncated to fit: R_MIPS_26 against `foo'
$

respectively instead.  Adjust the test suite accordingly.

	ld/
	* ldmisc.c (vfinfo): Don't print the function name again either
	if no source file name has been found both now and previously.
	* testsuite/ld-cris/tls-err-20x.d: Adjust accordingly.
	* testsuite/ld-mips-elf/mode-change-error-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-mips16.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-micromips.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-r6-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-2.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-r6-2.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-2.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-mips16.d:
	Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-micromips.d:
	Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-ignore-r6-1.d:
	Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-mips16-1.d:
	Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-micromips-1.d:
	Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-3.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jump.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jump-mips16.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jump-micromips.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-lwpc-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-ldpc-1.d: Likewise.
	* testsuite/ld-powerpc/tocopt.out: Likewise.
	* testsuite/ld-powerpc/tocopt7.out: Likewise.
2017-02-15 13:41:51 +00:00
Maciej W. Rozycki befe814dd9 LD: vfinfo: Remove static NULL initializers
Remove static NULL initializers, moving the respective variables from
data to BSS and saving some storage space.

	ld/
	* ldmisc.c (vfinfo) <'H'>: Remove static NULL initializers.
2017-02-15 13:40:08 +00:00
Igor Kudrin defe6f56b7 Use Windows style directory separators when running sysroot tests under MinGW and Cygwin.
* testsuite/ld-scripts/sysroot-prefix.exp
	(get_base_dir_for_scripts): New function.
	(run_sysroot_prefix_test): Use get_base_dir_for_scripts.
2017-02-15 09:13:56 +00:00
Palmer Dabbelt 10ddfe62f8 Don't use "_gp" on RISC-V, use "_global_pointer$" instead
"_gp" could conflict with ABI-complient code.  While it's probably OK
because MIPS uses this name, we figured it'd be good to clean this up
before a release with RISC-V in it.

ld/ChangeLog:

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

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

bfd/ChangeLog:

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

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

ld/ChangeLog:

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

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

(current) vs:

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

(corrected).  No functional change.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

and consequently removing a:

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

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

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

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

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

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

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

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

ld	* testsuite/ld-aarch64/aarch64-elf.exp: Run new tests.
	* testsuite/ld-aarch64/tls-desc-ie-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-all-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-gd-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-gdesc-le-2-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-gdesc-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-ie-le-2-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-ie-le-3-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-relax-ie-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-desc-le-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d: New test.
	* testsuite/ld-aarch64/tls-tiny-gd-le-ilp32.d: New test.
2017-01-23 17:07:13 +00:00
Nick Clifton 8069955ee0 Updated Irish translation for ld and Swedish translation for gas. 2017-01-23 13:32:12 +00:00
Maciej W. Rozycki 1e5f45bb15 PR ld/20828: Work around RISC-V failures
Complement commit 81ff47b3a5 ("PR ld/20828: Fix linker script symbols
wrongly forced local with section GC") and add `.plt' to the list of
output sections created, fixing:

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

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

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

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

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

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828.ld: Rename `_fdata' and `_edata' to
	`fdata' and `edata' respectively.
	* testsuite/ld-elf/pr20828.ver: Adjust accordingly.
	* testsuite/ld-elf/pr20828-a.sd: Likewise.
	* testsuite/ld-elf/pr20828-b.sd: Likewise.
	* testsuite/ld-elf/pr20828-c.sd: Likewise.
2017-01-23 11:26:06 +00:00
Maciej W. Rozycki adcbdc63e5 PR ld/20828: Relax symbol ordering in tests
Complement commit 81ff47b3a5 ("PR ld/20828: Fix linker script symbols
wrongly forced local with section GC") and make tests check for the
presence of global `_fdata' and `_edata' symbols separately, removing
any dependency on symbol table ordering for tests to succeed and
removing:

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

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

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

Rename dump pattern files accordingly for consistency.

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

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

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

In non-wide more the behaviour is completely unchanged.

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

binutils/ChangeLog:

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

ld/ChangeLog:

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

	ld/
	PR ld/20995
	* testsuite/ld-elf/elf.exp: Set GAS flags correctly for the
	`mips*-*-*' target and `pr20995' and `pr20995-2' tests.
2017-01-18 23:19:07 +00:00
Maciej W. Rozycki 81ff47b3a5 PR ld/20828: Fix linker script symbols wrongly forced local with section GC
Fix a generic ELF linker regression introduced with a chain of changes
made to unused input section garbage collection:

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

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

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

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

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

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

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

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828-1.sd: New test.
	* testsuite/ld-elf/pr20828-2a.sd: New test.
	* testsuite/ld-elf/pr20828-2b.sd: New test.
	* testsuite/ld-elf/pr20828.ld: New test linker script.
	* testsuite/ld-elf/pr20828.ver: New test version script.
	* testsuite/ld-elf/pr20828.s: New test source.
	* testsuite/ld-elf/shared.exp: Run the new test.
2017-01-18 18:30:34 +00:00
Maciej W. Rozycki 9e009953a5 PR gas/20649: MIPS: Fix GOT16/LO16 reloc pairing with comdat sections
Correct a regression from commit 8614eeee67 ("Traditional MIPS
patches"), <https://sourceware.org/ml/binutils/2000-07/msg00018.html>,
which caused symbols in linkonce or what is these days known as comdat
sections to be treated as external for the purpose of PIC relocation
generation even if their binding remains STB_LOCAL.  This in turn
disabled GOT16/LO16 relocation pairing with references to such symbols,
as no complementing LO16 relocation is expected for external GOT16
references in the o32 ABI, which ultimately leads to link errors, e.g.:

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

as with the LD test case included with this change.

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

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

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

bfd/

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

ld/

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

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

instead of

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

its unwind info should be

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

bfd/

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

ld/

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

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

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

bfd/

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

ld/

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

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

bfd/

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

ld/

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

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

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

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

ld/ChangeLog:

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

Thanks to Alan Morda for finding the problem!

ld/ChangeLog

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

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

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

	* testsuite/ld-elf/audit.exp: Check for shared lib support.
	* testsuite/ld-elf/compress.exp: Likewise.
	* testsuite/ld-elf/dwarf.exp: Likewise.
	* testsuite/ld-elf/shared.exp: Likewise.
	* testsuite/ld-elf/wrap.exp: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Check $CXX exists.
2017-01-04 09:39:12 +10:30
Alan Modra a44d0bd787 Check ld_compile return status
* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Do not
	allow test to continue after compilation errors.
	(run_cc_link_tests): Likewise.
2017-01-03 23:04:48 +10:30
Dimitar Dimitrov 27c3ce29f8 Fix PRU LD for --enable-targets=all config option
I noticed that PRU LD is broken when BFD is configured
with --enable-targets=all.  This patch fixes it, and takes the
opportunity to clean the epruelf.c dependencies.

	* Makefile.am (ALL_EMULATION_SOURCES): Add epruelf.c.
	(epruelf.c): Remove unneeded dependencies.
	* Makefile.in: Regenerate

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2017-01-03 17:35:45 +10:30
Alan Modra 8cfc7cf8c2 Add -rpath-link to various tests
Needed for cross-builds without --sysroot, where USE_LIBPATH isn't
set.  See elf32.em after_open.  Perhap ld ought to look at -rpath in
this case?

	* testsuite/ld-elf/shared.exp: Add -rpath-link and -no-as-needed
	to various tests.
	* testsuite/ld-elfweak/elfweak.exp: Likewise.
	* testsuite/ld-elfvers/vers.exp (vers19): Fix -rpath-link option.
2017-01-03 12:36:02 +10:30
Alan Modra 4ce6ca2c78 Don't run C tests in ld testsuite unless we have a C compiler
Removing the [isnative] check requires that we test for a C compiler.

	* testsuite/ld-elf/elf.exp: Check that $CC exists before C tests.
	* testsuite/ld-pie/pie.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Likewise.
2017-01-03 11:47:47 +10:30
Alan Modra d981640286 Run more ld tests when not native
Many of the ld tests are not run for cross builds, in some cases
because the test needs to run a newly linked executable, and in others
simply because it was easier to write the test for native only.  Even
when a test needs to run, it's good to compile and link to exercise
the linker.  So that's what this patch does.  I've also rid us of
the old ld_link procedure with all the HOSTING_CRT0 etc. setup.  It's
much simpler to just link with $CC.

This does mean that a cross build with cross-compiler installed but
no cross C-library will give lots of failures.  If that turns out to
be too annoying, I guess we can write a tcl procedure to detect it and
not run all the extra tests.

	* Makefile.am (bootstrap): Delete rule.
	(ld-partial, ld1, ld1-full, ld2, ld3): Likewise.
	(HOSTING_CRT0, HOSTING_SCRT0): Don't define.
	(HOSTING_LIBS, HOSTING_SLIBS, HOSTING_EMU): Likewise.
	* configure.ac (HOSTING_CRT0, HOSTING_SCRT0): Don't define.
	(HOSTING_LIBS, HOSTING_SLIBS): Likewise.
	* configure.host (HOSTING_CRT0, HOSTING_LIBS): Don't define.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* testsuite/config/default.exp (get_link_files): Delete.
	(HOSTING_CRT0, HOSTING_SCRT0, HOSTING_LIBS, HOSTING_SLIBS): Don't
	define.
	(ld_simple_link): Delete.
	* testsuite/lib/ld-lib.exp (default_ld_link): Delete
	(default_ld_simple_link): Rename to default_ld_link.
	(ld_simple_link_defsyms): Rename to ld_link_defsyms.
	(run_ld_link_tests): Use ld_link, not ld_simple_link.
	(run_cc_link_tests): Likewise.
	(run_ld_link_exec_tests): Use $CC or $CXX to link, not $ld.
	Don't run exe when not native, and return unsupported.
	* testsuite/ld-bootstrap/bootstrap.exp: Create gccld1 etc. dirs.
	Link ld1 etc. using $CC.
	* testsuite/ld-cdtest/cdtest.exp: Link cdtest using $CC.
	* testsuite/ld-checks/checks.exp: Use ld_link, not ld_simple_link.
	* testsuite/ld-cygwin/exe-export.exp: Likewise.
	* testsuite/ld-elf/binutils.exp: Likewise.
	* testsuite/ld-elf/eh-group.exp: Likewise.
	* testsuite/ld-elf/exclude.exp: Likewise.
	* testsuite/ld-elf/frame.exp: Likewise.
	* testsuite/ld-elf/sec-to-seg.exp: Likewise.
	* testsuite/ld-elf/tls_common.exp: Likewise.
	* testsuite/ld-elfcomm/elfcomm.exp: Likewise.
	* testsuite/ld-fastcall/fastcall.exp: Likewise.
	* testsuite/ld-gc/gc.exp: Likewise.
	* testsuite/ld-ifunc/binutils.exp: Likewise.
	* testsuite/ld-mep/mep.exp: Likewise.
	* testsuite/ld-mips-elf/mips-elf-flags.exp: Likewise.
	* testsuite/ld-mn10300/mn10300.exp: Likewise.
	* testsuite/ld-nios2/nios2.exp: Likewise.
	* testsuite/ld-pe/pe-compile.exp: Likewise.
	* testsuite/ld-pe/pe-run.exp: Likewise.
	* testsuite/ld-pe/pe-run2.exp: Likewise.
	* testsuite/ld-plugin/plugin.exp: Likewise.
	* testsuite/ld-scripts/align.exp: Likewise.
	* testsuite/ld-scripts/alignof.exp: Likewise.
	* testsuite/ld-scripts/assert.exp: Likewise.
	* testsuite/ld-scripts/defined.exp: Likewise.
	* testsuite/ld-scripts/extern.exp: Likewise.
	* testsuite/ld-scripts/log2.exp: Likewise.
	* testsuite/ld-scripts/map-address.exp: Likewise.
	* testsuite/ld-scripts/phdrs.exp: Likewise.
	* testsuite/ld-scripts/phdrs2.exp: Likewise.
	* testsuite/ld-scripts/script.exp: Likewise.
	* testsuite/ld-scripts/section-flags.exp: Likewise.
	* testsuite/ld-scripts/sizeof.exp: Likewise.
	* testsuite/ld-scripts/sysroot-prefix.exp: Likewise.
	* testsuite/ld-scripts/weak.exp: Likewise.
	* testsuite/ld-selective/selective.exp: Likewise.
	* testsuite/ld-sh/sh.exp: Likewise.
	* testsuite/ld-sh/sh64/relax.exp: Likewise.
	* testsuite/ld-sh/sh64/relfail.exp: Likewise.
	* testsuite/ld-srec/srec.exp: Likewise.
	* testsuite/ld-tic6x/tic6x.exp: Likewise.
	* testsuite/ld-undefined/weak-undef.exp: Likewise.
	* testsuite/ld-versados/versados.exp: Likewise.
	* testsuite/ld-x86-64/dwarfreloc.exp: Likewise.
	* testsuite/ld-xtensa/coalesce.exp: Likewise.
	* testsuite/ld-xtensa/diff_overflow.exp: Likewise.
	* testsuite/ld-xtensa/lcall.exp: Likewise.
	* testsuite/ld-elf/audit.exp: Run non-native too.
	* testsuite/ld-elf/compress.exp: Likewise.  Replace ld options with
	gcc -Wl, options.
	* testsuite/ld-elf/dwarf.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.  Add -Wl,--no-as-needed to some tests.
	* testsuite/ld-elf/elf.exp: Run non-native too.  Formatting.
	* testsuite/ld-elf/indirect.exp: Run non-native too.  Add
	-Wl,--no-as-needed to most tests.
	* testsuite/ld-elf/shared.exp: Run non-native too.  Use braces
	to simplify quoting.  Set run_tests using [list] rather than
	brace assignment to expand $extralibs.  Add -Wl,--no-as-needed
	to many test.  Prefix ld options with -Wl,.
	(mix_pic_and_non_pic): Don't run exe if not native.
	* testsuite/ld-elf/wrap.exp: Run non-native too.  Add
	-Wl,--no-as-needed and prefix ld options with -Wl,.
	* testsuite/ld-elfvers/vers.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	(visibility_test): Don't run exe if not native.
	* testsuite/ld-elfweak/elfweak.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.
	(build_exec): Don't run exe if not native.
	* testsuite/ld-ifunc/ifunc.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.  Link using $CC.  Add -Wl,--no-as-needed
	to some tests and prefix ld options with -Wl,.  Expect GNU
	for hppa-linux even when no ifuncs.  Delete cleanup.
	* testsuite/ld-pie/pie.exp: Run non-native too.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.  Use ld_link,
	not ld_simple_link.
	(shared_test): Don't run exe if not native.
	* testsuite/ld-size/size.exp: Run non-native too.  Add
	-Wl,--no-as-needed to some tests.  Prefix ld options with -Wl,.
	* testsuite/ld-unique/unique.exp: Run non-native too.  Use ld_link,
	not ld_simple_link.  Link using $CC.  Add -Wl,--no-as-needed
	to some tests and prefix ld options with -Wl,.  Expect GNU
	for hppa-linux even when no unique syms.  Delete cleanup.
	* testsuite/ld-x86-64/tls.exp: Add -Wl,--no-as-needed to some
	tests and prefix ld options with -Wl,.
	* testsuite/ld-x86-64/x86-64.exp: Use ld_link, not ld_simple_link.
	Add -Wl,--no-as-needed to some tests.  Prefix ld options with -Wl,.
2017-01-02 23:48:08 +10:30
Alan Modra 64859e1487 Support -z relro on metag
* emulparams/elf32metag.sh (COMMONPAGESIZE): Define.
2017-01-02 22:44:29 +10:30
Alan Modra f5657270bd Support -z relro on hppa
PR ld/21000
	* emulparams/hppalinux.sh (DATA_ADDR, SHLIB_DATA_ADDR): Don't define.
	(DATA_SEGMENT_ALIGN, DATA_SEGMENT_END, DATA_SEGMENT_RELRO_END): Define.
	* scripttempl/elf.sc: Don't define the above if DATA_SEGMENT_ALIGN
	is already defined.
2017-01-02 22:42:45 +10:30
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Alan Modra 5c1ad6b5bb ChangeLog rotation 2017-01-02 13:55:05 +10:30
Dimitar Dimitrov 0220170b4d PRU LD Port
* NEWS: Mention new PRU target.
	* Makefile.am: Add PRU target.
	* configure.tgt: Ditto.
	* emulparams/pruelf.sh: New file.
	* emultempl/pruelf.em: New file.
	* scripttempl/pru.sc: New file.
	* Makefile.in: Regenerate.
	* testsuite/ld-pru/emit-relocs-1.d: New PRU testcase file.
	* testsuite/ld-pru/emit-relocs-1.ld: Ditto.
	* testsuite/ld-pru/emit-relocs-1a.s: Ditto.
	* testsuite/ld-pru/emit-relocs-1b.s
	* testsuite/ld-pru/ldi32.d: Ditto.
	* testsuite/ld-pru/ldi32.s: Ditto.
	* testsuite/ld-pru/ldi32_symbol.s: Ditto.
	* testsuite/ld-pru/norelax_ldi32-data.d: Ditto.
	* testsuite/ld-pru/norelax_ldi32-dis.d: Ditto.
	* testsuite/ld-pru/pcrel_s10.d: Ditto.
	* testsuite/ld-pru/pcrel_s10.s: Ditto.
	* testsuite/ld-pru/pcrel_s10_label.s: Ditto.
	* testsuite/ld-pru/pcrel_u8-illegal.d: Ditto.
	* testsuite/ld-pru/pcrel_u8-illegal.s: Ditto.
	* testsuite/ld-pru/pcrel_u8-illegal2.d: Ditto.
	* testsuite/ld-pru/pcrel_u8-illegal2.s: Ditto.
	* testsuite/ld-pru/pcrel_u8-illegal3.d: Ditto.
	* testsuite/ld-pru/pcrel_u8-illegal3.s: Ditto.
	* testsuite/ld-pru/pcrel_u8.d: Ditto.
	* testsuite/ld-pru/pcrel_u8.s: Ditto.
	* testsuite/ld-pru/pcrel_u8_label.s: Ditto.
	* testsuite/ld-pru/pmem.d: Ditto.
	* testsuite/ld-pru/pmem.s: Ditto.
	* testsuite/ld-pru/pmem_symbol.s: Ditto.
	* testsuite/ld-pru/pru.exp: Ditto.
	* testsuite/ld-pru/relax_ldi32-data.d: Ditto.
	* testsuite/ld-pru/relax_ldi32-dis.d: Ditto.
	* testsuite/ld-pru/relax_ldi32.s: Ditto.
	* testsuite/ld-pru/relax_ldi32_symbol.s: Ditto.
	* testsuite/ld-pru/reloc.d: Ditto.
	* testsuite/ld-pru/reloc.s: Ditto.
	* testsuite/ld-pru/reloc_symbol.s: Ditto.
	* testsuite/ld-pru/u16.d: Ditto.
	* testsuite/ld-pru/u16.s: Ditto.
	* testsuite/ld-pru/u16_symbol.s: Ditto.

PRU does not export __end symbol because it is ambiguous for it.
Users are expected to use instead the section markers __text_end,
__data_end, __bss_end or __noinit_end.

	* testsuite/lib/ld-lib.exp (check_shared_lib_support): No shared
	libraries are supported for PRU.
	(check_gc_sections_available): Mark PRU as not supported.
	* testsuite/ld-elf/eh-frame-hdr.d: Disable for PRU.
	* testsuite/ld-elf/endsym.d: Likewise.
	* testsuite/ld-elf/group8a.d: Likewise.
	* testsuite/ld-elf/group8b.d: Likewise.
	* testsuite/ld-elf/group9a.d: Likewise.
	* testsuite/ld-elf/group9b.d: Likewise.
	* testsuite/ld-elf/merge.d: Likewise.
	* testsuite/ld-elf/pr12851.d: Likewise.
	* testsuite/ld-elf/pr14926.d: Likewise.
	* testsuite/ld-elf/sec-to-seg.exp: Likewise.
	* testsuite/ld-elf/sec64k.exp: Mark sec64k case as too big for PRU.
	* testsuite/ld-srec/srec.exp (run_srec_test): Add setup for PRU.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2016-12-31 12:04:11 +10:30
Dimitar Dimitrov 517c416698 ld testsuite: Sanitize output from ld
Leading dashes from an LD error message confuse send_log, because the
string is taken to be an option.

This patch fixes the following DejaGnu error:

  --defsym:1: undefined symbol `foo2' referenced in expression
  failed with: <--defsym:1: undefined symbol `foo2' referenced in expression>, no expected output
  ERROR: tcl error sourcing .../ld/testsuite/ld-gc/gc.exp.
  ERROR: usage: send [args] string
      while executing
  "send_log "$comp_output\n""
      (procedure "run_dump_test" line 376)

	* testsuite/lib/ld-lib.exp (run_dump_test): Pass -- to send_log.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2016-12-31 12:00:42 +10:30
Alan Modra 9acc85a62e Use dynrelro for symbols in relro sections too
PR ld/20995
bfd/
	* elflink.c (elf_link_add_object_symbols): Mark relro sections
	in dynamic objects SEC_READONLY.
ld/
	* testsuite/ld-elf/pr20995c.s: New test file.
	* testsuite/ld-elf/pr20995-2so.r: Likewise.
	* testsuite/ld-elf/elf.exp: Run it.
2016-12-28 22:10:38 +10:30
Alan Modra 5474d94f03 dynrelro section for read-only dynamic symbols copied into executable
Variables defined in shared libraries are copied into an executable's
.bss section when code in the executable is non-PIC and thus would
require dynamic text relocations to access the variable directly in
the shared library.  Recent x86 toolchains also copy variables into
the executable to gain a small speed improvement.

The problem is that if the variable was originally read-only, the copy
in .bss is writable, potentially opening a security hole.  This patch
cures that problem by putting the copy in a section that becomes
read-only after ld.so relocation, provided -z relro is in force.

The patch also fixes a microblaze linker segfault on attempting to
use dynamic bss variables.

bfd/
	PR ld/20995
	* elf-bfd.h (struct elf_link_hash_table): Add sdynrelro and
	sreldynrelro.
	(struct elf_backend_data): Add want_dynrelro.
	* elfxx-target.h (elf_backend_want_dynrelro): Define.
	(elfNN_bed): Update initializer.
	* elflink.c (_bfd_elf_create_dynamic_sections): Create
	sdynrelro and sreldynrelro sections.
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Place variables
	copied into the executable from read-only sections into sdynrelro.
	(elf32_arm_size_dynamic_sections): Handle sdynrelro.
	(elf32_arm_finish_dynamic_symbol): Select sreldynrelro for
	dynamic relocs in sdynrelro.
	(elf_backend_want_dynrelro): Define.
	* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol)
	(elf32_hppa_size_dynamic_sections, elf32_hppa_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol)
	(elf_i386_size_dynamic_sections, elf_i386_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-metag.c (elf_metag_adjust_dynamic_symbol)
	(elf_metag_size_dynamic_sections, elf_metag_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol)
	(microblaze_elf_size_dynamic_sections)
	(microblaze_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_symbol)
	(nios2_elf32_adjust_dynamic_symbol)
	(nios2_elf32_size_dynamic_sections)
	(elf_backend_want_dynrelro): As above.
	* elf32-or1k.c (or1k_elf_finish_dynamic_symbol)
	(or1k_elf_adjust_dynamic_symbol, or1k_elf_size_dynamic_sections)
	(elf_backend_want_dynrelro): As above.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol)
	(ppc_elf_size_dynamic_sections, ppc_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol)
	(elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol)
	(elf32_tic6x_size_dynamic_sections)
	(elf32_tic6x_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol)
	(tilepro_elf_size_dynamic_sections)
	(tilepro_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol)
	(ppc64_elf_size_dynamic_sections, ppc64_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol)
	(elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol)
	(elf_x86_64_size_dynamic_sections)
	(elf_x86_64_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol)
	(elfNN_aarch64_size_dynamic_sections)
	(elfNN_aarch64_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elfnn-riscv.c (riscv_elf_adjust_dynamic_symbol)
	(riscv_elf_size_dynamic_sections, riscv_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol)
	(_bfd_mips_elf_size_dynamic_sections)
	(_bfd_mips_vxworks_finish_dynamic_symbol): As above.
	* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol)
	(_bfd_sparc_elf_size_dynamic_sections)
	(_bfd_sparc_elf_finish_dynamic_symbol): As above.
	* elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol)
	(tilegx_elf_size_dynamic_sections)
	(tilegx_elf_finish_dynamic_symbol): As above.
	* elf32-mips.c (elf_backend_want_dynrelro): Define.
	* elf64-mips.c (elf_backend_want_dynrelro): Define.
	* elf32-sparc.c (elf_backend_want_dynrelro): Define.
	* elf64-sparc.c (elf_backend_want_dynrelro): Define.
	* elf32-tilegx.c (elf_backend_want_dynrelro): Define.
	* elf64-tilegx.c (elf_backend_want_dynrelro): Define.
	* elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol): Tidy.
	(microblaze_elf_size_dynamic_sections): Handle sdynbss.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Make use
	of linker shortcuts to dynamic sections rather than comparing
	names.  Correctly set "got" flag.
ld/
	PR ld/20995
	* testsuite/ld-arm/farcall-mixed-app-v5.d: Update to suit changed
	stub hash table traversal caused by section id increment.  Accept
	the previous output too.
	* testsuite/ld-arm/farcall-mixed-app.d: Likewise.
	* testsuite/ld-arm/farcall-mixed-lib-v4t.d: Likewise.
	* testsuite/ld-arm/farcall-mixed-lib.d: Likewise.
	* testsuite/ld-elf/pr20995a.s, * testsuite/ld-elf/pr20995b.s,
	* testsuite/ld-elf/pr20995.r: New test.
	* testsuite/ld-elf/elf.exp: Run it.
2016-12-26 13:47:51 +10:30
Alan Modra 09a1b0e943 Correct .dynbss in script
The only target that renames .bss is tic6x, turning .bss into .far,
and .sbss into .bss.  .dynbss is not renamed to .dynfar by BFD.

	* scripttempl/elf.sc: Don't use $BSS_NAME in .dynbss.
2016-12-26 13:42:20 +10:30
Tristan Gingold 99b5dbf2e7 Bump version to 2.28.51
bfd/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

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

binutils/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

gas/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

gprof/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

ld/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

opcodes/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.
2016-12-23 09:50:53 +01:00
Tristan Gingold 9703a4ef4d Add marker in NEWS files
binutils/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.28.

gas/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.28.

ld/
2016-12-23  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.28.
2016-12-23 09:43:13 +01:00
Tristan Gingold e0e7a9d436 Regenerate pot files. 2016-12-23 09:32:28 +01:00
Alan Modra ab55d1a098 Don't call "error" in sysroot-prefix.exp
We don't want to report a test failure as a tcl error.

	* testsuite/ld-scripts/sysroot-prefix.exp (sysroot_prefix_test_setup):
	Call perror rather than error on "as" or "ar" failures.
2016-12-22 15:20:32 +10:30
Igor Kudrin 9ef7906f20 Do not add padding if an output section is marked as ignored
* ldlang.c (size_input_section): Avoid calling insert_pad
	if output_section_statement->ignored is set.
2016-12-22 00:12:36 +10:30
Alan Modra 4e25adb395 Remove high bit set characters
gas/
	* doc/c-lm32.texi: Fix chars with high bit set.
	* testsuite/gas/bfin/vector2.s: Likewise.
gold/
	* arm.cc: Fix comment chars with high bit set.
include/
	* coff/pe.h: Fix comment chars with high bit set.
	* opcode/xgate.h: Likewise.
ld/
	* testsuite/ld-scripts/sysroot-prefix.exp: Fix chars with high bit set.
2016-12-21 19:18:46 +10:30
fincs 221855059a Implement and document --gc-keep-exported
include/
	* bfdlink.h (struct bfd_link_info): Add gc_keep_exported.
bfd/
	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Add handling
	for info->gc_keep_exported.
	(bfd_elf_gc_sections): Likewise.
ld/
	* ld.texinfo: Document --gc-keep-exported.
	* ldlex.h (enum option_values): Add OPTION_GC_KEEP_EXPORTED.
	* lexsup.c (parse_args): Add handling for --gc-keep-exported.
2016-12-16 13:49:03 +10:30
Yury Norov c1fc2d7ee5 ld: aarch64: fix TLS relaxation where TCB_SIZE is used
TCB_SIZE is 2*sizeof(void *), which is 0x10 for lp64, and 0x8 for
ilp32. During relaxation, ld goes to do a replace:
bl   __tls_get_addr => add R0, R0, TCB_SIZE

But actual implementation is:
bfd_putl32 (0x91004000, contents + rel->r_offset + 4);

Which is equivalent of add x0, x0, 0x10. This is wrong for ilp32.

The possible fix for it is:
bfd_putl32 (0x91000000 | (TCB_SIZE<<10), contents + rel->r_offset + 4);

But ilp32 also needs w-registers, so it's simpler to put proper
instruction in #if/#else condition.

There are 2 such relaxations in elfNN_aarch64_tls_relax(), and so 2 new
tests added for ilp32 mode to test it.

Yury

	* bfd/elfnn-aarch64.c: fix TLS relaxations for ilp32 where
	TCB_SIZE is used.
	* ld/testsuite/ld-aarch64/aarch64-elf.exp: Add tests for the case.
	* ld/testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d: New file.
	* ld/testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d: New file.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
2016-12-14 12:00:59 +05:30
Yury Norov 98fa61facf Revert "ld: aarch64: fix TLS relaxation where TCB_SIZE is used"
This reverts commit 6650f7bd18.
2016-12-14 11:56:54 +05:30
Yury Norov 6650f7bd18 ld: aarch64: fix TLS relaxation where TCB_SIZE is used
TCB_SIZE is 2*sizeof(void *), which is 0x10 for lp64, and 0x8 for
ilp32. During relaxation, ld goes to do a replace:
bl   __tls_get_addr => add R0, R0, TCB_SIZE

But actual implementation is:
bfd_putl32 (0x91004000, contents + rel->r_offset + 4);

Which is equivalent of add x0, x0, 0x10. This is wrong for ilp32.

The possible fix for it is:
bfd_putl32 (0x91000000 | (TCB_SIZE<<10), contents + rel->r_offset + 4);

But ilp32 also needs w-registers, so it's simpler to put proper
instruction in #if/#else condition.

THere are 2 such relaxations in elfNN_aarch64_tls_relax(), and so 2 new
tests added for ilp32 mode to test it.

Yury
2016-12-14 11:07:24 +05:30
Nick Clifton aa785360cf PE linker script improvements.
PR ld/19254
	* scripttempl/pe.sc (.fini): KEEP this section.
	(.gcc_except_table): Likewise.
	(.pdata): Also accept .pdata*.
2016-12-13 17:05:20 +00:00
Jiong Wang 971f1d27d2 [AArch64] Make LD testcases support ILP32 mode
ld/
	* testsuite/ld-aarch64/aarch64-elf.exp (aarch64_choose_lp64_emul): New
	function.
	(run_dump_test_lp64): New function which pass LP64 mode options to both
	assembler and linker when building test binary.
	(aarch64elftests): Remove eh-frame-merge test.
	(eh-frame-merge-lp64): Restrict eh-frame-merge test to LP64 only.
	(run_dump_test): Migrate to run_dump_test_lp64 if the test source was
	written for LP64 only.
	* testsuite/ld-aarch64/erratum843419.d: Support ILP32 mode.
	* testsuite/ld-aarch64/farcall-b-defsym.d: Likewise.
	* testsuite/ld-aarch64/farcall-b-plt.d: Likewise.
	* testsuite/ld-aarch64/farcall-b.d: Likewise.
	* testsuite/ld-aarch64/farcall-bl-defsym.d: Likewise.
	* testsuite/ld-aarch64/farcall-bl-plt.d: Likewise.
	* testsuite/ld-aarch64/farcall-bl.d: Likewise.
	* testsuite/ld-aarch64/ifunc-15.d: Likewise.
	* testsuite/ld-aarch64/ifunc-16.d: Likewise.
	* testsuite/ld-aarch64/ifunc-5a-local.d: Likewise.
	* testsuite/ld-aarch64/ifunc-5a.d: Likewise.
	* testsuite/ld-aarch64/ifunc-5b-local.d: Likewise.
	* testsuite/ld-aarch64/ifunc-5b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-5r-local.d: Likewise.
	* testsuite/ld-aarch64/ifunc-6a.d: Likewise.
	* testsuite/ld-aarch64/ifunc-6b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-7a.d: Likewise.
	* testsuite/ld-aarch64/ifunc-7b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-8.d: Likewise.
	* testsuite/ld-aarch64/limit-b.d: Likewise.
	* testsuite/ld-aarch64/limit-bl.d: Likewise.
2016-12-13 12:50:17 +00:00
Alan Modra 22b05d33b4 Don't add PHDR for objcopy/strip or ld script specifying PHDRS
HPPA64 needs to add a DT_PHDR header for shared libs.  That's fine
when linking but shouldn't happen for strip/objcopy.  Also PHDR must
come first so there's no need to look at all program headers.

bfd/
	* elf64-hppa.c (elf64_hppa_modify_segment_map): Don't add PHDR
	for objcopy/strip or when a ld script specifies PHDRS.
ld/
	* testsuite/ld-elf/nobits-1.d: Remove xfail for hppa64.
	* testsuite/ld-elf/note-1.d: Likewise.
	* testsuite/ld-elf/note-2.d: Likewise.
2016-12-13 09:37:59 +10:30
Alan Modra 6392030005 Don't fudge p_vaddr when PHDR in segment
RX does horrible fudges to PT_LOAD p_vaddr, that affect the testsuite
and mean the target won't support dynamic objects.  The latter
probably doesn't matter too much since RX is an embedded target, but
it's easy to stop some of the fudges in order to reduce special cases
for RX in the testsuite.  The changes make sense in isolation too.

bfd/
	* elf32-rx.c (elf32_rx_modify_program_headers): Don't adjust
	segments that include the ELF file header or program headers.
ld/
	* testsuite/ld-elf/flags1.d: Run for RX.
	* testsuite/ld-scripts/phdrs.exp: Likewise.
	* testsuite/ld-scripts/pr14962.d: Likewise.
	* testsuite/ld-scripts/pr14962-2.d: Likewise.
2016-12-13 09:37:37 +10:30
Alan Modra da17fe9de9 sync binutils config/ with gcc
config/
	* acx.m4: Import from gcc.
	* bootstrap-asan.mk: Likewise.
	* multi.m4: Likewise.
/
	* configure: Regnerate.
gas/
	* configure: Regnerate.
ld/
	* configure: Regnerate.
libiberty/
	* configure: Regnerate.
zlib/
	* configure: Regnerate.
2016-12-08 21:35:11 +10:30
Alan Modra 39eeab2534 PowerPC64 toc optimisation for power9
Recognize power9 and a few other insns from older machines.  Fixes
linker complaints like "toc optimization is not supported for
0xf4090002 instruction".  0xf4090002 is stxsd v0,0(r9)

bfd/
	* elf64-ppc.c (ok_lo_toc_insn): Add r_type param.  Recognize
	lq,lfq,lxv,lxsd,lxssp,lfdp,stq,stfq,stxv,stxsd,stxssp,stfdp.
	Don't match lmd and stmd.
ld/
	* testsuite/ld-powerpc/tocopt7.s,
	* testsuite/ld-powerpc/tocopt7.out,
	* testsuite/ld-powerpc/tocopt7.d: New test.
	* testsuite/ld-powerpc/tocopt8.s,
	* testsuite/ld-powerpc/tocopt8.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2016-12-06 18:25:14 +10:30
Nick Clifton 406bd128db Fix seg-fault in linker when passed a bogus input script.
PR ld/20906
	* ldlex.l: Check for bogus strings in linker scripts.
2016-12-05 16:00:43 +00:00
Alyssa Milburn 597e138ca0 bfd,ld: Continue after partially-successful relaxed call relocations in sparc.
bfd/ChangeLog:

2016-12-05  Alyssa Milburn <amilburn@zall.org>

  	* elfxx-sparc.c: Do not stop processing relocations after
    	partially relaxing a call with WDISP30.

ld/ChangeLog:

2016-12-05  Alyssa Milburn <amilburn@zall.org>

	* testsuite/ld-sparc/wdispcall.s: New file.
    	* testsuite/ld-sparc/wdispcall.dd: Likewise.
    	* testsuite/ld-sparc/sparc.exp: Run new test.
2016-12-04 22:59:18 -08:00
Alan Modra 8c5b4e5228 PowerPC64 dot-symbol compatibility bugfixes
Lots of fixes for the compatibility code that handles linking of
-mcall-aixdesc code (or that generated by 12 year old gcc) with
current ELFv1 ABI code.

1) A reference to a dot-symbol in an object file wasn't satisfied by a
   function descriptor in later object files.
2) The as-needed code had bit-rotted;  Shared libs now need a strong
   reference to be counted as needed.
3) --gc-sections involving dot-symbols was broken, needing
   func_desc_adjust to be run early and lots of other fixes.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_entry): Delete "was_undefined".
	(struct ppc_link_hash_table): Delete "twiddled_syms".  Add
	"need_func_desc_adj".
	(lookup_fdh): Link direct fdh sym via oh field and set flags.
	(make_fdh): Make strong and weak undefined function descriptor
	symbols.
	(ppc64_elf_merge_symbol): New function.
	(elf_backend_merge_symbol): Define.
	(ppc64_elf_archive_symbol_lookup): Don't test undefweak for fake
	function descriptors.
	(add_symbol_adjust): Don't twiddle symbols to undefweak.
	Propagate more ref flags to function descriptor symbol.  Make
	some function descriptor symbols dynamic.
	(ppc64_elf_before_check_relocs): Only run add_symbol_adjust for
	ELFv1.  Set need_func_desc_adj.  Don't fix undefs list.
	(ppc64_elf_check_relocs): Set non_ir_ref for descriptors.
	Don't call lookup_fdh here.
	(ppc64_elf_gc_sections): New function.
	(bfd_elf64_bfd_gc_sections): Define.
	(ppc64_elf_gc_mark_hook): Mark descriptor.
	(func_desc_adjust): Don't make fake function descriptor syms strong
	here.  Exit earlier on non-dotsyms.  Take note of elf.dynamic
	flag when deciding whether a dynamic function descriptor might
	be needed.  Transfer elf.dynamic and set elf.needs_plt.  Move
	plt regardless of visibility.  Make descriptor dynamic if
	entry sym is dynamic, not for other cases.
	(ppc64_elf_func_desc_adjust): Don't run func_desc_adjust if
	already done.
	(ppc64_elf_edit_opd): Use oh field rather than lookup_fdh.
	(ppc64_elf_size_stubs): Likewise.
	(ppc_build_one_stub): Don't clear was_undefined.  Only set sym
	undefweak if stub symbol is defined.
	(undo_symbol_twiddle, ppc64_elf_restore_symbols): Delete.
	* elf64-ppc.h (ppc64_elf_restore_symbols): Don't declare.
ld/
	* emultempl/ppc64elf.em (gld${EMULATION_NAME}_finish): Don't call
	ppc64_elf_restore_symbols.
	* testsuite/ld-powerpc/dotsym1.d: New.
	* testsuite/ld-powerpc/dotsym2.d: New.
	* testsuite/ld-powerpc/dotsym3.d: New.
	* testsuite/ld-powerpc/dotsym4.d: New.
	* testsuite/ld-powerpc/dotsymref.s: New.
	* testsuite/ld-powerpc/nodotsym.s: New.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
2016-12-03 21:00:01 +10:30
Alan Modra 4e95fbcd79 PowerPC64 dot-sym testsuite fixes
This illustrates quite well why dot-symbols had to go.  PowerPC64 gcc
for Linux stopped producing them 12 years ago, but the Linux kernel
still persists in using them so it's necessary to keep and
regression test ld support.

	* testsuite/ld-elf/indirect1b.c: Give dot-symbol a version too.
	* testsuite/ld-elf/indirect2.c: Likewise.
	* testsuite/ld-elf/indirect3b.c: Likewise.
	* testsuite/ld-elf/indirect4b.c: Likewise.
	* testsuite/ld-elf/pr18718.c: Likewise.
	* testsuite/ld-elf/pr18720b.c: Likewise.
	* testsuite/ld-elf/pr19553c.c: Likewise.
	* testsuite/ld-elfvers/vers.h (FUNC_SYMVER): Define.
	* testsuite/ld-elfvers/vers1.c: Use FUNC_SYMVER for functions.
	* testsuite/ld-elfvers/vers4.c: Likewise.
	* testsuite/ld-elfvers/vers5.c: Likewise.
	* testsuite/ld-elfvers/vers6.c: Likewise.
	* testsuite/ld-elfvers/vers7a.c: Likewise.
	* testsuite/ld-elfvers/vers9.c: Likewise.
	* testsuite/ld-elfvers/vers15.c: Likewise.
	* testsuite/ld-elfvers/vers18.c: Likewise.
	* testsuite/ld-elfvers/vers22a.c: Likewise.
	* testsuite/ld-elfvers/vers23a.c: Likewise.
	* testsuite/ld-elfvers/vers27d1.c: Likewise.
	* testsuite/ld-elfvers/vers21.c: Likewise.
	(_old_bar): Use attribute weak rather than asm weak.
	* testsuite/ld-ifunc/pr16467b.c: Give dot-symbol a version.
	* testsuite/ld-plugin/pr12760b.c: Define warning on .bar rather than
	bar for ppc64 -mcall-aixdesc.
	* testsuite/ld-plugin/pr16746a.c: Similarly for foobar.
	* testsuite/ld-plugin/pr16746b.c: Likewise.
	* testsuite/ld-elf/shared.exp: Allow dot-symbol in warnings and errors.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-plugin/plugin-6.d: Likewise.
	* testsuite/ld-plugin/plugin-7.d: Likewise.
	* testsuite/ld-plugin/plugin-8.d: Likewise.
	* testsuite/ld-plugin/plugin-13.d: Likewise.
	* testsuite/ld-plugin/plugin-14.d: Likewise.
	* testsuite/ld-plugin/plugin-15.d: Likewise.
	* testsuite/ld-plugin/plugin-16.d: Likewise.
	* testsuite/ld-plugin/plugin-20.d: Likewise.
	* testsuite/ld-plugin/plugin-21.d: Likewise.
	* testsuite/ld-plugin/plugin-22.d: Likewise.
	* testsuite/ld-plugin/plugin-23.d: Likewise.
	* testsuite/ld-plugin/plugin.exp: Define .main and .puts for ppc64
	-mcall-aixdesc.
	* testsuite/ld-elfvers/vers.exp (test_ar): Trim dot-symbols.
	(objdump_dynsymstuff): Likewise.
	(objdump_symstuff): Likewise.  Pack flags to keep column count
	consistent.
	* testsuite/ld-elfweak/elfweak.exp (objdump_dynsymstuff,
	objdump_symstuff): As for vers.exp.
	* testsuite/ld-elfvers/vers6.sym: Allow dot-symbols.
	* testsuite/ld-elfvers/vers1.sym: Allow missing F flag for
	-mcall-aixdesc .opd syms and adjust for flag packing.
	* testsuite/ld-elfvers/vers4.sym: Likewise.
	* testsuite/ld-elfvers/vers4a.sym: Likewise.
	* testsuite/ld-elfvers/vers7a.sym: Likewise.
	* testsuite/ld-elfvers/vers9.sym: Likewise.
	* testsuite/ld-elfvers/vers15.sym: Likewise.
	* testsuite/ld-elfvers/vers18.sym: Likewise.
	* testsuite/ld-elfvers/vers21.sym: Likewise.
	* testsuite/ld-elfvers/vers22a.sym: Likewise.
	* testsuite/ld-elfvers/vers23a.sym: Likewise.
	* testsuite/ld-elfvers/vers27d.sym: Likewise.
	* testsuite/ld-elfweak/strong.sym: Likewise.
	* testsuite/ld-elfweak/strongcomm.sym: Likewise.
	* testsuite/ld-elfweak/strongdata.sym: Likewise.
2016-12-03 20:59:43 +10:30