Commit Graph

444 Commits

Author SHA1 Message Date
Alan Modra 5474d94f03 dynrelro section for read-only dynamic symbols copied into executable
Variables defined in shared libraries are copied into an executable's
.bss section when code in the executable is non-PIC and thus would
require dynamic text relocations to access the variable directly in
the shared library.  Recent x86 toolchains also copy variables into
the executable to gain a small speed improvement.

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

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

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

	* elf-bfd.h (struct elf_link_hash_table): Add sdynbss and srelbss.
	* elflink.c (_bfd_elf_create_dynamic_sections): Set them.  Create
	.rel.bss/.rela.bss for executables, both PIE and non-PIE.
	* elf32-arc.c (struct elf_arc_link_hash_table): Delete srelbss.
	Use ELF hash table var throughout.
	* elf32-arm.c (struct elf32_arm_link_hash_table): Delete sdynbss
	and srelbss.  Use ELF hash table vars throughout.
	* elf32-hppa.c (struct elf32_hppa_link_hash_table): Likewise.
	* elf32-i386.c (struct elf_i386_link_hash_table): Likewise.
	* elf32-metag.c (struct elf_metag_link_hash_table): Likewise.
	* elf32-microblaze.c (struct elf32_mb_link_hash_table): Likewise.
	* elf32-nios2.c (struct elf32_nios2_link_hash_table): Likewise.
	* elf32-or1k.c (struct elf_or1k_link_hash_table): Likewise.
	* elf32-ppc.c (struct ppc_elf_link_hash_table): Likewise.
	* elf32-s390.c (struct elf_s390_link_hash_table): Likewise.
	* elf32-tic6x.c (struct elf32_tic6x_link_hash_table): Likewise.
	* elf32-tilepro.c (struct tilepro_elf_link_hash_table): Likewise.
	* elf64-ppc.c (struct ppc_link_hash_table): Likewise.
	* elf64-s390.c (struct elf_s390_link_hash_table): Likewise.
	* elf64-x86-64.c (struct elf_x86_64_link_hash_table): Likewise.
	* elfnn-aarch64.c (struct elf_aarch64_link_hash_table): Likewise.
	* elfnn-riscv.c (struct riscv_elf_link_hash_table): Likewise.
	* elfxx-mips.c (struct mips_elf_link_hash_table): Likewise.
	* elfxx-sparc.h (struct _bfd_sparc_elf_link_hash_table): Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c (struct tilegx_elf_link_hash_table): Likewise.

	* elf32-arc.c (arc_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf32-microblaze.c (microblaze_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf32-or1k.c (or1k_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf32-s390.c (elf_s390_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf64-ppc.c (ppc64_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf64-s390.c (elf_s390_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.

	* elf32-tilepro.c (tilepro_elf_create_dynamic_sections): Remove
	extraneous tests.
	* elfnn-aarch64.c (elfNN_aarch64_create_dynamic_sections): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_create_dynamic_sections): Likewise.
	* elfxx-tilegx.c (tilegx_elf_create_dynamic_sections): Likewise.

	* elf32-i386.c (elf_i386_create_dynamic_sections): Don't create
	".rel.bss" for executables.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Don't create
	".rela.bss" for executables.
	* elf32-nios2.c (nios2_elf32_create_dynamic_sections): Don't
	ignore return status from _bfd_elf_create_dynamic_sections.
2016-12-26 13:42:20 +10:30
Nick Clifton 1a9ccd70f9 Fix the linker so that it will not silently generate ELF binaries with invalid program headers. Fix readelf to report such invalid binaries.
PR ld/20815
bfd	* elf.c (elf_modify_segment_map): Allow empty LOAD segments if
	they contain the program headers.
	(_bfd_elf_map_sections_to_segments): If the linker created the
	PHDR segment then always attempt to include it in a LOAD segment.
	(assign_file_positions_for_non_load_sections): Allow LOAD segments
	to overlap PHDR segments.
	(phdr_sorter): New function.  Sorts program headers.
	(assign_file_positions_except_relocs): Sort the program headers
	before writing them out.  Issue an error if the PHDR segment is
	not covered by a LOAD segment, unless the backend allows it.
	* elf-bfd.h (struct elf_backend_data): Add
	elf_backend_allow_non_load_phdr.
	* elfxx-target.h (elf_backend_allow_non_load_phdr): Provide
	default definition that returns FALSE.
	(elfNN_bed): Initialise the elf_backend_allow_non_load_phdr
	field.
	* elf64-hppa.c (elf64_hppa_allow_non_load_phdr): New function.
	Returns TRUE.
	(elf_backend_allow_non_load_phdr): Define.
	* elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Do not
	place the interpreter string into the .interp section if the
	nointerp flag is set in the link info structure.
	* elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
	* elf32-score7.c (score_elf_final_link_relocate): Allow for the
	_gp symbol not being part of the output.

binutils* readelf.c (process_program_headers): Check PT_LOAD and PT_PHDR
	segments for validity.

ld	* ld.texinfo: Note that PT_TLS can be used as a segment type.
	* testsuite/ld-discard/discard.ld: Add space for program headers.
	* testsuite/ld-elf/flags1.ld: Likewise.
	* testsuite/ld-elf/maxpage3.t: Likewise.
	* testsuite/ld-elf/noload-1.t: Likewise.
	* testsuite/ld-elf/orphan.ld: Likewise.
	* testsuite/ld-elf/overlay.t: Likewise.
	* testsuite/ld-elf/pr14052.t: Likewise.
	* testsuite/ld-elf/pr19539.t: Likewise.
	* testsuite/ld-elf/provide-hidden-1.ld: Likewise.
	* testsuite/ld-elf/provide-hidden-s.ld: Likewise.
	* testsuite/ld-elf/weak-dyn-1.ld: Likewise.
	* testsuite/ld-i386/pr19539.t: Likewise.
	* testsuite/ld-scripts/defined.t: Likewise.
	* testsuite/ld-scripts/defined6.t: Likewise.
	* testsuite/ld-scripts/dynamic-sections.t: Likewise.
	* testsuite/ld-scripts/empty-aligned.t: Likewise.
	* testsuite/ld-scripts/provide-2.t: Likewise.
	* testsuite/ld-scripts/provide-4.t: Likewise.
	* testsuite/ld-vax-elf/plt-local.ld: Likewise.
	* testsuite/ld-x86-64/pr19539.t: Likewise.
	* testsuite/ld-elf/ehdr_start-missing.d: Do not initialise the
	dynamic linker.
	* testsuite/ld-elf/ehdr_start-weak.d: Likewise.
	* testsuite/ld-elf/elf.exp (pr14170, pr17068): Likewise.
	* testsuite/ld-elf/loadaddr1.d: Update expected readelf output.
	* testsuite/ld-elf/noload-2.d: Likewise.
	* testsuite/ld-powerpc/vxworks2.sd: Likewise.
	* testsuite/ld-scripts/phdrs3a.d: Likewise.
	* testsuite/ld-scripts/size-2.d: Likewise.
	* testsuite/ld-elf/group.ld: Add program headers.
	* testsuite/ld-elf/overlay.d: Skip for SPU.
	* testsuite/ld-elf/flags1.d: Skip for RX.
	* testsuite/ld-elf/pr19162.d: Skip for HPPA64.
	* testsuite/ld-elf/pr19539.d: Skip for ALPHA.
	* testsuite/ld-scripts/empty-orphan.t: Update program headers.
	* testsuite/ld-scripts/size-2.t: Likewise.
2016-11-23 11:10:39 +00:00
Alan Modra 64f52338e9 elf_backend_dtrel_excludes_plt
Now that all targets creating .rel.plt/.rela.plt use the ELF hash
table shortcut srelplt, the generic ELF code can set up DT_RELSZ/
DT_RELASZ and DT_REL/DT_RELA for targets that don't want PLT relocs
included in those tags.

	* elf-bfd.h (struct elf_backend_data): Add dtrel_excludes_plt.
	* elfxx-target.h (elf_backend_dtrel_excludes_plt): Define.
	(elfNN_bed): Init new field.
	* elflink.c (bfd_elf_final_link): Add and use htab variable.  Handle
	dtrel_excludes_plt.
	* elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_sections): Delete
	DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-arc.c (elf_arc_finish_dynamic_sections): Delete DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-arm.c (elf32_arm_finish_dynamic_sections): Delete code
	subtracting off plt relocs from DT_RELSZ, DT_RELASZ.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-cr16.c (_bfd_cr16_elf_finish_dynamic_sections): Delete
	DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-cris.c (elf_cris_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Delete DT_RELASZ
	and DT_RELA code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-i386.c (elf_i386_finish_dynamic_sections): Delete DT_RELSZ
	and DT_REL code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-lm32.c (lm32_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-m32r.c (m32r_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-m68k.c (elf_m68k_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-metag.c (elf_metag_finish_dynamic_sections): Delete DT_RELASZ
	and DT_RELA code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-microblaze.c (microblaze_elf_finish_dynamic_sections): Delete
	DT_RELASZ and DT_RELA code.  Use ELF htab shortcuts for other
	dynamic sections.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-mips.c (elf_backend_dtrel_excludes_plt): Define.
	* elf32-nds32.c (nds32_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-or1k.c (or1k_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-ppc.c (ppc_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-sh.c (sh_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-sparc.c (elf_backend_dtrel_excludes_plt): Define.
	* elf32-vax.c (elf_vax_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-alpha.c (elf64_alpha_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Delete DT_RELASZ
	and DT_RELA code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-sh64.c (sh64_elf64_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections): Delete
	DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elfnn-ia64.c (elfNN_ia64_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections): Delete
	DT_RELASZ code.
	* elfxx-sparc.c (sparc_finish_dyn): Delete DT_RELASZ code.
2016-11-23 15:43:25 +10:30
Nick Clifton e23eba971d Add support for RISC-V architecture.
bfd	* Makefile.am: Add entries for riscv32-elf and riscv64-elf.
	* config.bdf: Likewise.
	* configure.ac: Likewise.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* archures.c: Add bfd_riscv_arch.
	* reloc.c: Add riscv relocs.
	* targets.c: Add riscv_elf32_vec and riscv_elf64_vec.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elf-bfd.h: Add RISCV_ELF_DATA to enum elf_target_id.
	* elfnn-riscv.c: New file.
	* elfxx-riscv.c: New file.
	* elfxx-riscv.h: New file.

binutils* readelf.c (guess_is_rela): Add EM_RISCV.
	(get_machine_name): Likewise.
	(dump_relocations): Add support for riscv relocations.
	(get_machine_flags): Add support for riscv flags.
	(is_32bit_abs_reloc): Add R_RISCV_32.
	(is_64bit_abs_reloc): Add R_RISCV_64.
	(is_none_reloc): Add R_RISCV_NONE.
	* testsuite/binutils-all/objdump.exp (cpus_expected): Add riscv.
	Expect the debug_ranges test to fail.

gas	* Makefile.am: Add riscv files.
	* Makefile.in: Regenerate.
	* NEWS: Mention the support for this architecture.
	* configure.in: Define a default architecture.
	* configure: Regenerate.
	* configure.tgt: Add entries for riscv.
	* doc/as.texinfo: Likewise.
	* testsuite/gas/all/gas.exp: Expect the redef tests to fail.
	* testsuite/gas/elf/elf.exp: Expect the groupauto tests to fail.
	* config/tc-riscv.c: New file.
	* config/tc-riscv.h: New file.
	* doc/c-riscv.texi: New file.
	* testsuite/gas/riscv: New directory.
	* testsuite/gas/riscv/riscv.exp: New file.
	* testsuite/gas/riscv/t_insns.d: New file.
	* testsuite/gas/riscv/t_insns.s: New file.

ld	* Makefile.am: Add riscv files.
	* Makefile.in: Regenerate.
	* NEWS: Mention the support for this target.
	* configure.tgt: Add riscv entries.
	* emulparams/elf32lriscv-defs.sh: New file.
	* emulparams/elf32lriscv.sh: New file.
	* emulparams/elf64lriscv-defs.sh: New file.
	* emulparams/elf64lriscv.sh: New file.
	* emultempl/riscvelf.em: New file.

opcodes	* configure.ac: Add entry for bfd_riscv_arch.
	* configure: Regenerate.
	* disassemble.c (disassembler): Add support for riscv.
	(disassembler_usage): Likewise.
	* riscv-dis.c: New file.
	* riscv-opc.c: New file.

include	* dis-asm.h: Add prototypes for print_insn_riscv and
	print_riscv_disassembler_options.
	* elf/riscv.h: New file.
	* opcode/riscv-opc.h: New file.
	* opcode/riscv.h: New file.
2016-11-01 16:45:57 +00:00
Alan Modra 50e03d47b7 Pass link_info to _bfd_merge_private_bfd_data
Most BFD linker functions take a bfd_link_info param, which reinforces
the fact that they are linker functions and allow access to linker
callbacks, eg. einfo for printing errors.  I was going to use einfo
for --fatal-warnings support before I decided a better way was the
patch commit 4519d071.

bfd/
	* targets.c (bfd_target <_bfd_merge_private_bfd_data>): Replace
	obfd param with struct bfd_link_info param.  Update all callers.
	* linker.c (bfd_merge_private_bfd_data): Likewise.
	(_bfd_generic_verify_endian_match): Likewise.
	* aoutf1.h (sunos_merge_private_bfd_data): Likewise.
	* coff-arm.c (coff_arm_merge_private_bfd_data): Likewise.
	* elf-attrs.c (_bfd_elf_merge_object_attributes): Likewise.
	* elf-bfd.h (_bfd_elf_ppc_merge_fp_attributes): Likewise.
	(_bfd_elf_merge_object_attributes): Likewise.
	* elf-m10300.c (_bfd_mn10300_elf_merge_private_bfd_data): Likewise.
	* elf-s390-common.c (elf_s390_merge_obj_attributes): Likewise.
	* elf32-arc.c (arc_elf_merge_private_bfd_data): Likewise.
	* elf32-arm.c (elf32_arm_merge_eabi_attributes): Likewise.
	(elf32_arm_merge_private_bfd_data): Likewise.
	* elf32-bfin.c (elf32_bfin_merge_private_bfd_data): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_merge_private_bfd_data): Likewise.
	* elf32-cris.c (cris_elf_merge_private_bfd_data): Likewise.
	* elf32-frv.c (frv_elf_merge_private_bfd_data): Likewise.
	* elf32-h8300.c (elf32_h8_merge_private_bfd_data): Likewise.
	* elf32-i370.c (i370_elf_merge_private_bfd_data): Likewise.
	* elf32-iq2000.c (iq2000_elf_merge_private_bfd_data): Likewise.
	* elf32-m32c.c (m32c_elf_merge_private_bfd_data): Likewise.
	* elf32-m32r.c (m32r_elf_merge_private_bfd_data): Likewise.
	* elf32-m68hc1x.c (_bfd_m68hc11_elf_merge_private_bfd_data): Likewise.
	* elf32-m68hc1x.h (_bfd_m68hc11_elf_merge_private_bfd_data): Likewise.
	* elf32-m68k.c (elf32_m68k_merge_private_bfd_data): Likewise.
	* elf32-mcore.c (mcore_elf_merge_private_bfd_data): Likewise.
	* elf32-mep.c (mep_elf_merge_private_bfd_data): Likewise.
	* elf32-msp430.c (elf32_msp430_merge_mspabi_attributes): Likewise.
	(elf32_msp430_merge_private_bfd_data): Likewise.
	* elf32-mt.c (mt_elf_merge_private_bfd_data): Likewise.
	* elf32-nds32.c (nds32_elf_merge_private_bfd_data): Likewise.
	* elf32-nios2.c (nios2_elf32_merge_private_bfd_data): Likewise.
	* elf32-or1k.c (elf32_or1k_merge_private_bfd_data): Likewise.
	* elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): Likewise.
	(ppc_elf_merge_obj_attributes): Likewise.
	(ppc_elf_merge_private_bfd_data): Likewise.
	* elf32-rl78.c (rl78_elf_merge_private_bfd_data): Likewise.
	* elf32-rx.c (rx_elf_merge_private_bfd_data): Likewise.
	* elf32-s390.c (elf32_s390_merge_private_bfd_data): Likewise.
	* elf32-score.c (s3_elf32_score_merge_private_bfd_data): Likewise.
	(elf32_score_merge_private_bfd_data): Likewise.
	* elf32-score.h (s7_elf32_score_merge_private_bfd_data): Likewise.
	* elf32-score7.c (s7_elf32_score_merge_private_bfd_data): Likewise.
	* elf32-sh.c (sh_merge_bfd_arch, sh_elf_merge_private_data): Likewise.
	* elf32-sh64.c (sh64_elf_merge_private_data): Likewise.
	* elf32-sparc.c (elf32_sparc_merge_private_bfd_data): Likewise.
	* elf32-tic6x.c (elf32_tic6x_merge_attributes): Likewise.
	(elf32_tic6x_merge_private_bfd_data): Likewise.
	* elf32-v850.c (v850_elf_merge_private_bfd_data): Likewise.
	* elf32-vax.c (elf32_vax_merge_private_bfd_data): Likewise.
	* elf32-visium.c (visium_elf_merge_private_bfd_data): Likewise.
	* elf32-xtensa.c (elf_xtensa_merge_private_bfd_data): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_merge_private_bfd_data): Likewise.
	* elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Likewise.
	* elf64-s390.c (elf64_s390_merge_private_bfd_data): Likewise.
	* elf64-sh64.c (sh_elf64_merge_private_data): Likewise.
	* elf64-sparc.c (elf64_sparc_merge_private_bfd_data): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_merge_private_bfd_data): Likewise.
	* elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): Likewise.
	* elfxx-mips.c (mips_elf_merge_obj_e_flags): Likewise.
	(mips_elf_merge_obj_attributes): Likewise.
	(_bfd_mips_elf_merge_private_bfd_data): Likewise.
	* elfxx-mips.h (_bfd_mips_elf_merge_private_bfd_data): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_merge_private_bfd_data): Likewise.
	* elfxx-sparc.h (_bfd_sparc_elf_merge_private_bfd_data): Likewise.
	* elfxx-target.h (bfd_elfNN_bfd_merge_private_bfd_data): Likewise.
	* elfxx-tilegx.c (_bfd_tilegx_elf_merge_private_bfd_data): Likewise.
	* elfxx-tilegx.h (_bfd_tilegx_elf_merge_private_bfd_data): Likewise.
	* libbfd-in.h (_bfd_generic_bfd_merge_private_bfd_data): Likewise.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	* ldlang.c (lang_check): Update bfd_merge_private_bfd_data call.
2016-10-07 11:24:41 +10:30
Alan Modra 52d45da3f2 Make bfd_error_handler_type like vprintf
It was like printf, which means you can't use bfd_set_error_handler to
hook in a function to do something and then call the original handler.

The patch also deletes some unused functions and makes pointers local.

bfd/
	* bfd-in.h: Include stdarg.h.
	* bfd.c (bfd_error_handler_type): Make like vprintf.
	(_bfd_error_internal): Rename from _bfd_error_handler.  Make static.
	(error_handler_internal): New function, split out from..
	(_bfd_default_error_handler): ..here.  Rename to _bfd_error_handler.
	(bfd_set_error_handler): Update.
	(bfd_get_error_handler, bfd_get_assert_handler): Delete.
	(_bfd_assert_handler): Make static.
	* coffgen.c (null_error_handler): Update params.
	* elf-bfd.h (struct elf_backend_data <link_order_error_handler>):
	Don't use bfd_error_handler_type.
	* elf64-mmix.c (mmix_dump_bpo_gregs): Likewise.
	* elfxx-target.h (elf_backend_link_order_error_handler): Default
	to _bfd_error_handler.
	* libbfd-in.h (_bfd_default_error_handler): Don't declare.
	(bfd_assert_handler_type): Likewise.
	(_bfd_error_handler): Update.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	* ldlang.c (ignore_bfd_errors): Update params.
2016-09-30 11:38:39 +09:30
Akihiko Odaki 9eaff86138 Fix seg-fault in the linker introduced by the previous delta.
PR ld/20636
	* elf-bfd.h (struct elf_backend_data): Delete
	elf_backend_count_output_relocs callback and add
	elf_backend_update_relocs.
	* elf32-arm.c (elf32_arm_count_output_relocs): Deleted.
	(emit_relocs): Deleted.
	(elf32_arm_emit_relocs): Deleted.
	(elf_backend_emit_relocs): Updated not to use the old functions.
	(elf32_arm_update_relocs): New function.
	(elf_backend_update_relocs): New define.
	* elflink.c (bfd_elf_final_link): Add additional_reloc_count to the
	relocation count. Call elf_backend_emit_relocs.
	(_bfd_elf_size_reloc_section): Do not call
	elf_backend_count_output_relocs.
	* elfxx-target.h (elf_backend_count_output_relocs): Deleted.
	(elf_backend_update_relocs): New define.
2016-09-28 11:50:41 +01:00
Alan Modra 005d79fd61 PowerPC .gnu.attributes
This patch extends Tag_GNU_Power_ABI_FP to cover long double ABIs,
makes the assembler warn about undefined tag values, and removes
similar warnings from the linker.  I think it is better to not
warn in the linker about undefined tag values as future extensions to
the tags then won't result in likely bogus warnings.  This is
consistent with the fact that an older linker won't warn on an
entirely new tag.

include/
	* elf/ppc.h (Tag_GNU_Power_ABI_FP): Comment.
bfd/
	* elf-bfd.h (_bfd_elf_ppc_merge_fp_attributes): Declare.
	* elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): New function.
	(ppc_elf_merge_obj_attributes): Use it.  Don't copy first file
	attributes, merge them.  Don't warn about undefined tag bits,
	or copy unknown values to output.
	* elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Call
	_bfd_elf_ppc_merge_fp_attributes.
binutils/
	* readelf.c (display_power_gnu_attribute): Catch truncated section
	for all powerpc attributes.  Display long double ABI.  Don't
	capitalize words, except for names.  Show known bits of tag values
	when some unknown bits are present.  Whitespace fixes.
gas/
	* config/tc-ppc.c (ppc_elf_gnu_attribute): New function.
	(md_pseudo_table <ELF>): Handle "gnu_attribute".
ld/
	* testsuite/ld-powerpc/attr-gnu-4-4.s: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-14.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-24.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-34.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-41.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-32.d: Adjust expected warning.
	* testsuite/ld-powerpc/attr-gnu-8-23.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-01.d: Adjust expected output.
	* testsuite/ld-powerpc/attr-gnu-4-02.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-03.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-10.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-11.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-20.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-22.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-33.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-8-11.d: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Don't run deleted tests.
2016-09-26 18:04:57 +09:30
Akihiko Odaki 5025eb7c0d Delete relocations associatesd with deleted exidx entries.
PR ld/20595
ld	* testsuite/ld-arm/unwind-4.d: Add -q option to linker command
	line and -r option to objdump command line.  Match emitted relocs
	to make sure that superflous relocs are not generated.

bfd	* elf-bfd.h (struct elf_backend_data): Add
	elf_backend_count_output_relocs callback to count relocations in
	the final output.
	* elf-arm.c (elf32_arm_add_relocation): Deleted.
	(elf32_arm_write_section): Move additional relocation to emit_relocs.
	(elf32_arm_count_output_relocs): New function.
	(emit_relocs): New function.
	(elf32_arm_emit_relocs): New function.
	(elf32_arm_vxworks_emit_relocs): New function.
	(elf_backend_emit_relocs): Updated to use the new functions.
	(elf_backend_count_output_relocs): New define.
	* bfd/elflink.c (bfd_elf_final_link): Do not add additional_reloc_count
	to the relocation count.
	(_bfd_elf_link_size_reloc_section): Use callback to count the
	relocations which will be in output.
	(_bfd_elf_default_count_output_relocs): New function.
	* bfd/elfxx-target.h (elf_backend_count_output_relocs): New define.
2016-09-23 16:32:04 +01:00
Cupertino Miranda 8a36df4dcf Several fixes related to ARC PIE support.
Fixed conditions related to dynamic relocs relative offset patching.
Added arc_link_hash_table to be able to always generate and track
.rela.bss section.

bfd/ChangeLog:

Cupertino Miranda  <cmiranda@synopsys.com>

	* elf-bfd.h: Added ARC_ELF_DATA to enum elf_target_id.
	* elf32-arc.c (struct elf_arc_link_hash_entry): Added.
	(struct elf_arc_link_hash_table): Likewise.
	(elf_arc_link_hash_newfunc): Likewise.
	(elf_arc_link_hash_table_free): Likewise.
	(arc_elf_link_hash_table_create): Likewise.
	(elf_arc_relocate_section): Fixed conditions related to dynamic
	(elf_arc_check_relocs): Likewise.
	(arc_elf_create_dynamic_sections): Added
	(elf_arc_adjust_dynamic_symbol): Changed access to .rela.bss to be done
	through the hash table.
2016-08-26 12:09:17 +02:00
Alan Modra 90ac242072 Correct .dynsym sh_info
bfd/
	* elf-bfd.h (struct elf_link_hash_table): Add local_dynsymcount.
	* elflink.c (_bfd_elf_link_renumber_dynsyms): Set local_dynsymcount.
	(bfd_elf_final_link): Set .dynsym sh_info from local_dynsymcount.
ld/
	* testsuite/ld-tic6x/shlib-1.rd: Correct expected .dynsym sh_info.
	* testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
2016-08-13 00:07:20 +09:30
Thomas Preud'homme 7635954182 Add support for creating ELF import libraries
2016-07-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf-bfd.h (elf_backend_filter_implib_symbols): Declare backend hook.
	(_bfd_elf_filter_global_symbols): Declare.
	* elf.c (_bfd_elf_filter_global_symbols): New function.
	* elflink.c (elf_filter_global_symbols): Likewise.
	(elf_output_implib): Likewise.
	(bfd_elf_final_link): Call above function, failing if it does.
	* elfxx-target.h (elf_backend_filter_implib_symbols): Define macro and
	default it to NULL.
	(elf_backend_copy_indirect_symbol): Fix spacing.
	(elf_backend_hide_symbol): Likewise.
	(elfNN_bed): Initialize elf_backend_filter_implib_symbols backend hook.

include/
	* bfdlink.h (struct bfd_link_info): Declare new ldscript_def and
	out_implib_bfd fields.

2016-07-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>
	    Nick Clifton  <nickc@redhat.com>

ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Open import
	library file for writing and initialize implib_bfd field of link_info
	structure.
	* emultempl/pe.em (pe_implib_filename): Remove variable declaration.
	(OPTION_IMPLIB_FILENAME): Remove macro definition.
	(gld${EMULATION_NAME}_add_options): Remove --out-implib option.
	(gld_${EMULATION_NAME}_list_options): Likewise.
	(gld${EMULATION_NAME}_handle_option): Likewise.
	(gld_${EMULATION_NAME}_finish): Use command_line.out_implib_filename
	instead of pe_implib_filename.
	* emultempl/pep.em (pep_implib_filename): Remove variable declaration.
	(OPTION_IMPLIB_FILENAME): Remove enumerator.
	(gld${EMULATION_NAME}_add_options): Remove --out-implib option.
	(gld_${EMULATION_NAME}_list_options): Likewise.
	(gld${EMULATION_NAME}_handle_option): Likewise.
	(gld_${EMULATION_NAME}_finish): Use command_line.out_implib_filename
	instead of pep_implib_filename.
	* ld.h (args_type): Declare new out_implib_filename field.
	* ld.texinfo (--out-implib): Move documentation to arch-independent
	part and rephrase to apply to ELF targets.
	* ldexp.c (exp_fold_tree_1): Set ldscript_def field to 1 for symbols
	defined in linker scripts.
	* ldlex.h (enum option_values): Declare new OPTION_OUT_IMPLIB
	enumerator.
	* lexsup.c (ld_options): Add entry for new --out-implib switch.
	(parse_args): Handle OPTION_OUT_IMPLIB case.
	* testsuite/ld-elf/elf.exp (Generate empty import library): New test.
	(Generate import library): Likewise.
	* testsuite/ld-elf/implib.s: Likewise.
	* testsuite/ld-elf/implib.rd: New file.
	* testsuite/ld-elf/empty-implib.out: Likewise
2016-07-15 17:50:48 +01:00
H.J. Lu 233cc9c13a Don't generate PLT for IFUNC GOT/pointer reference
If a backend supports it, PLT entry isn't needed when all references
to a STT_GNU_IFUNC symbols are done via GOT or static function pointers.
For GOT entries, We generate dynamic R_*_GLOB_DAT relocations for
preemptable symbols and R_*_IRELATIVE relocations for non-preemptable
symbols to update them with real function address.  For static pointer
pointers, we generate dynamic pointer relocations and store them in:

1. .rel[a].ifunc section in PIC object.
2. .rel[a].got section in dynamic executable.
3. .rel[a].iplt section in static executable.

We don't allocate GOT entry if it isn't used.

bfd/

	PR ld/20253
	* elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add an
	bfd_boolean argument.
	* elf-ifunc.c (_bfd_elf_create_ifunc_sections): Replace
	"shared object" with "PIC object" in comments.
	(_bfd_elf_allocate_ifunc_dyn_relocs): Updated.  Replace
	"shared object" with "PIC object" in comments.  Avoid PLT if
	requested.  Generate dynamic relocations for non-GOT references.
	Make room for the special first entry in PLT and allocate PLT
	entry only for PLT and PC-relative references.  Store dynamic
	GOT relocations in .rel[a].iplt section for static executables.
	If PLT isn't used, always use GOT for symbol value.  Don't
	allocate GOT entry if it isn't used.
	* elf32-i386.c (elf_i386_check_relocs): Increment PLT reference
	count only in the code section.  Allocate dynamic pointer
	relocation against STT_GNU_IFUNC symbol in the non-code section.
	(elf_i386_adjust_dynamic_symbol): Increment PLT reference count
	only for PC-relative references.
	(elf_i386_allocate_dynrelocs): Pass TRUE to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	(elf_i386_relocate_section): Allow R_386_GOT32/R_386_GOT32X
	relocations against STT_GNU_IFUNC symbols without PLT.  Generate
	dynamic pointer relocation against STT_GNU_IFUNC symbol in
	the non-code section and store it in the proper REL section.
	Don't allow non-pointer relocation against STT_GNU_IFUNC symbol
	without PLT.
	(elf_i386_finish_dynamic_symbol): Generate dynamic
	R_386_IRELATIVE and R_386_GLOB_DAT GOT relocations against
	STT_GNU_IFUNC symbols without PLT.
	(elf_i386_finish_dynamic_sections): Don't handle local
	STT_GNU_IFUNC symbols here.
	(elf_i386_output_arch_local_syms): Handle local STT_GNU_IFUNC
	symbols here.
	(elf_backend_output_arch_local_syms): New.
	* elf32-x86-64.c (elf_i386_check_relocs): Increment PLT reference
	count only in the code section.  Allocate dynamic pointer
	relocation against STT_GNU_IFUNC symbol in the non-code section.
	(elf_x86_64_adjust_dynamic_symbol): Increment PLT reference
	count only for PC-relative references.
	(elf_x86_64_allocate_dynrelocs): Pass TRUE to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	(elf_x86_64_relocate_section): Allow R_X86_64_GOTPCREL,
	R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX and
	R_X86_64_GOTPCREL64 relocations against STT_GNU_IFUNC symbols
	without PLT.  Generate dynamic pointer relocation against
	STT_GNU_IFUNC symbol in the non-code section and store it in
	the proper RELA section.  Don't allow non-pointer relocation
	against STT_GNU_IFUNC symbol without PLT.
	(elf_x86_64_finish_dynamic_symbol): Generate dynamic
	R_X86_64_IRELATIVE and R_X86_64_GLOB_DAT GOT relocations against
	STT_GNU_IFUNC symbols without PLT.
	(elf_x86_64_finish_dynamic_sections): Don't handle local
	STT_GNU_IFUNC symbols here.
	(elf_x86_64_output_arch_local_syms): Handle local STT_GNU_IFUNC
	symbols here.
	(elf_backend_output_arch_local_syms): New.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Pass FALSE to _bfd_elf_allocate_ifunc_dyn_relocs.

ld/

	PR ld/20253
	* testsuite/ld-i386/i386.exp: Run PR ld/20253 tests.
	* testsuite/ld-i386/no-plt.exp: Likewise.
	* testsuite/ld-x86-64/no-plt.exp: Likewise.
	* testsuite/ld-i386/pr13302.d: Remove .rel.plt section.
	* testsuite/ld-ifunc/ifunc-13-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-13-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-15-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-15-x86-64.d: Likewise.
	* testsuite/ld-x86-64/pr13082-5a.d: Likewise.
	* testsuite/ld-x86-64/pr13082-5b.d: Likewise.
	* testsuite/ld-x86-64/pr13082-6a.d: Likewise.
	* testsuite/ld-x86-64/pr13082-6b.d: Likewise.
	* testsuite/ld-i386/pr20244-2a.d: Remove .plt section.
	* 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-i386/pr20244-2b.d: Updated.
	* testsuite/ld-i386/pr20244-2c.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise.
	* testsuite/ld-i386/pr20253-1a.c: New file.
	* testsuite/ld-i386/pr20253-1b.S: Likewise.
	* testsuite/ld-i386/pr20253-1c.S: Likewise.
	* testsuite/ld-i386/pr20253-1d.S: Likewise.
	* testsuite/ld-i386/pr20253-2a.c: Likewise.
	* testsuite/ld-i386/pr20253-2b.S: Likewise.
	* testsuite/ld-i386/pr20253-2c.S: Likewise.
	* testsuite/ld-i386/pr20253-2d.S: Likewise.
	* testsuite/ld-i386/pr20253-3.d: Likewise.
	* testsuite/ld-i386/pr20253-3.s: Likewise.
	* testsuite/ld-i386/pr20253-4.s: Likewise.
	* testsuite/ld-i386/pr20253-4a.d: Likewise.
	* testsuite/ld-i386/pr20253-4b.d: Likewise.
	* testsuite/ld-i386/pr20253-4c.d: Likewise.
	* testsuite/ld-i386/pr20253-5.d: Likewise.
	* testsuite/ld-i386/pr20253-5.s: Likewise.
	* testsuite/ld-ifunc/ifunc-23-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-23a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-23b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-23c-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24c-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25c-x86.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1.s: Likewise.
	* testsuite/ld-x86-64/pr20253-1a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1b.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1c.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1e.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1g.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1i.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1j.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1k.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1l.d: Likewise.
	* testsuite/ld-x86-64/pr20253-2a.c: Likewise.
	* testsuite/ld-x86-64/pr20253-2b.S: Likewise.
	* testsuite/ld-x86-64/pr20253-2c.S: Likewise.
	* testsuite/ld-x86-64/pr20253-2d.S: Likewise.
	* testsuite/ld-x86-64/pr20253-3.d: Likewise.
	* testsuite/ld-x86-64/pr20253-3.s: Likewise.
	* testsuite/ld-x86-64/pr20253-4.s: Likewise.
	* testsuite/ld-x86-64/pr20253-4a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4b.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4c.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4e.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-5.s: Likewise.
	* testsuite/ld-x86-64/pr20253-5a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-5b.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-i386.d: Remove extra IRELATIVE
	relocation.
	* testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a.s: Fix a typo.
	* testsuite/ld-x86-64/x86-64.exp: Run pr20253-1 tests.
2016-06-18 09:17:25 -07:00
Alan Modra ef53be8916 Use size_t rather than bfd_size_type
I noticed when writing _bfd_elf_strtab_save/restore that size_t would
be better than bfd_size_type for a number of things in elf-strtab.c.
Using a 64-bit bfd_size_type on a 32-bit host doesn't make much sense
for array sizes and indices.

	* elf-strtab.c (struct strtab_save): Use size_t for "size".
	(struct elf_strtab_hash): Likewise for "size" and "alloced".
	(_bfd_elf_strtab_init): Formatting.
	(_bfd_elf_strtab_add): Return size_t rather than bfd_size_type.
	(_bfd_elf_strtab_addref): Take size_t idx param.
	(_bfd_elf_strtab_delref, _bfd_elf_strtab_refcount): Likewise.
	(_bfd_elf_strtab_offset): Likewise.
	(_bfd_elf_strtab_clear_all_refs): Use size_t idx.
	(_bfd_elf_strtab_save): Use size_t "idx" and "size" vars.
	(_bfd_elf_strtab_restore, _bfd_elf_strtab_emit): Similarly.
	(_bfd_elf_strtab_finalize): Similarly.
	* elf-bfd.h (_bfd_elf_strtab_add): Update prototypes.
	(_bfd_elf_strtab_addref, _bfd_elf_strtab_delref): Likewise.
	(_bfd_elf_strtab_refcount, _bfd_elf_strtab_offset): Likewise.
	* elf.c (bfd_elf_get_elf_syms): Calculate symbol buffer size
	using bfd_size_type.
	(bfd_section_from_shdr): Delete amt.
	(_bfd_elf_init_reloc_shdr): Likewise.
	(_bfd_elf_link_assign_sym_version): Likewise.
	(assign_section_numbers): Use size_t reloc_count.
	* elflink.c (struct elf_symbuf_head): Use size_t "count".
	(bfd_elf_link_record_dynamic_symbol): Use size_t for some vars.
	(elf_link_is_defined_archive_symbol): Likewise.
	(elf_add_dt_needed_tag): Likewise.
	(elf_finalize_dynstr): Likewise.
	(elf_link_add_object_symbols): Likewise.
	(bfd_elf_size_dynamic_sections): Likewise.
	(elf_create_symbuf): Similarly.
	(bfd_elf_match_symbols_in_sections): Likewise.
	(elf_link_swap_symbols_out): Likewise.
	(elf_link_check_versioned_symbol): Likewise.
	(bfd_elf_gc_record_vtinherit): Likewise.
	(bfd_elf_gc_common_finalize_got_offsets): Likewise.
2016-06-11 17:24:56 +09:30
Alan Modra 14b57c7c6a PowerPC VLE
VLE is an encoding, not a particular processor architecture, so it
isn't really proper to select insns based on PPC_OPCODE_VLE.  For
example
{"evaddw",  VX (4, 512), VX_MASK, PPCSPE|PPCVLE, PPCNONE, {RS, RA, RB}},
{"vaddubs", VX (4, 512), VX_MASK, PPCVEC|PPCVLE, PPCNONE, {VD, VA, VB}},
shows two insns that have the same encoding, both available with VLE.
Enabling both with VLE means we can't disassemble the second variant
even if -Maltivec is given rather than -Mspe.  Also, we don't check
user assembly against the processor type as well as we could.

Another problem is that when using the VLE encoding, insns from the
main ppc opcode table are not available, except those using opcode 4
and 31.  Correcting this revealed two errors in the ld testsuite,
use of "nop" and "rfmci" when -mvle.

This patch fixes those problems in the opcode table, and removes
PPCNONE.  I find a plain 0 distracts less from other values.

In addition, I've implemented code to recognize some machine values
from the apuinfo note present in ppc32 objects.  It's not a complete
disambiguation since we're lacking info to detect newer chips, but
what we have should help with disassembly.

include/
	* elf/ppc.h (APUINFO_SECTION_NAME, APUINFO_LABEL, PPC_APUINFO_ISEL,
	PPC_APUINFO_PMR, PPC_APUINFO_RFMCI, PPC_APUINFO_CACHELCK,
	PPC_APUINFO_SPE, PPC_APUINFO_EFS, PPC_APUINFO_BRLOCK,
	PPC_APUINFO_VLE: Define.
opcodes/
	* ppc-dis.c (ppc_opts): Delete extraneous parentheses.  Default
	cpu for "vle" to e500.
	* ppc-opc.c (ALLOW8_SPRG): Remove PPC_OPCODE_VLE.
	(NO371, PPCSPE, PPCISEL, PPCEFS, MULHW, DCBT_EO): Likewise.
	(PPCNONE): Delete, substitute throughout.
	(powerpc_opcodes): Remove PPCVLE from "flags".  Add to "deprecated"
	except for major opcode 4 and 31.
	(vle_opcodes <se_rfmci>): Add PPCRFMCI to flags.
bfd/
	* cpu-powerpc.c (powerpc_compatible): Allow bfd_mach_ppc_vle entry
	to match other 32-bit archs.
	* elf32-ppc.c (_bfd_elf_ppc_set_arch): New function.
	(ppc_elf_object_p): Call it.
	(ppc_elf_special_sections): Use APUINFO_SECTION_NAME.  Fix
	overlong line.
	(APUINFO_SECTION_NAME, APUINFO_LABEL): Don't define here.
	* elf64-ppc.c (ppc64_elf_object_p): Call _bfd_elf_ppc_set_arch.
	* bfd-in.h (_bfd_elf_ppc_at_tls_transform,
	_bfd_elf_ppc_at_tprel_transform): Move to..
	* elf-bfd.h: ..here.
	(_bfd_elf_ppc_set_arch): Declare.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-ppc.c (PPC_APUINFO_ISEL, PPC_APUINFO_PMR,
	PPC_APUINFO_RFMCI, PPC_APUINFO_CACHELCK, PPC_APUINFO_SPE,
	PPC_APUINFO_EFS, PPC_APUINFO_BRLOCK, PPC_APUINFO_VLE): Don't define.
	(ppc_setup_opcodes): Check vle disables powerpc_opcodes overridden
	by vle_opcodes, and that vle flag doesn't enable opcodes.  Don't
	add vle_opcodes twice.
	(ppc_cleanup): Use APUINFO_SECTION_NAME and APUINFO_LABEL.
ld/
	* testsuite/ld-powerpc/apuinfo1.s: Delete nop.
	* testsuite/ld-powerpc/apuinfo-vle2.s: New.
	* testsuite/ld-powerpc/powerpc.exp: Use apuinfo-vle2.s.
2016-06-07 22:04:38 +09:30
Alan Modra 5b677558bc Revert PR16467 change
This reverts the pr16467 change, which was incorrect due to faulty
analysis of the pr16467 testcase.  The failure was not due to a
mismatch in symbol type (ifunc/non-ifunc) but due to a symbol loop
being set up.

See https://sourceware.org/ml/binutils/2016-06/msg00013.html for some
rambling on versioned symbols and ELF shared library symbol overriding
that explain this patch.

bfd/
	PR ld/20159
	PR ld/16467
	* elflink.c (_bfd_elf_merge_symbol): Revert PR16467 change.
	(_bfd_elf_add_default_symbol): Don't indirect to/from defined
	symbol given a version by a script different to the version
	of the symbol being added.
	(elf_link_add_object_symbols): Use _bfd_elf_strtab_save and
	_bfd_elf_strtab_restore.  Don't fudge dynstr references.
	* elf-strtab.c (_bfd_elf_strtab_restore_size): Delete.
	(struct strtab_save): New.
	(_bfd_elf_strtab_save, _bfd_elf_strtab_restore): New functions.
	* elf-bfd.h (_bfd_elf_strtab_restore_size): Delete.
	(_bfd_elf_strtab_save, _bfd_elf_strtab_restore): Declare.
2016-06-02 12:28:39 +09:30
Alan Modra 1a72702bb3 Return void from linker callbacks
The ldmain.c implementation of these linker callback functions always
return true, so any code handling a false return is dead.  What's
more, some of the bfd backends abort if ever a false return is seen,
and there seems to be some confusion in gdb's compile-object-load.c.
The return value was never meant to be "oh yes, a multiple_definition
error occurred", but rather "out of memory or other catastrophic
failure".

This patch removes the status return on the callbacks that always
return true.  I kept the return status for "notice" because that one
does happen to need to return "out of memory".

include/
	* bfdlink.h (struct bfd_link_callbacks): Update comments.
	Return void from multiple_definition, multiple_common,
	add_to_set, constructor, warning, undefined_symbol,
	reloc_overflow, reloc_dangerous and unattached_reloc.
bfd/
	* aoutx.h: Adjust linker callback calls throughout file,
	removing dead code.
	* bout.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-h8300.c: Likewise.
	* coff-h8500.c: Likewise.
	* coff-i960.c: Likewise.
	* coff-mcore.c: Likewise.
	* coff-mips.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff-w65.c: Likewise.
	* coff-z80.c: Likewise.
	* coff-z8k.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* cofflink.c: Likewise.
	* ecoff.c: Likewise.
	* elf-bfd.h: Likewise.
	* elf-m10200.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf32-arc.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cr16c.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-crx.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-epiphany.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-ft32.c: Likewise.
	* elf32-h8300.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-i860.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mep.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-sh64.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-visium.c: Likewise.
	* elf32-xstormy16.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-mmix.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-sh64.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* linker.c: Likewise.
	* pdp11.c: Likewise.
	* pe-mips.c: Likewise.
	* reloc.c: Likewise.
	* reloc16.c: Likewise.
	* simple.c: Likewise.
	* vms-alpha.c: Likewise.
	* xcofflink.c: Likewise.
	* elf32-rl78.c (get_symbol_value, get_romstart, get_ramstart): Delete
	status param.  Adjust calls to these and linker callbacks throughout.
	* elf32-rx.c: (get_symbol_value, get_gp, get_romstart,
	get_ramstart): Delete status param.  Adjust calls to these and
	linker callbacks throughout.
ld/
	* ldmain.c (multiple_definition, multiple_common, add_to_set,
	constructor_callback, warning_callback, undefined_symbol,
	reloc_overflow, reloc_dangerous, unattached_reloc): Return void.
	* emultempl/elf32.em: Adjust callback calls.
gdb/
	* compile/compile-object-load.c (link_callbacks_multiple_definition,
	link_callbacks_warning, link_callbacks_undefined_symbol,
	link_callbacks_undefined_symbol, link_callbacks_reloc_overflow,
	link_callbacks_reloc_dangerous,
	link_callbacks_unattached_reloc): Return void.
2016-05-28 11:17:20 +09:30
Alan Modra 1997c9943a ld -z combreloc reloc sorting
PLT relocs don't appear in .rela.dyn, at least not when using
normal linker scripts.  However, if they do, then they ought to be
placed last rather than in the middle of other relocs.

	* elf-bfd.h (elf_reloc_type_class): Put reloc_class_plt last.
2016-05-13 00:17:19 +09:30
H.J. Lu 97196564c7 Strip global symbol defined in discarded section
When a global symbol is defined in COMDAT group, we shouldn't leave an
undefined symbol in symbol table when the symbol section is discarded
unless there is a reference to the symbol outside of COMDAT group.

bfd/

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

ld/

	PR ld/17550
	* testsuite/ld-elf/pr17550-1.s: New file.
	* testsuite/ld-elf/pr17550-2.s: Likewise.
	* testsuite/ld-elf/pr17550-3.s: Likewise.
	* testsuite/ld-elf/pr17550-4.s: Likewise.
	* testsuite/ld-elf/pr17550a.d: Likewise.
	* testsuite/ld-elf/pr17550b.d: Likewise.
	* testsuite/ld-elf/pr17550c.d: Likewise.
	* testsuite/ld-elf/pr17550d.d: Likewise.
2016-05-06 09:46:50 -07:00
Nick Clifton 5522f910cb Enhance support for copying and stripping Solaris and ARM binaries.
PR 19938
bfd	* elf-bfd.h (struct elf_backend_data): Rename
	elf_backend_set_special_section_info_and_link to
	elf_backend_copy_special_section_fields.
	* elfxx-target.h: Likewise.
	* elf.c (section_match): Ignore the SHF_INFO_LINK flag when
	comparing section flags.
	(copy_special_section_fields): New function.
	(_bfd_elf_copy_private_bfd_data): Copy the EI_ABIVERSION field.
	Perform two scans over special sections.  The first one looks for
	a direct mapping between the output section and an input section.
	The second scan looks for a possible match based upon section
	characteristics.
	* elf32-arm.c (elf32_arm_copy_special_section_fields): New
	function.  Handle setting the sh_link field of SHT_ARM_EXIDX
	sections.
	* elf32-i386.c (elf32_i386_set_special_info_link): Rename to
	elf32_i386_copy_solaris_special_section_fields.
	* elf32-sparc.c (elf32_sparc_set_special_section_info_link):
	Rename to elf32_sparc_copy_solaris_special_section_fields.
	* elf64-x86-64.c (elf64_x86_64_set_special_info_link): Rename to
	elf64_x86_64_copy_solaris_special_section_fields.

binutils* readelf.c (get_solaris_segment_type): New function.
	(get_segment_type): Call it.
2016-04-29 09:24:42 +01:00
Alan Modra a6a4679fc0 Cache result of scan for __start_* and __stop_* sections
include/
	* bfdlink.h (struct bfd_link_hash_entry): Add "section" field to
	undef.  Formatting.
bfd/
	* elflink.c (_bfd_elf_is_start_stop): New function.
	(_bfd_elf_gc_mark_rsec): Use it.
	* elf-bfd.h (_bfd_elf_is_start_stop): Declare.
2016-04-27 17:05:26 +09:30
H.J. Lu d5486c4372 Always count the NULL entry in dynamic symbol table
There is an unused NULL entry at the head of dynamic symbol table which
we must account for in our count even if the table is empty or unused
since it is intended for the mandatory DT_SYMTAB tag (.dynsym section)
in .dynamic section.

	* elf-bfd.h (elf_link_hash_table): Update comments for
	dynsymcount.
	* elflink.c (_bfd_elf_link_renumber_dynsyms): Always count for
	the unused NULL entry at the head of dynamic symbol table.
	(bfd_elf_size_dynsym_hash_dynstr): Remove dynsymcount != 0
	checks.
2016-04-26 03:53:23 -07:00
H.J. Lu d968975277 Check ELF relocs after opening all input files
Delaying checking ELF relocations until opening all input files so
that symbol information is final when relocations are checked.  This
is only enabled for x86 targets.

bfd/

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

include/

	* bfdlink.h (bfd_link_info): Add check_relocs_after_open_input.

ld/

	* emulparams/elf32_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	New.
	* emulparams/elf_i386.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_be.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_chaos.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_ldso.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_vxworks.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse):
	Set check_relocs_after_open_input to TRUE if
	CHECK_RELOCS_AFTER_OPEN_INPUT is yes.
	(gld${EMULATION_NAME}_after_open): Call
	_bfd_elf_link_check_relocs on all inputs if
	check_relocs_after_open_input is TRUE.
2016-04-20 05:26:51 -07:00
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
Nick Clifton 9fb71ee49f Enhance GAS's .section directive so that it can take numeric values for the flags and type fields. (ELF only)
gas	* doc/as.texinfo (.section): Document that numeric values can now
	be used for the flags and type fields of the ELF target's .section
	directive.  Add notes about the restrictions on setting flags and
	types.
	* config/obj-elf.c (obj_elf_change_section): Allow known sections
	to be given processor specific section types.  Allow processor and
	application specific flags of a section to be set after
	definition.
	(obj_elf_parse_section_letters): Handle parsing numeric values.
	(obj_elf_section_type): Handle parsing numeric values.
	(obj_elf_section): Allow numeric type values.
	* config/obj-elf.h (obj_elf_change_section): Update prototype.
	* testsuite/gas/elf/section10.d: New test.
	* testsuite/gas/elf/section10.s: Source file for new test.
	* testsuite/gas/elf/elf.exp: Run the new test.
	* testsuite/gas/i386/ilp32/x86-64-unwind.d: Remove dependency upon
	the description of the flags produced by readelf.
	* testsuite/gas/tic6x/scomm-directive-4.d: Likewise.
	* NEWS: Mention the new feature.

bfd	* elf-bfd.h (struct bfd_elf_special_section): Use unsigned values
	for length and type fields.  Use a signed value for the
	suffix_length field.

binutils* readelf.c (get_section_type_name): Add hex prefix to offsets
	printed for LOPROC and LOOS values.  Ensure that a result is
	always returned for the V850 target, even when an unrecognised
	processor specific value is encountered.
	(process_section_headers): Display key values in the order in
	which they appear to the user.  Add the "C (compressed)" value to
	the list.

ld	* testsuite/ld-i386/pr12718.d: Remove dependency upon the
	description of the flags produced by readelf.
	* testsuite/ld-i386/pr12921.d: Likewise.
	* testsuite/ld-i386/tlsbin-nacl.rd: Likewise.
	* testsuite/ld-i386/tlsbin.rd: Likewise.
	* testsuite/ld-i386/tlsbindesc-nacl.rd: Likewise.
	* testsuite/ld-i386/tlsbindesc.rd: Likewise.
	* testsuite/ld-i386/tlsdesc-nacl.rd: Likewise.
	* testsuite/ld-i386/tlsdesc.rd: Likewise.
	* testsuite/ld-i386/tlsgdesc-nacl.rd: Likewise.
	* testsuite/ld-i386/tlsgdesc.rd: Likewise.
	* testsuite/ld-i386/tlsnopic-nacl.rd: Likewise.
	* testsuite/ld-i386/tlsnopic.rd: Likewise.
	* testsuite/ld-i386/tlspic-nacl.rd: Likewise.
	* testsuite/ld-i386/tlspic.rd: Likewise.
	* testsuite/ld-s390/tlsbin.rd: Likewise.
	* testsuite/ld-s390/tlsbin_64.rd: Likewise.
	* testsuite/ld-s390/tlspic.rd: Likewise.
	* testsuite/ld-s390/tlspic_64.rd: Likewise.
	* testsuite/ld-sh/tlsbin-2.d: Likewise.
	* testsuite/ld-sh/tlspic-2.d: Likewise.
	* testsuite/ld-tic6x/common.d: Likewise.
	* testsuite/ld-tic6x/shlib-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
	* testsuite/ld-x86-64/ilp32-4-nacl.d: Likewise.
	* testsuite/ld-x86-64/ilp32-4.d: Likewise.
	* testsuite/ld-x86-64/pr12718.d: Likewise.
	* testsuite/ld-x86-64/pr12921.d: Likewise.
	* testsuite/ld-x86-64/split-by-file-nacl.rd: Likewise.
	* testsuite/ld-x86-64/split-by-file.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin.rd: Likewise.
	* testsuite/ld-x86-64/tlsbindesc-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsgdesc-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlsgdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlspic-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlspic.rd: Likewise.
	* testsuite/ld-xtensa/tlsbin.rd: Likewise.
	* testsuite/ld-xtensa/tlspic.rd: Likewise.
2016-02-15 11:11:46 +00:00
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
Yury Usishchev 491d01d3da ARM: Fix exidx coverage for relocatable builds.
bfd  * elf-bfd.h: Add callback to count additional relocations.
     * elf32-arm.c (_arm_elf_section_data): Add new counter.
     (insert_cantunwind_after): Increment relocations counter.
     (elf32_arm_fix_exidx_coverage): Remove exidx entries and add
     terminating CANTUNWIND entry only in final builds.
     (elf32_arm_add_relocation): New function.
     (elf32_arm_write_section): Add relocations in relocatable builds.
     (elf32_arm_count_additional_relocs): New function.
     (elf_backend_count_additional_relocs): New define.
     * bfd/elflink.c (bfd_elf_final_link): Use callback and adjust size of
     .rel section.
     * bfd/elfxx-target.h (elf_backend_count_additional_relocs): New define.

ld   * emultempl/armelf.em (gld${EMULATION_NAME}_after_allocation): Call
     elf32_arm_fix_exidx_coverage for relocatable builds.

ld/testsuite
     * ld-arm/arm-elf.exp: New test.
     * ld-arm/unwind-rel.d: New file.
     * ld-arm/unwind-rel1.s: New file.
     * ld-arm/unwind-rel2.s: New file.
     * ld-arm/unwind-rel3.s: New file.
2015-12-22 15:50:13 +00:00
Alan Modra 923b198a84 addr2line vs. inlined C functions called from C++
In this case the inlined function doesn't have DW_AT_linkage_name in
.debug_info, but the language is C++ so find_nearest_line goes looking
in the symbol table.  Since the function is inlined the enclosing
non-inline function symbol is returned from _bfd_elf_find_function,
which is wrong.  This patch only uses a symbol if its address matches.

	PR binutils/19315
	* dwarf2.c (_bfd_elf_find_function): Return symbol matched.
	(_bfd_dwarf2_find_nearest_line): Check symbol returned above
	against dwarf range.
	* elf-bfd.h (_bfd_elf_find_function): Update prototype.
2015-12-02 23:55:51 +10:30
Alan Modra 1cce69b9dc Handle __start_* and __stop_* symbols in --gc-sections
PR ld/11133
	PR ld/19161
	PR ld/19167
	* elflink.c (_bfd_elf_gc_mark_hook): Delete code handling __start_*
	and __stop_* symbol refs.
	(_bfd_elf_gc_mark_rsec): Add start_stop parameter.  Handle __start_*
	and __stop_* symbol refs here..
	(_bfd_elf_gc_mark_reloc): ..and here.
	* elf-bfd.h (_bfd_elf_gc_mark_hook): Update prototype.
	* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Update
	_bfd_elf_gc_mark_rsec call.
2015-10-23 22:26:25 +10:30
Nick Clifton 6a40cf0c5c Add support for files that contain multiple symbol index tables. Fixes PR 15835
binutils	PR binutils/15835
	* readelf.c (struct elf_section_list): New structure.
	(symtab_shndx_hdr): Replace with symtab_shndx_list.
	(get_32bit_elf_symbols): Scan for a symbol index table matching
	the symbol table in use.
	(get_64bit_elf_symbols): Likewise.
	(process_section_headers): Handle multiple symbol index sections.

bfd	* elf-bfd.h (struct elf_section_list): New structure.
	(struct elf_obj_tdata): Replace symtab_shndx_hdr with
	symtab_shndx_list.  Delete symtab_shndx_section.
	(elf_symtab_shndx): Replace macro with elf_symtab_shndx_list.
	* elf.c (bfd_elf_get_syms): If symtab index sections are present,
	scan them for the section that matches the provided symbol table.
	(bfd_section_from_shdr): Record all SHT_SYMTAB_SHNDX sections.
	(assign_section_numbers): Use the first symtab index table in the
	list.
	(_bfd_elf_compute_section_file_positions): Replace use of
	symtab_shndx_hdr with use of symtab_shndx_list.
	(find_section_in_list): New function.
	(assign_file_postions_except_relocs): Use new function.
	(_bfd_elf_copy_private_symbol_data): Likewise.
	(swap_out_syms): Handle multiple symbol table index sections.
	* elf32-m32c.c (m32c_elf_relax_section): Replace use of
	symtab_shndx_hdr with use of symtab_shndx_list.
	* elf32-rl78.c (rl78_elf_relax_section): Likewise.
	* elf32-rx.c (rx_relax_section): Likewise.
	* elf32-v850.c (v850_elf_relax_delete_bytes): Likewise.
	* elflink.c (bfd_elf_final_link): Likewise.
2015-09-23 17:23:58 +01: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 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 422f11824b Replace hidden with versioned in elf_link_hash_entry
This patch replaces the "hidden" field with the "versioned" field in
elf_link_hash_entry so that we can avoid calling strchr and strrchr if
the symbol is unversioned.

	* elf-bfd.h (elf_symbol_version): New enum.
	(elf_link_hash_entry): Replace hidden with versioned.
	* elflink.c (_bfd_elf_merge_symbol): Don't look for symbol
	version if the symbol is unversioned.  Initialize versioned.
	(_bfd_elf_add_default_symbol): Don't look for symbol version
	if the symbol is unversioned or hidden.  Initialize versioned.
	(elf_collect_hash_codes): Don't look for symbol version if the
	symbol is unversioned.
	(elf_collect_gnu_hash_codes): Likewise.
	(bfd_elf_gc_mark_dynamic_ref_symbol): Likewise.
	(_bfd_elf_link_hash_copy_indirect): Check versioned instead of
	hidden.
	(elf_link_output_extsym): Likewise.
2015-08-10 07:57:57 -07:00
Nick Clifton 5ee4a1ca16 This fixes parsing a file containing ELF attributes with very large tag values.
PR binutils/18570
	* elf-attrs.c (obj_attr_size): Use an unsigned int type for the tag.
	(write_obj_attribute): Likewise.
	(elf_new_obj_attr): Likewise.
	(bfd_elf_get_obj_attr_int): Likewise.
	(bfd_elf_add_obj_attr_int): Likewise.
	(bfd_elf_add_obj_attr_string): Likewise.
	(bfd_elf_add_obj_attr_int_string): Likewise.
	(gnu_obj_attrs_arg_type): Likewise.
	(_bfd_elf_obj_attrs_arg_type): Likewise.
	(_bfd_elf_parse_attributes): Likewise.
	(_bfd_elf_merge_unknown_attribute_list): Likewise.
	* elf-bfd.h (struct obj_attribute_list): Likewise.
	Update prototypes.
2015-06-30 17:12:47 +01:00
H.J. Lu ef10c3ace0 Use strtab with GC and suffix merging for .strtab
This patch uses ELF strtab with GC and suffix merging support to create
ELF .strtab section.  There is some small memory overhead to use ELF
strtab:

==14928== HEAP SUMMARY:
==14928==     in use at exit: 3,276,318 bytes in 679 blocks
==14928==   total heap usage: 1,544 allocs, 865 frees, 15,259,146 bytes allocated

vs.

==14936== HEAP SUMMARY:
==14936==     in use at exit: 3,276,318 bytes in 679 blocks
==14936==   total heap usage: 1,532 allocs, 853 frees, 15,026,402 bytes allocated

when running:

./ld-new -m elf_x86_64 -o tmpdir/ld-partial.o -r ldgram.o ldlex-wrapper.o lexsup.o ldlang.o mri.o ldctor.o ldmain.o plugin.o ldwrite.o ldexp.o ldemul.o ldver.o ldmisc.o ldfile.o ldcref.o eelf_x86_64.o eelf32_x86_64.o eelf_i386.o eelf_iamcu.o ei386linux.o eelf_l1om.o eelf_k1om.o ldbuildid.o

The results are

  [32] .strtab STRTAB 0+ 3beff8 00407a 00 0 0 1

vs

  [32] .strtab STRTAB 0+ 3beff8 0041d8 00 0 0 1

It reduces the .strtab size by 350 bytes, about 2%

Saving on libc.so from glibc is much more since libc.so has many alias
symbols with the same suffix.  For x32 glibc,

 [82] .strtab STRTAB 0+ 81b348 0159e7 00 0 0 1

vs

 [82] .strtab STRTAB 0+ 81b8bc 019e72 00 0 0 1

It reduces the .strtab size by 17547 bytes, about 16%.

bfd/

	PR gas/18451
	* elf-bfd.h (elf_sym_strtab): New.
	(elf_link_hash_table): Add strtabcount, strtabsize and
	strtab.
	(_bfd_elf_stringtab_init): Removed.
	* elf.c (_bfd_elf_stringtab_init): Removed.
	(_bfd_elf_compute_section_file_positions): Replace
	bfd_strtab_hash/_bfd_elf_stringtab_init/_bfd_stringtab_free/
	_bfd_stringtab_size with
	elf_strtab_hash/_bfd_elf_strtab_init/_bfd_elf_strtab_free/
	_bfd_elf_strtab_size.  Use _bfd_elf_strtab_add,
	_bfd_elf_strtab_finalize and _bfd_elf_strtab_offset to get
	st_name.
	(swap_out_syms): Likewise.
	* elflink.c (elf_final_link_info): Replace bfd_strtab_hash
	with elf_strtab_hash.  Remove symbuf, symbuf_count,
	symbuf_size and shndxbuf_size.
	(elf_link_flush_output_syms): Removed.
	(elf_link_output_sym): Renamed to ...
	(elf_link_output_symstrtab): This.  Replace _bfd_stringtab_add
	with _bfd_elf_strtab_add.  Don't flush symbols to the file nor
	swap out symbols.
	(elf_link_swap_symbols_out): New.
	(elf_link_output_extsym): Replace elf_link_output_sym with
	elf_link_output_symstrtab.
	(elf_link_input_bfd): Likewise.
	(elf_final_link_free): Replace _bfd_stringtab_free with
	_bfd_elf_strtab_free.  Remove symbuf.
	(bfd_elf_final_link): Replace _bfd_elf_stringtab_init with
	_bfd_elf_strtab_init.  Don't set symbuf, symbuf_count,
	symbuf_size nor shndxbuf_size.  Initialize strtabsize and
	strtab.  Initialize symshndxbuf to -1 when number of sections
	>= 64K.  Replace elf_link_output_sym/elf_link_output_sym with
	elf_link_output_symstrtab/elf_link_output_symstrtab. Don't
	call elf_link_flush_output_syms.  Call _bfd_elf_strtab_finalize
	and elf_link_swap_symbols_out.  Replace _bfd_stringtab_size
	and _bfd_stringtab_emit with _bfd_elf_strtab_size and
	_bfd_elf_strtab_emit.

gas/testsuite/

	PR gas/18451
	* gas/elf/elf.exp: Run strtab.
	* gas/elf/strtab.d: New file.
	* gas/elf/strtab.s: Likewise.

ld/testsuite/

	PR gas/18451
	* ld-elf/strtab.d: New file.
	* ld-elf/strtab.s: Likewise.
2015-06-25 08:16:14 -07:00
Jon Turney c74f7d1c6c Allow gdb to find debug symbols file by build-id for PE file format also
This promotes BFD's struct elf_build_id to the generic struct bfd_build_id,
populated when an ELF or PE BFD is read.

gdb is updated to use that, and to use the build-id to find symbols for PE files
also.

There is currently no generic way to extract the build-id from an object file,
perhaps an option to objdump to do this might make sense?

On x86_64-pc-cygwin, gdb's sepdebug.exp changes:

-# of unsupported tests          1
+# of expected passes            90

I don't seem to get consistent testsuite runs on i686-linux-gnu, but there
don't appear to be any regressions.

bfd/ChangeLog:

2015-06-10  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf-bfd.h : Remove struct elf_build_id.
	* bfd.c : Add struct bfd_build_id.
	* bfd-in2.h: Regenerate.
	* elf.c (elfobj_grok_gnu_build_id): Update to use bfd_build_id.
	* libpei.h: Add protoype and macros for
	bfd_XXi_slurp_codeview_record.
	* peXXigen.c (_bfd_XXi_slurp_codeview_record): Make public
	* peicode.h (pe_bfd_read_buildid): Add.
	(pe_bfd_object_p): Use pe_bfd_read_buildid().

gdb/ChangeLog:

2015-06-10  Jon Turney  <jon.turney@dronecode.org.uk>

	* build-id.c: Don't include elf-bfd.h.
	(build_id_bfd_get): Use bfd_build_id.
	(build_id_verify): Ditto.
	* build-id.h: Ditto.
	(find_separate_debug_file_by_buildid): Ditto.
	* python/py-objfile.c: Don't include elf-bfd.h.
	(objfpy_get_build_id) Use bfd_build_id.
	(objfpy_build_id_matches, objfpy_lookup_objfile_by_build_id): Ditto.
	* coffread.c: Include build-id.h.
	(coff_symfile_read): Try find_separate_debug_file_by_buildid.

gdb/doc/ChangeLog:

2015-06-10  Jon Turney  <jon.turney@dronecode.org.uk>

	* gdb.texinfo (Separate Debug Files): Document that PE is also
	supported.

gdb/testsuite/ChangeLog:

2015-06-10  Jon Turney  <jon.turney@dronecode.org.uk>

	* gdb.base/sepdebug.exp: Add EXEEXT where needed.
	* lib/gdb.exp (get_build_id): Teach how to extract build-id from a
	PE file.
	* lib/future.exp (gdb_find_objdump): Add gdb_find_objdump.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2015-06-15 12:10:55 +01:00
Catherine Moore 2f0c68f23b Compact EH Support
The specification for the Compact EH format is available at:
https://github.com/MentorEmbedded/cxx-abi/blob/master/MIPSCompactEH.pdf

2015-05-28  Catherine Moore  <clm@codesourcery.com>
	    Bernd Schmidt <bernds@codesourcery.com>
	    Paul Brook <paul@codesourcery.com>

	bfd/
	* bfd-in2.h: Regenerated.
	* elf-bfd.h (DWARF2_EH_HDR, COMPACT_EH_HDR): Define.
	(COMPACT_EH_CANT_UNWIND_OPCODE): Define.
	(dwarf_eh_frame_hdr_info): Move dwarf-specific fields from
	eh_frame_hdr_info.
	(compact_eh_frame_hdr_info): Declare.
	(eh_frame_hdr_info):  Redeclare with union for dwarf-specific
	fields and compact-eh fields.
	(elf_backend_data): Add cant_unwind_opcode and compact_eh_encoding.
	(bfd_elf_section_data): Add eh_frame_entry_field.
	(elf_section_eh_frame_entry): Define.
	(bfd_elf_parse_eh_frame_entries): Declare.
	(_bfd_elf_parse_eh_frame_entry): Declare.
	(_bfd_elf_end_eh_frame_parsing): Declare.
	(_bfd_elf_write_section_eh_frame_entry): Declare.
	(_bfd_elf_eh_frame_entry_present): Declare.
	(_bfd_elf_section_for_symbol): Declare.
	* elf-eh-frame.c (bfd_elf_discard_eh_frame_entry): New function.
	(bfd_elf_record_eh_frame_entry): New function.
	(_bfd_elf_parse_eh_frame_entry): New function.
	(_bfd_elf_parse_eh_frame): Update hdr_info field references.
	(cmp_eh_frame_hdr): New function.
	(add_eh_frame_hdr_terminator): New function.
	(_bfd_elf_end_eh_frame_parsing): New function.
	(find_merged_cie): Update hdr_info field references.
	(_bfd_elf_discard_section_eh_frame): Likewise.
	(_bfd_elf_discard_section_eh_frame_hdr): Add Compact EH support.
	(_bfd_elf_eh_frame_entry_present): New function.
	(_bfd_elf_maybe_strip_eh_frame_hdr): Add Compact EH support.
	(_bfd_elf_write_section_eh_frame_entry): New function.
	(_bfd_elf_write_section_eh_frame): Update hdr_info field references.
	(_bfd_elf_fixup_eh_frame_hdr): New function.
	(write_compact_eh_frame_hdr): New function.
	(write_dwarf_eh_frame_hdr): New function.
	(_bfd_elf_write_section_eh_frame_hdr): Add Compact EH support.
	* elflink.c (_bfd_elf_section_for_symbol): New function.
	(elf_section_ignore_discarded_relocs): Add Compact EH support.
	(elf_link_input_bfd): Likewise.
	(bfd_elf_final_link): Likewise.
	(_bfd_elf_gc_mark): Likewise.
	(bfd_elf_parse_eh_frame_entries): New function.
	(bfd_elf_gc_sections): Add Compact EH support.
	(bfd_elf_discard_info): Likewise.
	* elfxx-mips.c: Include dwarf2.h.
	(_bfd_mips_elf_compact_eh_encoding): New function.
	(_bfd_mips_elf_cant_unwind_opcode): New function.
	* elfxx-mips.h (_bfd_mips_elf_compact_eh_encoding): Declare.
	(_bfd_mips_elf_cant_unwind_opcode): Declare.
	(elf_backend_compact_eh_encoding): Define.
	(elf_backend_cant_unwind_opcode): Define.
	* elfxx-target.h (elf_backend_compact_eh_encoding): Provide default.
	(elf_backend_cant_unwind_opcode): Provide default.
	(elf_backend_data elfNN_bed): Add elf_backend_compact_eh_encoding and
	elf_backend_cant_unwind_opcode.
	* section.c (SEC_INFO_TYPE_EH_FRAME_ENTRY): Add definition.

	gas/
	* config/tc-alpha.c (all_cfi_sections): Declare.
	(s_alpha_ent): Initialize all_cfi_sections.
	(alpha_elf_md_end): Invoke cfi_set_sections.
	* config/tc-mips.c (md_apply_fix):  Handle BFD_RELOC_NONE.
	(s_ehword): Use BFD_RELOC_32_PCREL.
	(mips_fix_adjustable): Handle BFD_RELOC_32_PCREL.
	(mips_cfi_reloc_for_encoding): New function.
	* tc-mips.h (DWARF2_FDE_RELOC_SIZE): Redefine.
	(DWARF2_FDE_RELOC_ENCODING): Define.
	(tc_cfi_reloc_for_encoding): Define.
	(mips_cfi_reloc_for_encoding): Define.
	(tc_compact_eh_opcode_stop): Define.
	(tc_compact_eh_opcode_pad): Define.
	* doc/as.texinfo: Document Compact EH extensions.
	* doc/internals.texi: Likewise.
	* dw2gencfi.c (EH_FRAME_LINKONCE): Redefine.
	(tc_cfi_reloc_for_encoding): Provide default.
	(compact_eh): Declare.
	(emit_expr_encoded): New function.
	(get_debugseg_name): Add Compact EH support.
	(alloc_debugseg_item): Likewise.
	(cfi_set_sections): New function.
	(dot_cfi_fde_data): New function.
	(dot_cfi_personality_id): New function.
	(dot_cfi_inline_lsda): New function.
	(cfi_pseudo_table): Add cfi_fde_data, cfi_personality_id,
	and cfi_inline_lsda.
	(dot_cfi_personality): Add Compact EH support.
	(dot_cfi_lsda): Likewise.
	(dot_cfi_sections): Likewise.
	(dot_cfi_startproc): Likewise.
	(get_cfi_seg): Likewise.
	(output_compact_unwind_data): New function.
	(output_cfi_insn): Add Compact EH support.
	(output_cie): Likewise.
	(output_fde): Likewise.
	(cfi_finish): Likewise.
	(cfi_emit_eh_header): New function.
	(output_eh_header): New function.
	* dw2gencfi.h (cfi_set_sections): Declare.
	(SUPPORT_COMPACT_EH): Define.
	(MULTIPLE_FRAME_SECTIONS): Define.
	New enumeration to describe the Compact EH header format.
	(fde_entry): Add new fields personality_id, eh_header_type, eh_data_size,
	eh_data, eh_loc and sections.
	(CFI_EMIT_eh_frame, CFI_EMIT_debug_frame, CFI_EMIT_target,
	CFI_EMIT_eh_frame_compact): Define.

2015-05-22  Catherine Moore  <clm@codesourcery.com>
	    Bernd Schmidt <bernds@codesourcery.com>

	gas/testsuite/
	* gas/mips/mips.exp: Run new tests.

	* gas/mips/compact-eh-1.s: New file.
	* gas/mips/compact-eh-2.s: New file.
	* gas/mips/compact-eh-3.s: New file.
	* gas/mips/compact-eh-4.s: New file.
	* gas/mips/compact-eh-5.s: New file.
	* gas/mips/compact-eh-6.s: New file.
	* gas/mips/compact-eh-7.s: New file.
	* gas/mips/compact-eh-eb-1.d: New file.
	* gas/mips/compact-eh-eb-2.d: New file.
	* gas/mips/compact-eh-eb-3.d: New file.
	* gas/mips/compact-eh-eb-4.d: New file.
	* gas/mips/compact-eh-eb-5.d: New file.
	* gas/mips/compact-eh-eb-6.d: New file.
	* gas/mips/compact-eh-eb-7.d: New file.
	* gas/mips/compact-eh-el-1.d: New file.
	* gas/mips/compact-eh-el-2.d: New file.
	* gas/mips/compact-eh-el-3.d: New file.
	* gas/mips/compact-eh-el-4.d: New file.
	* gas/mips/compact-eh-el-5.d: New file.
	* gas/mips/compact-eh-el-6.d: New file.
	* gas/mips/compact-eh-el-7.d: New file.
	* gas/mips/compact-eh-err1.l: New file.
	* gas/mips/compact-eh-err1.s: New file.
	* gas/mips/compact-eh-err2.l: New file.
	* gas/mips/compact-eh-err2.s: New file.

2015-05-22  Catherine Moore  <clm@codesourcery.com>

	include/
	* bfdlink.h: Rename eh_frame_hdr to eh_frame_hdr_type.

2015-05-22  Catherine Moore  <clm@codesourcery.com>
	    Paul Brook <paul@codesourcery.com>

	ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open):
	Add Compact EH support.
	* scripttempl/elf.sc: Handle .eh_frame_entry and .gnu_extab
	sections.

2015-05-22  Catherine Moore  <clm@codesourcery.com>

	ld/testsuite/
	* ld-mips-elf/compact-eh.ld: New linker script.
	* ld-mips-elf/compact-eh1.d: New.
	* ld-mips-elf/compact-eh1.s: New.
	* ld-mips-elf/compact-eh1a.s: New.
	* ld-mips-elf/compact-eh1b.s: New.
	* ld-mips-elf/compact-eh2.d: New.
	* ld-mips-elf/compact-eh2.s: New.
	* ld-mips-elf/compact-eh3.d: New.
	* ld-mips-elf/compact-eh3.s: New.
	* ld-mips-elf/compact-eh3a.s: New.
	* ld-mips-elf/compact-eh4.d: New.
	* ld-mips-elf/compact-eh5.d: New.
	* ld-mips-elf/compact-eh6.d: New.
	* ld-mips-elf/mips-elf.exp: Run new tests.
2015-05-28 15:21:17 -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 bd53a53af4 Properly set sh_info for .rela.plt/rel.plt section
Since .rela.plt/rel.plt section may contain relocations against .got.plt
section, we set sh_info for .rela.plt/rel.plt section to .got.plt section
index if target has .got.plt section.

bfd/

	PR ld/18169
	* elf-bfd.h (elf_backend_data): Add get_reloc_section.
	(_bfd_elf_get_reloc_section): New.
	* elf.c (_bfd_elf_get_reloc_section): Likewise.
	(assign_section_numbers): Call get_reloc_section to look up the
	section the relocs apply.
	* elfxx-target.h (elf_backend_get_reloc_section): Likewise.
	(elfNN_bed): Initialize get_reloc_section with
	elf_backend_get_reloc_section.

ld/testsuite/

	PR ld/18169
	* ld-elf/linkinfo1a.d: Updated.
	* ld-elf/linkinfo1b.d: Likewise.
2015-03-30 04:40:49 -07:00
Alan Modra b84171287f Relax PR 15228 protected visibility restriction
Allows .dynbss copy of shared library protected visibility variables
if they are read-only.

To recap: Copying a variable from a shared library into an executable's
.dynbss is an old hack invented for non-PIC executables, to avoid the
text relocations you'd otherwise need to access a shared library
variable.  This works with ELF shared libraries because global
symbols can be overridden.  The trouble is that protected visibility
symbols can't be overridden.  A shared library will continue to access
it's own protected visibility variable while the executable accesses a
copy.  If either the shared library or the executable updates the
value then the copy diverges from the original.  This is wrong since
there is only one definition of the variable in the application.

So I made the linker report an error on attempting to copy protected
visibility variables into .dynbss.  However, you'll notice the above
paragraph contains an "If".  An application that does not modify the
variable value remains correct even though two copies of the variable
exist.  The linker can detect this situation if the variable was
defined in a read-only section.

	PR ld/15228
	PR ld/18167
	* elflink.c (elf_merge_st_other): Add "sec" parameter.  Don't set
	protected_def when symbol section is read-only.  Adjust all calls.
	* elf-bfd.h (struct elf_link_hash_entry): Update protected_def comment.
2015-03-27 16:20:32 +10: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
Andreas Arnez 4ef9f41a95 S390: Support new vector register sections
The IBM z13 has new 128-bit wide vector registers v0-v31, where v0-v15
include the existing 64-bit wide floating point registers.  The Linux
kernel presents the vector registers as two additional register sets,
one for the right halves of v0-v15 and another one for the full
registers v16-v31.  Thus a new core file may contain two new register
note sections, and this patch adds support to binutils for them.

bfd/
	* elf-bfd.h (elfcore_write_s390_vxrs_low): Add prototype.
	(elfcore_write_s390_vxrs_high): Likewise.
	* elf.c (elfcore_grok_s390_vxrs_low): New function.
	(elfcore_grok_s390_vxrs_high): New function.
	(elfcore_grok_note): Call them.
	(elfcore_write_s390_vxrs_low): New function.
	(elfcore_write_s390_vxrs_high): New function.
	(elfcore_write_register_note): Call them.

binutils/
	* readelf.c (get_note_type): Add NT_S390_VXRS_LOW and
	NT_S390_VXRS_HIGH.

include/elf/
	* common.h (NT_S390_VXRS_LOW): New macro.
	(NT_S390_VXRS_HIGH): Likewise.
2015-02-20 10:39:53 +01:00
Pedro Alves 55172d69d0 Wrap BFD headers in extern "C"
These were the BFD changes needed for building a C++ GDB with
--enable-targets=all, on x86_64 Fedora 20.

For libbfd.h and libcoff.h, this does same as already done when
generating bfd.h: open extern "C" in the -in.h header, and close it
from the Makefile.

bfd/doc/ChangeLog:
2015-02-11  Pedro Alves  <palves@redhat.com>

	* Makefile.am (libbfd.h, libcoff.h): Close extern "C" scope.
	* Makefile.in: Regenerate.

bfd/ChangeLog:
2015-02-11  Pedro Alves  <palves@redhat.com>

	* libbfd-in.h [__cplusplus]: Open extern "C" scope.
	* libcoff-in.h [__cplusplus]: Open extern "C" scope.
	* libbfd.h: Regenerate.
	* libcoff.h: Regenerate.

	* elf-bfd.h [__cplusplus]: Wrap in extern "C".
	* mach-o.h [__cplusplus]: Wrap in extern "C".
	* som.h [__cplusplus]: Wrap in extern "C".
2015-02-11 10:04:47 +00:00
Alan Modra c4621b339e Fix garbage collection of common symbols
Running lang_common before garbage collection means slightly less work
in garbage collection code, since common symbols should no longer
appear there.  It does have the side effect of keeping linker script
symbols (at least those defined outside of sections) global too,
hence some testsuite churn.

bfd/
	PR 17165
	* elf-bfd.h (ELF_COMMON_DEF): Note that this might be true for
	linker script assignments too.
	* elflink.c (elf_gc_sweep_symbol): Don't drop ELF_COMMON_DEF syms.
	(bfd_elf_gc_mark_dynamic_ref_symbol): Similarly.
ld/
	PR 17165
	* ldlang.c (lang_process): Run lang_common before lang_gc_sections.
ld/testsuite/
	* ld-gc/pr14265.d,
	* ld-cris/tls-gc-68.d,
	* ld-cris/tls-gc-69.d,
	* ld-cris/tls-gc-70.d,
	* ld-cris/tls-gc-71.d,
	* ld-cris/tls-gc-75.d,
	* ld-cris/tls-gc-76.d,
	* ld-cris/tls-gc-79.d,
	* ld-mmix/bpo-10.d,
	* ld-mmix/bpo-11.d: Update.
2015-01-19 21:26:30 +10:30
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