Commit Graph

7183 Commits

Author SHA1 Message Date
Maciej W. Rozycki 71de341392 V850/BFD: Call `_bfd_elf_copy_private_bfd_data' again
Correct a regression introduced with commit 685080f210 ("Adds support
for generating notes in V850 binaries.") which replaced rather than
extending the call to `_bfd_elf_copy_private_bfd_data' with
`v850_elf_copy_private_bfd_data'.  Consequently ELFOSABI_GNU marking is
not propagated to output by `objcopy' from objects containing
STB_GNU_UNIQUE symbols.

	bfd/
	* elf32-v850.c (v850_elf_copy_notes): New function, factored out
	from...
	(v850_elf_copy_private_bfd_data): ... here.  Call the new
	function and `_bfd_elf_copy_private_bfd_data'.

	binutils/
	* testsuite/binutils-all/objcopy.exp: Don't skip the `strip-10'
	test for the V850.
2016-05-16 13:31:20 +01:00
H.J. Lu 2168b2688a Don't convert GOTPCREL relocation against large section
bfd/

	PR ld/20093
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Don't convert
	GOTPCREL relocation against large section.

ld/

	PR ld/20093
	* testsuite/ld-x86-64/pr20093-1.d: New file.
	* testsuite/ld-x86-64/pr20093-1.s: Likewise.
	* testsuite/ld-x86-64/pr20093-2.d: Likewise.
	* testsuite/ld-x86-64/pr20093-2.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr20093-1 and pr20093-2.
2016-05-13 11:07:02 -07:00
Alan Modra 4ade44b727 Set dynamic tag VMA and size from dynamic section when possible
Rather than searching the output for a specific named section, it's
better, where possible, to use a linker created dynamic section to set
a dynamic tag's value.  That way ld doesn't depend on the output
section name, making it possibile to map dynamic sections differently.

bfd/
	* elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_sections): Use
	linker dynamic sections in calculating size and address of
	* dynamic tags rather than using output sections.  Remove asserts.
	* elf32-arm.c (elf32_arm_finish_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_finish_dynamic_sections): Likewise.
	* elf32-cris.c (elf_cris_finish_dynamic_sections): Likewise.
	* elf32-i370.c (i370_elf_finish_dynamic_sections): Likewise.
	* elf32-lm32.c (lm32_elf_finish_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_finish_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_finish_dynamic_sections): Likewise.
	* elf32-metag.c (elf_metag_finish_dynamic_sections): Likewise.
	* elf32-microblaze.c (microblaze_elf_finish_dynamic_sections): Likewise.
	* elf32-nds32.c (nds32_elf_finish_dynamic_sections): Likewise.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_finish_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_finish_dynamic_sections): Likewise.
	* elf32-score.c (s3_bfd_score_elf_finish_dynamic_sections): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_finish_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_finish_dynamic_sections): Likewise.
	* elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Likewise.
	* elf64-alpha.c (elf64_alpha_finish_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_finish_dynamic_sections): Likewise.
	* elf64-sh64.c (sh64_elf64_finish_dynamic_sections): Likewise.
	* elflink.c (bfd_elf_final_link): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections): Likewise.
	* elfxx-sparc.c (sparc_finish_dyn): Likewise.  Adjust error message.
	* elf32-arc.c (GET_SYMBOL_OR_SECTION): Remove ASSERT arg and
	don't set doit.  Look up dynobj section.
	(elf_arc_finish_dynamic_sections): Adjust GET_SYMBOL_OR_SECTION
	invocation and dynamic tag vma calculation.  Don't test
	boolean var == TRUE.
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections): Fix
	DT_JMPREL calc.
ld/
	* testsuite/ld-arm/arm-elf.exp: Adjust for arm-no-rel-plt now passing.
	Use different output file name for static app without .rel.plt.
	* testsuite/ld-arm/arm-no-rel-plt.ld: Align .rel.dyn and .rela.dyn.
	* testsuite/ld-arm/arm-no-rel-plt.out: Delete.
	* testsuite/ld-arm/arm-no-rel-plt.r: New.
	* testsuite/ld-arm/arm-static-app.d: Don't check file name.
	* testsuite/ld-arm/arm-static-app.r: Likewise.
2016-05-13 14:34:45 +09:30
Alan Modra c8e44c6d16 ld -z combreloc elf_link_sort_relocs
A linker script may put .rela.plt in with other .rela.dyn relocs.
The change to elf_reloc_type_class puts any PLT relocs last.  This
patch makes the input section layout better match the sorted relocs.

	* elflink.c (elf_link_sort_relocs): Wrap overlong lines.  Fix
	octets_per_byte.  Put dynamic .rela.plt last in link orders.
	Assign output_offset for reloc sections rather than writing
	sorted relocs from block corresponding to output_offset.
2016-05-13 14:34:45 +09:30
Alan Modra 1997c9943a ld -z combreloc reloc sorting
PLT relocs don't appear in .rela.dyn, at least not when using
normal linker scripts.  However, if they do, then they ought to be
placed last rather than in the middle of other relocs.

	* elf-bfd.h (elf_reloc_type_class): Put reloc_class_plt last.
2016-05-13 00:17:19 +09:30
Matthew Fortune 8f4f9071ad Add MIPS32 DSPr3 support.
bfd/

	* elfxx-mips.c (print_mips_ases): Add DSPR3.

binutils/

	* readelf.c (print_mips_ases): Add DSPR3.

gas/

	* config/tc-mips.c (options): Add OPTION_DSPR3 and
	OPTION_NO_DSPR3.
	(md_longopts): Likewise.
	(md_show_usage): Add help for -mdspr3 and -mno-dspr3.
	(mips_ases): Define availability for DSPr3.
	(mips_ase_groups): Add ASE_DSPR3 to the DSP group.
	(mips_convert_ase_flags): Map ASE_DSPR3 to AFL_ASE_DSPR3.
	* doc/as.texinfo: Document -mdspr3, -mno-dspr3.  Fix -mdspr2
	formatting.
	* doc/c-mips.texi: Document -mdspr3, -mno-dspr3, .set dspr3 and
	.set nodspr3.  Fix -mdspr2 formatting.
	* testsuite/gas/mips/mips32-dspr3.d: New file.
	* testsuite/gas/mips/mips32-dspr3.s: Likewise.
	* testsuite/gas/mips/mips.exp: Run mips32-dspr3 test.

include/

	* elf/mips.h (AFL_ASE_DSPR3): New macro.
	(AFL_ASE_MASK): Update to include AFL_ASE_DSPR3.
	* opcode/mips.h (ASE_DSPR3): New macro.

opcodes/

	* mips-dis.c (mips_arch_choices): Add ASE_DSPR3 to mips32r6 and
	mips64r6.
	* mips-opc.c (D34): New macro.
	(mips_builtin_opcodes): Define bposge32c for DSPr3.
2016-05-11 17:06:13 +01:00
Alan Modra a464198b01 [HPPA] Attach linker created dynamic sections to stub bfd
bfd/
	* elf32-hppa.c (elf32_hppa_init_stub_bfd): New function.
	(elf32_hppa_check_relocs): Don't set dynobj.
	(elf32_hppa_size_stubs): Test !SEC_LINKER_CREATED for stub sections.
	(elf32_hppa_build_stubs): Likewise.
	* elf32-hppa.h (elf32_hppa_init_stub_bfd): Declare.
ld/
	* emultempl/hppaelf.em (hppaelf_create_output_section_statements):
	Call elf32_hppa_init_stub_bfd.
2016-05-11 22:51:14 +09:30
Alan Modra 3bd43ebcb6 ld --gc-sections fail with __tls_get_addr_opt
When --gc-sections is active, __tls_get_addr_opt is marked as not
needed and forced local before ppc*_elf_tls_setup is run.

bfd/
	PR 20060
	* elf64-ppc.c (ppc64_elf_tls_setup): Clear forced_local.
	* elf32-ppc.c (ppc_elf_tls_setup): Likewise.
ld/
	PR 20060
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
	* testsuite/ld-powerpc/tlsdll.s: New.
	* testsuite/ld-powerpc/tlsdll.ver: New.
	* testsuite/ld-powerpc/tlsdll_32.s: New.
	* testsuite/ld-powerpc/tlsopt5.d: New.
	* testsuite/ld-powerpc/tlsopt5.s: New.
	* testsuite/ld-powerpc/tlsopt5_32.d: New.
	* testsuite/ld-powerpc/tlsopt5_32.s: New.
2016-05-11 22:40:09 +09:30
Jiong Wang 4e7fbb34f0 [AArch64] Remove redundant tls relax in elfNN_aarch64_final_link_relocate
bfd/
  * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Remove redundant
  aarch64_tls_transition check.
2016-05-11 11:55:02 +01:00
Thomas Preud'homme 4f4faa4d43 Allow veneers to claim veneered symbols
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (enum elf32_arm_stub_type): New max_stub_type
	enumerator.
	(arm_stub_sym_claimed): New function.
	(elf32_arm_create_stub): Use veneered symbol name and section if
	veneer needs to claim its symbol, and keep logic unchanged otherwise.
	(arm_stub_claim_sym): New function.
	(arm_map_one_stub): Call arm_stub_claim_sym if veneer needs to claim
	veneered symbol, otherwise create local symbol as before.
2016-05-10 16:20:19 +01:00
Thomas Preud'homme 39d911fc3c Use getters/setters to access ARM branch type
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (elf32_arm_size_stubs): Use new macros
	ARM_GET_SYM_BRANCH_TYPE and ARM_SET_SYM_BRANCH_TYPE to respectively get
	and set branch type of a symbol.
	(bfd_elf32_arm_process_before_allocation): Likewise.
	(elf32_arm_relocate_section): Likewise and fix identation along the
	way.
	(allocate_dynrelocs_for_symbol): Likewise.
	(elf32_arm_finish_dynamic_symbol): Likewise.
	(elf32_arm_swap_symbol_in): Likewise.
	(elf32_arm_swap_symbol_out): Likewise.

gas/
	* config/tc-arm.c (arm_adjust_symtab): Use ARM_SET_SYM_BRANCH_TYPE to
	set branch type of a symbol.

gdb/
	* arm-tdep.c (arm_elf_make_msymbol_special): Use
	ARM_GET_SYM_BRANCH_TYPE to get branch type of a symbol.

include/
	* arm.h (enum arm_st_branch_type): Add new ST_BRANCH_ENUM_SIZE
	enumerator.
	(NUM_ENUM_ARM_ST_BRANCH_TYPE_BITS): New macro.
	(ENUM_ARM_ST_BRANCH_TYPE_BITMASK): Likewise.
	(ARM_SYM_BRANCH_TYPE): Replace by ...
	(ARM_GET_SYM_BRANCH_TYPE): This and ...
	(ARM_SET_SYM_BRANCH_TYPE): This in two versions depending on whether
	BFD_ASSERT is defined or not.

ld/
	* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Use
	ARM_GET_SYM_BRANCH_TYPE to get branch type of a symbol.

opcodes/
	* arm-dis.c (get_sym_code_type): Use ARM_GET_SYM_BRANCH_TYPE to get
	branch type of a symbol.
	(print_insn): Likewise.
2016-05-10 16:17:04 +01:00
Thomas Preud'homme 6bde4c52fb Allow stubs without associated input section in ARM backend
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* bfd-in.h (elf32_arm_size_stubs): Add an output section parameter.
	* bfd-in2.h: Regenerated.
	* elf32-arm.c (struct elf32_arm_link_hash_table): Add an output section
	parameter to add_stub_section callback.
	(elf32_arm_create_or_find_stub_sec): Get output section from link_sec
	and pass it down to add_stub_section.
	(elf32_arm_add_stub): Set section to stub_sec if NULL before using it
	for error message.
	(elf32_arm_size_stubs): Add output section parameter to
	add_stub_section function pointer parameter.

ld/
	* emultempl/armelf.em (elf32_arm_add_stub_section): Add output_section
	parameter and rename input_section parameter to after_input_section.
	Append input stub section to the output section if after_input_section
	is NULL.
2016-05-10 15:45:01 +01:00
Thomas Preud'homme b715f643ef Factor our stub creation in ARM backend
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (elf32_arm_create_stub): New function.
	(elf32_arm_size_stubs): Use elf32_arm_create_stub for stub creation.
2016-05-10 15:42:20 +01:00
Thomas Preud'homme 8d9d949014 Refactor Cortex-A8 erratum workaround in preparation
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (enum elf32_arm_stub_type): Delete
	arm_stub_a8_veneer_lwm enumerator.
	(arm_stub_a8_veneer_lwm): New unsigned constant to replace
	aforementioned enumerator.
	(struct elf32_arm_stub_hash_entry): Delete target_addend
	field and add source_value.
	(struct a8_erratum_fix): Delete addend field and add target_offset.
	(stub_hash_newfunc): Initialize source_value field amd remove
	initialization for target_addend.
	(arm_build_one_stub): Stop special casing Thumb relocations: promote
	the else to being always executed, moving the
	arm_stub_a8_veneer_b_cond specific code in it.  Remove
	stub_entry->target_addend from points_to computation.
	(cortex_a8_erratum_scan): Store in a8_erratum_fix structure the offset
	to target symbol from start of section rather than the offset from the
	stub address.
	(elf32_arm_size_stubs): Set stub_entry's source_value and target_value
	fields from struct a8_erratum_fix's offset and target_offset
	respectively.
	(make_branch_to_a8_stub): Rename target variable to loc.  Compute
	veneered_insn_loc and loc using stub_entry's source_value.
2016-05-10 15:28:10 +01:00
Thomas Preud'homme 15afaa63f3 Add support for ARMv8-M Mainline with DSP extension
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	(elf32_arm_merge_eabi_attributes): Add merging logic for
	Tag_DSP_extension.

binutils/
	* readelf.c (display_arm_attribute): Add output for Tag_DSP_extension.
	(arm_attr_public_tags): Define DSP_extension attribute.

gas/
	* NEWS: Document ARMv8-M and ARMv8-M Security and DSP Extensions.
	* config/tc-arm.c (arm_ext_dsp): New feature for Thumb DSP
	instructions.
	(arm_extensions): Add dsp extension for ARMv8-M Mainline.
	(aeabi_set_public_attributes): Memorize the feature bits of the
	architecture selected for Tag_CPU_arch.  Use it to set
	Tag_DSP_extension to 1 for ARMv8-M Mainline with DSP extension.
	(arm_convert_symbolic_attribute): Define Tag_DSP_extension.
	* testsuite/gas/arm/arch7em-bad.d: Rename to ...
	* testsuite/gas/arm/arch7em-bad-1.d: This.
	* testsuite/gas/arm/arch7em-bad-2.d: New file.
	* testsuite/gas/arm/arch7em-bad-3.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-1.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-2.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-3.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-4.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-5.d: Likewise.
	* testsuite/gas/arm/attr-march-armv8m.main.dsp.d: Likewise.

include/
	* elf/arm.h (Tag_DSP_extension): Define.

ld/
	* testsuite/ld-arm/arm-elf.exp (EABI attribute merging 10 (DSP)): New
	test.
	* testsuite/ld-arm/attr-merge-10b-dsp.s: New file.
	* testsuite/ld-arm/attr-merge-10-dsp.attr: Likewise.
2016-05-10 15:24:10 +01:00
Pip Cet 66a368220c PR 20059 _bfd_elf_copy_link_hash_symbol_type segfault
PR ld/20059
	* elfxx-target.h (bfd_elfNN_bfd_copy_link_hash_symbol_type):
	Define as _bfd_generic_copy_link_hash_symbol_type when using
	generic hash table.
2016-05-10 11:04:55 +09:30
Nick Clifton 315350be65 Fix seg fault objdumping a corrupt binary with an invalid sh_link field.
PR binutils/20063
	* elf.c (bfd_elf_get_elf_syms): Check for out of range sh_link
	field before accessing sections array.

	* readelf.c (get_32bit_section_headers): Warn if an out of range
	sh_link or sh_info field is encountered.
	(get_64bit_section_headers): Likewise.
2016-05-09 17:31:07 +01:00
Christophe Monat 9239bbd3a6 [ARM/STM32L4XX] PR 20030: --fix-stm32l4xx-629360 fails to create vldm/vpop veneers for double-precision registers
bfd/
	PR ld/20030
	* elf32-arm.c (is_thumb2_vldm): Account for T1 (DP) encoding.
	(stm32l4xx_need_create_replacing_stub): Rename ambiguous nb_regs
	to nb_words.
	(create_instruction_vldmia): Add is_dp to disambiguate SP/DP
	encoding.
	(create_instruction_vldmdb): Likewise.
	(stm32l4xx_create_replacing_stub_vldm): is_dp detects DP encoding,
	uses it to re-encode.

ld/
	PR ld/20030
	* testsuite/ld-arm/arm-elf.exp: Run new stm32l4xx-fix-vldm-dp
	tests. Fix misnamed stm32l4xx-fix-all.
	* testsuite/ld-arm/stm32l4xx-fix-vldm-dp.s: New tests for multiple
	loads with DP registers.
	* testsuite/ld-arm/stm32l4xx-fix-vldm-dp.d: New reference file.
	* testsuite/ld-arm/stm32l4xx-fix-vldm.s: Add missing comment.
	* testsuite/ld-arm/stm32l4xx-fix-all.s: Add tests for multiple
	loads with DP registers.
	* testsuite/ld-arm/stm32l4xx-fix-all.d: Update reference.
2016-05-09 15:10:37 +02:00
Nick Clifton 73597c183c Revert accidental commit.
PR 19938
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Revert accidental
	commit.
2016-05-09 12:07:32 +01:00
Alan Modra ae1bb19726 Redundant hash table check
* elf64-ppc.c (ppc64_elf_init_stub_bfd): Remove redundant NULL check.
2016-05-09 17:08:35 +09:30
H.J. Lu 97196564c7 Strip global symbol defined in discarded section
When a global symbol is defined in COMDAT group, we shouldn't leave an
undefined symbol in symbol table when the symbol section is discarded
unless there is a reference to the symbol outside of COMDAT group.

bfd/

	PR ld/17550
	* elf-bfd.h (elf_link_hash_entry): Update comments for indx,
	documenting that indx == -3 if symbol is defined in a discarded
	section.
	* elflink.c (elf_link_add_object_symbols): Set indx to -3 if
	symbol is defined in a discarded section.
	(elf_link_output_extsym): Strip a global symbol defined in a
	discarded section.

ld/

	PR ld/17550
	* testsuite/ld-elf/pr17550-1.s: New file.
	* testsuite/ld-elf/pr17550-2.s: Likewise.
	* testsuite/ld-elf/pr17550-3.s: Likewise.
	* testsuite/ld-elf/pr17550-4.s: Likewise.
	* testsuite/ld-elf/pr17550a.d: Likewise.
	* testsuite/ld-elf/pr17550b.d: Likewise.
	* testsuite/ld-elf/pr17550c.d: Likewise.
	* testsuite/ld-elf/pr17550d.d: Likewise.
2016-05-06 09:46:50 -07:00
H.J. Lu 030e823caf Define elf_backend_add_symbol_hook for Intel MCU
elf_backend_add_symbol_hook is undefined for FreeBSD.  Define it for
Intel MCU to support STB_GNU_UNIQUE for Intel MCU and NaCl.

	* elf32-i386.c (elf_backend_add_symbol_hook): Defined for Intel
	MCU.
2016-05-06 08:28:27 -07:00
H.J. Lu c175a65796 Extract convert_load_reloc from x86 convert_load
* elf32-i386.c (elf_i386_convert_load): Extract the GOT load
	conversion to ...
	(elf_i386_convert_load_reloc): This.  New function.
	* elf64-x86-64.c (elf_x86_64_convert_load): Extract the GOT load
	conversion to ...
	(elf_x86_64_convert_load_reloc): This.  New function.
2016-05-05 04:14:00 -07:00
H.J. Lu bedfd056d4 Cache the section contents in x86 check_relocs
Cache the section contents in x86 check_relocs for sections without
TLS relocations.

	* elf32-i386.c (elf_i386_check_tls_transition): Remove abfd.
	Don't check if contents == NULL.
	(elf_i386_tls_transition): Add from_relocate_section.  Check
	from_relocate_section instead of contents != NULL.  Update
	elf_i386_check_tls_transition call.
	(elf_i386_check_relocs): Cache the section contents if
	keep_memory is FALSE.  Pass FALSE as from_relocate_section to
	elf_i386_tls_transition.
	(elf_i386_relocate_section): Pass TRUE as from_relocate_section
	to elf_i386_tls_transition.
	(elf_backend_caches_rawsize): New.
	* elf64-x86-64.c (elf_x86_64_check_tls_transition): Don't check
	if contents == NULL.
	(elf_x86_64_tls_transition): Add from_relocate_section.  Check
	from_relocate_section instead of contents != NULL.
	(elf_x86_64_check_relocs): Cache the section contents if
	keep_memory is FALSE.  Pass FALSE as from_relocate_section to
	elf_x86_64_tls_transition.
	(elf_x86_64_relocate_section): Pass TRUE as from_relocate_section
	to elf_x86_64_tls_transition.
	(elf_backend_caches_rawsize): New.
2016-05-05 04:12:16 -07:00
Maciej W. Rozycki 6d6a648c07 PR 10549: MIPS/LD: Handle OSABI setting for STB_GNU_UNIQUE
Add missing OSABI handling for MIPS/LD, complementing:

commit f64b2e8d60
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Apr 11 08:13:22 2011 +0000

Adjust test coverage accordingly.

	bfd/
	PR 10549
	* elfxx-mips.c (_bfd_mips_elf_add_symbol_hook): Handle
	STB_GNU_UNIQUE.

	ld/
	PR 10549
	* testsuite/ld-unique/unique.exp: Also run for `mips*-*-*'.
2016-05-03 23:51:33 +01:00
Jiong Wang 1f56df9d0d [AArch64] Also puts value in place for R_AARCH64_RELATIVE
When handling absolute relocations for global symbols bind within the
shared object, AArch64 will generate one dynamic RELATIVE relocation,
but won't apply the value for this absolution relocations at static
linking stage. This is different from AArch64 gold linker and x86-64.

This is not a bug as AArch64 is RELA, there is only guarantee that
relocation addend is placed in the relocation entry.  But some
system softwares originally writen for x86-64 might assume AArch64
bfd linker gets the same behavior as x86-64, then they could take
advantage of this buy skipping those RELATIVE dynamic relocations
if the load address is the same as the static linking address.

This patch makes AArch64 BFD linker applies absolution relocations at
static linking stage for scenario described above.  Meanwhile old AArch64
android loader has a bug (PR19163) which relies on current linker behavior
as a workaround, so the same option --no-apply-dynamic-relocs added.
2016-05-03 11:59:37 +01:00
H.J. Lu 493f652c95 Set interpreter in x86 create_dynamic_sections
Set interpreter in x86 create_dynamic_sections to make this information
available to x86 check_relocs.

	* elf32-i386.c (elf_i386_size_dynamic_sections): Move interp
	setting to ...
	(elf_i386_create_dynamic_sections): Here.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Move
	interp setting to ...
	(elf_x86_64_create_dynamic_sections): Here.
2016-04-29 08:27:29 -07:00
H.J. Lu e62b9723fd Pass GOT_RELOC to UNDEFINED_WEAK_RESOLVED_TO_ZERO
When UNDEFINED_WEAK_RESOLVED_TO_ZERO is checked to convert load via
GOT, has_got_reloc is always TRUE.  This patch adds GOT_RELOC, which
is TRUE in x86 convert_load, to UNDEFINED_WEAK_RESOLVED_TO_ZERO.

	* elf32-i386.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Take GOT_RELOC
	and replace (EH)->has_got_reloc with GOT_RELOC.
	(elf_i386_fixup_symbol): Pass has_got_reloc to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(elf_i386_convert_load): Pass TRUE to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	* elf64-x86-64.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Take
	GOT_RELOC and replace (EH)->has_got_reloc with GOT_RELOC.
	(elf_x86_64_fixup_symbol): Pass has_got_reloc to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	(elf_x86_64_allocate_dynrelocs): Likewise.
	(elf_x86_64_relocate_section): Likewise.
	(elf_x86_64_finish_dynamic_symbol): Likewise.
	(elf_x86_64_convert_load): Pass TRUE to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
2016-04-29 08:21:51 -07:00
H.J. Lu c337a1627c i386: Don't relocate section when check_relocs failed
No need to relocate section when check_relocs failed.

	* elf32-i386.c (check_relocs_failed): New.
	(elf_i386_check_relocs): Set check_relocs_failed on error.
	(elf_i386_relocate_section): Skip if check_relocs failed.
2016-04-29 04:31:54 -07:00
H.J. Lu afd9acee15 X86-64: Set check_relocs_failed on error
When checking relocations, set check_relocs_failed on error.

	* elf64-x86-64.c (elf_x86_64_check_relocs): Set
	check_relocs_failed on error.
2016-04-29 04:29:38 -07:00
Nick Clifton 5522f910cb Enhance support for copying and stripping Solaris and ARM binaries.
PR 19938
bfd	* elf-bfd.h (struct elf_backend_data): Rename
	elf_backend_set_special_section_info_and_link to
	elf_backend_copy_special_section_fields.
	* elfxx-target.h: Likewise.
	* elf.c (section_match): Ignore the SHF_INFO_LINK flag when
	comparing section flags.
	(copy_special_section_fields): New function.
	(_bfd_elf_copy_private_bfd_data): Copy the EI_ABIVERSION field.
	Perform two scans over special sections.  The first one looks for
	a direct mapping between the output section and an input section.
	The second scan looks for a possible match based upon section
	characteristics.
	* elf32-arm.c (elf32_arm_copy_special_section_fields): New
	function.  Handle setting the sh_link field of SHT_ARM_EXIDX
	sections.
	* elf32-i386.c (elf32_i386_set_special_info_link): Rename to
	elf32_i386_copy_solaris_special_section_fields.
	* elf32-sparc.c (elf32_sparc_set_special_section_info_link):
	Rename to elf32_sparc_copy_solaris_special_section_fields.
	* elf64-x86-64.c (elf64_x86_64_set_special_info_link): Rename to
	elf64_x86_64_copy_solaris_special_section_fields.

binutils* readelf.c (get_solaris_segment_type): New function.
	(get_segment_type): Call it.
2016-04-29 09:24:42 +01:00
Nick Clifton 786a118cdf Updated Chinese (simplified) translations for bfd, binutils and gold. 2016-04-28 14:09:49 +01:00
H.J. Lu 91f8bf69a5 Skip debug sections when estimating distances
Skip debug sections when estimating distances between output sections
since compressed_size is used to compress debug sections and debug
sections aren't excluded from distances between output sections.

bfd/

	PR ld/20006
	* elf64-x86-64.c (elf_x86_64_convert_load): Skip debug sections
	when estimating distances between output sections.

ld/

	PR ld/20006
	* testsuite/ld-elfvsb/elfvsb.exp (COMPRESS_LDFLAG): New.
	(visibility_run): Pass COMPRESS_LDFLAG to visibility_test on
	ELF targets.
2016-04-27 09:13:10 -07:00
Alan Modra a6a4679fc0 Cache result of scan for __start_* and __stop_* sections
include/
	* bfdlink.h (struct bfd_link_hash_entry): Add "section" field to
	undef.  Formatting.
bfd/
	* elflink.c (_bfd_elf_is_start_stop): New function.
	(_bfd_elf_gc_mark_rsec): Use it.
	* elf-bfd.h (_bfd_elf_is_start_stop): Declare.
2016-04-27 17:05:26 +09:30
Trevor Saunders 28cc9170c3 add casts to avoid arithmetic on void *
arithmetic on void * is undefined in ISO C, so we should avoid it.  In
GNU C sizeof void * is defined as 1, and that is pretty clearly what
this code wants, so change it to do arithmetic on bfd_byte *.
Unfortunately most of the argument types come from virtual function
interfaces so changing the types to bfd_byte * isn't trivial though it
might make the code clearer.  So for the moment its easiest to leave the
variable types as void * and cast before doing arithmetic.

bfd/ChangeLog:

2016-04-26  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* elf32-rx.c (rx_set_section_contents): Avoid arithmetic on void *.
	* mmo.c (mmo_get_section_contents): Likewise.
	(mmo_set_section_contents): Likewise.
2016-04-26 20:09:57 -04:00
H.J. Lu d5486c4372 Always count the NULL entry in dynamic symbol table
There is an unused NULL entry at the head of dynamic symbol table which
we must account for in our count even if the table is empty or unused
since it is intended for the mandatory DT_SYMTAB tag (.dynsym section)
in .dynamic section.

	* elf-bfd.h (elf_link_hash_table): Update comments for
	dynsymcount.
	* elflink.c (_bfd_elf_link_renumber_dynsyms): Always count for
	the unused NULL entry at the head of dynamic symbol table.
	(bfd_elf_size_dynsym_hash_dynstr): Remove dynsymcount != 0
	checks.
2016-04-26 03:53:23 -07:00
H.J. Lu 6645479e9d Exclude linker created file from dynobj
Some ELF targets create a "linker stubs" fake bfd.  Don't use it to
set dynobj.

	* elflink.c (_bfd_elf_link_create_dynstrtab): Exclude linker
	created file from dynobj.
2016-04-21 21:45:57 -07:00
H.J. Lu 6cd255ca1f Set dynobj to a normal input file if possible
When check_relocs is called after gc-sections has run,
_bfd_elf_link_create_dynstrtab may be called with an dynamic object
and hash_table->dynobj may be NULL.  We may not set dynobj, an input
file holding linker created dynamic sections to the dynamic object,
which has its own dynamic sections.  We need to find a normal input
file to hold linker created sections if possible.  Otherwise ld will
crash during LTO input rescan when linker created dynamic section
overrides input dynamic section.

	* elflink.c (_bfd_elf_link_create_dynstrtab): Set dynobj to a
	normal input file if possible.
2016-04-21 19:14:28 -07:00
Nick Clifton 4f3b23b390 Add support for non-ELF targets to check their relocs.
bfd	* aout-adobe.c: Use _bfd_generic_link_check_relocs.
	* aout-target.h: Likewise.
	* aout-tic30.c: Likewise.
	* binary.c: Likewise.
	* bout.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* coffcode.h: Likewise.
	* i386msdos.c: Likewise.
	* i386os9k.c: Likewise.
	* ieee.c: Likewise.
	* ihex.c: Likewise.
	* libbfd-in.h: Likewise.
	* libecoff.h: Likewise.
	* mach-o-target.c: Likewise.
	* mmo.c: Likewise.
	* nlm-target.h: Likewise.
	* oasys.c: Likewise.
	* pef.c: Likewise.
	* plugin.c: Likewise.
	* ppcboot.c: Likewise.
	* som.c: Likewise.
	* srec.c: Likewise.
	* tekhex.c: Likewise.
	* versados.c: Likewise.
	* vms-alpha.c: Likewise.
	* xsym.c: Likewise.
	* elfxx-target.h: Use _bfd_elf_link_check_relocs.
	* linker.c (bfd_link_check_relocs): New function.
	(_bfd_generic_link_check_relocs): New function.
	* targets.c (BFD_JUMP_TABLE_LINK): Add initialization of
	_bfd_link_check_relocs field.
	(struct bfd_target)L Add _bfd_link_check_relocs field.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

ld	* ldlang.c (lang_check_relocs): Use bfd_link_check_relocs in
	prefernce to _bfd_elf_link_check_relocs.  Drop test for ELF
	targets.  Do not stop the checks when problems are encountered.

include	* bfdlink.h: Add prototype for bfd_link_check_relocs.
2016-04-21 15:43:00 +01:00
H.J. Lu e66cdd681f Remove x86 gc_sweep_hook
Since x86 backends never see the removed sections, there is no need
for gc_sweep_hook.

	* elf32-i386.c (elf_i386_gc_sweep_hook): Removed.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
2016-04-20 17:14:02 -07:00
H.J. Lu 5ce03cea78 Don't check relocations in excluded sections
When checking relocations after gc-sections has run, the unused sections
have been removed.  Don't check relocations in excluded sections.

	* elflink.c (_bfd_elf_link_check_relocs): Don't check relocations
	in excluded sections
2016-04-20 17:11:04 -07:00
H.J. Lu 338c190a92 Check run-time R_X86_64_32 relocation overflow
Since elf_x86_64_check_relocs is called after opening all input files,
we can detect dynamic R_X86_64_32 relocation overflow there.

bfd/

	PR ld/19969
	* elf64-x86-64.c (check_relocs_failed): New.
	(elf_x86_64_need_pic): Moved before elf_x86_64_check_relocs.
	Support relocation agaist local symbol.  Set check_relocs_failed.
	(elf_x86_64_check_relocs): Use elf_x86_64_need_pic.  Check
	R_X86_64_32 relocation overflow.
	(elf_x86_64_relocate_section): Skip if check_relocs failed.
	Update one elf_x86_64_need_pic and remove one elf_x86_64_need_pic.

ld/

	PR ld/19969
	* testsuite/ld-x86-64/pr19969.d: New file.
	* testsuite/ld-x86-64/pr19969a.S: Likewise.
	* testsuite/ld-x86-64/pr19969b.S: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr19969 tests.
2016-04-20 11:10:38 -07:00
H.J. Lu 466ee2af4a Call _bfd_elf_create_ifunc_sections only for ifunc
Since x86 check_relocs is called after opening all input files, we
need to call _bfd_elf_create_ifunc_sections only for STT_GNU_IFUNC
symbols.

	* elf32-i386.c (elf_i386_check_relocs): Call
	_bfd_elf_create_ifunc_sections only for STT_GNU_IFUNC symbol.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2016-04-20 05:34:15 -07:00
H.J. Lu d968975277 Check ELF relocs after opening all input files
Delaying checking ELF relocations until opening all input files so
that symbol information is final when relocations are checked.  This
is only enabled for x86 targets.

bfd/

	* elf-bfd.h (_bfd_elf_link_check_relocs): New.
	* elflink.c (_bfd_elf_link_check_relocs): New function.
	(elf_link_add_object_symbols): Call _bfd_elf_link_check_relocs
	if check_relocs_after_open_input is FALSE.

include/

	* bfdlink.h (bfd_link_info): Add check_relocs_after_open_input.

ld/

	* emulparams/elf32_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	New.
	* emulparams/elf_i386.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_be.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_chaos.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_ldso.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_vxworks.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse):
	Set check_relocs_after_open_input to TRUE if
	CHECK_RELOCS_AFTER_OPEN_INPUT is yes.
	(gld${EMULATION_NAME}_after_open): Call
	_bfd_elf_link_check_relocs on all inputs if
	check_relocs_after_open_input is TRUE.
2016-04-20 05:26:51 -07:00
Trevor Saunders e6c7cdec06 update many old style function definitions
This includes regenerating a bunch of files in opcodes/ with trunk cgen.

gprof/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* basic_blocks.c: Update old style function definitions.
	* cg_arcs.c: Likewise.
	* cg_print.c: Likewise.
	* gen-c-prog.awk: Likewise.
	* gmon_io.c: Likewise.
	* hertz.c: Likewise.
	* hist.c: Likewise.
	* sym_ids.c: Likewise.

bfd/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* cache.c: Update old style function definitions.
	* elf32-m68k.c: Likewise.
	* elf64-mmix.c: Likewise.
	* stab-syms.c: Likewise.

opcodes/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* alpha-dis.c: Regenerate.
	* crx-dis.c: Likewise.
	* disassemble.c: Likewise.
	* epiphany-opc.c: Likewise.
	* fr30-opc.c: Likewise.
	* frv-opc.c: Likewise.
	* ip2k-opc.c: Likewise.
	* iq2000-opc.c: Likewise.
	* lm32-opc.c: Likewise.
	* lm32-opinst.c: Likewise.
	* m32c-opc.c: Likewise.
	* m32r-opc.c: Likewise.
	* m32r-opinst.c: Likewise.
	* mep-opc.c: Likewise.
	* mt-opc.c: Likewise.
	* or1k-opc.c: Likewise.
	* or1k-opinst.c: Likewise.
	* tic80-opc.c: Likewise.
	* xc16x-opc.c: Likewise.
	* xstormy16-opc.c: Likewise.

ld/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* emultempl/scoreelf.em: Likewise.

binutils/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* resres.c: Likewise.

gas/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* cgen.c: Likewise.
	* config/tc-bfin.c: Likewise.
	* config/tc-ia64.c: Likewise.
	* config/tc-mep.c: Likewise.
	* config/tc-metag.c: Likewise.
	* config/tc-nios2.c: Likewise.
	* config/tc-rl78.c: Likewise.
2016-04-20 07:04:49 -04:00
Trevor Saunders b98e687124 change argument type to bfd_byte
We operate on the pointer's target as a set of bytes, and this avoids doing
arithmetic on void * which is undefined in ISO C.

bfd/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* elf32-arm.c (put_thumb2_insn): Change argument type to bfd_byte *.
2016-04-20 06:57:44 -04:00
H.J. Lu 6fd8e7c249 Regenerate Makefile.in/aclocal.m4 automake 1.11.6
bfd/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

binutils/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

gas/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

gold/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* testsuite/Makefile.in: Likewise.

gprof/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.

ld/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.

opcodes/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
2016-04-15 16:20:55 -07:00
Andrew Burgess 4b0c052e45 arc/nps400 : New cmem instructions and associated relocation
Add support for arc/nps400 cmem instructions, these load and store
instructions are hard-wired to access "0x57f00000 + 16-bit-offset".

Supporting this relocation required some additions to the arc relocation
handling in the bfd library, as well as the standard changes required to
add a new relocation type.

There's a test of the new instructions in the assembler, and a test of
the relocation in the linker.

bfd/ChangeLog:

	* reloc.c: Add BFD_RELOC_ARC_NPS_CMEM16 entry.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elf32-arc.c: Add 'opcode/arc.h' include.
	(struct arc_relocation_data): Add symbol_name.
	(arc_special_overflow_checks): New function.
	(arc_do_relocation): Use arc_special_overflow_checks, reindent as
	required, add an extra comment.
	(elf_arc_relocate_section): Setup symbol_name in reloc_data.

gas/ChangeLog:

	* testsuite/gas/arc/nps400-3.d: New file.
	* testsuite/gas/arc/nps400-3.s: New file.

include/ChangeLog:

	* elf/arc-reloc.def: Add ARC_NPS_CMEM16 reloc.
	* opcode/arc.h (NPS_CMEM_HIGH_VALUE): Define.

ld/ChangeLog:

	* testsuite/ld-arc/arc.exp: New file.
	* testsuite/ld-arc/nps-1.s: New file.
	* testsuite/ld-arc/nps-1a.d: New file.
	* testsuite/ld-arc/nps-1b.d: New file.
	* testsuite/ld-arc/nps-1b.err: New file.

opcodes/ChangeLog:

	* arc-nps400-tbl.h: Add xldb, xldw, xld, xstb, xstw, and xst
	instructions.
	* arc-opc.c (insert_nps_cmem_uimm16): New function.
	(extract_nps_cmem_uimm16): New function.
	(arc_operands): Add NPS_XLDST_UIMM16 operand.
2016-04-14 17:16:46 +01:00
Andrew Burgess 33cbe6c07e bfd/arc: Rename enum entries to avoid conflicts
In bfd/elf32-arc.c an enum is created that contains entries with generic
names like 'NONE' and 'OFF'.  This has been fine for now, but I had a
need to include opcode/arc.h into bfd/elf32-arc.c.  Unfortunately
opcode/arc.h includes a different enum with identical generic names.

Given that changing the enum in the header file could mean wide-ranging
changes, while changing the enum in the .c file is limited to only
changing the one file, I've added a prefix to the enum in the .c file.

This commit does not add the new include, that will come later.  There
should be no functional change with this commit.

bfd/ChangeLog:

	* elf32-arc.c (tls_got_entries): Add 'TLS_GOT_' prefix to all
	entries.
	(elf_arc_relocate_section): Update enum uses.
	(elf_arc_check_relocs): Likewise.
	(elf_arc_finish_dynamic_symbol): Likewise.
2016-04-14 17:15:42 +01:00
H.J. Lu 7634c4e679 Replace "link" with "sh_link"
On Linux/x86, GCC 4.2 issues a warning:

bfd/elf.c: In function ‘_bfd_elf_copy_private_bfd_data’:
bfd/elf.c:1334: warning: declaration of ‘link’ shadows a global declaration
/usr/include/unistd.h:757: warning: shadowed declaration is here
make[6]: *** [elf.lo] Error 1

Replace "link" with "sh_link" fixes it.

	* elf.c (_bfd_elf_copy_private_bfd_data): Replace "link" with
	"sh_link".
2016-04-14 08:36:32 -07:00