Commit Graph

13983 Commits

Author SHA1 Message Date
H.J. Lu 7c0ed39626 Call _close_and_cleanup in bfd_close_all_done
PR binutils/22032
	* opncls.c (bfd_close_all_done): Call _close_and_cleanup.
2017-08-30 06:22:52 -07:00
H.J. Lu 0f2425c4c8 Remove elf_x86_64_next_tls_desc_index/elf_x86_64_srelplt2
They are unused.

	* elf64-x86-64.c (elf_x86_64_next_tls_desc_index): Removed.
	(elf_x86_64_srelplt2): Likewise.
2017-08-30 05:29:22 -07:00
H.J. Lu 443701f509 Add missing ChangeLog entries 2017-08-30 05:28:10 -07:00
Alan Modra 9a23f96e91 PowerPC TPREL16_HA/LO reloc optimization
In the TLS GD/LD to LE optimization, ld replaces a sequence like

 addi 3,2,x@got@tlsgd		R_PPC64_GOT_TLSGD16	x
 bl __tls_get_addr(x@tlsgd)	R_PPC64_TLSGD		x
				R_PPC64_REL24		__tls_get_addr
 nop

with

 addis 3,13,x@tprel@ha		R_PPC64_TPREL16_HA	x
 addi 3,3,x@tprel@l		R_PPC64_TPREL16_LO	x
 nop

When the tprel offset is small, this can be further optimized to

 nop
 addi 3,13,x@tprel
 nop

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add do_tls_opt.
	(ppc64_elf_tls_optimize): Set it.
	(ppc64_elf_relocate_section): Nop addis on TPREL16_HA, and convert
	insn on TPREL16_LO and TPREL16_LO_DS relocs to use r13 when
	addis would add zero.
	* elf32-ppc.c (struct ppc_elf_link_hash_table): Add do_tls_opt.
	(ppc_elf_tls_optimize): Set it.
	(ppc_elf_relocate_section): Nop addis on TPREL16_HA, and convert
	insn on TPREL16_LO relocs to use r2 when addis would add zero.
gold/
	* powerpc.cc (Target_powerpc::Relocate::relocate): Nop addis on
	TPREL16_HA, and convert insn on TPREL16_LO and TPREL16_LO_DS
	relocs to use r2/r13 when addis would add zero.
ld/
	* testsuite/ld-powerpc/tls.s: Add calls with tls markers.
	* testsuite/ld-powerpc/tls32.s: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Run tls marker tests.
	* testsuite/ld-powerpc/tls.d: Adjust for TPREL16_HA/LO optimization.
	* testsuite/ld-powerpc/tlsexe.d: Likewise.
	* testsuite/ld-powerpc/tlsexetoc.d: Likewise.
	* testsuite/ld-powerpc/tlsld.d: Likewise.
	* testsuite/ld-powerpc/tlsmark.d: Likewise.
	* testsuite/ld-powerpc/tlsopt4.d: Likewise.
	* testsuite/ld-powerpc/tlstoc.d: Likewise.
2017-08-30 20:43:31 +09:30
Alan Modra b9f04fe0df PowerPC64 __tls_get_addr sequence optimization
There isn't a good reason for ld.bfd to behave differently from gold
in the code generated by TLS GD/LD to LE optimization.

bfd/
	* elf64-ppc.c (ppc64_elf_relocate_section): When optimizing
	__tls_get_addr call sequences to LE, don't move the addi down
	to the nop.  Replace the bl with addi and leave the nop alone.
ld/
	* testsuite/ld-powerpc/tls.d: Update.
	* testsuite/ld-powerpc/tlsexe.d: Update.
	* testsuite/ld-powerpc/tlsexetoc.d: Update.
	* testsuite/ld-powerpc/tlsld.d: Update.
	* testsuite/ld-powerpc/tlsmark.d: Update.
	* testsuite/ld-powerpc/tlsopt4.d: Update.
	* testsuite/ld-powerpc/tlstoc.d: Update.
2017-08-30 20:35:09 +09:30
GDB Administrator 22e5c8027a Automatic date update in version.in 2017-08-30 00:00:21 +00:00
H.J. Lu 5f0f0847e2 x86: Re-indent elf32-i386.c/elf64-x86-64.c
* elf32-i386.c (elf_i386_pie_finish_undefweak_symbol):
	Re-indent.
	* elf64-x86-64.c (elf_x86_64_finish_local_dynamic_symbol):
	Likewise.
	(elf_x86_64_pie_finish_undefweak_symbol): Likewise.
2017-08-29 14:44:40 -07:00
H.J. Lu 0afcef5384 Add elfxx-x86.h and elfxx-x86.c
Move common codes in elf32-i386.c and elf64-x86-64.c to elfxx-x86.c.

	* Makefile.am (BFD32_BACKENDS): Add elfxx-x86.lo.
	(BFD64_BACKENDS): Likewise.
	(BFD32_BACKENDS_CFILES): Add elfxx-x86.c.
	(BFD64_BACKENDS_CFILES): Likewise.
	* Makefile.in: Regenerated.
	* configure.ac (bfd_backends): Add elfxx-x86.lo together with
	elf32-i386.lo and elf64-x86-64.lo.
	* configure: Regenerated.
	* elf32-i386.c: Include "elfxx-x86.h" instead of "sysdep.h",
	"bfd.h", "bfdlink.h", "libbfd.h", "elf-bfd.h", "bfd_stdint.h",
	"objalloc.h" and "hashtab.h".
	(ELIMINATE_COPY_RELOCS): Removed.
	(UNDEFINED_WEAK_RESOLVED_TO_ZERO):Likewise.
	(SYMBOL_NO_COPYRELOC): Likewise.
	(elf_i386_link_hash_entry): Likewise.
	(GOT_UNKNOWN): Likewise.
	(GOT_NORMAL): Likewise.
	(GOT_TLS_GD): Likewise.
	(elf_i386_hash_entry): Likewise.
	(elf_i386_obj_tdata): Likewise.
	(elf_i386_tdata): Likewise.
	(elf_i386_local_got_tls_type): Likewise.
	(elf_i386_local_tlsdesc_gotent): Likewise.
	(elf_i386_hash_table): Likewise.
	(elf_i386_link_hash_newfunc): Likewise.
	(elf_i386_local_htab_hash): Likewise.
	(elf_i386_local_htab_eq): Likewise.
	(elf_i386_get_local_sym_hash): Likewise.
	(elf_i386_link_hash_table_free): Likewise.
	(elf_i386_copy_indirect_symbol): Likewise.
	(elf_i386_fixup_symbol): Likewise.
	(elf_i386_readonly_dynrelocs): Likewise.
	(elf_i386_always_size_sections): Likewise.
	(elf_i386_set_tls_module_base): Likewise.
	(elf_i386_dtpoff_base): Likewise.
	(compare_relocs): Likewise.
	(elf_i386_hash_symbol): Likewise.
	(elf_i386_parse_gnu_properties): Likewise.
	(elf_i386_merge_gnu_properties): Likewise.
	(elf_i386_link_check_relocs): Likewise.
	(elf_i386_merge_symbol_attribute): Likewise.
	(bfd_elf32_bfd_link_check_relocs): Likewise.
	(elf_backend_copy_indirect_symbol): Likewise.
	(elf_backend_always_size_sections): Likewise.
	(elf_backend_omit_section_dynsym): Likewise.
	(elf_backend_hash_symbol): Likewise.
	(elf_backend_fixup_symbol): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	(elf_backend_merge_symbol_attribute): Likewise.
	(elf_i386_mkobject): Updated.
	(elf_i386_link_hash_table_create): Likewise.
	(elf_i386_check_tls_transition): Likewise.
	(elf_i386_tls_transition): Likewise.
	(elf_i386_convert_load_reloc): Likewise.
	(elf_i386_check_relocs): Likewise.
	(elf_i386_adjust_dynamic_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_convert_load): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol ): Likewise.
	(elf_i386_finish_dynamic_sections): Likewise.
	(elf_i386_output_arch_local_syms): Likewise.
	(elf_i386_get_synthetic_symtab): Likewise.
	(elf_i386_link_setup_gnu_properties): Likewise.
	(elf_i386_link_hash_table): Use elf_x86_link_hash_table, instead
	of elf_link_hash_table, as base.
	(elf_i386_next_tls_desc_index): New.
	(elf_i386_srelplt2): Likewise.
	(elf_i386_plt): Likewise.
	(elf_i386_lazy_plt): Likewise.
	(elf_i386_non_lazy_plt): Likewise.
	* elf32-x86-64.c: Include "elfxx-x86.h" instead of "sysdep.h",
	"bfd.h", "bfdlink.h", "libbfd.h", "elf-bfd.h", "bfd_stdint.h",
	"objalloc.h" and "hashtab.h".
	(ELIMINATE_COPY_RELOCS): Removed.
	(UNDEFINED_WEAK_RESOLVED_TO_ZERO):Likewise.
	(SYMBOL_NO_COPYRELOC): Likewise.
	(elf_x86_64_link_hash_entry): Likewise.
	(GOT_UNKNOWN): Likewise.
	(GOT_NORMAL): Likewise.
	(GOT_TLS_GD): Likewise.
	(elf_x86_64_hash_entry): Likewise.
	(elf_x86_64_obj_tdata): Likewise.
	(elf_x86_64_tdata): Likewise.
	(elf_x86_64_local_got_tls_type): Likewise.
	(elf_x86_64_local_tlsdesc_gotent): Likewise.
	(elf_x86_64_hash_table): Likewise.
	(elf_x86_64_link_hash_newfunc): Likewise.
	(elf_x86_64_local_htab_hash): Likewise.
	(elf_x86_64_local_htab_eq): Likewise.
	(elf_x86_64_get_local_sym_hash): Likewise.
	(elf_x86_64_link_hash_table_free): Likewise.
	(elf_x86_64_copy_indirect_symbol): Likewise.
	(elf_x86_64_fixup_symbol): Likewise.
	(elf_x86_64_readonly_dynrelocs): Likewise.
	(elf_x86_64_always_size_sections): Likewise.
	(elf_x86_64_set_tls_module_base): Likewise.
	(elf_x86_64_dtpoff_base): Likewise.
	(compare_relocs): Likewise.
	(elf_x86_64_merge_symbol_attribute): Likewise.
	(elf_x86_64_hash_symbol): Likewise.
	(elf_x86_64_parse_gnu_properties): Likewise.
	(elf_x86_64_merge_gnu_properties): Likewise.
	(elf_x86_64_link_check_relocs): Likewise.
	(elf_backend_copy_indirect_symbol): Likewise.
	(elf_backend_always_size_sections): Likewise.
	(bfd_elf64_bfd_link_check_relocs): Likewise.
	(elf_backend_merge_symbol_attribute): Likewise.
	(elf_backend_hash_symbol): Likewise.
	(elf_backend_omit_section_dynsym): Likewise.
	(elf_backend_fixup_symbol): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	(bfd_elf32_bfd_link_check_relocs): Likewise.
	(elf_x86_64_mkobject): Updated.
	(elf_x86_64_link_hash_table_create): Likewise.
	(elf_x86_64_check_tls_transition): Likewise.
	(elf_x86_64_tls_transition): Likewise.
	(elf_x86_64_convert_load_reloc): Likewise.
	(elf_x86_64_check_relocs): Likewise.
	(elf_x86_64_adjust_dynamic_symbol): Likewise.
	(elf_x86_64_allocate_dynrelocs): Likewise.
	(elf_x86_64_convert_load): Likewise.
	(elf_x86_64_size_dynamic_sections): Likewise.
	(elf_x86_64_relocate_section): Likewise.
	(elf_x86_64_finish_dynamic_symbol ): Likewise.
	(elf_x86_64_finish_dynamic_sections): Likewise.
	(elf_x86_64_output_arch_local_syms): Likewise.
	(elf_x86_64_get_synthetic_symtab): Likewise.
	(elf_x86_64_link_setup_gnu_properties): Likewise.
	(elf_x86_64_link_hash_table): Use elf_x86_link_hash_table,
	instead of elf_link_hash_table, as base.
	(elf_x86_64_next_tls_desc_index): New.
	(elf_x86_64_srelplt2): Likewise.
	(elf_x86_64_plt): Likewise.
	(elf_x86_64_lazy_plt): Likewise.
	(elf_x86_64_non_lazy_plt): Likewise.
	* elfxx-x86.c: New file.
	* elfxx-x86.h: Likewise.
2017-08-29 12:58:51 -07:00
H.J. Lu 823cb06774 x86: Simplify bad return in get_synthetic_symtab
* elf32-i386.c (elf_i386_get_synthetic_symtab): Simplify bad
	return.
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
2017-08-29 11:28:10 -07:00
H.J. Lu 37c0b6ee65 x86: Check valid PLT sections before checking dynamic relocations
Update x86 get_synthetic_symtab to check valid PLT sections before
checking dynamic relocations and free invalid PLT section contents.

	* elf32-i386.c (elf_i386_get_synthetic_symtab): Check valid PLT
	sections before checking dynamic relocations and free invalid
	PLT section contents.
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
2017-08-29 10:40:03 -07:00
GDB Administrator f2d394fce1 Automatic date update in version.in 2017-08-29 00:01:09 +00:00
H.J. Lu 0fb0a76778 Remove unused _bfd_elf_ifunc_get_synthetic_symtab
Since _bfd_elf_ifunc_get_synthetic_symtab is no longer called by x86
get_synthetic_symtab, it is now unused.  This patch removes it.

	* elf-bfd.h (_bfd_elf_ifunc_get_synthetic_symtab): Removed.
	* elf-ifunc.c (_bfd_elf_ifunc_get_synthetic_symtab): Likewise.
2017-08-28 15:40:00 -07:00
H.J. Lu 90efb64229 x86: Check for valid PLT section size
Update x86 get_synthetic_symtab to check for valid PLT section size
before examining PLT section contents.

	PR binutils/22018
	* elf32-i386.c (elf_i386_get_synthetic_symtab): Check for valid
	PLT section size.
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
2017-08-28 11:25:58 -07:00
GDB Administrator 41e5237748 Automatic date update in version.in 2017-08-28 00:00:46 +00:00
H.J. Lu 596dc58f33 x86: Initialize def_protected
* elf32-i386.c (elf_i386_link_hash_newfunc): Initialize
	def_protected.
	* elf64-x86-64.c (elf_x86_64_link_hash_newfunc): Likewise.
2017-08-27 07:23:40 -07:00
H.J. Lu a5b4ee9451 Disallow copy relocation against protected data symbol
We shpouldn't generate copy relocation to resolve reference to protected
data symbol defined in shared object with the NO_COPY_ON_PROTECTED
property.  This patch adds a bit to elf_obj_tdata as well as
elf_i386_link_hash_entry and elf_x86_64_link_hash_entry to track the bfd
with the NO_COPY_ON_PROTECTED property as well as protected symbol
defined in shared object.  extern_protected_data is set to FALSE if any
input relocatable file contains the NO_COPY_ON_PROTECTED property.

bfd/

	PR ld/21997
	* elf-bfd.h (elf_obj_tdata): Use ENUM_BITFIELD on object_id,
	dyn_lib_class and has_gnu_symbols.  Change bad_symtab to bitfield.
	Add a has_no_copy_on_protected bitfield.
	(elf_has_no_copy_on_protected): New.
	* elf-properties.c (_bfd_elf_parse_gnu_properties): Set
	elf_has_no_copy_on_protected for GNU_PROPERTY_NO_COPY_ON_PROTECTED.
	(elf_merge_gnu_property_list): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Set extern_protected_data
	to FALSE for elf_has_no_copy_on_protected.
	* elf32-i386.c (SYMBOL_NO_COPYRELOC): New.
	(elf_i386_link_hash_entry): Add def_protected.
	(elf_i386_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC
	when checking info->nocopyreloc.
	(elf_i386_link_setup_gnu_properties): Don't set
	extern_protected_data here.
	(elf_i386_merge_symbol_attribute): New function.
	(elf_backend_merge_symbol_attribute): New.
	* elf64-x86-64.c (SYMBOL_NO_COPYRELOC): New.
	(elf_x86_64_link_hash_entry): Add def_protected.
	(elf_x86_64_need_pic): Report protected symbol for def_protected.
	(elf_x86_64_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC
	when checking info->nocopyreloc.
	(elf_x86_64_relocate_section): Also check for R_X86_64_PC32
	relocation run-time overflow and unresolvable R_X86_64_32S
	relocation against protected data symbol defined in shared object
	with GNU_PROPERTY_NO_COPY_ON_PROTECTED.
	(elf_x86_64_link_setup_gnu_properties): Don't set
	extern_protected_data here.
	(elf_x86_64_merge_symbol_attribute): New function.
	(elf_backend_merge_symbol_attribute): New.

ld/

	PR ld/21997
	* testsuite/ld-i386/i386.exp: Run PR ld/21997 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr21997-1a.S: New file.
	* testsuite/ld-i386/pr21997-1b.c: Likewise.
	* testsuite/ld-i386/pr21997-1c.S: Likewise.
	* testsuite/ld-x86-64/pr21997-1a.S: Likewise.
	* testsuite/ld-x86-64/pr21997-1a.err: Likewise.
	* testsuite/ld-x86-64/pr21997-1b.c: Likewise.
	* testsuite/ld-x86-64/pr21997-1b.err: Likewise.
	* testsuite/ld-x86-64/pr21997-1c.c: Likewise.
2017-08-26 19:26:21 -07:00
GDB Administrator aecbb010f9 Automatic date update in version.in 2017-08-27 00:00:52 +00:00
Alan Modra 7c8bbca5e6 PowerPC TPREL reloc handling
Tidy how these are handled in PIEs.

	* elf32-ppc.c (must_be_dyn_reloc): Use bfd_link_dll.  Comment.
	(ppc_elf_check_relocs): Only set DF_STATIC_TLS in shared libs.
	(ppc_elf_relocate_section): Comment fix.
	* elf64-ppc.c (must_be_dyn_reloc): Use bfd_link_dll.  Comment.
	(ppc64_elf_check_relocs): Only set DF_STATIC_TLS in shared libs.
	Support dynamic relocs for TPREL16 when non-pic too.
	(dec_dynrel_count): Adjust TPREL16 handling as per check_relocs.
	(ppc64_elf_relocate_section): Support dynamic relocs for TPREL16
	when non-pic too.
2017-08-26 20:52:07 +09:30
H.J. Lu 5fdda9d6a4 x86: Remove redundant "symbol" in comments
* elf32-i386.c (elf_i386_link_hash_entry): Remove redundant
	"symbol" in comments.
	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Likewise.
2017-08-25 17:13:58 -07:00
GDB Administrator 7d5b8b81d3 Automatic date update in version.in 2017-08-26 00:01:04 +00:00
GDB Administrator a2d64ef20b Automatic date update in version.in 2017-08-25 00:01:00 +00:00
H.J. Lu 7073b5b9ed x86-64: Check relocations with -z nocopyreloc
On x86-64, when -z nocopyreloc is used to build executable, relocations
may overflow at run-time or may not be resolved without PIC.  This patch
checks these conditions and issues an error with suggestion for -fPIC.

bfd/

	PR ld/22001
	* elf64-x86-64.c (elf_x86_64_relocate_section): Check for
	R_X86_64_PC32 relocation run-time overflow and unresolvable
	R_X86_64_32S relocation with -z nocopyreloc.

ld/

	PR ld/22001
	* testsuite/ld-i386/i386.exp: Run -z nocopyreloc tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* ld/testsuite/ld-i386/pr22001-1a.c: New file.
	* ld/testsuite/ld-i386/pr22001-1b.c: Likewise.
	* ld/testsuite/ld-i386/pr22001-1c.S: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1a.c: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1a.err: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1b.c: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1b.err: Likewise.
	* ld/testsuite/ld-x86-64/pr22001-1c.c: Likewise.
2017-08-24 06:34:38 -07:00
H.J. Lu 34bb2571d4 Revert commit aab921adcb
* elf32-i386.c (elf_i386_check_relocs): Revert the last change.
	Undefined symbols may not have a type.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2017-08-24 03:35:44 -07:00
GDB Administrator f8d31560e1 Automatic date update in version.in 2017-08-24 00:00:38 +00:00
H.J. Lu aab921adcb x86-64: Properly report output type when PIC is needed
-fPIC may be needed to compile PIE or PDE objects, not just shared
object.

bfd/

	* elf64-x86-64.c (elf_x86_64_need_pic): Add an argument for
	bfd_link_info.  Report shared, PIE or PDE object based on
	bfd_link_info.
	(elf_x86_64_check_relocs): Update elf_x86_64_need_pic call.
	(elf_x86_64_relocate_section): Likewise.

ld/

	* testsuite/ld-x86-64/pie2.d: Updated.
	* testsuite/ld-x86-64/pr19719.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19969.d: Likewise.
2017-08-23 13:43:45 -07:00
H.J. Lu b1bb697ea1 x86: Increment PLT count only for function symbols
Since PLT entry is needed only for function symbols, increment PLT count
only for function symbols.

	* elf32-i386.c (elf_i386_check_relocs): Increment PLT count only
	for function symbols.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2017-08-23 13:12:04 -07:00
H.J. Lu 73784fa565 x86: Clear extern_protected_data for GNU_PROPERTY_NO_COPY_ON_PROTECTED
When GNU_PROPERTY_NO_COPY_ON_PROTECTED is set, it indicates that there
are no copy relocations against protected data symbols.  When linker
sees GNU_PROPERTY_NO_COPY_ON_PROTECTED on any input relocatable file,
it sets extern_protected_data to FALSE.

bfd/

	* elf32-i386.c (elf_i386_link_setup_gnu_properties): Set
	extern_protected_data to FALSE if GNU_PROPERTY_NO_COPY_ON_PROTECTED
	is set on any input relocatable file.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Run protected7.
	* testsuite/ld-i386/protected7.d: New file.
	* testsuite/ld-i386/protected7.s: Likewise.
	* testsuite/ld-x86-64/protected8.d: Likewise.
	* testsuite/ld-x86-64/protected8.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run protected8.
2017-08-23 10:15:58 -07:00
GDB Administrator 98973784dc Automatic date update in version.in 2017-08-23 00:00:48 +00:00
Alan Modra 46434633f9 Make undefined symbols in allocate_dynrelocs dynamic
..if they have dynamic relocs.  An undefined symbol in a PIC object
that finds no definition ought to become dynamic in order to support
--allow-shlib-undefined, but there is nothing in the generic ELF
linker code to do this if the reference isn't via the GOT or PLT.  (An
initialized function pointer is an example.)  So it falls to backend
code to ensure the symbol is made dynamic.

	PR 21988
	* elf64-ppc.c (ensure_undef_dynamic): Rename from
	ensure_undefweak_dynamic.  Handle undefined too.
	* elf32-ppc.c (ensure_undef_dynamic): Likewise.
	* elf32-hppa.c (ensure_undef_dynamic): Likewise.
	(allocate_dynrelocs): Discard undefined non-default visibility
	relocs first.  Make undefined syms dynamic.  Tidy goto.
2017-08-23 08:58:08 +09:30
Alan Modra 487b6440da Make __start/__stop symbols protected visibility
They can't be hidden visibility since apparently people use dlsym to
look them up.

bfd/
	PR ld/21964
	* elf-bfd.h (SYMBOLIC_BIND): Return TRUE for __start/__stop symbols.
	* elflink.c (bfd_elf_define_start_stop): Rewrite.
ld/
	PR ld/21964
	* testsuite/ld-elf/pr21562a.d: Update for changed start/stop symbols.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/sizeofa.d: Likewise.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
	* testsuite/ld-gc/pr20022.d: Likewise.
	* testsuite/ld-gc/start.d: Likewise.
	* testsuite/ld-elf/pr21964-1a.c: New file.
	* testsuite/ld-elf/pr21964-1b.c: New file.
	* testsuite/ld-elf/pr21964-2a.c: New file.
	* testsuite/ld-elf/pr21964-2b.c: New file.
	* testsuite/ld-elf/shared.exp: Run PR ld/21964 tests.
2017-08-21 23:29:29 +09:30
Hans-Peter Nilsson 284d826d9f PR ld/20125, MMIX weak symbols
Weak undefineds with PUSHJ relocs were "lost", causing internal
inconsistencies and an abort.
2017-08-21 03:43:35 +02:00
GDB Administrator 454c9bb956 Automatic date update in version.in 2017-08-21 00:00:41 +00:00
GDB Administrator 45aee2da6b Automatic date update in version.in 2017-08-20 00:00:47 +00:00
GDB Administrator d7dec582d1 Automatic date update in version.in 2017-08-19 00:00:44 +00:00
Nick Clifton de25939739 Fix buffer overrun parsing a corrupt tekhex binary.
PR binutils/21962
	* tekhex.c (getsym): Fix check for source pointer walking off the
	end of the input buffer.
2017-08-18 08:45:12 +01:00
GDB Administrator dd66b39984 Automatic date update in version.in 2017-08-18 00:00:54 +00:00
Szabolcs Nagy 545bc2b377 [AArch64] Skip IFUNC relocations in debug sections
Skip IFUNC relocations in debug sections ignored by ld.so.
Fixes the following ld test failures on aarch64:

FAIL: Build libpr18808.so
FAIL: Build libpr18808.so_2
FAIL: Run pr18808

aborting at bfd/elfnn-aarch64.c:4986 in elf64_aarch64_final_link_relocate.

bfd/
	PR ld/18808
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Skip IFUNC
	relocations in debug sections, change abort to _bfd_error_handler.
2017-08-17 14:48:03 +01:00
GDB Administrator 8c1d4b8799 Automatic date update in version.in 2017-08-17 00:01:00 +00:00
GDB Administrator 1a457753cf Automatic date update in version.in 2017-08-16 00:13:28 +00:00
Nick Clifton 0c54f69295 Fix null pointer dereference when parsing a corrupt ELF binary.
PR 21957
	* elf.c (setup_group): Check for an empty or very small group
	section.
	* po/bfd.pot: Regenerate.
2017-08-14 12:09:36 +01:00
GDB Administrator d7f00f429a Automatic date update in version.in 2017-08-14 00:01:33 +00:00
Alan Modra 79a94a2ad1 PR21441, Unnecessary padding of .eh_frame section
Until all .eh_frame sections have been edited we don't know their
sizes.  So it isn't possible to properly decide whether a non-empty
.eh_frame section follows a given section until editing is complete.

bfd/
	PR 21441
	* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't add
	alignment padding here.
	* elflink.c (bfd_elf_discard_info): Add .eh_frame padding here
	in a reverse pass over sections.
ld/
	PR 21441
	* testsuite/ld-x86-64/pr21038a.d: Adjust.
	* testsuite/ld-x86-64/pr21038a-now.d: Adjust.
2017-08-14 09:25:17 +09:30
GDB Administrator 9ba349b544 Automatic date update in version.in 2017-08-13 00:00:56 +00:00
GDB Administrator 1a682d061c Automatic date update in version.in 2017-08-12 00:00:57 +00:00
H.J. Lu 98c5dfc994 x86: Allocate space for symbol names with symbol table
When synthesizing symbols for PLT entries, allocate space for symbol
names with @plt suffixes together with symbol table so that all memory
is returned when symbol table is freed.

	PR binutils/21943
	* elf32-i386.c (elf_i386_get_synthetic_symtab): Allocate space
	for @plt suffixes first.
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
2017-08-11 09:40:39 -07:00
GDB Administrator 5af3691c75 Automatic date update in version.in 2017-08-11 00:01:26 +00:00
Nick Clifton 957e1fc1c5 Fix out of bounds memory access when trying to allocate space for a note of size -1.
PR 21933
	* elf.c (elf_read_notes): Check for a note size of -1.
2017-08-10 09:37:36 +01:00
GDB Administrator 3ecaa9fd72 Automatic date update in version.in 2017-08-10 00:01:40 +00:00
GDB Administrator a26c49b78a Automatic date update in version.in 2017-08-09 00:00:58 +00:00
Nick Clifton 24d3e51bf0 Fix address violation problems when parsing corrupt ELF binaries.
PR 21916
	* elf-attrs.c (_bfd_elf_parse_attributes): Complain about very
	small section lengths.
	* elf.c (_bfd_elf_setup_sections): Skip empty entries in the group
	table.
	(elfcore_grok_freebsd_prstatus): Add checks to make sure that
	there is enough data present in the note.
2017-08-08 13:20:02 +01:00
Alan Modra 206c9c79ee PR21017, microblaze missing _GLOBAL_OFFSET_TABLE_ symbol
PR 21017
	* elf32-microblaze.c (microblaze_elf_check_relocs): Don't bump
	got.refcount for GOTOFF relocs, just create .got section.
2017-08-08 14:08:43 +09:30
GDB Administrator 5d1ceb0b87 Automatic date update in version.in 2017-08-08 00:00:54 +00:00
H.J. Lu 2980ccad59 Move common symbol check after bed->common_definition
bfd/

	* elflink.c (elf_link_add_object_symbols): Move common symbol
	check after bed->common_definition.

ld/

	* testsuite/ld-elf/pr21903.s (start): Removed.
	(_start): Likewise.
	(__start): Likewise.
	(main): Likewise.
	(bar): New.
2017-08-07 08:02:29 -07:00
Alan Modra b3293efaf8 PR21910, segfault in common symbol override test when hash-style=gnu
PR 21910
	* elflink.c (bfd_elf_final_link): Don't segfault when sections
	needed to define various dynamic tags have been discarded.
2017-08-07 21:26:09 +09:30
Nick Clifton b7a18930e3 Do not choose a non-ELF format input file to hold the linker created GOT sections.
PR 21884
	* elf32-i386.c (elf_i386_link_setup_gnu_properties): If the dynobj
	has not been set then use the bfd returned by
	_bfd_elf_link_setup_gnu_properties.  If that is null then search
	through all the input bfds selecting the first normal, ELF format
	one.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Likewise.
2017-08-07 10:09:51 +01:00
GDB Administrator 2010d1a3f8 Automatic date update in version.in 2017-08-07 00:01:03 +00:00
H.J. Lu 1d4af308ae x86: Lookup __tls_get_addr or ___tls_get_addr once
Instead of checking if a symbol is __tls_get_addr or ___tls_get_addr,
we check if there is a reference to __tls_get_addr or ___tls_get_addr
before starting relocation check.

	* elf32-i386.c (elf_i386_link_hash_entry): Change tls_get_addr
	to 1 bit.
	(elf_i386_link_hash_newfunc): Initialize tls_get_addr to 0.
	(elf_i386_check_tls_transition): Check tls_get_addr directly.
	(elf_i386_convert_load_reloc): Update tls_get_addr check.
	(elf_i386_link_check_relocs): New function.
	(bfd_elf32_bfd_link_check_relocs): New.
	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Change tls_get_addr
	to 1 bit.
	(elf_x86_64_link_hash_newfunc): Initialize tls_get_addr to 0.
	(elf_x86_64_check_tls_transition): Check tls_get_addr directly.
	(elf_x86_64_convert_load_reloc): Update tls_get_addr check.
	(elf_x86_64_link_check_relocs): New function.
	(bfd_elf64_bfd_link_check_relocs): New.
	(bfd_elf32_bfd_link_check_relocs): Likewise.
2017-08-06 08:41:07 -07:00
H.J. Lu a4819f54c0 Treat common symbol as undefined for --no-define-common
When --no-define-common is used to build shared library, treat common
symbol as undefined so that common symbols that are referenced from a
shared library to be assigned addresses only in the main program.  This
eliminates the unused duplicate space in the shared library, and also
prevents any possible confusion over resolving to the wrong duplicate
when there are many dynamic modules with specialized search paths for
runtime symbol resolution.

--no-define-common is only allowed when building a shared library.

bfd/

	PR ld/21903:
	* elflink.c (elf_link_add_object_symbols): Treat common symbol
	as undefined for --no-define-common.

include/

	PR ld/21903:
	* bfdlink.h (bfd_link_info): Add inhibit_common_definition.

ld/

	PR ld/21903:
	* ld.h (command_line): Remove inhibit_common_definition.
	* ldgram.y: Replace command_line.inhibit_common_definition with
	link_info.inhibit_common_definition.
	* ldlang.c (lang_common): Likewise.
	* lexsup.c (parse_args): Likewise.
	* ldmain.c (main): Only allow --no-define-common with -shared.
	* testsuite/ld-elf/pr21903.s: New file.
	* testsuite/ld-elf/pr21903a.d: Likewise.
	* testsuite/ld-elf/pr21903b.d: Likewise.
	* testsuite/ld-elf/pr21903c.d: Likewise.
	* testsuite/ld-elf/pr21903d.d: Likewise.
	* testsuite/ld-elf/pr21903e.d: Likewise.
2017-08-06 08:19:04 -07:00
GDB Administrator e2a084f2c1 Automatic date update in version.in 2017-08-06 00:00:44 +00:00
Alan Modra 55ef6584ca Don't fail in elf32_hppa_set_gp
The base bfd_link_hash_table works fine here, the only thing to watch
out for is to only set elf_gp if the output is ELF.

bfd/
	* elf32-hppa.c (elf32_hppa_set_gp): Don't require an
	hppa_link_hash_table.
ld/
	* testsuite/ld-unique/pr21529.d: Don't xfail hppa.
2017-08-05 23:28:21 +09:30
GDB Administrator a66930b357 Automatic date update in version.in 2017-08-05 00:00:19 +00:00
GDB Administrator a30d3a7990 Automatic date update in version.in 2017-08-04 00:00:52 +00:00
GDB Administrator 5f66bad45b Automatic date update in version.in 2017-08-03 00:01:14 +00:00
Max Filippov d84ed528d4 Fix potential illegal memory access in Xtensa port.
* xtensa-isa.c (xtensa_isa_init): Don't update lookup table
	entries for sysregs with negative indices.
2017-08-02 10:38:09 +01:00
GDB Administrator a5be90a4d9 Automatic date update in version.in 2017-08-02 00:00:53 +00:00
Andreas Krebbel 1ef692ea23 S/390: Fix claimfile failures
This fixes a segfault when trying to access the local_plt field in the
s390 specific elf data althoug the underlaying object is a generic elf
object.

This fixes the following testsuite failures:

< FAIL: plugin claimfile replace symbol with source
< FAIL: plugin claimfile resolve symbol with source
< FAIL: plugin claimfile replace file with source
< FAIL: plugin set symbol visibility with source
< FAIL: plugin ignore lib with source
< FAIL: plugin claimfile replace lib with source
< FAIL: plugin 2 with source lib
< FAIL: load plugin 2 with source
< FAIL: plugin 3 with source lib
< FAIL: load plugin 3 with source

bfd/ChangeLog:

2017-08-01  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf32-s390.c (elf_s390_finish_dynamic_sections): Skip if it
	isn't the S/390 specific elf data.
	* elf64-s390.c (elf_s390_finish_dynamic_sections): Likewise.
2017-08-01 15:13:40 +02:00
GDB Administrator 51b69c74c6 Automatic date update in version.in 2017-08-01 00:00:54 +00:00
Kuan-Lin Chen 5759343685 Improve handling of ADD and SUB relocations on the RISCV target.
* elfxx-riscv.c (riscv_elf_add_sub_reloc): New function.
	* (howto_table) [R_RISCV_ADD8]: Use riscv_elf_add_sub_reloc.
	[R_RISCV_ADD16]: Likewise.
	[R_RISCV_ADD32]: Likewise.
	[R_RISCV_ADD64]: Likewise.
	[R_RISCV_SUB6]: Likewise.
	[R_RISCV_SUB8]: Likewise.
	[R_RISCV_SUB16]: Likewise.
	[R_RISCV_SUB32]: Likewise.
	[R_RISCV_SUB64]: Likewise.
2017-07-31 15:33:48 +01:00
Alan Modra d44c746aed PR 21847, PowerPC64 --plt-localentry again
This makes ld warn about --plt-localentry if a version of glibc
without the necessary ld.so checks is detected, and revises the
documentation.

bfd/
	* elf64-ppc.c (ppc64_elf_tls_setup): Warn on --plt-localentry
	without ld.so checks.
gold/
	* powerpc.cc (Target_powerpc::scan_relocs): Warn on --plt-localentry
	without ld.so checks.
ld/
	* ld.texinfo (plt-localentry): Revise.
2017-07-31 13:20:44 +09:30
GDB Administrator 93e0a1eab1 Automatic date update in version.in 2017-07-31 00:00:25 +00:00
GDB Administrator 10683b8d11 Automatic date update in version.in 2017-07-30 00:00:45 +00:00
Alan Modra 8b5f1ed877 PR 21847, Don't default PowerPC64 to --plt-localentry
The big comment in ppc64_elf_tls_setup says why.  I've also added some
code to the bfd linker that catches the -lpthread -lc symbol
differences and disable generation of optimized call stubs even when
--plt-localentry is activated.  Gold doesn't yet have that.

	PR 21847
bfd/
	* elf64-ppc.c (struct ppc_link_hash_entry): Add non_zero_localentry.
	(ppc64_elf_merge_symbol): Set non_zero_localentry.
	(is_elfv2_localentry0): Test non_zero_localentry.
	(ppc64_elf_tls_setup): Default to --no-plt-localentry.
gold/
	* powerpc.cc (Target_powerpc::scan_relocs): Default to
	--no-plt-localentry.
ld/
	* ld.texinfo (plt-localentry): Document.
2017-07-29 13:02:27 +09:30
GDB Administrator ef080e7ed4 Automatic date update in version.in 2017-07-29 00:01:03 +00:00
Andreas Krebbel 894dde0ba7 Add missing changelog 2017-07-28 18:34:34 +02:00
Andreas Krebbel 79c12faeea S/390: Fix segfault when linking -shared -nostartfiles
Regression-tested on s390x.

bfd/ChangeLog:

2017-07-28  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf32-s390.c (elf_s390_finish_dynamic_sections): Add NULL
	pointer check for htab->elf.irelplt.
	* elf64-s390.c (elf_s390_finish_dynamic_sections): Likewise.
2017-07-28 18:26:25 +02:00
GDB Administrator 242f30e67c Automatic date update in version.in 2017-07-28 00:00:46 +00:00
Nick Clifton 8bdf0be19d Fix address violation issues encountered when parsing corrupt binaries.
PR 21840
	* mach-o.c (bfd_mach_o_read_symtab_strtab): Fail if the symtab
	size is -1.
	* nlmcode.h (nlm_swap_auxiliary_headers_in): Replace assertion
	with error return.
	* section.c (bfd_make_section_with_flags): Fail if the name or bfd
	are NULL.
	* vms-alpha.c (bfd_make_section_with_flags): Correct computation
	of end pointer.
	(evax_bfd_print_emh): Check for invalid string lengths.
2017-07-27 12:04:50 +01:00
GDB Administrator 63d4980d60 Automatic date update in version.in 2017-07-27 00:00:47 +00:00
GDB Administrator 11f1093690 Automatic date update in version.in 2017-07-26 00:00:31 +00:00
Nick Clifton 133193b8ae Fix thinko in previous change to elf32-msp430.c 2017-07-25 12:47:46 +01:00
Nick Clifton c26bb06769 Updated French translation for the BFD library. 2017-07-25 09:46:14 +01:00
Benjamin Green cfe7b9bd58 Add a linker branch optimization for the MSP430.
PR 21824
	* elf32-msp430.c (msp430_elf_relax_section): Allow conversion of
	16-bit absolute branches into 10-bit pc-relative branches on the
	MSP430 as well as the MSP430X.
2017-07-25 09:41:23 +01:00
Alan Modra d4aaa2a074 __tls_get_addr_opt stub eh_frame info
Since the __tls_get_addr_opt stub saves LR and makes a call, eh_frame
info should be generated to describe how to unwind through the stub.

The patch also changes the way the backend iterates over stubs, from
looking at all sections in stub_bfd to which all dynamic sections are
attached as well, to iterating over the group list, which gets just
the stub sections.  Most binaries will have just one or two stub
groups, so this is a little faster.

bfd/
	* elf64-ppc.c (struct map_stub): Add tls_get_addr_opt_bctrl.
	(stub_eh_frame_size): New function.
	(ppc_size_one_stub): Set group tls_get_addr_opt_bctrl.
	(group_sections): Init group tls_get_addr_opt_bctrl.
	(ppc64_elf_size_stubs): Update sizing and initialization of
	.eh_frame.  Iteration over stubs via group list.
	(ppc64_elf_build_stubs): Iterate over stubs via group list.
	(ppc64_elf_finish_dynamic_sections): Update finalization of
	.eh_frame.
ld/
	* testsuite/ld-powerpc/tlsopt5.s: Add cfi.
	* testsuite/ld-powerpc/tlsopt5.d: Update.
	* testsuite/ld-powerpc/tlsopt5.wf: New file.
	* testsuite/ld-powerpc/powerpc.exp: Perform new tlsopt5 test.
2017-07-25 15:14:39 +09:30
GDB Administrator aafd38357a Automatic date update in version.in 2017-07-25 00:01:08 +00:00
Nick Clifton 8a2df5e2df Fix another memory access error triggered by attempting to parse a corrupt binary.
PR 21813
	(alpha_vms_object_p): Check for a truncated record.
2017-07-24 14:04:04 +01:00
Nick Clifton ca4cf9b9c6 Fix address violation errors parsing corrupt binary files.
PR 21813
binutils* rddbg.c (read_symbol_stabs_debugging_info): Check for an empty
	string whilst concatenating symbol names.

bfd	* mach-o.c (bfd_mach_o_canonicalize_relocs): Pass the base address
	of the relocs to the canonicalize_one_reloc routine.
	* mach-o.h (struct bfd_mach_o_backend_data): Update the prototype
	for the _bfd_mach_o_canonicalize_one_reloc field.
	* mach-o-arm.c (bfd_mach_o_arm_canonicalize_one_reloc): Add
	res_base parameter.  Use to check for corrupt pair relocs.
	* mach-o-aarch64.c (bfd_mach_o_arm64_canonicalize_one_reloc):
	Likewise.
	* mach-o-i386.c (bfd_mach_o_i386_canonicalize_one_reloc):
	Likewise.
	* mach-o-x86-64.c (bfd_mach_o_x86_64_canonicalize_one_reloc):
	Likewise.

	* vms-alpha.c (_bfd_vms_slurp_eihd): Make sure that there is
	enough data in the record before attempting to parse it.
	(_bfd_vms_slurp_eeom): Likewise.

	(_bfd_vms_slurp_egsd): Check for an invalid section index.
	(image_set_ptr): Likewise.
	(alpha_vms_slurp_relocs): Likewise.
2017-07-24 13:49:22 +01:00
Nick Clifton 47aeb64c10 Improve "unrecognized relocation" error messages to add the suggestion that the linker might be out of date.
PR 21803
	* reloc.c (_bfd_unrecognized_reloc): New function.  Reports
	an unrecognized reloc and sets the bfd_error value.
	* libbfd.h: Regenerate.
	* elf32-arm.c (elf32_arm_final_link_relocate): Use the new
	function.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
2017-07-24 11:27:33 +01:00
GDB Administrator 8ca02f6a21 Automatic date update in version.in 2017-07-24 00:00:58 +00:00
Alan Modra 15a3a14fdd Correct eh_frame info for __glink_PLTresolve
My PPC64_OPT_LOCALENTRY patch of June 1, git commit f378ab099d, and
the later gold change, git commit 7ee7ff7015, added an insn in
__glink_PLTresolve which needs a corresponding adjustment in the
eh_frame info for asynchronous exceptions to unwind correctly.

It would have been OK for both ABIs to use +5 for the advance before
restore of LR, since we can put the DW_CFA_restore_extended on any
insn after the actual restore and before the r12/r0 copy is clobbered,
but it's slightly better to delay as much as possible.  There are
then more addresses where fewer CFA program insns are executed.

bfd/
	* elf64-ppc.c (ppc64_elf_size_stubs): Correct advance to
	restore of LR.
gold/
	* powerpc.cc (glink_eh_frame_fde_64v2): Correct advance to
	restore of LR.
	(glink_eh_frame_fde_64v1): Advance to restore of LR at latest
	possible insn.
2017-07-23 20:40:39 +09:30
GDB Administrator 5c2c0020fb Automatic date update in version.in 2017-07-23 00:00:36 +00:00
GDB Administrator dbdda973f3 Automatic date update in version.in 2017-07-22 00:00:45 +00:00
GDB Administrator 33d69f8727 Automatic date update in version.in 2017-07-21 00:00:33 +00:00
GDB Administrator 8e8f892f70 Automatic date update in version.in 2017-07-20 00:00:34 +00:00
Szabolcs Nagy f2e6a8430e [AArch64] Fix PR18841 ifunc relocation ordering
In order to get the ifunc relocs properly sorted the correct class
needs to be returned.  The code mimics what has been done for x86.

Fixes
FAIL: Run pr18841 with libpr18841c.so

bfd/
	PR ld/18841
	* elfnn-aarch64.c (elfNN_aarch64_reloc_type_class): Return
	reloc_class_ifunc for ifunc symbols.
2017-07-19 18:47:22 +01:00
Nick Clifton 6c4e7b6bfb Extend previous fix to coff-rs6000.c to coff64-rs6000.c
PR 21786
	* coff64-rs6000.c (_bfd_strntol): New function.
	(_bfd_strntoll): New function.
	(GET_VALUE_IN_FIELD): New macro.
	(xcoff64_slurp_armap): Use new macros.
2017-07-19 16:14:02 +01:00
Nick Clifton 909e4e716c Fix use-after-free error when parsing a corrupt nested archive.
PR 21787
	* archive.c (bfd_generic_archive_p): If the bfd does not have the
	correct magic bytes at the start, set the error to wrong format
	and clear the format selector before returning NULL.
2017-07-19 14:49:12 +01:00
Nick Clifton 29866fa186 Fix address violation when attempting to read a corrupt field in a COFF archive header structure.
PR 21786
	* coff-rs6000.c (_bfd_strntol): New function.
	(_bfd_strntoll): New function.
	(GET_VALUE_IN_FIELD): New macro.
	(EQ_VALUE_IN_FIELD): new macro.
	(_bfd_xcoff_slurp_armap): Use new macros.
	(_bfd_xcoff_archive_p): Likewise.
	(_bfd_xcoff_read_ar_hdr): Likewise.
	(_bfd_xcoff_openr_next_archived_file): Likewise.
	(_bfd_xcoff_stat_arch_elt): Likewise.
2017-07-19 11:07:43 +01:00
John Eric Martin 684d5a10b1 [ARC] Add JLI support.
The following relocation types were added to GCC/binutils:

ARC_JLI_SECTOFF is a relocation type in Metaware that is now used by
GCC as well to adjust the index of function calls to functions with
attribute jli_call_always.

bfd/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elf32-arc.c (JLI): Define.
	* reloc.c: Add JLI relocations.

gas/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/gas/arc/jli-1.d: New file.
	* testsuite/gas/arc/jli-1.s: Likewise.
	* testsuite/gas/arc/taux.d: Update for jli_base.

include/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* elf/arc-reloc.def: Add JLI relocs howto.
	* opcode/arc-func.h (replace_jli): New function.

ld/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* emulparams/arcelf.sh (JLI_START_TABLE): Define.
	* scripttempl/elfarc.sc: Handle jlitab section.
	* scripttempl/elfarcv2.sc: Likewise.
	* testsuite/ld-arc/arc.exp: Add JLI test.
	* testsuite/ld-arc/jli-script.ld: New file.
	* testsuite/ld-arc/jli-simple.dd: Likewise.
	* testsuite/ld-arc/jli-simple.rd: Likewise.
	* testsuite/ld-arc/jli-simple.s: Likewise.
	* testsuite/ld/testsuite/ld-arc/jli-overflow.s: Likewise.
	* testsuite/ld/testsuite/ld-arc/jli-overflow.d: Likewise.
	* testsuite/ld/testsuite/ld-arc/jli-overflow.err: Likewise.

opcode/
2017-07-19  Claudiu Zissulescu  <claziss@synopsys.com>
	    John Eric Martin  <John.Martin@emmicro-us.com>

	* arc-opc.c (UIMM10_6_S_JLIOFF): Define.
	(UIMM3_23): Adjust accordingly.
	* arc-regs.h: Add/correct jli_base register.
	* arc-tbl.h (jli_s): Likewise.
2017-07-19 09:56:55 +02:00
GDB Administrator 801f648cfc Automatic date update in version.in 2017-07-19 00:00:59 +00:00
Yuri Chornovian de194d8575 Fix spelling typos. 2017-07-18 16:58:14 +01:00
Nick Clifton e4e21d9ed1 Fix runtime failure triggered by a corrupt ecoff input file.
PR binutils/21781
	* coffcode.h (handle_COMDAT): Replace abort with an error message
	and return.
2017-07-18 15:46:13 +01:00
GDB Administrator 25bda061bf Automatic date update in version.in 2017-07-18 00:00:50 +00:00
H.J. Lu 8e85f840e1 Add missing ChangeLog entries for PR ld/21782 fix 2017-07-17 12:40:57 -07:00
H.J. Lu c5bb8910e8 x86-64: Limit PIC check to shared library build
When building an executable, undefined symbols are error and undefined
weak symbols are resolved to zero.  We only need to check PIC for
building a shared library.

bfd/

	PR ld/21782
	* elf64-x86-64.c (elf_x86_64_relocate_section): Limit PIC check
	to shared library.

ld/

	PR ld/21782
	* testsuite/ld-x86-64/pie3-nacl.d: New file.
	* testsuite/ld-x86-64/pie3.d: Likewise.
	* testsuite/ld-x86-64/pie3.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pie3 and pie3-nacl.
2017-07-17 12:17:59 -07:00
H.J. Lu dd57c19c1a Re-indent elf_x86_64_relocate_section
* elf64-x86-64.c (elf_x86_64_relocate_section): Re-indent.
2017-07-17 10:40:18 -07:00
GDB Administrator caa74962b6 Automatic date update in version.in 2017-07-17 00:00:58 +00:00
Alan Modra 676ee2b5fa __tls_get_addr_opt GOT entries
My 2017-01-24 patch (commit f0158f44) wrongly applied an optimization
of GOT entries for the __tls_get_addr_opt stub, to shared libraries.

When the TLS segment layout is known, as it is for the executable and
shared libraries loaded at initial program start, powerpc supports a
__tls_get_addr optimization.  On the first call to __tls_get_addr for
a given __tls_index GOT entry, the DTPMOD word is set to zero and the
DTPREL word to the thread pointer offset to the thread variable.  This
allows the __tls_get_addr_opt stub to return that value immediately
without making a call into glibc for any subsequent __tls_get_addr
calls using that __tls_index GOT entry.

That's all fine, but I thought I'd be clever and when the thread
variable is local, set up the GOT entry as if __tls_get_addr had
already been called.  Which is good only for the executable, since ld
cannot know the TLS layout for shared libraries.

Of course, if this only applies to executables there isn't much point
to the optimization.  Normally, GD and LD code in an executable will
be converted to IE or LE, losing the __tls_get_addr call.  So the only
time it will trigger is with --no-tls-optimize.  Thus, revert all
support.

	* elf64-ppc.c (ppc64_elf_relocate_section): Don't optimize
	__tls_index GOT entries when using __tls_get_addr_opt stub.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
2017-07-16 21:31:38 +09:30
GDB Administrator 046c08c44b Automatic date update in version.in 2017-07-16 00:00:55 +00:00
GDB Administrator 71d01ca93b Automatic date update in version.in 2017-07-15 00:00:42 +00:00
GDB Administrator ee77ed019f Automatic date update in version.in 2017-07-14 00:00:47 +00:00
GDB Administrator bbe7ef6699 Automatic date update in version.in 2017-07-13 00:00:50 +00:00
Alan Modra 429d795d50 Update PO files
bfd/
	* po/es.po: Update from translationproject.org/latest/bfd/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/ja.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/hr.po: New file from translationproject.org.
	* configure.ac (ALL_LINGUAS): Add hr.  Sort.
	* configure: Regenerate.

binutils/
	* po/bg.po: Update from translationproject.org/latest/binutils/.
	* po/ca.po: Likewise.
	* po/da.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/hr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sk.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/zh_TW.po: Likewise.

gas/
	* po/es.po: Update from translationproject.org/latest/gas/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/ja.po: Likewise.
	* po/ru.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/zh_CN.po: Likewise.

gold/
	* po/es.po: Update from translationproject.org/latest/gold/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/ja.po: New file from translationproject.org.
	* po/sv.po: Likewise.
	* po/uk.po: Likewise.

gprof/
	* po/bg.po: Update from translationproject.org/latest/gprof/.
	* po/da.po: Likewise.
	* po/de.po: Likewise.
	* po/eo.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/ga.po: Likewise.
	* po/hu.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/ms.po: Likewise.
	* po/nl.po: Likewise.
	* po/pt_BR.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.

ld/
	* po/bg.po: Update from translationproject.org/latest/ld/.
	* po/da.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/zh_TW.po: Likewise.
	* po/de.po: New file from translationproject.org.
	* po/ru.po: Likewise.
	* configure.ac (ALL_LINGUAS): Add de, ru.  Sort.
	* configure: Regenerate.

opcodes/
	* po/da.po: Update from translationproject.org/latest/opcodes/.
	* po/de.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/nl.po: Likewise.
	* po/pt_BR.po: Likewise.
	* po/ro.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
2017-07-12 23:08:59 +09:30
Nick Clifton 0bae9e9ec5 Fix compile time warnings building the binutils with gcc 7.1.1.
bfd	* elf32-xtensa.c (elf_xtensa_get_plt_section): Increase length of
	plt_name buffer.
	(elf_xtensa_get_gotplt_section): Increase length of got_name
	buffer.
	* mach-o-arm.c (bfd_mach_o_arm_canonicalize_one_reloc): Add a
	default return of FALSE.
	* mach-o-i386.c (bfd_mach_o_i386_canonicalize_one_reloc): Add a
	default return of FALSE.

binutils * dwarf.c (dwarf_vmatoa_1): Do not pass a NULL string pointer to
	sprintf.
	* srconv.c (walk_tree_type): Initialise the spare field of the
	IT_dty structure.

gas	* config/tc-pru.c (md_assemble): Add continue statement after
	handling 'E' operand character.
	* config/tc-v850.c (md_assemble): Initialise the 'insn' variable.
2017-07-12 12:17:02 +01:00
Alan Modra d42c267e9b bfd_error_handler bfd_vma and bfd_size_type args
This patch uses the new %L _bfd_error_handler support for printing
bfd_vma arguments, and fixes a many other format and/or argument
errors in error messages.

bfd/
	* binary.c (binary_set_section_contents): Don't print filepos in
	error message.
	(coff_write_object_contents): Cast size_t for error message.
	(coff_slurp_line_table): Don't use bfd_vma symndx.
	(coff_slurp_reloc_table): Remove unneeded cast.
	* dwarf2.c (read_section): Cast bfd_int64_t to long long for
	error message.
	(find_abstract_instance_name): Likewise.
	* elf32-arm.c (arm_type_of_stub): Correct error arg order.
	(bfd_elf32_arm_stm32l4xx_erratum_scan): Don't cast error arg.
	(elf32_arm_check_relocs): Make r_symndx an int.
	* elf32-cris.c (cris_elf_check_relocs): Delete extraneous %s in
	format string.
	* elf32-metag.c (elf_metag_relocate_section): Delete extra error
	message arg.
	* elf32-nds32.c (nds32_elf_ex9_build_hash_table): Rewrite bogus
	error message.
	* elf32-i386.c (elf_i386_check_relocs): Make r_symndx an int.
	* elf32-s390.c (elf_s390_check_relocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_check_relocs): Likewise.
	* elf32-tilepro.c (tilepro_elf_check_relocs): Likewise.
	* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
	* elf64-s390.c (elf_s390_check_relocs): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Likewise.
	* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
	* elfxx-tilegx.c (tilegx_elf_check_relocs): Likewise.
	* elf64-mmix.c (_bfd_mmix_after_linker_allocation): Cast size_t args
	and use %lu for error message.
	* elflink.c (elf_link_adjust_relocs): Delete extra error message arg.
	* mmo.c (mmo_scan): Make stab_loc a file_ptr.  Cast expression for
	error message.

	* elf32-arm.c (elf32_arm_tls_relax): Correct format string and args
	in error message.
	(elf32_arm_final_link_relocate): Likewise.
	* coff-arm.c (bfd_arm_process_before_allocation): Likewise.
	* coffcode.h (styp_to_sec_flags): Likewise.
	* cofflink.c (_bfd_coff_write_global_sym): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_symbol_table): Likewise.
	* elf32-arc.c (arc_elf_merge_private_bfd_data): Likewise.
	* elf32-bfin.c (bfinfdpic_check_relocs): Likewise.
	(elf32_bfin_merge_private_bfd_data): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-frv.c (frv_elf_merge_private_bfd_data): Likewise.
	* elf32-i370.c (i370_elf_merge_private_bfd_data): Likewise.
	(i370_elf_relocate_section): Likewise.
	* elf32-iq2000.c (iq2000_elf_merge_private_bfd_data): Likewise.
	* elf32-m32c.c (m32c_elf_merge_private_bfd_data): Likewise.
	* elf32-m68hc1x.c (_bfd_m68hc11_elf_merge_private_bfd_data): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-mep.c (mep_elf_merge_private_bfd_data): Likewise.
	* elf32-mt.c (mt_elf_merge_private_bfd_data): Likewise.
	* elf64-sparc.c (elf64_sparc_merge_private_bfd_data): Likewise.
	* elfxx-mips.c (mips_elf_merge_obj_e_flags): Likewise.
	(_bfd_mips_elf_merge_private_bfd_data): Likewise.
	* ieee.c (ieee_write_id, read_id): Likewise.
	* mach-o.c (bfd_mach_o_write_contents): Likewise.
	(bfd_mach_o_layout_commands, bfd_mach_o_read_section_32): Likewise.
	(bfd_mach_o_read_section_64, bfd_mach_o_read_symtab_symbol): Likewise.
	(bfd_mach_o_read_command, bfd_mach_o_header_p): Likewise.
	* peXXigen.c (_bfd_XXi_swap_aouthdr_in): Likewise.
	* stabs.c (_bfd_link_section_stabs): Likewise.

	* coff-arm.c (coff_arm_relocate_section): Use L modifier in error
	format.
	* coff-mcore.c (coff_mcore_relocate_section): Likewise.
	* coff-ppc.c (coff_ppc_relocate_section): Likewise.
	* coff-rs6000.c (xcoff_reloc_type_toc): Likewise.
	* coff-sh.c (sh_relax_section): Likewise.
	(sh_relax_delete_bytes, sh_swap_insns): Likewise.
	* coff-tic80.c (coff_tic80_relocate_section): Likewise.
	* coffcode.h (coff_slurp_reloc_table): Likewise.
	* coffgen.c (_bfd_coff_get_external_symbols): Likewise.
	(_bfd_coff_read_string_table): Likewise.
	* cofflink.c (_bfd_coff_generic_relocate_section): Likewise.
	* compress.c (bfd_get_full_section_contents): Likewise.
	* dwarf2.c (read_formatted_entries, decode_line_info): Likewise.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf.c (bfd_elf_string_from_elf_section): Likewise.
	* elf32-arc.c (arc_special_overflow_checks): Likewise.
	* elf32-arm.c (elf32_arm_tls_relax): Likewise.
	(elf32_arm_final_link_relocate, elf32_arm_relocate_section): Likewise.
	(elf32_arm_write_section): Likewise.
	* elf32-bfin.c (bfin_relocate_section): Likewise.
	(bfinfdpic_relocate_section): Likewise.
	* elf32-hppa.c (hppa_build_one_stub): Likewise.
	(final_link_relocate, elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_tls_transition): Likewise.
	(elf_i386_relocate_section): Likewise.
	* elf32-ip2k.c (ip2k_final_link_relocate): Likewise.
	* elf32-lm32.c (lm32_elf_finish_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-metag.c (elf_metag_relocate_section): Likewise.
	* elf32-nds32.c (unrecognized_reloc_msg): Likewise.
	(nds32_elf_relax_longcall1, nds32_elf_relax_longcall2): Likewise.
	(nds32_elf_relax_longcall3, nds32_elf_relax_longjump1): Likewise.
	(nds32_elf_relax_longjump2, nds32_elf_relax_longjump3): Likewise.
	(nds32_elf_relax_longcall4, nds32_elf_relax_longcall5): Likewise.
	(nds32_elf_relax_longcall6, nds32_elf_relax_longjump4): Likewise.
	(nds32_elf_relax_longjump5, nds32_elf_relax_longjump6): Likewise.
	(nds32_elf_relax_longjump7, nds32_elf_relax_loadstore): Likewise.
	(nds32_elf_relax_ptr, nds32_elf_ex9_build_hash_table): Likewise.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-rx.c (UNSAFE_FOR_PID): Likewise.
	* elf32-s390.c (invalid_tls_insn, elf_s390_relocate_section): Likewise.
	* elf32-score.c (s3_bfd_score_elf_check_relocs): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_relax_section): Likewise.
	(sh_elf_relax_delete_bytes, sh_elf_swap_insns): Likewise.
	(sh_elf_relocate_section): Likewise.
	* elf32-sh64.c (shmedia_prepare_reloc): Likewise.
	* elf32-spu.c (spu_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-v850.c (v850_elf_relax_section): Likewise.
	* elf32-vax.c (elf_vax_check_relocs): Likewise.
	(elf_vax_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	(extend_ebb_bounds_forward, extend_ebb_bounds_backward): Likewise.
	(compute_text_actions, compute_ebb_proposed_actions): Likewise.
	(do_fix_for_relocatable_link): Likewise.
	* elf64-alpha.c (elf64_alpha_relax_got_load): Likewise.
	(elf64_alpha_relax_with_lituse): Likewise.
	* elf64-hppa.c (elf64_hppa_finish_dynamic_symbol): Likewise.
	(elf_hppa_final_link_relocate): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_relax_section): Likewise.
	(elf64_ia64_choose_gp, elf64_ia64_relocate_section): Likewise.
	(elf64_vms_link_add_object_symbols): Likewise.
	* elf64-mmix.c (mmix_elf_perform_relocation): Likewise.
	(mmix_final_link_relocate): Likewise.
	* elf64-s390.c (invalid_tls_insn): Likewise.
	(elf_s390_relocate_section): Likewise.
	* elf64-sh64.c (sh_elf64_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
	(elf_x86_64_relocate_section): Likewise.
	* elfcode.h (elf_slurp_symbol_table): Likewise.
	* elfcore.h (elf_core_file_p): Likewise.
	* elflink.c (elf_link_read_relocs_from_section): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	(elfNN_aarch64_relocate_section): Likewise.
	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
	(elfNN_ia64_choose_gp, elfNN_ia64_relocate_section): Likewise.
	* elfnn-riscv.c (riscv_elf_relocate_section): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
	(_bfd_mips_elf_relocate_section): Likewise.
	(_bfd_mips_elf_finish_dynamic_symbol, mips_finish_exec_plt): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
	* ieee.c (ieee_slurp_external_symbols): Likewise.
	* ihex.c (ihex_write_object_content): Likewise.
	* mach-o.c (bfd_mach_o_build_exec_seg_command): Likewise.
	* merge.c (_bfd_merged_section_offset): Likewise.
	* mmo.c (mmo_write_loc_chunk): Likewise.
	(mmo_write_object_contents): Likewise.
	* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Likewise.
	* stabs.c (_bfd_link_section_stabs): Likewise.
	* xcofflink.c (xcoff_link_add_symbols, xcoff_find_tc0): Likewise.
ld/
	* testsuite/ld-arc/nps-1b.err: Update.
	* testsuite/ld-x86-64/ilp32-11.d: Update.
2017-07-12 14:03:48 +09:30
GDB Administrator bd6a8c1905 Automatic date update in version.in 2017-07-12 00:00:47 +00:00
Alan Modra e3fbc3da13 ppc32 use of %x in einfo format, typo fix
* elf32-ppc.c (ppc_elf_relocate_section): Fix typo.
2017-07-11 22:42:43 +09:30
Alan Modra 2c4d9cbe51 ppc32 use of %x in einfo format
einfo doesn't support %x.

	* elf32-ppc.c (ppc_elf_relocate_section): Emit "unexpected
	instruction" error using _bfd_error_handler, not einfo.
2017-07-11 19:18:47 +09:30
GDB Administrator 36cebdda80 Automatic date update in version.in 2017-07-11 00:00:41 +00:00
Nick Clifton adce5b398d Fix compile time warning about duplicate case values for powerpc-aix target.
* coffcode.h (coff_slurp_symbol_table): Do not include an entry
	for C_AIX_WEAKEXT if it has the same value as C_WEAKEXT.
2017-07-10 13:18:05 +01:00
GDB Administrator a074796714 Automatic date update in version.in 2017-07-10 00:00:41 +00:00
GDB Administrator f4db828807 Automatic date update in version.in 2017-07-09 00:00:41 +00:00
GDB Administrator 12c1f20d6f Automatic date update in version.in 2017-07-08 00:00:40 +00:00
John Baldwin e6f3b9c319 Create pseudo sections for FreeBSD NT_PTLWPINFO core notes.
bfd/ChangeLog:

	* elf.c (elfcore_grok_freebsd_note): Handle NT_FREEBSD_PTLWPINFO.
2017-07-07 16:11:42 -07:00
Alan Modra 532cc31305 Add some missing xcoff support
* coffcode.h (coff_slurp_symbol_table): Handle C_AIX_WEAKEXT.
2017-07-07 10:35:31 +09:30
Alan Modra 1cf9552bf1 Another _doprnt fix for %L handling
* bfd.c (_doprnt): Replace "L" with "ll" when printing bfd_vma
	as long long.  Move code replacing "ll" with "I64", and simplify.
2017-07-07 10:35:31 +09:30
GDB Administrator 9691e722c6 Automatic date update in version.in 2017-07-07 00:00:35 +00:00
H.J. Lu a0b7b10523 Convert 'L' to 'l' when setting wide_width to 1
When setting wide_width to 1, convert 'L' to 'l'.  Otherwise, %Lx/%Lu/%Ld
will be passed to fprintf which will treat the argument as long long.

	* bfd.c (_doprnt): Convert 'L' to 'l' when setting wide_width
	to 1.
2017-07-06 06:52:13 -07:00
GDB Administrator 4b617f5235 Automatic date update in version.in 2017-07-06 00:00:56 +00:00
H.J. Lu 1d827a720c Fix build with GCC 4.2
Fix GCC 4.2 warnings like:

cc1: warnings being treated as errors
binutils-gdb/bfd/dwarf2.c:1844: warning: declaration of ‘time’ shadows a global declaration
/usr/include/time.h:187: warning: shadowed declaration is here
binutils-gdb/bfd/dwarf2.c: In function ‘line_info_add_file_name’:
binutils-gdb/bfd/dwarf2.c:1854: warning: declaration of ‘time’ shadows a global declaration
/usr/include/time.h:187: warning: shadowed declaration is here

bfd/

	* dwarf2.c (line_info_add_include_dir_stub): Replace time with
	xtime.
	(line_info_add_file_name): Likewise.
	(decode_line_info): Likewise.

binutils/

	* dwarf.c (display_debug_names): Replace index with xindex.
2017-07-05 09:05:05 -07:00
GDB Administrator 033ea118c0 Automatic date update in version.in 2017-07-05 00:00:31 +00:00
Tristan Gingold 0d702cfe5d Regenerate configure.
bfd/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

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

binutils/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

gas/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

gprof/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

ld/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.

opcodes/
2017-07-04  Tristan Gingold  <gingold@adacore.com>

	* configure: Regenerate.
2017-07-04 11:15:33 +02:00
Jiong Wang 564e46b795 [AArch64] Remove useless and incorrect assertion
The outer caller elf_link_output_extsym in elflink.c is a traverse function on
all external symbol, and it will only call *finish_dynamic_symbol if some
conditions is meet.  It is executed conditionally.

If the condition to trigger that assertion is satisified, it then won't satify
the outer check in finish_dynamic_symbol, so *finish_dynamic_symbol won't be
called that the assertion is expected to be dead code.

If elf_link_output_extsym is a traverse function that unconditionally called
on external symbols decided to be exported, then an assertion to make sure these
symbols are in sane status might make sense.

bfd/
        * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Remove the
        sanity check at the head of this function.
2017-07-04 09:24:10 +01:00
Jan Kratochvil 0041f7df74 [binutils patch] DWARF-5: Extend bfd/dwarf2.c parse_comp_unit()
bfd/
2017-07-04  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2.c (struct dwarf2_debug): Add fields dwarf_line_str_buffer and
	dwarf_line_str_size.
	(struct attr_abbrev): Add field implicit_const.
	(dwarf_debug_sections): Add .debug_line_str.
	(enum dwarf_debug_section_enum): Add debug_line_str and debug_max.
	(dwarf_debug_section_assert): Add static assertion.
	(read_indirect_line_string): New.
	(read_abbrevs): Support DW_FORM_implicit_const.
	(is_str_attr): Support DW_FORM_line_strp.
	(read_attribute_value): Support DW_FORM_line_strp and
	DW_FORM_implicit_const.
	(read_attribute): Support DW_FORM_implicit_const.
	(line_info_add_include_dir, line_info_add_include_dir_stub):
	(line_info_add_file_name, read_formatted_entries): New.
	(decode_line_info, parse_comp_unit): Support DWARF 5.
	(_bfd_dwarf2_cleanup_debug_info): Free dwarf_line_str_buffer.
2017-07-04 10:09:27 +02:00
GDB Administrator 568fc4f4f8 Automatic date update in version.in 2017-07-04 00:00:43 +00:00
Egeyar Bagcioglu d8cd8c1f48 bfd: partial revert commit EC1ACAB (prevent all but undef weak symbols to become dynamic in sparc).
bfd/ChangeLog:

2017-07-03  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>

        * elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Remove the
        abort statement that was put for symbols that are not dynamic.
2017-07-03 20:06:35 +02:00
Tristan Gingold 15e6ed8cbf Regenerate pot files. 2017-07-03 17:02:01 +02:00
Alan Modra 76cfced5ad Support %Lx, %Lu, %Ld in _bfd_error_handler format
One way to print 64-bit bfd_vma or bfd_size_type values on 32-bit
hosts is to cast the value to long long and use the 'll' modifier in
printf format strings.  However, that's awkward because we also
support the Microsoft C library printf that uses 'I64' as a modifier
instead, and having variants of translated strings would not endear us
to the translation project.  So, rewrite the 'll' modifier in
_doprint for Microsoft.  Even with that capability it's not so nice
for 32-bit code to need casts to long long, so this patch makes 'L' a
modifier for bfd_vma rather than an alias for 'll'.

I've then used the new 'L' modifier to fix selected format strings.

	* bfd.c (_doprnt): Rewrite "ll" and "L" modifiers to "I64" for
	__MSVCRT__.  Support "L" modifier for bfd_vma.  Formatting.
	* elf.c (setup_group): Use "Lx" to print sh_size.
	(_bfd_elf_setup_sections): Remove unnecessary cast and print
	unknown section type in hex.
	(copy_special_section_fields): Style fix.
	(bfd_section_from_shdr): Correct format for sh_link.  Use a
	common error message for all the variants of unrecognized
	section types.
	(assign_file_positions_for_load_sections): Use "Lx" for lma
	adjust error message.
	(assign_file_positions_for_non_load_sections): Formatting.
	(rewrite_elf_program_header): Formatting.  Use "Lx" for
	bfd_vma values in error messages.
	* elfcode.h (elf_slurp_reloc_table_from_section): Cast
	ELF_R_SYM value to type expected by format.
	* elflink.c (elf_link_read_relocs_from_section): Use "Lx"
	in error messages.
	(elf_link_add_object_symbols): Use "Lu" for symbol sizes.
	(elf_link_input_bfd): Use "Lx" for r_info.
	(bfd_elf_gc_record_vtinherit): Use "Lx" for offset.
2017-07-03 22:03:49 +09:30
Alan Modra ce9116fdbf BFD long long cleanup
long long isn't supposed to be used without a configure test, to
support ancient compilers.  Probably not terribly important nowadays.

	* bfd.c (bfd_scan_vma): Don't use long long unless HAVE_LONG_LONG.
	* coff-rs6000.c (FMT20): Handle hosts with 64-bit long and
	Microsoft C library variant of long long format specifier.
	(PRINT20): Cast value to bfd_uint64_t not long long.
	* coffcode.h (coff_print_aux): Use BFD_VMA_FMT.
	* coff-x86_64.c (coff_amd64_reloc): Use bfd_uint64_t rather than
	long long.  Don't cast to bfd_vma.
	* elf32-score.c (score3_bfd_getl48): Likewise.
	* vms-alpha.c (_bfd_vms_slurp_eisd): Likewise.
2017-07-03 22:03:48 +09:30
Alan Modra cd9af601e6 Miscellaneous format string fixes
* elf.c (_bfd_elf_print_private_bfd_data): Use BFD_VMA_FMT to
	print d_tag.
	(bfd_elf_print_symbol): Don't cast symbol->flags.
	(_bfd_elf_symbol_from_bfd_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_begin_write_processing): Correct
	_bfd_error_handler argument order.
	(ppc_elf_merge_private_bfd_data): Don't cast flags.
2017-07-03 22:03:28 +09:30
Alan Modra 33c734b2f8 Missing config for bfd.c:_doprnt
This function uses HAVE_LONG_LONG and HAVE_LONG_DOUBLE

	* configure.ac: Invoke AC_CHECK_TYPES for long long.  Invoke
	AC_TYPE_LONG_DOUBLE.
	* configure: Regenerate.
	* config.in: Regenerate.
2017-07-03 21:55:57 +09:30
GDB Administrator 2040444f33 Automatic date update in version.in 2017-07-03 00:00:39 +00:00
GDB Administrator c6eb149dfa Automatic date update in version.in 2017-07-02 00:00:47 +00:00
GDB Administrator 3c465ea0ff Automatic date update in version.in 2017-07-01 00:00:41 +00:00
GDB Administrator 8d011e87df Automatic date update in version.in 2017-06-30 00:00:30 +00:00
Andrew Waterman 3df5cd1394 RISC-V: Fix TLS copy relocs
The dynrelro introduction wasn't implemented quite right for RISC-V,
as it didn't consider TLS copy relocs.

bfd/ChangeLog

2017-06-29  Andrew Waterman  <andrew@sifive.com>

        * elfnn-riscv.c (riscv_elf_adjust_dynamic_symbol): Fix TLS copy
        relocs.
2017-06-29 09:38:50 -07:00
Egeyar Bagcioglu ec1acaba13 bfd: prevent all but undef weak syms from becoming dynamic in sparc.
Prevent sparc backend making symbols dynamic unless they are undefined
weak. Use R_SPARC_RELATIVE for the symbols which are not dynamic in PIC.

This patch is tested on sparc64-unknown-linux-gnu, no regressions are
found.

bfd/ChangeLog:

2017-06-29  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>

	* elfxx-sparc.c (allocate_dynrelocs): Don't make a symbol dynamic
	unless it is undefined weak.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Set the flag
	relative_reloc to direct non-dynamic symbols to R_SPARC_RELATIVE
	relocation.
	* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): If symbol
        is not dynamic in PIC, abort.
2017-06-29 04:28:27 -07:00
Jiong Wang ff07562f1e [AArch64] Only override the symbol dynamic decision on undefined weak symbol
This fix is an adaption of the x86-64 PR ld/21402 fix to AArch64.

After the generic code deciding one symbol is not dynamic, AArch64 backend
only overrides the decision on undefined weak symbols.

bfd/
	PR ld/21402
	* elfnn-aarch64.c (elfNN_aarch64_allocate_dynrelocs): Only make
	undefined weak symbols into dynamic.
	(elfNN_aarch64_final_link_relocate): Generate runtime RELATIVE
	relocation for non-dynamic symbols.
	(elfNN_aarch64_finish_dynamic_symbol): Add sanity check.
2017-06-29 11:47:43 +01:00
Jiong Wang 2aff25ba76 [AArch64] Remove duplicated code when handling some GOT relocations types
There are quite a few duplicated code supporting several GP based
relocation types.  They are:

  BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
  BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
  BFD_RELOC_AARCH64_MOVW_GOTOFF_G1

These relocation types are supposed to be used for large memory model PIC/pic
mode under which we will have an initialized GP register points to the base of
GOT table, then these relocations are supposed to put the distance between GOT
entry and GOT table base address into the related instructions.

So, the parameters required to calculate the relocation should be the same as
BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 etc, all of them are require the GOT entry
address and GOT table base address to perform the relocation.

This patch has removed those duplicated code when handling above listed
relocation types,  grouped them with others as relocation types that are
require GOT table base address during performing relocation, reused the
existed GOT handling code.

The relocation calculation for these types before and after this patch should be
identical.

bfd/
	* elfnn-aarch64.c (aarch64_relocation_aginst_gp_p): New function.
	(elfNN_aarch64_final_link_relocate): Delete duplicated code for
	BFD_RELOC_AARCH64_LD64_GOTOFF_LO15, BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC,
	BFD_RELOC_AARCH64_MOVW_GOTOFF_G1.
	* elfxx-aarch64.c (_bfd_aarch64_elf_resolve_relocation): Optimize the
	support for them.
2017-06-29 11:45:24 +01:00
Andreas Arnez 88ab90e860 S390: Support guarded-storage core note sections
Newer Linux kernel versions offer two new register sets in support of the
z/Architecture's guarded storage facility: NT_S390_GS_CB, the
"guarded-storage registers", and NT_S390_GS_BC, the "guarded-storage
broadcast control block".  This patch adds support for the respective core
notes sections to binutils.

bfd/ChangeLog:
	* elf-bfd.h (elfcore_write_s390_gs_cb): Add prototype.
	(elfcore_write_s390_gs_bc): Likewise.
	* elf.c (elfcore_grok_s390_gs_cb): New function.
	(elfcore_grok_s390_gs_bc): New function.
	(elfcore_grok_note): Call them.
	(elfcore_write_s390_gs_cb): New function.
	(elfcore_write_s390_gs_bc): New function.
	(elfcore_write_register_note): Call them.

binutils/ChangeLog:
	* readelf.c (get_note_type): Add NT_S390_GS_CB and NT_S390_GS_BC.

include/ChangeLog:
	* elf/common.h (NT_S390_GS_CB): New macro.
	(NT_S390_GS_BC): Likewise.
2017-06-29 10:30:09 +02:00
GDB Administrator 1b19ec9710 Automatic date update in version.in 2017-06-29 00:01:02 +00:00
H.J. Lu 328ce951b2 Don't call bfd_get_file_size in _bfd_generic_get_section_contents
Since it is impossible to read beyond the end of normal files, we only
need to check archive element size in _bfd_generic_get_section_contents

	* libbfd.c (_bfd_generic_get_section_contents): Don't call
	bfd_get_file_size.  Check archive element size.
	(_bfd_generic_get_section_contents_in_window): Likewise.
2017-06-28 11:07:04 -07:00
H.J. Lu 47fdcf63c0 Change bfd_get_size/bfd_get_file_size to ufile_ptr
bfd_get_size and bfd_get_file_size should return the unsigned file
size.  Otherwise they return negative values for file >= 2GB with
32-bit ufile_ptr.

bfd/

	* bfd-in2.h: Regenerated.
	* bfdio.c (bfd_get_size): Change return type to ufile_ptr.
	(bfd_get_file_size): Likewise.

binutils/

	* objdump.c (dump_relocs_in_section): Cast to ufile_ptr when
	comparing against bfd_get_file_size return.
2017-06-28 11:01:21 -07:00
Maciej W. Rozycki 38bf472a15 MIPS: Add Imagination interAptiv MR2 MIPS32r3 processor support
Add support for the Imagination interAptiv MR2 MIPS32r3 processor with
the MIPS16e2 ASE as per documentation, including in particular:

1. Support for implementation-specific interAptiv MR2 COPYW and UCOPYW
   MIPS16e2 instructions[1], for assembly and disassembly,

2. Support for implementation-specific interAptiv MR2 SAVE and RESTORE
   regular MIPS instructions[2], for assembly and disassembly,

3. ELF binary file annotation for the interAptiv MR2 MIPS architecture
   extension.

4. Support for interAptiv MR2 architecture selection for assembly, in
   the form of the `-march=interaptiv-mr2' command-line option and its
   corresponding `arch=interaptiv-mr2' setting for the `.set' and
   `.module' pseudo-ops.

5. Support for interAptiv MR2 architecture selection for disassembly,
   in the form of the `mips:interaptiv-mr2' target architecture, for
   use e.g. with the `-m' command-line option for `objdump'.

Parts of this change by Matthew Fortune and Andrew Bennett.

References:

[1] "MIPS32 interAptiv Multiprocessing System Software User's Manual",
    Imagination Technologies Ltd., Document Number: MD00904, Revision
    02.01, June 15, 2016, Section 24.3 "MIPS16e2 Implementation Specific
    Instructions", pp. 878-883

[2] same, Chapter 25 "Implementation-specific Instructions", pp. 911-917

	include/
	* elf/mips.h (E_MIPS_MACH_IAMR2): New macro.
	(AFL_EXT_INTERAPTIV_MR2): Likewise.
	* opcode/mips.h: Document new operand codes defined.
	(INSN_INTERAPTIV_MR2): New macro.
	(INSN_CHIP_MASK): Adjust accordingly.
	(CPU_INTERAPTIV_MR2): New macro.
	(cpu_is_member) <CPU_INTERAPTIV_MR2>: New case.
	(MIPS16_ALL_ARGS): Rename to...
	(MIPS_SVRS_ALL_ARGS): ... this.
	(MIPS16_ALL_STATICS): Rename to...
	(MIPS_SVRS_ALL_STATICS): ... this.

	bfd/
	* archures.c (bfd_mach_mips_interaptiv_mr2): New macro.
	* cpu-mips.c (I_interaptiv_mr2): New enum value.
	(arch_info_struct): Add "mips:interaptiv-mr2" entry.
	* elfxx-mips.c (_bfd_elf_mips_mach) <E_MIPS_MACH_IAMR2>: New
	case.
	(mips_set_isa_flags) <bfd_mach_mips_interaptiv_mr2>: Likewise.
	(bfd_mips_isa_ext) <bfd_mach_mips_interaptiv_mr2>: Likewise.
	(print_mips_isa_ext) <AFL_EXT_INTERAPTIV_MR2>: Likewise.
	(mips_mach_extensions): Add `bfd_mach_mipsisa32r3' and
	`bfd_mach_mips_interaptiv_mr2' entries.
	* bfd-in2.h: Regenerate.

	opcodes/
	* mips-formats.h (INT_BIAS): New macro.
	(INT_ADJ): Redefine in INT_BIAS terms.
	* mips-dis.c (mips_arch_choices): Add "interaptiv-mr2" entry.
	(mips_print_save_restore): New function.
	(print_insn_arg) <OP_SAVE_RESTORE_LIST>: Update comment.
	(validate_insn_args) <OP_SAVE_RESTORE_LIST>: Remove `abort'
	call.
	(print_insn_args): Handle OP_SAVE_RESTORE_LIST.
	(print_mips16_insn_arg): Call `mips_print_save_restore' for
	OP_SAVE_RESTORE_LIST handling, factored out from here.
	* mips-opc.c (decode_mips_operand) <'-'> <'m'>: New case.
	(RD_31, RD_SP, WR_SP, MOD_SP, IAMR2): New macros.
	(mips_builtin_opcodes): Add "restore" and "save" entries.
	* mips16-opc.c (decode_mips16_operand) <'n', 'o'>: New cases.
	(IAMR2): New macro.
	(mips16_opcodes): Add "copyw" and "ucopyw" entries.

	binutils/
	* readelf.c (get_machine_flags) <E_MIPS_MACH_IAMR2>: New case.
	(print_mips_isa_ext) <AFL_EXT_INTERAPTIV_MR2>: Likewise.
	* NEWS: Mention Imagination interAptiv MR2 processor support.

	gas/
	* config/tc-mips.c (validate_mips_insn): Handle
	OP_SAVE_RESTORE_LIST specially.
	(mips_encode_save_restore, mips16_encode_save_restore): New
	functions.
	(match_save_restore_list_operand): Factor out SAVE/RESTORE
	operand insertion into the instruction word or halfword to these
	new functions.
	(mips_cpu_info_table): Add "interaptiv-mr2" entry.

	* doc/c-mips.texi (MIPS Options): Add `interaptiv-mr2' to the
	`-march=' argument list.
2017-06-28 02:07:36 +01:00
GDB Administrator 9991e9d77f Automatic date update in version.in 2017-06-28 00:00:40 +00:00
Nick Clifton 2d68166e87 Remove debugging accidentally left in tekhex.c.
* tekhex.c (pass_over): Revert accidental conversion of a local
	array to a static array.
2017-06-27 12:11:22 +01:00
Senthil Kumar Selvaraj 6806377956 Fix PR 13402
Fix incorrect adjustment of diff relocs when relaxing, and thus the
resulting source line to address mismatch.

Fix two issues when adjusting diff relocs to account for
deleted bytes.

1. Don't adjust the difference if the end address is the shrinked
insn's address i.e. use < instead of <=. The relaxation code deletes
count bytes from or after shrinked_insn_address, so the difference
between start_address and end_address should remain unchanged in this
case.

2. Adjust the reloc addend if the difference is to be adjusted and
symval + reloc addend is past the shrinked insn address. This is
because for a typical sym1 - sym2 diff reloc, sym1 is .text +
irel->r_addend, and the addend should be reduced to account for the
shrinked insn.

For example, assume the reloc value is .text + 0x8 with .text = 0, the
diff value in the object file = 0x4, and shrinked_insn_address = 0x4
with count = 0x2. Then the existing code writes 0x2 into the object
file to account for the deleted bytes, as shrinked_insn_address lies
between 0x8 and 0x8 - 0x4 = 0x4, but leaves the addend as is. The next
time the reloc is looked at, the code sees if a shrinked_insn_address
lies between 0x8 and 0x8 - 0x2 = 0x6, instead of 0x6 and 0x4. If there
happens to be one, then the diff value in the object file ends up
getting reduced again.

bfd/

2017-06-27  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/13402
	* elf32-avr.c (elf32_avr_adjust_diff_reloc_value): Adjust
	reloc addend if necessary. Adjust diff only if
	shrinked_insn_address < end_address.

ld/

2017-06-27  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/13402
	* testsuite/ld-avr/pr13402.d: New test.
	* testsuite/ld-avr/pr13402.s: New test.
2017-06-27 14:47:02 +05:30
Alan Modra ea9aafc41a Warning fix
PR binutils/21665
	* libbfd.c (_bfd_generic_get_section_contents): Warning fix.
	(_bfd_generic_get_section_contents_in_window): Likewise.
2017-06-27 14:46:52 +09:30
Kuan-Lin Chen a6cbf936e3 RISC-V: Use pc-relative relocation for FDE initial location
The symbol address in .eh_frame may be adjusted in
_bfd_elf_discard_section_eh_frame, and the content of .eh_frame will be
adjusted in _bfd_elf_write_section_eh_frame. Therefore, we cannot insert
a relocation whose addend symbol is in .eh_frame. Othrewise, the value
may be adjusted twice.

bfd/ChangeLog
2017-06-26  Kuan-Lin Chen  <rufus@andestech.com>

	* elfnn-riscv.c (perform_relocation): Support the new
	R_RISCV_32_PCREL relocation.
	(riscv_elf_relocate_section): Likewise.
	* elfxx-riscv.c (howto_table): Likewise.
	(riscv_reloc_map): Likewise.
	* bfd-in2.h (BFD_RELOC_RISCV_32_PCREL): New relocation.
	* libbfd.h: Regenerate.

gas/ChangeLog
2017-06-26  Kuan-Lin Chen  <rufus@andestech.com>

	* config/tc-riscv.c (md_apply_fix) [BFD_RELOC_32]: Convert to a
	R_RISCV_32_PCREL relocation.

include/ChangeLog
2017-06-26  Kuan-Lin Chen  <rufus@andestech.com>

	* elf/riscv.h (R_RISCV_32_PCREL): New.
2017-06-26 18:26:40 -07:00
Alan Modra 7211ae501e More fixes for bfd_get_section_contents change
PR binutils/21665
	* libbfd.c (_bfd_generic_get_section_contents): Delete abort.
	Use unsigned file pointer type, and remove cast.
	* libbfd.c (_bfd_generic_get_section_contents_in_window): Likewise.
	Add "count", not "sz".
2017-06-27 09:46:45 +09:30
GDB Administrator dc819143fe Automatic date update in version.in 2017-06-27 00:01:02 +00:00
Pedro Alves ab27f80c5d Fix GDB regressions caused by previous bfd_get_section_contents changes
Ref: https://sourceware.org/ml/binutils/2017-06/msg00343.html

bfd/ChangeLog:
2017-06-26  Pedro Alves  <palves@redhat.com>

	PR binutils/21665
	* libbfd.c (_bfd_generic_get_section_contents): Add "count", not
	"sz".
2017-06-27 00:21:25 +01:00
H.J. Lu 1f473e3d0a Add a missing line to _bfd_generic_get_section_contents_in_window
PR binutils/21665
	* libbfd.c (_bfd_generic_get_section_contents_in_window): Add
	a missing line.
2017-06-26 15:47:16 -07:00
Maciej W. Rozycki b417536f23 MIPS/BFD: Consistently mark the LSI CW4010 as a MIPS II processor
Make BFD agree with GAS and mark the LSI MiniRISC CW4010 processor core
(for an odd reason referred to as LSI R4010 across our code base) as a
MIPS II processor in BFD as well, fixing a bug that has been there since
forever and addressing linker warnings like:

$ as -m4010 empty.s -o 4010.o
$ ld -r 4010.o -o 4010-r.o
ld: 4010.o: warning: Inconsistent ISA between e_flags and .MIPS.abiflags
$

due to the ISA level being recorded as MIPS III in ELF file header's
`e_flags' vs MIPS II in the MIPS ABI Flags section:

$ readelf -Ah 4010.o
ELF Header:
  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, big endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          348 (bytes into file)
  Flags:                             0x20821000, 4010, o32, mips3
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         11
  Section header string table index: 10
Attribute Section: gnu
File Attributes
  Tag_GNU_MIPS_ABI_FP: Hard float (double precision)

MIPS ABI Flags Version: 0

ISA: MIPS2
GPR size: 32
CPR1 size: 32
CPR2 size: 0
FP ABI: Hard float (double precision)
ISA Extension: LSI R4010
ASEs:
	None
FLAGS 1: 00000000
FLAGS 2: 00000000
$

Available documentation[1][2] clearly indicates the LSI CW4010 processor
is only backwards compatible with the MIPS R4000 processor as far as the
latter's 32-bit instructions are concerned and consequently can only be
considered a MIPS II ISA implementation (with vendor extensions).

This fixes an LD testsuite failure:

FAIL: MIPS incompatible objects:  "-march=r4010 -32"      "-march=r4650 -32"

triggered for the `mips-sgi-irix5' and `mips-sgi-irix6' targets.

References:

[1] Paul Cobb, Bob Caulk, Joe Cesana, "The MiniRISC CW4010: A
    Superscalar MIPS Processor ASIC Core", LSI Logic, July 1995,
    presented at Hot Chips VII, Stanford University, Stanford,
    California, August 1995

[2] "MiniRISC MR4010 Superscalar Microprocessor Reference Device", LSI
    Logic, November 1996, Doc. No. DB09-000028-00, Order No. C15017

	bfd/
	* cpu-mips.c (arch_info_struct): Mark the 4010 32-bit.
	* elfxx-mips.c (mips_set_isa_flags) <bfd_mach_mips4010>: Set
	E_MIPS_ARCH_2 rather than E_MIPS_ARCH_3 in `e_flags'.
	(mips_mach_extensions): Mark `bfd_mach_mips4010' as extending
	`bfd_mach_mips6000' rather than `bfd_mach_mips4000'.

	ld/
	* testsuite/ld-mips-elf/lsi-4010-isa.d: New test.
	* ld/testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2017-06-26 19:27:14 +01:00
H.J. Lu 0630b49c47 Check file size before getting section contents
Don't check the section size in bfd_get_full_section_contents since
the size of a decompressed section may be larger than the file size.
Instead, check file size in _bfd_generic_get_section_contents.

	PR binutils/21665
	* compress.c (bfd_get_full_section_contents): Don't check the
	file size here.
	* libbfd.c (_bfd_generic_get_section_contents): Check for and
	reject a section whoes size + offset is greater than the size
	of the entire file.
	(_bfd_generic_get_section_contents_in_window): Likewise.
2017-06-26 09:30:20 -07:00
Maciej W. Rozycki 515a446417 LD: Fix .startof.SECNAME/.sizeof.SECNAME tests for MIPS/IRIX
Correct .startof.SECNAME/.sizeof.SECNAME tests for MIPS/IRIX targets,
complementing commit dc74becf49 ("ld: Add tests for -Ur") and commit
da614360f5 ("ld: Add tests for .startof.SECNAME/.sizeof.SECNAME") with
subsequent updates, and in reference to commit cbd0eecf26 ("Always
define referenced __start_SECNAME/__stop_SECNAME") and commit
7dba9362c1 ("Rewrite __start and __stop symbol handling").

These targets set the STT_OBJECT type for non-function symbol
references, according to `elf_frob_symbol' code in gas/config/obj-elf.c:

  /* The Irix 5 and 6 assemblers set the type of any common symbol and
     any undefined non-function symbol to STT_OBJECT.  We try to be
     compatible, since newer Irix 5 and 6 linkers care.  However, we
     only set undefined symbols to be STT_OBJECT if we are on Irix,
     because that is the only time gcc will generate the necessary
     .global directives to mark functions.  */

  if (S_IS_COMMON (symp))
    symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;

  if (strstr (TARGET_OS, "irix") != NULL
      && ! S_IS_DEFINED (symp)
      && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0)
    symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;

and consequently entries in the symbol table listing from `readelf'
produced with these tests do not match the NOTYPE pattern expected,
causing test suite failures:

FAIL: ld-elf/sizeofa
FAIL: ld-elf/sizeofc
FAIL: ld-elf/startofa
FAIL: ld-elf/startofc

specifically with the `mips-sgi-irix5' and `mips-sgi-irix6' targets.

Given that it does not matter for the feature covered by these tests
whether the type of the symbols produced is STT_NOTYPE or STT_OBJECT
adjust the problematic cases to accept either type, removing the
failures observed.

	ld/
	* testsuite/ld-elf/sizeofa.d: Also accept the OBJECT type for
	the symbols examined.
	* testsuite/ld-elf/sizeofc.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofc.d: Likewise.
2017-06-26 16:15:15 +01:00
Nick Clifton 04e15b4a94 Fix address violation parsing a corrupt texhex format file.
PR binutils/21670
	* tekhex.c (getvalue): Check for the source pointer exceeding the
	end pointer before the first byte is read.
2017-06-26 15:46:34 +01:00
Nick Clifton cfd14a500e Fix address violations when atempting to parse fuzzed binaries.
PR binutils/21665
bfd	* opncls.c (get_build_id): Check that the section is beig enough
	to contain the whole note.
	* compress.c (bfd_get_full_section_contents): Check for and reject
	a section whoes size is greater than the size of the entire file.
	* elf32-v850.c (v850_elf_copy_notes): Allow for the ouput to not
	contain a notes section.

binutils* objdump.c (disassemble_section): Skip any section that is bigger
	than the entire file.
2017-06-26 15:25:08 +01:00
Andreas Krebbel fd52715cfa Add pgste marker changelog 2017-06-26 11:07:17 +02:00
Andreas Krebbel 93ec5e2376 S/390: Fix testsuite segfault added with recent pgste patch.
The recent pgste patch caused several testcases to fail with a
segfault.  Fixed with this patch by adding NULL pointer checks.

regression-tested on s390x.

bfd/ChangeLog:

2017-06-26  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf64-s390.c (elf_s390_additional_program_headers): Add NULL
	pointer checks.
	(elf_s390_modify_segment_map): Likewise.
	(bfd_elf_s390_set_options): Lisewise.
2017-06-26 11:01:58 +02:00
GDB Administrator 46adbd1740 Automatic date update in version.in 2017-06-26 00:00:38 +00:00
Alan Modra 57963c05b9 Don't attach linker created section to --just-syms bfd
All sections on a --just-syms bfd are discarded from the output, so
attaching linker created sections to such a bfd results in errors.
In other cases, like the .note.GNU-stack check, it's wrong to have a
--just-syms object potentially affect the output.

bfd/
	* elflink.c (_bfd_elf_link_create_dynstrtab): Don't make dynobj
	a --just-syms bfd.
	(_bfd_elf_size_group_sections): Skip --just-syms bfds.
	(bfd_elf_size_dynamic_sections): Ignore .note.GNU-stack and
	.preinit_array on --just-syms bfds.
	(_bfd_elf_gc_mark_extra_sections): Skip --just-syms bfds.
	(elf_gc_sweep, bfd_elf_parse_eh_frame_entries): Likewise.
	(bfd_elf_gc_sections, bfd_elf_discard_info): Likewise.
ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Skip
	--just-syms bfds when looking for a place to attach .note.gnu.build-id
	and .eh_frame_hdr sections.  Delete dead code.
2017-06-26 09:10:22 +09:30
Sergei Trofimovich 5cc4ca837d fix out-of-bounds access in elf.c:find_link
The out-of-bounds access is reproducible on 'ia64-strip' command
(see sample from https://bugs.gentoo.org/show_bug.cgi?id=622500)

The output file contains less section than original one.
This tricks 'hint' access to go out-of-bounds:

	* elf.c (find_link): Bounds check "hint".
2017-06-25 10:29:57 +09:30
GDB Administrator b21351faa2 Automatic date update in version.in 2017-06-25 00:00:40 +00:00
Thomas Preud'homme bff0500d7a [ARM] Add linker support for ARMv8-R
=== Context ===

This patch is part of a patch series to add support for ARMv8-R
architecture. Its purpose is to add support for ARMv8-R in the linker.

=== Patch description ===

This patch is composed of 3 changes:

1) The main change is the addition of the logic for merging a file whose
Tag_CPU_arch build attribute is 15 (ARMv8-R). Namely, all pre-ARMv8 are
merged into ARMv8-R as well as ARMv8-R itself. ARMv8-A (14) merges into
ARMv8-A. ARMv8-M Baseline (16) and Mainline (17) are not allowed to
merge merge with ARMv8-R. Note that merging only occurs if the two
profiles are identical or one is S (Application or Realtime) and the
other is R.

2) using_thumb_only, using_thumb2_bl, using_thumb2 and arch_has_arm_nop
are updated according to capabilities of ARMv8-R and their BFD_ASSERT
updated to reflect that the logic is valid for ARMv8-R.

3) 2 build attribute merging tests are added to test the first change.

2017-06-24  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (using_thumb_only): Update list of architectures in
	BFD_ASSERT for which the logic is valid.
	(using_thumb2_bl): Likewise.
	(using_thumb2): Likewise and return true for ARMv8-R.
	(arch_has_arm_nop): Likewise.
	(tag_cpu_arch_combine): New v8r table for ARMv8-R Tag_CPU_arch
	merging logic.  Update commentis for value 15 of v8m_baseline,
	v8m_mainline and v4t_plus_v6_m arrays.  Use v8r array to decide
	merging of value 15 of Tag_CPU_arch.

ld/
	* testsuite/ld-arm/arm-elf.exp (EABI attribute merging 11): New test.
	(EABI attribute merging 12): Likewise.
	* testsuite/ld-arm/attr-merge-11a.s: New file.
	* testsuite/ld-arm/attr-merge-11b.s: New file.
	* testsuite/ld-arm/attr-merge-11.attr: New file.
	* testsuite/ld-arm/attr-merge-12a.s: New file.
	* testsuite/ld-arm/attr-merge-12b.s: New file.
	* testsuite/ld-arm/attr-merge-12.attr: New file.
2017-06-24 10:48:08 +01:00
GDB Administrator 926770baf4 Automatic date update in version.in 2017-06-24 00:00:42 +00:00
Jiong Wang 4aa57d6a2b [AArch64] Fix typo in comments on relocation name
BFD_RELOC_AARCH64_ADR_GOTPAGE should be BFD_RELOC_AARCH64_ADR_GOT_PAGE.

bfd/
  * reloc.c (BFD_RELOC_AARCH64_ADR_GOTPAGE): Rename to
  BFD_RELOC_AARCH64_ADR_GOT_PAGE
  * bfd-in2.h: Regenerated.
2017-06-23 13:45:30 +01:00
Andreas Krebbel b4cbbe8f72 S/390: Add support for pgste marker
This patch adds a new S/390 specific segment type: PT_S390_PGSTE.  For
binaries marked with that segment the kernel will allocate 4k page
tables.  The only user so far will be qemu.

ld/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* Makefile.in: Add s390.em as build dependency.
	* emulparams/elf64_s390.sh (EXTRA_EM_FILE): Add s390.em.
	* emultempl/s390.em: New file.
	* gen-doc.texi: Add documentation for --s390-pgste option.
	* ld.texinfo: Likewise.

include/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf/s390.h (PT_S390_PGSTE): Define macro.

binutils/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* readelf.c (get_s390_segment_type): Add support for the new
	segment type PT_S390_PGSTE.
	(get_segment_type): Call get_s390_segment_type.

elfcpp/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elfcpp.h (enum PT): Add PT_S390_PGSTE to enum.

bfd/ChangeLog:

2017-06-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf-s390.h: New file.
	* elf64-s390.c (struct elf_s390_link_hash_table): Add params
	field.
	(elf_s390_additional_program_headers): New function.
	(elf_s390_modify_segment_map): New function.
	(bfd_elf_s390_set_options): New function.
	(elf_backend_additional_program_headers)
	(elf_backend_modify_segment_map): Add macro definitions.
2017-06-23 08:00:46 +02:00
GDB Administrator 790ba5c898 Automatic date update in version.in 2017-06-23 00:00:39 +00:00
H.J. Lu 5d8763a382 x86-64: Move the error_alignment label forward
Move the error_alignment label forward to avoid clang warning on

if (!bfd_set_section_alignment (ebfd, sec, 2))
  goto error_alignment;

htab = elf_x86_64_hash_table (info);

error_alignment:
  info->callbacks->einfo (_("%F%A: failed to align section\n"), sec);
                             "%F" causes a fatal linker error and
			     immediate exit.

sec = htab->elf.sgotplt;

Also fix alignment on program property note section.

	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Move
	the error_alignment label forward.  Properly align program
	property note section.
2017-06-22 14:26:09 -07:00
H.J. Lu 84da4cf89e x86: Resolve local undefined weak symbol to 0
Local undefined weak symbol should always be resolved to 0.

	* elf32-i386.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Resolve
	local undefined weak symbol to 0.
	* elf64-x86-64.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Likewise.
2017-06-22 12:53:39 -07:00
Eric Christopher e652757bad 2017-06-22 Eric Christopher <echristo@gmail.com>
* elf32-arm.c (elf32_arm_final_link_relocate): Use labs	rather than
	abs to fix a truncation warning.
2017-06-22 11:01:13 -07:00
H.J. Lu 48580982ef x86: Support Intel Shadow Stack with SHSTK property
To support Intel Shadow Stack (SHSTK) in Intel Control-flow Enforcement
Technology (CET) instructions:

https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf

 #define GNU_PROPERTY_X86_FEATURE_1_SHSTK (1U << 1)

is added to GNU program properties to indicate that all executable sections
are compatible with SHSTK where return address popped from shadow stack
always matches return address popped from normal stack.

GNU_PROPERTY_X86_FEATURE_1_SHSTK is set on output only if it is set on all
relocatable inputs.

bfd/

	* elf32-i386.c (elf_i386_merge_gnu_properties): If info->shstk
	is set, turn on GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	(elf_i386_link_setup_gnu_properties): If info->shstk is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.
	* elf64-x86-64.c (elf_x86_64_merge_gnu_properties): If
	info->shstk is set, turn on GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	(elf_x86_64_link_setup_gnu_properties): If info->shstk is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.

binutils/

	* readelf.c (decode_x86_feature): Decode
	GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	* testsuite/binutils-all/i386/shstk.d: New file.
	* testsuite/binutils-all/i386/shstk.s: Likewise.
	* testsuite/binutils-all/x86-64/shstk-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk.s: Likewise.

include/

	* bfdlink.h (bfd_link_info): Add shstk.
	* elf/common.h (GNU_PROPERTY_X86_FEATURE_1_SHSTK): New.

ld/

	* NEWS: Mention -z shstk and GNU_PROPERTY_X86_FEATURE_1_SHSTK.
	* emulparams/cet.sh (PARSE_AND_LIST_OPTIONS_CET): Add "-z shstk".
	(PARSE_AND_LIST_ARGS_CASE_Z_CET): Support "-z shstk".
	* ld.texinfo: Document -z shstk.
	* testsuite/ld-i386/i386.exp: Run SHSTK tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/property-x86-shstk.s: New file.
	* testsuite/ld-i386/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk2.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk4.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk.s: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5.d: Likewise.
2017-06-22 05:50:31 -07:00
H.J. Lu ee2fdd6f36 x86: Support Intel IBT with IBT property and IBT-enable PLT
To support IBT in Intel Control-flow Enforcement Technology (CET)
instructions:

https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf

 #define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002

 #define GNU_PROPERTY_X86_FEATURE_1_IBT (1U << 0)

are added to GNU program properties to indicate that all executable
sections are compatible with IBT when ENDBR instruction starts each
valid target where an indirect branch instruction can land.

GNU_PROPERTY_X86_FEATURE_1_IBT is set on output only if it is set on
all relocatable inputs.

The followings changes are made to the Procedure Linkage Table (PLT):

1. For 64-bit x86-64,  PLT is changed to

PLT0:  push       GOT[1]
       bnd jmp    *GOT[2]
       nop
...
PLTn:  endbr64
       push       namen_reloc_index
       bnd jmp    PLT0

together with the second PLT section:

PLTn:  endbr64
       bnd jmp   *GOT[namen_index]
       nop

BND prefix is also added so that IBT-enabled PLT is compatible with MPX.

2. For 32-bit x86-64 (x32) and i386,  PLT is changed to

PLT0:  push       GOT[1]
       jmp        *GOT[2]
       nop
...
PLTn:  endbr64                                 # endbr32 for i386.
       push       namen_reloc_index
       jmp        PLT0

together with the second PLT section:

PLTn:  endbr64                                 # endbr32 for i386.
       jmp       *GOT[namen_index]
       nop

BND prefix isn't used since MPX isn't supported on x32 and BND registers
aren't used in parameter passing on i386.

GOT is an array of addresses.  Initially, GOT[namen_index] is filled
with the address of the ENDBR instruction of the corresponding entry
in the first PLT section.  The function, namen, is called via the
ENDBR instruction in the second PLT entry.  GOT[namen_index] is updated
to the actual address of the function, namen, at run-time.

2 linker command line options are added:

1. -z ibtplt: Generate IBT-enabled PLT.
2. -z ibt: Generate GNU_PROPERTY_X86_FEATURE_1_IBT in GNU program
properties as well as IBT-enabled PLT.

bfd/

	* elf32-i386.c (elf_i386_lazy_ibt_plt0_entry): New.
	(elf_i386_lazy_ibt_plt_entry): Likewise.
	(elf_i386_pic_lazy_ibt_plt0_entry): Likewise.
	(elf_i386_non_lazy_ibt_plt_entry): Likewise.
	(elf_i386_pic_non_lazy_ibt_plt_entry): Likewise.
	(elf_i386_eh_frame_lazy_ibt_plt): Likewise.
	(elf_i386_lazy_plt_layout): Likewise.
	(elf_i386_non_lazy_plt_layout): Likewise.
	(elf_i386_link_hash_entry): Add plt_second.
	(elf_i386_link_hash_table): Add plt_second and
	plt_second_eh_frame.
	(elf_i386_allocate_dynrelocs): Use the second PLT if needed.
	(elf_i386_size_dynamic_sections): Use .plt.got unwind info for
	the second PLT.  Check the second PLT.
	(elf_i386_relocate_section): Use the second PLT to resolve
	PLT reference if needed.
	(elf_i386_finish_dynamic_symbol): Fill and use the second PLT if
	needed.
	(elf_i386_finish_dynamic_sections): Set sh_entsize on the
	second PLT.  Generate unwind info for the second PLT.
	(elf_i386_plt_type): Add plt_second.
	(elf_i386_get_synthetic_symtab): Support the second PLT.
	(elf_i386_parse_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.
	(elf_i386_merge_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.  If info->ibt is set, turn
	on GNU_PROPERTY_X86_FEATURE_1_IBT
	(elf_i386_link_setup_gnu_properties): If info->ibt is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.  Use IBT-enabled PLT
	for info->ibtplt, info->ibt or GNU_PROPERTY_X86_FEATURE_1_IBT
	is set on all relocatable inputs.
	* elf64-x86-64.c (elf_x86_64_lazy_ibt_plt_entry): New.
	(elf_x32_lazy_ibt_plt_entry): Likewise.
	(elf_x86_64_non_lazy_ibt_plt_entry): Likewise.
	(elf_x32_non_lazy_ibt_plt_entry): Likewise.
	(elf_x86_64_eh_frame_lazy_ibt_plt): Likewise.
	(elf_x32_eh_frame_lazy_ibt_plt): Likewise.
	(elf_x86_64_lazy_ibt_plt): Likewise.
	(elf_x32_lazy_ibt_plt): Likewise.
	(elf_x86_64_non_lazy_ibt_plt): Likewise.
	(elf_x32_non_lazy_ibt_plt): Likewise.
	(elf_x86_64_get_synthetic_symtab): Support the second PLT.
	(elf_x86_64_parse_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.
	(elf_x86_64_merge_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_AND.  If info->ibt is set, turn
	on GNU_PROPERTY_X86_FEATURE_1_IBT
	(elf_x86_64_link_setup_gnu_properties): If info->ibt is set,
	turn on GNU_PROPERTY_X86_FEATURE_1_IBT.  Use IBT-enabled PLT
	for info->ibtplt, info->ibt or GNU_PROPERTY_X86_FEATURE_1_IBT
	is set on all relocatable inputs.

binutils/

	* readelf.c (decode_x86_feature): New.
	(print_gnu_property_note): Call decode_x86_feature on
	GNU_PROPERTY_X86_FEATURE_1_AND.
	* testsuite/binutils-all/i386/empty.d: New file.
	* testsuite/binutils-all/i386/empty.s: Likewise.
	* testsuite/binutils-all/i386/ibt.d: Likewise.
	* testsuite/binutils-all/i386/ibt.s: Likewise.
	* testsuite/binutils-all/x86-64/empty-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/empty.d: Likewise.
	* testsuite/binutils-all/x86-64/empty.s: Likewise.
	* testsuite/binutils-all/x86-64/ibt-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt.s: Likewise.

include/

	* bfdlink.h (bfd_link_info): Add ibtplt and ibt.
	* elf/common.h (GNU_PROPERTY_X86_FEATURE_1_AND): New.
	(GNU_PROPERTY_X86_FEATURE_1_IBT): Likewise.

ld/

	* Makefile.am (ELF_X86_DEPS): Add $(srcdir)/emulparams/cet.sh.
	* Makefile.in: Regenerated.
	* NEWS: Mention GNU_PROPERTY_X86_FEATURE_1_IBT, -z ibtplt
	and -z ibt.
	* emulparams/cet.sh: New file.
	* testsuite/ld-i386/ibt-plt-1.d: Likewise.
	* testsuite/ld-i386/ibt-plt-1.s: Likewise.
	* testsuite/ld-i386/ibt-plt-2.s: Likewise.
	* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2d.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3.s: Likewise.
	* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3d.d: Likewise.
	* testsuite/ld-i386/plt-main-ibt.dd: Likewise.
	* testsuite/ld-i386/plt-pie-ibt.dd: Likewise.
	* testsuite/ld-i386/property-x86-empty.s: Likewise.
	* testsuite/ld-i386/property-x86-ibt.s: Likewise.
	* testsuite/ld-i386/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt2.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt4.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt5.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.s: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2.s: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2b-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2d-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2d.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3.s: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3b-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3d-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3d.d: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt-now.rd: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt-x32.dd: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt.dd: Likewise.
	* testsuite/ld-x86-64/property-x86-empty.s: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt.s: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5.d: Likewise.
	* emulparams/elf32_x86_64.sh: Source emulparams/cet.sh.
	(TINY_READONLY_SECTION): Add .plt.sec.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_x86_64.sh: Source emulparams/cet.sh.
	* ld.texinfo: Document -z ibtplt and -z ibt.
	* testsuite/ld-i386/i386.exp: Run IBT and IBT PLT tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-x86-64/pr21481b.S (check): Updated for x32.
2017-06-22 05:44:53 -07:00
Nick Clifton d19237d98d Fix address violation parsing a corrupt SOM binary.
PR binutils/21649
	* som.c (setup_sections): NUL terminate the space_strings buffer.
	Check that the space.name field does not index beyond the end of
	the space_strings buffer.
2017-06-22 10:33:56 +01:00
GDB Administrator a765d07242 Automatic date update in version.in 2017-06-22 00:01:05 +00:00
Nick Clifton 6879f5a99e Fix addrss violation when processing a corrupt SH COFF binary.
PR binutils/21646
	* coff-sh.c (sh_reloc): Check for an out of range reloc.
2017-06-21 16:36:44 +01:00
Nick Clifton 7adc0a8174 Fix address violation parsing a corrupt Alpha VMS binary file.
PR binutils/21639
	* vms-misc.c (_bfd_vms_save_sized_string): Use unsigned int as
	type of the size parameter.
	(_bfd_vms_save_counted_string): Add second parameter - the maximum
	length of the counted string.
	* vms.h (_bfd_vms_save_sized_string): Update prototype.
	(_bfd_vms_save_counted_string): Likewise.
	* vms-alpha.c (_bfd_vms_slurp_eisd): Update calls to
	_bfd_vms_save_counted_string.
	(_bfd_vms_slurp_ehdr): Likewise.
	(_bfd_vms_slurp_egsd): Likewise.
	(Parse_module): Likewise.
2017-06-21 15:21:11 +01:00
Alan Modra 6e1816be66 PowerPC64 localentry:0 plt calls
These don't need a following nop.  Also, a localentry:0 plt call
marked with an R_PPC64_TOCSAVE reloc should ignore the tocsave.
There's no need to save r2 in the prologue for such calls.

	* elf64-ppc.c (ppc64_elf_size_stubs): Test for localentry:0 plt
	calls before tocsave calls.
	(ppc64_elf_relocate_section): Allow localentry:0 plt calls without
	following nop.
2017-06-21 22:45:15 +09:30
Nick Clifton 20bd1b6ba5 Fix seg-fault in the BFD parsing a corrupt input binary.
PR binutils/21645
	* reloc.c (bfd_generic_get_relocated_section_contents): Fail if
	bfd_get_full_section_contents returns no contents.
2017-06-21 13:18:46 +01:00
Nick Clifton 3de58d950c Fix potential address violation parsing a corrupt Alpha VMS file.
PR binutils/21638
	* vms-alpha.c (_bfd_vms_slurp_egsd): Check for an undersized
	record.
2017-06-21 12:04:07 +01:00
Nick Clifton cb06d03ad9 Fix address violation parsing a corrupt IEEE Alpha binary.
PR binutils/21637
	* vms-alpha.c (_bfd_vms_slurp_egsd): Check for an empty section
	list.
	(image_set_ptr): Likewise.
	(alpha_vms_fix_sec_rel): Likewise.
	(alpha_vms_slurp_relocs): Likewise.
2017-06-21 11:13:49 +01:00
Nick Clifton c458d0079c Fix address violation when parsing a corrupt IEEE binary.
PR binutils/21633
	* ieee.c (ieee_slurp_sections): Check for a NULL return from
	read_id.
	(ieee_archive_p): Likewise.
	(ieee_object_p): Likewise.
2017-06-21 10:54:04 +01:00
Nick Clifton ce49701009 Fix seg-fault reading a corrupt ELF binary.
PR binutils/21640
	* elf.c (setup_group): Zero the group section pointer list after
	allocation so that loops can be caught.  Check for NULL pointers
	when processing a group list.
2017-06-21 10:36:58 +01:00
GDB Administrator eceb74ca64 Automatic date update in version.in 2017-06-21 00:00:36 +00:00
H.J. Lu abfa390dac Check the DYNAMIC bit for input shared objects
Since the BFD section count may not be cleared for shared objects during
linking, we should check the DYNAMIC bit for input shared objects.

bfd/

	PR ld/21626
	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Check
	the DYNAMIC bit instead of bfd_count_sections.

ld/

	PR ld/21626
	* testsuite/ld-i386/i386.exp: Run ld/21626 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2017-06-19 20:30:20 -07:00
GDB Administrator a6cab9afd2 Automatic date update in version.in 2017-06-20 00:00:38 +00:00
Nick Clifton bc21b167eb Fix address violations when reading corrupt VMS records.
PR binutils/21618
	* vms-alpha.c (evax_bfd_print_emh): Check for insufficient record
	length.
	(evax_bfd_print_eeom): Likewise.
	(evax_bfd_print_egsd): Check for an overlarge record length.
	(evax_bfd_print_etir): Likewise.
2017-06-19 14:52:36 +01:00
Nick Clifton acb56a8301 Fix access violation when parsing a corrupt IEEE binary.
PR binutils/21612
	* libieee.h (struct common_header_type): Add end_p field.
	* ieee.c (this_byte_and_next): Do not advance input_p beyond
	end_p.
	(read_id): Check for a length that exceeds the remaining bytes in
	the input buffer.
	(ieee_seek): Initialise end_p.
	(ieee_archive_p): Likewise.
	(ieee_object_p): Likewise.
2017-06-19 14:06:53 +01:00
Nick Clifton 80053e466b Fix access violation disassembling a corrupt VMS binary.
PR binutils/21611
	* vms-alpha.c (_bfd_vms_slurp_eihs): Check for invalid offset
	before reading the EIHS structure entries.
2017-06-19 13:01:57 +01:00
Nick Clifton 72e84f9694 Fix access violation when disassembling a corrupt VMS binary.
PR 21615
	* vms-alpha.c (_bfd_vms_slurp_egsd): Use unsigned int for
	gsd_size.  Check that there are enough bytes remaining to read the
	type and size of the next egsd.  Check that the size of the egsd
	does not exceed the size of the record.
2017-06-19 12:31:07 +01:00
Alan Modra 875ffa3edc Correct target_underscore for cris
* config.bfd: Correct targ_underscore for cris.
2017-06-19 16:05:09 +09:30
GDB Administrator 65ce7763df Automatic date update in version.in 2017-06-19 00:00:23 +00:00
Alan Modra bdd32e03c5 is_underscore_target for ld-elf tests
and correct targ_underscore in config.bfd

bfd/
	* config.bfd: Correct targ_underscore for epiphany, ip2k,
	m32c, mn10200, pru, rl78, rx, crisv32 and v850.
ld/
	* testsuite/lib/ld-lib.exp (is_underscore_target): New.
	* testsuite/ld-elf/elf.exp (ASFLAGS): Define UNDERSCORE.
	* testsuite/ld-elf/pr21562a.s: If UNDERSCORE defined,
	reference sym with prefix.
	* testsuite/ld-elf/pr21562b.s: Likewise.
	* testsuite/ld-elf/sizeof.s: Likewise.
	* testsuite/ld-elf/startof.s: Likewise.
	* testsuite/ld-elf/pr14156a.d: Adjust for extra symbols.
	* testsuite/ld-elf/pr21562a.d: Remove underscore target from
	xfails, and match prefixed symbol.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/sizeofa.d: Likewise.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/sizeofc.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
	* testsuite/ld-elf/startofc.d: Likewise.
2017-06-18 11:56:19 +09:30
GDB Administrator 99149362b1 Automatic date update in version.in 2017-06-18 00:00:37 +00:00
GDB Administrator 291e629539 Automatic date update in version.in 2017-06-17 00:00:41 +00:00
Nick Clifton 4b48e2f6a5 Fixing linking configure generated tests of ifunc support.
* elflink.c (bfd_elf_size_dynsym_hash_dynstr): Do not fail if the
	bucketlist is empty because there are no symbols to add to the
	list.
2017-06-16 15:16:19 +01:00
Alan Modra 7dba9362c1 Rewrite __start and __stop symbol handling
This arranges for __start and __stop symbols to be defined before
garbage collection, for all target formats.  That should allow the
COFF and PE --gc-sections to keep a singleton orphan input section,
a feature lost by 2017-06-13 commit cbd0eecf26.  The fancier ELF
treatment of keeping all input sections associated with a __start or
__stop symbol, from 2015-10-23 commit 1cce69b9dc, is retained.

.startof. and .sizeof. symbols are deliberately not defined before
garbage collection, so these won't affect garbage collection of
sections.

The patch also ensures __start, __stop, .startof. and .sizeof. symbols
are defined before target size_dynamic_sections is called, albeit
with a preliminary value, so that target code doesn't need to cope
with a symbol changing from undefined at size_dynamic_sections to
defined at relocate_section.

Also, a number of problems with the testcases have been fixed.

	PR ld/20022
	PR ld/21557
	PR ld/21562
	PR ld/21571
include/
	* bfdlink.h (struct bfd_link_hash_entry): Delete undef.section.
bfd/
	* targets.c (struct bfd_target): Add _bfd_define_start_stop.
	(BFD_JUMP_TABLE_LINK): Likewise.
	* elf-bfd.h (bfd_elf_define_start_stop): Declare.
	* elflink.c (_bfd_elf_gc_mark_rsec): Update comment.
	(bfd_elf_define_start_stop): New function.
	* linker.c (bfd_generic_define_start_stop): New function.
	* coff64-rs6000.c (rs6000_xcoff64_vec, rs6000_xcoff64_aix_vec): Init
	new field.
	* aout-adobe.c (aout_32_bfd_define_start_stop): Define.
	* aout-target.h (MY_bfd_define_start_stop): Define.
	* aout-tic30.c (MY_bfd_define_start_stop): Define.
	* binary.c (binary_bfd_define_start_stop): Define.
	* bout.c (b_out_bfd_define_start_stop): Define.
	* coff-alpha.c (_bfd_ecoff_bfd_define_start_stop): Define.
	* coff-mips.c (_bfd_ecoff_bfd_define_start_stop): Define.
	* coff-rs6000.c (_bfd_xcoff_bfd_define_start_stop): Define.
	* coffcode.h (coff_bfd_define_start_stop): Define.
	* elfxx-target.h (bfd_elfNN_bfd_define_start_stop): Define.
	* i386msdos.c (msdos_bfd_define_start_stop): Define.
	* i386os9k.c (os9k_bfd_define_start_stop): Define.
	* ieee.c (ieee_bfd_define_start_stop): Define.
	* ihex.c (ihex_bfd_define_start_stop): Define.
	* libbfd-in.h (_bfd_nolink_bfd_define_start_stop): Define.
	* mach-o-target.c (bfd_mach_o_bfd_define_start_stop): Define.
	* mmo.c (mmo_bfd_define_start_stop): Define.
	* nlm-target.h (nlm_bfd_define_start_stop): Define.
	* oasys.c (oasys_bfd_define_start_stop): Define.
	* pef.c (bfd_pef_bfd_define_start_stop): Define.
	* plugin.c (bfd_plugin_bfd_define_start_stop): Define.
	* ppcboot.c (ppcboot_bfd_define_start_stop): Define.
	* som.c (som_bfd_define_start_stop): Define.
	* srec.c (srec_bfd_define_start_stop): Define.
	* tekhex.c (tekhex_bfd_define_start_stop): Define.
	* versados.c (versados_bfd_define_start_stop): Define.
	* vms-alpha.c (vms_bfd_define_start_stop): Define.
	(alpha_vms_bfd_define_start_stop): Define.
	* xsym.c (bfd_sym_bfd_define_start_stop): Define.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Don't set
	__start/__stop syms here.
	* ldlang.c (lang_set_startof): Delete.
	(start_stop_syms, start_stop_count, start_stop_alloc): New vars.
	(lang_define_start_stop, lang_init_start_stop, foreach_start_stop,
	undef_start_stop, lang_undef_start_stop, lang_init_startof_sizeof,
	set_start_stop, lang_finalize_start_stop): New functions.
	(lang_process): Call _start_stop functions.
	* testsuite/ld-elf/pr21562a.d: Use xfail rather than notarget.
	Correct typos and list of xfail targets.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/sizeofa.d: Likewise.  Adjust to pass for generic ELF.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/startofa.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
2017-06-16 23:38:28 +09:30
Jiong Wang d68f19767d [AArch64] Use SYMBOL_REFERENCES_LOCAL in one symbol check
For some pc-relative relocations we want to allow them under PIC mode while
a normal global symbol defined in the same dynamic object can still bind
externally through copy relocation.  So, we should not allow pc-relative
relocation against such symbol.

SYMBOL_REFERENCES_LOCAL should be used and is more accurate than the original
individual checks.

bfd/
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Use
	SYMBOL_REFERENCES_LOCAL.
ld/
	* testsuite/ld-aarch64/aarch64-elf.exp: Update test name
	* testsuite/ld-aarch64/pcrel.s: Add new testcases.
	* testsuite/ld-aarch64/pcrel_pic_undefined.d: Update the expected
	warnings.
	* testsuite/ld-aarch64/pcrel_pic_defined_local.d: Rename ...
	* testsuite/ld-aarch64/pcrel_pic_defined.d: ... to this.
	Update expected warnings.
2017-06-16 14:20:38 +01:00
GDB Administrator 00fd923b24 Automatic date update in version.in 2017-06-16 00:00:27 +00:00
Jiong Wang 6353d82b8f [AArch64] Allow COPY relocation elimination
As discussed at the PR, this patch tries to avoid COPY relocation generation
and propagate the original relocation into runtime if it was relocating on
writable section.  The ELIMINATE_COPY_RELOCS has been set to true and it's
underlying infrastructure has been improved so that the COPY reloc elimination
at least working on absoluate relocations (ABS64) on AArch64.

  BFD linker copy relocation elimination framwork requires the backend to always
allocate dynrelocs for all those relocation types that are possible to introduce
copy relocations.  This is for adjust_dynamic_symbol hook to be able to get all
symbol reference information.  Should one symbol is referenced by more than one
relocations, if there is any of them needs copy relocation then linker should
generate it.

bfd/
	PR ld/21532
	* elfnn-aarch64.c (ELIMINATE_COPY_RELOCS): Set to 1.
	(elfNN_aarch64_final_link_relocate): Also propagate relocations to
	runtime for if there needs copy relocation elimination.
	(need_copy_relocation_p): New function.  Return true for symbol with
	pc-relative references and if it's against read-only sections.
	(elfNN_aarch64_adjust_dynamic_symbol): Use need_copy_relocation_p.
	(elfNN_aarch64_check_relocs): Allocate dynrelocs for relocation types
	that are related with accessing external objects.
	(elfNN_aarch64_gc_sweep_hook): Sync the relocation types with the change
	in elfNN_aarch64_check_relocs.

ld/
	* testsuite/ld-aarch64/copy-reloc-exe-2.s: New test source file.
	* testsuite/ld-aarch64/copy-reloc-2.d: New test.
	* testsuite/ld-aarch64/copy-reloc-exe-eliminate.s: New test source file.
	* testsuite/ld-aarch64/copy-reloc-eliminate.d: New test.
	* testsuite/ld-aarch64/copy-reloc-so.s: Define new global objects.
	* testsuite/ld-aarch64/aarch64-elf.exp: Run new tests.
2017-06-15 17:04:04 +01:00
Nick Clifton 62b76e4b6e Fix address violation parsing a corrupt ieee binary.
PR binutils/21581
	(ieee_archive_p): Use a static buffer to avoid compiler bugs.
2017-06-15 13:08:47 +01:00
Nick Clifton 63634bb4a1 Avoid a possible compiler bug by using a static buffer instead of a stack local buffer.
PR binutils/21582
	* ieee.c (ieee_object_p): Use a static buffer to avoid compiler
	bugs.
2017-06-15 12:44:23 +01:00
Nick Clifton 76800cba59 Handle EITR records in VMS Alpha binaries with overlarge command length parameters.
PR binutils/21579
	* vms-alpha.c (_bfd_vms_slurp_etir): Extend check of cmd_length.
2017-06-15 12:08:57 +01:00
GDB Administrator 6e89f89989 Automatic date update in version.in 2017-06-15 00:00:48 +00:00
Max Filippov f7e16c2a9c xtensa: don't expect XCHAL_* macros to be constant
Get rid of the assumption that XCHAL_* macros are preprocessor
constants: don't use them in preprocessor conditionals or in static
variable initializers.

2017-06-14  Max Filippov  <jcmvbkbc@gmail.com>
bfd/
	* elf32-xtensa.c (elf_xtensa_be_plt_entry,
	elf_xtensa_le_plt_entry): Add dimension for the ABI to arrays,
	keep both windowed and call0 ABI PLT definitions.
	(elf_xtensa_create_plt_entry): Use selected ABI to choose upper
	elf_xtensa_*_plt_entry endex.
	(ELF_MAXPAGESIZE): Fix at minimal supported MMU page size.

gas/
	* config/tc-xtensa.c (density_supported, xtensa_fetch_width,
	absolute_literals_supported): Leave definitions uninitialized.
	(directive_state): Leave entries for directive_density and
	directive_absolute_literals initialized to false.
	(xg_init_global_config, xtensa_init): New functions.
	* config/tc-xtensa.h (TARGET_BYTES_BIG_ENDIAN): Define as 0.
	(HOST_SPECIAL_INIT): New definition.
	(xtensa_init): New declaration.
2017-06-14 11:05:50 -07:00
Nick Clifton f461bbd847 Fix address violation bug when disassembling a corrupt SH binary.
PR binutils/21578
	* elf32-sh.c (sh_elf_set_mach_from_flags): Fix check for invalid
	flag value.
2017-06-14 17:01:54 +01:00
Nick Clifton c53d2e6d74 Fix potential address violations when processing a corrupt Alpha VMA binary.
PR binutils/21589
	* vms-alpha.c (_bfd_vms_get_value): Add an extra parameter - the
	maximum value for the ascic pointer.  Check that name processing
	does not read beyond this value.
	(_bfd_vms_slurp_etir): Add checks for attempts to read beyond the
	end of etir record.
2017-06-14 11:27:15 +01:00
Nick Clifton 04f963fd48 Fix seg-faults in objdump when disassembling a corrupt versados binary.
PR binutils/21591
	* versados.c (versados_mkobject): Zero the allocated tdata structure.
	(process_otr): Check for an invalid offset in the otr structure.
2017-06-14 10:35:16 +01:00
Sebastian Huber 319c2dbe24 Accept more epiphany targets
In particular this adds support for the epiphany-rtems target.

bfd/
	* config.bfd (epiphany-*-elf): Accept epiphany-*-*.

ld/
	* configure.tgt (epiphany-*-elf): Accept epiphany-*-*.
2017-06-14 06:59:37 +02:00
GDB Administrator f9a36b297d Automatic date update in version.in 2017-06-14 00:00:25 +00:00
H.J. Lu cbd0eecf26 Always define referenced __start_SECNAME/__stop_SECNAME
Currently, linker will define __start_SECNAME and __stop_SECNAME symbols
only for orphaned sections.

However, during garbage collection, ELF linker marks all sections with
references to __start_SECNAME and __stop_SECNAME symbols as used even
when section SECNAME isn't an orphaned section and linker won't define
__start_SECNAME nor __stop_SECNAME.  And ELF linker stores the first
input section whose name matches __start_SECNAME or __stop_SECNAME in
u.undef.section for garbage collection.  If these symbols are provided
in linker script, u.undef.section is set to the section where they will
defined by linker script, which leads to the incorrect output.

This patch changes linker to always define referenced __start_SECNAME and
__stop_SECNAME if the input section name is the same as the output section
name, which is always true for orphaned sections, and SECNAME is a C
identifier.  Also __start_SECNAME and __stop_SECNAME symbols are marked
as hidden by ELF linker so that __start_SECNAME and __stop_SECNAME symbols
for section SECNAME in different modules are unique.  For garbage
collection, ELF linker stores the first matched input section in the
unused vtable field.

bfd/

	PR ld/20022
	PR ld/21557
	PR ld/21562
	PR ld/21571
	* elf-bfd.h (elf_link_hash_entry): Add start_stop.  Change the
	vtable field to a union.
	(_bfd_elf_is_start_stop): Removed.
	* elf32-i386.c (elf_i386_convert_load_reloc): Also check for
	__start_SECNAME and __stop_SECNAME symbols.
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise.
	* elflink.c (_bfd_elf_is_start_stop): Removed.
	(_bfd_elf_gc_mark_rsec): Check start_stop instead of calling
	_bfd_elf_is_start_stop.
	(elf_gc_propagate_vtable_entries_used): Skip __start_SECNAME and
	__stop_SECNAME symbols.  Updated.
	(elf_gc_smash_unused_vtentry_relocs): Likewise.
	(bfd_elf_gc_record_vtinherit): Likewise.
	(bfd_elf_gc_record_vtentry): Likewise.

ld/

	PR ld/20022
	PR ld/21557
	PR ld/21562
	PR ld/21571
	* ld.texinfo: Update __start_SECNAME/__stop_SECNAME symbols.
	* ldlang.c (lang_insert_orphan): Move handling of __start_SECNAME
	and __stop_SECNAME symbols to ...
	(lang_set_startof): Here.  Also define __start_SECNAME and
	__stop_SECNAME for -Ur.
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Mark
	referenced __start_SECNAME and __stop_SECNAME symbols as hidden
	and set start_stop for garbage collection.
	* testsuite/ld-elf/pr21562a.d: New file.
	* testsuite/ld-elf/pr21562a.s: Likewise.
	* testsuite/ld-elf/pr21562a.t: Likewise.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562b.s: Likewise.
	* testsuite/ld-elf/pr21562b.t: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562c.t: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562d.t: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-gc/pr20022.d: Likewise.
	* testsuite/ld-gc/pr20022a.s: Likewise.
	* testsuite/ld-gc/pr20022b.s: Likewise.
	* testsuite/ld-gc/gc.exp: Run PR ld/20022 tests.
	* testsuite/ld-gc/pr19161.d: Also accept local __start_SECNAME
	symbol.
	* testsuite/ld-gc/start.d: Likewise.
	* testsuite/ld-x86-64/lea1a.d: Updated.
	* testsuite/ld-x86-64/lea1b.d: Updated.
	* testsuite/ld-x86-64/lea1d.d: Updated.
	* testsuite/ld-x86-64/lea1e.d: Likewise.
2017-06-13 08:53:22 -07:00
Nick Clifton 10bbbc1d79 Prevent a call to abort when a relocatable link encounters a relocation against a symbol in a section removed by garbage collection.
PR ld/21524
	* elflink.c (elf_link_adjust_relocs): Generate an error when
	encountering a reloc against a symbol removed by garbage
	collection.
2017-06-13 14:03:16 +01:00
GDB Administrator a0688fac4b Automatic date update in version.in 2017-06-13 00:00:43 +00:00
H.J. Lu 5c3ce2bc8a ELF: Pass bfd_link_info to merge_gnu_properties
Pass struct bfd_link_info * to merge_gnu_properties to give backend
control of how GNU properties are merged based on linker command line
options.

	* elf-bfd.h (elf_backend_data): Add struct bfd_link_info *
	to merge_gnu_properties.
	* elf-properties.c (elf_merge_gnu_properties): Add struct
	bfd_link_info * and pass it to merge_gnu_properties.
	(elf_merge_gnu_property_list): Add struct bfd_link_info *
	and pass it to elf_merge_gnu_properties.
	(_bfd_elf_link_setup_gnu_properties): Pass info to
	elf_merge_gnu_property_list.
	* elf32-i386.c (elf_i386_merge_gnu_properties): Add struct
	bfd_link_info *.
	* elf64-x86-64.c (elf_x86_64_merge_gnu_properties): Likewise.
2017-06-12 07:37:56 -07:00
Andreas Krebbel 3704e3589d S/390: Return with an error for broken tls rewrites
bfd/ChangeLog:

2017-06-12  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf32-s390.c (elf_s390_relocate_section): Return false in case
	the rewriting fails.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
2017-06-12 10:54:55 +02:00
GDB Administrator fd0219988d Automatic date update in version.in 2017-06-12 00:00:38 +00:00
Alan Modra 9b97dfbf80 PR 21564, Section start in binary output file incorrect
PR 21564
	* binary.c (binary_set_section_contents): Scale lma by octets
	per byte to set filepos.
2017-06-11 13:45:18 +09:30
GDB Administrator c7198f97e0 Automatic date update in version.in 2017-06-11 00:00:44 +00:00
GDB Administrator 561bf3e950 Automatic date update in version.in 2017-06-10 00:00:43 +00:00
Jiong Wang dbb2bcd005 Revert "[AArch64] Allow COPY relocation elimination"
This reverts commit bc327528fd.

This patch can only be committed after PC-relative relocation types
support on copy relocation elimination is also completed.
2017-06-09 12:04:44 +01:00
GDB Administrator fe7bb2d5ab Automatic date update in version.in 2017-06-09 00:00:44 +00:00
Cupertino Miranda e3d1d4088a [ARC] Corrected conditions for dynamic sections creation.
Fixed conditions to create the dynamic sections.
Previously there would be times where the dynamic sections would not be created
although they were actually required for linking to work.

Issue found through OpenADK build, more precisely the ublicb testsuite package.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	elf32-arc.c (elf_arc_check_relocs): Fixed conditions to generate
	dynamic sections.
2017-06-08 19:00:37 +02:00
Cupertino Miranda 64aa8e0303 [ARC] Fixed condition to generate TEXTREL.
TEXTREL was being generated even when relocatable .o files had the .rela.text
section. Now it is limitted only to dynamic object files that still have them.
Nevertheless, our target aborts in those cases due to architecture limitations
where icache is not coherent with dcache, and to force this coherence expensive
kernel level support would be needed.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	* elf32-arc.c (elf_arc_size_dynamic_sections): Changed condition to
	require TEXTREL.
2017-06-08 19:00:37 +02:00
Cupertino Miranda a0abe74332 [ARC] Fixed TLS for IE model.
In the case of static relocation, the GOT entries are fixed at link time
and are set by the linker.
In order to compute the right TLS offset it is necessary to add TCB_SIZE
to the offset, just in case the dynamic linker is not expected to be
executed (static linked case).
This problem does appear in dynamic linked applications, as the dynamic
linker is adding this TCB_SIZE by operating the TCB block structure.

Problem revealed in GLIBC with static linking.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	arc-got.h (relocate_fix_got_relocs_for_got_info): Added TCB_SIZE to
	patched section contents for TLS IE reloc.
	elf32-arc.c: Remove TCB_SIZE preprocessor macro.

Rebase to 0006
2017-06-08 19:00:36 +02:00
Cupertino Miranda f4e6805f98 [ARC] Add RELOC_FOR_GLOBAL_SYMBOL in ARC target code.
This miss was identified in the context of openssh building for ARC.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	elf32-arc.c (elf_arc_relocate_section): Added "call" to
	RELOC_FOR_GLOBAL_SYMBOL macro.
2017-06-08 19:00:36 +02:00
Cupertino Miranda cd6402916f [ARC] ARC_PC32 dynamic reloc incorrectly generated.
Fixed issue related to the generation of ARC_PC32 dynamic relocs when symbol
is dynamic but still defined in a non shared object.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	elf32-arc.c (elf_arc_relocate_section): Small refactor and condition
	changes.
2017-06-08 19:00:35 +02:00
Vineet Gupta 7ef0acc15e [ARC] Don't convert _DYNAMIC@ to _GLOBAL_OFFSET_TABLE_
Historically the arc abi demanded that a GOT[0] should be referencible as
[pc+_DYNAMIC@gotpc].  Hence we convert a _DYNAMIC@gotpc to a GOTPC reference to
_GLOBAL_OFFSET_TABLE_.

This is no longer the case and uClibc and upcomming GNU libc don't expect this
to happen.

gas/ChangeLog:

    Vineet Gupta  <vgupta@synopsys.com>
    Cupertino Miranda  <cmiranda@synopsys.com>

	* config/tc-arc.c (md_undefined_symbol): Changed.
	* config/tc-arc.h (DYNAMIC_STRUCT_NAME): Removed.
2017-06-08 19:00:35 +02:00
Cupertino Miranda cc89d0b334 [ARC] Reassign the symbol got information to actual symbol when indirect.
GOT information would not be reassign to symbol when it became a indect
symbol.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	* elf32-arc.c (elf_arc_relocate_section): Fixed reassign of indirect
	symbols.
2017-06-08 19:00:34 +02:00
Cupertino Miranda 9d5c718b7a [ARC] Disable warning on absolute relocs when symbol is local.
R_ARC_32 and R_ARC_32_ME cannot be generated as dynamic relocs.
However, a warning message and check_relocs was aborting when this type of
reloc was being resolved to a local symbol.
This is wrong as local symbols are resolvable at link time.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	* elf32-arc.c (elf_arc_check_relocs): Added condition to disable
	warning and "Bad value" for local symbols ARC_32 or ARC_32_ME relocs.
2017-06-08 19:00:34 +02:00
Cupertino Miranda be9e3704f9 [ARC] Avoid creating dynamic relocs when static linked is requested.
bfd/Changelog:

    Cupertino Miranda  <cmiranda@synopsys.com>

	* elf32-arc.c (ADD_RELA): Changed to only work when dynamic object is
	created.
2017-06-08 18:38:50 +02:00
Richard Earnshaw 4ec192e6ab [bfd][arm] Don't assert on suspicious build attributes in input file
It's generally a bad idea to use assertions to validate our idea of
what an input file looks like.  We need to be as liberal as possible
in what we accept with respect to standards and conservative with what
we produce.

Currently, if gcc is used to produce an assembler file which contains
only data, but the FPU is set to fpv4-sp-d16 and mfloat-abi=hard, then
the following attributes will be set in the output:

        .cpu arm7tdmi
        .eabi_attribute 27, 1   @ Tag_ABI_HardFP_use
        .eabi_attribute 28, 1   @ Tag_ABI_VFP_args
        .eabi_attribute 20, 1   @ Tag_ABI_FP_denormal
        .eabi_attribute 21, 1   @ Tag_ABI_FP_exceptions
        .eabi_attribute 23, 3   @ Tag_ABI_FP_number_model
        .eabi_attribute 24, 1   @ Tag_ABI_align8_needed
        .eabi_attribute 25, 1   @ Tag_ABI_align8_preserved
        .eabi_attribute 26, 2   @ Tag_ABI_enum_size
        .eabi_attribute 30, 6   @ Tag_ABI_optimization_goals
        .eabi_attribute 34, 0   @ Tag_CPU_unaligned_access
        .eabi_attribute 18, 4   @ Tag_ABI_PCS_wchar_t

There is then no .fpu directive to cause Tag_FP_arch to be set,
because there are no functions containing code in the object file.  If
this object file is assembled by hand, but without -mfpu on the
invocation of the assembler, then the build attributes produced will
trigger an assertion during linking.

Thinking about the build attributes, the combination of a
single-precision only implementation of no floating-point architecture
is still no floating-point architecture.  Hence the assertion on the
input BFD in the linker makes no real sense.

We should, however, be more conservative in what we generate, so I've
left the assertion on the output bfd in place; I don't think we can
trigger it with this change since we never merge the problematic tags
from a perversely generated input file.

	* elf32-arm.c (elf32_arm_merge_eabi_attributes): Remove assertion
	that the input bfd has Tag_FP_ARCH non-zero if Tag_ABI_HardFP_use
	is non-zero.  Add clarifying comments.
2017-06-08 15:11:44 +01:00
H.J. Lu 6322e5c5cb x86: Dump local IFUNC functions in the map file
Dump local IFUNC functions in the map file when generating IRELATIVE
relocations if -Map is used.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Set local IFUNC symbol
	name.  Use local IFUNC symbol name string to report unsupported
	non-PIC call to IFUNC function.
	(elf_i386_relocate_section): Dump local IFUNC name with minfo
	when generating R_386_IRELATIVE relocation.
	(elf_i386_finish_dynamic_symbol): Likewise.
	* elf_x86_64_check_relocs (elf_x86_64_check_relocs): Set local
	IFUNC symbol name.
	(elf_x86_64_relocate_section): Dump local IFUNC name with minfo
	when generating R_X86_64_IRELATIVE relocation.
	(elf_x86_64_finish_dynamic_symbol): Likewise.

ld/

	* testsuite/ld-ifunc/ifunc-1-local-x86.d: Pass
	"-Map tmpdir/ifunc-1-local-x86.map" to ld and check
	ifunc-1-local-x86.map.
	* testsuite/ld-ifunc/ifunc-1-x86.d: Pass
	"-Map tmpdir/ifunc-1-x86.map" to ld and check ifunc-1-x86.map.
	* testsuite/ld-ifunc/ifunc-1-local-x86.map: New file.
	* testsuite/ld-ifunc/ifunc-1-x86.map: Likewise.
2017-06-08 03:53:43 -07:00
H.J. Lu 51fa2693ad cl 2017-06-08 03:53:43 -07:00
Jiong Wang bc327528fd [AArch64] Allow COPY relocation elimination
As discussed at the PR, this patch tries to avoid COPY relocation generation
and propagate the original relocation into runtime if it was relocating on
writable section.  The ELIMINATE_COPY_RELOCS has been set to true and it's
underlying infrastructure has been improved so that the COPY reloc elimination
at least working on absoluate relocations (ABS64) after this patch.

bfd/
        PR ld/21532
        * elfnn-aarch64.c (ELIMINATE_COPY_RELOCS): Set to 1.
        (elfNN_aarch64_final_link_relocate): Also propagate relocations to
        runtime for copy relocation elimination cases.
        (alias_readonly_dynrelocs): New function.
        (elfNN_aarch64_adjust_dynamic_symbol): Keep the dynamic relocs instead
        of generating copy relocation if it is not against read-only sections.
        (elfNN_aarch64_check_relocs): Likewise.

ld/
        * testsuite/ld-aarch64/copy-reloc-eliminate.d: New test.
        * testsuite/ld-aarch64/copy-reloc-exe-eliminate.s: New test source file.
        * testsuite/ld-aarch64/aarch64-elf.exp: Run new testcase.
2017-06-08 09:43:39 +01:00
GDB Administrator 3030551ec5 Automatic date update in version.in 2017-06-08 00:00:39 +00:00
GDB Administrator 58f59b7616 Automatic date update in version.in 2017-06-07 00:00:40 +00:00
Jose E. Marchesi 78e8a2ff5f bfd: support section groups with preceding SHF_GROUP sections
GAS always places section groups (SHT_GROUP) before the rest of the
sections in the output file.  However, other assemblers may place
section groups after the group members.

This patch fixes handlign such situations, and removes some duplicated
logic.

bfd/ChangeLog:

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

	* elf.c (setup_group): Make sure BFD sections are created for all
	group sections in the input file when processing SHF_GROUP
	sections.
	(bfd_section_from_shdr): Avoid duplicating logic already
	implemented in `setup_group'.
2017-06-06 11:19:06 -07:00
Daniel Bonniot de Ruisselet 9949827bea Handle printing information about PE format files which have 0 as the value of the HInt Table in the import tables structure.
PR binutils/21546
	* peXXigen.c (pe_print_idata): Use the address of the first thunk
	if the hint address is zero.
2017-06-06 15:06:02 +01:00
James Clarke 0ee3a6dbd0 Fix AArch64 in the same way as other targets updated in 8170f7693b.
PR ld/19579
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Check
	ELF_COMMON_DEF_P for common symbols.
2017-06-06 14:30:47 +01:00
Andrew Burgess 7bdf4127c3 ld: Allow section groups to be resolved as part of a relocatable link
This commit adds a new linker feature: the ability to resolve section
groups as part of a relocatable link.

Currently section groups are automatically resolved when performing a
final link, and are carried through when performing a relocatable link.
By carried through this means that one copy of each section group (from
all the copies that might be found in all the input files) is placed
into the output file.  Sections that are part of a section group will
not match input section specifiers within a linker script and are
forcibly kept as separate sections.

There is a slight resemblance between section groups and common
section.  Like section groups, common sections are carried through when
performing a relocatable link, and resolved (allocated actual space)
only at final link time.

However, with common sections there is an ability to force the linker to
allocate space for the common sections when performing a relocatable
link, there's currently no such ability for section groups.

This commit adds such a mechanism.  This new facility can be accessed in
two ways, first there's a command line switch --force-group-allocation,
second, there's a new linker script command FORCE_GROUP_ALLOCATION.  If
one of these is used when performing a relocatable link then the linker
will resolve the section groups as though it were performing a final
link, the section group will be deleted, and the members of the group
will be placed like normal input sections.  If there are multiple copies
of the group (from multiple input files) then only one copy of the group
members will be placed, the duplicate copies will be discarded.

Unlike common sections that have the --no-define-common command line
flag, and INHIBIT_COMMON_ALLOCATION linker script command there is no
way to prevent group resolution during a final link, this is because the
ELF gABI specifically prohibits the presence of SHT_GROUP sections in a
fully linked executable.  However, the code as written should make
adding such a feature trivial, setting the new resolve_section_groups
flag to false during a final link should work as you'd expect.

bfd/ChangeLog:

	* elf.c (_bfd_elf_make_section_from_shdr): Don't initially mark
	SEC_GROUP sections as SEC_EXCLUDE.
	(bfd_elf_set_group_contents): Replace use of abort with an assert.
	(assign_section_numbers): Use resolve_section_groups flag instead
	of relocatable link type.
	(_bfd_elf_init_private_section_data): Use resolve_section_groups
	flag instead of checking the final_link flag for part of the
	checks in here.  Fix white space as a result.
	* elflink.c (elf_link_input_bfd): Use resolve_section_groups flag
	instead of relocatable link type.
	(bfd_elf_final_link): Likewise.

include/ChangeLog:

	* bfdlink.h (struct bfd_link_info): Add new resolve_section_groups
	flag.

ld/ChangeLog:

	* ld.h (struct args_type): Add force_group_allocation field.
	* ldgram.y: Add support for FORCE_GROUP_ALLOCATION.
	* ldlex.h: Likewise.
	* ldlex.l: Likewise.
	* lexsup.c: Likewise.
	* ldlang.c (unique_section_p): Check resolve_section_groups flag
	not the relaxable link flag.
	(lang_add_section): Discard section groups when we're resolving
	groups.  Clear the SEC_LINK_ONCE flag if we're resolving section
	groups.
	* ldmain.c (main): Initialise resolve_section_groups flag in
	link_info based on command line flags.
	* testsuite/ld-elf/group11.d: New file.
	* testsuite/ld-elf/group12.d: New file.
	* testsuite/ld-elf/group12.ld: New file.
	* NEWS: Mention new features.
	* ld.texinfo (Options): Document --force-group-allocation.
	(Miscellaneous Commands): Document FORCE_GROUP_ALLOCATION.
2017-06-06 09:53:38 +01:00