Commit Graph

523 Commits

Author SHA1 Message Date
Alan Modra 827041555a Update year range in copyright notice of binutils files 2019-01-01 22:06:53 +10:30
H.J. Lu b366503e45 i386: Remove the unused bfd pointer argument
Remove the unused bfd pointer argument of elf_i386_rtype_to_howto.

	* elf32-i386.c (elf_i386_rtype_to_howto): Remove the unused bfd
	pointer argument.
	(elf_i386_info_to_howto_rel): Updated.
	(elf_i386_tls_transition): Likewise.
	(elf_i386_relocate_section): Likewise.
2018-12-23 09:45:29 -08:00
H.J. Lu 76268e0274 x86: Call rtype_to_howto to get reloc_howto_type pointer
* elf32-i386.c (elf_i386_relocate_section): Call
	elf_i386_rtype_to_howto to get reloc_howto_type pointer.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Call
	elf_x86_64_rtype_to_howto to get reloc_howto_type pointer.
2018-12-20 13:25:41 -08:00
Alan Modra 7af5d5c4dd PR23980, assertion fail
All of the backend relocate_section functions that interpret reloc
numbers assuming the input file is of the expected type (ie. same as
output or very similar) really ought to be checking input file type.
Not many do, and those that do currently just assert.  This patch
replaces the assertion with a more graceful exit.

	PR 23980
	* elf32-i386.c (elf_i386_relocate_section): Exit with wrong format
	error rather than asserting input file is as expected.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Exit with wrong format
	error if input file is not ppc32 ELF.
2018-12-18 10:47:02 +10:30
Alan Modra 0930cb3021 _bfd_clear_contents bounds checking
This PR shows a fuzzed binary triggering a segfault via a bad
relocation in .debug_line.  It turns out that unlike normal
relocations applied to a section, the linker applies those with
symbols from discarded sections via _bfd_clear_contents without
checking that the relocation is within the section bounds.  The same
thing now happens when reading debug sections since commit
a4cd947aca, the PR23425 fix.

	PR 23770
	PR 23425
	* reloc.c (_bfd_clear_contents): Replace "location" param with
	"buf" and "off".  Bounds check "off".  Return status.
	* cofflink.c (_bfd_coff_generic_relocate_section): Update
	_bfd_clear_contents call.
	* elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Likewise.
	* elf32-arc.c (elf_arc_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-metag.c (metag_final_link_relocate): Likewise.
	* elf32-nds32.c (nds32_elf_get_relocated_section_contents): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-visium.c (visium_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-x86-64.c *(elf_x86_64_relocate_section): Likewise.
	* libbfd-in.h (_bfd_clear_contents): Update prototype.
	* libbfd.h: Regenerate.
2018-10-13 23:54:33 +10:30
H.J. Lu 92e68c1d65 x86-64: Add TLSDESC fields to elf_x86_lazy_plt_layout
ENDBR64 is added to the special TLSDESC entry, which is similar to the
PLT0 entry, in the x86-64 lazy procedure linkage table to support Intel
CET.  The NaCl PLT is different from the normal PLT.  This patch adds
plt_tlsdesc_entry, plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
plt_tlsdesc_got2_insn_end to elf_x86_lazy_plt_layout to support both
normal and NaCl TLSDESC entries.  This fixed

FAIL: TLS descriptor -fpic -shared transitions

for x86_64-nacl.

	* elf32-i386.c (elf_i386_lazy_plt): Add plt_tlsdesc_entry,
	plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
	plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
	plt_tlsdesc_got2_insn_end for TLSDESC entry.
	(elf_i386_lazy_ibt_plt): Likewise.
	(elf_i386_nacl_plt): Likewise.
	* elf64-x86-64.c (tlsdesc_plt_entry): Moved and renamed to ...
	(elf_x86_64_tlsdesc_plt_entry): This.
	(elf_x86_64_lazy_plt): Add plt_tlsdesc_entry,
	plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
	plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
	plt_tlsdesc_got2_insn_end for TLSDESC entry.
	(elf_x86_64_lazy_bnd_plt): Likewise.
	(elf_x86_64_lazy_ibt_plt): Likewise.
	(elf_x32_lazy_ibt_plt): Likewise.
	(elf_x86_64_nacl_plt): Likewise.
	(elf_x86_64_finish_dynamic_sections): Use plt_tlsdesc_entry,
	plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
	plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
	plt_tlsdesc_got2_insn_end to update TLSDESC entry.
	* elfxx-x86.h (elf_x86_lazy_plt_layout): Update comments.
	Add plt_tlsdesc_entry, plt_tlsdesc_entry_size,
	plt_tlsdesc_got1_offset, plt_tlsdesc_got2_offset,
	plt_tlsdesc_got1_insn_end and plt_tlsdesc_got2_insn_end.
	(elf_x86_non_lazy_plt_layout): Update comments.
	(elf_x86_plt_layout): Likewise.
2018-05-28 10:46:16 -07:00
H.J. Lu 011b32fd42 x86: Don't set eh->local_ref to 1 for linker defined symbols
Since symbols created by HIDDEN and PROVIDE_HIDDEN assignments in
linker script may be marked as defined, but not hidden, we can't
set eh->local_ref to 1 in _bfd_x86_elf_link_symbol_references_local.

Also R_386_GOT32X should be handled as just like R_386_GOT32 when
relocating a section.  The input R_386_GOT32X relocations, which
can be relaxed, should have been converted to R_386_PC32, R_386_32
or R_386_GOTOFF.

bfd/

	PR ld/23189
	* elf32-i386.c (elf_i386_relocate_section): Handle R_386_GOT32X
	like R_386_GOT32.
	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
	set eh->local_ref to 1 for linker defined symbols.

ld/

	PR ld/23189
	* testsuite/ld-i386/i386.exp: Run pr23189.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr23189.d: New file.
	* testsuite/ld-i386/pr23189.s: Likewise.
	* testsuite/ld-i386/pr23189.t: Likewise.
	* testsuite/ld-x86-64/pr23189.d: Likewise.
	* testsuite/ld-x86-64/pr23189.s: Likewise.
	* testsuite/ld-x86-64/pr23189.t: Likewise.
2018-05-18 06:43:34 -07:00
H.J. Lu 4ec0995016 x86; Allow IFUNC pointer defined in PDE
If IFUNC symbol is defined in position-dependent executable, we should
change it to the normal function and set its address to its PLT entry
which should be resolved by R_*_IRELATIVE at run-time.  All external
references should be resolved to its PLT in executable.

bfd/

	PR ld/23169
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Don't issue
	an error on IFUNC pointer defined in PDE.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Call
	_bfd_x86_elf_link_fixup_ifunc_symbol.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_fixup_ifunc_symbol): New
	function.
	* elfxx-x86.h (_bfd_x86_elf_link_fixup_ifunc_symbol): New.

ld/

	PR ld/23169
	* testsuite/ld-ifunc/ifunc-9-i386.d: New file.
	* testsuite/ld-ifunc/ifunc-9-x86-64.d: Likewise.
	* testsuite/ld-ifunc/pr23169a.c: Likewise.
	* testsuite/ld-ifunc/pr23169a.rd: Likewise.
	* testsuite/ld-ifunc/pr23169b.c: Likewise.
	* testsuite/ld-ifunc/pr23169b.c: Likewise.
	* testsuite/ld-ifunc/pr23169c.rd: Likewise.
	* testsuite/ld-ifunc/pr23169c.rd: Likewise.
	* testsuite/ld-ifunc/ifunc-9-x86.d: Removed.
	* testsuite/ld-ifunc/ifunc.exp: Run PR ld/23169 tests.
2018-05-14 03:55:50 -07:00
H.J. Lu 8f56f7a239 elf32_bed/elf64_bed 2018-04-17 18:13:48 -07:00
H.J. Lu 347a87745e x86: Treat relocation against IFUNC symbol as FUNC
When resolving a relocation against IFUNC symbol in a SHT_NOTE section
without SHF_ALLOC, we treat it as relocation against FUNC symbol since
it needs the address of IFUNC symbol, not the address returned by IFUNC
function.

bfd/

	PR ld/22929
	* elf32-i386.c (elf_i386_relocate_section): Treat relocation
	against IFUNC symbol in SHT_NOTE section without SHF_ALLOC as
	relocation against FUNC symbol.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.

ld/

	PR ld/22929
	* testsuite/ld-i386/i386.exp: Run PR ld/22929 test.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22929.d: New file.
	* testsuite/ld-i386/pr22929.s: Likewise.
	* testsuite/ld-x86-64/pr22929.d: Likewise.
	* testsuite/ld-x86-64/pr22929.s: Likewise.
2018-03-08 06:36:52 -08:00
Nick Clifton e8f5af786c Use standardized error message for unrecognized relocs.
bfd	* aout-cris.c (swap_ext_reloc_out): Standadize error/warning
	message.
	* elf-hppa.h (elf_hppa_info_to_howto_rel): Likewise.
	* elf32-i386.c (elf_i386_reloc_type_lookup): Likewise.
	* elf32-xtensa.c (elf_xtensa_reloc_type_lookup): Likewise.
	* elf64-ppc.c (ppc64_elf_reloc_type_lookup): Likewise.
	* elf64-s390.c (elf_s390_reloc_type_lookup): Likewise.
	* elf64-sh64.c (sh_elf64_info_to_howto): Likewise.
	* elfxx-ia64.c (ia64_elf_reloc_type_lookup): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_reloc_type_lookup): Likewise.
	* elfxx-tilegx.c (tilegx_reloc_type_lookup): Likewise.
2018-02-27 12:16:04 +00:00
Nick Clifton f3185997ac Have info_to_howto functions return a success/fail status. Check this result. Stop strip from completeing if one of these functions fails.
bfd	PR 22875
	* elf-bfd.h (struct elf_backend_data): Change the return type of
	the elf_info_to_howto and elf_info_to_howto_rel function pointers
	to bfd_boolean.
	* elfcode.h (elf_slurp_reloc_table_from_section): Check the return value from the info_to_howto function and fail if that function failed.
	* elf32-h8300.c (elf32_h8_relocate_section): Check return value from the info_to_howto function.
	(elf32_h8_relax_section): Likewise.
	* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
	* elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise.
	* elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Likewise.
	* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
	* elfnn-ia64.c (elfNN_ia64_relocate_section): Likewise.
	* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
	(riscv_elf_relocate_section): Likewise.
	* elf-hppa.h (elf_hppa_info_to_howto): Change return type to
	bfd_boolean.  Issue an error message, set an error value and
	return FALSE if the reloc is not recognized.
	(elf_hppa_info_to_howto_rel): Likewise.
	* elf-m10200.c (mn10200_info_to_howto): Likewise.
	* elf-m10300.c (mn10300_info_to_howto): Likewise.
	* elf.c (_bfd_elf_no_info_to_howto): Likewise.
	* elf32-arc.c (arc_info_to_howto_rel): Likewise.
	* elf32-arm.c (elf32_arm_info_to_howto): Likewise.
	* elf32-avr.c (avr_info_to_howto_rela): Likewise.
	* elf32-bfin.c (bfin_info_to_howto): Likewise.
	* elf32-cr16.c (elf_cr16_info_to_howto): Likewise.
	* elf32-cr16c.c (elf_cr16c_info_to_howto): Likewise.
	* elf32-cris.c (elf_cr16c_info_to_howto_rel, cris_info_to_howto_rela): Likewise.
	* elf32-crx.c (elf_crx_info_to_howto): Likewise.
	* elf32-d10v.c (d10v_info_to_howto_rel): Likewise.
	* elf32-d30v.c (d30v_info_to_howto_rel, d30v_info_to_howto_rela): Likewise.
	* elf32-dlx.c (dlx_rtype_to_howto, elf32_dlx_info_to_howto, elf32_dlx_info_to_howto_rel): Likewise.
	* elf32-epiphany.c (epiphany_info_to_howto_rela): Likewise.
	* elf32-fr30.c (fr30_info_to_howto_rela): Likewise.
	* elf32-frv.c (frv_info_to_howto_rela, 	frvfdpic_info_to_howto_rel): Likewise.
	* elf32-ft32.c (ft32_info_to_howto_rela): Likewise.
	* elf32-gen.c (elf_generic_info_to_howto, elf_generic_info_to_howto_rel): Likewise.
	* elf32-h8300.c (elf32_h8_info_to_howto, elf32_h8_info_to_howto_rel): Likewise.
	* elf32-i370.c (i370_elf_info_to_howto): Likewise.
	* elf32-i386.c (elf_i386_reloc_type_lookup, elf_i386_rtype_to_howto, elf_i386_info_to_howto_rel): Likewise.
	* elf32-i860.c (lookup_howto, elf32_i860_info_to_howto_rela): Likewise.
	* elf32-i960.c (elf32_i960_info_to_howto_rel): Likewise.
	* elf32-ip2k.c (ip2k_info_to_howto_rela): Likewise.
	* elf32-iq2000.c (iq2000_info_to_howto_rela): Likewise.
	* elf32-lm32.c (lm32_info_to_howto_rela): Likewise.
	* elf32-m32c.c (m32c_info_to_howto_rela): Likewise.
	* elf32-m32r.c (m32r_info_to_howto_rel, m32r_info_to_howto): Likewise.
	* elf32-m68hc11.c (m68hc11_info_to_howto_rel): Likewise.
	* elf32-m68hc12.c (m68hc11_info_to_howto_rel): Likewise.
	* elf32-m68k.c (rtype_to_howto): Likewise.
	* elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
	* elf32-mep.c (mep_info_to_howto_rela): Likewise.
	* elf32-metag.c (metag_info_to_howto_rela): Likewise.
	* elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
	* elf32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): Likewise.
	* elf32-moxie.c (moxie_info_to_howto_rela): Likewise.
	* elf32-msp430.c (msp430_info_to_howto_rela): Likewise.
	* elf32-mt.c (mt_info_to_howto_rela): Likewise.
	* elf32-nds32.c (nds32_info_to_howto_rel, nds32_info_to_howto): Likewise.
	* elf32-nios2.c (nios2_elf32_info_to_howto): Likewise.
	* elf32-or1k.c (or1k_info_to_howto_rela): Likewise.
	* elf32-pj.c (pj_elf_info_to_howto): Likewise.
	* elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
	* elf32-pru.c (pru_elf32_info_to_howto): Likewise.
	* elf32-rl78.c (rl78_info_to_howto_rela): Likewise.
	* elf32-rx.c (rx_info_to_howto_rela): Likewise.
	* elf32-s390.c (elf_s390_info_to_howto): Likewise.
	* elf32-score.c (s3_bfd_score_info_to_howto, _bfd_score_info_to_howto): Likewise.
	* elf32-score7.c (s7_bfd_score_info_to_howto): Likewise.
	* elf32-sh.c (sh_elf_info_to_howto): Likewise.
	* elf32-spu.c (spu_elf_info_to_howto): Likewise.
	* elf32-tic6x.c (elf32_tic6x_info_to_howto, elf32_tic6x_info_to_howto_rel): Likewise.
	* elf32-tilepro.c (tilepro_info_to_howto_rela): Likewise.
	* elf32-v850.c (v850_elf_info_to_howto_rel, v850_elf_info_to_howto_rela, v800_elf_info_to_howto): Likewise.
	* elf32-vax.c (rtype_to_howto): Likewise.
	* elf32-visium.c (visium_info_to_howto_rela): Likewise.
	* elf32-wasm32.c (elf32_wasm32_rtype_to_howto, elf32_wasm32_info_to_howto_rela): Likewise.
	* elf32-xc16x.c (elf32_xc16x_info_to_howto): Likewise.
	* elf32-xgate.c (xgate_info_to_howto_rel): Likewise.
	* elf32-xstormy16.c (xstormy16_info_to_howto_rela): Likewise.
	* elf32-xtensa.c (elf_xtensa_info_to_howto_rela): Likewise.
	* elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
	* elf64-gen.c (elf_generic_info_to_howto, elf_generic_info_to_howto_rel): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_info_to_howto): Likewise.
	* elf64-mips.c (mips_elf64_info_to_howto_rela): Likewise.
	* elf64-mmix.c (mmix_info_to_howto_rela): Likewise.
	* elf64-ppc.c (ppc64_elf_info_to_howto): Likewise.
	* elf64-s390.c (elf_s390_reloc_type_lookup): Likewise.
	* elf64-sh64.c (elf_s390_info_to_howto, sh_elf64_info_to_howto): Likewise.
	* elf64-x86-64.c (elf_x86_64_info_to_howto): Likewise.
	* elfn32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_info_to_howto): Likewise.
	* elfnn-ia64.c (elfNN_ia64_info_to_howto): Likewise.
	* elfnn-riscv.c (riscv_info_to_howto_rela): Likewise.
	* elfxx-ia64.c (ia64_elf_reloc_type_lookup): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_info_to_howto): Likewise.
	* elfxx-tilegx.c (tilegx_info_to_howto_rela): Likewise.
	* elf32-score.h (s7_bfd_score_info_to_howto): Update prototype.
	* elfxx-sparc.h (_bfd_sparc_elf_info_to_howto): Update prototype.
	* elfxx-tilegx.h (tilegx_info_to_howto_rela): Update prototype.
	* elfxx-target.h (elf_info_to_howto, elf_info_to_howto_rel): Default to NULL.

binutils PR 22875
	* objcopy.c (copy_object): Check the error status after marking symbols used in relocations.
	* testsuite/binutils-all/strip-13.s: New test source file.
	* testsuite/binutils-all/strip-13.s: New test driver file.
	* testsuite/binutils-all/objcopy.exp: Run the new test.
2018-02-27 10:15:13 +00:00
Alan Modra 0aa13feeeb unrecognized/unsupported reloc message
It must get boring translating all the variants we have of
unrecognized/unsupported/invalid/unexpected reloc number.  This patch
cuts down on the number of variations.

	* aoutx.h, * coff-alpha.c, * coff-i860.c, * coff-m68k.c,
	* coff-mcore.c, * coff-ppc.c, * coff-rs6000.c, * coff-sh.c,
	* coff-tic4x.c, * coff-tic54x.c, * coff-tic80.c, * coff-w65.c,
	* elf-bfd.h, * elf-m10300.c, * elf.c, * elf32-avr.c, * elf32-bfin.c,
	* elf32-cr16.c, * elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c,
	* elf32-d10v.c, * elf32-d30v.c, * elf32-dlx.c, * elf32-epiphany.c,
	* elf32-fr30.c, * elf32-frv.c, * elf32-i370.c, * elf32-i386.c,
	* elf32-i960.c, * elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c,
	* elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c,
	* elf32-m68k.c, * elf32-mcore.c, * elf32-mep.c, * elf32-metag.c,
	* elf32-microblaze.c, * elf32-mips.c, * elf32-moxie.c,
	* elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c, * elf32-or1k.c,
	* elf32-pj.c, * elf32-ppc.c, * elf32-rl78.c, * elf32-rx.c,
	* elf32-s390.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
	* elf32-v850.c, * elf32-vax.c, * elf32-visium.c, * elf32-wasm32.c,
	* elf32-xgate.c, * elf32-xtensa.c, * elf64-alpha.c,
	* elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c,
	* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
	* elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* elfnn-riscv.c, * elfxx-mips.c, * elfxx-riscv.c, * elfxx-riscv.h,
	* elfxx-sparc.c, * elfxx-sparc.h, * reloc.c: Standardize
	unrecognized/unsupported reloc message.
2018-02-26 09:28:27 +10:30
Alan Modra 2dcf00ce6c %L conversions
* bfd-in.h: Include inttypes.h or if not available define
	PRId64, PRIu64 and PRIx64.
	* bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Remove support for L
	modifier to print bfd_vma.
	* coff-arm.c, * coff-mcore.c, * coff-ppc.c, * coff-rs6000.c,
	* coff-sh.c, * coff-tic80.c, * coffcode.h, * coffgen.c, * cofflink.c,
	* compress.c, * dwarf2.c, * elf-m10300.c, * elf.c, * elf32-arc.c,
	* elf32-arm.c, * elf32-bfin.c, * elf32-cris.c, * elf32-hppa.c,
	* elf32-i386.c, * elf32-ip2k.c, * elf32-lm32.c, * elf32-m32r.c,
	* elf32-m68k.c, * elf32-metag.c, * elf32-nds32.c, * elf32-nios2.c,
	* elf32-ppc.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
	* elf32-score7.c, * elf32-sh.c, * elf32-sh64.c, * elf32-spu.c,
	* elf32-tic6x.c, * elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c,
	* elf32-xtensa.c, * elf64-alpha.c, * elf64-hppa.c, * elf64-ia64-vms.c,
	* elf64-mmix.c, * elf64-s390.c, * elf64-sh64.c, * elf64-x86-64.c,
	* elfcode.h, * elfcore.h, * elflink.c, * elfnn-aarch64.c,
	* elfnn-ia64.c, * elfnn-riscv.c, * elfxx-mips.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * ieee.c, * ihex.c, * mach-o.c, * merge.c, * mmo.c,
	* peXXigen.c, * xcofflink.c: Replace use of Lx modifier with PRIx64,
	and cast input to uint64_t, and similarly for Ld and Lu.
	* bfd-in2.h: Regenerate.
2018-02-19 23:55:54 +10:30
Alan Modra 871b3ab29e Use %pA and %pB in messages rather than %A and %B
First step towards compiler verification of _bfd_error_handler
arguments, and better verification of translated messages.

bfd/
	* bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Handle %pA and %pB in place
	of %A and %B.
	* aout-adobe.c: Update all messages using %A and %B.
	* aout-cris.c: Likewise.
	* aoutx.h: Likewise.
	* archive.c: Likewise.
	* binary.c: Likewise.
	* cache.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-i860.c: Likewise.
	* coff-mcore.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-tic4x.c: Likewise.
	* coff-tic54x.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* coffcode.h: Likewise.
	* coffgen.c: Likewise.
	* cofflink.c: Likewise.
	* coffswap.h: Likewise.
	* compress.c: Likewise.
	* cpu-arm.c: Likewise.
	* ecoff.c: Likewise.
	* elf-attrs.c: Likewise.
	* elf-eh-frame.c: Likewise.
	* elf-ifunc.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf-properties.c: Likewise.
	* elf-s390-common.c: Likewise.
	* elf.c: Likewise.
	* elf32-arc.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cr16c.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-crx.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-d30v.c: Likewise.
	* elf32-epiphany.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-gen.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-i960.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc11.c: Likewise.
	* elf32-m68hc12.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mcore.c: Likewise.
	* elf32-mep.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-pj.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-rx.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh-symbian.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-sh64.c: Likewise.
	* elf32-sparc.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-visium.c: Likewise.
	* elf32-wasm32.c: Likewise.
	* elf32-xgate.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-gen.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-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfcode.h: Likewise.
	* elfcore.h: 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.
	* elfxx-x86.c: Likewise.
	* hpux-core.c: Likewise.
	* ieee.c: Likewise.
	* ihex.c: Likewise.
	* libbfd.c: Likewise.
	* linker.c: Likewise.
	* mach-o.c: Likewise.
	* merge.c: Likewise.
	* mmo.c: Likewise.
	* oasys.c: Likewise.
	* pdp11.c: Likewise.
	* pe-mips.c: Likewise.
	* peXXigen.c: Likewise.
	* peicode.h: Likewise.
	* reloc.c: Likewise.
	* rs6000-core.c: Likewise.
	* srec.c: Likewise.
	* stabs.c: Likewise.
	* vms-alpha.c: Likewise.
	* xcofflink.c: Likewise.
ld/
	* ldmisc.c (vfinfo): Handle %pA and %pB in place of %A and %B.
	* ldcref.c: Update all messages using %A and %B.
	* ldexp.c: Likewise.
	* ldlang.c: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* pe-dll.c: Likewise.
	* plugin.c: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/cr16elf.em: Likewise.
	* emultempl/elf32.em: Likewise.
	* emultempl/m68kcoff.em: Likewise.
	* emultempl/m68kelf.em: Likewise.
	* emultempl/mmo.em: Likewise.
	* emultempl/nds32elf.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/sunos.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
2018-02-19 23:55:53 +10:30
H.J. Lu 451875b4f9 x86-64: Use PLT address for PC-relative reloc
Since PLT in PDE and PC-relative PLT in PIE can be used as function
address, there is no need for dynamic PC-relative relocation against
a dynamic function definition in PIE.  Linker should resolve PC-relative
reference to its PLT address.

NB: i386 has non-PIC PLT and PIC PLT.  Only non-PIC PLT in PDE can
be used as function address.  PIC PLT in PIE can't be used as
function address.

bfd/

	PR ld/22842
	* elf32-i386.c (elf_i386_check_relocs): Pass FALSE for non
	PC-relative PLT to NEED_DYNAMIC_RELOCATION_P.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Create PLT for
	R_X86_64_PC32 reloc against dynamic function in data section.
	Pass TRUE for PC-relative PLT to NEED_DYNAMIC_RELOCATION_P.
	(elf_x86_64_relocate_section): Use PLT for R_X86_64_PC32 reloc
	against dynamic function in data section.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Use PLT in PIE as
	function address only if pcrel_plt is true.
	(_bfd_x86_elf_link_hash_table_create): Set pcrel_plt.
	* elfxx-x86.h (NEED_DYNAMIC_RELOCATION_P): Add PCREL_PLT for
	PC-relative PLT.  If PLT is PC-relative, don't generate dynamic
	PC-relative relocation against a function definition in data
	secton in PIE.  Remove the obsolete comments.
	(elf_x86_link_hash_table): Add pcrel_plt.

ld/

	PR ld/22842
	* testsuite/ld-i386/i386.exp: Run PR ld/22842 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22842a.c: New file.
	* testsuite/ld-i386/pr22842b.S: Likewise.
	* testsuite/ld-x86-64/pr22842a.c: Likewise.
	* testsuite/ld-x86-64/pr22842a.rd: Likewise.
	* testsuite/ld-x86-64/pr22842b.S: Likewise.
	* testsuite/ld-x86-64/pr22842b.rd: Likewise.
2018-02-14 03:50:55 -08:00
H.J. Lu 3b4c384407 x86: Add is_solaris to elf_x86_target_os
Add is_solaris to elf_x86_target_os since Solaris is quite different.

	* elf32-i386.c (elf_i386_get_synthetic_symtab): Also handle
	is_solaris.
	(i386_elf32_sol2_vec): Don't declare.
	(elf_i386_link_setup_gnu_properties): Also handle is_solaris.
	Don't set need_global_offset_table.
	(elf_i386_solaris_arch_bed): New.
	(elf_backend_arch_data): Set to elf_i386_solaris_arch_bed for
	Solaris.
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Check
	target_os != is_nacl instead of target_os == is_normal.
	(x86_64_elf64_sol2_vec): Don't declare.
	(elf_x86_64_link_setup_gnu_properties): Check target_os !=
	is_nacl instead of target_os == is_normal.  Don't set
	need_global_offset_table.
	(elf_x86_64_solaris_arch_bed): New.
	(elf_backend_arch_data): Set to elf_x86_64_solaris_arch_bed for
	Solaris.
	* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep
	_GLOBAL_OFFSET_TABLE_ for Solaris.
	(_bfd_x86_elf_link_setup_gnu_properties): Don't copy
	need_global_offset_table.
	* elfxx-x86.h (elf_x86_target_os): Add is_solaris.
	(elf_x86_link_hash_table): Remove need_global_offset_table.
	(elf_x86_init_table): Likewise.
2018-02-09 08:45:07 -08:00
H.J. Lu 15b23f3612 x86: Set need_global_offset_table with info->output_bfd->xvec
* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
	Remove prototype.
	(i386_elf32_sol2_vec): Declared.
	(elf_i386_link_setup_gnu_properties): Set
	need_global_offset_table with info->output_bfd->xvec.
	* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
	Remove prototype.
	(x86_64_elf64_sol2_vec): Declared.
	(elf_x86_64_link_setup_gnu_properties): Set
	need_global_offset_table with info->output_bfd->xvec.
2018-02-08 16:30:55 -08:00
H.J. Lu dc11dea212 x86: Keep the unused _GLOBAL_OFFSET_TABLE_ for Solaris
Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it isn't used.
This patch detects Solaris target and keeps _GLOBAL_OFFSET_TABLE_ for
Solaris.

	* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
	New prototype.
	(elf_i386_link_setup_gnu_properties): Set need_global_offset_table
	for Solaris.
	* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
	New prototype.
	(elf_x86_64_link_setup_gnu_properties): Set
	need_global_offset_table for Solaris.
	* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep the
	unused _GLOBAL_OFFSET_TABLE_ for Solaris.
	(_bfd_x86_elf_link_setup_gnu_properties): Copy
	need_global_offset_table.
	* elfxx-x86.h (elf_x86_link_hash_table): Add
	need_global_offset_table.
	(elf_x86_init_table): Likewise.
2018-02-08 13:52:22 -08:00
H.J. Lu cd04836359 x86: Remove the unused _GLOBAL_OFFSET_TABLE_
Since _GLOBAL_OFFSET_TABLE_ may be referenced implicitly on x86,
checking ref_regular_nonweak leaves the unused _GLOBAL_OFFSET_TABLE_
in output.  This patch checks explicit GOT references instead.

ld-i386/discarded1.s and ld-x86-64/discarded1.s are updated to avoid
linker optimization which removes GOT references.

bfd/

	PR ld/22782
	* elf32-i386.c (elf_i386_check_relocs): Set got_referenced if
	_GLOBAL_OFFSET_TABLE_ is referenced or GOT is needed to resolve
	undefined weak symbol to 0.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Set got_referenced
	if _GLOBAL_OFFSET_TABLE_ is referenced.
	* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Check
	got_referenced instead of ref_regular_nonweak.  Remove the
	unused _GLOBAL_OFFSET_TABLE_ from symbol table.
	* elfxx-x86.h (elf_x86_link_hash_table): Add got_referenced.

ld/

	PR ld/22782
	* testsuite/ld-i386/discarded1.s: Replace mov with div.
	* testsuite/ld-x86-64/discarded1.s: Likewise.
	* testsuite/ld-i386/i386.exp: Run pr22782.
	* testsuite/ld-i386/load1-nacl.d: Updated for removing
	_GLOBAL_OFFSET_TABLE_ from output.
	* testsuite/ld-i386/load1.d: Likewise.
	* testsuite/ld-x86-64/load1a-nacl.d: Likewise.
	* testsuite/ld-x86-64/load1a.d: Likewise.
	* testsuite/ld-x86-64/load1b-nacl.d: Likewise.
	* testsuite/ld-x86-64/load1b.d: Likewise.
	* testsuite/ld-i386/pr22782.d: New file.
	* testsuite/ld-i386/pr22782.s: Likewise.
	* testsuite/ld-x86-64/pr22782.s: Likewise.
	* testsuite/ld-x86-64/pr22782a.d: Likewise.
	* testsuite/ld-x86-64/pr22782b.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr22782a and pr22782b.
2018-02-05 08:38:16 -08:00
Alan Modra 219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
Alan Modra 07d6d2b834 BFD whitespace fixes
Binutils is supposed to use tabs.  In my git config I have
whitespace = indent-with-non-tab,space-before-tab,trailing-space
and I got annoyed enough seeing red in "git diff" output to fix
the problems.

	* doc/header.sed: Trim trailing space when splitting lines.
	* aix386-core.c, * aout-adobe.c, * aout-arm.c, * aout-cris.c,
	* aout-ns32k.c, * aout-target.h, * aout-tic30.c, * aoutf1.h, * aoutx.h,
	* arc-got.h, * arc-plt.def, * arc-plt.h, * archive.c, * archive64.c,
	* archures.c, * armnetbsd.c, * bfd-in.h, * bfd.c, * bfdio.c, * binary.c,
	* bout.c, * cache.c, * cisco-core.c, * coff-alpha.c, * coff-apollo.c,
	* coff-arm.c, * coff-h8300.c, * coff-i386.c, * coff-i860.c,
	* coff-i960.c, * coff-m68k.c, * coff-m88k.c, * coff-mcore.c,
	* coff-mips.c, * coff-ppc.c, * coff-rs6000.c, * coff-sh.c,
	* coff-stgo32.c, * coff-tic4x.c, * coff-tic54x.c, * coff-tic80.c,
	* coff-we32k.c, * coff-x86_64.c, * coff-z80.c, * coff-z8k.c,
	* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
	* coffswap.h, * compress.c, * corefile.c, * cpu-alpha.c, * cpu-arm.c,
	* cpu-avr.c, * cpu-bfin.c, * cpu-cr16.c, * cpu-cr16c.c, * cpu-crx.c,
	* cpu-d10v.c, * cpu-frv.c, * cpu-ft32.c, * cpu-i370.c, * cpu-i960.c,
	* cpu-ia64-opc.c, * cpu-ip2k.c, * cpu-lm32.c, * cpu-m32r.c,
	* cpu-mcore.c, * cpu-microblaze.c, * cpu-mips.c, * cpu-moxie.c,
	* cpu-mt.c, * cpu-nios2.c, * cpu-ns32k.c, * cpu-or1k.c, * cpu-powerpc.c,
	* cpu-pru.c, * cpu-sh.c, * cpu-spu.c, * cpu-v850.c, * cpu-v850_rh850.c,
	* cpu-xgate.c, * cpu-z80.c, * dwarf1.c, * dwarf2.c, * ecoff.c,
	* ecofflink.c, * ecoffswap.h, * elf-bfd.h, * elf-eh-frame.c,
	* elf-hppa.h, * elf-m10200.c, * elf-m10300.c, * elf-s390-common.c,
	* elf-strtab.c, * elf-vxworks.c, * elf.c, * elf32-am33lin.c,
	* elf32-arc.c, * elf32-arm.c, * elf32-avr.c, * elf32-avr.h,
	* elf32-bfin.c, * elf32-cr16.c, * elf32-cr16c.c, * elf32-cris.c,
	* elf32-crx.c, * elf32-d10v.c, * elf32-d30v.c, * elf32-dlx.c,
	* elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c, * elf32-ft32.c,
	* elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c, * elf32-i860.c,
	* elf32-i960.c, * elf32-ip2k.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c, * elf32-m68hc1x.c,
	* elf32-m68hc1x.h, * elf32-m68k.c, * elf32-m88k.c, * elf32-mcore.c,
	* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c, * elf32-mips.c,
	* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
	* elf32-nds32.h, * elf32-nios2.c, * elf32-or1k.c, * elf32-pj.c,
	* elf32-ppc.c, * elf32-ppc.h, * elf32-pru.c, * elf32-rl78.c,
	* elf32-rx.c, * elf32-s390.c, * elf32-score.c, * elf32-score.h,
	* elf32-score7.c, * elf32-sh-symbian.c, * elf32-sh.c, * elf32-sh64.c,
	* elf32-sparc.c, * elf32-spu.c, * elf32-tic6x.c, * elf32-tilegx.c,
	* elf32-tilegx.h, * elf32-tilepro.c, * elf32-tilepro.h, * elf32-v850.c,
	* elf32-vax.c, * elf32-wasm32.c, * elf32-xc16x.c, * elf32-xgate.c,
	* elf32-xgate.h, * elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
	* elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c,
	* elf64-ppc.c, * elf64-s390.c, * elf64-sh64.c, * elf64-sparc.c,
	* elf64-tilegx.c, * elf64-tilegx.h, * elf64-x86-64.c, * elfcore.h,
	* elflink.c, * elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* elfnn-riscv.c, * elfxx-aarch64.c, * elfxx-aarch64.h, * elfxx-ia64.c,
	* elfxx-ia64.h, * elfxx-mips.c, * elfxx-riscv.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * elfxx-x86.c, * elfxx-x86.h, * freebsd.h, * hash.c,
	* host-aout.c, * hp300hpux.c, * hppabsd-core.c, * hpux-core.c,
	* i386aout.c, * i386linux.c, * i386lynx.c, * i386mach3.c, * i386msdos.c,
	* i386netbsd.c, * ieee.c, * ihex.c, * irix-core.c, * libaout.h,
	* libbfd-in.h, * libbfd.c, * libcoff-in.h, * libnlm.h, * libpei.h,
	* libxcoff.h, * linker.c, * lynx-core.c, * m68k4knetbsd.c,
	* m68klinux.c, * m68knetbsd.c, * m88kmach3.c, * mach-o-aarch64.c,
	* mach-o-arm.c, * mach-o-i386.c, * mach-o-target.c, * mach-o-x86-64.c,
	* mach-o.c, * mach-o.h, * merge.c, * mipsbsd.c, * mmo.c, * netbsd.h,
	* netbsd-core.c, * newsos3.c, * nlm-target.h, * nlm32-ppc.c,
	* nlm32-sparc.c, * nlmcode.h, * ns32k.h, * ns32knetbsd.c, * oasys.c,
	* opncls.c, * pc532-mach.c, * pdp11.c, * pe-arm.c, * pe-i386.c,
	* pe-mcore.c, * pe-mips.c, * pe-x86_64.c, * peXXigen.c, * pef.c,
	* pef.h, * pei-arm.c, * pei-i386.c, * pei-mcore.c, * pei-x86_64.c,
	* peicode.h, * plugin.c, * ppcboot.c, * ptrace-core.c, * reloc.c,
	* riscix.c, * rs6000-core.c, * section.c, * som.c, * som.h,
	* sparclinux.c, * sparcnetbsd.c, * srec.c, * stabs.c, * sunos.c,
	* syms.c, * targets.c, * tekhex.c, * trad-core.c, * vax1knetbsd.c,
	* vaxnetbsd.c, * verilog.c, * versados.c, * vms-alpha.c, * vms-lib.c,
	* vms-misc.c, * wasm-module.c, * wasm-module.h, * xcofflink.c,
	* xsym.c, * xsym.h: Whitespace fixes.
	* bfd-in2.h, * libbfd.h, * libcoff.h: Regenerate.
2017-12-06 17:51:43 +10:30
H.J. Lu 6c6bc89930 ELF: Don't set non_ir_ref_regular in check_relocs
Since elf_link_add_object_symbols sets non_ir_ref_regular now, there is
no need to set non_ir_ref_regular in check_relocs.

Tested on i686 and x86-64.

	* elf-m10300.c (mn10300_elf_check_relocs): Don't set
	non_ir_ref_regular.
	* elf32-arm.c (elf32_arm_check_relocs): Likewise.
	* elf32-bfin.c (bfin_check_relocs): Likewise.
	* elf32-cr16.c (cr16_elf_check_relocs): Likewise.
	* elf32-cris.c (cris_elf_check_relocs): Likewise.
	* elf32-d10v.c (elf32_d10v_check_relocs): Likewise.
	* elf32-dlx.c (elf32_dlx_check_relocs): Likewise.
	* elf32-fr30.c (fr30_elf_check_relocs): Likewise.
	* elf32-frv.c (elf32_frv_check_relocs): Likewise.
	* elf32-hppa.c (elf32_hppa_check_relocs): Likewise.
	* elf32-i370.c (i370_elf_check_relocs): Likewise.
	* elf32-i386.c (elf_i386_check_relocs): Likewise.
	* elf32-iq2000.c (iq2000_elf_check_relocs): Likewise.
	* elf32-lm32.c (lm32_elf_check_relocs): Likewise.
	* elf32-m32c.c (m32c_elf_check_relocs): Likewise.
	* elf32-m32r.c (m32r_elf_check_relocs): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_check_relocs): Likewise.
	* elf32-m68k.c (elf_m68k_check_relocs): Likewise.
	* elf32-mcore.c (mcore_elf_check_relocs): Likewise.
	* elf32-metag.c (elf_metag_check_relocs): Likewise.
	* elf32-microblaze.c (microblaze_elf_check_relocs): Likewise.
	* elf32-moxie.c (moxie_elf_check_relocs): Likewise.
	* elf32-msp430.c (elf32_msp430_check_relocs): Likewise.
	* elf32-mt.c (mt_elf_check_relocs): Likewise.
	* elf32-nios2.c (nios2_elf32_check_relocs): Likewise.
	* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
	* elf32-ppc.c (ppc_elf_check_relocs): Likewise.
	* elf32-rl78.c (rl78_elf_check_relocs): Likewise.
	* elf32-s390.c (elf_s390_check_relocs): Likewise.
	* elf32-score.c (s3_bfd_score_elf_check_relocs): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_check_relocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_check_relocs): Likewise.
	* elf32-tilepro.c (tilepro_elf_check_relocs): Likewise.
	* elf32-v850.c (v850_elf_check_relocs): Likewise.
	* elf32-vax.c (elf_vax_check_relocs): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_check_relocs): Likewise.
	* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
	* elf64-aarch64.c (elf64_aarch64_check_relocs): Likewise.
	* elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
	* elf64-hppa.c (elf64_hppa_check_relocs): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_check_relocs): Likewise.
	* elf64-mmix.c (mmix_elf_check_relocs): Likewise.
	* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
	* elf64-s390.c (elf_s390_check_relocs): Likewise.
	* elf64-sh64.c (sh_elf64_check_relocs): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Likewise.
	* elfnn-ia64.c (elfNN_ia64_check_relocs): Likewise.
	* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
	* elfxx-tilegx.c (tilegx_elf_check_relocs): Likewise.
2017-11-28 04:55:34 -08:00
H.J. Lu 79b0c981b8 x86: Remove func_pointer_refcount
Since check_reloc is running after gc_sections, there is no need for
reference count.  If a function pointer relocation can be resolved at
run-time, there is no need for PLT and it doesn't count as non-GOT/PLT
relocation.  func_pointer_refcount can be removed.

	* elf32-i386.c (elf_i386_check_relocs): Set plt.refcount to 1.
	Don't use func_pointer_refcount.  Don't set plt.refcount nor
	non_got_ref for function pointer reference.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Don't use
	func_pointer_refcount.
	(_bfd_x86_elf_copy_indirect_symbol): Don't copy
	func_pointer_refcount.
	(_bfd_x86_elf_hide_symbol): Don't use func_pointer_refcount.
	* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Likewise.
	(elf_x86_link_hash_entry): Remove func_pointer_refcount.
2017-11-03 11:15:10 -07:00
H.J. Lu 851b6fa137 x86: Add elf_x86_backend_data
Add plt0_pad_byte and target_os fields to elf_x86_link_hash_table.
Replace elf_i386_backend_data and elf_x86_64_backend_data with
elf_x86_backend_data.

	* elf32-i386.c (elf_i386_backend_data): Removed.
	(get_elf_i386_backend_data): Likewise.
	(elf_i386_arch_bed): Replace elf_i386_backend_data with
	elf_x86_backend_data.
	(elf_i386_get_synthetic_symtab): Likewise.
	(elf_i386_nacl_arch_bed): Likewise.
	(elf_i386_vxworks_arch_bed): Likewise.
	(elf_i386_relocate_section): Check target_os instead of
	is_vxworks.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(elf_i386_finish_dynamic_sections): Use htab->plt0_pad_byte.
	Check target_os instead of is_vxworks.
	(elf_i386_link_setup_gnu_properties): Remove normal_target and
	is_vxworks.  Initialize plt0_pad_byte.
	* elf64-x86-64.c (elf_x86_64_backend_data); Removed.
	(get_elf_x86_64_arch_data): Likewise.
	(get_elf_x86_64_backend_data): Likewise.
	(elf_x86_64_arch_bed): Replace elf_x86_64_backend_data with
	elf_x86_backend_data.
	(elf_x86_64_get_synthetic_symtab): Likewise.
	(elf_x86_64_nacl_arch_bed): Likewise.
	(elf_x86_64_link_setup_gnu_properties): Remove is_vxworks and
	normal_target.  Initialize plt0_pad_byte.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Check target_os
	instead of is_vxworks.
	(_bfd_x86_elf_size_dynamic_sections): Likewise.
	(_bfd_x86_elf_finish_dynamic_sections): Likewise.
	(_bfd_x86_elf_adjust_dynamic_symbol): Likewise.
	(_bfd_x86_elf_link_hash_table_create): Initialize target_os.
	(_bfd_x86_elf_link_setup_gnu_properties): Remove is_vxworks.
	Update normal_target.  Set up plt0_pad_byte.  Check target_os
	instead of is_vxworks.
	* elfxx-x86.h (elf_x86_target_os): New.
	(elf_x86_backend_data): Likewise.
	(get_elf_x86_backend_data): Likewise.
	(elf_x86_link_hash_table): Remove is_vxworks.  Add plt0_pad_byte
	and target_os.
	(elf_x86_init_table): Remove normal_target and is_vxworks.  Add
	plt0_pad_byte.
2017-10-14 11:32:52 -07:00
H.J. Lu 9577f60b5a x86: Add _bfd_x86_elf_finish_dynamic_sections
Extract the common parts of elf_i386_finish_dynamic_sections and
elf_x86_64_finish_dynamic_sections into a separate function in
elfxx-x86.c.

	* elf32-i386.c (elf_i386_finish_dynamic_sections): Call
	_bfd_x86_elf_finish_dynamic_sections.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_finish_dynamic_sections): New
	function.
	* elfxx-x86.h (_bfd_x86_elf_finish_dynamic_sections): New
	prototype.
2017-10-14 11:31:25 -07:00
H.J. Lu 9f8575350f x86: Add _bfd_x86_elf_hide_symbol
When there is no dynamic interpreter in PIE, make the undefined weak
symbol dynamic so that PC relative branch to the undefined weak symbol
will land to address 0.

	* elf32-i386.c (elf_backend_hide_symbol): New.
	* elf64-x86-64.c (elf_backend_hide_symbol): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_hide_symbol): Likewise.
	* elfxx-x86.h (_bfd_x86_elf_hide_symbol): Likewise.
2017-10-12 02:14:34 -07:00
Maciej W. Rozycki a2f63b2e7a ELF/BFD,GDB: Handle both variants of the 32-bit Linux core PRPSINFO note
Fix commit 70a38d42c5 ("New entry points for writing Linux NT_PRPSINFO
notes."), <https://sourceware.org/ml/binutils/2013-02/msg00023.html>,
and commit b3ac9c7756 ("Put more info in NT_PRPSINFO Linux notes"),
<https://sourceware.org/ml/binutils/2013-02/msg00024.html>, and handle
both variants of the 32-bit Linux core PRPSINFO note across all targets.

The 32-bit Linux core PRPSINFO note matches the 32-bit kernel structure,
defined as follows:

(gdb) ptype struct elf_prpsinfo
type = struct elf_prpsinfo {
    char pr_state;
    char pr_sname;
    char pr_zomb;
    char pr_nice;
    unsigned long pr_flag;
    __kernel_uid_t pr_uid;
    __kernel_gid_t pr_gid;
    pid_t pr_pid;
    pid_t pr_ppid;
    pid_t pr_pgrp;
    pid_t pr_sid;
    char pr_fname[16];
    char pr_psargs[80];
}
(gdb)

where the individual data types of most members are the same across all
32-bit Linux ports, with the exception of `__kernel_uid_t' and
`__kernel_gid_t'.  These are defined in <asm-generic/posix_types.h> as
32-bit `unsigned int' by default, however overridden as 16-bit `unsigned
short' in port-specific <asm/posix_types.h> for a few targets, mostly
earlier ports of Linux, specifically: ARM, CRIS, FR-V, M32R, m68k,
MN10300/AM33, s390, SuperH, SPARC and i386.

The default is the same as the PowerPC variant already handled, as from
the commits referred.  Make the special PowerPC case generic then,
removing the GDB part, and provide a backend flag to switch between the
two cases possible, with the 32-bit one being the default and the 16-bit
one explicitly selected.  Set the flag in the target backends affected.

	bfd/
	* elf-bfd.h (elf_backend_data): Add `linux_prpsinfo32_ugid16'
	member.
	(elfcore_write_ppc_linux_prpsinfo32): Remove prototype.
	* elf32-ppc.c (elfcore_write_ppc_linux_prpsinfo32): Remove.
	(elf_external_ppc_linux_prpsinfo32)
	(swap_ppc_linux_prpsinfo32_out): Move to...
	* elf-linux-core.h (elf_external_linux_prpsinfo32_ugid32)
	(swap_linux_prpsinfo32_ugid32_out): ... these.
	(elf_external_linux_prpsinfo32): Rename to...
	(elf_external_linux_prpsinfo32_ugid16): ... this.
	(swap_linux_prpsinfo32_out): Rename to...
	(swap_linux_prpsinfo32_ugid16_out): ... this.
	* elfxx-target.h [!elf_backend_linux_prpsinfo32_ugid16]
	(elf_backend_linux_prpsinfo32_ugid16): Define.
	(elfNN_bed): Initialize `linux_prpsinfo32_ugid16' member.
	* elf.c (elfcore_write_linux_prpsinfo32): Handle both variants
	of the 32-bit Linux core PRPSINFO note.
	* elf32-am33lin.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-arm.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-cris.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-frv.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-i386.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-m32r.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-m68k.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-s390.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-sh.c (elf_backend_linux_prpsinfo32_ugid16): Define.
	* elf32-sparc.c (elf_backend_linux_prpsinfo32_ugid16): Define.

	gdb/
	* ppc-linux-tdep.c (ppc_linux_init_abi): Remove call to
	`set_gdbarch_elfcore_write_linux_prpsinfo'.
2017-10-11 15:01:40 +01:00
H.J. Lu 0f09b4d8d8 x86: Set GOT refcount to 1
Since x86 check_relocs is called after opening all inputs and garbage
collection, they never see the removed sections.  There is no need
for incrementing GOT refcount.  But since PLT refcount is also used in

  /* Don't create the PLT entry if there are only function pointer
     relocations which can be resolved at run-time.  */
  else if (htab->elf.dynamic_sections_created
           && (h->plt.refcount > eh->func_pointer_refcount
               || eh->plt_got.refcount > 0))
    {

we must increment it.

	* elf32-i386.c (elf_i386_check_relocs): Set GOT refcount to 1
	instead of incrementing it.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2017-10-10 15:52:39 -07:00
H.J. Lu 98b273dc13 x86: Use zero_undefweak in elf_x86_link_hash_entry
Replace has_got_reloc and has_non_got_reloc in elf_x86_link_hash_entry
with zero_undefweak:

Bit 0: Symbol has no GOT nor PLT relocations.
Bit 1: Symbol has non-GOT/non-PLT relocations in text sections.

zero_undefweak is initialized to 1 and undefined weak symbol should be
resolved to 0 if zero_undefweak > 0.

	* elf32-i386.c (elf_i386_check_relocs): Replace has_got_reloc
	and has_non_got_reloc with zero_undefweak.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_hash_newfunc): Initialize
	zero_undefweak to 1.
	(_bfd_x86_elf_copy_indirect_symbol): Replace has_got_reloc and
	has_non_got_reloc with zero_undefweak.
	* elfxx-x86.h (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Replace
	has_got_reloc and has_non_got_reloc with zero_undefweak.
	(elf_x86_link_hash_entry): Likewise.
2017-10-06 15:29:32 -07:00
H.J. Lu ff38b4cc55 x86: Add VERIFY_COPY_RELOC
Add VERIFY_COPY_RELOC to verify that symbol supports copy relocation.

	* elfxx-x86.h (VERIFY_COPY_RELOC): New.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Use it.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
2017-10-06 00:51:40 -07:00
H.J. Lu f3180fa9ee x86: Add VERIFY_PLT_ENTRY
Add VERIFY_PLT_ENTRY to verify that symbol has an entry in the procedure
linkage table.

	* elfxx-x86.h (VERIFY_PLT_ENTRY): New.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Use it.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
2017-10-06 00:48:26 -07:00
H.J. Lu e74399c47c x86: Add COPY_INPUT_RELOC_P
Add COPY_INPUT_RELOC_P which returns TRUE if input relocation should
be copied to output.

	* elfxx-x86.h (COPY_INPUT_RELOC_P): New.
	* elf32-i386.c (elf_i386_relocate_section): Use it.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2017-10-06 00:44:38 -07:00
H.J. Lu aebcc8ffd2 x86: Add GENERATE_DYNAMIC_RELOCATION_P
Add GENERATE_DYNAMIC_RELOCATION_P which returns TRUE if dynamic
relocation should be generated.

	* elf32-i386.c (X86_SIZE_TYPE_P): New.
	(elf_i386_relocate_section): Use GENERATE_DYNAMIC_RELOCATION_P.
	* elf64-x86-64.c (X86_SIZE_TYPE_P): New.
	(elf_x86_64_relocate_section): Use GENERATE_DYNAMIC_RELOCATION_P.
	* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): New.
2017-10-06 00:41:58 -07:00
H.J. Lu cf1070f1a1 x86: Add POINTER_LOCAL_IFUNC_P/PLT_LOCAL_IFUNC_P
Add POINTER_LOCAL_IFUNC_P which returns TRUE for pointer reference to
local IFUNC symbol.  Add PLT_LOCAL_IFUNC_P which returns TRUE for PLT
reference to local IFUNC symbol.

	* elfxx-x86.h (POINTER_LOCAL_IFUNC_P): New.
	(PLT_LOCAL_IFUNC_P): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Use them.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2017-10-06 00:37:43 -07:00
H.J. Lu f70656b260 x86: Add GENERATE_RELATIVE_RELOC_P
Add GENERATE_RELATIVE_RELOC_P which returns TRUE if dynamic relative
relocation should be generated.

	* elfxx-x86.h (GENERATE_RELATIVE_RELOC_P): New.
	* elf32-i386.c (elf_i386_relocate_section): Use it.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2017-10-06 00:32:43 -07:00
H.J. Lu 2eba97c207 Add RESOLVED_LOCALLY_P 2017-10-06 00:24:23 -07:00
H.J. Lu daf1c414a4 x86: Add NEED_DYNAMIC_RELOCATION_P
Add NEED_DYNAMIC_RELOCATION_P which returns TRUE if dynamic relocation
is needed.

	* elf32-i386.c (X86_PCREL_TYPE_P): New.
	(elf_i386_check_relocs): Use NEED_DYNAMIC_RELOCATION_P.
	* elf64-x86-64.c (IS_X86_64_PCREL_TYPE): Renamed to ...
	(X86_PCREL_TYPE_P): This.
	(elf_x86_64_check_relocs): Use NEED_DYNAMIC_RELOCATION_P.
	Replace IS_X86_64_PCREL_TYPE with X86_PCREL_TYPE_P.
	(elf_x86_64_relocate_section): Replace IS_X86_64_PCREL_TYPE with
	X86_PCREL_TYPE_P.
	* elfxx-x86.h (NEED_DYNAMIC_RELOCATION_P): New.
2017-10-06 00:23:00 -07:00
H.J. Lu 51537393bd x86: Add TLS_TRANSITION_IE_TO_LE_P
Add TLS_TRANSITION_IE_TO_LE_P which returns TRUE if TLS IE->LE transition
is OK.

	* elfxx-x86.h (TLS_TRANSITION_IE_TO_LE_P): New.
	* elf32-i386.c (elf_i386_tls_transition): Use it.
	* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
2017-10-06 00:13:52 -07:00
H.J. Lu 5e5e02aeca x86: Cache section contents and relocations
bfd/

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

ld/

	PR ld/22135
	* testsuite/ld-i386/i386.exp: Run pr22135.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22135.d: New file.
	* testsuite/ld-i386/pr22135.s: Likewise.
	* testsuite/ld-x86-64/pr22135.d: Likewise.
	* testsuite/ld-x86-64/pr22135.s: Likewise.
2017-09-14 12:29:29 -07:00
H.J. Lu c5bce5c697 x86: Update UNDEFINED_WEAK_RESOLVED_TO_ZERO
Since the only information which SYMBOL_REFERENCES_LOCAL_P doesn't check
is relocations, UNDEFINED_WEAK_RESOLVED_TO_ZERO only needs to check for
relocations with SYMBOL_REFERENCES_LOCAL_P.

	* elf32-i386.c (elf_i386_relocate_section): Update usage of
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	(elf_i386_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	(elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Likewise.
	(_bfd_x86_elf_fixup_symbol): Likewise.
2017-09-09 07:29:29 -07:00
H.J. Lu 0a27fed72d x86: Properly handle __ehdr_start
After _bfd_i386_elf_convert_load and _bfd_x86_64_elf_convert_load are
removed, elf_i386_convert_load_reloc and elf_x86_64_convert_load_reloc
see __ehdr_start as an undefined symbol when they are called from
check_relocs to convert GOT relocations against local symbols.  But
__ehdr_start will be defined as a hidden symbol by linker at the later
stage if it is referenced.  This patch marks __ehdr_start as a defined
local symbol at the start of check_relocs if it is referenced and not
defined.

bfd/

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

ld/

	PR ld/22115
	* ld-i386/i386.exp: Run PR ld/22115 tests,
	* ld/testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22115-1.s: New file.
	* testsuite/ld-i386/pr22115-1a.d: Likewise.
	* testsuite/ld-i386/pr22115-1b.d: Likewise.
	* testsuite/ld-i386/pr22115-1c.d: Likewise.
	* testsuite/ld-i386/pr22115-1d.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1.s: Likewise.
	* testsuite/ld-x86-64/pr22115-1a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1a.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1b.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1c.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1d.d: Likewise.
2017-09-09 05:05:29 -07:00
H.J. Lu 1de031c80b x86: Replace elf_x86_plt_layout_table with elf_x86_init_table
* elf32-i386.c (elf_i386_link_setup_gnu_properties): Replace
	elf_x86_plt_layout_table with elf_x86_init_table.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties):
	Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties):
	Likewise.
	* elfxx-x86.h (elf_x86_plt_layout_table): Renamed to ...
	(elf_x86_init_table): This.
	(_bfd_x86_elf_link_setup_gnu_properties): Replace
	elf_x86_plt_layout_table with elf_x86_init_table.
2017-09-08 04:10:34 -07:00
H.J. Lu 7a382c1c50 x86; Don't add elf64-x86-64.lo nor elf64.lo together with elfxx-x86.lo
Don't set r_info and r_sym fields in _bfd_x86_elf_link_hash_table_create.
Instead, set them in _bfd_x86_elf_link_setup_gnu_properties.  We can
avoid adding elf64-x86-64.lo and elf64.lo together with elfxx-x86.lo to
bfd_backends.

	* configure.ac (bfd_backends): Don't add elf64-x86-64.lo nor
	elf64.lo together with elfxx-x86.lo for 64-bit BFD.
	* configure: Regenerated.
	* elf32-i386.c (elf_i386_link_setup_gnu_properties): Set r_info
	and r_sym fields of plt_layout.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties):
	Likewise.
	* elfxx-x86.c (elf_x86_64_is_reloc_section): Remove BFD64 check.
	(_bfd_x86_elf_link_hash_table_create): Likewise.  Don't set
	r_info nor r_sym fields.
	(_bfd_x86_elf_link_setup_gnu_properties): Set r_info and r_sym
	fields of htab.
	* elfxx-x86.h (elf_x86_plt_layout_table): Add r_info and r_sym.
2017-09-07 17:21:07 -07:00
H.J. Lu 6999821f8b x86: Remove _bfd_{i386,x86_64}_elf_convert_load
Instead of converting GOT relocations when sizing dynamic sections, we
convert GOT relocations during relocation check.  Add a field, local_ref,
to elf_x86_link_hash_entry to indicate if symbol references are always
local with a new function to check if symbol references are always local,
which works in check_relocs.

	* elf32-i386.c (elf_i386_convert_load_reloc): Add an argument,
	r_type_p.  Remove the converted argument.  Replace
	SYMBOL_REFERENCES_LOCAL with SYMBOL_REFERENCES_LOCAL_P.  Return
	the new relocation type via r_type_p.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(need_convert_load): Removed.
	(check_relocs_failed): Updated.
	(elf_i386_check_relocs): Call elf_i386_convert_load_reloc,
	instead of setting need_convert_load.
	(_bfd_i386_elf_convert_load): Removed.
	* elf64-x86-64.c (need_convert_load): Removed.
	(check_relocs_failed): Updated.
	(elf_x86_64_convert_load_reloc): Add an argument, r_type_p.
	Replace SYMBOL_REFERENCES_LOCAL with SYMBOL_REFERENCES_LOCAL_P.
	Return the new relocation type via r_type_p.
	(elf_x86_64_check_relocs): Call elf_x86_64_convert_load_reloc,
	instead of setting need_convert_load.
	(elf_x86_64_check_relocs): Don't check PIC if relocation has
	been converted.
	(_bfd_x86_64_elf_convert_load): Removed.
	(elf_x86_64_relocate_section): Replace SYMBOL_REFERENCES_LOCAL
	with SYMBOL_REFERENCES_LOCAL_P.
	(elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Don't
	set convert_load.
	(_bfd_x86_elf_size_dynamic_sections): Don't call convert_load.
	(_bfd_x86_elf_link_symbol_references_local): New function.
	* elfxx-x86.h (SYMBOL_REFERENCES_LOCAL_P): New.
	(UNDEFINED_WEAK_RESOLVED_TO_ZERO): Replace elf.forced_local with
	SYMBOL_REFERENCES_LOCAL_P.
	(elf_x86_link_hash_entry): Add local_ref.
	(elf_x86_link_hash_table): Remove convert_load.
	(_bfd_i386_elf_convert_load): Removed.
	(_bfd_x86_64_elf_convert_load): Likewise.
	(_bfd_x86_elf_link_symbol_references_local): New.
2017-09-07 04:03:30 -07:00
H.J. Lu 419414eafc x86: Don't change r_type when performing TLS transitions
Don't change r_type when performing TLS transitions to avoid getting
the relocation type with ELF32_R_TYPE again.

	* elf32-i386.c (elf_i386_relocate_section): Don't change r_type
	when calling elf_i386_tls_transition.  Don't use ELF32_R_TYPE
	to get the relocation type again.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Don't change
	r_type when calling elf_x86_64_tls_transition.  Don't use
	ELF32_R_TYPE to get the relocation type again.
2017-09-06 04:53:59 -07:00
H.J. Lu 5e2ac45d56 x86: Add _bfd_x86_elf_size_dynamic_sections
elf_i386_size_dynamic_sections and elf_x86_64_size_dynamic_sections are
very similar, except for the followings:

1. elf_i386_size_dynamic_sections checks GOT_TLS_IE and GOT_TLS_IE_BOTH.
elf_x86_64_size_dynamic_sections checks only GOT_TLS_IE.  Since
GOT_TLS_IE_BOTH is never true for x86-64, it is OK to check GOT_TLS_IE
for both i386 and x86-64.
2, x86-64 sets tlsdesc_plt, but i386 doesn't.  We set tlsdesc_plt only
if target_id == X86_64_ELF_DATA.
3. x86-64 has

	  if (s != htab->elf.srelplt)
	    s->reloc_count = 0;

and i386 has

	  s->reloc_count = 0;

i386 did have

	  if (s != htab->srelplt)
	    s->reloc_count = 0;

in the original commit:

commit 67a4f2b710
Author: Alexandre Oliva <aoliva@redhat.com>
Date:   Wed Jan 18 21:07:51 2006 +0000

But it was removed by

commit 5ae0bfb60a
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Tue Feb 28 07:16:12 2006 +0000

    bfd/
            * elf32-i386.c (elf_i386_link_hash_table): Add next_tls_desc_index.
            (elf_i386_link_hash_table_create): Initialize it.
            (elf_i386_compute_jump_table_size): Use it instead of
            srelplt->reloc_count.
            (allocate_dynrelocs): Likewise.
            (elf_i386_size_dynamic_sections): Likewise.
            (elf_i386_relocate_section): Likewise.

A later commit:

commit e1f987424b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 21 15:13:37 2011 +0000

    Put IRELATIVE relocations after JUMP_SLOT.

    bfd/

    2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>

            PR ld/13302
            * elf32-i386.c (elf_i386_link_hash_table): Add next_jump_slot_index
            and next_irelative_index.
            (elf_i386_link_hash_table_create): Initialize next_jump_slot_index
            and next_irelative_index.
            (elf_i386_allocate_dynrelocs): Increment reloc_count instead of
            next_tls_desc_index.
            (elf_i386_size_dynamic_sections): Set next_tls_desc_index and
            next_irelative_index from reloc_count.
            (elf_i386_finish_dynamic_symbol): Put R_386_IRELATIVE after
            R_386_JUMP_SLOT.

changed it back to use reloc_count again. So it is correct to use

	  if (s != htab->elf.srelplt)
	    s->reloc_count = 0;

for both i386 and x86-64 now.
4. i386 and x86-64 use different DT_XXXs.  They are handled by adding
them to elf_x86_link_hash_table.

With these changes, we can share _bfd_x86_elf_size_dynamic_sections in
elf32-i386.c and elf64-x86-64.c.

	* elf32-i386.c (elf_i386_convert_load): Renamed to ...
	(_bfd_i386_elf_convert_load): This.  Remove static.
	(elf_i386_size_dynamic_sections): Removed.
	(elf_backend_size_dynamic_sections): Likewise.
	* elf64-x86-64.c (elf_x86_64_convert_load): Renamed to ...
	(_bfd_x86_64_elf_convert_load): This.  Remove static.
	(elf_x86_64_size_dynamic_sections): Removed.
	(elf_backend_size_dynamic_sections): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_allocate_dynrelocs): Renamed to ...
	(elf_x86_allocate_dynrelocs): This.  Make it static.
	(_bfd_x86_elf_allocate_local_dynrelocs): Renamed to ...
	(elf_x86_allocate_local_dynreloc): This.  Make it static.
	(elf_i386_is_reloc_section): New function.
	(elf_x86_64_is_reloc_section): Likewise.
	(_bfd_x86_elf_link_hash_table_create): Initialize convert_load,
	is_reloc_section, dt_reloc, dt_reloc_sz and dt_reloc_ent.
	Rearrange got_entry_size initialization.
	(_bfd_x86_elf_size_dynamic_sections): New function.
	* elfxx-x86.h (elf_x86_link_hash_table): Add convert_load,
	is_reloc_section, dt_reloc, dt_reloc_sz and dt_reloc_ent.
	(_bfd_i386_elf_convert_load): New.
	(_bfd_x86_64_elf_convert_load): Likewise.
	(_bfd_x86_elf_size_dynamic_sections): Likewise.
	(elf_backend_size_dynamic_sections): Likewise.
	(_bfd_x86_elf_allocate_dynrelocs): Removed.
	(_bfd_x86_elf_allocate_local_dynrelocs): Likewise.
2017-09-02 15:12:04 -07:00
H.J. Lu 92c10f5f61 i386: Update sgotplt_jump_table_size setting
elf_i386_size_dynamic_sections has

      htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
      htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;

This patch changes it to

      htab->sgotplt_jump_table_size
	= elf_x86_compute_jump_table_size (htab)

Since elf_x86_compute_jump_table_size is defined as

  ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size)

there is no change in output.  It makes elf_i386_size_dynamic_sections
the same as elf_x86_64_size_dynamic_sections.

	* elf32-i386.c (elf_i386_size_dynamic_sections): Set
	sgotplt_jump_table_size with elf_x86_compute_jump_table_size.
2017-09-02 11:18:30 -07:00
H.J. Lu aa595247af x86: Define PLT_CIE_LENGTH and PLT_FDE_* in elfxx-x86.h
Since PLT_CIE_LENGTH, PLT_FDE_LENGTH, PLT_FDE_START_OFFSET and
PLT_FDE_LEN_OFFSET are identical in elf32-i386.c and elf64-x86-64.c,
they can be defined in elfxx-x86.h.

	* elf32-i386.c (PLT_CIE_LENGTH, PLT_FDE_LENGTH,
	PLT_FDE_START_OFFSET, PLT_FDE_LEN_OFFSET): Moved to ...
	* elfxx-x86.h (PLT_CIE_LENGTH, PLT_FDE_LENGTH,
	PLT_FDE_START_OFFSET, PLT_FDE_LEN_OFFSET): Here.
	* elf64-x86-64.c (PLT_CIE_LENGTH, PLT_FDE_LENGTH,
	PLT_FDE_START_OFFSET, PLT_FDE_LEN_OFFSET): Removed.
2017-09-02 11:10:51 -07:00
H.J. Lu b9ce864ca8 x86: Add _bfd_x86_elf_allocate_dynrelocs
Share _bfd_x86_elf_allocate_dynrelocs in elf32-i386.c and elf64-x86-64.c.

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Removed.
	(elf_i386_allocate_local_dynrelocs): Likewise.
	(elf_i386_size_dynamic_sections): Replace
	elf_i386_allocate_dynrelocs/elf_i386_allocate_local_dynrelocs
	with _bfd_x86_elf_allocate_dynrelocs and
	_bfd_x86_elf_allocate_local_dynrelocs.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Removed.
	(elf_x86_64_allocate_local_dynrelocs): Likewise.
	(elf_x86_64_size_dynamic_sections): Replace
	elf_x86_64_allocate_dynrelocs/elf_x86_64_allocate_local_dynrelocs
	with _bfd_x86_elf_allocate_dynrelocs and
	_bfd_x86_elf_allocate_local_dynrelocs.
	* elfxx-x86.c (_bfd_x86_elf_allocate_dynrelocs): New function.
	(_bfd_x86_elf_allocate_local_dynrelocs): Likewise.
	* elfxx-x86.h (_bfd_x86_elf_allocate_dynrelocs): New prototype.
	(_bfd_x86_elf_allocate_local_dynrelocs): Likewise.
2017-09-02 07:27:40 -07:00