Commit Graph

538 Commits

Author SHA1 Message Date
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
Nick Clifton 8486501545 Fix copying Solaris binaries with objcopy.
PR target/19938
bfd	* elf-bbfd.h (struct elf_backend_data): New field:
	elf_strtab_flags.
	New field: elf_backend_set_special_section_info_and_link
	* elfxx-target.h (elf_backend_strtab_flags): Define if not already
	defined.
	(elf_backend_set_special_section_info_and_link): Define if not
	already defined.
	(elfNN_bed): Use elf_backend_set_special_section_info_and_link and
	elf_backend_strtab_flags macros to initialise fields in structure.
	* elf.c (_bfd_elf_make_section_from_shdr): Check for SHF_STRINGS
	being set even if SHF_MERGE is not set.
	(elf_fake_sections): Likewise.
	(section_match): New function.  Matches two ELF sections based
	upon fixed characteristics.
	(find_link): New function.  Locates a section in a BFD that
	matches a section in a different BFD.
	(_bfd_elf_copy_private_bfd_data): Copy the sh_info and sh_link
	fields of reserved sections.
	(bfd_elf_compute_section_file_positions): Set the flags for the
	.shstrtab section based upon the elf_strtab_flags field in the
	elf_backend_data structure.
	(swap_out_syms): Likewise for the .strtab section.
	* elflink.c (bfd_elf_final_link): Set the flags for the
	.strtab section based upon the elf_strtab_flags field in the
	elf_backend_data structure.
	* elf32-i386.c (elf32_i386_set_special_info_link): New function.
	(elf_backend_strtab_flags): Set to SHF_STRINGS for Solaris
	targets.
	(elf_backend_set_special_section_info_and_link): Define for
	Solaris targets.
	* elf32-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.

binutils* testsuite/binutils-all/i386/compressed-1b.d: Allow for the
	string sections possibly having the SHF_STRINGS flag bit set.
	* testsuite/binutils-all/i386/compressed-1c.d: Likewise.
	* testsuite/binutils-all/readelf.s: Likewise.
	* testsuite/binutils-all/readelf.s-64: Likewise.
	* testsuite/binutils-all/x86-64/compressed-1b.d: Likewise.
	* testsuite/binutils-all/x86-64/compressed-1c.d: Likewise.

gas	* testsuite/gas/i386/ilp32/x86-64-unwind.d: Allow for the string
	sections possibly having the SHF_STRINGS flag bit set.
	* testsuite/gas/i386/x86-64-unwind.d: Likewise.
2016-04-14 12:04:09 +01:00
H.J. Lu 2df3368d85 Properly handle dynamic reloc against normal symbol
We shouldn't issue an error for read-only segment with dynamic IFUNC
relocations when dynamic relocations are against normal symbols.

bfd/

	PR ld/19939
	* elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add a pointer
	to bfd_boolean.
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Updated.
	Set *readonly_dynrelocs_against_ifunc_p to TRUE if dynamic reloc
	applies to read-only section.
	* elf32-i386.c (elf_i386_link_hash_table): Add
	readonly_dynrelocs_against_ifunc.
	(elf_i386_allocate_dynrelocs): Updated.
	(elf_i386_size_dynamic_sections): Issue an error for read-only
	segment with dynamic IFUNC relocations only if
	readonly_dynrelocs_against_ifunc is TRUE.
	* elf64-x86-64.c (elf_x86_64_link_hash_table): Add
	readonly_dynrelocs_against_ifunc.
	(elf_x86_64_allocate_dynrelocs): Updated.
	(elf_x86_64_size_dynamic_sections): Issue an error for read-only
	segment with dynamic IFUNC relocations only if
	readonly_dynrelocs_against_ifunc is TRUE.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Updated.

ld/

	PR ld/19939
	* testsuite/ld-i386/i386.exp: Run PR ld/19939 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr19939.s: New file.
	* testsuite/ld-i386/pr19939a.d: Likewise.
	* testsuite/ld-i386/pr19939b.d: Likewise.
	* testsuite/ld-x86-64/pr19939.s: Likewise.
	* testsuite/ld-x86-64/pr19939a.d: Likewise.
	* testsuite/ld-x86-64/pr19939b.d: Likewise.
2016-04-11 19:41:52 -07:00
H.J. Lu 4e0c91e454 Bind defined symbol locally in PIE
Symbols defined in PIE should be bound locally, the same as -shared
-Bsymbolic.

bfd/

	PR ld/19827
	* elf32-i386.c (elf_i386_check_relocs): Bind defined symbol
	locally in PIE.
	(elf_i386_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	(elf_x86_64_relocate_section): Likewise.

ld/

	PR ld/19827
	* testsuite/ld-i386/i386.exp: Run PR ld/19827 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr19827.rd: New file.
	* testsuite/ld-i386/pr19827a.S: Likewise.
	* testsuite/ld-i386/pr19827b.S: Likewise.
	* testsuite/ld-x86-64/pr19827.rd: Likewise.
	* testsuite/ld-x86-64/pr19827a.S: Likewise.
	* testsuite/ld-x86-64/pr19827b.S: Likewise.
2016-03-15 11:47:06 -07:00
H.J. Lu d1ed1c7d69 Handle local IFUNC symbols in shared object
Increment PLT reference count for locally defined local IFUNC symbols
in shared object since STT_GNU_IFUNC symbol must go through PLT even
if it is locally defined and undefined symbol may turn out to be a
STT_GNU_IFUNC symbol later.

bfd/

	PR ld/19784
	* elf32-i386.c (elf_i386_check_relocs): Increment PLT reference
	count for locally defined local IFUNC symbols in shared object.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/

	PR ld/19784
	* testsuite/ld-i386/i386.exp: Remove pr19636-2e-nacl test.
	* testsuite/ld-i386/pr19636-2e-nacl.d: Moved to ...
	* testsuite/ld-i386/pr19636-2e.d: Here.  Remove notarget.
	* testsuite/ld-ifunc/ifunc.exp: Run PR ld/19784 tests.
	* testsuite/ld-ifunc/pass.out: New file.
	* testsuite/ld-ifunc/pr19784a.c: Likewise.
	* testsuite/ld-ifunc/pr19784b.c: Likewise.
	* testsuite/ld-ifunc/pr19784c.c: Likewise.
2016-03-08 09:42:16 -08:00
H.J. Lu bae420ef26 Optimize x86 GOT32X/GOTPCRELX relocations
R_386_GOT32X, R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX relocations
retrieve the symbol address via its GOT slot.  If the symbol address is
known at the link-time, we can use it directly by changing instruction
encoding.  Indirect branch can only be converted to PC relative direct
branch.  MOV can be changed to LEA or encoded differently with signed
address.  The subset of binary operations can be encoded only with
signed address.

If undefined weak symbol is resolved to zero link-time, we can use it
as address.  Zero addresss can't used with PC relative direct branch
when PIC is true since the current PC is unknown.  In 64-bit, 32-bit
relocation for PC relatiave direct branch to zero may also overflow.

If this optimization causes relocation overflow, --no-relax can be used
to work around it.

bfd/

	PR ld/19609
	* elf32-i386.c (elf_i386_convert_load): Convert to R_386_32 for
	load with locally bound symbols if PIC is false or there is no
	base register.  Optimize branch to 0 if PIC is false.
	(elf_i386_relocate_section): Don't generate dynamic relocations
	against undefined weak symbols if PIC is false.
	* elf64-x86-64.c (elf_x86_64_convert_load): Disable optimization
	if we can't estimate relocation overflow with --no-relax.
	Convert to R_X86_64_32S/R_X86_64_32 for load with locally bound
	symbols if PIC is false.  Optimize branch to 0 if PIC is false.
	(elf_x86_64_relocate_section): Don't generate dynamic relocations
	against undefined weak symbols if PIC is false.

ld/

	PR ld/19609
	* testsuite/ld-i386/got1.dd: Updated.
	* testsuite/ld-i386/lea1c.d: Likewise.
	* testsuite/ld-i386/load1-nacl.d: Likewise.
	* testsuite/ld-i386/load1.d: Likewise.
	* testsuite/ld-i386/load4b.d: Likewise.
	* testsuite/ld-i386/load5b.d: Likewise.
	* testsuite/ld-i386/mov1b.d: Likewise.
	* testsuite/ld-x86-64/mov1b.d: Likewise.
	* testsuite/ld-x86-64/mov1d.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise.
	* testsuite/ld-x86-64/gotpcrel1.dd: Likewise.
	* testsuite/ld-x86-64/lea1a.d: Likewise.
	* testsuite/ld-x86-64/lea1b.d: Likewise.
	* testsuite/ld-x86-64/lea1c.d: Likewise.
	* testsuite/ld-x86-64/lea1d.d: Likewise.
	* testsuite/ld-x86-64/lea1e.d: Likewise.
	* testsuite/ld-x86-64/lea1f.d: Likewise.
	* testsuite/ld-x86-64/mov1b.d: Likewise.
	* testsuite/ld-x86-64/mov1d.d: Likewise.
	* testsuite/ld-x86-64/pr13082-3b.d: Likewise.
	* testsuite/ld-x86-64/pr13082-4b.d: Likewise.
	* testsuite/ld-x86-64/lea1.s: Add tests for 32-bit registers.
	* testsuite/ld-i386/pr19609-1.s: New file.
	* testsuite/ld-i386/pr19609-1a.d: Likewise.
	* testsuite/ld-i386/pr19609-1b.d: Likewise.
	* testsuite/ld-i386/pr19609-1c.d: Likewise.
	* testsuite/ld-i386/pr19609-1d.d: Likewise.
	* testsuite/ld-i386/pr19609-1e.d: Likewise.
	* testsuite/ld-i386/pr19609-1f.d: Likewise.
	* testsuite/ld-i386/pr19609-1g.d: Likewise.
	* testsuite/ld-i386/pr19609-1h.d: Likewise.
	* testsuite/ld-i386/pr19609-1i.d: Likewise.
	* testsuite/ld-i386/pr19609-2.s: Likewise.
	* testsuite/ld-i386/pr19609-2a.d: Likewise.
	* testsuite/ld-i386/pr19609-2b.d: Likewise.
	* testsuite/ld-i386/pr19609-2c.d: Likewise.
	* testsuite/ld-i386/undefweak.s: Likewise.
	* testsuite/ld-i386/undefweaka.d: Likewise.
	* testsuite/ld-i386/undefweakb.d: Likewise.
	* testsuite/ld-x86-64/pr13082-3c.d: Likewise.
	* testsuite/ld-x86-64/pr13082-3d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1.s: Likewise.
	* testsuite/ld-x86-64/pr19609-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1f.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1g.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1h.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1i.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1j.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1k.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1l.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1m.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2.s: Likewise.
	* testsuite/ld-x86-64/pr19609-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-3.s: Likewise.
	* testsuite/ld-x86-64/pr19609-3a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-3b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4.s: Likewise.
	* testsuite/ld-x86-64/pr19609-4a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5.s: Likewise.
	* testsuite/ld-x86-64/pr19609-5a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6.s: Likewise.
	* testsuite/ld-x86-64/pr19609-6a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7.s: Likewise.
	* testsuite/ld-x86-64/pr19609-7a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7d.d: Likewise.
	* testsuite/ld-i386/i386.exp: Run undefweak tests and tests for
	PR ld/19609.
	* testsuite/ld-x86-64/x86-64.exp: Run pr13082-3c, pr13082-3d
	and tests for PR ld/19609.
2016-02-26 09:39:24 -08:00
H.J. Lu aec6b87e0b [x86] Resolve non-PIC undefweak symbols in executable
For i386 and x86-64, non-PIC references to undefined weak symbols are
resolved without dynamic relocation when creating executable.  Resolved
undefined weak symbols are removed from the dynamic symbol table in
executable.  One exception is on i386, we need resolved undefined weak
symbols in the dynamic symbol table in PIE if input relocatable files
contain branchs without PLT so that we can branch to 0 with dynamic
relocation in text section.

This makes behaviors of dynamic executable and position independent
executable predictable with mixed PIC and non-PIC references to undefined
weak symbols.  If all references to undefined weak symbols are PIC,
dynamic relocations against undefined weak symbols will be generated
in executable unless -z nodynamic-undefined-weak is passed to linker.

bfd/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* elf32-i386.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
	(elf_i386_link_hash_entry): Add has_got_reloc and
	has_non_got_reloc.
	(elf_i386_link_hash_table): Add interp.
	(elf_i386_link_hash_newfunc): Initialize has_got_reloc and
	has_non_got_reloc.
	(elf_i386_copy_indirect_symbol): Copy has_got_reloc and
	has_non_got_reloc.
	(elf_i386_check_relocs): Set has_got_reloc and has_non_got_reloc.
	(elf_i386_fixup_symbol): New function.
	(elf_i386_pie_finish_undefweak_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Don't allocate space for dynamic
	relocations and discard relocations against resolved undefined
	weak symbols in executable.  Don't make resolved undefined weak
	symbols in executable dynamic.  Keep dynamic non-GOT/non-PLT
	relocation against undefined weak symbols in PIE.
	(elf_i386_size_dynamic_sections): Set interp to .interp section.
	(elf_i386_relocate_section): Don't generate dynamic relocations
	against resolved undefined weak symbols in PIE, except for
	R_386_PC32.
	(elf_i386_finish_dynamic_symbol): Keep PLT/GOT entries without
	dynamic PLT/GOT relocations for resolved undefined weak symbols.
	Don't generate dynamic relocation against resolved undefined weak
	symbol in executable.
	(elf_i386_finish_dynamic_sections): Call
	elf_i386_pie_finish_undefweak_symbol on all symbols in PIE.
	(elf_backend_fixup_symbol): New.
	* elf64-x86-64.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
	(elf_x86_64_link_hash_entry): Add has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_link_hash_table): Add interp.
	(elf_x86_64_link_hash_newfunc): Initialize has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_copy_indirect_symbol): Copy has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_check_relocs): Set has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_fixup_symbol): New function.
	(elf_x86_64_pie_finish_undefweak_symbol): Likewise.
	(elf_x86_64_allocate_dynrelocs): Don't allocate space for dynamic
	relocations and discard relocations against resolved undefined
	weak symbols in executable.  Don't make resolved undefined weak
	symbols in executable dynamic.
	(elf_x86_64_size_dynamic_sections): Set interp to .interp section.
	(elf_x86_64_relocate_section): Check relocation overflow for
	dynamic relocations against unresolved weak undefined symbols.
	Don't generate dynamic relocations against resolved weak
	undefined symbols in PIE.
	(elf_x86_64_finish_dynamic_symbol): Keep PLT/GOT entries without
	dynamic PLT/GOT relocations for resolved undefined weak symbols.
	Don't generate dynamic relocation against resolved undefined weak
	symbol in executable.
	(elf_x86_64_finish_dynamic_sections): Call
	elf_x86_64_pie_finish_undefweak_symbol on all symbols in PIE.
	(elf_backend_fixup_symbol): New.

include/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* bfdlink.h (bfd_link_info): Add dynamic_undefined_weak.

ld/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* Makefile.am (ELF_X86_DEPS): Add dynamic_undefined_weak.sh.
	* Makefile.in: Regenerated.
	* NEWS: Mention -z nodynamic-undefined-weak.
	* ld.texinfo: Document -z nodynamic-undefined-weak.
	* ldmain.c (main): Initialize dynamic_undefined_weak to -1.
	* emulparams/dynamic_undefined_weak.sh: New file.
	* emulparams/elf32_x86_64.sh: Source dynamic_undefined_weak.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_i386_be.sh: Likewise.
	* emulparams/elf_i386_chaos.sh: Likewise.
	* emulparams/elf_i386_ldso.sh: Likewise.
	* emulparams/elf_i386_vxworks.sh: Likewise.
	* emulparams/elf_iamcu.sh: Likewise.
	* emulparams/elf_k1om.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/extern_protected_data.sh (PARSE_AND_LIST_OPTIONS):
	Append.
	(PARSE_AND_LIST_ARGS_CASE_Z): Likewise.
	* testsuite/ld-elf/pr19719a.c: New file.
	* testsuite/ld-elf/pr19719b.c: Likewise.
	* testsuite/ld-elf/pr19719c.c: Likewise.
	* testsuite/ld-elf/pr19719d.c: Likewise.
	* testsuite/ld-i386/pr19636-1.s: Likewise.
	* testsuite/ld-i386/pr19636-1a.d: Likewise.
	* testsuite/ld-i386/pr19636-1b.d: Likewise.
	* testsuite/ld-i386/pr19636-1c.d: Likewise.
	* testsuite/ld-i386/pr19636-1d-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-1d.d: Likewise.
	* testsuite/ld-i386/pr19636-1e.d: Likewise.
	* testsuite/ld-i386/pr19636-1f.d: Likewise.
	* testsuite/ld-i386/pr19636-1g.d: Likewise.
	* testsuite/ld-i386/pr19636-1h.d: Likewise.
	* testsuite/ld-i386/pr19636-1i.d: Likewise.
	* testsuite/ld-i386/pr19636-2.s: Likewise.
	* testsuite/ld-i386/pr19636-2a.d: Likewise.
	* testsuite/ld-i386/pr19636-2b.d: Likewise.
	* testsuite/ld-i386/pr19636-2c-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-i386/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2d.d: Likewise.
	* testsuite/ld-i386/pr19636-2e-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2e.d: Likewise.
	* testsuite/ld-i386/pr19636-3.s: Likewise.
	* testsuite/ld-i386/pr19636-3a.d: Likewise.
	* testsuite/ld-i386/pr19636-3b.d: Likewise.
	* testsuite/ld-i386/pr19636-3c.d: Likewise.
	* testsuite/ld-i386/pr19636-3d.d: Likewise.
	* testsuite/ld-i386/pr19636-3e.d: Likewise.
	* testsuite/ld-i386/pr19636-3f.d: Likewise.
	* testsuite/ld-i386/pr19636-3g.d: Likewise.
	* testsuite/ld-i386/pr19636-4.s: Likewise.
	* testsuite/ld-i386/pr19636-4a.d: Likewise.
	* testsuite/ld-i386/pr19636-4b.d: Likewise.
	* testsuite/ld-i386/pr19636-4c.d: Likewise.
	* testsuite/ld-i386/pr19636-4d.d: Likewise.
	* testsuite/ld-i386/pr19704.out: Likewise.
	* testsuite/ld-i386/pr19704a.c: Likewise.
	* testsuite/ld-i386/pr19704b.c: Likewise.
	* testsuite/ld-x86-64/pr19636-1.s: Likewise.
	* testsuite/ld-x86-64/pr19636-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1f.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1g.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2.s: Likewise.
	* testsuite/ld-x86-64/pr19636-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2e.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2f.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2g.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2h.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2i.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3.s: Likewise.
	* testsuite/ld-x86-64/pr19636-3a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3d.d: Likewise.
	* testsuite/ld-x86-64/pr19704.out: Likewise.
	* testsuite/ld-x86-64/pr19704a.c: Likewise.
	* testsuite/ld-x86-64/pr19704b.c: Likewise.
	* testsuite/ld-elf/shared.exp (mix_pic_and_non_pic): New.
	Run mix_pic_and_non_pic.
	* testsuite/ld-i386/i386.exp (undefined_weak): New.
	Run undefined_weak and PR ld/19636 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-x86-64/pr13082-3b.d: Updated.
	* testsuite/ld-x86-64/pr13082-4b.d: Likewise.
2016-02-26 04:55:57 -08:00
H.J. Lu 13f422778f Set plt_got.offset to (bfd_vma) -1
Since plt_got.offset may be updated in x86 allocate_dynrelocs, set
plt_got.offset to (bfd_vma) -1 when setting needs_plt to 0.

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Set plt_got.offset
	to (bfd_vma) -1 when setting needs_plt to 0.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2016-02-24 05:49:48 -08:00
H.J. Lu 32875eb1f3 Mask off the least significant bit in GOT offset
The least significant bit in GOT offset is to record whether we have
initialized the GOT entry in R_386_GOT32 processing.  We need to mask
it off for R_386_GOT32X.

	PR ld/19601
	* elf32-i386.c (elf_i386_relocate_section): Mask off the least
	significant bit in GOT offset for R_386_GOT32X.
2016-02-10 19:33:52 -08:00
Alan Modra ec1f73bb0b x86 synthetic plt symbols
Changing "pushq $1" in the following to "pushq $too_big" results in an
abort.  BFD shouldn't abort on (deliberately) bad user input.

 400480:       ff 25 9a 0b 20 00       jmpq   *0x200b9a(%rip)
 400486:       68 01 00 00 00          pushq  $0x1
 40048b:       e9 d0 ff ff ff          jmpq   400460 <_init+0x20>

	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Don't abort on
	an out of range reloc_index.
	* elf32-i386.c (elf_i386_get_plt_sym_val): Likewise.
2016-02-01 21:27:02 +10:30
H.J. Lu d9e3b59069 Check reloc against IFUNC symbol only with dynamic symbols
There is no need to check relocation IFUNC symbol if there are no
dynamic symbols.

bfd/

	PR ld/19539
	* elf32-i386.c (elf_i386_reloc_type_class): Check relocation
	against STT_GNU_IFUNC symbol only with dynamic symbols.
	* elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise.

ld/

	PR ld/19539
	* testsuite/ld-elf/pr19539.d: New file.
	* testsuite/ld-elf/pr19539.s: Likewise.
	* testsuite/ld-elf/pr19539.t: Likewise.
2016-01-30 16:08:20 -08:00
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
H.J. Lu 02e2aef89b Optimize R_386_GOT32/R_386_GOT32X only if addend is 0
Linker can't optimize R_386_GOT32 and R_386_GOT32X relocations if addend
isn't 0.  It isn't valid to convert

movl	foo@GOT+1(%ecx), %eax

to

leal	foo@GOTOFF+1(%ecx), %eax

nor to convert

movq	foo@GOTPCREL+1(%rip), %rax

to

leaq	foo(%rip), %rax

for x86-64.  We should check if addend is 0 before optimizing R_386_GOT32
and R_386_GOT32X relocations.  Testcases are added for i386 and x86-64.

bfd/

	* elf32-i386.c (elf_i386_convert_load): Skip if addend isn't 0.
	(elf_i386_relocate_section): Skip R_386_GOT32X optimization if
	addend isn't 0.

ld/testsuite/

	* ld-i386/i386.exp: Run mov2a, mov2b and mov3.
	* ld-i386/mov2.s: New file.
	* ld-i386/mov2a.d: Likewise.
	* ld-i386/mov2b.d: Likewise.
	* ld-i386/mov3.d: Likewise.
	* ld-i386/mov3.s: Likewise.
	* ld-x86-64/mov2.s: Likewise.
	* ld-x86-64/mov2a.d: Likewise.
	* ld-x86-64/mov2b.d: Likewise.
	* ld-x86-64/mov2c.d: Likewise.
	* ld-x86-64/mov2d.d: Likewise.
	* ld-x86-64/x86-64.exp: Run mov2a, mov2b, mov2c and mov2d.
2015-12-04 09:03:04 -08:00
H.J. Lu ead3d5427a Properly check symbol defined by assignment in linker script
Symbol defined by a linker assignment may have type bfd_link_hash_new
or bfd_link_hash_undefined.  And h->def_regular is always set.
elf_i386_convert_load and elf_x86_64_convert_load should check
h->def_regular as well as bfd_link_hash_undefined and bfd_link_hash_new
to see if a symbol is defined by a linker script.

bfd/

	PR ld/19319
	* elf32-i386.c (elf_i386_convert_load): Check h->def_regular
	instead of bfd_link_hash_new.
	* elf64-x86-64.c (elf_x86_64_convert_load): Likewise.  Skip
	relocation overflow for bfd_link_hash_undefined and
	bfd_link_hash_new if h->def_regular is set.

ld/testsuite/

	PR ld/19319
	* ld-i386/i386.exp: Run pr19319 test.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr19319.dd: New file.
	* ld-i386/pr19319a.S: Likewise.
	* ld-i386/pr19319b.S: Likewise.
	* ld-x86-64/pr19319.dd: Likewise.
	* ld-x86-64/pr19319a.S: Likewise.
	* ld-x86-64/pr19319b.S: Likewise.
2015-12-01 14:45:51 -08:00
H.J. Lu 18954b29a1 Handle x86 VTINHERIT/VTENTRY relocs when deleting relocations
* elf32-i386.c (elf_i386_relocate_section): Handle VTINHERIT
	and VTENTRY relocations when deleting relocations.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-11-10 04:27:51 -08:00
H.J. Lu 2d5da47320 Properly move kept relocations when deleting relocations
* elf32-i386.c (elf_i386_relocate_section): Properly move
	kept relocations when deleting relocations.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-11-10 00:17:59 -08:00
H.J. Lu 60f2e42e00 Fix performance regression on x86 with ld -r
Similar fix to "commit c316a17c40e44e8798b34ff84130904f2e7a53de".

	* elf32-i386.c (elf_i386_relocate_section): Use read and write
	pointers to reloc array, rather than memmove when deleting a
	reloc.  Don't use RELOC_AGAINST_DISCARDED_SECTION.  Adjust
	reloc counts at end of loop.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-11-10 00:00:04 -08:00
H.J. Lu a3718e9efd Fix a typo in comment in elf32-i386.c
* elf32-i386.c (elf_i386_relocate_section): Fix a typo in
	comment.
2015-10-28 09:15:40 -07:00
H.J. Lu 7b7e7f1da2 Check symbol defined by assignment in linker script
Symbol symbol defined by an assignment in a linker script has type
bfd_link_hash_new.  elf_i386_convert_load and elf_x86_64_convert_load
should check bfd_link_hash_new to see if a symbol is defined by a linker
script.

bfd/

	PR ld/19175
	* elf32-i386.c (elf_i386_convert_load): Check bfd_link_hash_new
	instead of calling bfd_link_get_defined_symbol.
	* elf64-x86-64.c (elf_x86_64_convert_load): Likewise.  Skip
	relocation overflow for bfd_link_hash_new.
	* linker.c (bfd_link_get_defined_symbol): Removed.
	* bfd-in2.h: Regenerated.

ld/testsuite/

	PR ld/19175
	* ld-i386/i386.exp: Run pr19175.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr19175.d: New file.
	* ld-i386/pr19175.s: Likewise.
	* ld-i386/pr19175.t: Likewise.
	* ld-x86-64/pr19175.d: Likewise.
	* ld-x86-64/pr19175.s: Likewise.
	* ld-x86-64/pr19175.t: Likewise.
2015-10-26 16:32:55 -07:00
H.J. Lu a6af384b19 Properly convert address load of __start_XXX/__stop_XXX
Since __start_XXX and __stop_XXX symbols aren't defined when address
load is being converted, we need to check if there is an XXX output
section to get their section and value.  This patch adds a new function,
bfd_link_get_defined_symbol, to search for the XXX output section to
check if __start_XXX and __stop_XXX symbols are defined.

bfd/

	PR ld/19171
	* elf32-i386.c (elf_i386_convert_load): Call
	bfd_link_get_defined_symbol to check if a symbol is defined.
	* elf64-x86-64.c (elf_x86_64_convert_load): Call
	bfd_link_get_defined_symbol to get defined symbol section and
	value.
	* linker.c (bfd_link_get_defined_symbol): New function.
	* bfd-in2.h: Regenerated.

ld/testsuite/

	PR ld/19171
	* ld-i386/lea1.s: Add tests for address load of __start_XXX
	and __stop_XXX.
	* ld-i386/mov1.s: Likewise.
	* ld-x86-64/lea1.s: Likewise.
	* ld-x86-64/mov1.s: Likewise.
	* ld-i386/lea1a.d: Updated.
	* ld-i386/lea1b.d: Likewise.
	* ld-i386/lea1c.d: Likewise.
	* ld-i386/mov1a.d: Likewise.
	* ld-i386/mov1b.d: Likewise.
	* ld-x86-64/lea1a.d: Likewise.
	* ld-x86-64/lea1b.d: Likewise.
	* ld-x86-64/lea1c.d: Likewise.
	* ld-x86-64/lea1d.d: Likewise.
	* ld-x86-64/lea1e.d: Likewise.
	* ld-x86-64/lea1f.d: Likewise.
	* ld-x86-64/mov1a.d: Likewise.
	* ld-x86-64/mov1b.d: Likewise.
	* ld-x86-64/mov1c.d: Likewise.
	* ld-x86-64/mov1d.d: Likewise.
2015-10-26 08:11:55 -07:00
H.J. Lu caa65211bb Add "-z call-nop=PADDING" option to ld
The ld linker can transform indirect call to a locally defined function,
foo, via its GOT slot, to either "NOP call foo" or "call foo NOP" where
NOP is a 1-byte NOP padding.  This patch adds a "-z call-nop=PADDING"
option to x86 ld to control 1-byte NOP padding for x86 call instruction.
PADDING is one of prefix-addr, prefix-nop, suffix-nop, prefix-NUMBER or
suffix-NUMBER.

bfd/

	* elf32-i386.c (elf_i386_convert_load): Use call_nop_byte and
	check call_nop_as_suffix for 1-byte NOP padding to pad call.
	* elf64-x86-64.c (elf_x86_64_convert_load): Likewise.

include/

	* bfdlink.h (bfd_link_info): Add call_nop_as_suffix and
	call_nop_byte.

ld/

	* ld/ld.texinfo: Document "-z call-nop=PADDING" option.
	* emulparams/call_nop.sh: New file.
	* emulparams/elf_i386_be.sh: Source
	${srcdir}/emulparams/call_nop.sh.
	* emulparams/elf_i386_chaos.sh: Likewise.
	* emulparams/elf_i386_ldso.sh: Likewise.
	* emulparams/elf_i386_vxworks.sh: Likewise.
	* emulparams/elf_iamcu.sh: Likewise.
	* emulparams/elf_k1om.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
	link_info.call_nop_byte if $CALL_NOP_BYTE isn't empty.

ld/testsuite/

	* ld-i386/call3.s: New file.
	* ld-i386/call3a.d: Likewise.
	* ld-i386/call3b.d: Likewise.
	* ld-i386/call3c.d: Likewise.
	* ld-i386/call3d.d: Likewise.
	* ld-i386/call3e.d: Likewise.
	* ld-i386/call3f.d: Likewise.
	* ld-i386/call3g.d: Likewise.
	* ld-i386/call3h.d: Likewise.
	* ld-i386/load1-nacl.d: Likewise.
	* ld-x86-64/call1.s: Likewise.
	* ld-x86-64/call1a.d: Likewise.
	* ld-x86-64/call1b.d: Likewise.
	* ld-x86-64/call1c.d: Likewise.
	* ld-x86-64/call1d.d: Likewise.
	* ld-x86-64/call1e.d: Likewise.
	* ld-x86-64/call1f.d: Likewise.
	* ld-x86-64/call1g.d: Likewise.
	* ld-x86-64/call1h.d: Likewise.
	* ld-x86-64/call1i.d: Likewise.
	* ld-x86-64/load1a-nacl.d: Likewise.
	* ld-x86-64/load1b-nacl.d: Likewise.
	* ld-x86-64/load1c-nacl.d: Likewise.
	* ld-x86-64/load1d-nacl.d: Likewise.
2015-10-22 04:56:39 -07:00
H.J. Lu 02a866936d Add R_386_GOT32X support to gas and ld
This patch adds support for the R_386_GOT32X relocation proposed in

https://groups.google.com/forum/#!topic/ia32-abi/GbJJskkid4I

to gas and ld.  It updates gas to generate R_386_GOT32X relocation for
memory operand, foo@GOT[(%reg)].  We must encode "mov foo@GOT, %eax"
with the 0x8b opcode, instead of the 0xb8 opcode, so that it can be
transformed to "lea foo, %eax".  With the locally defined symbol, foo,
we convert

   mov foo@GOT[(%reg1)], %reg2
to
   lea foo[@GOTOFF(%reg1)], %reg2

and convert

   call/jmp *foo@GOT[(%reg)]
to

   nop call foo/jmp foo nop

When PIC is false, convert

   test %reg1, foo@GOT[(%reg2)]
to
   test $foo, %reg1

and convert

binop foo@GOT[(%reg1)], %reg2

to

binop $foo, %reg2

where binop is one of adc, add, and, cmp, or, sbb, sub, xor instructions.

bfd/

	* elf32-i386.c: Include opcode/i386.h.
	(elf_howto_table): Add R_386_GOT32X.
	(R_386_ext2): Replace R_386_IRELATIVE with R_386_GOT32X.
	(elf_i386_reloc_type_lookup): Handle BFD_RELOC_386_GOT32X.
	(need_convert_mov_to_lea): Renamed to ...
	(need_convert_load): This.
	(elf_i386_check_relocs): Handle R_386_GOT32X.  Replace
	need_convert_mov_to_lea with need_convert_load.
	(elf_i386_gc_sweep_hook): Handle R_386_GOT32X.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_convert_mov_to_lea): Renamed to ...
	(elf_i386_convert_load): This.  Replace need_convert_mov_to_lea
	with need_convert_load.  Support R_386_GOT32X transformations.
	* reloc.c (BFD_RELOC_386_GOT32X): New.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

gas/

	* config/tc-i386.c (tc_i386_fix_adjustable): Handle
	BFD_RELOC_386_GOT32X.
	(tc_gen_reloc): Likewise.
	(match_template): Force 0x8b encoding for "mov foo@GOT, %eax".
	(output_disp): Check for "call/jmp *mem", "mov mem, %reg",
	"test %reg, mem" and "binop mem, %reg" where binop is one of
	adc, add, and, cmp, or, sbb, sub, xor instructions.  Set
	fx_tcbit if the REX prefix is generated.  Set fx_tcbit2 if
	BFD_RELOC_386_GOT32X should be generated.
	(i386_validate_fix): Generate BFD_RELOC_386_GOT32X if fx_tcbit2
	is set.

gas/testsuite/

	* gas/i386/got.d: New file.
	* gas/i386/got.s: Likewise.
	* gas/i386/i386.exp: Run got.
	* gas/i386/localpic.d: Replace R_386_GOT32 with R_386_GOT32X.
	* gas/i386/mixed-mode-reloc32.d: Likewise.
	* gas/i386/reloc32.d: Likewise.

include/elf/

	* i386.h (R_386_GOT32X): New relocation.

ld/testsuite/

	* ld-i386/branch1.d: New file.
	* ld-i386/branch1.s: Likewise.
	* ld-i386/call1.d: Likewise.
	* ld-i386/call1.s: Likewise.
	* ld-i386/call2.d: Likewise.
	* ld-i386/call2.s: Likewise.
	* ld-i386/got1.dd: Likewise.
	* ld-i386/got1.out: Likewise.
	* ld-i386/got1a.S: Likewise.
	* ld-i386/got1b.c: Likewise.
	* ld-i386/got1c.c: Likewise.
	* ld-i386/got1d.S: Likewise.
	* ld-i386/jmp1.d: Likewise.
	* ld-i386/jmp1.s: Likewise.
	* ld-i386/jmp2.d: Likewise.
	* ld-i386/jmp2.s: Likewise.
	* ld-i386/load1.d: Likewise.
	* ld-i386/load1.s: Likewise.
	* ld-i386/load2.d: Likewise.
	* ld-i386/load2.s: Likewise.
	* ld-i386/load3.d: Likewise.
	* ld-i386/load3.s: Likewise.
	* ld-i386/load4.s: Likewise.
	* ld-i386/load4a.d: Likewise.
	* ld-i386/load4b.d: Likewise.
	* ld-i386/load5.s: Likewise.
	* ld-i386/load5a.d: Likewise.
	* ld-i386/load5b.d: Likewise.
	* ld-i386/load6.d: Likewise.
	* ld-i386/load6.s: Likewise.
	* ld-i386/i386.exp: Run branch1, call1, call2, jmp1, jmp2,
	load1, load2, load3, load4a, load4b, load5a, load5b and load6
	tests.  Run got1 test.
2015-10-22 04:47:07 -07:00
H.J. Lu 75a06c790f Check if symbol is defined when converting mov to lea
We need to check if symbol is defined when converting mov to lea since
SYMBOL_REFERENCES_LOCAL may return true on hidden undefined symbols.

	* elf32-i386.c (elf_i386_convert_mov_to_lea): Check if symbol
	is defined.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
2015-10-16 04:21:03 -07:00
H.J. Lu b31bcacc48 Convert mov to lea for loading address of local common symbol
There is no need to check def_regular when converting mov to lea for
loading address of local symbols since def_regular may be false for
common symbols and SYMBOL_REFERENCES_LOCAL is sufficient.

bfd/

	* elf32-i386.c (elf_i386_convert_mov_to_lea): Don't check
	def_regular.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.

ld/testsuite/

	* ld-i386/lea1.s: Add a test for loading address of local common
	symbol.
	* ld-x86-64/lea1.s: Likewise.
	* ld-i386/lea1a.d: Updated.
	* ld-i386/lea1b.d: Likewise.
	* ld-i386/lea1c.d: Likewise.
	* ld-x86-64/lea1a.d: Likewise.
	* ld-x86-64/lea1b.d: Likewise.
	* ld-x86-64/lea1c.d: Likewise.
	* ld-x86-64/lea1d.d: Likewise.
	* ld-x86-64/lea1e.d: Likewise.
	* ld-x86-64/lea1f.d: Likewise.
2015-10-16 03:14:40 -07:00
H.J. Lu 4b627c1844 Create a PLT entry for R_386_PC32 in non-code sections
Since something like ".long foo - ." may be used as pointer, we make
sure that PLT is used if foo is a function defined in a shared library.

bfd/

	PR ld/19031
	* elf32-i386.c (elf_i386_check_relocs): Set
	pointer_equality_needed for R_386_PC32 reloc in non-code
	sections.

ld/testsuite/

	PR ld/19031
	* ld-i386/i386.exp: Run PR ld/19031 test.
	* ld/testsuite/ld-i386/pr19031.out: New file.
	* ld/testsuite/ld-i386/pr19031a.c: Likewise.
	* ld/testsuite/ld-i386/pr19031b.S: Likewise.
	* ld/testsuite/ld-i386/pr19031c.c: Likewise.
2015-09-30 08:45:13 -07:00
Rich Felker 9b8b325a1f Add --no-dynamic-linker option to ld, for static PIE use
Inhibits output of .interp section in ELF executables.

include/
	* bfdlink.h (struct bfd_link_info): Add "nointerp" field.
bfd/
	* elflink.c (_bfd_elf_link_create_dynamic_sections): Don't create
	.interp when info->nointerp.
	(bfd_elf_size_dynamic_sections): Adjust assert.
	* elf32-arm.c (elf32_arm_size_dynamic_sections): Don't size .interp
	when info->nointerp.
	* elf32-bfin.c (elf32_bfinfdpic_size_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
	* elf32-cris.c (elf_cris_size_dynamic_sections): Likewise.
	* elf32-frv.c (elf32_frvfdpic_size_dynamic_sections): Likewise.
	* elf32-hppa.c (elf32_hppa_size_dynamic_sections): Likewise.
	* elf32-i370.c (i370_elf_size_dynamic_sections): Likewise.
	* elf32-i386.c (elf_i386_size_dynamic_sections): Likewise.
	* elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
	* elf32-metag.c (elf_metag_size_dynamic_sections): Likewise.
	* elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf32-score.c (s3_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-sh.c (sh_elf_size_dynamic_sections): Likewise.
	* elf32-tic6x.c (elf32_tic6x_size_dynamic_sections): Likewise.
	* elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
	* elf32-xtensa.c (elf_xtensa_size_dynamic_sections): Likewise.
	* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
	* elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise.
	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf64-sh64.c (sh64_elf64_size_dynamic_sections): Likewise.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections): Likewise.
	* elfnn-ia64.c (elfNN_ia64_size_dynamic_sections): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_size_dynamic_sections): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Likewise.
	* elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
ld/
	* ld.texinfo (--no-dynamic-linker): Document.
	* ldlex.h (enum option_values): Add OPTION_NO_DYNAMIC_LINKER.
	* lexsup.c (ld_options, parse_args): Handle --no-dynamic-linker.
2015-09-20 15:52:27 +09:30
H.J. Lu c74be520ba Rename R_386_irelative to R_386_ext2
* elf32-i386.c (R_386_irelative): Renamed to ...
	(R_386_ext2): This.
	(R_386_vt_offset): Updated.
	(elf_i386_rtype_to_howto): Likewise.
	(elf_i386_relocate_section): Likewise.
2015-09-02 05:13:08 -07:00
H.J. Lu 04ebc307f9 Skip PLT for function pointer initialization
We use its PLT entry to initialize function pointer at run-time.  If
there is no other usage for the PLT entry, we can generate run-time
function pointer relocations in read-write section, which can be
resolved by dynamic linker, to initialize function pointers.  It avoids
the extra indirect branch overhead in PLT.

bfd/

	PR ld/18900
	* elf32-i386.c (elf_i386_link_hash_entry): Add
	func_pointer_refcount.
	(elf_i386_link_hash_newfunc): Clear func_pointer_refcount.
	(elf_i386_get_local_sym_hash): Likewise.
	(elf_i386_copy_indirect_symbol): Also copy
	func_pointer_refcount.
	(elf_i386_check_relocs): Increment func_pointer_refcount.
	(elf_i386_gc_sweep_hook): Decrement func_pointer_refcount.
	(elf_i386_allocate_dynrelocs): Don't create the PLT entry if
	there are only function pointer relocations which can be
	resolved at run-time.  Keep dynanamic relocations for run-time
	function pointer initialization.
	(elf_i386_relocate_section): Copy dynamic function pointer
	relocations.
	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add
	func_pointer_refcount.
	(elf_x86_64_link_hash_newfunc): Clear func_pointer_refcount.
	(elf_x86_64_get_local_sym_hash): Likewise.
	(elf_x86_64_copy_indirect_symbol): Also copy
	func_pointer_refcount.
	(elf_x86_64_check_relocs): Increment func_pointer_refcount.
	(elf_x86_64_gc_sweep_hook): Decrement func_pointer_refcount.
	(elf_x86_64_allocate_dynrelocs): Don't create the PLT entry if
	there are only function pointer relocations which can be
	resolved at run-time.  Keep dynanamic relocations for run-time
	function pointer initialization.
	(elf_x86_64_relocate_section): Copy dynamic function pointer
	relocations.

ld/testsuite/

	PR ld/18900
	* ld-i386/i386.exp: Run tests for PR ld/18900.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr18900.out: New file.
	* ld-i386/pr18900a.c: Likewise.
	* ld-i386/pr18900a.c: Likewise.
	* ld-i386/pr18900a.rd: Likewise.
	* ld-i386/pr18900b.c: Likewise.
	* ld-i386/pr18900b.rd: Likewise.
	* ld-i386/pr18900c.c: Likewise.
	* ld-x86-64/pr18900.out: Likewise.
	* ld-x86-64/pr18900a.c: Likewise.
	* ld-x86-64/pr18900a.rd: Likewise.
	* ld-x86-64/pr18900b.c: Likewise.
	* ld-x86-64/pr18900b.rd: Likewise.
	* ld-x86-64/pr18900c.c: Likewise.
	* ld-x86-64/mpx3.dd: Updated.
2015-09-01 05:06:33 -07:00
H.J. Lu cae1fbbb7e Return reloc_class_ifunc for reloc against IFUNC
elf_XXX_reloc_type_class should return reloc_class_ifunc for relocation
against STT_GNU_IFUNC symbol.

bfd/

	PR ld/18841
	* elf-bfd.h (elf_link_hash_table): Add dynsym.
	* elf32-i386.c (elf_i386_reloc_type_class): Return
	reloc_class_ifunc for relocation against STT_GNU_IFUNC symbol.
	* elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise.
	* elflink.c (_bfd_elf_link_create_dynamic_sections): Set dynsym.
	(bfd_elf_size_dynsym_hash_dynstr): Use dynsym.
	(elf_final_link_info): Remove dynsym_sec.
	(elf_link_output_extsym): Replace dynsym_sec with dynsym.
	(bfd_elf_final_link): Remove reference to dynsym_sec.  Replace
	dynsym_sec with dynsym.

ld/testsuite/

	PR ld/18841
	* ld-ifunc/ifunc.exp: Add a test for PR ld/18841.
	* ld-ifunc/pr18841.out: New file.
	* ld-ifunc/pr18841a.c: Likewise.
	* ld-ifunc/pr18841b.c: Likewise.
2015-08-18 09:50:08 -07:00
H.J. Lu 0e1862bb40 Add output_type to bfd_link_info
The "shared" field in bfd_link_info is set for both DSO and and PIE.
There are separate fields for executable and relocatable outputs.  This
patch adds an "output_type" field:

enum output_type
{
  type_unknown = 0,
  type_executable,
  type_dll,
  type_relocatable
};

and a "pic" field to bfd_link_info to replace shared, executable and
relocatable fields so that we can use the "output_type" field to check
for output type and the "pic" field check if output is PIC.  Macros,
bfd_link_executable, bfd_link_dll, bfd_link_relocatable, bfd_link_pic
and bfd_link_pie, are provided to check for output features.

bfd/

	* bfd/aoutx.h: Replace shared, executable, relocatable and pie
	fields with bfd_link_executable, bfd_link_dll,
	bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
	* bfd/bout.c: Likewise.
	* bfd/coff-alpha.c: Likewise.
	* bfd/coff-arm.c: Likewise.
	* bfd/coff-i386.c: Likewise.
	* bfd/coff-i960.c: Likewise.
	* bfd/coff-m68k.c: Likewise.
	* bfd/coff-mcore.c: Likewise.
	* bfd/coff-mips.c: Likewise.
	* bfd/coff-ppc.c: Likewise.
	* bfd/coff-rs6000.c: Likewise.
	* bfd/coff-sh.c: Likewise.
	* bfd/coff-tic80.c: Likewise.
	* bfd/coff-x86_64.c: Likewise.
	* bfd/coff64-rs6000.c: Likewise.
	* bfd/coffgen.c: Likewise.
	* bfd/cofflink.c: Likewise.
	* bfd/ecoff.c: Likewise.
	* bfd/ecofflink.c: Likewise.
	* bfd/elf-bfd.h: Likewise.
	* bfd/elf-eh-frame.c: Likewise.
	* bfd/elf-ifunc.c: Likewise.
	* bfd/elf-m10200.c: Likewise.
	* bfd/elf-m10300.c: Likewise.
	* bfd/elf-s390-common.c: Likewise.
	* bfd/elf-vxworks.c: Likewise.
	* bfd/elf.c: Likewise.
	* bfd/elf32-arm.c: Likewise.
	* bfd/elf32-avr.c: Likewise.
	* bfd/elf32-bfin.c: Likewise.
	* bfd/elf32-cr16.c: Likewise.
	* bfd/elf32-cr16c.c: Likewise.
	* bfd/elf32-cris.c: Likewise.
	* bfd/elf32-crx.c: Likewise.
	* bfd/elf32-d10v.c: Likewise.
	* bfd/elf32-dlx.c: Likewise.
	* bfd/elf32-epiphany.c: Likewise.
	* bfd/elf32-fr30.c: Likewise.
	* bfd/elf32-frv.c: Likewise.
	* bfd/elf32-ft32.c: Likewise.
	* bfd/elf32-h8300.c: Likewise.
	* bfd/elf32-hppa.c: Likewise.
	* bfd/elf32-i370.c: Likewise.
	* bfd/elf32-i386.c: Likewise.
	* bfd/elf32-i860.c: Likewise.
	* bfd/elf32-ip2k.c: Likewise.
	* bfd/elf32-iq2000.c: Likewise.
	* bfd/elf32-lm32.c: Likewise.
	* bfd/elf32-m32c.c: Likewise.
	* bfd/elf32-m32r.c: Likewise.
	* bfd/elf32-m68hc11.c: Likewise.
	* bfd/elf32-m68hc1x.c: Likewise.
	* bfd/elf32-m68k.c: Likewise.
	* bfd/elf32-mcore.c: Likewise.
	* bfd/elf32-mep.c: Likewise.
	* bfd/elf32-metag.c: Likewise.
	* bfd/elf32-microblaze.c: Likewise.
	* bfd/elf32-moxie.c: Likewise.
	* bfd/elf32-msp430.c: Likewise.
	* bfd/elf32-mt.c: Likewise.
	* bfd/elf32-nds32.c: Likewise.
	* bfd/elf32-nios2.c: Likewise.
	* bfd/elf32-or1k.c: Likewise.
	* bfd/elf32-ppc.c: Likewise.
	* bfd/elf32-rl78.c: Likewise.
	* bfd/elf32-rx.c: Likewise.
	* bfd/elf32-s390.c: Likewise.
	* bfd/elf32-score.c: Likewise.
	* bfd/elf32-score7.c: Likewise.
	* bfd/elf32-sh-symbian.c: Likewise.
	* bfd/elf32-sh.c: Likewise.
	* bfd/elf32-sh64.c: Likewise.
	* bfd/elf32-spu.c: Likewise.
	* bfd/elf32-tic6x.c: Likewise.
	* bfd/elf32-tilepro.c: Likewise.
	* bfd/elf32-v850.c: Likewise.
	* bfd/elf32-vax.c: Likewise.
	* bfd/elf32-visium.c: Likewise.
	* bfd/elf32-xc16x.c: Likewise.
	* bfd/elf32-xstormy16.c: Likewise.
	* bfd/elf32-xtensa.c: Likewise.
	* bfd/elf64-alpha.c: Likewise.
	* bfd/elf64-hppa.c: Likewise.
	* bfd/elf64-ia64-vms.c: Likewise.
	* bfd/elf64-mmix.c: Likewise.
	* bfd/elf64-ppc.c: Likewise.
	* bfd/elf64-s390.c: Likewise.
	* bfd/elf64-sh64.c: Likewise.
	* bfd/elf64-x86-64.c: Likewise.
	* bfd/elflink.c: Likewise.
	* bfd/elfnn-aarch64.c: Likewise.
	* bfd/elfnn-ia64.c: Likewise.
	* bfd/elfxx-mips.c: Likewise.
	* bfd/elfxx-sparc.c: Likewise.
	* bfd/elfxx-tilegx.c: Likewise.
	* bfd/i386linux.c: Likewise.
	* bfd/linker.c: Likewise.
	* bfd/m68klinux.c: Likewise.
	* bfd/pdp11.c: Likewise.
	* bfd/pe-mips.c: Likewise.
	* bfd/peXXigen.c: Likewise.
	* bfd/reloc.c: Likewise.
	* bfd/reloc16.c: Likewise.
	* bfd/sparclinux.c: Likewise.
	* bfd/sunos.c: Likewise.
	* bfd/vms-alpha.c: Likewise.
	* bfd/xcofflink.c: Likewise.

include/

	* include/bfdlink.h (output_type): New enum.
	(bfd_link_executable): New macro.
	(bfd_link_dll): Likewise.
	(bfd_link_relocatable): Likewise.
	(bfd_link_pic): Likewise.
	(bfd_link_pie): Likewise.
	(bfd_link_info): Remove shared, executable, pie and relocatable.
	Add output_type and pic.

ld/

	* ld/ldctor.c: Replace shared, executable, relocatable and pie
	fields with bfd_link_executable, bfd_link_dll,
	bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
	* ld/ldemul.c: Likewise.
	* ld/ldfile.c: Likewise.
	* ld/ldlang.c: Likewise.
	* ld/ldmain.c: Likewise.
	* ld/ldwrite.c: Likewise.
	* ld/lexsup.c: Likewise.
	* ld/pe-dll.c: Likewise.
	* ld/plugin.c: Likewise.
	* ld/emultempl/aarch64elf.em: Likewise.
	* ld/emultempl/aix.em: Likewise.
	* ld/emultempl/alphaelf.em: Likewise.
	* ld/emultempl/armcoff.em: Likewise.
	* ld/emultempl/armelf.em: Likewise.
	* ld/emultempl/avrelf.em: Likewise.
	* ld/emultempl/beos.em: Likewise.
	* ld/emultempl/cr16elf.em: Likewise.
	* ld/emultempl/elf-generic.em: Likewise.
	* ld/emultempl/elf32.em: Likewise.
	* ld/emultempl/genelf.em: Likewise.
	* ld/emultempl/generic.em: Likewise.
	* ld/emultempl/gld960.em: Likewise.
	* ld/emultempl/gld960c.em: Likewise.
	* ld/emultempl/hppaelf.em: Likewise.
	* ld/emultempl/irix.em: Likewise.
	* ld/emultempl/linux.em: Likewise.
	* ld/emultempl/lnk960.em: Likewise.
	* ld/emultempl/m68hc1xelf.em: Likewise.
	* ld/emultempl/m68kcoff.em: Likewise.
	* ld/emultempl/m68kelf.em: Likewise.
	* ld/emultempl/metagelf.em: Likewise.
	* ld/emultempl/mipself.em: Likewise.
	* ld/emultempl/mmo.em: Likewise.
	* ld/emultempl/msp430.em: Likewise.
	* ld/emultempl/nds32elf.em: Likewise.
	* ld/emultempl/needrelax.em: Likewise.
	* ld/emultempl/nios2elf.em: Likewise.
	* ld/emultempl/pe.em: Likewise.
	* ld/emultempl/pep.em: Likewise.
	* ld/emultempl/ppc32elf.em: Likewise.
	* ld/emultempl/ppc64elf.em: Likewise.
	* ld/emultempl/sh64elf.em: Likewise.
	* ld/emultempl/solaris2.em: Likewise.
	* ld/emultempl/spuelf.em: Likewise.
	* ld/emultempl/sunos.em: Likewise.
	* ld/emultempl/tic6xdsbt.em: Likewise.
	* ld/emultempl/ticoff.em: Likewise.
	* ld/emultempl/v850elf.em: Likewise.
	* ld/emultempl/vms.em: Likewise.
	* ld/emultempl/vxworks.em: Likewise.
2015-08-18 05:51:19 -07:00
H.J. Lu 8efa2874ab Issue an error for read-only segment with dynamic IFUNC relocations
To load an ELF binary with DT_TEXTREL tag, the dynamic linker calls
__mprotect on the read-only segment with PROT_READ|PROT_WRITE before
applying dynamic relocation.  It leads to segfault when performing
IFUNC relocations since the read-only segment has no execute permission.
This patch changes x86 linker to issue an error for read-only segment
with dynamic IFUNC relocations.  Other backends with IFUNC support
may need a similar change.

bfd/

	PR ld/18801
	* elf32-i386.c (elf_i386_size_dynamic_sections): Issue an error
	for read-only segment with dynamic IFUNC relocations.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.

ld/testsuite/

	PR ld/18801
	* ld-i386/i386.exp: Run pr18801.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr18801.d: New file.
	* ld-i386/pr18801.s: Likewise.
	* ld-x86-64/pr18801.d: Likewise.
	* ld-x86-64/pr18801.s: Likewise.
2015-08-13 04:31:38 -07:00
H.J. Lu 13a2df29c9 Set EI_OSABI to ELFOSABI_GNU for local IFUNC symbols
Since the backend elf_add_symbol_hook isn't called on local symbols,
the EI_OSABI field isn't to ELFOSABI_GNU where are local IFUNC symbols.
This patch changes the x86 backends to set has_gnu_symbols if there are
relocations against IFUNC symbols.  Other backends with IFUNC support
may need a similar change.

This patch also changes the type of has_gnu_symbols from bfd_boolean to
enum elf_gnu_symbols.

bfd/

	PR ld/18815
	* elf-bfd.h (elf_gnu_symbols): New enum.
	(elf_obj_tdata): Use elf_gnu_symbols on has_gnu_symbols.
	* elf-s390-common.c (elf_s390_add_symbol_hook): Set
	has_gnu_symbols to elf_gnu_symbol_any.
	* elf32-arm.c (elf32_arm_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* lfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elf32-i386.c (elf_i386_check_relocs): Update has_gnu_symbols
	if there are relocations against IFUNC symbols.
	(elf_i386_add_symbol_hook): Don't check STT_GNU_IFUNC here.
	* elf64-x86-64. (elf_x86_64_check_relocs): Update has_gnu_symbols
	if there are relocations against IFUNC symbols.
	(elf_x86_64_add_symbol_hook): Don't check STT_GNU_IFUNC here.

ld/testsuite/

	PR ld/18815
	* ld-i386/i386.exp: Run pr18815.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr18815.d: New file.
	* ld-i386/pr18815.s: Likewise.
	* ld-x86-64/pr18815.d: Likewise.
	* ld-x86-64/pr18815.s: Likewise.
2015-08-12 13:47:41 -07:00
H.J. Lu 0eace2105d Properly skip IFUNC relocations in debug sections
Use "continue" instead of "break" to skip IFUNC relocations in debug
sections.

	* elf32-i386.c (elf_i386_relocate_section): Properly skip IFUNC
	relocations in debug sections.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-08-11 19:04:38 -07:00
H.J. Lu 97dc35c88d Skip IFUNC relocations in debug sections
Skip IFUNC relocations in debug sections ignored by ld.so.

bfd/

	PR ld/18808
	* elf32-i386.c (elf_i386_relocate_section): Skip IFUNC
	relocations in debug sections.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.

ld/testsuite/

	PR ld/18808
	* ld-ifunc/ifunc.exp: Add a test for PR ld/18808.
	* ld-ifunc/pr18808.out: New file.
	* ld-ifunc/pr18808a.c: Likewise.
	* ld-ifunc/pr18808b.c: Likewise.
2015-08-11 12:59:11 -07:00
H.J. Lu 7c1e8d3ed5 Keep .plt section and DT_PLTGOT for prelink
Since the .plt section and DT_PLTGOT are used by prelink to undo
prelinking for dynamic relocations, we must keep them even if there is
no PLT relocation.  This patch reverted commit a3747075a.

bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Always allocate
	space for the first .plt entry.
	(elf_i386_size_dynamic_sections): Always add DT_PLTGOT for .plt
	section.  Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
	there are PLT relocations.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Always
	allocate space for the first .plt entry.
	(elf_x86_64_size_dynamic_sections): Always add DT_PLTGOT for
	.plt section.  Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
	there are PLT relocations.

ld/testsuite/

	* ld-i386/i386.exp: Run pltgot-2 for Linux targets.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pltgot-1.d: Updated.
	* ld-x86-64/pltgot-1.d: Likewise.
	* ld-i386/pltgot-2.d: New file.
	* ld-x86-64/pltgot-2.d: Likewise.
2015-06-24 13:47:37 -07:00
H.J. Lu 8ded2ddc8b Convert PLT reloc only if pointer equality isn't needed
When pointer equality needed, we can't replace PLT relocations with
GOT relocations for -z now.  This patch checks if pointer equality is
needed before converting PLT relocations to GOT relocations.

bfd/

	PR binutils/18458
	* elf32-i386.c (elf_i386_check_relocs): Create .plt.got section
	for now binding only if pointer equality isn't needed.
	(elf_i386_allocate_dynrelocs): Use .plt.got section for now
	binding only if pointer equality isn't needed.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Create .plt.got
	section for now binding only if pointer equality isn't needed.
	(elf_x86_64_allocate_dynrelocs): Use .plt.got section for now
	binding only if pointer equality isn't needed.

ld/testsuite/

	PR binutils/18458
	* ld-elf/shared.exp (build_tests): Build libpr18458a.so and
	libpr18458b.so.
	(run_tests): Run pr18458 test.
	* ld-elf/pr18458a.c: New file.
	* ld-elf/pr18458b.c: Likewise.
	* ld-elf/pr18458c.c: Likewise.
2015-05-27 14:32:24 -07:00
H.J. Lu fca6ae69c4 Skip extra relocations in .rel.plt/.rela.plt
Extra relocations may be added to the .rel.plt/.rela.plt section, which
are unrelated to PLT.  We should skip them when retrieving PLT entry
symbol values.

	PR binutils/18437
	* elf32-i386.c (elf_i386_get_plt_sym_val): Skip extra relocations
	in .rel.plt/.rela.plt.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-05-20 07:55:45 -07:00
H.J. Lu 25070364b0 Don't generate PLT relocations for now binding
There is no need for PLT relocations with -z now. We can use GOT
relocations, which take less space, instead and replace 16-byte .plt
entres with 8-byte .plt.got entries.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Create .plt.got section
	for now binding.
	(elf_i386_allocate_dynrelocs): Use .plt.got section for now
	binding.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Create .plt.got
	section for now binding.
	(elf_x86_64_allocate_dynrelocs): Use .plt.got section for now
	binding.

ld/testsuite/

	* ld-i386/i386.exp: Run PR ld/17689 tests with -z now.
	* ld-x86-64/x86-64.exp: Likewise
	* ld-i386/pr17689now.rd: New file.
	* ld-x86-64/pr17689now.rd: Likewise
2015-05-16 07:00:55 -07:00
H.J. Lu a3747075ae Allocate the first .plt entry space only if needed
Commit dd7e64d45b may optimize out
i386/x86-64 JUMP_SLOT relocation.  If there is no JUMP_SLOT relocation
left, we don't need to the first .plt entry.  This patch allocates
space for the first .plt entry only if we also reserve space for a PLT
slot for JUMP_SLOT relocation.

bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Allocate space
	for the first .plt entry only if needed.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.

ld/testsuite/

	* ld-i386/i386.exp: Run pltgot-1 for Linux targets.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pltgot-1.d: New file.
	* ld-i386/pltgot-1.s: Likewise.
	* ld-x86-64/pltgot-1.d: Likewise.
	* ld-x86-64/pltgot-1.s: Likewise.
2015-05-12 13:11:48 -07:00
H.J. Lu bf64a9511f Add Intel MCU support to bfd
bfd/

	* Makefile.am (ALL_MACHINES): Add cpu-iamcu.lo.
	(ALL_MACHINES_CFILES): Likewise.
	* archures.c (bfd_mach_iamcu): New.
	(bfd_mach_i386_iamcu): Likewise.
	(bfd_mach_i386_iamcu_intel_syntax): Likewise.
	(bfd_iamcu_arch): Likewise.
	(bfd_archures_list): Add &bfd_iamcu_arch.
	* config.bfd (targ_selvecs): Add iamcu_elf32_vec to
	i386_elf32_vec.
	(targ_archs): Add bfd_iamcu_arch if needed.
	* configure.ac: Support iamcu_elf32_vec.
	* cpu-iamcu.c: New file.
	* elf32-i386.c (elf32_iamcu_elf_object_p): New function.
	Add support for iamcu_elf32_vec and elf32_iamcu_bed.
	* targets.c (iamcu_elf32_vec): New.
	(_bfd_target_vector): Add iamcu_elf32_vec.
	* Makefile.in: Regenerated.
	* bfd-in2.h: Likewise.
	* configure: Likewise.

binutils/testsuite/

	* binutils-all/objdump.exp (cpus_expected): Append iamcu.
2015-05-11 10:31:00 -07:00
H.J. Lu 4b71eec627 Replace input_bfd and output_bfd with abfd
The first argument to bfd_get_8/bfd_put_8 isn't used.  But we should
use something real.  Replace input_bfd and output_bfd with abfd.

	* elf32-i386.c (elf_i386_convert_mov_to_lea): Replace input_bfd
	and output_bfd with abfd.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
2015-05-10 06:44:12 -07:00
H.J. Lu 914082d11b Undef elf_backend_post_process_headers for Solaris
* elf32-i386.c (elf_backend_post_process_headers): Undef for
	Solaris 2.
2015-04-30 06:52:34 -07:00
H.J. Lu d5597ebccc i386: Allow copy relocs for building PIE
This patch allows copy relocs for R_386_GOTOFF relocations in PIE.  For

extern int glob_a;
int foo ()
{
  return glob_a;
}

compiler now can optimize it from

	call	__x86.get_pc_thunk.ax
	addl	$_GLOBAL_OFFSET_TABLE_, %eax
	movl	glob_a@GOT(%eax), %eax
	movl	(%eax), %eax
	ret

to

	call	__x86.get_pc_thunk.ax
	addl	$_GLOBAL_OFFSET_TABLE_, %eax
	movl	glob_a@GOTOFF(%eax), %eax
	ret

bfd/

	PR ld/18289
	* elf32-i386.c (elf_i386_link_hash_entry): Add gotoff_ref.
	(elf_i386_link_hash_newfunc): Initialize gotoff_ref to 0.
	(elf_i386_create_dynamic_sections): Always allow copy relocs for
	building executables.
	(elf_i386_copy_indirect_symbol): Also copy gotoff_ref.
	(elf_i386_check_relocs): Set gotoff_ref for R_386_GOTOFF.
	(elf_i386_adjust_dynamic_symbol): Also allocate copy relocs for
	PIE and R_386_GOTOFF.
	(elf_i386_relocate_section): Allow R_386_GOTOFF in executable.

ld/testsuite/

	PR ld/18289
	* ld-i386/copyreloc-lib.c: New file.
	* ld-i386/copyreloc-main.S: Likewise.
	* ld-i386/copyreloc-main.out: Likewise.
	* ld-i386/copyreloc-main1.rd: Likewise.
	* ld-i386/copyreloc-main2.rd: Likewise.
	* ld-i386/dummy.c: Likewise.
	* ld-i386/pr17689.out: Likewise.
	* ld-i386/pr17689.rd: Likewise.
	* ld-i386/pr17689a.c: Likewise.
	* ld-i386/pr17689b.S: Likewise.
	* ld-i386/pr17827.rd: Likewise.
	* ld-i386/pr17827ver.rd: Likewise.
	* ld-i386/i386.exp: Run copyreloc tests.
2015-04-22 05:30:01 -07:00
H.J. Lu e3c0e32792 Replace SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL
When checking R_386_GOTOFF/R_X86_64_GOTOFF64 for building shared library,
we should check SYMBOL_REFERENCES_LOCAL instead of SYMBOLIC_BIND to cover
more cases.

bfd/

	* elf32-i386.c (elf_i386_relocate_section): Replace SYMBOLIC_BIND
	with SYMBOL_REFERENCES_LOCAL when checking R_386_GOTOFF against
	protected data symbol when building shared library.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Check
	R_X86_64_GOTOFF64 against undefined symbol and replace
	SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL when checking
	R_X86_64_GOTOFF64 against protected data symbol when building
	shared library.

ld/testsuite/

	* ld-i386/i386.exp: Run protected6a.
	* ld-i386/protected6.d: Renamed to ...
	* ld-i386/protected6a.d: This.
	* ld-x86-64/hidden4.d: New file.
	* ld-x86-64/hidden4.s: Likewise.
	* ld-x86-64/hidden5.d: Likewise.
	* ld-x86-64/hidden5.s: Likewise.
	* ld-x86-64/protected6.d: Renamed to ...
	* ld-x86-64/protected6a.d: This.
	* ld-x86-64/x86-64.exp: Run hidden4, hidden5, protected6a,
	protected7a and protected7b.
2015-04-11 07:56:48 -07:00
H.J. Lu 3d9499950a Check GOTOFF reloc against protected data on x86
R_386_GOTOFF/R_X86_64_GOTOFF64 relocation shouldn't be used against
protected data symbol on x86 since with copy relocation, address of
protected data defined in the shared library may be external.

This patch will break building shared libraries with protected data
symbols using GCCs older than GCC 5 without the bug fix for

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248

GCC backport request should be made in the GCC bug report above.

bfd/

	PR ld/pr17709
	* elf32-i386.c (elf_i386_relocate_section): Also check R_386_GOTOFF
	against protected data symbol when building shared library.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Also check
	R_X86_64_GOTOFF64 against protected data symbol when building
	shared library.

ld/testsuite/

	PR ld/pr17709
	* ld-i386/protected6.d: New file.
	* ld-i386/protected6.s: Likewise.
	* ld-x86-64/protected6.d: Likewise.
	* ld-x86-64/protected6.s: Likewise.
	* ld-x86-64/protected7.d: Likewise.
	* ld-x86-64/protected7.s: Likewise.
	* ld-x86-64/protected7a.d: Likewise.
	* ld-x86-64/protected7b.d: Likewise.
2015-04-10 14:02:23 -07:00
H.J. Lu f74839702e Add extern_protected_data and set it for x86
Re-apply: commit ca3fe95e46

With copy relocation, address of protected data defined in the shared
library may be external.  This patch adds extern_protected_data and
changes _bfd_elf_symbol_refs_local_p to return false for protected data
if extern_protected_data is true.

This patch will break building shared libraries with protected data
symbols using GCCs older than GCC 5 without the bug fix for

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248

GCC backport request should be made in the GCC bug report above.

To get correct run-time behavior on Linux, glibc 2.22 or above are
required, which have the bug fix for

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

Backports for glibc 2.21, 2.20, 2.19 and 2.18 are on hjl/pr17711/2.21,
hjl/pr17711/2.20, hjl/pr17711/2.19 and hjl/pr17711/2.18 branches,
respectively, at

https://sourceware.org/git/?p=glibc.git;a=summary

bfd/

	PR ld/pr15228
	PR ld/pr17709
	* elf-bfd.h (elf_backend_data): Add extern_protected_data.
	* elf32-i386.c (elf_backend_extern_protected_data): New.
	Defined to 1.
	* elf64-x86-64.c (elf_backend_extern_protected_data): Likewise.
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Don't error on
	copy relocs against protected symbols if extern_protected_data
	is true.
	(_bfd_elf_symbol_refs_local_p): Don't return true on protected
	non-function symbols if extern_protected_data is true.
	* elfxx-target.h (elf_backend_extern_protected_data): New.
	Default to 0.
	(elfNN_bed): Initialize extern_protected_data with
	elf_backend_extern_protected_data.

ld/testsuite/

	PR ld/pr15228
	PR ld/pr17709
	* ld-i386/i386.exp (i386tests): Add a test for PR ld/17709.
	* ld-i386/pr17709-nacl.rd: New file.
	* ld-i386/pr17709.rd: Likewise.
	* ld-i386/pr17709a.s: Likewise.
	* ld-i386/pr17709b.s: Likewise.
	* ld-i386/protected3.d: Updated.
	* ld-i386/protected3.s: Likewise.
	* ld-x86-64/pr17709-nacl.rd: New file.
	* ld-x86-64/pr17709.rd: Likewise.
	* ld-x86-64/pr17709a.s: Likewise.
	* ld-x86-64/pr17709b.s: Likewise.
	* ld-x86-64/protected3.d: Updated.
	* ld-x86-64/protected3.s: Likewise.
	* ld-x86-64/x86-64.exp (x86_64tests): Add a test for PR ld/17709.
2015-04-10 11:06:34 -07:00
Alan Modra 8d2ea2a80a Revert "Add extern_protected_data and set it for x86"
This reverts commit ca3fe95e46.
2015-04-10 19:16:47 +09:30
H.J. Lu ca3fe95e46 Add extern_protected_data and set it for x86
With copy relocation, address of protected data defined in the shared
library may be external.  This patch adds extern_protected_data and
changes _bfd_elf_symbol_refs_local_p to return false for protected data
if extern_protected_data is true.

bfd/

	PR ld/pr15228
	PR ld/pr17709
	* elf-bfd.h (elf_backend_data): Add extern_protected_data.
	* elf32-i386.c (elf_backend_extern_protected_data): New.
	Defined to 1.
	* elf64-x86-64.c (elf_backend_extern_protected_data): Likewise.
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Don't error on
	copy relocs against protected symbols if extern_protected_data
	is true.
	(_bfd_elf_symbol_refs_local_p): Don't return true on protected
	non-function symbols if extern_protected_data is true.
	* elfxx-target.h (elf_backend_extern_protected_data): New.
	Default to 0.
	(elfNN_bed): Initialize extern_protected_data with
	elf_backend_extern_protected_data.

ld/testsuite/

	PR ld/pr15228
	PR ld/pr17709
	* ld-i386/i386.exp (i386tests): Add a test for PR ld/17709.
	* ld-i386/pr17709-nacl.rd: New file.
	* ld-i386/pr17709.rd: Likewise.
	* ld-i386/pr17709a.s: Likewise.
	* ld-i386/pr17709b.s: Likewise.
	* ld-i386/protected3.d: Updated.
	* ld-i386/protected3.s: Likewise.
	* ld-x86-64/pr17709-nacl.rd: New file.
	* ld-x86-64/pr17709.rd: Likewise.
	* ld-x86-64/pr17709a.s: Likewise.
	* ld-x86-64/pr17709b.s: Likewise.
	* ld-x86-64/protected3.d: Updated.
	* ld-x86-64/protected3.s: Likewise.
	* ld-x86-64/x86-64.exp (x86_64tests): Add a test for PR ld/17709.
2015-03-05 06:34:53 -08:00
H.J. Lu c1d11331c9 Convert mov to lea only if needed
We can convert mov to lea only if there are R_386_GOT32/R_X86_64_GOTPCREL
relocations against non IFUNC symbols.

	* elf32-i386.c (need_convert_mov_to_lea): New.
	(elf_i386_check_relocs): Set need_convert_mov_to_lea if needed.
	(elf_i386_convert_mov_to_lea): Return TRUE if
	need_convert_mov_to_lea is unset.
	* elf64-x86-64.c (need_convert_mov_to_lea): New.
	(elf_x86_64_check_relocs): Set need_convert_mov_to_lea if needed.
	(elf_x86_64_convert_mov_to_lea): Return TRUE if
	need_convert_mov_to_lea is unset.
2015-02-27 11:35:37 -08:00
H.J. Lu 576fa8831a Set root.linker_def on _TLS_MODULE_BASE_
* elf32-i386.c (elf_i386_always_size_sections): Set root.linker_def
	on _TLS_MODULE_BASE_.
	* elf64-x86-64.c (elf_x86_64_always_size_sections): Likewise.
2015-02-15 09:56:08 -08:00
Ed Maste 35181b3eaa Avoid incrementing uninitialized variable
* elf32-i386.c (elf_i386_get_plt_sym_val): Avoid incrementing
	uninitialized and unused variable.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-02-09 13:55:34 -08:00
H.J. Lu 1952c5cd7d Issue relocation in RO section warning for -z text
This patch changes linker to issue a warning for relocation in readonly
section for -z text.

bfd/

	PR ld/17935
	* elf32-i386.c (elf_i386_readonly_dynrelocs): Also issue a
	warning for relocation in readonly section for -z text.
	(elf_i386_size_dynamic_sections): Likewise.
	* elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise.
	(elf_x86_64_size_dynamic_sections): Likewise.

ld/testsuite/

	PR ld/17935
	* ld-i386/i386.exp: Run pr17935-1 and pr17935-2.
	* ld-x86-64/x86-64.exp: Likewise.

	* ld-i386/pr17935-1.d: New file.
	* ld-i386/pr17935-1.s: Likewise.
	* ld-i386/pr17935-2.d: Likewise.
	* ld-i386/pr17935-2.s: Likewise.
	* ld-x86-64/pr17935-1.d: Likewise.
	* ld-x86-64/pr17935-1.s: Likewise.
	* ld-x86-64/pr17935-2.d: Likewise.
	* ld-x86-64/pr17935-2.s: Likewise.
2015-02-07 05:28:06 -08:00
Alan Modra 6346d5ca43 Fallout from recent bfd_reloc_outofrange changes
Commit ec93045b and cd21f5da introduced a large number of tic4x and
tic54x regressions, due to the new checks being wrong for targets
with octets_per_byte != 1.  To fix that I introduced a new
bfd_get_section_limit_octets and performed the check on octets rather
than byte adresses, reducing the number of bfd_octets_per_byte calls.
bfd_octets_per_byte is rather expensive..

I then wondered why the same bfd_reloc_outofrange check added to
bfd_perform_relocation wasn't also added to bfd_install_relocation.
The two functions are virtually identical and ought to remain that
way.  However, adding the same check to bfd_install_relocation
resulted in ld-elf "FAIL Link eh-group.o to eh-group" on many ELF
targets, including x64_64-linux.  The reason being that eh-group.o
has NONE relocs at the end of a section, and most targets give NONE
relocs a non-zero size.  So if we are to keep the new outofrange
check it appears that NONE relocs must have a zero size.

	* bfd-in.h (bfd_get_section_limit_octets): New define, extracted from..
	(bfd_get_section_limit): ..here.
	* reloc.c (bfd_perform_relocation): Correct bfd_reloc_outofrange check.
	(bfd_install_relocation, _bfd_final_link_relocate): Add same check here.
	* elf32-sh.c (sh_elf_reloc): Correct bfd_reloc_outofrange check.
	* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Remove duplicated
	bfd_reloc_outofrange check.
	* bfd-in2.h: Regenerate.

	* cpu-ns32k.c (_bfd_do_ns32k_reloc_contents): Return bfd_reloc_ok
	on zero size relocs.
	* ecoff.c (ecoff_reloc_link_order): Likewise.
	* elf32-nds32.c (nds32_relocate_contents): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Likewise.

	* reloc.c (_bfd_relocate_contents): Don't bomb on zero size relocs.
	(_bfd_clear_contents): Likewise.
	* elfxx-mips.c (mips_elf_obtain_contents): Likewise.
	(mips_elf_perform_relocation): Likewise.

	* aoutx.h (aout_link_reloc_link_order): Allow for NULL return
	from malloc on zero size alloc.
	* cofflink.c (_bfd_coff_reloc_link_order): Likewise.
	* elflink.c (elf_reloc_link_order): Likewise.
	* linker.c (_bfd_generic_reloc_link_order): Likewise.
	* pdp11.c (aout_link_reloc_link_order): Likewise.
	* xcofflink.c (xcoff_reloc_link_order): Likewise.

	* aoutx.h (howto_table_ext): Ensure NONE relocs have size 3,
	bitsize 0, and complain_overflow_dont.
	* coff-sparc.c (coff_sparc_howto_table): Likewise.
	* elf-hppa.h (elf_hppa_howto_table): Likewise.
	* elf-m10200.c (elf_mn10200_howto_table): Likewise.
	* elf-m10300.c (elf_mn10300_howto_table): Likewise.
	* elf32-arc.c (elf_arc_howto_table): Likewise.
	* elf32-arm.c (elf32_arm_howto_table_1): Likewise.
	* elf32-avr.c (elf_avr_howto_table): Likewise.
	* elf32-bfin.c (bfin_howto_table): Likewise.
	* elf32-cr16.c (cr16_elf_howto_table): Likewise.
	* elf32-cris.c (cris_elf_howto_table): Likewise.
	* elf32-crx.c (crx_elf_howto_table): Likewise.
	* elf32-d10v.c (elf_d10v_howto_table): Likewise.
	* elf32-d30v.c (elf_d30v_howto_table): Likewise.
	* elf32-dlx.c (dlx_elf_howto_table): Likewise.
	* elf32-epiphany.c (epiphany_elf_howto_table): Likewise.
	* elf32-fr30.c (fr30_elf_howto_table): Likewise.
	* elf32-frv.c (elf32_frv_howto_table): Likewise.
	* elf32-h8300.c (h8_elf_howto_table): Likewise.
	* elf32-i370.c (i370_elf_howto_raw): Likewise.
	* elf32-i386.c (elf_howto_table): Likewise.
	* elf32-i860.c (elf32_i860_howto_table): Likewise.
	* elf32-i960.c (elf32_i960_relocate): Likewise.
	* elf32-ip2k.c (ip2k_elf_howto_table): Likewise.
	* elf32-iq2000.c (iq2000_elf_howto_table): Likewise.
	* elf32-lm32.c (lm32_elf_howto_table): Likewise.
	* elf32-m32c.c (m32c_elf_howto_table): Likewise.
	* elf32-m32r.c (m32r_elf_howto_table): Likewise.
	* elf32-m68hc11.c (elf_m68hc11_howto_table): Likewise.
	* elf32-m68hc12.c (elf_m68hc11_howto_table): Likewise.
	* elf32-m68k.c (howto_table): Likewise.
	* elf32-mcore.c (mcore_elf_howto_raw): Likewise.
	* elf32-mep.c (mep_elf_howto_table): Likewise.
	* elf32-metag.c (elf_metag_howto_table): Likewise.
	* elf32-microblaze.c (microblaze_elf_howto_raw): Likewise.
	* elf32-mips.c (elf_mips_howto_table_rel): Likewise.
	* elf32-moxie.c (moxie_elf_howto_table): Likewise.
	* elf32-msp430.c (elf_msp430_howto_table): Likewise.
	* elf32-mt.c (mt_elf_howto_table): Likewise.
	* elf32-nds32.c (nds32_elf_howto_table): Likewise.
	* elf32-nios2.c (elf_nios2_howto_table_rel): Likewise.
	* elf32-or1k.c (or1k_elf_howto_table): Likewise.
	* elf32-pj.c (pj_elf_howto_table): Likewise.
	* elf32-ppc.c (ppc_elf_howto_raw): Likewise.
	* elf32-rl78.c (rl78_elf_howto_table): Likewise.
	* elf32-rx.c (rx_elf_howto_table): Likewise.
	* elf32-s390.c (elf_howto_table): Likewise.
	* elf32-score.c (elf32_score_howto_table): Likewise.
	* elf32-score7.c (elf32_score_howto_table): Likewise.
	* elf32-sh-relocs.h (R_SH_NONE): Likewise.
	* elf32-spu.c (elf_howto_table): Likewise.
	* elf32-tic6x.c (elf32_tic6x_howto_table): Likewise.
	* elf32-tilepro.c (tilepro_elf_howto_table): Likewise.
	* elf32-v850.c (v850_elf_howto_table): Likewise.
	* elf32-vax.c (howto_table): Likewise.
	* elf32-visium.c (visium_elf_howto_table): Likewise.
	* elf32-xc16x.c (xc16x_elf_howto_table): Likewise.
	* elf32-xgate.c (elf_xgate_howto_table): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_howto_table): Likewise.
	* elf32-xtensa.c (elf_howto_table): Likewise.
	* elf64-alpha.c (elf64_alpha_howto_table): Likewise.
	* elf64-mips.c (mips_elf64_howto_table_rel): Likewise.
	* elf64-mmix.c (elf_mmix_howto_table): Likewise.
	* elf64-ppc.c (ppc64_elf_howto_raw): Likewise.
	* elf64-s390.c (elf_howto_table): Likewise.
	* elf64-sh64.c (sh_elf64_howto_table): Likewise.
	* elf64-x86-64.c (x86_64_elf_howto_table): Likewise.
	* elfn32-mips.c (elf_mips_howto_table_rel): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_howto_table): Likewise.
	(elfNN_aarch64_howto_none): Likewise.
	* elfxx-ia64.c (ia64_howto_table): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_howto_table): Likewise.
	* elfxx-tilegx.c (tilegx_elf_howto_table): Likewise.
	* nlm32-sparc.c (nlm32_sparc_howto_table): Likewise.
2015-01-19 19:37:45 +10:30
H.J. Lu 6f25f22356 Skip unknown relocation
PR binutils/17512
	* elf32-i386.c (elf_i386_get_plt_sym_val): Skip unknown relocation.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-01-06 16:46:36 -08:00
H.J. Lu 533d0af0b8 Return NULL on corrupt input
PR binutils/17512
	* elf32-i386.c (elf_i386_get_plt_sym_val): Return NULL on corrupt
	input.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-01-05 17:43:34 -08:00
Nick Clifton 896ca09813 More fixes for invalid memory accesses triggered by fuzzed binaries.
PR binutils/17512
	* nm.c (print_symbol): Add 'is_synthetic' parameter.  Use it to
	help initialize the info.elfinfo field.
	(print_size_symbols): Add 'synth_count' parameter.  Use it to set
	the is_synthetic parameter when calling print_symbol.
	(print_symbols): Likewise.
	(display_rel_file): Pass synth_count to printing function.
	(display_archive): Break loop if the last archive displayed
	matches the current archive.
	* size.c (display_archive): Likewise.

	* archive.c (do_slurp_bsd_armap): Make sure that the parsed sized
	is at least big enough for the header to be read.
	* elf32-i386.c (elf_i386_get_plt_sym_val): Skip unknown relocs.
	* mach-o.c (bfd_mach_o_get_synthetic_symtab): Add range checks.
	(bfd_mach_o_read_command): Prevetn duplicate error messages about
	unrecognized commands.
	* syms.c (_bfd_stab_section_find_nearest_line): Add range checks
	when indexing into the string table.
2015-01-05 23:13:50 +00:00
Alan Modra b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
Alan Modra 6cabe1ea46 Copy relocations against protected symbols
Copy relocs are used in a scheme to avoid dynamic text relocations in
non-PIC executables that refer to variables defined in shared
libraries.  The idea is to have the linker define any such variable in
the executable, with a copy reloc copying the initial value, then have
both the executable and shared library refer to the executable copy.
If the shared library defines the variable as protected then we have
two copies of the variable being used.

	PR 15228
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Add "info" param.
	Error on copy relocs against protected symbols.
	(elf_merge_st_other): Set h->protected_def.
	* elf-bfd.h (struct elf_link_hash_entry): Add "protected_def".
	(_bfd_elf_adjust_dynamic_copy): Update prototype.
	* elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Update
	_bfd_elf_adjust_dynamic_copy call.
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_adjust_dynamic_symbol): Likewise.
	* elf32-cris.c (elf_cris_adjust_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol): Likewise.
	* elf32-i370.c (i370_elf_adjust_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Likewise.
	* elf32-lm32.c (lm32_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m32r.c (m32r_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m68k.c (elf_m68k_adjust_dynamic_symbol): Likewise.
	* elf32-metag.c (elf_metag_adjust_dynamic_symbol): Likewise.
	* elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf32-sh.c (sh_elf_adjust_dynamic_symbol): Likewise.
	* elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol): Likewise.
	* elf32-vax.c (elf_vax_adjust_dynamic_symbol): Likewise.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf64-sh64.c (sh64_elf64_adjust_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol): Likewise.
2014-12-12 23:35:50 +10:30
H.J. Lu 3972882e52 Add _bfd_elf_ifunc_get_synthetic_symtab
In i386 and x86-64 binaries with ifunc, relocations against .got.plt
section may not be in the same order as entries in PLT section.  This
patch adds _bfd_elf_ifunc_get_synthetic_symtab.  It takes a function
pointer which returns an array of PLT entry symbol values.  It calls
the function pointer to get the PLT entry symbol value array indexed
by relocation index, instead of calling plt_sym_val on each relocation
index.

	PR binutils/17677
	* elf-bfd.h (_bfd_elf_ifunc_get_synthetic_symtab): New prototype.
	* elf-ifunc.c (_bfd_elf_ifunc_get_synthetic_symtab): New
	function.
	* elf32-i386.c (elf_i386_plt_sym_val): Removed.
	(elf_backend_plt_sym_val): Likewise.
	(elf_i386_get_plt_sym_val): New.
	(elf_i386_get_synthetic_symtab): Likewise.
	(bfd_elf32_get_synthetic_symtab): Likewise.
	* elf64-x86-64.c (elf_x86_64_plt_sym_val): Removed.
	(elf_x86_64_plt_sym_val_offset_plt_bnd): Likewise.
	(elf_backend_plt_sym_val): Likewise.
	(elf_x86_64_get_plt_sym_val): New.
	(elf_x86_64_get_synthetic_symtab): Use
	_bfd_elf_ifunc_get_synthetic_symtab.
	(bfd_elf64_get_synthetic_symtab): Don't undefine for NaCl.
2014-12-04 16:55:39 -08:00
Nick Clifton 06614111d1 More fixes for memory access violations exposed by fuzzed binaries.
PR binutils/17512
	* dwarf.h (struct dwarf_section): Add user_data field.
	* dwarf.c (frame_need_space): Check for an over large register
	number.
	(display_debug_frames): Check the return value from
	frame_need_space.  Check for a CFA expression that is so long the
	start address wraps around.
	(debug_displays): Initialise the user_data field.
	* objdump.c (load_specific_debug_section): Save the BFD section
	pointer in the user_data field of the dwarf_section structure.
	(free_debug_section): Update BFD section data when freeing section
	contents.
	* readelf.c (load_specific_debug_section): Initialise the
	user_data field.

	* archive.c (do_slurp_coff_armap): Add range checks to prevent
	running off the end of the string table.
	* compress.c (bfd_get_full_section_contents): Return a NULL
	pointer for zero sized sections.  Do not attempt to copy a buffer
	onto itself.
	* elf-attrs.c (_bfd_elf_parse_attributes): Check for an empty
	header.  Add range checks to avoid running off the end of the
	section.
	* elf.c (bfd_elf_get_str_section): Seek before allocating so that
	if the seek fails, no memory is allocated.
	(bfd_elf_string_from_elf_section): Do not allocate a string from a
	non string section.  It only leads to trouble later on.
	(_bfd_elf_print_private_bfd_data): Check for there being too
	little external dynamic data.
	(bfd_section_from_shdr): Replace assertion with a failure mode.
	(bfd_section_from_shdr): When walking a loaded group section use
	the internal structure size, not the external size.  Check for the
	group section being empty.
	* elf32-i386.c (elf_i386_rtype_to_howto): Replace assertion with a
	failure mode.
	* elfcode.h (elf_slurp_reloc_table): Likewise.
	* reloc.c (bfd_perform_relocation): Avoid seg-fault if the howto
	parameter is NULL.
2014-12-01 16:43:46 +00:00
H.J. Lu dd7e64d45b Optimize out i386/x86-64 JUMP_SLOT relocation
When there are both PLT and GOT references to the same function symbol,
linker will create a GOTPLT slot for PLT entry and a GOT slot for GOT
reference.  A run-time JUMP_SLOT relocation is created to update the
GOTPLT slot and a run-time GLOB_DAT relocation is created to update the
GOT slot.  Both JUMP_SLOT and GLOB_DAT relocations will apply the same
symbol value to GOTPLT and GOT slots, respectively, at run-time.

This optimization combines GOTPLT and GOT slots into a single GOT slot
and removes the run-time JUMP_SLOT relocation.  It replaces the regular
PLT entry:

	indirect jump	[GOTPLT slot]
	push		relocation index
	jump		PLT0

with an GOT PLT entry with an indirect jump via the GOT slot:

	indirect jump	[GOT slot]
	nop

and resolves PLT reference to the GOT PLT entry.

We must avoid this optimization if pointer equality is needed since
we don't clear symbol value in this case and the dynamic linker won't
update the GOT slot.  Otherwise, the resulting binary will get into an
infinite loop at run-time.

bfd/

	* elf32-i386.c (elf_i386_got_plt_entry): New.
	(elf_i386_pic_got_plt_entry): Likewise.
	(elf_i386_link_hash_entry): Add plt_got.
	(elf_i386_link_hash_table): Likewise.
	(elf_i386_link_hash_newfunc): Initialize plt_got.offset to -1.
	(elf_i386_get_local_sym_hash): Likewise.
	(elf_i386_check_relocs): Create the GOT PLT if there are both
	PLT and GOT references when the regular PLT is used.
	(elf_i386_allocate_dynrelocs): Use the GOT PLT if there are
	both PLT and GOT references unless pointer equality is needed.
	(elf_i386_relocate_section): Also check the GOT PLT when
	resolving R_386_PLT32.
	(elf_i386_finish_dynamic_symbol): Use the GOT PLT if it is
	available.

	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add plt_got.
	(elf_x86_64_link_hash_table): Likewise.
	(elf_x86_64_link_hash_newfunc): Initialize plt_got.offset to -1.
	(elf_x86_64_get_local_sym_hash): Likewise.
	(elf_x86_64_check_relocs): Create the GOT PLT if there are both
	PLT and GOT references when the regular PLT is used.
	(elf_x86_64_allocate_dynrelocs): Use the GOT PLT if there are
	both PLT and GOT references unless pointer equality is needed.
	(elf_x86_64_relocate_section): Also check the GOT PLT when
	resolving R_X86_64_PLT32.
	(elf_x86_64_finish_dynamic_symbol): Use the GOT PLT if it is
	available.

ld/

	* emulparams/elf_i386.sh (TINY_READONLY_SECTION): New.
	* emulparams/elf_x86_64.sh (TINY_READONLY_SECTION): Add .plt.got.

ld/testsuite/

	* ld-i386/i386.exp: Add run-time relocation tests for plt-main.
	* ld-i386/plt-main.rd: New file.
	* ld-x86-64/plt-main-bnd.dd: Likewise.
	* ld-x86-64/plt-main.rd: Likewise.
	* ld-x86-64/x86-64.exp: Add run-time relocation tests for
	plt-main.
2014-11-25 05:05:39 -08:00
Alan Modra f1885d1e59 Fix 17492, ld segfault with --oformat=binary
PR 17492
	* elf32-arm.c (elf32_arm_add_symbol_hook): Only set has_gnu_symbols
	on ELF output bfd.
	* elf32-i386.c (elf_i386_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elf-s390-common.c (elf_s390_add_symbol_hook): Likewise.  Handle
	STB_GNU_UNIQUE too.
2014-10-16 21:18:16 +10:30
H.J. Lu 5697705ac6 Convert mov to lea only if r_offset >= 2
* elf32-i386.c (elf_i386_convert_mov_to_lea): Skip if relocation
	offset is less than 2.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
2014-10-14 08:03:32 -07:00
H.J. Lu cf7363b42b Fix build for OLD_FREEBSD_ABI_LABEL
PR ld/17440
	* elf32-i386.c (elf_i386_fbsd_post_process_headers): Fix build
	for OLD_FREEBSD_ABI_LABEL.
2014-09-29 08:35:49 -07:00
H.J. Lu c8831961f9 Use bfd_is_abs_section to check discarded input section
bfd/

	PR ld/17306
	* elf32-i386.c (elf_i386_convert_mov_to_lea): Use bfd_is_abs_section
	to check discarded input section.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.

ld/testsuite/

	PR ld/17306
	* ld-i386/i386.exp (i386tests): Add tests for PR ld/17306.
	* ld-x86-64/x86-64.exp (x86_64tests): Likewise.

	* ld-i386/pr17306a.s: New file.
	* ld-i386/pr17306b.s: Likewise.
	* ld-x86-64/pr17306a.s: Likewise.
	* ld-x86-64/pr17306b.s: Likewise.
2014-08-27 07:59:48 -07:00
H.J. Lu cca5b8b64b Match PLT entry only for ELFOSABI_GNU input
* elf32-i386.c (elf_i386_plt_sym_val): Match PLT entry only for
	ELFOSABI_GNU input.
	* elf64-x86-64.c (elf_x86_64_plt_sym_val): Likewise.
	(elf_x86_64_plt_sym_val_offset_plt_bnd): Likewise.
2014-07-16 11:15:56 -07:00
H.J. Lu 144bed8d4d Properly match PLT entry against .got.plt relocation
Relocations against .got.plt section may not be in the same order as
entries in PLT section.  It is incorrect to assume that the Ith reloction
index against .got.plt section always maps to the (I + 1)th entry in PLT
section.  This patch matches the .got.plt relocation offset/index in PLT
entry against the index in .got.plt relocation table.  It only checks
R_*_JUMP_SLOT and R_*_IRELATIVE relocations.  It ignores R_*_TLS_DESC
and R_*_TLSDESC relocations since they have different PLT entries.

bfd/

	PR binutils/17154
	* elf32-i386.c (elf_i386_plt_sym_val): Only match R_*_JUMP_SLOT
	and R_*_IRELATIVE relocation offset with PLT entry.
	* elf64-x86-64.c (elf_x86_64_plt_sym_val): Likewise.
	(elf_x86_64_plt_sym_val_offset_plt_bnd): New.
	(elf_x86_64_get_synthetic_symtab): Use it.

ld/testsuite/

	PR binutils/17154
	* ld-ifunc/pr17154-i386.d: New file.
	* ld-ifunc/pr17154-x86-64.d: Likewise.
	* ld-ifunc/pr17154-x86.s: Likewise.
	* ld-x86-64/bnd-ifunc-2.d: Likewise.
	* ld-x86-64/bnd-ifunc-2.s: Likewise.
	* ld-x86-64/mpx.exp: Run bnd-ifunc-2.
	* ld-x86-64/tlsdesc-nacl.pd: Updated.
	* ld-x86-64/tlsdesc.pd: Likewise.
2014-07-16 10:57:49 -07:00
H.J. Lu 998d811a23 Update elf_i386_compute_jump_table_size
Commit e1f987424b changed how
next_tls_desc_index was set up.  This patch updates
elf_i386_compute_jump_table_size to use elf.srelplt->reloc_count
instead of next_tls_desc_index.

bfd/

	PR ld/17057
	* elf32-i386.c (elf_i386_compute_jump_table_size): Replace
	next_tls_desc_index with elf.srelplt->reloc_count.

ld/testsuite/

	PR ld/17057
	* ld-i386/i386.exp: Run pr17057.
	* ld-i386/pr17057.d: New file.
	* ld-i386/pr17057.s: Likewise.
2014-07-15 13:09:55 -07:00
Alan Modra d495ab0d84 Free linker hash table from bfd_close.
Also tidies numerous error exit paths in various link_hash_table_create
functions that failed to free memory.

include/
	* bfdlink.h (struct bfd_link_hash_table): Add hash_table_free field.
bfd/
	* archive.c: Include bfdlink.h.
	(_bfd_archive_close_and_cleanup): Call linker hash_table_free.
	* bfd.c (struct bfd): Add is_linker_output field.
	* elf-bfd.h (_bfd_elf_link_hash_table_free): Update prototype.
	* linker.c (_bfd_link_hash_table_init): Set up hash_table_free,
	link.hash and is_linker_output.
	(_bfd_generic_link_hash_table_free): Replace bfd_link_hash_table*
	param with bfd*.  Assert is_linker_output and link.hash, and
	clear them before exit.
	* elf-m10300.c (elf32_mn10300_link_hash_table_free): Replace
	bfd_link_hash_table* param with bfd*.  Hack is_linker_output
	and link.hash so we can free two linker hash tables.
	(elf32_mn10300_link_hash_table_create): Create static_hash_table
	first.  Clean up on errors.  Set hash_table_free pointer.
	* elf32-arm.c (elf32_arm_link_hash_table_free): Replace
	bfd_link_hash_table* param with bfd*.
	(elf32_arm_link_hash_table_create): Clean up on errors.  Set
	hash_table_free pointer.
	* elf32-avr.c, * elf32-hppa.c, * elf32-i386.c, * elf32-m68hc1x.c,
	* elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c, * elf32-xgate.c,
	* elf64-ia64-vms.c, * elf64-ppc.c, * elf64-x86-64.c, * elflink.c,
	* elfnn-aarch64.c, * elfnn-ia64.c, * elfxx-sparc.c,
	* xcofflink.c: Similarly.
	* simple.c (bfd_simple_get_relocated_section_contents): Save and
	clear link.next before creating linker hash table.  Clean up on
	errors, and restore link.next on exit.
	* elf32-m68hc1x.h (m68hc11_elf_bfd_link_hash_table_free): Delete.
	* elf32-xgate.h (xgate_elf_bfd_link_hash_table_free): Delete.
	* elfxx-sparc.h (_bfd_sparc_elf_link_hash_table_free): Delete.
	* libcoff-in.h (_bfd_xcoff_bfd_link_hash_table_free): Delete.
	* hash.c (bfd_hash_table_init_n): Free table on error.
	* libbfd-in.h (_bfd_generic_link_hash_table_free): Update proto.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* libcoff.h: Regenerate.
2014-06-13 19:11:39 +09:30
Alan Modra caa4096e84 Don't call bfd_link_hash_table_free
Freeing the linker hash table is a royal pain.  It can't be freed
before the _bfd_write_contents call in bfd_close, because some target
bfd_write_contents functions access the hash table.  It can't be freed
after bfd_close either, since bfd_alloc memory holding side data
structures disappears (PR17047).  Clearly the only place it can be freed
is actually in bfd_close.  This patch doesn't do that, but kills off
the existing means of freeing the hash table via a bfd target xvec call.

bfd/
	PR 17047
	* targets.c (BFD_JUMP_TABLE): Delete NAME##_bfd_link_hash_table_free.
	(struct bfd_target <_bfd_link_hash_table_free>): Delete.
	* bfd.c (bfd_link_hash_table_free): Don't define.
	* aout-adobe.c, * aout-target.h, * aout-tic30.c, * binary.c, * bout.c,
	* coff64-rs6000.c, * coffcode.h, * elf-m10300.c, * elf32-arm.c,
	* elf32-avr.c, * elf32-hppa.c, * elf32-i386.c, * elf32-m68hc11.c,
	* elf32-m68hc12.c, * elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c,
	* elf32-sparc.c, * elf32-xgate.c, * elf64-ia64-vms.c, * elf64-ppc.c,
	* elf64-sparc.c, * elf64-x86-64.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* elfxx-target.h, * i386msdos.c, * i386os9k.c, * ieee.c, * ihex.c,
	* libbfd-in.h, * libecoff.h, * mach-o-target.c, * mmo.c,
	* nlm-target.h, * oasys.c, * pef.c, * plugin.c, * ppcboot.c, * som.c,
	* srec.c, * tekhex.c, * verilog.c, * versados.c, * vms-alpha.c,
	* xsym.c: Don't define various link_hash_table_free defines, and
	remove from bfd_target vars.  Temporarily reference some of the
	target link_hash_table_free functions to avoid warnings.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	PR 17047
	* ldlang.c (output_bfd_hash_table_free_fn): Delete.
	(open_output): Don't set it..
	* ldmain.c (ld_cleanup): ..or call it.
2014-06-13 19:11:29 +09:30
Alan Modra 68faa6378d Move link_hash_table_free functions earlier
Move some code around, in preparation for a followup patch.

	* elf-m10300.c, * elf32-arm.c, * elf32-avr.c, * elf32-hppa.c,
	* elf32-i386.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-metag.c,
	* elf32-nios2.c, * elf64-ia64-vms.c, * elf64-ppc.c, * elf64-x86-64.c,
	* elfnn-aarch64.c, * elfnn-ia64.c, * elfxx-sparc.c, * xcofflink.c:
	Move link_hash_table_free functions before their corresponding
	link_hash_table_create functions.
2014-06-13 19:11:19 +09:30
Alan Modra c72f2fb2bb Make bfd.link_next field a union
This field of struct bfd is currently only used to chain together
linker input files.  This patch prepares to use the field to stash
the linker hash table, which is always created on the linker output
file.

bfd/
	* bfd.c (struct bfd): Replace link_next with a union.
	* aoutx.h, * bfd.c, * coff-ppc.c, * coff-rs6000.c, * cofflink.c,
	* ecoff.c, * elf-m10300.c, * elf32-arm.c, * elf32-avr.c,
	* elf32-hppa.c, * elf32-i386.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-metag.c,
	* elf32-microblaze.c, * elf32-nds32.c, * elf32-nios2.c,
	* elf32-or1k.c, * elf32-ppc.c, * elf32-rl78.c, * elf32-s390.c,
	* elf32-score.c, * elf32-score7.c, * elf32-sh.c, * elf32-spu.c,
	* elf32-tic6x.c, * elf32-tilepro.c, * elf32-xstormy16.c,
	* elf32-xtensa.c, * elf64-alpha.c, * elf64-hppa.c, * elf64-ia64-vms.c,
	* elf64-mmix.c, * elf64-ppc.c, * elf64-s390.c, * elf64-x86-64.c,
	* elflink.c, * elfnn-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * linker.c, * pdp11.c, * peXXigen.c, * simple.c,
	* sunos.c, * vms-alpha.c, * xcofflink.c: Update for above.
	* bfd-in2.h: Regenerate.
include/
	* bfdlink.h: Update for bfd.link_next change.
ld/
	* emultempl/cr16elf.em, * emultempl/elf32.em, * emultempl/genelf.em,
	* emultempl/m68kcoff.em, * emultempl/m68kelf.em,
	* emultempl/nds32elf.em, * emultempl/pe.em, * emultempl/pep.em,
	* ldlang.c, * ldmain.c, * pe-dll.c: Update for bfd.link_next change.
2014-06-13 19:10:57 +09:30
Alan Modra 6d00b59031 bfd target vector rationalisation
This renames the bfd targets to <cpu>_<format>_<other>_<endian>_vec.
So for example, bfd_elf32_ntradlittlemips_vec becomes
mips_elf32_ntrad_le_vec and hp300bsd_vec becomes m68k_aout_hp300bsd_vec.

bfd/
	* aix386-core.c, * aout-adobe.c, * aout-arm.c, * aout-ns32k.c,
	* aout-sparcle.c, * aout0.c, * aoutx.h, * armnetbsd.c, * bout.c,
	* cf-i386lynx.c, * cf-sparclynx.c, * cisco-core.c, * coff-alpha.c,
	* coff-apollo.c, * coff-arm.c, * coff-aux.c, * coff-go32.c,
	* coff-h8300.c, * coff-h8500.c, * coff-i386.c, * coff-i860.c,
	* coff-i960.c, * coff-m68k.c, * coff-m88k.c, * coff-mips.c,
	* coff-rs6000.c, * coff-sh.c, * coff-sparc.c, * coff-stgo32.c,
	* coff-svm68k.c, * coff-tic80.c, * coff-u68k.c, * coff-w65.c,
	* coff-we32k.c, * coff-x86_64.c, * coff-z80.c, * coff-z8k.c,
	* coff64-rs6000.c, * config.bfd, * configure.com, * configure.in,
	* demo64.c, * elf-m10200.c, * elf-m10300.c, * elf32-am33lin.c,
	* elf32-arc.c, * elf32-arm.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-gen.c, * elf32-h8300.c,
	* elf32-hppa.c, * elf32-i370.c, * elf32-i386.c, * elf32-i860.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-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-nios2.c,
	* elf32-or1k.c, * elf32-pj.c, * elf32-ppc.c, * elf32-rl78.c,
	* elf32-rx.c, * elf32-s390.c, * elf32-score.c, * elf32-sh-symbian.c,
	* elf32-sh.c, * elf32-sh64.c, * elf32-sparc.c, * elf32-spu.c,
	* elf32-tic6x.c, * elf32-tilegx.c, * elf32-tilepro.c, * elf32-v850.c,
	* elf32-vax.c, * elf32-xc16x.c, * elf32-xgate.c, * elf32-xstormy16.c,
	* elf32-xtensa.c, * elf64-alpha.c, * elf64-gen.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-x86-64.c, * elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* epoc-pe-arm.c, * epoc-pei-arm.c, * hp300bsd.c, * hp300hpux.c,
	* hppabsd-core.c, * hpux-core.c, * i386aout.c, * i386bsd.c,
	* i386dynix.c, * i386freebsd.c, * i386linux.c, * i386lynx.c,
	* i386mach3.c, * i386msdos.c, * i386netbsd.c, * i386os9k.c,
	* irix-core.c, * m68k4knetbsd.c, * m68klinux.c, * m68knetbsd.c,
	* m88kmach3.c, * m88kopenbsd.c, * mach-o-i386.c, * mach-o-x86-64.c,
	* makefile.vms, * mipsbsd.c, * mmo.c, * netbsd-core.c, * newsos3.c,
	* nlm32-alpha.c, * nlm32-i386.c, * nlm32-ppc.c, * nlm32-sparc.c,
	* ns32knetbsd.c, * osf-core.c, * pc532-mach.c, * pe-arm-wince.c,
	* pe-arm.c, * pe-i386.c, * pe-mcore.c, * pe-mips.c, * pe-ppc.c,
	* pe-sh.c, * pe-x86_64.c, * pei-arm-wince.c, * pei-arm.c,
	* pei-i386.c, * pei-ia64.c, * pei-mcore.c, * pei-mips.c, * pei-ppc.c,
	* pei-sh.c, * pei-x86_64.c, * ppcboot.c, * ptrace-core.c, * riscix.c,
	* sco5-core.c, * som.c, * sparclinux.c, * sparclynx.c,
	* sparcnetbsd.c, * sunos.c, * targets.c, * trad-core.c,
	* vax1knetbsd.c, * vaxbsd.c, * vaxnetbsd.c, * versados.c,
	* vms-alpha.c, * vms-lib.c: Rename bfd targets to
	<cpu>_<format>_<other>_<endian>_vec.  Adjust associated MY macros
	on aout targets.
	* configure: Regenerate.
binutils/
	* emul_aix.c: Update bfd target vector naming.
	* testsuite/binutils-all/objcopy.exp: Likewise.
ld/
	* emultempl/metagelf.em: Update bfd target vector naming.
	* emultempl/nios2elf.em: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/tic6xdsbt.em: Likewise.
2014-05-02 20:09:40 +09:30
Alan Modra 4b95cf5c0c Update copyright years 2014-03-05 22:16:15 +10:30
H.J. Lu c353e543fe Revert the last change
It has been fixed by

commit 4199e3b866
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jan 15 21:50:55 2014 +1030

    non-PIC references to __ehdr_start in pie and shared

    Rather than hacking every backend to not discard dynamic relocations
    against an undefined hidden __ehdr_start, make it appear to be defined
    early.  We want __ehdr_start hidden before size_dynamic_sections so
    that it isn't put in .dynsym, but we do need the dynamic relocations
    for a PIE or shared library with a non-PIC reference.  Defining it
    early is wrong if we don't actually define the symbol later to its
    proper value.  (In some cases we want to leave the symbol undefined,
    for example, when the ELF header isn't loaded, and we don't have this
    infomation available in before_allocation.)

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Revert the last
	change.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-15 03:59:42 -08:00
H.J. Lu 818d220a6f Don't discard relocs against __ehdr_start
__ehdr_start will be defined by assign_file_positions_for_non_load_sections
later.

	PR ld/16428
	* elf32-i386.c (elf_i386_allocate_dynrelocs): Don't discard relocs
	against __ehdr_start.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-14 16:42:35 -08:00
H.J. Lu c3ce498cbd Revert the last change
* elf32-i386.c (elf_i386_allocate_dynrelocs): Revert the last
	change.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-14 16:40:51 -08:00
H.J. Lu d1ec1e40b5 Don't update reloc count if there are any non pc-relative relocs
PR ld/16428
	* elf32-i386.c (elf_i386_allocate_dynrelocs): Don't update reloc
	count if there are any non pc-relative relocs.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-14 10:48:39 -08:00
H.J. Lu 782450358d Default elf_backend_post_process_headers to set OSABI
* elf-bfd.h (_bfd_elf_set_osabi): Renamed to ...
	(_bfd_elf_post_process_headers): This.
	* elf.c (_bfd_elf_compute_section_file_positions): Always
	call elf_backend_post_process_headers.
	(_bfd_elf_set_osabi): Renamed to ...
	(_bfd_elf_post_process_headers): This.
	* elf32-hppa.c (elf_backend_post_process_headers): Removed.
	* elf32-i370.c (elf_backend_post_process_headers): Likewise.
	* elf32-msp430.c (elf_backend_post_process_headers): Likewise.
	* elf32-ppc.c (elf_backend_post_process_headers): Likewise.
	* elf32-sparc.c (elf_backend_post_process_headers): Likewise.
	* elf64-hppa.c (elf_backend_post_process_headers): Likewise.
	* elf64-ppc.c (elf_backend_post_process_headers): Likewise.
	* elf64-sparc.c (elf_backend_post_process_headers): Likewise.
	* elf64-x86-64.c (elf_backend_post_process_headers): Likewise.
	*  (elf_backend_post_process_headers): Likewise.
	*  (elf_backend_post_process_headers): Likewise.
	* elf32-i386.c (elf_backend_post_process_headers): Don't
	define as _bfd_elf_set_osabi.
	(elf_i386_fbsd_post_process_headers): Updated.
	* elf32-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elf32-tic6x.c (elf32_tic6x_set_osabi): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elf64-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elfn32-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_post_process_headers): Updated.
	* elfxx-target.h (elf_backend_post_process_headers): Default
	to _bfd_elf_post_process_headers.
2013-12-17 13:41:17 -08:00
H.J. Lu bb81b736af Make room for PLT0 directly
* elf32-i386.c (elf_i386_allocate_dynrelocs): Make room for
	PLT0 directly.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2013-11-15 09:32:24 -08:00
Roland McGrath 64b384e1e8 Set CPU type in BFD backend for x86_64-nacl* and i?86-nacl* targets
bfd/
	* archures.c (bfd_mach_i386_nacl): Fix definition so it doesn't
	collide with bfd_mach_l1om.
	* bfd-in2.h: Regenerate.

	* elf32-i386.c (elf32_i386_nacl_elf_object_p): New function.
	(elf_backend_object_p): Use that in elf32-i386-nacl definition.
	* elf64-x86-64.c (elf64_x86_64_nacl_elf_object_p): New function.
	(elf_backend_object_p): Use that in elf64-x86-64-nacl definition.
	(elf32_x86_64_nacl_elf_object_p): New function.
	(elf_backend_object_p): Use that in elf32-x86-64-nacl definition.

binutils/
	* objdump.c (dump_dwarf): Grok bfd_mach_x86_64_nacl and
	bfd_mach_x64_32_nacl as equivalent to bfd_mach_x86_64.

ld/testsuite/
	* ld-x86-64/x86-64.exp (mixed1, mixed2): Loosen error string match
	so it accepts "i386:nacl" in place of "i386".
	* ld-x86-64/ilp32-2.d: Likewise.
	* ld-x86-64/ilp32-3.d: Likewise.
	* ld-x86-64/lp64-2.d: Likewise.
	* ld-x86-64/lp64-3.d: Likewise.
2013-11-07 10:00:32 -08:00
H.J. Lu 62d887d406 Pass ignored unresolved relocations to ld backend
bfd/

	PR ld/4409
	* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): Add an argument for
	error ignored.
	* elf-m10200.c (mn10200_elf_relocate_section): Updated.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf32-arm.c (elf32_arm_relocate_section): Likewise.
	* elf32-avr.c (elf32_avr_relocate_section): Likewise.
	* elf32-bfin.c (bfinfdpic_relocate_section): Likewise.
	(bfin_relocate_section): Likewise.
	* elf32-cr16.c (elf32_cr16_relocate_section): Likewise.
	* elf32-cr16c.c (elf32_cr16c_relocate_section): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-crx.c (elf32_crx_relocate_section): Likewise.
	* elf32-d10v.c (elf32_d10v_relocate_section): Likewise.
	* elf32-epiphany.c (epiphany_elf_relocate_section): Likewise.
	* elf32-fr30.c (fr30_elf_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-h8300.c (elf32_h8_relocate_section): Likewise.
	* elf32-hppa.c (elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-i860.c (elf32_i860_relocate_section): Likewise.
	* elf32-ip2k.c (ip2k_elf_relocate_section): Likewise.
	* elf32-iq2000.c (iq2000_elf_relocate_section): Likewise.
	* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-metag.c (elf_metag_relocate_section): Likewise.
	* elf32-microblaze.c (microblaze_elf_relocate_section): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-mep.c (mep_elf_relocate_section): Likewise.
	* elf32-moxie.c (moxie_elf_relocate_section): Likewise.
	* elf32-msp430.c (elf32_msp430_relocate_section): Likewise.
	* elf32-mt.c (mt_elf_relocate_section): Likewise.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-openrisc.c (openrisc_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-rl78.c (rl78_elf_relocate_section): Likewise.
	* elf32-rx.c (rx_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-v850.c (v850_elf_relocate_section): Likewise.
	* elf32-vax.c (elf_vax_relocate_section): Likewise.
	* elf32-xc16x.c (elf32_xc16x_relocate_section): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-alpha.c (elf64_alpha_relocate_section): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise.
	* elf64-mmix.c (mmix_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Likewise.

	* elfnn-ia64.c (elfNN_ia64_relocate_section): Skip if error
	from RELOC_FOR_GLOBAL_SYMBOL in executable is ignored.

ld/testsuite/

	PR ld/4409
	* ld-ia64/error1.d: New file.
	* ld-ia64/error1.s: Likewise.
	* ld-ia64/error2.d: Likewise.
	* ld-ia64/error3.d: Likewise.
2013-11-05 10:29:44 -08:00
Roland McGrath 887badb310 bfd/
* elf-nacl.c (nacl_modify_segment_map): Fix logic reordering the
	elf_segment_map list.  If an executable segment is page-aligned
	but does not end with a full page, then append a fake section into
	the segment map entry that pads out the page.
	(nacl_final_write_processing): New function.  Write the code fill
	laid out in nacl_modify_segment_map.
	* elf-nacl.h: Declare it.
	* elf32-arm.c (elf32_arm_nacl_final_write_processing): New function.
	(elf_backend_final_write_processing): Define it for NaCl backend.
	* elf32-i386.c (elf_backend_final_write_processing): Likewise.
	* elf64-x86-64.c (elf_backend_final_write_processing): Likewise.

	* elf-nacl.c (segment_eligible_for_headers): Rename MAXPAGESIZE
	parameter to MINPAGESIZE.
	(nacl_modify_segment_map): Use minpagesize instead of maxpagesize.

	* elf32-arm.c (ELF_MINPAGESIZE, ELF_COMMONPAGESIZE): Set to
	0x10000	for NaCl targets.

ld/testsuite/
	* ld-x86-64/ilp32-4-nacl.d: Loosen .shstrtab line regexp to match
	any file offset.
	* ld-x86-64/tlsbin-nacl.rd: Update expected code segment PT_LOAD.
	* ld-x86-64/tlsbindesc-nacl.rd: Likewise.
	* ld-scripts/rgn-at3.d: XFAIL for *-*-nacl* targets.
	* ld-scripts/rgn-over8-ok.d: Likewise.
2013-08-26 19:27:25 +00:00
Will Newton 7b70956dc8 bfd/elf-ifunc.c: Add header size arg to _bfd_elf_allocate_ifunc_dyn_relocs.
bfd/ChangeLog:

2013-05-07  Will Newton  <will.newton@linaro.org>

	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Add a
	plt_header_size argument for ports where it differs from
	plt_entry_size.
	* elf-bfd.h: Likewise.
	* elf32-i386.c: Pass plt_header_size to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	* elf64-x86-64.c: Likewise.
2013-05-07 17:03:52 +00:00
H.J. Lu 61315175ad Set non_ir_ref if a symbol is referenced by a non-shared object
bfd/

	PR ld/15323
	* elf32-i386.c (elf_i386_check_relocs): Set non_ir_ref if a
	symbol is referenced by a non-shared object.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/testsuite/

	PR ld/15323
	* ld-plugin/lto.exp (lto_link_tests): Add pr15323a-r.o.
	(lto_run_tests): Add a test for PR ld/15323.

	* ld-plugin/pr15323.out: New file.
	* ld-plugin/pr15323a.c: Likewise.
	* ld-plugin/pr15323b.c: Likewise.
2013-03-30 00:38:39 +00:00
Alan Modra 7e612e9848 * elf-bfd.h (enum elf_reloc_type_class): Add reloc_class_ifunc.
(struct elf_backend_data <elf_backed_reloc_type_class>): Add
	bfd_link_info* and asection* params.
	(_bfd_elf_reloc_type_class): Likewise.
	* elf.c (_bfd_elf_reloc_type_class): Likewise.
	* elflink.c (elf_link_sort_cmp2): Sort first on reloc class.
	(elf_link_sort_relocs): Update elf_backed_reloc_type_class call.
	* elf32-ppc.c (ppc_elf_reloc_type_class): Return reloc_class_ifunc
	for any reliplt reloc.  Don't return reloc_class_plt for
	R_PPC_REL24 and R_PPC_ADDR24.
	* elf64-ppc.c (allocate_got): Formatting.
	(ppc64_elf_reloc_type_class): Return reloc_class_ifunc for any
	reliplt reloc.
	* elf-m10300.c, * elf32-arm.c, * elf32-bfin.c, * elf32-cr16.c,
	* elf32-cris.c, * elf32-hppa.c, * elf32-i386.c, * elf32-lm32.c,
	* elf32-m32r.c, * elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c,
	* elf32-s390.c, * elf32-sh.c, * elf32-sparc.c, * elf32-tilepro.c,
	* elf32-vax.c, * elf32-xtensa.c, * elf64-aarch64.c, * elf64-alpha.c,
	* elf64-hppa.c, * elf64-ia64-vms.c, * elf64-s390.c, * elf64-sparc.c,
	* elf64-x86-64.c, * elfnn-ia64.c, * elfxx-tilegx.c, * elfxx-tilegx.h:
	Add extra params to the various reloc_type_class functions.
2013-03-27 13:37:51 +00:00
Alan Modra 228e534f16 * elf-bfd.h (struct core_elf_obj_tdata): New.
(struct elf_obj_tdata): Delete core_signal, core_pid, core_lwpid,
	core_program, and core_command.  Add "core".
	* elf.c (bfd_elf_mkcorefile): Allocate "core" struct.
	Update all refs to tdata core fields.
	* elf32-am33lin.c, * elf32-arm.c, * elf32-cris.c, * elf32-frv.c,
	* elf32-hppa.c, * elf32-i386.c, * elf32-m68k.c, * elf32-mips.c,
	* elf32-nios2.c, * elf32-ppc.c, * elf32-s390.c, * elf32-score.c,
	* elf32-score7.c, * elf32-sh.c, * elf32-sparc.c, * elf32-tilegx.c,
	* elf32-tilepro.c, * elf32-xtensa.c, * elf64-aarch64.c,
	* elf64-hppa.c, * elf64-mips.c, * elf64-ppc.c, * elf64-tilegx.c,
	* elf64-x86-64.c, * elfcore.h, * elfn32-mips.c: Update all refs
	to tdata core fields.
2013-02-21 03:02:30 +00:00
Alan Modra 9f7c3e5e99 * elfcode.h (elf_checksum_contents): Free contents.
* elf-bfd.h (_bfd_elf_link_hash_table_free): Declare.
	* elflink.c (_bfd_elf_link_hash_table_free): New function.
	(elf_final_link_free): New function, extracted from..
	(bfd_elf_final_link): ..here.  Always call
	_bfd_elf_write_section_eh_frame_hdr.
	* elfxx-target.h (bfd_elfNN_bfd_link_hash_table_free): Default to
	_bfd_elf_link_hash_table_free.
	* libbfd-in.h (_bfd_merge_sections_free): Declare.
	* libbfd.h: Regenerate.
	* merge.c (_bfd_merge_sections_free): New function.
	* elf-eh-frame.c (_bfd_elf_write_section_eh_frame_hdr): Free
	hdr_info->array.
	* elf-m10300.c (elf32_mn10300_link_hash_table_free): Call
	_bfd_elf_link_hash_table_free.
	* elf32-arm.c (elf32_arm_link_hash_table_free): Likewise.
	* elf32-avr.c (elf32_avr_link_hash_table_free): Likewise.
	* elf32-hppa.c (elf32_hppa_link_hash_table_free): Likewise.
	* elf32-i386.c (elf_i386_link_hash_table_free): Likewise.
	* elf32-m68hc1x.c (m68hc11_elf_hash_table_free): Likewise.
	* elf32-m68k.c (elf_m68k_link_hash_table_free): Likewise.
	* elf32-metag.c (elf_metag_link_hash_table_free): Likewise.
	* elf32-xgate.c (xgate_elf_bfd_link_hash_table_free): Likewise.
	* elf64-aarch64.c (elf64_aarch64_link_hash_table_free): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_hash_table_free): Likewise.
	* elf64-ppc.c (ppc64_elf_link_hash_table_free): Likewise.
	* elf64-x86-64.c (elf_x86_64_link_hash_table_free): Likewise.
	* elfnn-ia64.c (elfNN_ia64_hash_table_free): Likewise.
	* elf32-cr16.c (elf32_cr16_link_hash_table_free): Delete.
	(bfd_elf32_bfd_link_hash_table_free): Don't define.
	* elf32-tic6x.c (elf32_tic6x_link_hash_table_free): Delete.
	(bfd_elf32_bfd_link_hash_table_free): Dont' define.
2013-02-11 05:30:54 +00:00
Alan Modra 7bf52ea2ca * coff-arm.c (coff_arm_link_hash_table_create): Use bfd_zmalloc.
* coff-h8300.c (h8300_coff_link_hash_table_create): Likewise.
	* m68klinux.c (linux_link_hash_table_create): Likewise.
	* sparclinux.c (linux_link_hash_table_create): Likewise.
	* sunos.c (sunos_link_hash_table_create): Likewise.
	* xcofflink.c (_bfd_xcoff_bfd_link_hash_table_create): Likewise.
	* elf-m10300.c (elf32_mn10300_link_hash_table_create): Likewise.
	* elf32-arm.c (elf32_arm_link_hash_table_create): Likewise.
	* elf32-avr.c (elf32_avr_link_hash_table_create): Likewise.
	* elf32-cr16.c (elf32_cr16_link_hash_table_create): Likewise.
	* elf32-cris.c (elf_cris_link_hash_table_create): Likewise.
	* elf32-hppa.c (elf32_hppa_link_hash_table_create): Likewise.
	* elf32-i386.c (elf_i386_link_hash_table_create): Likewise.
	* elf32-lm32.c (lm32_elf_link_hash_table_create): Likewise.
	* elf32-m32r.c (m32r_elf_link_hash_table_create): Likewise.
	* elf32-m68hc1x.c (m68hc11_elf_hash_table_create): Likewise.
	* elf32-m68k.c (elf_m68k_link_hash_table_create): Likewise.
	* elf32-metag.c (elf_metag_link_hash_table_create): Likewise.
	* elf32-nios2.c (nios2_elf32_link_hash_table_create): Likewise.
	* elf32-s390.c (elf_s390_link_hash_table_create): Likewise.
	* elf32-score.c (elf32_score_link_hash_table_create): Likewise.
	* elf32-spu.c (spu_elf_link_hash_table_create): Likewise.
	* elf32-tic6x.c (elf32_tic6x_link_hash_table_create): Likewise.
	* elf32-vax.c (elf_vax_link_hash_table_create): Likewise.
	* elf32-xgate.c (xgate_elf_bfd_link_hash_table_create): Likewise.
	* elf32-xtensa.c (elf_xtensa_link_hash_table_create): Likewise.
	* elf64-aarch64.c (elf64_aarch64_link_hash_table_create): Likewise.
	* elf64-s390.c (elf_s390_link_hash_table_create): Likewise.
	* elf64-sh64.c (sh64_elf64_link_hash_table_create): Likewise.
	* elf64-x86-64.c (elf_x86_64_link_hash_table_create): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_link_hash_table_create): Likewise.
	* elflink.c (_bfd_elf_link_hash_table_create): Likewise.
	(_bfd_elf_link_hash_table_init): Assume zero fill table on entry.
2013-02-10 04:36:33 +00:00
H.J. Lu 20e52bd2b8 Don't resolve size relocation against non-zero TLS symbol
bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Don't clear pc_count
	for non-zero TLS symbol.
	(elf_i386_relocate_section): Don't resolve size relocation against
	non-zero TLS symbol.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Don't clear
	pc_count for non-zero TLS symbol.
	(elf_x86_64_relocate_section): Don't resolve size relocation
	against non-zero TLS symbol.

ld/testsuite/

	* ld-size/size-10.rd: Updated.
	* ld-size/size-8.rd: Likewise.
	* ld-size/size32-2-i386.d: Likewise.
	* ld-size/size32-2-x32.d: Likewise.
	* ld-size/size32-2-x86-64.d: Likewise.
	* ld-size/size64-2-x32.d: Likewise.
	* ld-size/size64-2-x86-64.d: Likewise.

	* ld-size/size.exp (run_time_tests): Pass --hash-styl=gnu to
	linker for size-8 test.
2013-02-07 02:15:30 +00:00
H.J. Lu 3bea1fcb8b Resolve size relocation against non-zero TLS symbol
bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Clear pc_count for
	non-zero TLS symbol.
	(elf_i386_relocate_section): Resolve size relocation against
	non-zero TLS symbol.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Clear pc_count
	for non-zero TLS symbol.
	(elf_x86_64_relocate_section): Resolve size relocation against
	non-zero TLS symbol.

ld/testsuite/

	* ld-size/size-10.rd: Updated.
	* ld-size/size-8.rd: Likewise.
	* ld-size/size32-2-i386.d: Likewise.
	* ld-size/size32-2-x32.d: Likewise.
	* ld-size/size32-2-x86-64.d: Likewise.
	* ld-size/size64-2-x32.d: Likewise.
	* ld-size/size64-2-x86-64.d: Likewise.
2013-01-18 22:50:30 +00:00
H.J. Lu 06a6a421f2 Count size relocation as PC-relative relocation
bfd/

	* elf32-i386.c (elf_i386_check_relocs): Count size relocation as
	PC-relative relocation.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Count size relocation
	as PC-relative relocation.

ld/testsuite/

	* ld-size/size32-3-i386.d: New file.
	* ld-size/size32-3-x32.d: Likewise.
	* ld-size/size32-3-x86-64.d: Likewise.
	* ld-size/size32-3.s: Likewise.
2013-01-17 23:36:10 +00:00
H.J. Lu 6a3e1baeae Update x86 size relocation check
* elf32-i386.c (elf_i386_check_relocs): Update R_386_SIZE32
	check.
	(elf_i386_relocate_section): Don't check TLS for R_386_SIZE32.

	* elf64-x86-64.c (elf_x86_64_check_relocs): Update R_X86_64_SIZE32
	and R_X86_64_SIZE64 check.
	(elf_x86_64_relocate_section): Don't check TLS for R_X86_64_SIZE32
	nor R_X86_64_SIZE64.
2013-01-16 22:41:03 +00:00
H.J. Lu 1788fc08f7 Add x86 size relocation support to bfd
* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

	* elf32-i386.c (elf_howto_table): Fill R_386_SIZE32 entry.
	(elf_i386_reloc_type_lookup): Support BFD_RELOC_SIZE32.
	(elf_i386_check_relocs): Handle R_386_SIZE32.
	(elf_i386_gc_sweep_hook): Likewise.
	(elf_i386_relocate_section): Likewise.

	* elf64-x86-64.c (x86_64_elf_howto_table): Fill R_X86_64_SIZE32
	and R_X86_64_SIZE64 entries.
	(x86_64_reloc_map): Add BFD_RELOC_SIZE32 and BFD_RELOC_SIZE64,
	(elf_x86_64_rtype_to_howto): Handle R_X86_64_SIZE32 for x32.
	(elf_x86_64_reloc_name_lookup): Likewise.
	(elf_x86_64_check_relocs): Handle R_X86_64_SIZE32 and
	R_X86_64_SIZE64.
	(elf_x86_64_gc_sweep_hook): Likewise.
	(elf_x86_64_relocate_section): Likewise.

	* reloc.c (bfd_reloc_code_type): Add BFD_RELOC_SIZE32 and
	BFD_RELOC_SIZE64.
2013-01-16 21:34:46 +00:00
H.J. Lu 68c4a57ee6 Set bfd errror for normal and TLS symbol access
* elf32-i386.c (elf_i386_check_relocs): Set bfd errror for
	normal and TLS symbol access.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2013-01-13 00:30:20 +00:00
H.J. Lu a5479e5ff4 Properly adjust h->plt.refcount
bfd/

	PR ld/14980
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Properly
	adjust h->plt.refcount.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.

ld/testsuite/

	PR ld/14980
	* ld-ifunc/ifunc-14c.s: New file.
	* ld-ifunc/ifunc-14e-i386.d: Likewise.
	* ld-ifunc/ifunc-14e-x86-64.d: Likewise.
	* ld-ifunc/ifunc-14f-i386.d: Likewise.
	* ld-ifunc/ifunc-14f-x86-64.d: Likewise.
2012-12-21 18:15:22 +00:00
H.J. Lu c3b0209786 Fix indentation in the last checkin 2012-12-19 19:50:40 +00:00
H.J. Lu 59d6ffb2c9 Fix and use elf_append_rel
* elf32-i386.c (elf_i386_relocate_section): Replace
	bfd_elf32_swap_reloc_out with elf_append_rel.
	(elf_i386_finish_dynamic_symbol): Likewise.

	* elflink.c (elf_append_rel): Call swap_reloc_out instead of
	swap_reloca_out.
2012-12-19 19:45:43 +00:00
H.J. Lu 13ca314985 Reindent elf_i386_finish_dynamic_symbol
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Reindent.
2012-12-19 19:41:18 +00:00
H.J. Lu ad1e85de41 Don't check IFUNC relocations in elf_*_check_relocs
* elf32-i386.c (elf_i386_check_relocs): Don't check IFUNC
	relocations here.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2012-12-16 23:01:13 +00:00
H.J. Lu 73bcf23385 Also check local IFUNC references
bfd/

	PR ld/14968
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Also check
	local IFUNC references.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.

ld/testsuite/

	PR ld/14968
	* ld-ifunc/ifunc-18a-i386.d: New file.
	* ld-ifunc/ifunc-18a-x86-64.d: Likewise.
	* ld-ifunc/ifunc-18a.s: Likewise.
	* ld-ifunc/ifunc-18b-i386.d: Likewise.
	* ld-ifunc/ifunc-18b-x86-64.d: Likewise.
	* ld-ifunc/ifunc-18b.s: Likewise.
	* ld-ifunc/ifunc-19a-i386.d: Likewise.
	* ld-ifunc/ifunc-19a-x86-64.d: Likewise.
	* ld-ifunc/ifunc-19a.s: Likewise.
	* ld-ifunc/ifunc-19b-i386.d: Likewise.
	* ld-ifunc/ifunc-19b-x86-64.d: Likewise.
	* ld-ifunc/ifunc-19b.s: Likewise.
2012-12-16 20:31:08 +00:00
H.J. Lu 5ca5bb3545 Check local IFUNC calls
bfd/

2012-12-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/14956
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Check local
	IFUNC calls.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.

ld/testsuite/

2012-12-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/14956
	* ld-ifunc/ifunc-14-i386.d: Renamed to ...
	* ld-ifunc/ifunc-14a-i386.d: This.

	* ld-ifunc/ifunc-14-x86-64.d: Renamed to ...
	* ld-ifunc/ifunc-14a-x86-64.d: This.

	* ld-ifunc/ifunc-14b-i386.d: New file.
	* ld-ifunc/ifunc-14b-x86-64.d: Likewise.
	* ld-ifunc/ifunc-14c-i386.d: Likewise.
	* ld-ifunc/ifunc-14c-x86-64.d: Likewise.
	* ld-ifunc/ifunc-14d-i386.d: Likewise.
	* ld-ifunc/ifunc-14d-x86-64.d: Likewise.
2012-12-13 21:07:16 +00:00
H.J. Lu 9d4b2dba0e Replace _GLOBAL_OFFSET_TABLE_ lookup with htab->elf.hgot
* elf32-i386.c (elf_i386_size_dynamic_sections): Replace
	_GLOBAL_OFFSET_TABLE_ lookup with htab->elf.hgot.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.
2012-10-25 13:36:08 +00:00
H.J. Lu fbdc86d9c9 Ignore discarded section when converting mov to lea
* elf32-i386.c (elf_i386_convert_mov_to_lea): Ignore discarded
	section.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
2012-09-18 00:41:59 +00:00
H.J. Lu cec7f46ac2 Replace return FALSE with abort in x86 finish_dynamic_symbol
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Replace return
	FALSE with abort.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
2012-09-17 18:31:15 +00:00
H.J. Lu 9637f6ef78 Add hdynamic to elf_link_hash_table for _DYNAMIC
* elf-bfd.h (elf_link_hash_table): Add hdynamic for the
	_DYNAMIC symbol.

	* elflink.c (_bfd_elf_link_create_dynamic_sections): Set
	hdynamic.

	* elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_symbol): Check
	hdynamic instead of "_DYNAMIC".
	* elf32-arm.c (elf32_arm_finish_dynamic_symbol): Likewise.
	* elf32-cr16.c (elf32_arm_finish_dynamic_symbol): Likewise.
	* elf32-cris.c (elf_cris_finish_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_finish_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_convert_mov_to_lea): Likewise.
	* elf32-lm32.c (lm32_elf_finish_dynamic_symbol): Likewise.
	* elf32-m32r.c (m32r_elf_finish_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf32-sh.c (sh_elf_finish_dynamic_symbol): Likewise.
	* elf32-tic6x.c (elf32_tic6x_finish_dynamic_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_finish_dynamic_symbol): Likewise.
	* elf32-vax.c (elf_vax_finish_dynamic_symbol): Likewise.
	* elf32-xtensa.c (elf_xtensa_finish_dynamic_symbol): Likewise.
	* elf64-aarch64.c elf64_aarch64_finish_dynamic_symbol(): Likewise.
	* elf64-alpha.c (elf64_alpha_finish_dynamic_symbol): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_finish_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf64-sh64.c (sh64_elf64_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
	* elfnn-ia64.c (elfNN_ia64_finish_dynamic_symbol): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_finish_dynamic_symbol): Likewise.

	* elf32-microblaze.c (microblaze_elf_finish_dynamic_symbol): Check
	hdynamic, hgot, hplt instead of _DYNAMIC, _GLOBAL_OFFSET_TABLE_,
	_PROCEDURE_LINKAGE_TABLE_.
	* elf32-score.c (s3_bfd_score_elf_finish_dynamic_symbol): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_finish_dynamic_symbol): Likewise.
2012-09-02 12:17:27 +00:00
H.J. Lu 3f65f59941 Don't optimize relocation against _DYNAMIC
bfd/

	* elf32-i386.c (elf_i386_convert_mov_to_lea): Don't optimize
	_DYNAMIC.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.

ld/testsuite/

	* ld-i386/i386.exp: Run mov1a, mov1b.
	* ld-x86-64/x86-64.exp: Run mov1a, mov1b, mov1c, mov1d.

	* ld-i386/mov1.s: New file.
	* ld-i386/mov1a.d: Likewise.
	* ld-i386/mov1b.d: Likewise.
	* ld-x86-64/mov1.s: Likewise.
	* ld-x86-64/mov1a.d: Likewise.
	* ld-x86-64/mov1b.d: Likewise.
	* ld-x86-64/mov1c.d: Likewise.
	* ld-x86-64/mov1d.d: Likewise.
2012-09-01 02:50:14 +00:00
H.J. Lu daa6760707 Convert mov to lea in size_dynamic_sections
bfd/

	* elf32-i386.c (elf_i386_convert_mov_to_lea): New.
	(elf_i386_size_dynamic_sections): Use it on input sections.
	(elf_i386_relocate_section): Don't convert
	"mov foo@GOT(%reg), %reg" to "lea foo@GOTOFF(%reg), %reg"
	for local symbols here.

	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): New.
	(elf_x86_64_size_dynamic_sections): Use it on input sections.
	(elf_x86_64_relocate_section): Don't convert
	"mov foo@GOTPCREL(%rip), %reg" to "lea foo@GOTOFF(%reg), %reg"
	for local symbols.

ld/testsuite/

	* ld-i386/i386.exp: Run lea1d, lea1f, lea1f.
	* ld-x86-64/x86-64.exp: Run lea1g, lea1h, lea1i, lea1j, lea1k,
	lea1l.

	* ld-ifunc/ifunc-13-i386.d: Remove R_386_RELATIVE entry.

	* ld-i386/lea1d.d: New file.
	* ld-i386/lea1e.d: Likewise.
	* ld-i386/lea1f.d: Likewise.
	* ld-x86-64/lea1g.d: Likewise.
	* ld-x86-64/lea1h.d: Likewise.
	* ld-x86-64/lea1i.d: Likewise.
	* ld-x86-64/lea1j.d: Likewise.
	* ld-x86-64/lea1k.d: Likewise.
	* ld-x86-64/lea1l.d: Likewise.
2012-08-31 20:41:41 +00:00
H.J. Lu 80d873266d Convert mov to lea for loading local function address
bfd/

	* elf32-i386.c (elf_i386_relocate_section): Convert
	"mov foo@GOT(%reg), %reg" to "lea foo@GOTOFF(%reg), %reg"
	for local symbols.

	* elf64-x86-64.c (elf_x86_64_relocate_section): Convert
	"mov foo@GOTPCREL(%rip), %reg" to "lea foo(%rip), %reg"
	for local symbols.

ld/testsuite/

	* ld-i386/i386.exp: Run lea1a, lea1b, lea1c.
	* ld-x86-64/x86-64.exp: Run lea1a, lea1b, lea1c, lea1d, lea1e,
	lea1f.

	* ld-i386/lea1.s: New file.
	* ld-i386/lea1a.d: Likewise.
	* ld-i386/lea1b.d: Likewise.
	* ld-i386/lea1c.d: Likewise.
	* ld-x86-64/lea1.s: Likewise.
	* ld-x86-64/lea1a.d: Likewise.
	* ld-x86-64/lea1b.d: Likewise.
	* ld-x86-64/lea1c.d: Likewise.
	* ld-x86-64/lea1d.d: Likewise.
	* ld-x86-64/lea1e.d: Likewise.
	* ld-x86-64/lea1f.d: Likewise.
2012-08-31 04:26:17 +00:00
Alan Modra 3d4d4302b9 * section.c (bfd_get_linker_section): New function.
* elf32-arm.c: When retrieving SEC_LINKER_CREATED sections, use
	the above throughout rather than bfd_get_section_by_name.  Use
	bfd_make_section_anyway rather than bfd_make_section when creating
	them.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-xstormy16.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-sh64.c: Likewise.
	* elf64-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* elflink.c: Likewise.
	* elf-vxworks.c: Likewise.
	* elf-m10300.c: Likewise.  Also make use of htab plt, got and
	gotplt shortcuts.
	* bfd-in2.h: Regenerate.
	* elf32-lm32.c (lm32_elf_check_relocs): Use the correct bfd when
	calling create_rofixup_section.
	* elflink.c (bfd_elf_final_link): Simplify test for .dynstr.
2012-06-29 14:46:03 +00:00
H.J. Lu bbf96e4eef Don't use dynamic_sec_flags on PLT .eh_frame section
* elf32-i386.c (elf_i386_create_dynamic_sections): Don't use
	dynamic_sec_flags to create PLT .eh_frame section.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Likewise.
2012-05-25 16:20:15 +00:00
Alan Modra 9a2a56cc5a PR ld/13909
* elf-eh-frame.c (_bfd_elf_eh_frame_present): New function.
	(_bfd_elf_maybe_strip_eh_frame_hdr): Use it here.
	* elf-bfd.h (_bfd_elf_eh_frame_present): Declare.
	* elflink.c (bfd_elf_size_dynamic_sections): Let the backend
	size dynamic sections before stripping eh_frame_hdr.
	(bfd_elf_gc_sections): Handle multiple .eh_frame sections.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Drop glink_eh_frame
	if no other .eh_frame sections exist.
	* elf64-ppc.c (ppc64_elf_size_stubs): Likewise.
	* elf32-i386.c (elf_i386_create_dynamic_sections): Don't size
	or alloc plt_eh_frame here..
	(elf_i386_size_dynamic_sections): ..do it here instead.  Don't
	specially keep sgotplt, iplt, tgotplt, sdynbss for symbols.
	(elf_i386_finish_dynamic_sections): Check plt_eh_frame->contents
	before writing plt offset.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Don't size
	or alloc plt_eh_frame here..
	(elf_x86_64_size_dynamic_sections): ..do it here instead.
	(elf_x86_64_finish_dynamic_sections): Check plt_eh_frame->contents
	before writing plt offset.
2012-05-25 01:12:20 +00:00
H.J. Lu e4de50d447 Revert the change for PR ld/r13909
bfd/

	PR ld/13909
	* elf32-i386.c (elf_i386_create_dynamic_sections): Revert the
	last change.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Likewise.

ld/testsuite/

2012-05-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/13909
	* ld-i386/i386.exp: Revert the last change.
	* ld-x86-64/x86-64.exp: Likewise.

	* ld-i386/dummy.s: Removed.
	* ld-i386/pr13909.d: Likewise.
	* ld-x86-64/pr13909.d: Likewise.
2012-05-22 15:55:01 +00:00
H.J. Lu 5d4f7eb2f0 Create PLT eh_frame section if there is .eh_frame section
bfd/

	PR ld/13909
	* elf32-i386.c (elf_i386_create_dynamic_sections): Create PLT
	eh_frame section if there is an input .eh_frame section.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Likewise.

ld/testsuite/

	PR ld/13909
	* ld-i386/i386.exp: Run pr13909.
	* ld-x86-64/x86-64.exp: Likewise.

	* ld-i386/dummy.s: New file.
	* ld-i386/pr13909.d: Likewise.
	* ld-x86-64/pr13909.d: Likewise.
2012-05-22 14:46:44 +00:00
H.J. Lu 2fe0fd0638 Always create PLT eh_frame section for i386/x86-64
bfd/

2012-05-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/14105
	* elf32-i386.c (elf_i386_create_dynamic_sections): Always
	create PLT eh_frame section with SEC_LINKER_CREATED.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Likewise.

ld/testsuite/

2012-05-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/14105
	* ld-elf/eh4.d: Add PLT eh_frame.

	* ld-i386/i386.exp: Run pr12570a and pr12570b.
	* ld-x86-64/x86-64.exp: Likewise.

	* ld-i386/pr12570a.d: New file.
	* ld-i386/pr12570a.s: Likewise.
	* ld-i386/pr12570b.s: Likewise.
	* ld-i386/pr12570b.s: Likewise.
	* ld-x86-64/pr12570a.d: Likewise.
	* ld-x86-64/pr12570a.s: Likewise.
	* ld-x86-64/pr12570b.d: Likewise.
	* ld-x86-64/pr12570b.s: Likewise.
2012-05-22 14:05:21 +00:00
H.J. Lu 220cf8092f Don't make _DYNAMIC/_GLOBAL_OFFSET_TABLE_ absolute
bfd/

	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Don't make
	_DYNAMIC nor _GLOBAL_OFFSET_TABLE_ absolute.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.

ld/testsuite/

	* ld-i386/tlsdesc-nacl.rd: Update for dynamic sym changes.
	* ld-i386/tlsdesc.rd: Likewise.
	* ld-i386/tlsgdesc-nacl.rd: Likewise.
	* ld-i386/tlsgdesc.rd: Likewise.
	* ld-i386/tlsnopic-nacl.rd: Likewise.
	* ld-i386/tlsnopic.rd: Likewise.
	* ld-i386/tlspic-nacl.rd: Likewise.
	* ld-i386/tlspic.rd: Likewise.
	* ld-x86-64/tlsdesc-nacl.rd: Likewise.
	* ld-x86-64/tlsdesc.rd: Likewise.
	* ld-x86-64/tlsgdesc-nacl.rd: Likewise.
	* ld-x86-64/tlsgdesc.rd: Likewise.
	* ld-x86-64/tlspic-nacl.rd: Likewise.
	* ld-x86-64/tlspic.rd: Likewise.
2012-05-18 22:26:18 +00:00
Maciej W. Rozycki 545fd46b6b * elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Handle compound
relocations.
	* elfxx-mips.c (mips_reloc_against_discarded_section): New
	function.
	(_bfd_mips_elf_relocate_section): Call it, in place of
	RELOC_AGAINST_DISCARDED_SECTION.
	* elf-m10200.c (mn10200_elf_relocate_section): Update arguments
	to RELOC_AGAINST_DISCARDED_SECTION.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf32-arm.c (elf32_arm_relocate_section): Likewise.
	* elf32-avr.c (elf32_avr_relocate_section): Likewise.
	* elf32-bfin.c (bfin_relocate_section): Likewise.
	(bfinfdpic_relocate_section): Likewise.
	* elf32-cr16.c (elf32_cr16_relocate_section): Likewise.
	* elf32-cr16c.c (elf32_cr16c_relocate_section): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-crx.c (elf32_crx_relocate_section): Likewise.
	* elf32-d10v.c (elf32_d10v_relocate_section): Likewise.
	* elf32-epiphany.c (epiphany_elf_relocate_section): Likewise.
	* elf32-fr30.c (fr30_elf_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-h8300.c (elf32_h8_relocate_section): Likewise.
	* elf32-hppa.c (elf32_hppa_relocate_section): Likewise.
	* elf32-i370.c (i370_elf_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-i860.c (elf32_i860_relocate_section): Likewise.
	* elf32-ip2k.c (ip2k_elf_relocate_section): Likewise.
	* elf32-iq2000.c (iq2000_elf_relocate_section): Likewise.
	* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
	* elf32-m32c.c (m32c_elf_relocate_section): Likewise.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-mep.c (mep_elf_relocate_section): Likewise.
	* elf32-moxie.c (moxie_elf_relocate_section): Likewise.
	* elf32-msp430.c (elf32_msp430_relocate_section): Likewise.
	* elf32-mt.c (mt_elf_relocate_section): Likewise.
	* elf32-openrisc.c (openrisc_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-rl78.c (rl78_elf_relocate_section): Likewise.
	* elf32-rx.c (rx_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-spu.c (spu_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-v850.c (v850_elf_relocate_section): Likewise.
	* elf32-vax.c (elf_vax_relocate_section): Likewise.
	* elf32-xc16x.c (elf32_xc16x_relocate_section): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-alpha.c (elf64_alpha_relocate_section_r): Likewise.
	(elf64_alpha_relocate_section): Likewise.
	* elf64-hppa.c (elf64_hppa_relocate_section): Likewise.
	* elf64-mmix.c (mmix_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-sh64.c (sh_elf64_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elfnn-ia64.c (elfNN_ia64_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
2012-05-07 03:27:52 +00:00
Alan Modra dbaa201145 PR ld/13991
bfd/
	* bfd/elf-bfd.h (_bfd_elf_link_just_syms): Define as
	_bfd_generic_link_just_syms.
	* bfd/elflink.c (_bfd_elf_link_just_syms): Delete.
	* bfd/linker.c (_bfd_generic_link_just_syms): Set sec_info_type.

	* bfd/bfd-in.h (discarded_section): Renamed from elf_discarded_section.
	* bfd/section.c (SEC_INFO_TYPE_NONE, SEC_INFO_TYPE_STABS,
	SEC_INFO_TYPE_MERGE, SEC_INFO_TYPE_EH_FRAME,
	SEC_INFO_TYPE_JUST_SYMS): Renamed from corresponding ELF_INFO_TYPE.
	* bfd/elf-eh-frame.c, * bfd/elf-m10200.c, * bfd/elf-m10300.c,
	* bfd/elf.c, * bfd/elf32-arm.c, * bfd/elf32-avr.c, * bfd/elf32-bfin.c,
	* bfd/elf32-cr16.c, * bfd/elf32-cr16c.c, * bfd/elf32-cris.c,
	* bfd/elf32-crx.c, * bfd/elf32-d10v.c, * bfd/elf32-epiphany.c,
	* bfd/elf32-fr30.c, * bfd/elf32-frv.c, * bfd/elf32-h8300.c,
	* bfd/elf32-hppa.c, * bfd/elf32-i370.c, * bfd/elf32-i386.c,
	* bfd/elf32-i860.c, * bfd/elf32-ip2k.c, * bfd/elf32-iq2000.c,
	* bfd/elf32-lm32.c, * bfd/elf32-m32c.c, * bfd/elf32-m32r.c,
	* bfd/elf32-m68hc1x.c, * bfd/elf32-m68k.c, * bfd/elf32-mcore.c,
	* bfd/elf32-mep.c, * bfd/elf32-moxie.c, * bfd/elf32-msp430.c,
	* bfd/elf32-mt.c, * bfd/elf32-openrisc.c, * bfd/elf32-ppc.c,
	* bfd/elf32-rl78.c, * bfd/elf32-rx.c, * bfd/elf32-s390.c,
	* bfd/elf32-score.c, * bfd/elf32-score7.c, * bfd/elf32-sh.c,
	* bfd/elf32-spu.c, * bfd/elf32-tic6x.c, * bfd/elf32-tilepro.c,
	* bfd/elf32-v850.c, * bfd/elf32-vax.c, * bfd/elf32-xc16x.c,
	* bfd/elf32-xstormy16.c, * bfd/elf32-xtensa.c, * bfd/elf64-alpha.c,
	* bfd/elf64-hppa.c, * bfd/elf64-ia64-vms.c, * bfd/elf64-mmix.c,
	* bfd/elf64-ppc.c, * bfd/elf64-s390.c, * bfd/elf64-sh64.c,
	* bfd/elf64-x86-64.c, * bfd/elflink.c, * bfd/elfnn-ia64.c,
	* bfd/elfxx-mips.c, * bfd/elfxx-sparc.c, * bfd/elfxx-tilegx.c,
	* bfd/reloc.c: Update all references.
	* bfd/bfd-in2.h: Regenerate.
ld/
	* ld/ldlang.c (size_input_section): Use sec_info_type rather than
	usrdata->flags.just_syms.
	* ld/ldwrite.c (build_link_order): Likewise.
	* ld/emultempl/hppaelf.em (build_section_lists): Likewise.
	* ld/emultempl/ppc64elf.em (build_toc_list): Likewise.
	* ld/emultempl/armelf.em (build_section_lists): Likewise.
	(after_allocation): Update for renamed sec_info_type value.
	* ld/emultempl/tic6xdsbt.em: Likewise.
2012-04-24 05:12:40 +00:00
Roland McGrath 5a68afcf73 bfd/
2012-04-03  Roland McGrath  <mcgrathr@google.com>

	* elf-nacl.c: New file.
	* elf-nacl.h: New file.
	* elf32-i386.c (elf_backend_modify_segment_map): Define for
	bfd_elf32_i386_nacl_vec.
	(elf_backend_modify_program_headers): Likewise.
	* elf64-x86-64.c (elf_backend_modify_segment_map): Define for
	bfd_elf64_x86_64_nacl_vec and bfd_elf32_x86_64_nacl_vec.
	(elf_backend_modify_program_headers): Likewise.
	* Makefile.am (BFD32_BACKENDS, BFD64_BACKENDS): Add elf-nacl.lo here.
	(BFD32_BACKENDS_CFILES, BFD64_BACKENDS_CFILES): Add elf-nacl.c here.
	* Makefile.in: Regenerated.
	* configure.in (bfd_elf64_x86_64_nacl_vec): Add elf-nacl.o to tb here.
	(bfd_elf32_x86_64_nacl_vec): Likewise.
	(bfd_elf64_x86_64_vec, bfd_elf32_x86_64_vec): Likewise.
	(bfd_elf64_x86_64_freebsd_vec, bfd_elf64_x86_64_sol2_vec): Likewise.
	(bfd_elf64_l1om_vec, bfd_elf64_l1om_freebsd_vec): Likewise.
	(bfd_elf64_k1om_vec, bfd_elf64_k1om_freebsd_vec): Likewise.
	(bfd_elf32_i386_nacl_vec): Likewise.
	(bfd_elf32_i386_sol2_vec, bfd_elf32_i386_freebsd_vec): Likewise.
	(bfd_elf32_i386_vxworks_vec, bfd_elf32_i386_vec): Likewise.
	* configure: Regenerated.

binutils/testsuite/
2012-04-03  Roland McGrath  <mcgrathr@google.com>

	* lib/binutils-common.exp (is_elf_format): Consider *-*-nacl* to
	be ELF too.

	* binutils-all/elfedit-4.d: Add "#as: --64" option.

	* binutils-all/i386/i386.exp: Accept nacl targets too.
	* binutils-all/x86-64/x86-64.exp: Likewise.

gas/testsuite/
2012-04-03  Roland McGrath  <mcgrathr@google.com>

	* gas/i386/k1om.d: Add not-target match for *-*-nacl*.
	* gas/i386/l1om.d: Likewise.

ld/
2012-04-03  Roland McGrath  <mcgrathr@google.com>

	* configure.tgt (i[3-7]86-*-nacl*, x86_64-*-nacl*): Handle them.
	* emulparams/elf_nacl.sh: New file.
	* emulparams/elf_i386_nacl.sh: New file.
	* emulparams/elf32_x86_64_nacl.sh: New file.
	* emulparams/elf_x86_64_nacl.sh: New file.
	* Makefile.am (ALL_EMULATION_SOURCES): Add eelf_i386_nacl.c here.
	(ALL_64_EMULATION_SOURCES): Add eelf32_x86_64_nacl.c and
	eelf_x86_64_nacl.c here.
	(eelf_i386_nacl.c, eelf32_x86_64_nacl.c, eelf_x86_64_nacl.c):
	New targets.
	* Makefile.in: Regenerated.

	* scripttempl/elf.sc: Handle SEPARATE_CODE cases.

ld/testsuite/
2012-04-03  Roland McGrath  <mcgrathr@google.com>

	* ld-x86-64/ilp32-4-nacl.d: New file.
	* ld-x86-64/x86-64.exp: Run it.

	* ld-discard/discard.exp: Accept nacl targets too.
	* ld-elf/binutils.exp: Likewise.
	* ld-elf/comm-data.exp: Likewise.
	* ld-elf/elf.exp: Likewise.
	* ld-elf/tls_common.exp: Likewise.
	* ld-elfvers/vers.exp: Likewise.
	* ld-elfvsb/elfvsb.exp: Likewise.
	* ld-elfweak/elfweak.exp: Likewise.
	* ld-gc/gc.exp: Likewise.
	* ld-ifunc/binutils.exp: Likewise.
	* ld-ifunc/ifunc.exp: Likewise.
	* ld-linkonce/linkonce.exp:Likewise.
	* ld-pie/pie.exp: Likewise.
	* ld-shared/shared.exp: Likewise.
	* ld-undefined/weak-undef.exp: Likewise.
	* ld-unique/unique.exp: Likewise.
	* ld-x86-64/dwarfreloc.exp: Likewise.
	* ld-x86-64/line.exp: Likewise.

	* lib/ld-lib.exp (slurp_options): Support global array
	options_regsub to apply substitutions to the contents
	of options lines read from the file.
	* ld-i386/emit-relocs.d: Renamed to ...
	* ld-i386/emit-relocs.rd: ... this.
	* ld-i386/i386.exp: Accept nacl targets too.
	For them, use options_regsub to replace elf_i386 with
	elf_i386_nacl in run_dump_test cases; apply the same
	substitution in $i386tests; replace foo.rd expectations
	files with foo-nacl.rd in $i386tests.
	(i386tests): Change emit-relocs.d to emit-relocs.rd here.
	* ld-i386/emit-relocs-nacl.rd: New file.
	* ld-i386/plt-nacl.pd: New file.
	* ld-i386/plt-pic-nacl.pd: New file.
	* ld-i386/tlsbin-nacl.rd: New file.
	* ld-i386/tlsbindesc-nacl.rd: New file.
	* ld-i386/tlsdesc-nacl.rd: New file.
	* ld-i386/tlsgdesc-nacl.rd: New file.
	* ld-i386/tlsnopic-nacl.rd: New file.
	* ld-i386/tlspic-nacl.rd: New file.
	* ld-x86-64/x86-64.exp: Accept nacl targets too.
	For them, use options_regsub to replace elf_x86_64 with
	elf_x86_64_nacl in run_dump_test cases; apply the same
	substitution in $x86_64tests; replace foo.rd expectations
	files with foo-nacl.rd in $x86_64tests.
	Add explicit -melf_x86_64 to ld options in tests that need it,
	in case the default emulation is x32 (as it is for x86_64-nacl).
	* ld/testsuite/ld-x86-64/plt-nacl.pd: New file.
	* ld/testsuite/ld-x86-64/split-by-file-nacl.rd: New file.
	* ld/testsuite/ld-x86-64/tlsbin-nacl.rd: New file.
	* ld/testsuite/ld-x86-64/tlsbindesc-nacl.rd: New file.
	* ld/testsuite/ld-x86-64/tlsdesc-nacl.pd: New file.
	* ld/testsuite/ld-x86-64/tlsdesc-nacl.rd: New file.
	* ld/testsuite/ld-x86-64/tlsgdesc-nacl.rd: New file.
	* ld/testsuite/ld-x86-64/tlspic-nacl.rd: New file.

	* ld-i386/hidden2.d: Loosen regexps to match any file format variant,
	and not to depend on exact addresses, displacements, etc. where
	they are irrelevant.
	* ld-i386/pcrel16.d: Likewise.
	* ld-i386/pcrel16abs.d: Likewise.
	* ld-i386/pr12718.d: Likewise.
	* ld-i386/pr12921.d: Likewise.
	* ld-i386/reloc.d: Likewise.
	* ld-i386/tlsbin.dd: Likewise.
	* ld-i386/tlsbin.sd: Likewise.
	* ld-i386/tlsbin.td: Likewise.
	* ld-i386/tlsbindesc.dd: Likewise.
	* ld-i386/tlsbindesc.sd: Likewise.
	* ld-i386/tlsbindesc.td: Likewise.
	* ld-i386/tlsdesc.dd: Likewise.
	* ld-i386/tlsdesc.sd: Likewise.
	* ld-i386/tlsdesc.td: Likewise.
	* ld-i386/tlsg.sd: Likewise.
	* ld-i386/tlsgdesc.dd: Likewise.
	* ld-i386/tlsindntpoff.dd: Likewise.
	* ld-i386/tlsnopic.dd: Likewise.
	* ld-i386/tlsnopic.sd: Likewise.
	* ld-i386/tlspic.dd: Likewise.
	* ld-i386/tlspic.sd: Likewise.
	* ld-i386/tlspic.td: Likewise.
	* ld-i386/tlspie2.d: Likewise.
	* ld-x86-64/hidden2.d: Likewise.
	* ld-x86-64/pcrel16.d: Likewise.
	* ld-x86-64/pr12718.d: Likewise.
	* ld-x86-64/pr12921.d: Likewise.
	* ld-x86-64/protected3.d: Likewise.
	* ld-x86-64/tlsbin.dd: Likewise.
	* ld-x86-64/tlsbin.sd: Likewise.
	* ld-x86-64/tlsbin.td: Likewise.
	* ld-x86-64/tlsbindesc.dd: Likewise.
	* ld-x86-64/tlsbindesc.sd: Likewise.
	* ld-x86-64/tlsbindesc.td: Likewise.
	* ld-x86-64/tlsdesc.dd: Likewise.
	* ld-x86-64/tlsdesc.sd: Likewise.
	* ld-x86-64/tlsdesc.td: Likewise.
	* ld-x86-64/tlsg.sd: Likewise.
	* ld-x86-64/tlsgd5.dd: Likewise.
	* ld-x86-64/tlsgd6.dd: Likewise.
	* ld-x86-64/tlsgdesc.dd: Likewise.
	* ld-x86-64/tlspic.dd: Likewise.
	* ld-x86-64/tlspic.sd: Likewise.
	* ld-x86-64/tlspic.td: Likewise.

	* ld-x86-64/ilp32-8.d: Match any file format variant.
	Use a -Ttext and adjust expected results, to handle variant layouts.
	* ld-x86-64/ilp32-9.d: Likewise.

	* ld-i386/alloc.t: Remove superfluous OUTPUT_FORMAT statement.
	* ld-i386/pr12627.t: Likewise.

	* ld-x86-64/abs-l1om.d: Add target: constraint.
	* ld-x86-64/protected2-l1om.d: Likewise.
	* ld-x86-64/protected3-l1om.d: Likewise.
	* ld-x86-64/ilp32-4.d: Likewise.

	* ld-x86-64/plt.s: New file.
	* ld-x86-64/pltlib.s: New file.
	* ld-x86-64/plt.pd: New file.
	* ld-x86-64/x86-64.exp (x86_64tests): Add them.

	* ld-i386/plt.s: New file.
	* ld-i386/pltlib.s: New file.
	* ld-i386/plt.pd: New file.
	* ld-i386/plt-pic.s: New file.
	* ld-i386/plt-pic.pd: New file.
	* ld-i386/i386.exp (i386tests): Add them.
2012-04-03 16:01:38 +00:00
H.J. Lu bdb892b995 Handle relocation against protected function for -Bsymbolic
bfd/

2012-03-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/13880
	* elf32-i386.c (elf_i386_relocate_section): Don't issue an error
	for R_386_GOTOFF relocation against protected function if
	SYMBOLIC_BIND is true.

	* elf64-x86-64.c (elf_x86_64_relocate_section): Don't issue an
	error for R_X86_64_GOTOFF64 relocation against protected function
	when building executable or SYMBOLIC_BIND is true.

ld/testsuite/

2012-03-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/13880
	* ld-i386/i386.exp: Run protected4 and protected5.
	* ld-x86-64/x86-64.exp: Likewise.

	* ld-i386/protected4.d: New.
	* ld-i386/protected4.s: Likewise.
	* ld-i386/protected5.d: Likewise.
	* ld-i386/protected5.s: Likewise.
	* ld-x86-64/protected4.d: Likewise.
	* ld-x86-64/protected4.s: Likewise.
	* ld-x86-64/protected5.d: Likewise.
	* ld-x86-64/protected5.s: Likewise.
2012-03-20 18:16:38 +00:00
Roland McGrath caa0075c38 * elf32-i386.c (elf_i386_nacl_pic_plt0_entry): Initialize up
to the full size, padding out with nop instructions.
2012-03-14 19:32:11 +00:00
Alan Modra 1d7e9d183f * elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Don't error
on zero size dynbss symbol.
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_adjust_dynamic_symbol): Likewise.
	* elf32-cris.c (elf_cris_adjust_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol): Likewise.
	* elf32-i370.c (i370_elf_adjust_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Likewise.
	* elf32-lm32.c (lm32_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m32r.c (m32r_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m68k.c (elf_m68k_adjust_dynamic_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf32-sh.c (sh_elf_adjust_dynamic_symbol): Likewise.
	* elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol): Likewise.
	* elf32-vax.c (elf_vax_adjust_dynamic_symbol): Likewise.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf64-sh64.c (sh64_elf64_adjust_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol): Likewise.
2012-03-13 06:04:37 +00:00
H.J. Lu 56b8aada47 Restore R_386_IRELATIVE and R_X86_64_IRELATIVE
bfd/

2012-03-09  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/13817
	* bfd/elf32-i386.c (elf_i386_relocate_section): Restore
	R_386_IRELATIVE.

	* * elf64-x86-64.c (elf_x86_64_relocate_section): Restore
	R_X86_64_IRELATIVE.

ld/testsuite/

2012-03-09  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/13817
	* ld-i386/pr13302.d: Updated.
	* ld-x86-64/pr13082-5b.d: Likewise.
	* ld-x86-64/pr13082-6a.d: Likewise.
	* ld-x86-64/pr13082-6b.d: Likewise.
2012-03-09 16:28:38 +00:00
H.J. Lu 9892017203 Replace IRELATIVE relocations with RELATIVE in .rel.dyn.
bfd/

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

	PR ld/13302
	* elf32-i386.c (elf_i386_relocate_section): Replace
	R_386_IRELATIVE with R_386_RELATIVE.

	* elf64-x86-64.c (elf_x86_64_relocate_section): Replace
	R_X86_64_IRELATIVE with R_X86_64_RELATIVE.

ld/testsuite/

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

	PR ld/13302
	* ld-i386/i386.exp: Run pr13302.

	* ld-i386/pr13302.d: New.
	* ld-i386/pr13302.s: Likewise.

	* ld-x86-64/pr13082-5b.d: Updated.
	* ld-x86-64/pr13082-6a.d: Likewise.
	* ld-x86-64/pr13082-6b.d: Likewise.
2011-10-21 19:37:15 +00:00
H.J. Lu c293fa4964 Fix a typo in comments.
2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>.

	* elf32-i386.c (elf_i386_relocate_section): Fix a typo in
	comments.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2011-10-21 16:16:51 +00:00
H.J. Lu e1f987424b 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.

	* elf64-x86-64.c (elf_x86_64_link_hash_table): Add
	next_jump_slot_index and next_irelative_index.
	(elf_x86_64_link_hash_table_create): Initialize
	next_jump_slot_index and next_irelative_index.
	(elf_x86_64_size_dynamic_sections): Set next_irelative_index
	from reloc_count.
	(elf_x86_64_finish_dynamic_symbol): Put R_X86_64_IRELATIVE after
	R_X86_64_JUMP_SLOT.

ld/testsuite/

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

	PR ld/13302
	* ld-ifunc/ifunc-16-i386.d: New.
	* ld-ifunc/ifunc-16-x86-64.d: Likewise.
	* ld-ifunc/ifunc-16-x86.s: Likewise.
2011-10-21 15:13:37 +00:00
Alan Modra fa289a5fde * elf32-i386.c (i386_opcode16): Delete.
(elf_i386_check_tls_transition): Use memcmp to compare contents.
	* elf64-x86-64.c (x86_64_opcode16, x86_64_opcode32): Delete.
	(elf_x86_64_check_tls_transition): Use memcmp to compare contents.
2011-10-19 23:02:50 +00:00
Alan Modra 1d5316ab67 PR ld/13177
bfd/
	* elflink.c (_bfd_elf_gc_mark_rsec): Set symbol "mark".
	(elf_gc_sweep_symbol): Don't test plt/got refcounts, instead test
	"mark".  Hide undefweak too.  Clear def_regular and ref_regular.
	* elf-m10300.c (mn10300_elf_relocate_section): Ignore unresolved
	reloc errors from garbage-collected code.
	* elf32-arm.c (elf32_arm_relocate_section): Likewise.
	* elf32-bfin.c (bfin_relocate_section): Likewise.
	(bfinfdpic_relocate_section): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-spu.c (spu_elf_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-alpha.c (elf64_alpha_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-sh64.c (sh_elf64_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
ld/testsuite/
	* ld-elf/elf.exp: Move test for shared lib support..
	* lib/ld-lib.exp (check_shared_lib_support): ..to here. Add m68hc1*,
	and s/ms1/mt/.
	(check_gc_sections_available): Match hppa*64 not hppa64.  Comment.
	* ld-gc/libpersonality.s: New.
	* ld-gc/personality.s, * ld-gc/personality.d: New.
	* ld-gc/gc.exp: Run personality test.
2011-10-19 07:17:21 +00:00
Roland McGrath a27e437177 BFD vector for elf32-i386-nacl:
bfd/
	* elf32-i386.c (NACL_PLT_ENTRY_SIZE, NACLMASK): New macros.
	(elf_i386_nacl_plt0_entry): New variable.
	(elf_i386_plt_entry): New variable.
	(elf_i386_nacl_pic_plt0_entry): New variable.
	(elf_i386_nacl_pic_plt_entry): New variable.
	(elf_i386_nacl_plt, elf_i386_nacl_arch_bed): New variables.
	(elf_backend_arch_data): New macro setting for elf_i386_nacl_vec stanza.
	(elf_backend_plt_alignment): Likewise.

	* config.bfd: Handle i[3-7]86-*-nacl*.
	* elf32-i386.c (bfd_elf32_i386_nacl_vec): New backend vector stanza.
	* targets.c: Support bfd_elf32_i386_nacl_vec.
	* configure.in: Likewise.
	* configure: Regenerated.
2011-07-28 22:35:15 +00:00
Roland McGrath 25e762b98d Parameterize elf32-i386 PLT generation:
* elf32-i386.c (struct elf_i386_plt_layout): New type.
	(GET_PLT_ENTRY_SIZE): New macro.
	(elf_i386_plt): New variable.
	(struct elf_i386_backend_data): New member `plt'.
	(elf_i386_arch_bed): Add initializer for it.
	(elf_i386_vxworks_arch_bed): Likewise.
	(elf_i386_allocate_dynrelocs): Use GET_PLT_ENTRY_SIZE.
	(elf_i386_plt_sym_val): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	Also use other elf_i386_plt_layout members for PLT details.
	(elf_i386_finish_dynamic_sections): Likewise.
2011-07-28 18:47:56 +00:00
Roland McGrath 23209a7853 Clean up elf32-i386-vxworks:
* elf32-i386.c (struct elf_i386_backend_data): New type.
	(get_elf_i386_backend_data): New macro.
	(elf_i386_arch_bed): New variable.
	(elf_backend_arch_data): New macro.
	(struct elf_i386_link_hash_table): Remove plt0_pad_byte and is_vxworks.
	(elf_i386_link_hash_table_create): Don't initialize them.
	(elf_i386_create_dynamic_sections): Find is_vxworks flags in
	elf_i386_backend_data, not elf_i386_link_hash_table.
	(elf_i386_adjust_dynamic_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_readonly_dynrelocs): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(elf_i386_finish_dynamic_sections): Likewise.  Same for plt0_pad_byte.
	(elf_i386_vxworks_link_hash_table_create): Function removed.
	(elf_i386_vxworks_arch_bed): New variable.
	(elf_backend_arch_data): New macro in elf32-i386-vxworks stanza.

	* elf-bfd.h (elf_backend_data): New member arch_backend_data.
	* elfxx-target.h (elf_backend_arch_data): New macro.
	(elfNN_bed): Use it as initializer for the new member.
2011-07-28 17:39:20 +00:00
Ian Lance Taylor 28ede8be33 * elf32-i386.c (elf_i386_eh_frame_plt): Correct expression: change
DW_OP_lit3 to DW_OP_lit2.
2011-07-01 22:14:56 +00:00
Jan Kratochvil 332ce62bf3 bfd/
* elf64-x86-64.c (elf_x86_64_link_hash_table_create): Initialize
	PLT_EH_FRAME.
	* elf32-i386.c (elf_i386_link_hash_table): Likewise.
2011-06-25 00:43:15 +00:00
Jakub Jelinek e41b3a1379 PR ld/12570
include/
	* bfdlink.h (struct bfd_link_info): Add no_ld_generated_unwind_info
	option.
ld/
	* emultempl/elf32.em (OPTION_LD_GENERATED_UNWIND_INFO,
	OPTION_NO_LD_GENERATED_UNWIND_INFO): Define.
	(gld${EMULATION_NAME}_handle_option): Handle
	--ld-generated-unwind-info and --no-ld-generated-unwind-info.
	* ld.texinfo (--ld-generated-unwind-info,
	--no-ld-generated-unwind-info): Document.
bfd/
	* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Allow no relocations
	at all for linker created .eh_frame sections.
	(_bfd_elf_discard_section_eh_frame): Handle linker created
	.eh_frame sections with no relocations.
	* elf64-x86-64.c: Include dwarf2.h.
	(elf_x86_64_eh_frame_plt): New variable.
	(PLT_CIE_LENGTH, PLT_FDE_LENGTH, PLT_FDE_START_OFFSET,
	PLT_FDE_LEN_OFFSET): Define.
	(struct elf_x86_64_link_hash_table): Add plt_eh_frame field.
	(elf_x86_64_create_dynamic_sections): Create and fill in
	.eh_frame section for .plt section.
	(elf_x86_64_size_dynamic_sections): Write .plt section size
	into .eh_frame FDE covering .plt section.
	(elf_x86_64_finish_dynamic_sections): Write .plt section
	start into .eh_frame FDE covering .plt section.  Call
	_bfd_elf_write_section_eh_frame on htab->plt_eh_frame section.
	(elf_backend_plt_alignment): Define to 4.
	* elf32-i386.c: Include dwarf2.h.
	(elf_i386_eh_frame_plt): New variable.
	(PLT_CIE_LENGTH, PLT_FDE_LENGTH, PLT_FDE_START_OFFSET,
	PLT_FDE_LEN_OFFSET): Define.
	(struct elf_i386_link_hash_table): Add plt_eh_frame field.
	(elf_i386_create_dynamic_sections): Create and fill in
	.eh_frame section for .plt section.
	(elf_i386_size_dynamic_sections): Write .plt section size
	into .eh_frame FDE covering .plt section.
	(elf_i386_finish_dynamic_sections): Write .plt section
	start into .eh_frame FDE covering .plt section.  Call
	_bfd_elf_write_section_eh_frame on htab->plt_eh_frame section.
	(elf_backend_plt_alignment): Define to 4.
ld/testsuite/
	* ld-x86-64/x86-64.exp: Link some testcases with
	--no-ld-generated-unwind-info.
	* ld-x86-64/tlsbin.rd: Add --no-ld-generated-unwind-info to ld
	comment.
	* ld-x86-64/tlsdesc.dd: Likewise.
	* ld-x86-64/tlspic.dd: Likewise.
	* ld-x86-64/tlsdesc.sd: Likewise.
	* ld-x86-64/tlspic.rd: Likewise.
	* ld-x86-64/tlsbindesc.rd: Likewise.
	* ld-x86-64/tlsbindesc.sd: Likewise.
	* ld-x86-64/tlsbin.td: Likewise.
	* ld-x86-64/tlsdesc.pd: Likewise.
	* ld-x86-64/tlsdesc.td: Likewise.
	* ld-x86-64/tlsbindesc.dd: Likewise.
	* ld-x86-64/tlsbin.dd: Likewise.
	* ld-x86-64/tlsgdesc.rd: Likewise.
	* ld-x86-64/tlspic.sd: Likewise.
	* ld-x86-64/tlsbindesc.td: Likewise.
	* ld-x86-64/tlspic.td: Likewise.
	* ld-x86-64/tlsbin.sd: Likewise.
	* ld-x86-64/ilp32-4.d: Likewise.
	* ld-x86-64/tlsgdesc.dd: Add --no-ld-generated-unwind-info to ld
	comment.  Adjust.
	* ld-x86-64/tlsdesc.rd: Likewise.
	* ld-x86-64/tlsgd6.dd: Adjust.
	* ld-x86-64/tlsgd5.dd: Likewise.
	* ld-i386/i386.exp: Link some testcases with
	--no-ld-generated-unwind-info.
	* ld-i386/tlsbin.rd: Add --no-ld-generated-unwind-info to ld
	comment..
	* ld-i386/tlsdesc.dd: Likewise.
	* ld-i386/tlspic.dd: Likewise.
	* ld-i386/tlsdesc.sd: Likewise.
	* ld-i386/tlsgdesc.dd: Likewise.
	* ld-i386/tlsnopic.sd: Likewise.
	* ld-i386/tlspic.rd: Likewise.
	* ld-i386/tlsdesc.rd: Likewise.
	* ld-i386/tlsbindesc.rd: Likewise.
	* ld-i386/tlsbindesc.sd: Likewise.
	* ld-i386/tlsbin.td: Likewise.
	* ld-i386/tlsdesc.td: Likewise.
	* ld-i386/tlsnopic.dd: Likewise.
	* ld-i386/tlsbindesc.dd: Likewise.
	* ld-i386/tlsbin.dd: Likewise.
	* ld-i386/tlsgdesc.rd: Likewise.
	* ld-i386/tlspic.sd: Likewise.
	* ld-i386/tlsnopic.rd: Likewise.
	* ld-i386/tlsbindesc.td: Likewise.
	* ld-i386/tlspic.td: Likewise.
	* ld-i386/tlsbin.sd: Likewise.
2011-06-20 13:18:52 +00:00
Alan Modra 7686d77de3 * linker.c (bfd_link_hash_traverse): Follow warning symbol link.
(_bfd_generic_link_write_global_symbol, fix_syms): Don't handle
	warning symbols here.
	* elf-m10300.c (elf32_mn10300_finish_hash_table_entry): Likewise.
	* elf32-arm.c (allocate_dynrelocs_for_symbol,
	elf32_arm_readonly_dynrelocs): Likewise.
	* elf32-bfin.c (bfin_discard_copies): Likewise.
	* elf32-cris.c (elf_cris_adjust_gotplt_to_got,
	elf_cris_discard_excess_dso_dynamics,
	elf_cris_discard_excess_program_dynamics): Likewise.
	* elf32-hppa.c (allocate_plt_static, allocate_dynrelocs,
	clobber_millicode_symbols, readonly_dynrelocs): Likewise.
	* elf32-i370.c (i370_elf_adjust_dynindx): Likewise.
	* elf32-i386.c (elf_i386_allocate_dynrelocs,
	elf_i386_readonly_dynrelocs): Likewise.
	* elf32-lm32.c (allocate_dynrelocs, readonly_dynrelocs): Likewise.
	* elf32-m32c.c (m32c_relax_plt_check, m32c_relax_plt_realloc): Likewise.
	* elf32-m32r.c (allocate_dynrelocs, readonly_dynrelocs): Likewise.
	* elf32-m68k.c (elf_m68k_discard_copies): Likewise.
	* elf32-microblaze.c (allocate_dynrelocs): Likewise.
	* elf32-ppc.c (allocate_dynrelocs, maybe_set_textrel): Likewise.
	* elf32-s390.c (allocate_dynrelocs, readonly_dynrelocs): Likewise.
	* elf32-score.c (score_elf_sort_hash_table_f): Likewise.
	* elf32-score7.c (score_elf_sort_hash_table_f): Likewise.
	* elf32-sh.c (allocate_dynrelocs, readonly_dynrelocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_allocate_dynrelocs,
	elf32_tic6x_readonly_dynrelocs): Likewise.
	* elf32-vax.c (elf_vax_discard_copies): Likewise.
	* elf32-xstormy16.c (xstormy16_relax_plt_check,
	xstormy16_relax_plt_realloc): Likewise.
	* elf32-xtensa.c (elf_xtensa_allocate_dynrelocs): Likewise.
	* elf64-alpha.c (elf64_alpha_output_extsym,
	elf64_alpha_calc_got_offsets_for_symbol,
	elf64_alpha_calc_dynrel_sizes, elf64_alpha_size_rela_got_1): Likewise.
	* elf64-hppa.c (elf64_hppa_mark_exported_functions,
	allocate_global_data_opd, elf64_hppa_mark_milli_and_exported_functions,
	elf_hppa_unmark_useless_dynamic_symbols,
	elf_hppa_remark_useless_dynamic_symbols): Likewise.
	* elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref, func_desc_adjust,
	adjust_opd_syms, adjust_toc_syms, allocate_dynrelocs,
	readonly_dynrelocs, merge_global_got, reallocate_got,
	undo_symbol_twiddle): Likewise.
	* elf64-s390.c (allocate_dynrelocs, readonly_dynrelocs): Likewise.
	* elf64-sh64.c (sh64_elf64_discard_copies): Likewise.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs,
	elf_x86_64_readonly_dynrelocs): Likewise.
	* elflink.c (elf_link_renumber_hash_table_dynsyms,
	elf_link_renumber_local_hash_table_dynsyms, _bfd_elf_export_symbol,
	_bfd_elf_link_find_version_dependencies,
	_bfd_elf_link_assign_sym_version, _bfd_elf_adjust_dynamic_symbol,
	_bfd_elf_link_sec_merge_syms, elf_adjust_dynstr_offsets,
	elf_collect_hash_codes, elf_collect_gnu_hash_codes,
	elf_renumber_gnu_hash_syms, elf_gc_sweep_symbol,
	elf_gc_propagate_vtable_entries_used,
	elf_gc_smash_unused_vtentry_relocs, bfd_elf_gc_mark_dynamic_ref_symbol,
	elf_gc_allocate_got_offsets): Likewise.
	* elfnn-ia64.c (elfNN_ia64_global_dyn_info_free,
	elfNN_ia64_global_dyn_sym_thunk): Likewise.
	* elfxx-mips.c (mips_elf_check_symbols, mips_elf_output_extsym,
	mips_elf_sort_hash_table_f, allocate_dynrelocs): Likewise.
	* elfxx-sparc.c (allocate_dynrelocs, readonly_dynrelocs): Likewise.
	* i386linux.c (linux_tally_symbols): Likewise.
	* m68klinux.c (linux_tally_symbols): Likewise.
	* sparclinux.c (linux_tally_symbols): Likewise.
	* sunos.c (sunos_scan_dynamic_symbol): Likewise.
	* xcofflink.c (xcoff_post_gc_symbol): Likewise.

	* elflink.c (elf_link_output_extsym): Make it a bfd_hash_traverse
	function.  Update all callers.
	* aoutx.h (aout_link_write_other_symbol): Likewise.
	* pdp11.c (aout_link_write_other_symbol): Likewise.
	* cofflink.c (_bfd_coff_write_global_sym): Likewise.
	* ecoff.c (ecoff_link_write_external): Likewise.
	* xcofflink.c (xcoff_write_global_symbol): Likewise.
	* vms-alpha.c (alpha_vms_link_output_symbol): Likewise.  Handle
	warning symbols.
	* ecoff.c (ecoff_link_hash_traverse): Delete.
	* coff-ppc.c (ppc_bfd_coff_final_link): Use bfd_hash_traverse for
	_bfd_coff_write_global_sym.
	* libcoff-in.h (_bfd_coff_write_global_sym): Update prototype.
	* libcoff.h: Regenerate.
2011-06-13 00:59:15 +00:00
H.J. Lu 4b819e1f6e Properly warn relocation in readonly section in a shared object.
2011-06-01  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_size_dynamic_sections): Properly warn
	relocation in readonly section in a shared object.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.
2011-06-01 19:42:01 +00:00
Alan Modra 9d4057ee3b PR ld/12718
* elf32-i386.c (elf_i386_check_relocs): Ensure dynobj set before
	creating ifunc sections.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2011-05-01 12:04:10 +00:00
H.J. Lu b70321a200 Warn relocation in readonly section in a shared object.
2011-04-22  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_readonly_dynrelocs): Warn relocation
	in readonly section in a shared object.
	(elf_i386_size_dynamic_sections): Likewise.
	* elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise.
	(elf_x86_64_size_dynamic_sections): Likewise.
2011-04-23 01:16:31 +00:00
H.J. Lu aa71524235 Skip local IFUNC symbols when checking dynamic relocs in read-only sections.
bfd/

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

	PR ld/12694
	* elf32-i386.c (elf_i386_readonly_dynrelocs): Skip local IFUNC
	symbols.
	* elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise.

ld/testsuite/

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

	PR ld/12694
	* ld-ifunc/ifunc-14-i386.d: New.
	* ld-ifunc/ifunc-14-x86-64.d: Likewise.
	* ld-ifunc/ifunc-14a.s: Likewise.
	* ld-ifunc/ifunc-14b.s: Likewise.
2011-04-21 22:25:39 +00:00
H.J. Lu f6df62c820 Return false on dynamic symbol error.
2011-04-21  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Return false
	on dynamic symbol error.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
2011-04-21 21:16:51 +00:00
H.J. Lu 2a750708dc Fix the array access for BFD_RELOC_386_IRELATIVE.
2011-04-11  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_reloc_type_lookup): Fix the out of bound
	array access for BFD_RELOC_386_IRELATIVE.
2011-04-11 18:27:23 +00:00
Nick Clifton f64b2e8d60 PR 10549
* elf-bfd.h (has_ifunc_symbols): Renamed to has_gnu_symbols.
	(has_gnu_symbols): Renamed from has_ifunc_symbols.
	* elf.c (_bfd_elf_set_osabi): Use new has_gnu_symbols name.
	* elf32-arm.c (elf32_arm_add_symbol_hook): Set has_gnu_symbols
	also if STB_GNU_UNIQUE symbol binding was seen.
	* elf32-i386.c (elf_i386_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.

	* ld-unique: New directory.
	* ld-unique/unique.exp: New file: Run the UNIQUE tests.
	* ld-unique/unique.s: New test file.
	* ld-unique/unique_empty.s: Likewise.
	* ld-unique/unique_shared.s: Likewise.
2011-04-11 08:13:22 +00:00
H.J. Lu 9f973f2842 Update copyright year.
2011-04-09  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c: Update copyright year.
	* elf64-x86-64.c: Likewise.
2011-04-09 16:48:39 +00:00
H.J. Lu 62d7890874 Return relocation error on unsupported relocation.
2011-04-09  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_relocate_section): Return relocation
	error on unsupported relocation.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2011-04-09 15:37:57 +00:00
H.J. Lu 959b0961c9 Properly handle R_386_TLS_LDO_32 for PIE.
bfd/

2011-04-08  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12654
	* elf32-i386.c (elf_i386_relocate_section): Check !executable
	instead of shared for R_386_TLS_LDO_32.

ld/testsuite/

2011-04-08  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12654
	* ld-i386/i386.exp: Run tlspie2.

	* ld-i386/tlspie2.d: New.
	* ld-i386/tlspie2.s: Likewise.
2011-04-08 16:14:49 +00:00
Michael Snyder d59a60e937 2011-03-06 Michael Snyder <msnyder@vmware.com>
* elf32-i386.c (elf_i386_relocate_section): Document fall through.
2011-03-06 18:22:36 +00:00
H.J. Lu 3db2e7dda6 Handle STT_GNU_IFUNC symols when building shared library.
bfd/

2012-01-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12366
	PR ld/12371
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Properly
	handle symbols marked with regular reference, but not non-GOT
	reference when building shared library.

	* elf32-i386.c (elf_i386_gc_sweep_hook): Properly handle
	local and global STT_GNU_IFUNC symols when building shared
	library.
	* elf64-x86-64.c (elf_x86_64_gc_sweep_hook): Likewise.

ld/testsuite/

2012-01-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12366
	PR ld/12371
	* ld-ifunc/ifunc-10-i386.s: Add more tests.
	* ld-ifunc/ifunc-10-x86-64.s: Likewise.
	* ld-ifunc/ifunc-11-i386.s: Likewise.
	* ld-ifunc/ifunc-11-x86-64.s: Likewise.

	* ld-ifunc/ifunc-12-i386.d: New.
	* ld-ifunc/ifunc-12-i386.s: Likewise.
	* ld-ifunc/ifunc-12-x86-64.d: Likewise.
	* ld-ifunc/ifunc-12-x86-64.s: Likewise.
	* ld-ifunc/ifunc-13-i386.d: Likewise.
	* ld-ifunc/ifunc-13-x86-64.d: Likewise.
	* ld-ifunc/ifunc-13a-i386.s: Likewise.
	* ld-ifunc/ifunc-13a-x86-64.s: Likewise.
	* ld-ifunc/ifunc-13b-i386.s: Likewise.
	* ld-ifunc/ifunc-13b-x86-64.s: Likewise.
2011-01-06 18:45:05 +00:00
Rainer Orth 7dc98aeaf1 * elf-bfd.h (struct elf_backend_data): New member
static_tls_alignment.
	* elfxx-target.h (elf_backend_static_tls_alignment): Provide
	default.
	(elfNN_bed): Initialize static_tls_alignment.
	* elflink.c (bfd_elf_final_link): Don't round end of TLS section
	if static TLS has special alignment requirements.
	* elf32-i386.c (elf_i386_tpoff): Define bed, static_tls_size.
	Consider static_tls_alignment.
	(elf_backend_static_tls_alignment): Redefine for Solaris 2.
	Undef again for VxWorks.
	* elf64-x86-64.c (elf64_x86_64_tpoff):  Define bed,
	static_tls_size.
	Consider static_tls_alignment.
	(elf_backend_static_tls_alignment): Redefine for Solaris 2.
	Undef again for Intel L1OM.
2010-10-21 12:29:02 +00:00
H.J. Lu e28df02b6c Clear non_elf on ELF linker defined symbols.
2010-09-30  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11812
	* elf32-i386.c (elf_i386_size_dynamic_sections): Don't
	 allocate .got.plt section if there are no GOT nor PLT
	 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_.
	 * elf64-x86-64.c (elf64_x86_64_size_dynamic_sections): Li.kewise.

	* elflink.c (_bfd_elf_define_linkage_sym): Clear non_elf.
2010-10-01 04:28:04 +00:00
H.J. Lu ae95ffa628 Add target_id to elf_backend_data.
2010-08-25  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11944
	* elf-bfd.h (elf_backend_data): Add target_id.
	(bfd_elf_make_generic_object): Renamed to ...
	(bfd_elf_make_object): This.

	* elf.c (bfd_elf_make_generic_object): Removed.
	(bfd_elf_make_object): New.
	(bfd_elf_mkcorefile): Really treat it as an object file.

	* elf-m10300.c (ELF_TARGET_ID): New.
	* elf32-arm.c (ELF_TARGET_ID): Likewise.
	* elf32-bfin.c (ELF_TARGET_ID): Likewise.
	* elf32-cris.c (ELF_TARGET_ID): Likewise.
	* elf32-frv.c (ELF_TARGET_ID): Likewise.
	* elf32-i386.c (ELF_TARGET_ID): Likewise.
	* elf32-lm32.c (ELF_TARGET_ID): Likewise.
	* elf32-m32r.c (ELF_TARGET_ID): Likewise.
	* elf32-m68hc11.c (ELF_TARGET_ID): Likewise.
	* elf32-m68hc12.c (ELF_TARGET_ID): Likewise.
	* elf32-m68k.c (ELF_TARGET_ID): Likewise.
	* elf32-microblaze.c (ELF_TARGET_ID): Likewise.
	* elf32-ppc.c (ELF_TARGET_ID): Likewise.
	* elf32-s390.c (ELF_TARGET_ID): Likewise.
	* elf32-sh.c (ELF_TARGET_ID): Likewise.
	* elf32-sparc.c (ELF_TARGET_ID): Likewise.
	* elf32-spu.c (ELF_TARGET_ID): Likewise.
	* elf32-tic6x.c (ELF_TARGET_ID): Likewise.
	* elf32-xtensa.c (ELF_TARGET_ID): Likewise.
	* elf64-alpha.c (ELF_TARGET_ID): Likewise.
	* elf64-hppa.c (ELF_TARGET_ID): Likewise.
	* elf64-ppc.c (ELF_TARGET_ID): Likewise.
	* elf64-s390.c (ELF_TARGET_ID): Likewise.
	* elf64-x86-64.c (ELF_TARGET_ID): Likewise.
	* elfxx-ia64.c (ELF_TARGET_ID): Likewise.

	* elf32-hppa.c (elf32_hppa_mkobject): Removed.
	(bfd_elf32_mkobject): Likewise.
	(ELF_TARGET_ID): New.

	* elf32-mips.c (ELF_TARGET_ID): New.
	(bfd_elf32_mkobject): Removed.

	* elf64-mips.c (ELF_TARGET_ID): New.
	(bfd_elf64_mkobject): Removed.

	* elfn32-mips.c (ELF_TARGET_ID): New.
	(bfd_elf32_mkobject): Removed.

	* elfxx-mips.c (_bfd_mips_elf_mkobject): Removed.
	* elfxx-mips.h (_bfd_mips_elf_mkobject): Likewise.

	* elfxx-target.h (bfd_elfNN_mkobject): Default to
	bfd_elf_make_object.
	(ELF_TARGET_ID): New.  Default to GENERIC_ELF_DATA.
	(elfNN_bed): Initialize target_id.
2010-08-25 14:53:45 +00:00
Pedro Alves 261b8d0859 2010-08-18 Pedro Alves <pedro@codesourcery.com>
PR corefile/8210

	bfd/
	* bfd-in2.h: Regenerate.
	* corefile.c (bfd_core_file_pid): New.

	* targets.c (BFD_JUMP_TABLE_CORE): Add NAME##_core_file_pid.
	(struct bfd_target) <_core_file_pid>: New.

	* libbfd-in.h (_bfd_nocore_core_file_pid): Declare.
	* libbfd.c (_bfd_nocore_core_file_pid): New.

	* elf-bfd.h (bfd_elf32_core_file_pid, bfd_elf64_core_file_pid):
	Declare.
	* elfcode.h (elf_core_file_pid): New define.
	* elfcore.h (elf_core_file_pid): New function.

	* elf.c (elfcore_make_pid): Rewrite.
	(elfcore_grok_prstatus): Only set core_pid if not set yet.
	(elfcore_grok_prstatus) [!HAVE_PRSTATUS_T_PR_WHO]: Fallback to
	getting the lwpid from prstat.pr_pid.

	* elf64-x86-64.c (elf64_x86_64_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	(elf64_x86_64_grok_psinfo): Extract the the main process's PID,
	and store it in elf_tdata's core_pid field.
	* elf32-i386.c (elf_i386_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	(elf_i386_grok_psinfo): Extract the the main process's PID, and
	store it in elf_tdata's core_pid field.

	* elf32-am33lin.c (elf32_am33lin_grok_prstatus): Write the LWPID
	to elf_tdata's core_lwpid instead of to core_pid.
	* elf32-arm.c (elf32_arm_nabi_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-cris.c (cris_elf_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-frv.c (elf32_frv_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-hppa.c (elf32_hppa_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-mips.c (elf32_mips_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-ppc.c (ppc_elf_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-s390.c (elf_s390_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-score.c (s3_bfd_score_elf_grok_prstatus): Write the LWPID
	to elf_tdata's core_lwpid instead of to core_pid.
	* elf32-score7.c (s7_bfd_score_elf_grok_prstatus): Write the LWPID
	to elf_tdata's core_lwpid instead of to core_pid.
	* elf32-sh.c (elf32_shlin_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf32-xtensa.c (elf_xtensa_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf64-hppa.c (elf64_hppa_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf64-mips.c (elf64_mips_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elf64-ppc.c (ppc64_elf_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.
	* elfn32-mips.c (elf32_mips_grok_prstatus): Write the LWPID to
	elf_tdata's core_lwpid instead of to core_pid.

	* plugin.c (bfd_plugin_core_file_pid): New function.
	* aout-target.h (MY_core_file_pid): Define.
	* aout-tic30.c (MY_core_file_pid, MY_core_file_p): New defines.
	* coff-rs6000.c (coff_core_file_pid): New define.
	(rs6000coff_vec, pmac_xcoff_vec): Use BFD_JUMP_TABLE_CORE.
	* coff64-rs6000.c (coff_core_file_pid): New define.
	(rs6000coff64_vec): Use BFD_JUMP_TABLE_CORE.
	(xcoff64_core_file_pid): New define.
	(aix5coff64_vec): Use BFD_JUMP_TABLE_CORE.
	* mach-o-target.c (bfd_mach_o_core_file_pid): New define.
	* aix386-core.c (aix386_core_file_pid): New define.
	* hppabsd-core.c (hppabsd_core_core_file_pid): New define.
	* hpux-core.c (hpux_core_core_file_pid): New define.
	* irix-core.c (irix_core_core_file_pid): New define.
	* lynx-core.c (lynx_core_file_pid): New define.
	* osf-core.c (osf_core_core_file_pid): New define.
	* ptrace-core.c (ptrace_unix_core_file_pid): New define.
	* sco5-core.c (sco5_core_file_pid): New define.
	* xcoff-target.h (coff_core_file_pid): New define.
	* netbsd-core.c (netbsd_core_core_file_pid): New define.

gdb/
2010-08-18  Pedro Alves  <pedro@codesourcery.com>

	PR corefile/8210

	gdb/
	* corelow.c (add_to_thread_list): Don't use
	gdbarch_core_reg_section_encodes_pid.  Use bfd_core_file_pid.
	(get_core_register_section): Don't use
	gdbarch_core_reg_section_encodes_pid.

	* gdbarch.sh (core_reg_section_encodes_pid): Delete.
	* gdbarch.h, gdbarch.c: Regenerate.
	* amd64-sol2-tdep.c (amd64_sol2_init_abi): Don't set
	gdbarch_core_reg_section_encodes_pid.
	* i386-sol2-tdep.c (i386_sol2_init_abi): Ditto.
	* sparc-sol2-tdep.c (sparc32_sol2_init_abi): Ditto.
	* sparc64-sol2-tdep.c (sparc64_sol2_init_abi): Ditto.
2010-08-18 12:24:13 +00:00
H.J. Lu 56d4289c6c Check if .got.plt section is discarded before using it.
bfd/

2010-08-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11913
	* elf32-i386.c (elf_i386_finish_dynamic_sections): Check if
	 .got.plt section is discarded.
	 * elf64-x86-64.c (elf64_x86_64_finish_dynamic_sections): Likewise.

ld/testsuite/

2010-08-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11913
	* ld-i386/discarded1.d: New.
	* ld-i386/discarded1.s: Likewise.
	* ld-i386/discarded1.t: Likewise.
	* ld-x86-64/discarded1.d: Likewise.
	* ld-x86-64/discarded1.s: Likewise.
	* ld-x86-64/discarded1.t: Likewise.

	* ld-i386/i386.exp: Run discarded1.
	* ld-x86-64/x86-64.exp: Likewise.
2010-08-13 20:50:27 +00:00
H.J. Lu a7b16ceb92 Don't allocate .got.plt section if there are no GOT nor PLT entries.
bfd/

2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11812
	* elf32-i386.c (elf_i386_size_dynamic_sections): Don't
	 allocate .got.plt section if there are no GOT nor PLT
	 entries.
	 * elf64-x86-64.c (elf64_x86_64_size_dynamic_sections): Likewise.

ld/testsuite/

2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11812
	* ld-elf/exclude3b.d: Don't run on ia64-*-*.  Replace .got with
	.dynamic.

	* ld-elf/exclude3d.d: New.
	* ld-i386/nogot1.d: Likewise.
	* ld-i386/nogot1.s: Likewise.
	* ld-x86-64/nogot1.d: Likewise.
	* ld-x86-64/nogot1.s: Likewise.

	* ld-i386/i386.exp: Run nogot1.
	* ld-x86-64/x86-64.exp: Likewise.
2010-07-14 00:30:57 +00:00
H.J. Lu bb1cb422ae Support garbage collection against STT_GNU_IFUNC symbols.
bfd/

2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11791
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Support
	garbage collection against STT_GNU_IFUNC symbols.

	* elf32-i386.c (elf_i386_get_local_sym_hash): Don't set
	elf.plt.offset/elf.got.offset to -1.
	(elf_i386_tls_transition): Skip TLS transition for functions.
	(elf_i386_gc_sweep_hook): Support STT_GNU_IFUNC symbols.

	* elf64-x86-64.c (elf64_x86_64_get_local_sym_hash): Don't set
	elf.plt.offset/elf.got.offset to -1.
	(elf64_x86_64_tls_transition): Skip TLS transition for functions.
	(elf64_x86_64_gc_sweep_hook): Support STT_GNU_IFUNC symbols.

ld/testsuite/

2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11791
	* ld-ifunc/ifunc-10-i386.d: New.
	* ld-ifunc/ifunc-10-i386.s: Likewise.
	* ld-ifunc/ifunc-10-x86-64.d: Likewise.
	* ld-ifunc/ifunc-10-x86-64.s: Likewise.
	* ld-ifunc/ifunc-11-i386.d: Likewise.
	* ld-ifunc/ifunc-11-i386.s: Likewise.
	* ld-ifunc/ifunc-11-x86-64.d: Likewise.
	* ld-ifunc/ifunc-11-x86-64.s: Likewise.
2010-07-13 16:59:14 +00:00
H.J. Lu 9fff0c3957 Re-indent elf32-i386.c.
2010-07-12  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_check_relocs): Re-indent.
	(elf_i386_relocate_section): Likewise.
2010-07-12 21:13:24 +00:00
H.J. Lu 0672748ac0 Remove relocation against discarded sections for relocatable link.
bfd/

2010-04-30  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11542
	* elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): New.

	* elf32-i386.c (elf_i386_relocate_section): Use it.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.

ld/testsuite/

2010-04-30  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/11542
	* ld-elf/discard.ld: New.
	* ld-elf/discard1.d: Likewise.
	* ld-elf/discard1.s: Likewise.
	* ld-elf/discard2.d: Likewise.
	* ld-elf/discard2.s: Likewise.
	* ld-elf/discard3.d: Likewise.
2010-04-30 18:27:32 +00:00
Nick Clifton 3d540e936b bfd/ChangeLog
2010-04-09  Nick Clifton  <nickc@redhat.com>

        * aoutx.h (aout_link_input_bfd): Remove unused variable sym_count.
        * elf-eh-frame.c (_bfd_elf_eh_frame_section_offset): Remove unused
        variables htab and hdr_info and mark info parameter as unused.
        * elf.c (prep_headers): Remove unused variable i_phdrp.
        (_bfd_elf_write_object_contents): Remove unused variable i_ehdrp.
        * elf32-i386.c (elf_i386_relocate_section): Mark variabled warned
        as unused.
        * peXXigen.c (pe_print_reloc): Remove unused variable datasize.
        * verilog.c (verilog_write_section): Remove unused variable
        address.

binutils/ChangeLog
2010-04-09  Nick Clifton  <nickc@redhat.com>

        * dwarf.c (process_debug_info): Remove unused variable
        cu_abbrev_offset_ptr.
        (display_debug_lines_decoded): Remove unused variable prev_line.
        * elfedit.c (process_archive): Remove unused variable
        file_name_size.
        * ieee.c (ieee_start_compilation_unit): Remove unused variable
        nindx.
        (ieee_set_type): Remove unused variables info, targetindx and
        baseindx.
        * objdump.c (disassmble_byte): Remove unused variable done_dot.
        * rddbg.c (read_section_stabs_debugging_info): Remove unused
        variable other.
        * readelf.c (dump_section_as_strings): Remove unused variable
        addr.
        (process_archive): Remove unused variable file_name_size.
        * stabs.c (parse_stab_string): Mark desc parameter as unused.
        Remove unused variable lineno.
        (parse_stab_struct_type): Remove unused variable orig.
        (stab_demangle_type): Remove unused variables constp, volatilep
        and hold.

gas/ChangeLog
2010-04-09  Nick Clifton  <nickc@redhat.com>

        * as.c (create_obj_attrs_section): Remove unused variable addr.
        * listing.c (listing_listing): Remove unused variable message.
        * read.c: Remove unnecessary register type qualifiers.
        (s_mri): Only define/use old_flag variable if MRI_MODE_CHANGE is
        defined.

ld/ChangeLog
2010-04-09  Nick Clifton  <nickc@redhat.com>

        * ldlang.c (wild_sort): Remove unused variable section_name.

opcodes/ChangeLog
2010-04-09  Nick Clifton  <nickc@redhat.com>

        * i386-dis.c (print_insn): Remove unused variable op.
        (OP_sI): Remove unused variable mask.
2010-04-09 14:40:18 +00:00
Rainer Orth a6cc6b3bc4 ld:
* Makefile.am (ALL_EMULATIONS): Add eelf32_sparc_sol2.o,
	eelf_i386_sol2.o.
	(ALL_64_EMULATIONS): Add eelf_x86_64_sol2.o, eelf64_sparc_sol2.o.
	(eelf32_sparc_sol2.c): New rule.
	(eelf64_sparc_sol2.c): Likewise.
	(eelf_x86_64_sol2.c): Likewise.
	(eelf_i386_sol2.c): Likewise.
	* Makefile.in: Regenerate.
	* configure.tgt (i[3-7]86-*-solaris2*): Change targ_emul to
	elf_i386_sol2.
	Add elf_i386_ldso, elf_x86_64_sol2 to targ_extra_emuls.
	(x86_64-*-solaris2*): Change targ_emul to elf_x86_64_sol2.
	Add elf_x86_64, elf_i386_sol2, elf_i386 to targ_extra_emuls.
	(sparc-*-solaris2.[0-6]*): Change targ_emul to elf32_sparc_sol2.
	Add target_extra_emuls.
	(sparc-*-solaris2*): Change targ_emul to elf32_sparc_sol2.
	Add elf32_sparc, elf64_sparc_sol2 to targ_extra_emuls.
	(sparcv9-*-solaris2*): Change targ_emul to elf64_sparc_sol2.
	Add elf64_sparc, elf32_sparc_sol2 to target_extra_emuls.
	* emulparams/elf32_sparc_sol2.sh: New file.
	* emulparams/elf64_sparc_sol2.sh: New file.
	* emulparams/elf_i386_sol2.sh: New file.
	* emulparams/elf_x86_64_sol2.sh: New file.
	* emultempl/solaris2.em: New file.

	bfd:
	* elflink.c (bfd_elf_size_dynamic_sections): Don't emit base
	version twice.
	Skip it when constructing def.vd_next.

	* elf32-i386.c (TARGET_LITTLE_SYM): Redefine to
	bfd_elf32_i386_sol2_vec.
	(TARGET_LITTLE_NAME): Redefine to elf32-i386-sol2.
	(elf32_bed): Redefine to elf32_i386_sol2_bed.
	(elf_backend_want_plt_sym): Redefine to 1.

	* elf64-x86-64.c (TARGET_LITTLE_SYM): Redefine to
	bfd_elf64_x86_64_sol2_vec.
	(TARGET_LITTLE_NAME): Redefine to elf64-x86-64-sol2.
	(elf64_bed): Redefine to elf64_x86_64_sol2_bed.
	(elf_backend_want_plt_sym): Redefine to 1.

	* config.bfd (i[3-7]86-*-solaris2*): Set targ_defvec to
	bfd_elf32_i386_sol2_vec.
	Replace bfd_elf64_x86_64_vec by bfd_elf64_x86_64_sol2_vec in
	targ64_selvecs.
	(x86_64-*-solaris2*): Set targ_defvec to bfd_elf32_i386_sol2_vec.
	Replace bfd_elf64_x86_64_vec by bfd_elf64_x86_64_sol2_vec in
	targ_selvecs.

	* configure.in: Handle bfd_elf32_i386_sol2_vec,
	bfd_elf64_x86_64_sol2_vec.
	* configure: Regenerate.

	* targets.c (bfd_elf32_i386_sol2_vec): Declare.
	(bfd_elf64_x86_64_sol2_vec): Declare.
	(_bfd_target_vector): Add bfd_elf32_i386_sol2_vec,
	bfd_elf64_x86_64_sol2_vec.
2010-03-05 19:49:00 +00:00
H.J. Lu c16153aed7 Don't set ELFOSABI_LINUX in dynamic ifunc-using executable.
bfd/

2010-02-18  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_add_symbol_hook): Don't set
	has_ifunc_symbols if the symbol comes from a shared library.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf64_x86_64_add_symbol_hook): Likewise.

ld/testsuite/

2010-02-18  H.J. Lu  <hongjiu.lu@intel.com>

	* ld-ifunc/ifunc.exp: Expect System V OSABI in dynamic
	ifunc-using executable.
2010-02-19 05:07:50 +00:00
H.J. Lu 6bbec50578 Remove trailing white spaces.
2010-02-05  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c: Remove trailing white spaces.
	* elf64-x86-64.c: Likewise.
2010-02-05 14:58:11 +00:00
Nick Clifton 4dfe6ac6fe * elf-bfd.h (emum elf_object_id): Rename to elf_target_id. Add
entries for other architectures.
        (struct elf_link_hash_table): Add hash_table_id field.
        (elf_hash_table_id): New accessor macro.
        * elflink.c (_bfd_elf_link_hash_table_init): Add target_id
        parameter.
        * elf-m10300.c (elf32_mn10300_hash_table): Check table id before
        returning cast pointer.
        (elf32_mn10300_link_hash_table_create): Identify new table as
        containing MN10300 extensions.
        (mn10300_elf_relax_section): Check pointer returned by
        elf32_mn10300_hash_table.
        * elf32-arm.c: Likewise, except using ARM extensions.
        * elf32-avr.c: Likewise, except using AVR extensions.
        * elf32-bfin.c: Likewise, except using BFIN extensions.
        * elf32-cris.c: Likewise, except using CRIS extensions.
        * elf32-frv.c: Likewise, except using FRV extensions.
        * elf32-hppa.c: Likewise, except using HPPA32 extensions.
        * elf32-i386.c: Likewise, except using I386 extensions.
        * elf32-lm32.c: Likewise, except using LM32 extensions.
        * elf32-m32r.c: Likewise, except using M32RM extensions.
        * elf32-m68hc11.c: Likewise, except using M68HC11 extensions.
        * elf32-m68hc1x.c: Likewise, except using M68HC11 extensions.
        * elf32-m68hc1x.h: Likewise, except using M68HC11 extensions.
        * elf32-m68k.c: Likewise, except using M68K extensions.
        * elf32-microblaze.c: Likewise, except using MICROBLAZE extensions.
        * elf32-ppc.c: Likewise, except using PPC32 extensions.
        * elf32-s390.c: Likewise, except using S390 extensions.
        * elf32-sh.c: Likewise, except using SH extensions.
        * elf32-spu.c: Likewise, except using SPU extensions.
        * elf32-xtensa.c: Likewise, except using XTENSA extensions.
        * elf64-alpha.c: Likewise, except using ALPHA extensions.
        * elf64-hppa.c: Likewise, except using HPPA64 extensions.
        * elf64-ppc.c: Likewise, except using PPC64 extensions.
        * elf64-s390.c: Likewise, except using S390 extensions.
        * elf64-x86-64.c: Likewise, except using X86_64 extensions.
        * elfxx-ia64.c: Likewise, except using IA64 extensions.
        * elfxx-mips.c: Likewise, except using MIPS extensions.
        * elfxx-sparc.c: Likewise, except using SPARC extensions.
        * elfxx-sparc.h: Likewise, except using SPARC extensions.
        * elf32-cr16.c (struct elf32_cr16_link_hash_table): Delete
        redundant structure.
        (elf32_cr16_hash_table): Delete unused macro.
        (elf32_cr16_link_hash_traverse): Delete unused macro.
        * elf32-score.c: Likewise.
        * elf32-score7.c: Likewise.
        * elf32-vax.c: Likewise.
        * elf64-sh64.c: Likewise.

        * emultempl/alphaelf.em: Update value expected from elf_object_id.
        * emultempl/hppaelf.em: Likewise.
        * emultempl/mipself.em: Likewise.
        * emultempl/ppc32elf.em: Likewise.
        * emultempl/ppc64elf.em: Likewise.
2010-02-04 09:16:43 +00:00
Nick Clifton 91d6fa6a03 Add -Wshadow to the gcc command line options used when compiling the binutils.
Fix up all warnings generated by the addition of this switch.
2009-12-11 13:42:17 +00:00
H.J. Lu cd2b2c108e 2009-10-13 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/10763
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Declare plt
	earlier.
2009-10-13 16:37:39 +00:00
Nick Clifton a50b1753d4 Updated soruces in bfd/* to compile cleanly with -Wc++-compat.
* bfd/aoutx.h: Add casts.
        * bfd/archive.c: Add casts.
        * bfd/archive64.c: Add casts.
        * bfd/archures.c: Add casts.
        * bfd/bfd-in2.h: Regenerated.
        * bfd/bfd.c: Add casts. (enum bfd_direction): Move out to top
        level.
        * bfd/bfdio.c: Add casts.
        * bfd/binary.c: Add casts.
        * bfd/cache.c (cache_bseek,cache_bread_1,cache_bwrite): Updated
        parameter to use enum value instead of int.
        * bfd/coffcode.h: Add casts.
        * bfd/coffgen.c: Add casts.
        * bfd/cofflink.c: Add casts.
        * bfd/compress.c: Add casts.
        * bfd/dwarf1.c: Add casts.
        * bfd/dwarf2.c: Add casts. (struct dwarf2_debug): Rename member
        bfd to bfd_ptr. Update code to use new name.
        * bfd/elf-attrs.c: Add casts.
        * bfd/elf-bfd.h (elf_link_virtual_table_entry): Gives name to
        anonymous struct. (union gotplt_union, struct
        elf_link_virtual_table_entry): Move to top level.
        * bfd/elf-eh-frame.c: Add casts.
        * bfd/elf-strtab.c: Add casts.
        * bfd/elf.c: Add casts. (_bfd_elm_make_Section_from_phdr): Change
        argument name from typename to type_name.
        * bfd/elf32-i386.c: Add casts.
        * bfd/elf64-x86-64.c: Add casts.
        * bfd/elfcode.h: Add casts.
        * bfd/elfcore.h: Add casts.
        * bfd/elflink.c: Add casts.
        * bfd/format.c: Add casts.
        * bfd/hash.c: Add casts.
        * bfd/ihex.c: Add casts.
        * bfd/libaout.h (enum aout_subformat, enum aout_magic): Move to
        top level.
        * bfd/libbfd.c: Add casts.
        * bfd/linker.c: Add casts.
        * bfd/merge.c: Add casts.
        * bfd/opncls.c: Add casts.
        * bfd/peXXigen.c: Add casts.
        * bfd/peicode.h: Add casts.
        * bfd/reloc.c: Add casts.
        * bfd/section.c: Add casts.
        * bfd/simple.c: Add casts.
        * bfd/srec.c: Add casts.
        * bfd/stabs.c: Add casts.
        * bfd/syms.c: Add casts.
        * bfd/targets.c: Add casts.
        * bfd/tekhex.c: Add casts.
        * bfd/verilog.c: Add casts.
        * include/bfdlink.h (struct bfd_link_hash_common_entry): Move to
        top level.
2009-09-09 21:38:59 +00:00
Alan Modra aa820537ea update copyright dates 2009-09-02 07:25:43 +00:00
H.J. Lu 883c74100f 2009-08-30 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Revert the
	accidental checkin.
	* elf64-x86-64.c (elf64_x86_64_finish_dynamic_symbol): Likwise.
2009-08-30 18:31:53 +00:00
Nick Clifton d3ce72d070 Updated sources to avoid using the identifier name "new", which is a
keyword in c++.

        * bfd/aoutx.h (NAME (aout, make_empty_symbol)): Rename variable
        new to new_symbol.
        * bfd/coffgen.c (coff_make_empty_symbol)
        (coff_bfd_make_debug_symbol): Rename variable new to new_symbol.
        * bfd/cpu-ia64-opc.c (ext_reg, ins_imms_scaled): Rename variable
        new to new_insn.
        * bfd/doc/chew.c (newentry, add_intrinsic): Rename variable new to
        new_d.
        * bfd/ecoff.c (_bfd_ecoff_make_empty_symbol): Rename variable new
        to new_symbol.
        * bfd/elf32-m68k.c (elf_m68k_get_got_entry_type): Rename argument
        new to new_reloc.
        * bfd/hash.c (bfd_hash_lookup): Rename variable new to new_string.
        * bfd/ieee.c (ieee_make_empty_symbol): Rename variable new to
        new_symbol.
        * bfd/linker.c (bfd_new_link_order): Rename variable new to
        new_lo.
        * bfd/mach-o.c (bfd_mach_o_sizeof_headers): Rename variable new to
        symbol.
        * bfd/oasys.c (oasys_make_empty_symbol): Rename variable new to
        new_symbol_type.
        * bfd/pdp11.c (NAME (aout, make_empty_symbol)): Rename variable
        new to new_symbol_type.
        * bfd/plugin.c (bfd_plugin_make_empty_symbol): Rename variable new
        to new_symbol.
        * bfd/rs6000-core.c (CoreHdr, VmInfo): Rename union member new to
        new_dump.
        (read_hdr, rs6000coff_core_p)
        (rs6000coff_core_file_matches_executable_p)
        (rs6000coff_core_file_failing_command)
        (rs6000coff_core_file_failing_signal): Updated function to use new
        union member name.
        * bfd/som.c (som_make_empty_symbol): Rename variable new to
        new_symbol_type.
        * bfd/syms.c (_bfd_generic_make_empty_symbol): Rename variable new
        to new_symbol.
        * bfd/tekhex.c (first_phase, tekhex_make_empty_symbol): Rename
        variable new to new_symbol.
        * binutils/nlmconv.c (main): Rename variable new to new_name.
        * gas/config/tc-arm.c (insert_reg_alias): Rename variable new to
        new_reg.
        * gas/config/tc-dlx.c (parse_operand): Rename variable new to
        new_pos.
        * gas/config/tc-ia64.c (ia64_gen_real_reloc_type): Rename variable
        new to newr.
        * gas/config/tc-mcore.c (parse_exp, parse_imm): Rename variable
        new to new_pointer.
        * gas/config/tc-microblaze.c (parse_exp, parse_imm, check_got):
        Change name from new to new_pointer.
        * gas/config/tc-or32.c (parse_operand): Rename variable new to
        new_pointer.
        * gas/config/tc-pdp11.c (md_assemble): Rename variable new to
        new_pointer.
        * gas/config/tc-pj.c (alias): Change argument new to new_name.
        * gas/config/tc-score.c (s3_build_score_ops_hsh): Rename variable
        new to new_opcode. (s3_build_dependency_insn_hsh) Rename variable
        new to new_i2n. (s3_convert): Rename variables old and new to
        r_old and r_new.
        * gas/config/tc-score7.c (s7_build_score_ops_hsh): Rename variable
        new to new_opcode. (s7_build_dependency_insn_hsh): Rename variable
        new to new_i2d. (s7_b32_relax_to_b16, s7_convert_frag): Rename
        variables old and new to r_old and r_new.
        * gas/config/tc-sh.c (parse_exp): Rename variable new to
        new_pointer.
        * gas/config/tc-sh64.c (shmedia_parse_exp): Rename variable new to
        new_pointer.
        * gas/config/tc-tic4x.c (tic4x_operand_parse): Rename variable new
        to new_pointer.
        * gas/config/tc-z8k.c (parse_exp): Rename variable new to
        new_pointer.
        * gas/listing.c (listing_newline): Rename variable new to new_i.
        * ld/ldexp.c (exp_intop, exp_bigintop, exp_relop, exp_binop)
        (exp_trinop, exp_unop, exp_nameop, exp_assop): Rename variable new
        to new_e.
        * ld/ldfile.c (ldfile_add_library_path): Rename variable new to
        new_dirs. (ldfile_add_arch): Rename variable new to new_arch.
        * ld/ldlang.c (new_statement, lang_final, lang_add_wild)
        (lang_target, lang_add_fill, lang_add_data, lang_add_assignment)
        (lang_add_insert): Rename variable new to new_stmt. (new_afile):
        Added missing cast. (lang_memory_region_lookup): Rename variable
        new to new_region. (init_os): Rename variable new to
        new_userdata. (lang_add_section): Rename variable new to
        new_section. (ldlang_add_undef): Rename variable new to
        new_undef. (realsymbol): Rename variable new to new_name.
        * opcodes/z8kgen.c (internal, gas): Rename variable new to new_op.

        Updated sources to avoid using the identifier name "template",
        which is a keyword in c++.

        * bfd/elf32-arm.c (struct stub_def): Rename member template to
        template_sequence. (arm_build_one_stub,
        find_stub_size_and_template, arm_size_one_stub, arm_map_one_stub):
        Rename variable template to template_sequence.
        * bfd/elfxx-ia64.c (elfNN_ia64_relax_br, elfNN_ia64_relax_brl):
        Rename variable template to template_val.
        * gas/config/tc-arm.c (struct asm_cond, struct asm_psr, struct
        asm_barrier_opt): Change member template to
        template_name. (md_begin): Update code to reflect new member
        names.
        * gas/config/tc-i386.c (struct templates, struct _i386_insn)
        (match_template, cpu_flags_match, match_reg_size, match_mem_size)
        (operand_size_match, md_begin, i386_print_statistics, pi)
        (build_vex_prefix, md_assemble, parse_insn, optimize_imm)
        (optimize_disp): Updated code to use new names. (parse_insn):
        Added casts.
        * gas/config/tc-ia64.c (dot_template, emit_one_bundle): Updated
        code to use new names.
        * gas/config/tc-score.c (struct s3_asm_opcode): Renamed member
        template to template_name. (s3_parse_16_32_inst, s3_parse_48_inst,
        s3_do_macro_ldst_label, s3_build_score_ops_hsh): Update code to
        use new names.
        * gas/config/tc-score7.c (struct s7_asm_opcode): Renamed member
        template to template_name. (s7_parse_16_32_inst,
        s7_do_macro_ldst_label, s7_build_score_ops_hsh): Update code to
        use new names.
        * gas/config/tc-tic30.c (md_begin, struct tic30_insn)
        (md_assemble): Update code to use new names.
        * gas/config/tc-tic54x.c (struct _tic54x_insn, md_begin)
        (optimize_insn, tic54x_parse_insn, next_line_shows_parallel):
        Update code to use new names.
        * include/opcode/tic30.h (template): Rename type template to
        insn_template. Updated code to use new name.
        * include/opcode/tic54x.h (template): Rename type template to
        insn_template.
        * opcodes/cris-dis.c (bytes_to_skip): Update code to use new name.
        * opcodes/i386-dis.c (putop): Update code to use new name.
        * opcodes/i386-gen.c (process_i386_opcodes): Update code to use
        new name.
        * opcodes/i386-opc.h (struct template): Rename struct template to
        insn_template. Update code accordingly.
        * opcodes/i386-tbl.h (i386_optab): Update type to use new name.
        * opcodes/ia64-dis.c (print_insn_ia64): Rename variable template
        to template_val.
        * opcodes/tic30-dis.c (struct instruction, get_tic30_instruction):
        Update code to use new name.
        * opcodes/tic54x-dis.c (has_lkaddr, get_insn_size)
        (print_parallel_instruction, print_insn_tic54x, tic54x_get_insn):
        Update code to use new name.
        * opcodes/tic54x-opc.c (tic54x_unknown_opcode, tic54x_optab):
        Update type to new name.
2009-08-29 22:11:02 +00:00
H.J. Lu 1d85728fd7 2009-08-02 H.J. Lu <hongjiu.lu@intel.com>
Jakub Jelinek  <jakub@redhat.com>

	PR ld/6443
	* elf32-i386.c (elf_i386_tls_transition): Check executable
	instead of shared for TLS when building PIE.
	(elf_i386_check_relocs): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_relocate_section): Likewise.

	* elf64-x86-64.c (elf64_x86_64_tls_transition): Check executable
	instead of shared for TLS when building PIE.
	(elf64_x86_64_check_relocs): Likewise.
	(elf64_x86_64_allocate_dynrelocs): Likewise.
	(elf64_x86_64_relocate_section): Likewise.

ld/testsuite/

2009-08-02  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/6443
	* ld-i386/i386.exp: Run tlspie1.
	* ld-x86-64/x86-64.exp: tlspie1.

	* ld-i386/tlspie1.d: New.
	* ld-i386/tlspie1.s: Likewise.
	* ld-x86-64/tlspie1.d: Likewise.
	* ld-x86-64/tlspie1.s: Likewise.
2009-08-02 23:55:49 +00:00
H.J. Lu 1f85278f17 bfd/
2009-07-16  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_relocate_section): Don't get local
	STT_GNU_IFUNC symbol for relocatable link.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.

ld/testsuite/

2009-07-16  H.J. Lu  <hongjiu.lu@intel.com>

	* ld-ifunc/ifunc-5r-local-i386.d: New.
	* ld-ifunc/ifunc-5r-local-x86-64.d: Likewise.
2009-07-16 14:23:12 +00:00
Alan Modra 7ae26bc141 * elf-bfd.h (struct elf_link_hash_entry): Clarify ref_regular
and ref_regular_nonweak comment.
	* elflink.c (elf_link_output_extsym): Special case ifunc syms
	when def_regular, not ref_regular.
	(elf_link_add_object_symbols): Don't set needs_plt on ifunc syms,..
	* elf32-i386.c (elf_i386_check_relocs): ..set it here instead..
	* elf64-x86-64.c (elf64_x86_64_check_relocs): ..and here.
2009-07-10 10:04:20 +00:00
H.J. Lu 09a24cbf39 2009-06-19 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Properly check local
	symbol on error.
	* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
2009-06-20 00:43:21 +00:00
H.J. Lu 4c5448074d bfd/
2009-06-19  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_tls_transition): Add a parameter,
	r_symndx.  Report local symbol name on error.
	(elf_i386_check_relocs): Updated.  Report local symbol name on
	error.
	(elf_i386_gc_sweep_hook): Updated.
	(elf_i386_relocate_section): Likewise.

	* elf64-x86-64.c (elf64_x86_64_tls_transition): Add a parameter,
	r_symndx.  Report local symbol name on error.
	(elf64_x86_64_check_relocs): Updated.  Report local symbol name
	on error.
	(elf64_x86_64_gc_sweep_hook): Updated.
	(elf64_x86_64_relocate_section): Likewise.

ld/testsuite/

2009-06-19  H.J. Lu  <hongjiu.lu@intel.com>

	* ld-i386/i386.exp: Run tlsgd2.

	* ld-i386/tlsgd2.d: New.
	* ld-i386/tlsgd2.s: Likewise.

	* ld-x86-64/tlsgd3.d: Updated.
2009-06-19 16:00:33 +00:00
H.J. Lu c2e61a4e93 2009-06-18 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Remove isymbuf and use
	bfd_sym_from_r_symndx.
	* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
2009-06-18 15:49:39 +00:00
Alan Modra 87d72d41b0 * elf-bfd.h (struct sym_sec_cache): Delete.
(struct sym_cache): New.
	(bfd_section_from_r_symndx): Delete prototype.
	(bfd_sym_from_r_symndx): Define prototype.
	* elf.c (bfd_section_from_r_symndx): Delete, replace with..
	(bfd_sym_from_r_symndx): ..new function.
	* elf32-arm.c: Update all uses of struct sym_sec_cache and
	bfd_section_from_r_symndx to new struct and function.
	* elf32-bfin.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68hc1x.h: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-sparc.h: Likewise.
2009-06-18 14:18:29 +00:00
H.J. Lu 14aae7232b 2009-06-18 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Cache or free isymbuf.
	* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
2009-06-18 12:49:41 +00:00
H.J. Lu e03a8ed803 2009-06-17 H.J. Lu <hongjiu.lu@intel.com>
* elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): New.
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Likewise.
	* elf32-i386.c (elf_i386_allocate_dynrelocs): Use it.
	* elf64-x86-64.c (elf64_x86_64_allocate_dynrelocs): Likewise.

2009-06-17  H.J. Lu  <hongjiu.lu@intel.com>

	* elf-bfd.h (_bfd_elf_create_ifunc_dyn_reloc): New.
	* elf-ifunc.c (_bfd_elf_create_ifunc_dyn_reloc): Likewise.
	* elf32-i386.c (elf_i386_check_relocs): Use it.
	* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.

2009-06-17  H.J. Lu  <hongjiu.lu@intel.com>

	* elf-bfd.h (elf_dyn_relocs): New.

	* elf32-i386.c (elf_i386_dyn_relocs): Removed.
	(elf_i386_link_hash_entry): Replace elf_i386_dyn_relocs with
	elf_dyn_relocs.
	(elf_i386_copy_indirect_symbol): Likewise.
	(elf_i386_check_relocs): Likewise.
	(elf_i386_gc_sweep_hook): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_readonly_dynrelocs): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.

	* elf64-x86-64.c (elf64_x86_64_dyn_relocs): Removed.
	(elf64_x86_64_link_hash_entry): Replace elf64_x86_64_dyn_relocs
	with elf_dyn_relocs.
	(elf64_x86_64_copy_indirect_symbol): Updated.
	(elf64_x86_64_check_relocs): Likewise.
	(elf64_x86_64_gc_sweep_hook): Likewise.
	(elf64_x86_64_adjust_dynamic_symbol): Likewise.
	(elf64_x86_64_allocate_dynrelocs): Likewise.
	(elf64_x86_64_readonly_dynrelocs): Likewise.
	(elf64_x86_64_size_dynamic_sections): Likewise.
2009-06-18 00:45:14 +00:00
H.J. Lu d2149d727f 2009-06-16 H.J. Lu <hongjiu.lu@intel.com>
* elf-bfd.h (ELF_LOCAL_SYMBOL_HASH): New.

	* elf32-i386.c (elf_i386_local_hash): Removed.
	(elf_i386_local_htab_hash): Use ELF_LOCAL_SYMBOL_HASH.
	(elf_i386_get_local_sym_hash): Likewise.

	* elf64-x86-64.c (elf64_x86_64_local_hash): Removed.
	(elf64_x86_64_local_htab_hash): Use ELF_LOCAL_SYMBOL_HASH.
	(elf64_x86_64_get_local_sym_hash): Likewise.
	* elfxx-ia64.c (elfNN_ia64_local_htab_hash): Likewise.
	(get_local_sym_hash): Likewise.
2009-06-16 17:45:08 +00:00
H.J. Lu 6de2ae4a2a 2009-06-16 H.J. Lu <hongjiu.lu@intel.com>
* configure.in (elf): Add elf-ifunc.lo.

	* configure: Regenerated.
	* Makefile.in: Likewise.

	* elf-bfd.h (elf_link_hash_table): Add sgot, sgotplt,
	srelgot, splt, srelplt, igotplt, iplt, irelplt and irelifunc.

	* elf32-i386.c (elf_i386_link_hash_table): Remove sgot,
	sgotplt, srelgot, splt, srelplt, igotplt, iplt, irelplt and
	irelifunc.
	(elf_i386_link_hash_table_create): Likewise.
	(elf_i386_create_dynamic_sections): Likewise.
	(elf_i386_check_relocs): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(elf_i386_finish_dynamic_sections): Likewise.
	(elf_i386_create_got_section): Removed.

	* elf64-x86-64.c (elf64_x86_64_link_hash_table): Remove sgot,
	sgotplt, srelgot, splt, srelplt, igotplt, iplt, irelplt and
	irelifunc.
	(elf64_x86_64_compute_jump_table_size): Updated.
	(elf64_x86_64_link_hash_table_create): Likewise.
	(elf64_x86_64_create_dynamic_sections): Likewise.
	(elf64_x86_64_check_relocs): Likewise.
	(elf64_x86_64_allocate_dynrelocs): Likewise.
	(elf64_x86_64_size_dynamic_sections): Likewise.
	(elf64_x86_64_relocate_section): Likewise.
	(elf64_x86_64_finish_dynamic_symbol): Likewise.
	(elf64_x86_64_finish_dynamic_sections): Likewise.
	(elf64_x86_64_create_got_section): Removed.

	* elflink.c (_bfd_elf_create_got_section): Use log_file_align
	for pointer alignment.  Set up section pointers.
	(_bfd_elf_create_dynamic_sections): Likewise.
	(_bfd_elf_create_ifunc_sections): Moved to ...
	* elf-ifunc.c: Here.  New.

	* Makefile.am (BFD32_BACKENDS): Add elf-ifunc.lo.
	(BFD32_BACKENDS_CFILES): Add elf-ifunc.c.
	Run "make dep-am".
2009-06-16 13:41:10 +00:00
H.J. Lu 188dbb07f1 2009-06-15 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_allocate_dynrelocs): Update comments.
	* elf64-x86-64.c (elf64_x86_64_allocate_dynrelocs): Likewise.
2009-06-15 18:25:20 +00:00
H.J. Lu 048cbda441 2009-06-15 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Reformat.
	* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
2009-06-15 17:23:43 +00:00
H.J. Lu eba077f227 2009-06-15 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_allocate_dynrelocs): Fix a typo.
	* elf64-x86-64.c (elf64_x86_64_allocate_dynrelocs): Likewise.
2009-06-15 13:12:33 +00:00
H.J. Lu b80ee1aa0e 2009-06-14 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c: Remove duplicated comments.
2009-06-15 00:37:08 +00:00
H.J. Lu 44c4ea11d3 bfd/
2009-06-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10270
	* elf32-i386.c (elf_i386_allocate_dynrelocs): Disallow
	dynamic IFUNC pointer in non-shared object.  Use .got.plt
	for IFUNC definition in PIE.
	(elf_i386_allocate_dynrelocs): Resolve IFUNC definition in
	PIE locally.

	* elf64-x86-64.c (elf64_x86_64_allocate_dynrelocs): Disallow
	dynamic IFUNC pointer in non-shared object.  Use .got.plt
	for IFUNC definition in PIE.
	(elf64_x86_64_relocate_section): Resolve IFUNC definition in
	PIE locally.

ld/testsuite/

2009-06-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10270
	* ld-ifunc/ifunc-9-x86.d: New.
	* ld-ifunc/ifunc-9-x86.s: Likewise.
2009-06-14 22:13:30 +00:00
H.J. Lu 637fa7af7f 2009-06-13 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_relocate_section): Properly report
	local symbol for unhandled relocation against STT_GNU_IFUNC
	symbol.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.
2009-06-14 05:53:55 +00:00
H.J. Lu 8b7e29925c 2009-06-13 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Properly report
	local symbol for unhandled relocation against STT_GNU_IFUNC
	symbol.
	* elf64-x86-64.c (elf64_x86_64_check_relocs):  Likewise.
2009-06-14 05:45:09 +00:00
H.J. Lu c25bc9fc0d bfd/
2009-06-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10269
	* elf32-i386.c: Include "objalloc.h" and "hashtab.h".
	(elf_i386_link_hash_table): Add loc_hash_table and
	loc_hash_memory.
	(elf_i386_local_hash): New.
	(elf_i386_local_htab_hash): Likewise.
	(elf_i386_local_htab_eq): Likewise.
	(elf_i386_get_local_sym_hash): Likewise.
	(elf_i386_link_hash_table_free): Likewise.
	(elf_i386_allocate_local_dynrelocs): Likewise.
	(elf_i386_finish_local_dynamic_symbol): Likewise.
	(bfd_elf64_bfd_link_hash_table_free): Likewise.
	(elf_i386_link_hash_table_create): Create loc_hash_table and
	loc_hash_memory.
	(elf_i386_check_relocs): Handle local STT_GNU_IFUNC symbols.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_sections): Likewise.
	(elf_i386_finish_dynamic_symbol): Check _DYNAMIC only if sym
	isn't NULL.

	* elf64-x86-64.c: Include "objalloc.h" and "hashtab.h".
	(elf64_x86_64_link_hash_table): Add loc_hash_table and
	loc_hash_memory.
	(elf64_x86_64_local_hash): New.
	(elf64_x86_64_local_htab_hash): Likewise.
	(elf64_x86_64_local_htab_eq): Likewise.
	(elf64_x86_64_get_local_sym_hash): Likewise.
	(elf64_x86_64_link_hash_table_free): Likewise.
	(elf64_x86_64_allocate_local_dynrelocs): Likewise.
	(elf64_x86_64_finish_local_dynamic_symbol): Likewise.
	(bfd_elf64_bfd_link_hash_table_free): Likewise.
	(elf64_x86_64_link_hash_table_create): Create loc_hash_table
	and loc_hash_memory.
	(elf64_x86_64_check_relocs): Handle local STT_GNU_IFUNC
	symbols.
	(elf64_x86_64_size_dynamic_sections): Likewise.
	(elf64_x86_64_relocate_section): Likewise.
	(elf64_x86_64_finish_dynamic_sections): Likewise.
	(elf64_x86_64_finish_dynamic_symbol): Check _DYNAMIC only if
	sym isn't NULL.

gas/

2009-06-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10269
	* config/tc-i386.c (md_apply_fix): Use TC_FORCE_RELOCATION
	instead of generic_force_reloc.

	* config/tc-i386.h (TC_FORCE_RELOCATION): New.

ld/testsuite/

2009-06-13  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10269
	*: ld-ifunc/ifunc-1-local-x86.d: New.
	*: ld-ifunc/ifunc-1-local-x86.s: Likewise.
	*: ld-ifunc/ifunc-2-local-i386.d: Likewise.
	*: ld-ifunc/ifunc-2-local-i386.s: Likewise.
	*: ld-ifunc/ifunc-2-local-x86-64.d: Likewise.
	*: ld-ifunc/ifunc-2-local-x86-64.s: Likewise.
	*: ld-ifunc/ifunc-4-local-x86.d: Likewise.
	*: ld-ifunc/ifunc-4-local-x86.s: Likewise.
	*: ld-ifunc/ifunc-5-local-i386.s: Likewise.
	*: ld-ifunc/ifunc-5-local-x86-64.s: Likewise.
	*: ld-ifunc/ifunc-5a-local-i386.d: Likewise.
	*: ld-ifunc/ifunc-5a-local-x86-64.d: Likewise.
	*: ld-ifunc/ifunc-5b-local-i386.d: Likewise.
	*: ld-ifunc/ifunc-5b-local-x86-64.d: Likewise.
2009-06-14 01:39:46 +00:00
H.J. Lu 2a81c24ab1 bfd/
2009-06-06  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_link_hash_table): Add irelifunc.
	(elf_i386_link_hash_table_create): Initialize irelifunc.
	(elf_i386_check_relocs): Updated.  Set up irelifunc for
	shared objects.
	(elf_i386_allocate_dynrelocs): Use irelifunc for dynamic
	relocation for non-GOT reference of STT_GNU_IFUNC symbol in
	shared objects.
	(elf_i386_relocate_section): Likewise.

	* elf64-x86-64.c (elf64_x86_64_link_hash_table): Add irelifunc.
	(elf64_x86_64_link_hash_table_create): Initialize irelifunc.
	(elf64_x86_64_check_relocs): Updated.  Set up irelifunc for
	shared objects.
	(elf64_x86_64_allocate_dynrelocs): Use irelifunc for dynamic
	relocation for non-GOT reference of STT_GNU_IFUNC symbol in
	shared objects.
	(elf64_x86_64_relocate_section): Likewise.

	* elf-bfd.h (_bfd_elf_create_static_ifunc_sections): Renamed to
	...
	(_bfd_elf_create_ifunc_sections): This.

	* elflink.c (_bfd_elf_create_static_ifunc_sections): Renamd to
	...
	(_bfd_elf_create_ifunc_sections): This.  Create .rel[a].ifunc
	for shared objects.

ld/

2009-06-06  H.J. Lu  <hongjiu.lu@intel.com>

	* scripttempl/elf.sc: Add .rel.ifunc and .rela.ifunc.
2009-06-06 22:39:25 +00:00
H.J. Lu 710ab2870f 2009-06-06 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Make room for dynamic
	relocation for R_386_32 against STT_GNU_IFUNC symbol when
	building shared object.  Check info->executable instead of
	!info->shared when setting non_got_ref.
	(elf_i386_allocate_dynrelocs): Allocate dynamic relocation
	for non-GOT reference of STT_GNU_IFUNC symbol in shared
	object. Allocate GOT relocation agsinst STT_GNU_IFUNC
	symbol if needed.
	(elf_i386_relocate_section): Output dynamic relocation for
	R_386_32 against STT_GNU_IFUNC symbol to get the real
	function address when building shared object.
	(elf_i386_finish_dynamic_symbol): Output R_386_GLOB_DAT
	relocation for STT_GNU_IFUNC symbol in shared object.

	* elf64-x86-64.c (elf64_x86_64_check_relocs): Make room for
	dynamic relocation for R_X86_64_64 against STT_GNU_IFUNC
	symbol when building shared object.  Check info->executable
	instead of !info->shared when setting non_got_ref.
	(elf64_x86_64_allocate_dynrelocs): Allocate dynamic relocation
	for non-GOT reference of STT_GNU_IFUNC symbol in shared
	library. Allocate GOT relocation agsinst STT_GNU_IFUNC symbol
	if needed.
	(elf64_x86_64_relocate_section): Output dynamic relocation
	for R_X86_64_64 against STT_GNU_IFUNC symbol to get the real
	function address when building shared object.
	(elf64_x86_64_finish_dynamic_symbol): Output R_X86_64_GLOB_DAT
	relocation for STT_GNU_IFUNC symbol in shared object.
2009-06-06 11:48:11 +00:00
H.J. Lu 2e75bb3530 2009-06-03 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_allocate_dynrelocs): Remove check of
	h->plt.refcount > 0 on STT_GNU_IFUNC symbol.
	* elf64-x86-64.c (elf64_x86_64_allocate_dynrelocs): Likewise.
2009-06-03 16:58:12 +00:00
H.J. Lu 0018b0a3d5 2009-06-03 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_allocate_dynrelocs): Allocate
	GOT entry for STT_GNU_IFUNC symbol with pointer equality.
	(elf_i386_relocate_section): Adjust R_386_GOT32 relocation
	against STT_GNU_IFUNC symbols for static executables.
	(elf_i386_finish_dynamic_symbol): Load GOT entry with
	PLT entry for STT_GNU_IFUNC symbol with pointer equality.

	* elf64-x86-64.c (elf64_x86_64_allocate_dynrelocs): Allocate
	GOT entry for STT_GNU_IFUNC symbol with pointer equality.
	(elf64_x86_64_finish_dynamic_symbol): Load GOT entry with
	PLT entry for STT_GNU_IFUNC symbol with pointer equality.
2009-06-03 12:35:18 +00:00
H.J. Lu 7afd84dc1f bfd/
2009-06-02  H.J. Lu  <hongjiu.lu@intel.com>

	* elf32-i386.c (elf_i386_check_relocs): Increment
	got.refcount for R_386_GOT32/R_386_GOTOFF relocations
	against STT_GNU_IFUNC symbol.
	(elf_i386_allocate_dynrelocs): Set got.refcount to 0 if
	local STT_GNU_IFUNC definition is used.
	(elf_i386_relocate_section): Handle got.offset != -1 for
	R_386_GOT32/R_386_GOTOFF relocations against STT_GNU_IFUNC
	symbol.

	* elf64-x86-64.c (elf64_x86_64_check_relocs): Increment
	got.refcount for R_X86_64_GOTPCREL/R_X86_64_GOTPCREL64
	relocations against STT_GNU_IFUNC symbol.
	(elf64_x86_64_allocate_dynrelocs): Set got.refcount to 0 if
	local STT_GNU_IFUNC definition is used.
	(elf64_x86_64_relocate_section): Handle got.offset != -1
	for R_X86_64_GOTPCREL/R_X86_64_GOTPCREL64 relocations against
	STT_GNU_IFUNC symbol.

ld/testsuite/

2009-06-02  H.J. Lu  <hongjiu.lu@intel.com>

	* ld-ifunc/ifunc-5-i386.d: Renamed to ...
	* ld-ifunc/ifunc-5a-i386.d: This.

	* ld-ifunc/ifunc-5-x86-64.d: Renamed to ...
	* ld-ifunc/ifunc-5a-x86-64.d: This.

	* ld-ifunc/ifunc-5b-i386.d: New.
	* ld-ifunc/ifunc-5b-x86-64.d: Likewise.
	* ld-ifunc/ifunc-6a-i386.d: Likewise.
	* ld-ifunc/ifunc-6a-x86-64.d: Likewise.
	* ld-ifunc/ifunc-6b-i386.d: Likewise.
	* ld-ifunc/ifunc-6b-x86-64.d: Likewise.
	* ld-ifunc/ifunc-6-i386.s: Likewise.
	* ld-ifunc/ifunc-6-x86-64.s: Likewise.
	* ld-ifunc/ifunc-7a-i386.d: Likewise.
	* ld-ifunc/ifunc-7a-x86-64.d: Likewise.
	* ld-ifunc/ifunc-7b-i386.d: Likewise.
	* ld-ifunc/ifunc-7b-x86-64.d: Likewise.
	* ld-ifunc/ifunc-7-i386.s: Likewise.
	* ld-ifunc/ifunc-7-x86-64.s: Likewise.
2009-06-02 17:31:42 +00:00
H.J. Lu cbe950e9fe bfd/
2009-06-01  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10205
	* elf32-i386.c (elf_howto_table): Add R_386_IRELATIVE.
	(elf_i386_reloc_type_lookup): Likewise.
	(R_386_tls): Removed.
	(R_386_irelative): New.
	(R_386_vt_offset): Updated.
	(elf_i386_rtype_to_howto): Likewise.
	(elf_i386_link_hash_table): Add igotplt, iplt and irelplt.
	(elf_i386_link_hash_table_create): Initialize igotplt,
	iplt and irelplt.
	(elf_i386_check_relocs): Handle STT_GNU_IFUNC symbol first.
	(elf_i386_adjust_dynamic_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_size_dynamic_sections): Set up .iplt and .igot.plt
	sections.
	(elf_i386_finish_dynamic_symbol): When building a static
	executable, use .iplt, .igot.plt and .rel.iplt sections for
	STT_GNU_IFUNC symbols.  Generate R_386_IRELATIVE relocation for
	locally defined STT_GNU_IFUNC symbol.

	* elf64-x86-64.c (x86_64_elf_howto): Add R_X86_64_IRELATIVE.
	(x86_64_reloc_map): Likewise.
	(R_X86_64_standard): Updated.
	(elf64_x86_64_link_hash_table): Add igotplt, iplt and irelplt.
	(elf64_x86_64_link_hash_table_create): Initialize igotplt,
	iplt and irelplt.
	(elf64_x86_64_check_relocs): Handle STT_GNU_IFUNC symbol first.
	(elf64_x86_64_adjust_dynamic_symbol): Likewise.
	(elf64_x86_64_allocate_dynrelocs): Likewise.
	(elf64_x86_64_relocate_section): Likewise.
	(elf64_x86_64_size_dynamic_sections): Set up .iplt and .igot.plt
	sections.
	(elf64_x86_64_finish_dynamic_symbol): When building a static
	executable, use .iplt, .igot.plt and .rela.iplt sections for
	STT_GNU_IFUNC symbols.  Generate R_X86_64_IRELATIVE relocation
	for locally defined STT_GNU_IFUNC symbol.

	* reloc.c (BFD_RELOC_386_IRELATIVE): New.
	(BFD_RELOC_X86_64_IRELATIVE): Likewise.

	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

include/elf/

2009-06-01  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10205
	* i386.h (R_386_IRELATIVE): New.
	* x86-64.h (R_X86_64_IRELATIVE): Likewise.

ld/testsuite/

2009-06-01  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10205
	* ld-ifunc/ifunc.exp (contains_irelative_reloc): New.
	Use it on executable and shared library.
	Run *.d.

	* ld-ifunc/lib.c: Add a hidden alias, __GI_library_func2, for
	library_func2.
	(library_func): New.

	* ld-ifunc/ifunc-1-x86.d: New.
	* ld-ifunc/ifunc-1-x86.s: Likewise.
	* ld-ifunc/ifunc-2-i386.d: Likewise.
	* ld-ifunc/ifunc-2-i386.s: Likewise.
	* ld-ifunc/ifunc-2-x86-64.d: Likewise.
	* ld-ifunc/ifunc-2-x86-64.s: Likewise.
	* ld-ifunc/ifunc-3a-x86.d: Likewise.
	* ld-ifunc/ifunc-3b-x86.d: Likewise.
	* ld-ifunc/ifunc-3-x86.s: Likewise.
	* ld-ifunc/ifunc-4-x86.d: Likewise.
	* ld-ifunc/ifunc-4-x86.s: Likewise.
	* ld-ifunc/ifunc-5-i386.d: Likewise.
	* ld-ifunc/ifunc-5-i386.s: Likewise.
	* ld-ifunc/ifunc-5-x86-64.d: Likewise.
	* ld-ifunc/ifunc-5-x86-64.s: Likewise.
2009-06-01 13:11:52 +00:00
H.J. Lu eb4ff4d67f 2009-05-29 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (link_hash_newfunc): Add elf_i386_ prefix.
	(create_got_section): Likewise.
	(allocate_dynrelocs): Likewise.
	(readonly_dynrelocs): Likewise.
	(set_tls_module_base): Likewise.
	(dtpoff_base): Likewise.
	(tpoff): Likewise.
	(elf_i386_link_hash_table_create): Updated.
	(elf_i386_create_dynamic_sections): Likewise.
	(elf_i386_check_relocs): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.

	* elf64-x86-64.c (link_hash_newfunc): Add elf64_x86_64_ prefix.
	(create_got_section): Likewise.
	(allocate_dynrelocs): Likewise.
	(readonly_dynrelocs): Likewise.
	(set_tls_module_base): Likewise.
	(dtpoff_base): Likewise.
	(tpoff): Likewise.
	(elf64_x86_64_link_hash_table_create): Updated.
	(elf64_x86_64_create_dynamic_sections): Likewise.
	(elf64_x86_64_check_relocs): Likewise.
	(elf64_x86_64_size_dynamic_sections): Likewise.
	(elf64_x86_64_relocate_section): Likewise.
2009-05-29 18:30:30 +00:00
H.J. Lu 68d7e96a43 2009-05-26 H.J. Lu <hongjiu.lu@intel.com>
* elf-bfd.h (_bfd_elf_is_ifunc_symbol): New.

	* elf32-i386.c (is_indirect_symbol): Renamed to ...
	* elflink.c (_bfd_elf_is_ifunc_symbol): This.

	* elf32-i386.c (allocate_dynrelocs): Updated.
	(elf_i386_relocate_section): Likewise.
	* elf64-x86-64.c (allocate_dynrelocs): Likewise.
	(elf64_x86_64_relocate_section): Likewise.

	* elf64-x86-64.c (is_indirect_symbol): Removed.
2009-05-26 22:18:22 +00:00
Nick Clifton d8045f234d include/elf
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * common.h (STT_GNU_IFUNC): Define.

elfcpp
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * (enum STT): Add STT_GNU_IFUNC.

gas
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * config/obj-elf.c (obj_elf_type): Add support for a
        gnu_indirect_function type.
        * config/tc-i386.c (tc_i386_fix_adjustable): Do not adjust fixups
        against indirect function symbols.
        * doc/as.texinfo (.type): Document the support for the
        gnu_indirect_function symbol type.
        * NEWS: Mention the new feature.

gas/testsuite
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * gas/elf/elf.exp: Extend type test to include an ifunc symbol.
        Provide an alternative test for targets which do not support ifunc
        symbols.
        (type.s): Add entry for an ifunc symbol.
        (type.e): Add ifunc entry to expected symbol dump.
        (section2.e-armelf): Add  entry for ifunc symbol.
        (type-noifunc.s): New file.
        (type-noifunc.e): New file.

bfd/
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * elf-bfd.h (struct bfd_elf_section_data): Add indirect_relocs
        section pointer.
        (struct elf_obj_data): Add has_ifunc_symbols boolean.
        * elf.c (swap_out_syms): Convert BSF_GNU_INDIRECT_FUNCTION flags
        into a STT_GNU_IFUNC symbol type.
        (_bfd_elf_is_function_type): Accept STT_GNU_IFUNC as a function
        type.
        (_bfd_elf_set_osabi): Set the osasbi field to ELFOSABI_LINUX if
        the binary contains ifunc symbols.
        * elfcode.h (elf_slurp_symbol_table): Translate the STT_GNU_IFUNC
        symbol type into a BSF_GNU_INDIRECT_FUNCTION flag.
        * elf32-i386.c (is_indirect_function): New function.
        (elf_i386_check_relocs): Create an ifunc output section.
        (allocate_dynrelocs): Create dynamic relocs in the ifunc output
        section if necessary.
        (elf_i386_relocate_section): Emit a reloc against an ifunc symbol
        if necessary.
        (elf_i386_add_symbol_hook): New function. Set the
        has_ifunc_symbols field of the elf_obj_data structure if an ifunc
        symbol is encountered.
        (elf_backend_post_process_headers): Define.
        (elf_backend_add_symbol_hook): Define.
        (elf_i386_post_process_headers): Rename to
        elf_i388_fbsd_post_process_headers.
        * elf64-x86_64.c (IS_X86_64_PCREL_TYPE): New macro.
        (is_indirect_function): New function.
        (elf64_x86_64_check_relocs): Create an ifunc output section.
        (allocate_dynrelocs): Create dynamic relocs in the ifunc output
        section if necessary.
        (elf64_x86_64_relocate_section): Emit a reloc against an ifunc
        symbol if necessary.
        (elf_i386_add_symbol_hook): Set the has_ifunc_symbols field of the
        elf_obj_data structure if an ifunc symbol is encountered.
        (elf_backend_post_process_headers): Define.
        * elflink.c (_bfd_elf_adjust_dynamic_symbol): Always create a PLT
        if we have ifunc symbols to handle.
        (get_ifunc_reloc_section_name): New function.  Computes the name
        for an ifunc section.
        (_bfd_elf_make_ifunc_reloc_section): New function.  Creates a
        section to hold ifunc relocs.
        * syms.c (BSF_GNU_INDIRECT_FUNCTION): Define.
        (bfd_print_symbol_vandf): Handle ifunc symbols.
        (bfd_decode_symclass): Likewise.
        * bfd-in2.h: Regenerate.

binutils
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * readelf.c (dump_relocations): Display a relocation against an
        ifunc symbol as if it were a function invocation.
        (get_symbol_type): Handle STT_GNU_IFUNC.

ld
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * NEWS: Mention support for IFUNC symbols.

ld/testsuite
2009-04-30  Nick Clifton  <nickc@redhat.com>

        * ld-ifunc: New directory.
        * ld-ifunc/ifunc.exp: New file: Run the IFUNC tests.
        * ld-ifunc/prog.c: New file.
        * ld-ifunc/lib.c: New file.
2009-04-30 15:47:13 +00:00
H.J. Lu c4fb387b7c 2009-03-12 H.J. Lu <hongjiu.lu@intel.com>
PR ld/9938
	* elf32-i386.c (elf_i386_check_tls_transition): Use strncmp
	to check ___tls_get_addr.

	* elf64-x86-64.c (elf64_x86_64_check_tls_transition): Use
	strncmp to check __tls_get_addr.
2009-03-12 17:13:41 +00:00
H.J. Lu 09e8c3bf89 2009-03-11 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_tls_transition): Fix a typo in
	comments.
2009-03-11 16:42:23 +00:00
Nick Clifton 0f88be7a13 Remove STT_IFUNC support. 2008-12-23 09:01:51 +00:00
Nick Clifton e7c3341679 include/elf/
* common.h (STT_IFUNC): Define.
elfcpp/
            * elfcpp.h (enum STT): Add STT_IFUNC.
bfd/
            * syms.c (struct bfd_symbol): Add new flag BSF_INDIRECT_FUNCTION.
            Remove redundant flag BFD_FORT_COMM_DEFAULT_VALUE.  Renumber flags
            to remove gaps.
            (bfd_print_symbol_vandf): Return 'i' for BSF_INDIRECT_FUNCTION.
            (bfd_decode_symclass): Likewise.
            * elf.c (swap_out_syms): Translate BSF_INDIRECT_FUNCTION into
            STT_IFUNC.
            (elf_find_function): Treat STT_IFUNC in the same way as STT_FUNC.
            (_bfd_elf_is_function_type): Likewise.
            * elf32-arm.c (arm_elf_find_function): Likewise.
            (elf32_arm_adjust_dynamic_symbol): Likewise.
            (elf32_arm_swap_symbol_in): Likewise.
            (elf32_arm_additional_program_headers): Likewise.
            * elf32-i386.c (is_indirect_symbol): New function.
            (elf_i386_check_relocs): Also generate dynamic relocs for
            relocations against STT_IFUNC symbols.
            (allocate_dynrelocs): Likewise.
            (elf_i386_relocate_section): Likewise.
            * elf64-x86-64.c (is_indirect_symbol): New function.
            (elf64_x86_64_check_relocs): Also generate dynamic relocs for
            relocations against STT_IFUNC symbols.
            (allocate_dynrelocs): Likewise.
            (elf64_x86_64_relocate_section): Likewise.
            * elfcode.h (elf_slurp_symbol_table): Translate STT_IFUNC into
            BSF_INDIRECT_FUNCTION.
            * elflink.c (_bfd_elf_adjust_dynamic_reloc_section): Add support
            for STT_IFUNC symbols.
            (get_ifunc_reloc_section_name): New function.
            (_bfd_elf_make_ifunc_reloc_section): New function.
            * elf-bfd.h (struct bfd_elf_section_data): Add indirect_relocs field.
            * bfd-in2.h: Regenerate.
gas/
            * config/obj-elf.c (obj_elf_type): Add support for STT_IFUNC type.
            * doc/as.texinfo: Document new feature.
            * NEWS: Mention new feature.
gas/testsuite/
            * gas/elf/type.s: Add test of STT_IFUNC symbol type.
            * gas/elf/type.e: Update expected disassembly.
            * gas/elf/elf.exp: Update grep of symbol types.
ld/
            * NEWS: Mention new feature.
            * pe-dll.c (process_def_file): Replace use of redundant
            BFD_FORT_COMM_DEFAULT_VALUE with 0.
            * scripttempl/elf.sc: Add .rel.ifunc.dyn and .rela.ifunc.dyn
            sections.
ld/testsuite/
            * ld-mips-elf/reloc-1-n32.d: Updated expected output for reloc
            descriptions.
            * ld-mips-elf/reloc-1-n64.d: Likewise.
            * ld-i386/ifunc.d: New test.
            * ld-i386/ifunc.s: Source file for the new test.
            * ld-i386/i386.exp: Run the new test.
2008-12-03 14:51:00 +00:00
Nick Clifton 83bac4b010 * elflink.c (is_reloc_section): New function. Returns true if the
given name matches the name of the reloc-containing section
        associated with the given section.
        (get_dynamic_reloc_section_name): New function.  Computes the name
        of the section that contains the dynamic relocs associated with
        the given section.
        (_bfd_elf_get_dynamic_reloc_section): New function.  Returns a
        pointer to the section containing the dynamic relocs associated
        with the given section.
        (_bfd_elf_make_dynamic_reloc_section): New function.  Creates a
        section to contain the dynamic relocs associated with a given
        section.
        * elf-bfd.h: Prototype the new functions.
        * elf-m10300.c (mn10300_elf_check_relocs): Use new functions.
        (mn10300_elf_final_link_relocs): Likewise.
        * elf32-arm.c (reloc_section_p): Delete - replaced by new
        functions.
        (elf32_arm_final_link_relocate): Use new functions.
        (elf32_arm_check_relocs): Likewise.
        * elf32-cris.c (cris_elf_relocate_section): Likewise.
        (elf_cris_check_relocs): Likewise.
        * elf32-hppa.c (elf32_hppa_check_relocs): Likewise.
        * elf32-i370.c (i370_elf_check_relocs): Likewise.
        (i370_elf_relocate_section): Likewise.
        * elf32-i386.c (elf_i386_check_relocs): Likewise.
        * elf32-m32r.c (m32r_elf_relocate_section): Likewise.
        (m32r_elf_check_relocs): Likewise.
        * elf32-m68k.c (elf_m68k_check_relocs): Likewise.
        * elf32_ppc.c (ppc_elf_check_relocs): Likewise.
        (ppc_elf_relocate_section): Likewise.
        * elf32-s390.c (elf_s390_check_relocs): Likewise.
        * elf32-sh.c (sh_elf_relocate_section): Likewise.
        (sh_elf_check_relocs): Likewise.
        * elf32-vax.c (elf_vax_check_relocs): Likewise.
        (elf_vax_relocate_section): Likewise.
        * elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
        * elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
        * elf64-s390.c (elf_s390_check_relocs): Likewise.
        * elf64-sh64.c (sh_elf64_relocate_section): Likewise.
        * elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
        * elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
        * elf32-bfin.c (bfin_check_relocs): Remove redundant local
        variable 'sreloc'.
        (bfin_relocate_section): Likewise.
        * elf32-v850.c (v850_elf_check_relocs): Likewise.
2008-11-25 13:03:56 +00:00