Commit Graph

8780 Commits

Author SHA1 Message Date
Alan Modra 242a115951 PR24392, Clang warning Wtautological-constant-out-of-range-compare
PR 24392
	* configure.ac: Invoke AC_CHECK_SIZEOF(int).
	* configure: Regenerate.
	* coffgen.c (coff_get_reloc_upper_bound): Replace gcc diagnostic
	workaround with SIZEOF_LONG vs. SIZEOF_INT check.
	* elf.c (_bfd_elf_get_reloc_upper_bound): Likewise.
	* elf64-sparc.c (elf64_sparc_get_reloc_upper_bound): Likewise.
	* mach-o.c (bfd_mach_o_get_reloc_upper_bound): Likewise.
2019-03-28 17:10:31 +10:30
Jim Wilson a9f5a5517f RISC-V: Fix linker crash in section symbol check.
sym is only set for local symbols.  h is only set for global symbols.  Gas
won't let me create a global section symbol, but bfd appears to have some
support for that, and I can't rule out that other assemblers might do this.
So we need to support both, and verify sym and h are non-NULL before using.

	bfd/
	PR 24365
	* elfnn-riscv.c (riscv_elf_relocate_section): For STT_SECTION check,
	verify sym non-NULL before using.  Add identical check using h.
2019-03-21 15:16:19 -07:00
Sudakshina Das 4e5391148d [BFD, AArch64, x86] Improve warning for --force-bti
The AArch64 linker option to turn on BTI (--force-bti) warns in case there are
input objects which have a missing GNU NOTE section for BTI. This patch is trying
to improve the warnings that come out.

In order to do so, I propose adding a new argument to elf_merge_gnu_properties
and the backend function merge_gnu_properties. This new argument makes sure
that we now pass both the objects along with the properties to which they
belong to. The x86 backend function has also been updated to match this
change.

*** bfd/ChangeLog ***

2019-03-21  Sudakshina Das  <sudi.das@arm.com>

	* elf-bfd.h (struct elf_backend_data): Add argument to
	merge_gnu_properties.
	* elf-properties.c (elf_merge_gnu_properties): Add argument to
	itself and while calling bed->merge_gnu_properties.
	(elf_merge_gnu_property_list): Update the calls for
	elf_merge_gnu_properties.
	* elfnn-aarch64.c (elfNN_aarch64_merge_gnu_properties): Update handling
	of --force-bti warning and add argument.
	* elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Add
	warning.
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Add argument.
	* elfxx-x86.h (_bfd_x86_elf_merge_gnu_properties): Likewise in
	declaration.

*** ld/ChangeLog ***

2019-03-21  Sudakshina Das  <sudi.das@arm.com>

	* testsuite/ld-aarch64/aarch64-elf.exp: Add new test.
	* testsuite/ld-aarch64/bti-plt-1.s: Add .ifdef for PAC note section.
	* testsuite/ld-aarch64/bti-plt-6.d: Update warning.
	* testsuite/ld-aarch64/bti-plt-7.d: Likewise.
	* testsuite/ld-aarch64/bti-warn.d: New test.
2019-03-21 16:20:21 +00:00
Sudakshina Das acde6c6b43 [BFD, AArch64] Define elf_backend_fixup_gnu_properties in AArch64
This patch add support for elf_backend_fixup_gnu_properties for GNU
property support for AArch64. The new AArch64 specific definition
_bfd_aarch64_elf_link_fixup_gnu_properties goes through the property
list to find AArch64 type properties and removes the properties that
are marked as "property_remove".

*** bfd/ChangeLog ***

2019-03-20  Sudakshina Das  <sudi.das@arm.com>

	* elfxx-aarch64.c (_bfd_aarch64_elf_link_fixup_gnu_properties): Define.
	* elfxx-aarch64.h (_bfd_aarch64_elf_link_fixup_gnu_properties): Declare.
	(elf_backend_fixup_gnu_properties): Define for AArch64.
2019-03-20 18:00:07 +00:00
Alan Modra 8cd1fe1bf5 PR24355, segmentation fault in function called from ppc_finish_symbols
This one looks to be a bug going back to 2009, git commit e054468f6c
"STT_GNU_IFUNC support for PowerPC".  That bug was carried over with
git commit 49c09209d0 "Rearrange PLT reloc output on powerpc".

If the refcount for an ifunc local sym plt entry was zero,
ppc_elf_size_dynamic_sections would correctly set plt.offset to -1 but
leave glink_offset uninitialized.  That leads to occasional segfaults
(which can be made solid with MALLOC_PERTURB_=1 when using glibc).
So, guard the write_glink_stub call with plt.offset != -1.  Also,
remove the totally ineffective attempt at writing multiple-use glink
stubs only once.

	PR 24355
	* elf32-ppc.c (ppc_finish_symbols): Don't call write_glink_stub
	for local iplt syms with ent->plt.offset == -1.  Remove ineffective
	attempt at writing glink stubs only once.
2019-03-18 22:38:29 +10:30
Alan Modra 6835821be8 PR24337, segfault in _bfd_elf_rela_local_sym, again
Reverts commit 1ff31e135f, fixing the problem more generally.  There
are likely other place that will segfault on a NULL section.

	PR 24337
	* elf.c (_bfd_elf_rela_local_sym): Revert last change.
	(_bfd_elf_rel_local_sym): Likewise.
	* elflink.c (elf_link_input_bfd): Use bfd_und_section for
	section of symbols with unrecognized shndx.
2019-03-16 11:55:28 +10:30
H.J. Lu 2219ae0b0e COFF: Check for symbols defined in discarded section
For LTO, a symbol may defined in discarded section.  We should mark it
as undefined so that LTO plugin will make IR definition available.

	PR ld/24267
	* coffgen.c (_bfd_coff_section_already_linked): Skip discarded
	section.
	* cofflink.c (coff_link_add_symbols): Check for symbols defined
	in discarded section.
2019-03-15 22:19:20 +08:00
Alan Modra fe3fef62ad PR24339, segfault on NULL symbol section
PR 24339
	* elflink.c (elf_link_add_object_symbols): Bail out on a local
	symbol after globals if elf_bad_symtab is not set.
2019-03-15 20:05:18 +10:30
Alan Modra 1ff31e135f PR24337, segfault in _bfd_elf_rela_local_sym
PR 24337
	* elf.c (_bfd_elf_rela_local_sym): Don't segfault on NULL sec.
	(_bfd_elf_rel_local_sym): Likewise.
2019-03-15 20:05:18 +10:30
Alan Modra f55b1e3248 PR24336, buffer overflow in swap_reloca_in
PR 24336
	* elflink.c (elf_link_read_relocs_from_section): Handle fuzzed
	object files with sh_size not a multiple of sh_entsize.
2019-03-15 20:05:18 +10:30
H.J. Lu 418d4036ee x86-64: Check for corrupt input with bad relocation
PR ld/24338
	* elf64-x86-64.c (elf_x86_64_relocate_section): Check for corrupt
	input with bad relocation.
2019-03-15 15:46:12 +08:00
H.J. Lu da0d12d2bd Re-indent elf_x86_64_relocate_section
* elf64-x86-64.c (elf_x86_64_relocate_section): Re-indent.
2019-03-15 14:43:36 +08:00
Nick Clifton d7f848c3b5 Fix a buffer overrun error when attempting to parse corrupt DWARF information.
PR 24334
	* dwarf2.c (struct dwarf2_debug): Add sec_vma_count field.
	(save_section_vma): Initialise field to the number of entries in
	the sec_vma table.
	(section_vma_same): Check that the number of entries in the
	sec_vma table matches the number of sections in the bfd.
2019-03-14 17:21:41 +00:00
Nick Clifton 6cc71b820c Fix an illegal memory access when parsing a corrupt ELF file.
PR 24333
	* elflink.c (_bfd_elf_add_default_symbol): Add a check for a NULL
	section owner pointer when adding the default symbol.
2019-03-14 16:03:07 +00:00
Nick Clifton be22c732bf Fix illegal memory access parsing a corrupt ELF file.
PR 24332
	* elflink.c (elf_link_add_object_symbols): Add new local variable
	extversym_end.  Initialise it to point to the end of the version
	symbol table, if present.  Check it when initialising and updating
	the ever pointer.
2019-03-14 14:45:32 +00:00
Sudakshina Das 1dbade7441 [BFD, LD, AArch64, 3/3] Add --pac-plt to enable PLTs protected with PAC.
This is part of the patch series to add support for BTI and
PAC in AArch64 linker.

1) This patch adds new definitions of PAC enabled PLTs
and both BTI and PAC enabled PLTs.
2) It also defines the new dynamic tag DT_AARCH64_PAC_PLT
for the PAC enabled PLTs.
3) This patch adds a new ld command line option: --pac-plt.
In the presence of this option, the linker uses the PAC
enabled PLTs and marks with DT_AARCH64_PAC_PLT.
4) In case both BTI and PAC are enabled the linker should
pick PLTs enabled with both and also use dynamic tags for both.
All these are made according to the new AArch64 ELF ABI
https://developer.arm.com/docs/ihi0056/latest/elf-for-the-arm-64-bit-architecture-aarch64-abi-2018q4

*** bfd/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* elfnn-aarch64.c (PLT_PAC_ENTRY_SIZE, PLT_PAC_SMALL_ENTRY_SIZE): New.
	(PLT_BTI_PAC_ENTRY_SIZE, PLT_BTI_PAC_SMALL_ENTRY_SIZE): New.
	(setup_plt_values): Account for PAC or PAC and BTI enabled PLTs.
	(elfNN_aarch64_size_dynamic_sections): Add checks for PLT_BTI_PAC
	and PLT_PAC_PLT.
	(elfNN_aarch64_finish_dynamic_sections): Account for PLT_BTI_PAC.
	(get_plt_type): Add case for DT_AARCH64_PAC_PLT.
	(elfNN_aarch64_plt_sym_val): Add cases for PLT_BTI_PAC and PLT_PAC.

*** binutils/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* readelf.c (get_aarch64_dynamic_type): Add case for
	DT_AARCH64_PAC_PLT.
	(dynamic_section_aarch64_val): Likewise.

*** include/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* elf/aarch64.h (DT_AARCH64_PAC_PLT): New.

*** ld/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* NEWS: Document --pac-plt.
	* emultempl/aarch64elf.em (OPTION_PAC_PLT): New.
	(PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS): Add pac-plt.
	(PARSE_AND_LIST_ARGS_CASES): Handle OPTION_PAC_PLT.
	* testsuite/ld-aarch64/aarch64-elf.exp: Add the following tests.
	* testsuite/ld-aarch64/bti-pac-plt-1.d: New test.
	* testsuite/ld-aarch64/bti-pac-plt-2.d: New test.
	* testsuite/ld-aarch64/pac-plt-1.d: New test.
	* testsuite/ld-aarch64/pac-plt-2.d: New test.
	* testsuite/ld-aarch64/bti-plt-1.s: Add .ifndef directive.
2019-03-13 11:47:33 +00:00
Sudakshina Das 37c18eedff [BFD, LD, AArch64, 2/3] Add --force-bti to enable BTI and to select BTI enabled PLTs
This is part of the patch series to add support for BTI and
PAC in AArch64 linker.

1) This patch adds a new ld command line option: --force-bti.
In the presence of this option, the linker enables BTI with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI feature. This gives out warning
in case of missing gnu notes for BTI in inputs.
2) It also defines a new set of BTI enabled PLTs. These are used either
when all the inputs are marked with GNU_PROPERTY_AARCH64_FEATURE_1_BTI
or when the new --force-bti option is used. This required adding new
fields in elf_aarch64_link_hash_table so that we could make the PLT
related information more generic.
3) It also defines a dynamic tag DT_AARCH64_BTI_PLT. The linker uses
this whenever it picks BTI enabled PLTs.
All these are made according to the new AArch64 ELF ABI
https://developer.arm.com/docs/ihi0056/latest/elf-for-the-arm-64-bit-architecture-aarch64-abi-2018q4

*** bfd/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>
	    Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* bfd-in.h (aarch64_plt_type, aarch64_enable_bti_type): New.
	(aarch64_bti_pac_info): New.
	(bfd_elf64_aarch64_set_options): Add aarch64_bti_pac_info argument.
	(bfd_elf32_aarch64_set_options): Likewise.
	* bfd-in2.h: Regenerate
	* elfnn-aarch64.c (PLT_BTI_ENTRY_SIZE): New.
	(PLT_BTI_SMALL_ENTRY_SIZE, PLT_BTI_TLSDESC_ENTRY_SIZE): New.
	(elfNN_aarch64_small_plt0_bti_entry): New.
	(elfNN_aarch64_small_plt_bti_entry): New.
	(elfNN_aarch64_tlsdesc_small_plt_bti_entry): New.
	(elf_aarch64_obj_tdata): Add no_bti_warn and plt_type fields.
	(elf_aarch64_link_hash_table): Add plt0_entry, plt_entry and
	tlsdesc_plt_entry_size fields.
	(elfNN_aarch64_link_hash_table_create): Initialise the new fields.
	(setup_plt_values): New helper function.
	(bfd_elfNN_aarch64_set_options): Use new bp_info to set plt sizes and
	bti enable type.
	(elfNN_aarch64_allocate_dynrelocs): Use new size members instead of
	fixed macros.
	(elfNN_aarch64_size_dynamic_sections): Likewise and add checks.
	(elfNN_aarch64_create_small_pltn_entry): Use new generic pointers
	to plt stubs instead of fixed ones and update filling them according
	to the need for bti.
	(elfNN_aarch64_init_small_plt0_entry): Likewise.
	(elfNN_aarch64_finish_dynamic_sections): Likewise.
	(get_plt_type, elfNN_aarch64_get_synthetic_symtab): New.
	(elfNN_aarch64_plt_sym_val): Update size accordingly.
	(elfNN_aarch64_link_setup_gnu_properties): Set up plts if BTI GNU NOTE
	is set.
	(bfd_elfNN_get_synthetic_symtab): Define.
	(elfNN_aarch64_merge_gnu_properties): Give out warning with --force-bti
	and mising BTI NOTE SECTION.

*** binutils/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>
	    Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* readelf.c (get_aarch64_dynamic_type): New.
	(get_dynamic_type): Use above for EM_AARCH64.
	(dynamic_section_aarch64_val): New.
	(process_dynamic_section): Use above for EM_AARCH64.

*** include/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>
	    Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* elf/aarch64.h (DT_AARCH64_BTI_PLT): New.

*** ld/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>
	    Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* NEWS: Document --force-bti.
	* emultempl/aarch64elf.em (plt_type, bti_type, OPTION_FORCE_BTI): New.
	(PARSE_AND_LIST_SHORTOPTS, PARSE_AND_LIST_OPTIONS): Add force-bti.
	(PARSE_AND_LIST_ARGS_CASES): Handle OPTION_FORCE_BTI.
	* testsuite/ld-aarch64/aarch64-elf.exp: Add all the tests below.
	* testsuite/ld-aarch64/bti-plt-1.d: New test.
	* testsuite/ld-aarch64/bti-plt-1.s: New test.
	* testsuite/ld-aarch64/bti-plt-2.s: New test.
	* testsuite/ld-aarch64/bti-plt-2.d: New test.
	* testsuite/ld-aarch64/bti-plt-3.d: New test.
	* testsuite/ld-aarch64/bti-plt-4.d: New test.
	* testsuite/ld-aarch64/bti-plt-5.d: New test.
	* testsuite/ld-aarch64/bti-plt-6.d: New test.
	* testsuite/ld-aarch64/bti-plt-7.d: New test.
	* testsuite/ld-aarch64/bti-plt-so.s: New test.
	* testsuite/ld-aarch64/bti-plt.ld: New test.
2019-03-13 11:47:07 +00:00
Sudakshina Das cd702818c6 [BFD, LD, AArch64, 1/3] Add support for GNU PROPERTIES in AArch64 for BTI and PAC
This is part of the patch series to add support for BTI and
PAC in AArch64 linker.

This patch implements the following:
1) This extends in the gnu property support in the linker for
AArch64 by defining backend hooks for elf_backend_setup_gnu_properties,
elf_backend_merge_gnu_properties and elf_backend_parse_gnu_properties.
2) It defines AArch64 specific GNU property
GNU_PROPERTY_AARCH64_FEATURE_1_AND and 2 bit for BTI and PAC in it.
3) It also adds support in readelf.c to read and print these new
GNU properties in AArch64.
All these are made according to the new AArch64 ELF ABI
https://developer.arm.com/docs/ihi0056/latest/elf-for-the-arm-64-bit-architecture-aarch64-abi-2018q4

*** bfd/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Exclude
	linker created inputs from merge.
	* elfnn-aarch64.c (struct elf_aarch64_obj_tdata): Add field for
	GNU_PROPERTY_AARCH64_FEATURE_1_AND properties.
	(elfNN_aarch64_link_setup_gnu_properties): New.
	(elfNN_aarch64_merge_gnu_properties): New.
	(elf_backend_setup_gnu_properties): Define for AArch64.
	(elf_backend_merge_gnu_properties): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Define.
	(_bfd_aarch64_elf_parse_gnu_properties): Define.
	(_bfd_aarch64_elf_merge_gnu_properties): Define.
	* elfxx-aarch64.h (_bfd_aarch64_elf_link_setup_gnu_properties): Declare.
	(_bfd_aarch64_elf_parse_gnu_properties): Declare.
	(_bfd_aarch64_elf_merge_gnu_properties): Declare.
	(elf_backend_parse_gnu_properties): Define for AArch64.

*** binutils/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* readelf.c (decode_aarch64_feature_1_and): New.
	(print_gnu_property_note): Add case for AArch64 gnu notes.

*** include/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* elf/common.h (GNU_PROPERTY_AARCH64_FEATURE_1_AND): New.
	(GNU_PROPERTY_AARCH64_FEATURE_1_BTI): New.
	(GNU_PROPERTY_AARCH64_FEATURE_1_PAC): New.

*** ld/ChangeLog ***

2019-03-13  Sudakshina Das  <sudi.das@arm.com>

	* NEWS: Document GNU_PROPERTY_AARCH64_FEATURE_1_BTI and
	GNU_PROPERTY_AARCH64_FEATURE_1_PAC.
	* testsuite/ld-aarch64/aarch64-elf.exp: Add run commands for new tests.
	* testsuite/ld-aarch64/property-bti-pac1.d: New test.
	* testsuite/ld-aarch64/property-bti-pac1.s: New test.
	* testsuite/ld-aarch64/property-bti-pac2.d: New test.
	* testsuite/ld-aarch64/property-bti-pac2.s: New test.
	* testsuite/ld-aarch64/property-bti-pac3.d: New test.
2019-03-13 11:47:00 +00:00
H.J. Lu 44b27f959a x86: Properly set IBT and SHSTK properties for -z ibt/shstk
There should be no AND properties if some input doesn't have them.  We
should set IBT and SHSTK properties for -z ibt and -z shstk if needed.

bfd/

	PR ld/24322
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Properly
	merge GNU_PROPERTY_X86_FEATURE_1_[IBT|SHSTK].

ld/

	PR ld/24322
	* testsuite/ld-i386/i386.exp: Run PR ld/24322 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr24322a.d: New file.
	* testsuite/ld-i386/pr24322b.d: Likewise.
	* testsuite/ld-x86-64/pr24322a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24322a.d: Likewise.
	* testsuite/ld-x86-64/pr24322b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24322b.d: Likewise.
	* testsuite/ld-x86-64/pr24322a.s: Likewise.
	* testsuite/ld-x86-64/pr24322b.s: Likewise.
	* testsuite/ld-x86-64/pr24322c.s: Likewise.
2019-03-13 14:38:29 +08:00
Alan Modra 7a6e0d89bb Don't use bfd_get_file_size in objdump
Compressed debug sections can have uncompressed sizes that exceed the
original file size, so we can't use bfd_get_file_size.  objdump also
used bfd_get_file_size to limit reloc section size, but I believe the
underlying bug causing the PR22508 out of bounds buffer access was
that we had an integer overflow when calculating the reloc buffer
size.  I've fixed that instead in most of the backends, som and
vms-alpha being the exceptions.  SOM and vmd-alpha have rather more
serious bugs in their slurp_relocs routines that would need fixing
first if we want to fuss about making them safe against fuzzed object
files.

The patch also fixes a number of other potential overflows by using
the bfd_alloc2/malloc2/zalloc2 memory allocation functions.

bfd/
	* coffcode.h (buy_and_read): Delete unnecessary forward decl.  Add
	nmemb parameter.  Use bfd_alloc2.
	(coff_slurp_line_table): Use bfd_alloc2.  Update buy_and_read calls.
	Delete assertion.
	(coff_slurp_symbol_table): Use bfd_alloc2 and bfd_zalloc2.
	(coff_slurp_reloc_table): Use bfd_alloc2.  Update buy_and_read calls.
	* coffgen.c (coff_get_reloc_upper_bound): Ensure size calculation
	doesn't overflow.
	* elf.c (bfd_section_from_shdr): Use bfd_zalloc2.  Style fix.
	(assign_section_numbers): Style fix.
	(swap_out_syms): Use bfd_malloc2.
	(_bfd_elf_get_reloc_upper_bound): Ensure size calculation doesn't
	overflow.
	(_bfd_elf_make_empty_symbol): Style fix.
	(elfobj_grok_stapsdt_note_1): Formatting.
	* elfcode.h (elf_object_p): Use bfd_alloc2.
	(elf_write_relocs, elf_write_shdrs_and_ehdr): Likewise.
	(elf_slurp_symbol_table): Use bfd_zalloc2.
	(elf_slurp_reloc_table): Use bfd_alloc2.
	(_bfd_elf_bfd_from_remote_memory): Use bfd_malloc2.
	* elf64-sparc (elf64_sparc_get_reloc_upper_bound): Ensure
	size calculation doesn't overflow.
	(elf64_sparc_get_dynamic_reloc_upper_bound): Likewise.
	* mach-o.c (bfd_mach_o_get_reloc_upper_bound): Likewise.
	* pdp11.c (get_reloc_upper_bound): Copy aoutx.h version.
binutils/
	* objdump.c (load_specific_debug_section): Don't compare section
	size against file size.
	(dump_relocs_in_section): Don't compare reloc size against file size.
	Print "failed to read relocs" on bfd_get_reloc_upper_bound error.
2019-03-12 23:54:09 +10:30
Alan Modra ebd2263ba9 PR24311, FAIL: S-records with constructors
Not padding string merge section output to its alignment can cause
failures of the S-record tests when input string merge sections are
padded, since the ELF linker output for the single string section
would shrink compared to the SREC linker output.  That might result in
following sections having different addresses.
On the other hand, padding string merge section output when input
string merge sections are *not* padded can also cause failures, in
this case due to the ELF linker output for the string section being
larger (due to padding) than the SREC linker output.

It would be better to write a more robust test, but it is also nice
to leave input unchanged when no string merges occur.

	PR 24311
	* merge.c (merge_strings): Return secinfo.  Don't pad section
	to alignment here.
	(_bfd_merge_sections): Pad section to alignment here, if input
	sections contributing to merged output all pad to alignment.
	Formatting.
2019-03-08 23:28:34 +10:30
Nick Clifton 219d6836e9 Fix a segmentation fault triggered by disassembling an EFi file with source included.
* dwarf2.c (_bfd_dwarf2_find_symbol_bias): Check for a NULL symbol
	table pointer.
	* coffgen.c (coff_find_nearest_line_with_names): Do not call
	_bfd_dwarf2_find_symbol_bias if there is no symbol table available.

https://bugzilla.redhat.com/show_bug.cgi?id=1685727
2019-03-06 09:43:54 +00:00
Andreas Krebbel 24801b1576 Revert "Add support to GNU ld to separate got related plt entries"
bfd/ChangeLog:

2019-03-01  Andreas Krebbel  <krebbel@linux.ibm.com>

	This reverts commit 5a12586d44.
	2019-01-14  Maamoun Tarsha  <maamountk@hotmail.com>

	PR 20113
	* elf32-s390.c (allocate_dynrelocs): Update comment.

ld/ChangeLog:

2019-03-01  Andreas Krebbel  <krebbel@linux.ibm.com>

	This reverts commit 5a12586d44.
	2019-01-14  Maamoun Tarsha  <maamountk@hotmail.com>

	PR 20113
	* emulparams/elf64_s390.sh (SEPARATE_GOTPLT): Define.
	* emulparams/elf_s390.sh (SEPARATE_GOTPLT): Define.
	* testsuite/ld-s390/gotreloc_31-1.dd: Update expected output.
	* testsuite/ld-s390/tlsbin.dd: Likewise.
	* testsuite/ld-s390/tlsbin.rd: Likewise.
	* testsuite/ld-s390/tlsbin.sd: Likewise.
	* testsuite/ld-s390/tlsbin_64.dd: Likewise.
	* testsuite/ld-s390/tlsbin_64.rd: Likewise.
	* testsuite/ld-s390/tlsbin_64.sd: Likewise.
	* testsuite/ld-s390/tlspic.dd: Likewise.
	* testsuite/ld-s390/tlspic.rd: Likewise.
	* testsuite/ld-s390/tlspic.sd: Likewise.
	* testsuite/ld-s390/tlspic_64.dd: Likewise.
	* testsuite/ld-s390/tlspic_64.rd: Likewise.
	* testsuite/ld-s390/tlspic_64.sd: Likewise.
	* testsuite/ld-s390/s390.exp: Skip s390 tests for tpf targets.
2019-03-01 15:35:00 +01:00
Tamar Christina 4ffd290906 Binutils: Always skip only 1 byte for CIE version 1's return address register.
According to the specification for the CIE entries, when the CIE version is 1 then
the return address register field is always 1 byte.  Readelf does this correctly in
read_cie in dwarf.c but ld does this incorrectly and always tries to read a
skip_leb128.  If the value here has the top bit set then ld will incorrectly read
at least another byte, causing either an assert failure or an incorrect address to
be used in eh_frame.

I'm not sure how to generate a generic test for this as I'd need to write assembly,
and it's a bit hard to trigger. Essentially the relocated value needs to start with
something that & 0x70 != 0x10 while trying to write a personality.

bfd/ChangeLog:

	* elf-eh-frame.c (_bfd_elf_write_section_eh_frame): Correct CIE parse.
2019-03-01 11:38:22 +00:00
Nick Clifton eed5def8d0 Prevent a buffer overrun error when attempting to parse a corrupt ELF file.
PR 24273
	* elf.c (bfd_elf_string_from_elf_section): Check for a string
	section that is not NUL terminated.
2019-02-28 14:30:20 +00:00
H.J. Lu 5cfe428cd1 x86-64: Skip protected check on symbol defined by linker
Skip symbol defined by linker when checking copy reloc on protected
symbol.

bfd/

	PR ld/24276
	* elf64-x86-64.c (elf_x86_64_check_relocs): Skip symbol defined
	by linker when checking copy reloc on protected symbol.

ld/

	PR ld/24276
	* testsuite/ld-i386/i386.exp: Run PR ld/24276 test.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr24276.dso: New file.
	* testsuite/ld-i386/pr24276.warn: Likewise.
	* testsuite/ld-x86-64/pr24276.dso: Likewise.
	* testsuite/ld-x86-64/pr24276.warn: Likewise.
2019-02-27 11:53:27 -08:00
Alan Modra f616c36b79 PR24144, pdp11-ld overwriting section data with zeros
bfd/
	PR 24144
	* pdp11.c (set_section_contents): Revert 2015-02-24 change.
gas/
	PR 24144
	* config/obj-aout.c (obj_aout_frob_file_before_fix): Write to end
	of section to ensure file contents cover aligned section size.
2019-02-24 18:57:04 +10:30
Max Filippov eed62915fd bfd: xtensa: fix callx relaxation
Big section alignment requirements between source and destination of a
long call can result in making call range bigger than what's reachable
by the call opcode. Add biggest section alignment of sections between
the call site and call destination to the call distance when making
long call relaxation decision.

2019-02-20  Eric Tsai  <erictsai@cadence.com>
bfd/
	* elf32-xtensa.c (is_resolvable_asm_expansion): Scan output
	sections between the call site and call destination and adjust
	call distance by the largest alignment.

ld/
	* testsuite/ld-xtensa/call_overflow.d: New test definition.
	* testsuite/ld-xtensa/call_overflow1.s: New test source.
	* testsuite/ld-xtensa/call_overflow2.s: New test source.
	* testsuite/ld-xtensa/call_overflow3.s: New test source.
	* testsuite/ld-xtensa/xtensa.exp: Add call_overflow test.
2019-02-20 02:51:01 -08:00
Alan Hayward e6c3b5bfb4 AArch64: Add pauth core file section
Used for the AArch64 pointer authentication code mask registers in Arm v8.3-a.

NT_ARM_PAC_MASK matches the value in Linux include/uapi/linux/elf.h

include/ChangeLog:

	* elf/common.h (NT_ARM_PAC_MASK): Add define.

bfd/ChangeLog:

	* elf-bfd.h (elfcore_write_aarch_pauth): Add declaration.
	* elf.c (elfcore_grok_aarch_pauth): New function.
	(elfcore_grok_note): Check for NT_ARM_PAC_MASK.
	(elfcore_write_aarch_pauth): New function.
	(elfcore_write_register_note): Check for AArch64 pauth section.
2019-02-20 10:39:28 +00:00
Alan Modra 34d75fb5c4 Check asprintf return value
git a31b8bd9a0 introduced a warning (depending on your system
headers).

	PR 24225
	* elf32-nios2.c (nios2_elf32_relocate_section): Check asprintf
	return value.
2019-02-20 18:54:41 +10:30
Michael Roitzsch edd01d077c Use or1k-darwin host SHARED_LIBADD for *-darwin.
* configure.ac (SHARED_LIBADD): Add -liberty -lintl for all
	Darwin hosts, not just or1k.
	* configure: Regenerate.
2019-02-20 14:49:07 +10:30
Alan Modra 8abac8031e PR24236, Heap buffer overflow in _bfd_archive_64_bit_slurp_armap
PR 24236
	* archive64.c (_bfd_archive_64_bit_slurp_armap): Move code adding
	sentinel NUL to string buffer nearer to loop where it is used.
	Don't go past sentinel when scanning strings, and don't write
	NUL again.
	* archive.c (do_slurp_coff_armap): Simplify string handling to
	archive64.c style.
2019-02-20 11:50:07 +10:30
Alan Modra 179f2db0d9 PR24235, Read memory violation in pei-x86_64.c
PR 24235
	* pei-x86_64.c (pex64_bfd_print_pdata_section): Correct checks
	attempting to prevent read past end of section.
2019-02-19 22:52:55 +10:30
Alan Modra a31b8bd9a0 PR24225, nios2 buffer overflow
PR 24225
	* elf32-nios2.c (nios2_elf32_relocate_section): Use asprintf and
	PRIx64 to generate warning messages.  Print local sym names too.
2019-02-18 15:12:34 +10:30
Claudiu Zissulescu a0e90a73f0 [ARC] don't force _init/_fini as DT_INIT/DT_FINI.
Recent gcc commit b4371b277f1e ("[ARC] Enable init_array support")
inhibits DT_"INIT,FINI} in favor of DT_{INIT,FINI}ARRAY.

Even prior to that, it seems ARC port is the only one with this
special DT_INIT/FINI handling in linker emulation. Removing it
doesn't seem to change any uClibc/glibc testsuite results,
so this can RIP anyways.

bfd/
    2019-02-01  Vineet Gupta <vgupta@synopsys.com>

           * elf32-arc.c: Delete init_str, fini_str

ld/
    2019-02-01  Vineet Gupta <vgupta@synopsys.com>

           * emultempl/arclinux.em : Delete special INIT/FINI handling.
2019-02-09 11:07:42 +01:00
Alan Modra 482f3505d1 Make inline plt reloc "unsupported for bss-plt" an error
This was always supposed to be an error.  Code emitted by gcc for
inline PLT calls assumes PLT is an array of addresses.

	* elf32-ppc.c (ppc_elf_relocate_section): Add %X to "unsupported
	for bss-plt" warning to make it an error.
2019-02-08 21:32:40 +10:30
Eric Botcazou b2abe1bd81 SPARC: fix PR ld/18841
This fixes the last ld failures on SPARC64/Linux:

FAIL: Run pr18841 with libpr18841b.so
FAIL: Run pr18841 with libpr18841c.so
FAIL: Run pr18841 with libpr18841bn.so (-z now)
FAIL: Run pr18841 with libpr18841cn.so (-z now)

by mimicing what has been done on x86-64 and Aarch64 to fix the PR.

bfd/
	PR ld/18841
        * elf32-sparc.c (elf32_sparc_reloc_type_class): Return
        reloc_class_ifunc for ifunc symbols.
        * elf64-sparc.c (elf64_sparc_reloc_type_class): Likewise.
2019-02-07 17:04:31 +01:00
Eric Botcazou 68a091326f Visium: fix bogus overflow check on 32-bit hosts
bfd/
	* elf32-visium.c (visium_elf_howto_parity_reloc): Minor tweak.
	<R_VISIUM_PC16>: Use explicit range test to detect an overflow.
2019-02-07 17:02:24 +01:00
Nick Clifton 2012bf013b Move potentially obsolete BFD targets into the definitely obsolete section. Add a note to the README-how-to-make-a-release document about doing this.
bfd	* config.bfd: Move the powerpc-lynxos and powerpc-windiss targets
	into the definitely obsolete list.

binutils * README-how-to-make-a-release: Add a note about updating the
	obsolete targets in the bfd/config.bfd file.
2019-02-07 14:30:02 +00:00
H.J. Lu 83924b3846 x86-64: Restore PIC check for PCREL reloc against protected symbol
commit bd7ab16b45
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 13 07:34:22 2018 -0800

    x86-64: Generate branch with PLT32 relocation

removed check R_X86_64_PC32 relocation against protected symbols in
shared objects.  Since elf_x86_64_check_relocs is called after we
have seen all input files, we can check for PC-relative relocations in
elf_x86_64_check_relocs.  We should not allow PC-relative relocations
against protected symbols since address of protected function and
location of protected data may not be in the shared object.

bfd/

	PR ld/24151
	* elf64-x86-64.c (elf_x86_64_need_pic): Check
	SYMBOL_DEFINED_NON_SHARED_P instead of def_regular.
	(elf_x86_64_relocate_section): Move PIC check for PC-relative
	relocations to ...
	(elf_x86_64_check_relocs): Here.
	(elf_x86_64_finish_dynamic_symbol): Use SYMBOL_DEFINED_NON_SHARED_P
	to check if a symbol is defined in a non-shared object.
	* elfxx-x86.h (SYMBOL_DEFINED_NON_SHARED_P): New.

ld/

	PR ld/24151
	* testsuite/ld-x86-64/pr24151a-x32.d: New file.
	* testsuite/ld-x86-64/pr24151a.d: Likewise.
	* testsuite/ld-x86-64/pr24151a.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr24151a and pr24151a-x32.
2019-02-05 18:45:34 -08:00
Sergio Durigan Junior 453f8e1e49 Fix GCC9 warning on elf32-arm.c:elf32_arm_final_link_relocate
Fedora Rawhide has just switched to GCC9, and now GDB doesn't compile
because of a BFD warning:

  BUILDSTDERR: ../../bfd/elf32-arm.c: In function 'elf32_arm_final_link_relocate':
  BUILDSTDERR: ../../bfd/elf32-arm.c:10907:10: error: absolute value function 'labs' given an argument of type 'bfd_signed_vma' {aka 'long long int'} but has parameter of type 'long int' which may cause truncation of value [-Werror=absolute-value]
  BUILDSTDERR: 10907 |  value = labs (relocation);
  BUILDSTDERR:       |          ^~~~

You can take a look at the full build log here:

  https://kojipkgs.fedoraproject.org//work/tasks/4828/32174828/build.log

The fix is (apparently) simple: instead of using 'labs', we should use
'llabs', since we're passing a 'bfd_signed_vma' to it, which is at
least a 'long long int', as far as I have checked.  This is what this
patch does.

bfd/ChangeLog:
2019-01-25  Sergio Durigan Junior  <sergiodj@redhat.com>

	* elf32-arm.c (elf32_arm_final_link_relocate): Use 'llabs' instead
	of 'labs' (and fix GCC warning).
2019-01-28 10:50:23 -05:00
Nick Clifton 9ed1348c20 Updated Bulgarian and Russian translations for some of the binutils sub-directories 2019-01-25 11:48:55 +00:00
Nick Clifton d99386305c Updated translations for some of the binutils subdirectory. 2019-01-23 10:26:54 +00:00
Nick Clifton 375cd4233d Updated translations for various binutils subdirectories. 2019-01-21 12:59:20 +00:00
Yuri Chornoivan acef8081ec Fix spelling mistakes in BFD library.
PR 24108
bfd	* elf32-nds32.c (nds32_relocate_section): Add space between words
	in error message.
	* elfnn-riscv.c (riscv_version_mismatch): Fix spelling mistake in
	error message.
	(riscv_i_or_e_p): Likewise.
	(riscv_merge_arch_attr_info): Likewise.

ld	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Update
	expected error message.
2019-01-21 12:39:24 +00:00
Nick Clifton f48dfe417e Change version to 2.32.51 and regenerate configure and pot files. 2019-01-19 16:51:42 +00:00
Nick Clifton f974f26cb1 Add markers for 2.32 branch to NEWS and ChangeLog files. 2019-01-19 15:55:50 +00:00
Jim Wilson a4bf3d0720 Don't emit vendor attribute section if there is no attribute to emit.
2019-01-16  Kito Cheng  <kito@andestech.com>
	bfd/
	* elf-attrs.c (vendor_obj_attr_size): Return 0 if size is 0 even
	for OBJ_ATTR_PROC.
	gas/
	* testsuite/gas/riscv/attribute-empty.d: New.
2019-01-16 13:37:35 -08:00
Jim Wilson 7d7a7d7ccf RISC-V: Merge ELF attribute for ld.
2019-01-16  Kito Cheng  <kito@andestech.com>
		    Nelson Chu  <nelson@andestech.com>

	bfd/
	* elfnn-riscv.c (in_subsets): New.
	(out_subsets): Likewise.
	(merged_subsets): Likewise.
	(riscv_std_ext_p): Likewise.
	(riscv_non_std_ext_p): Likewise.
	(riscv_std_sv_ext_p): Likewise.
	(riscv_non_std_sv_ext_p): Likewise.
	(riscv_version_mismatch): Likewise.
	(riscv_i_or_e_p): Likewise.
	(riscv_merge_std_ext): Likewise.
	(riscv_merge_non_std_and_sv_ext): Likewise.
	(riscv_merge_arch_attr_info): Likewise.
	(riscv_merge_attributes): Likewise.
	(_bfd_riscv_elf_merge_private_bfd_data): Merge attribute.
	ld/
	* testsuite/ld-elf/orphan-region.d: XFAIL for RISC-V, because add new
	section.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Add new tests.
	* testsuite/ld-riscv-elf/attr-merge-arch-01.d: New test.
	* testsuite/ld-riscv-elf/attr-merge-arch-01a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-01b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-02a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-02b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-03a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-03b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-stack-align-a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-stack-align-b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-stack-align-failed-a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-stack-align-failed-b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-stack-align-failed.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-stack-align.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-01.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-01a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-01b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-02a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-02b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-03a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-03b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-04.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-04a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-04b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-05.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-05a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-05b.s: Likewise.
2019-01-16 13:28:35 -08:00
Jim Wilson 2dc8dd17cd RISC-V: Support ELF attribute for gas and readelf.
2019-01-16  Kito Cheng  <kito@andestech.com>
		    Nelson Chu  <nelson@andestech.com>

	bfd/
	* elfnn-riscv.c (riscv_elf_obj_attrs_arg_type): New.
	(elf_backend_obj_attrs_vendor): Define.
	(elf_backend_obj_attrs_section_type): Likewise.
	(elf_backend_obj_attrs_section): Likewise.
	(elf_backend_obj_attrs_arg_type): Define as
	riscv_elf_obj_attrs_arg_type.
	* elfxx-riscv.c (riscv_estimate_digit): New.
	(riscv_estimate_arch_strlen1): Likewise.
	(riscv_estimate_arch_strlen): Likewise.
	(riscv_arch_str1): Likewise.
	(riscv_arch_str): Likewise.
	* elfxx-riscv.h (riscv_arch_str): Declare.
	binutils/
	* readelf.c (get_riscv_section_type_name): New function.
	(get_section_type_name): Add handler for RISC-V.
	(riscv_attr_tag_t): Declare.
	(riscv_attr_tag): New.
	(display_riscv_attribute): New function.
	(process_attributes): Add handler for RISC-V.
	* testsuite/binutils-all/strip-3.d: Remove .riscv.attribute
	section.
	gas/
	* config/tc-riscv.c (DEFAULT_RISCV_ATTR): Define to 0 if not defined.
	(riscv_set_options): Add `arch_attr` field.
	(riscv_opts): Set default value for arch_attr.
	(riscv_write_out_arch_attr): New.
	(riscv_set_public_attributes): Likewise.
	(riscv_md_end): Likewise.
	(riscv_convert_symbolic_attribute): Likewise.
	(s_riscv_attribute): Likewise.
	(explicit_arch_attr): Likewise.
	(riscv_pseudo_table): Add .attribute to the table.
	(options): Add OPTION_ARCH_ATTR and OPTION_NO_ARCH_ATTR
	enumeration constants.
	(md_longopts): Add `march-attr' and `mno-arch-attr' options.
	(md_parse_option): Handle the new options.
	(md_show_usage): Document the `march-attr' option.
	* config/tc-riscv.h (md_end): Define as riscv_md_end
	(riscv_md_end): Declare.
	(CONVERT_SYMBOLIC_ATTRIBUTE): Define as
	riscv_convert_symbolic_attribute.
	(riscv_convert_symbolic_attribute): Declare.
	(start_assemble): Declare.
	* testsuite/gas/elf/elf.exp: Adjust test case for section2.e.
	* testsuite/gas/elf/section2.e-riscv: New.
	* testsuite/gas/riscv/attribute-01.d: New test
	* testsuite/gas/riscv/attribute-02.d: Likewise.
	* testsuite/gas/riscv/attribute-03.d: Likewise.
	* testsuite/gas/riscv/attribute-04.d: Likewise.
	* testsuite/gas/riscv/attribute-04.s: Likewise.
	* testsuite/gas/riscv/attribute-05.d: Likewise.
	* testsuite/gas/riscv/attribute-05.s: Likewise.
	* testsuite/gas/riscv/attribute-06.d: Likewise.
	* testsuite/gas/riscv/attribute-06.s: Likewise.
	* testsuite/gas/riscv/attribute-07.d: Likewise.
	* testsuite/gas/riscv/attribute-07.s: Likewise.
	* testsuite/gas/riscv/attribute-08.d: Likewise.
	* testsuite/gas/riscv/attribute-08.s: Likewise.
	* testsuite/gas/riscv/attribute-unknown.d: Likewise.
	* testsuite/gas/riscv/attribute-unknown.s: Likewise.
	* testsuite/gas/riscv/empty.l: Likewise.
	* doc/c-riscv.texi (.attribute): Add documentation.
	* configure.ac (--enable-default-riscv-attribute): New options.
	* configure: Re-generate.
	* config.in: Re-generate.
	include/
	* elf/riscv.h (SHT_RISCV_ATTRIBUTES): Define.
	(Tag_RISCV_arch): Likewise.
	(Tag_RISCV_priv_spec): Likewise.
	(Tag_RISCV_priv_spec_minor): Likewise.
	(Tag_RISCV_priv_spec_revision): Likewise.
	(Tag_RISCV_unaligned_access): Likewise.
	(Tag_RISCV_stack_align): Likewise.
2019-01-16 13:14:59 -08:00
John Darrington d5dcaf1b59 S12Z: Emit RELOC_S12Z_OPR instead of RELOC_EXT24 where appropriate.
When assembling instructions which involve OPR references, emit
RELOC_S12Z_OPR instead of RELOC_EXT24.

bfd/
	* bfd-in2.h [BFD_RELOC_S12Z_OPR]: New reloc.
	* libbfd.h: regen.
	* elf32-s12z.c (eld_s12z_howto_table): R_S12Z_OPR takes non zero
	source field.  (md_apply_fix): Apply final fix
	to BFD_RELOC_S12Z_OPR.
	* reloc.c[BFD_RELOC_S12Z_OPR]: New reloc.

gas/
	* config/tc-s12z.c (emit_opr): Emit BFD_RELOC_S12Z_OPR instead of
	BFD_RELOC_24.
	* testsuite/gas/s12z/opr-indirect-expr.d: Expect R_S12Z_OPR instead
	of R_S12Z_EXT24.
2019-01-16 14:39:04 +01:00
Nick Clifton f466c3053d Correct PR number in prevvious delta 2019-01-14 16:04:18 +00:00
Maamoun Tarsha 5a12586d44 Add support to GNU ld to separate got related plt entries from normal ones in order to be able to switch the non-plt got entries to read-only after startup, conforming to revised Linux for zSeries ABI.
PR 20133
	* emulparams/elf64_s390.sh (SEPARATE_GOTPLT): Define.
	* emulparams/elf_s390.sh (SEPARATE_GOTPLT): Define.
	* testsuite/ld-s390/gotreloc_31-1.dd: Update expected output.
	* testsuite/ld-s390/tlsbin.dd: Likewise.
	* testsuite/ld-s390/tlsbin.rd: Likewise.
	* testsuite/ld-s390/tlsbin.sd: Likewise.
	* testsuite/ld-s390/tlsbin_64.dd: Likewise.
	* testsuite/ld-s390/tlsbin_64.rd: Likewise.
	* testsuite/ld-s390/tlsbin_64.sd: Likewise.
	* testsuite/ld-s390/tlspic.dd: Likewise.
	* testsuite/ld-s390/tlspic.rd: Likewise.
	* testsuite/ld-s390/tlspic.sd: Likewise.
	* testsuite/ld-s390/tlspic_64.dd: Likewise.
	* testsuite/ld-s390/tlspic_64.rd: Likewise.
	* testsuite/ld-s390/tlspic_64.sd: Likewise.
	* testsuite/ld-s390/s390.exp: Skip s390 tests for tpf targets.
2019-01-14 16:00:14 +00:00
Andrew Paprocki 3107326d3d Adjust bfd/warning.m4 egrep patterns
Adjust the `bfd/warning.m4` `egrep` patterns to handle preprocessors
that do not define `__GNUC__`, leaving the string in the output.

bfd/
	* warning.m4: Adjust egrep pattern for non-GNU compilers.
	* configure: Regenerate.
binutils/
	* configure: Regenerate.
gas/
	* configure: Regenerate.
gold/
	* configure: Regenerate.
gprof/
	* configure: Regenerate.
ld/
	* configure: Regenerate.
opcodes/
	* configure: Regenerate.
2019-01-09 13:51:08 +10:30
Alan Modra a9859e0172 PR24065, 32-bit objcopy fails with 64-bit address ... out of range
PR 23699
	PR 24065
	* ihex.c (ihex_write_object_contents): Properly check 32-bit
	address range.
2019-01-08 22:25:09 +10:30
Yoshinori Sato c8c89dac38 RX: bfd - Add RXv3 support.
* bfd/archures.c: Add bfd_mach_rx_v2 and bfd_mach_rx_v3.
        * bfd/bfd-in2.h: Regenerate.
        * bfd/cpu-rx.c (arch_info_struct): Add RXv2 and RXv3 entry.
        * bfd/elf32-rx.c (elf32_rx_machine): Add RXv2 and RXv3 support.
2019-01-05 22:52:53 +09:00
Lifang Xia d9858c3791 Change the default for the CSKY target to be little endian.
* config.bfd (csky-*-elf* | csky-*-linux*): Modify the csky
	default target, little endian target is more suitable.
2019-01-04 13:56:46 +00:00
Alan Modra 677bd4c69d PR24061, powerpc-ibm-aix-ar sets bogus file permissions when extracting
Mode field should be read in octal, all the rest in decimal.  Do so.

	PR 24061
	PR 21786
	* coff-rs6000.c (GET_VALUE_IN_FIELD): Add base parameter and
	adjust all callers.
	(EQ_VALUE_IN_FIELD): Likewise.
	* coff64-rs6000.c (GET_VALUE_IN_FIELD): Likewise.
2019-01-04 12:23:56 +10:30
Alan Modra 827041555a Update year range in copyright notice of binutils files 2019-01-01 22:06:53 +10:30
Alan Modra d5c04e1bf8 ChangeLog rotation 2019-01-01 21:25:40 +10:30
Alan Modra 54025d5812 PR24041, Invalid Memory Address Dereference in elf_link_add_object_symbols
PR 24041
	* elflink.c (elf_link_add_object_symbols): Don't segfault on
	crafted ET_DYN with no program headers.
2018-12-31 15:57:39 +10:30
Alan Modra c96e057398 [PowerPC64] Nop out ld 2,24(1) after old-style __tls_get_addr
When optimising inline plt calls to __tls_get_addr without tls marker
relocs, ld should zap any toc restore insn after the bctrl, to stop a
load-hit-store stall.

	* elf64-ppc.c (ppc64_elf_relocate_section <tls_ldgd_opt>): When
	editing an old-style __tls_get_addr call, replace a toc restore
	insn with a nop.
2018-12-31 12:12:38 +10:30
Alan Modra 0e41bebb93 PR24015, glibc-2.28 on little-endian mips32 broken
Commit 2bf2bf23da exposed a bug on targets that create common sections
other than the standard ELF SHN_COMMON.  If these are output by ld -r,
then their type becomes SHT_PROGBITS unless the target handles them
specially (eg. by elf_backend_special_sections), and if they are
merged into .bss/.sbss by ld -r then that section becomes SHT_PROGBITS.

Worse, if they are output by ld -r, then their size is increased by
bfd_generic_define_common_symbol during final link, which leads to
bogus file contents being copied to output.

For mips, it seems to me that the .scommon section should not be
output for ld -r, but I haven't made that change in this patch.

	PR 24015
	* elf.c (bfd_elf_get_default_section_type): Make common sections
	SHT_NOBITS.
	* linker.c (bfd_generic_define_common_symbol): Clear
	SEC_HAS_CONTENTS.
2018-12-28 15:02:08 +10:30
Alan Modra cb87d9f1a4 PR23966, mingw failure due to 32-bit long
PR 23966
	* libbfd.c (SSIZE_MAX): Define.
	(bfd_malloc, bfd_realloc): Don't cast size to long to check for
	"negative" values, compare against SSIZE_MAX instead.
2018-12-28 15:02:04 +10:30
H.J. Lu b366503e45 i386: Remove the unused bfd pointer argument
Remove the unused bfd pointer argument of elf_i386_rtype_to_howto.

	* elf32-i386.c (elf_i386_rtype_to_howto): Remove the unused bfd
	pointer argument.
	(elf_i386_info_to_howto_rel): Updated.
	(elf_i386_tls_transition): Likewise.
	(elf_i386_relocate_section): Likewise.
2018-12-23 09:45:29 -08:00
H.J. Lu 76268e0274 x86: Call rtype_to_howto to get reloc_howto_type pointer
* elf32-i386.c (elf_i386_relocate_section): Call
	elf_i386_rtype_to_howto to get reloc_howto_type pointer.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Call
	elf_x86_64_rtype_to_howto to get reloc_howto_type pointer.
2018-12-20 13:25:41 -08:00
Alan Modra 2d5d5a8f0a Include bfd_stdint.h in bfd.h
This patch adds bfd_stdint.h to bfd.h, so that BFD can use size_t
where appropriate in function parameters and return values.  I also
tidy a few other cases where headers are included twice.

bfd/
	* Makefile.am (bfdinclude_HEADERS): Add bfd_stdint.h.
	(BFD_H_DEPS): Add include/diagnostics.h.
	(LOCAL_H_DEPS): Add bfd_stdint.h.
	* bfd-in.h: Include bfd_stdint.h.
	* arc-plt.h: Don't include stdint.h.
	* coff-rs6000.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* elfxx-riscv.c: Likewise.
	* cache.c: Don't include bfd_stdint.h.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-rx.c: Likewise.
	* elf32-wasm32.c: Likewise.
	* elf64-nfp.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-ia64.c: Likewise.
	* elfxx-x86.h: Likewise.
	* wasm-module.c: Likewise, and don't include sysdep.h twice.
	* elf-nacl.h: Don't include bfd.h.
	* mach-o.h: Likewise.
	* elfxx-aarch64.c: Include bfd.h and elf-bfd.h.
	* elfxx-aarch64.h: Don't include bfd.h, elf-bfd.h or stdint.h.
	* mach-o-aarch64.c: Include mach-o.h later.
	* mach-o-arm.c: Likewise.
	* mach-o-i386.c: Likewise.
	* mach-o-x86-64.c: Likewise.
	* mach-o.c: Likewise.
	* sysdep.h: Don't include ansidecl.h or sys/stat.h.
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
opcodes/
	* arm-dis.c: Include bfd.h.
	* aarch64-opc.c: Include bfd_stdint.h rather than stdint.h.
	* csky-dis.c: Likewise.
	* nds32-asm.c: Likewise.
	* riscv-dis.c: Likewise.
	* s12z-dis.c: Likewise.
	* wasm32-dis.c: Likewise.
2018-12-18 23:49:48 +10:30
Alan Modra 7af5d5c4dd PR23980, assertion fail
All of the backend relocate_section functions that interpret reloc
numbers assuming the input file is of the expected type (ie. same as
output or very similar) really ought to be checking input file type.
Not many do, and those that do currently just assert.  This patch
replaces the assertion with a more graceful exit.

	PR 23980
	* elf32-i386.c (elf_i386_relocate_section): Exit with wrong format
	error rather than asserting input file is as expected.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Exit with wrong format
	error if input file is not ppc32 ELF.
2018-12-18 10:47:02 +10:30
Alan Modra 87469ba2d2 PR23980, powerpc64 ld segfault
PR 23980
	* elf64-ppc.c (ppc64_elf_hide_symbol): Check hash table type
	before referencing ppc64-only fields of hash entries.
2018-12-18 09:03:45 +10:30
Alan Modra 3a551c7a1b PR23994, libbfd integer overflow
PR 23994
	* aoutx.h: Include limits.h.
	(get_reloc_upper_bound): Detect long overflow and return a file
	too big error if it occurs.
	* elf.c: Include limits.h.
	(_bfd_elf_get_symtab_upper_bound): Detect long overflow and return
	a file too big error if it occurs.
	(_bfd_elf_get_dynamic_symtab_upper_bound): Likewise.
	(_bfd_elf_get_dynamic_reloc_upper_bound): Likewise.
2018-12-17 12:49:38 +10:30
H.J. Lu 0a59decbb8 elf: Add PT_GNU_PROPERTY segment type
Linkers group input note sections with the same name into one output
note section with the same name.  One output note section is placed in
one PT_NOTE segment.  New linkers merge all input .note.gnu.property
sections into one output .note.gnu.property section with a single
NT_GNU_PROPERTY_TYPE_0 note in a single PT_NOTE segment.  Since older
linkers treat input .note.gnu.property section as a generic note section
and just concatenate all input .note.gnu.property sections into one
output .note.gnu.property section without merging them, we may
see one or more NT_GNU_PROPERTY_TYPE_0 notes in PT_NOTE segment, which
are invalid.

GNU_PROPERTY_X86_UINT32_VALID was defined to address this issue such
that linker sets the bit for non-relocatable outputs.  But it isn't
sufficient:

1. It doesn't cover generic properties.
2. When -mx86-used-note=yes is passed to x86 assembler, the
GNU_PROPERTY_X86_UINT32_VALID bit is set in GNU_PROPERTY_X86_ISA_1_USED
property in object file and older linkers generate invalid
NT_GNU_PROPERTY_TYPE_0 notes with the GNU_PROPERTY_X86_UINT32_VALID bit
set.

I am proposing the following changes:

1. Add PT_GNU_PROPERTY segment type:

 # define PT_GNU_PROPERTY (PT_LOOS + 0x474e553)

which covers .note.gnu.property section.
2. Remove GNU_PROPERTY_X86_UINT32_VALID.

bfd/

	PR ld/23900
	* elf.c (get_program_header_size): Add a PT_GNU_PROPERTY
	segment for NOTE_GNU_PROPERTY_SECTION_NAME.
	(_bfd_elf_map_sections_to_segments): Create a PT_GNU_PROPERTY
	segment for NOTE_GNU_PROPERTY_SECTION_NAME.
	* elfxx-x86.c (_bfd_elf_link_setup_gnu_properties): Don't set
	GNU_PROPERTY_X86_UINT32_VALID.

binutils/

	PR ld/23900
	* readelf.c (get_segment_type): Support PT_GNU_PROPERTY.
	(decode_x86_isa): Don't check GNU_PROPERTY_X86_UINT32_VALID.
	(decode_x86_feature_1): Likewise.
	(decode_x86_feature_2): Likewise.
	(print_gnu_property_note): Remove GNU_PROPERTY_X86_UINT32_VALID
	check.
	* testsuite/binutils-all/i386/empty.d: Updated.
	* testsuite/binutils-all/x86-64/empty-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/empty.d: Likewise.
	* testsuite/binutils-all/i386/pr21231b.s: Change
	GNU_PROPERTY_X86_ISA_1_USED bits to 0x7fffffff.
	* testsuite/binutils-all/x86-64/pr21231b.s: Likewise.

gas/

	PR ld/23900
	* config/tc-i386.c (x86_cleanup): Don't set
	GNU_PROPERTY_X86_UINT32_VALID.
	* testsuite/gas/i386/property-1.s: Change
	GNU_PROPERTY_X86_ISA_1_USED bits to 0.

include/

	PR ld/23900
	* elf/common.h (PT_GNU_PROPERTY): New.
	(GNU_PROPERTY_X86_UINT32_VALID): Removed.

ld/

	PR ld/23900
	* testsuite/ld-elf/elf.exp: Run PR ld/23900 test.
	* testsuite/ld-elf/pr23900-1-32.rd: New file.
	* testsuite/ld-elf/pr23900-1-64.rd: Likewise.
	* testsuite/ld-elf/pr23900-1.d: Likewise.
	* testsuite/ld-elf/pr23900-1.s: Likewise.
	* testsuite/ld-elf/pr23900-2.s: Likewise.
	* testsuite/ld-elf/pr23900-2a.d: Likewise.
	* testsuite/ld-elf/pr23900-2b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-1.d: Adjusted.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2d.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3d.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-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-2c.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-i386/pr23372c.d: Expect <None>
	for GNU_PROPERTY_X86_ISA_1_USED.
	* testsuite/ld-x86-64/pr23372c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372c.d: Likewise.
	* testsuite/ld-x86-64/pr23372d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372d.d: Likewise.
	* testsuite/ld-x86-64/property-x86-5a.s: Change
	GNU_PROPERTY_X86_ISA_1_USED bits to 0.
	* testsuite/ld-x86-64/property-x86-5b.s: Likewise.
2018-12-14 04:55:34 -08:00
Max Filippov 00863b8e40 bfd: xtensa: ignore overflow in hight part of const16 relocation
32-bit constants loaded by two const16 opcodes that involve relocation
(e.g. calculated as a sum of a symbol and a constant) may overflow,
resulting in linking error with the following message:

  dangerous relocation: const16: cannot encode: (_start+0x70000000)

They should wrap around instead. Limit const16 opcode immediate field to
16 least significant bits to implement this wrap around.

bfd/
2018-12-11  Max Filippov  <jcmvbkbc@gmail.com>

	* elf32-xtensa.c (elf_xtensa_do_reloc): Limit const16 opcode
	immediate field to 16 least significant bits.
2018-12-11 14:21:39 -08:00
H.J. Lu 209d1499de xc16x: Add elf32_xc16x_rtype_to_howto
Add elf32_xc16x_rtype_to_howto to get reloc_howto_type pointer from
ELF32_R_TYPE.

	* elf32-xc16x.c (elf32_xc16x_rtype_to_howto): New function.
	(elf32_xc16x_relocate_section): Call elf32_xc16x_rtype_to_howto
	instead of xc16x_reloc_type_lookup to get reloc_howto_type.
2018-12-11 06:01:46 -08:00
H.J. Lu fbcc8bafeb Override the previous definition from IR object
Mark the previous definition from IR object as undefined so that the
generic linker will override it.

bfd/

	PR ld/23958
	* elflink.c (_bfd_elf_add_default_symbol): Override the previous
	definition from IR object.

ld/

	PR ld/23958
	* testsuite/ld-plugin/lto.exp: Run PR ld/23958 test.
	* testsuite/ld-plugin/pr23958.c: New file.
	* testsuite/ld-plugin/pr23958.t: Likewise.
2018-12-07 15:40:02 -08:00
Stafford Horne 42e151bf4c gdb/or1k: Add linux debugging support
Up until now OpenRISC GDB only has supported bare metal debugging.  This
patch adds linux userspace debugging and core dump analysis support.

The changes are loosely based on nios2 and riscv implementations.

This was tested with linux 4.20 core dumps for executables linked
against musl libc.

bfd/ChangeLog:

	* elf32-or1k.c (or1k_grok_prstatus): New function.
	(or1k_grok_psinfo): Likewise.

gdb/ChangeLog:

	* Makefile.in (ALL_TARGET_OBS): Add or1k-linux-tdep.o.
	* configure.tgt: Add or1k*-*-linux*.
	* or1k-linux-tdep.c: New file.
	* or1k-tdep.c (or1k_gdbarch_init): Call gdbarch_init_osabi.
2018-12-08 07:07:36 +09:00
H.J. Lu d2ef37ebd9 elf: Report property change when merging properties
With merging properties, report property change in linker map file, like

Merging program properties

Removed property 0xc0010000 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (0x0) and /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crti.o (0x0)
Removed property 0xc0000002 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (0x3) and x.o (not found)
Removed property 0xc0000000 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (not found) and /usr/lib64/libc_nonshared.a(elf-init.oS) (0x0)
Removed property 0xc0000001 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (not found) and /usr/lib64/libc_nonshared.a(elf-init.oS) (0x0)

bfd/

	* elf-properties.c (elf_find_and_remove_property): Add a
	bfd_boolean argument to indicate if the property should be
	removed.
	(elf_merge_gnu_property_list): Updated.  Report
	property change in linker map file.
	(elf_get_gnu_property_section_size): Skip property_remove
	properties.
	(elf_write_gnu_properties): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Report property merge
	in linker map file.  Pass abfd to elf_merge_gnu_property_list.

include/

	* bfdlink.h (bfd_link_info): Add has_map_file.

ld/

	* NEWS: Updated for property change report.
	* ld.texi: Document property change report.
	* ldmain.c (main): Set link_info.has_map_file to TRUE when
	linker map file is used.
	* testsuite/ld-scripts/rgn-over1.d: Updated.
	* testsuite/ld-scripts/rgn-over2.d: Likewise.
	* testsuite/ld-scripts/rgn-over3.d: Likewise.
	* testsuite/ld-scripts/rgn-over4.d: Likewise.
	* testsuite/ld-scripts/rgn-over5.d: Likewise.
	* testsuite/ld-scripts/rgn-over6.d: Likewise.
	* testsuite/ld-scripts/rgn-over7.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Check linker map
	file.
	* testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a.map: New file.
2018-12-07 08:30:43 -08:00
Alan Modra c2f5dc30af PR23952, memory leak in _bfd_generic_read_minisymbols
bfd/
	PR 23952
	* syms.c (_bfd_generic_read_minisymbols): Free syms before
	returning with zero symcount.
binutils/
	* nm.c (display_rel_file): Use xrealloc to increase minisyms
	for synthetic symbols.
2018-12-08 00:11:16 +10:30
Alan Modra bb6bf75e7a PowerPC @l, @h and @ha warnings, plus VLE e_li
This patch started off just adding the warnings in tc-ppc.c about
incorrect usage of @l, @h and @ha in instructions that don't have
16-bit D-form fields.  That unfortunately showed up three warnings in
ld/testsuite/ld-powerpc/vle-multiseg.s on instructions like
	e_li r3, IV_table@l+0x00
which was being assembled to
   8:	70 60 00 00 	e_li    r3,0
			a: R_PPC_ADDR16_LO	IV_table
The ADDR16_LO reloc is of course completely bogus on e_li, which has
a split 20-bit signed integer field in bits 0x1f7fff, the low 11 bit
in 0x7ff, the next 5 bits in 0x1f0000, and the high 4 bits in 0x7800.
Applying an ADDR16_LO reloc to the instruction potentially changes
the e_li instruction to e_add2i., e_add2is, e_cmp16i, e_mull2i,
e_cmpl16i, e_cmph16i, e_cmphl16i, e_or2i, e_and2i., e_or2is, e_lis,
e_and2is, or some invalid encodings.

Now there is a relocation that suits e_li, R_PPC_VLE_ADDR20, which was
added 2017-09-05 but I can't see code in gas to generate the
relocation.  In any case, VLE_ADDR20 probably doesn't have the correct
semantics for @l since ideally you'd want an @l to pair with @h or @ha
to generate a 32-bit constant.  Thus @l should only produce a 16-bit
value, I think.  So we need some more relocations to handle e_li it
seems, or as I do in this patch, modify the behaviour of existing
relocations when applied to e_li instructions.

include/
	* opcode/ppc.h (E_OPCODE_MASK, E_LI_MASK, E_LI_INSN): Define.
bfd/
	* elf32-ppc.c (ppc_elf_howto_raw <R_PPC_VLE_ADDR20>): Correct
	mask and shift value.
	(ppc_elf_vle_split16): Use E_OPCODE_MASK.  Handle e_li
	specially.
gas/
	* config/tc-ppc.c (md_assemble): Adjust relocs for VLE before
	TLS tweaks.  Handle e_li.  Warn on unexpected operand field
	for lo16/hi16/ha16 relocs.
2018-12-06 23:01:03 +10:30
Sam Tebbs 3a67e1a6b4 [aarch64] Add support for pointer authentication B key
Armv8.3-A has another key used in pointer authentication called the
B-key (other than the A-key that is already supported). In order for
stack unwinders to work it is necessary to be able to identify frames
that have been signed with the B-key rather than the A-key and it was
felt that keeping this as an augmentation character in the CIE was the
best bet. The DWARF extensions for ARM therefore propose to add a new
augmentation character 'B' to the CIE augmentation string and the
corresponding cfi directive ".cfi_b_key_frame". I've made the relevant
changes to GAS and LD to add support for B-key unwinding, which required
modifying LD to check for 'B' in the augmentation string, adding the
".cfi_b_key_frame" directive to GAS and adding a "pauth_key" field to
GAS's fde_entry and cie_entry structs.

The pointer authentication instructions will behave as NOPs on
architectures that don't support them, and so a check for the
architecture being assembled for is not necessary since there will be no
behavioural difference between augmentation strings with and without the
'B' character on such architectures.

2018-12-05  Sam Tebbs  <sam.tebbs@arm.com>

bfd/
	* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Add check for 'B'.

gas/
	* dw2gencfi.c (struct cie_entry): Add tc_cie_entry_extras invocation.
	(alloc_fde_entry): Add tc_fde_entry_init_extra invocation.
	(output_cie): Add tc_output_cie_extra invocation.
	(select_cie_for_fde): Add tc_cie_fde_equivalent_extra and
	tc_cie_entry_init_extra invocation.
	(frch_cfi_data, cfa_save_data): Move to dwgencfi.h.
	* config/tc-aarch64.c (s_aarch64_cfi_b_key_frame): Declare.
	(md_pseudo_table): Add "cfi_b_key_frame".
	* config/tc-aarch64.h (tc_fde_entry_extras, tc_cie_entry_extras,
	tc_fde_entry_init_extra, tc_output_cie_extra,
	tc_cie_fde_equivalent_extra, tc_cie_entry_init_extra): Define.
	* dw2gencfi.h (struct fde_entry): Add tc_fde_entry_extras invocation.
	(pointer_auth_key): Define.
	(frch_cfi_data, cfa_save_data): Move from dwgencfi.c.
	* doc/c-aarch64.texi (.cfi_b_key_frame): Add documentation.
	* testsuite/gas/aarch64/(pac_ab_key.d, pac_ab_key.s): New file.
2018-12-05 18:30:08 +00:00
H.J. Lu fde51dd189 x86: Don't remove empty GNU_PROPERTY_X86_UINT32_OR_AND properties
For GNU_PROPERTY_X86_COMPAT_ISA_1_USED and GNU_PROPERTY_X86_UINT32_OR_AND
properties, a bit in the output pr_data field is set if it is set in any
relocatable input pr_data fields and this property is present in all
relocatable input files.  A missing property implies that its bits have
unknown values.  When all bits in the the output pr_data field are zero,
this property should not be removed from output to indicate it has zero
in all bits.

bfd/

	PR ld/23372
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Don't remove
	empty properties for GNU_PROPERTY_X86_COMPAT_ISA_1_USED and
	GNU_PROPERTY_X86_UINT32_OR_AND.
	(_bfd_x86_elf_link_fixup_gnu_properties): Likewise.

ld/

	PR ld/23372
	* testsuite/ld-i386/pr23372a.d: Updated.
	* testsuite/ld-i386/pr23372c.d: Likewise.
	* testsuite/ld-x86-64/pr23372a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372a.d: Likewise.
	* testsuite/ld-x86-64/pr23372c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372c.d: Likewise.
2018-12-04 06:01:14 -08:00
Jim Wilson 1080bf78c0 RISC-V: Accept version, supervisor ext and more than one NSE for -march.
This patch moves all -march parsing logic into bfd, because we will use this
code in ELF attributes.

	bfd/
	* elfxx-riscv.h (RISCV_DONT_CARE_VERSION): New macro.
	(struct riscv_subset_t): New structure.
	(riscv_subset_t): New typedef.
	(riscv_subset_list_t): New structure.
	(riscv_release_subset_list): New prototype.
	(riscv_add_subset): Likewise.
	(riscv_lookup_subset): Likewise.
	(riscv_lookup_subset_version): Likewise.
	(riscv_release_subset_list): Likewise.
	* elfxx-riscv.c: Include safe-ctype.h.
	(riscv_parsing_subset_version): New function.
	(riscv_supported_std_ext): Likewise.
	(riscv_parse_std_ext): Likewise.
	(riscv_parse_sv_or_non_std_ext): Likewise.
	(riscv_parse_subset): Likewise.
	(riscv_add_subset): Likewise.
	(riscv_lookup_subset): Likewise.
	(riscv_lookup_subset_version): Likewise.
	(riscv_release_subset_list): Likewise.
	gas/
	* config/tc-riscv.c: Include elfxx-riscv.h.
	(struct riscv_subset): Removed.
	(riscv_subsets): Change type to riscv_subset_list_t.
	(riscv_subset_supports): Removed argument: xlen_required and move
	logic into libbfd.
	(riscv_multi_subset_supports): Removed argument: xlen_required.
	(riscv_clear_subsets): Removed.
	(riscv_add_subset): Ditto.
	(riscv_set_arch): Extract parsing logic into libbfd.
	(riscv_ip): Update argument for riscv_multi_subset_supports and
	riscv_subset_supports. Update riscv_subsets due to struct definition
	changed.
	(riscv_after_parse_args): Update riscv_subsets due to struct
	definition changed, update and argument for riscv_subset_supports.
	* testsuite/gas/riscv/empty.s: New.
	* testsuite/gas/riscv/march-fail-rv32ef.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32ef.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32i.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32i.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iam.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iam.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32ic.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32ic.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32icx2p.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32icx2p.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32imc.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32imc.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv64I.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv64I.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv64e.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv64e.l: Likewise.
	* testsuite/gas/riscv/march-ok-g2.d: Likewise.
	* testsuite/gas/riscv/march-ok-g2p0.d: Likewise.
	* testsuite/gas/riscv/march-ok-i2p0.d: Likewise.
	* testsuite/gas/riscv/march-ok-nse-with-version.: Likewise.d
	* testsuite/gas/riscv/march-ok-s-with-version.d: Likewise.
	* testsuite/gas/riscv/march-ok-s.d: Likewise.
	* testsuite/gas/riscv/march-ok-sx.d: Likewise.
	* testsuite/gas/riscv/march-ok-two-nse.d: Likewise.
	* testsuite/gas/riscv/march-ok-g2_p1.d: Likewise.
	* testsuite/gas/riscv/march-ok-i2p0m2_a2f2.d: Likewise.
	include/
	* opcode/riscv.h (riscv_opcode): Change type of xlen_requirement to
	unsigned.
	opcodes/
	* riscv-opc.c: Change the type of xlen, because type of
	xlen_requirement changed.
2018-12-03 14:05:17 -08:00
H.J. Lu b44ee3a8cf x86: Delay setting the iplt section alignment
Delay setting its alignment until we know it is non-empty.  Otherwise an
empty iplt section may change vma and lma of the following sections, which
triggers moving dot of the following section backwards, resulting in a
warning and section lma not being set properly.  It later leads to a
"File truncated" error.

bfd/

	PR ld/23930
	* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Update
	the iplt section alignment if it is non-empty.
	(_bfd_x86_elf_link_setup_gnu_properties): Set plt.iplt_alignment
	and delay setting the iplt section alignment.
	* elfxx-x86.h (elf_x86_plt_layout): Add iplt_alignment.

ld/

	PR ld/23930
	* testsuite/ld-i386/i386.exp: Run pr23930.
	* testsuite/ld-i386/pr23930.d: New file.
	* testsuite/ld-x86-64/pr23930-32.t: Likewise.
	* testsuite/ld-x86-64/pr23930-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23930.d: Likewise.
	* testsuite/ld-x86-64/pr23930.t: Likewise.
	* testsuite/ld-x86-64/pr23930a.s: Likewise.
	* testsuite/ld-x86-64/pr23930b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr23930 and pr23930-x32.
2018-12-01 06:35:03 -08:00
Nick Clifton 20a7119479 Add PR number to previous delta to the bfd/ directory. 2018-11-30 17:45:07 +00:00
Nick Clifton 5f60af5d24 Fix a memory exhaustion bug when attempting to allocate room for an impossible number of program headers.
* elfcode.h (elf_object_p): Check for corrupt input files with
	more program headers than can actually fit in the file.
2018-11-30 11:45:33 +00:00
Nick Clifton beab453223 Remove an abort in the bfd library and add a check for an integer overflow when mapping sections to segments.
PR 23932
	* elf.c (IS_CONTAINED_BY_LMA): Add a check for a negative section
	size.
	(rewrite_elf_program_header): If no sections are mapped into a
	segment return an error.
2018-11-30 11:43:12 +00:00
Alan Modra ba85c15dab PR23937, powerpc64le local ifunc IRELATIVE relocs are wrong
IFUNC resolvers must always be called via their global entry point.
They will be called from ld.so rather than from the local executable.

	PR 23937
bfd/
	* elf64-ppc.c (write_plt_relocs_for_local_syms): Don't add local
	entry offset for ifuncs.
ld/
	* testsuite/ld-powerpc/pr23937.d,
	* testsuite/ld-powerpc/pr23937.s: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.
2018-11-30 16:18:58 +10:30
H.J. Lu ffd9e4d022 elf: Don't merge .note.gnu.property section in IR
.note.gnu.property section in IR inputs should be ignored.  Don't
merge them.

	PR ld/23929
	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Don't
	merge .note.gnu.property section in IR inputs.
2018-11-29 04:45:16 -08:00
Thomas Preud'homme b5ab31636d [ARM] Update knowledge of bfd architectures
Commit c0c468d562 updated bfd's knowledge
of Arm architectures to Armv5TEJ and later but missed the list of CPUs
recognized by objdump -d -m<cpu>.

.note.gnu.arm.ident related code is intentionally not updated as build
attributes are a better mechanism to express the ISA in a file. However
this patch adds tests for the existing code since no existing testcase
cover those codepaths. Since I've only ever managed for
bfd_arm_get_mach_from_notes () to have an effect by using objcopy on
a file with a note but no Arm build attribute, the tests make use of
both objcopy actions supported by run_dump_test which requires to have a
ld line as well.

Note that the CPU list in bfd/cpu-arm.c was simply copied over from
GAS' CPU list but sorted alphabetically as already done for existing
entries.

2018-11-27  Thomas Preud'homme  <thomas.preudhomme@linaro.org>

bfd/
	* cpu-arm.c (processors): Add processors known to GAS but missing here
	and reindent.
	(bfd_arm_update_notes): Add comment explaining why the list of
	architectures in the switch should not be updated.
	(architectures): Likewise.

gas/
	* testsuite/gas/arm/cpu-arm1020.d: New testcase.
	* testsuite/gas/arm/cpu-arm1020e.d: Likewise.
	* testsuite/gas/arm/cpu-arm1020t.d: Likewise.
	* testsuite/gas/arm/cpu-arm1022e.d: Likewise.
	* testsuite/gas/arm/cpu-arm1026ej-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm1026ejs.d: Likewise.
	* testsuite/gas/arm/cpu-arm10e.d: Likewise.
	* testsuite/gas/arm/cpu-arm10t.d: Likewise.
	* testsuite/gas/arm/cpu-arm10tdmi.d: Likewise.
	* testsuite/gas/arm/cpu-arm1136j-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm1136jf-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm1136jfs.d: Likewise.
	* testsuite/gas/arm/cpu-arm1136js.d: Likewise.
	* testsuite/gas/arm/cpu-arm1156t2-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm1156t2f-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm1176jz-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm1176jzf-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm2.d: Likewise.
	* testsuite/gas/arm/cpu-arm250.d: Likewise.
	* testsuite/gas/arm/cpu-arm3.d: Likewise.
	* testsuite/gas/arm/cpu-arm6.d: Likewise.
	* testsuite/gas/arm/cpu-arm60.d: Likewise.
	* testsuite/gas/arm/cpu-arm600.d: Likewise.
	* testsuite/gas/arm/cpu-arm610.d: Likewise.
	* testsuite/gas/arm/cpu-arm620.d: Likewise.
	* testsuite/gas/arm/cpu-arm7.d: Likewise.
	* testsuite/gas/arm/cpu-arm70.d: Likewise.
	* testsuite/gas/arm/cpu-arm700.d: Likewise.
	* testsuite/gas/arm/cpu-arm700i.d: Likewise.
	* testsuite/gas/arm/cpu-arm710.d: Likewise.
	* testsuite/gas/arm/cpu-arm7100.d: Likewise.
	* testsuite/gas/arm/cpu-arm710c.d: Likewise.
	* testsuite/gas/arm/cpu-arm710t.d: Likewise.
	* testsuite/gas/arm/cpu-arm720.d: Likewise.
	* testsuite/gas/arm/cpu-arm720t.d: Likewise.
	* testsuite/gas/arm/cpu-arm740t.d: Likewise.
	* testsuite/gas/arm/cpu-arm7500.d: Likewise.
	* testsuite/gas/arm/cpu-arm7500fe.d: Likewise.
	* testsuite/gas/arm/cpu-arm7d.d: Likewise.
	* testsuite/gas/arm/cpu-arm7di.d: Likewise.
	* testsuite/gas/arm/cpu-arm7dm.d: Likewise.
	* testsuite/gas/arm/cpu-arm7dmi.d: Likewise.
	* testsuite/gas/arm/cpu-arm7m.d: Likewise.
	* testsuite/gas/arm/cpu-arm7t.d: Likewise.
	* testsuite/gas/arm/cpu-arm7tdmi-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm7tdmi.d: Likewise.
	* testsuite/gas/arm/cpu-arm8.d: Likewise.
	* testsuite/gas/arm/cpu-arm810.d: Likewise.
	* testsuite/gas/arm/cpu-arm9.d: Likewise.
	* testsuite/gas/arm/cpu-arm920.d: Likewise.
	* testsuite/gas/arm/cpu-arm920t.d: Likewise.
	* testsuite/gas/arm/cpu-arm922t.d: Likewise.
	* testsuite/gas/arm/cpu-arm926ej-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm926ej.d: Likewise.
	* testsuite/gas/arm/cpu-arm926ejs.d: Likewise.
	* testsuite/gas/arm/cpu-arm940t.d: Likewise.
	* testsuite/gas/arm/cpu-arm946e-r0.d: Likewise.
	* testsuite/gas/arm/cpu-arm946e-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm946e.d: Likewise.
	* testsuite/gas/arm/cpu-arm966e-r0.d: Likewise.
	* testsuite/gas/arm/cpu-arm966e-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm966e.d: Likewise.
	* testsuite/gas/arm/cpu-arm968e-s.d: Likewise.
	* testsuite/gas/arm/cpu-arm9e-r0.d: Likewise.
	* testsuite/gas/arm/cpu-arm9e.d: Likewise.
	* testsuite/gas/arm/cpu-arm9tdmi.d: Likewise.
	* testsuite/gas/arm/cpu-arm_any.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a12.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a15.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a17.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a32.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a35.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a5.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a53.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a55.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a57.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a7.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a72.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a73.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a75.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a76.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a8.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-a9.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m0.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m0plus.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m1.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m23.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m3.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m33.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m4.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-m7.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-r4.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-r4f.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-r5.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-r52.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-r7.d: Likewise.
	* testsuite/gas/arm/cpu-cortex-r8.d: Likewise.
	* testsuite/gas/arm/cpu-ep9312.d: Likewise.
	* testsuite/gas/arm/cpu-exynos-m1.d: Likewise.
	* testsuite/gas/arm/cpu-fa526.d: Likewise.
	* testsuite/gas/arm/cpu-fa606te.d: Likewise.
	* testsuite/gas/arm/cpu-fa616te.d: Likewise.
	* testsuite/gas/arm/cpu-fa626.d: Likewise.
	* testsuite/gas/arm/cpu-fa626te.d: Likewise.
	* testsuite/gas/arm/cpu-fa726te.d: Likewise.
	* testsuite/gas/arm/cpu-fmp626.d: Likewise.
	* testsuite/gas/arm/cpu-i80200.d: Likewise.
	* testsuite/gas/arm/cpu-iwmmxt.d: Likewise.
	* testsuite/gas/arm/cpu-iwmmxt2.d: Likewise.
	* testsuite/gas/arm/cpu-marvell-pj4.d: Likewise.
	* testsuite/gas/arm/cpu-marvell-whitney.d: Likewise.
	* testsuite/gas/arm/cpu-mpcore.d: Likewise.
	* testsuite/gas/arm/cpu-mpcorenovfp.d: Likewise.
	* testsuite/gas/arm/cpu-sa1.d: Likewise.
	* testsuite/gas/arm/cpu-strongarm.d: Likewise.
	* testsuite/gas/arm/cpu-strongarm1.d: Likewise.
	* testsuite/gas/arm/cpu-strongarm110.d: Likewise.
	* testsuite/gas/arm/cpu-strongarm1100.d: Likewise.
	* testsuite/gas/arm/cpu-strongarm1110.d: Likewise.
	* testsuite/gas/arm/cpu-xgene1.d: Likewise.
	* testsuite/gas/arm/cpu-xgene2.d: Likewise.
	* testsuite/gas/arm/cpu-xscale.d: Likewise.
	* testsuite/gas/arm/nop-asm.s: Likewise.
	* testsuite/gas/arm/note-march-armv2.d: Likewise.
	* testsuite/gas/arm/note-march-armv2.s: Likewise.
	* testsuite/gas/arm/note-march-armv2a.d: Likewise.
	* testsuite/gas/arm/note-march-armv2a.s: Likewise.
	* testsuite/gas/arm/note-march-armv3.d: Likewise.
	* testsuite/gas/arm/note-march-armv3.s: Likewise.
	* testsuite/gas/arm/note-march-armv3m.d: Likewise.
	* testsuite/gas/arm/note-march-armv3m.s: Likewise.
	* testsuite/gas/arm/note-march-armv4.d: Likewise.
	* testsuite/gas/arm/note-march-armv4.s: Likewise.
	* testsuite/gas/arm/note-march-armv4t.d: Likewise.
	* testsuite/gas/arm/note-march-armv4t.s: Likewise.
	* testsuite/gas/arm/note-march-armv5.d: Likewise.
	* testsuite/gas/arm/note-march-armv5.s: Likewise.
	* testsuite/gas/arm/note-march-armv5t.d: Likewise.
	* testsuite/gas/arm/note-march-armv5t.s: Likewise.
	* testsuite/gas/arm/note-march-armv5te.d: Likewise.
	* testsuite/gas/arm/note-march-armv5te.d: Likewise.
	* testsuite/gas/arm/note-march-ep9312.d: Likewise.
	* testsuite/gas/arm/note-march-ep9312.s: Likewise.
	* testsuite/gas/arm/note-march-iwmmxt.d: Likewise.
	* testsuite/gas/arm/note-march-iwmmxt.s: Likewise.
	* testsuite/gas/arm/note-march-iwmmxt2.d: Likewise.
	* testsuite/gas/arm/note-march-iwmmxt2.s: Likewise.
	* testsuite/gas/arm/note-march-xscale.d: Likewise.
	* testsuite/gas/arm/note-march-xscale.s: Likewise.
2018-11-27 18:28:35 +00:00
Maciej W. Rozycki 3c7687b9cd MIPS/LD: Accept high-part relocations in PIC code with absolute symbols
Accept R_MIPS_HI16, R_MIPS_HIGHER and R_MIPS_HIGHEST relocations and
their compressed counterparts in PIC code where the symbol referred is
absolute.  Such an operation is meaningful, because an absolute symbol
effectively is a constant the calculation of the value of which has been
deferred to the static link time, and which is not going to change any
further at the dynamic load time.  Therefore there is no need ever to
refuse the use of these relocations with such symbols, as the resulting
run-time value observed by the program will be correct even in PIC code.

This is not the case with R_MIPS_26 and its compressed counterparts,
because the run-time value calculated by the instructions these
relocations are used with depends on the address of the instruction
itself, and that can change according to the base address used by the
dynamic loader.  Therefore these relocations have to continue being
rejected in PIC code even with absolute symbols.

This allows successful linking of code that relies on previous linker
behavior up to commit 861fb55ab5 ("Defer allocation of R_MIPS_REL32
GOT slots"), <https://sourceware.org/ml/binutils/2008-08/msg00096.html>,
which introduced the problematic check missing this special exception
for absolute symbols.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_check_relocs) <R_MIPS16_HI16>
	<R_MIPS_HI16, R_MIPS_HIGHER, R_MIPS_HIGHEST, R_MICROMIPS_HI16>
	<R_MICROMIPS_HIGHER, R_MICROMIPS_HIGHEST>: Also accept an
	absolute symbol in PIC code.

	ld/
	* testsuite/ld-mips-elf/pic-reloc-0.d: New test.
	* testsuite/ld-mips-elf/pic-reloc-1.d: New test.
	* testsuite/ld-mips-elf/pic-reloc-2.d: New test.
	* testsuite/ld-mips-elf/pic-reloc-3.d: New test.
	* testsuite/ld-mips-elf/pic-reloc-4.d: New test.
	* testsuite/ld-mips-elf/pic-reloc-absolute-hi.ld: New test
	linker script.
	* testsuite/ld-mips-elf/pic-reloc-absolute-lo.ld: New test
	linker script.
	* testsuite/ld-mips-elf/pic-reloc-ordinary.ld: New test linker
	script.
	* testsuite/ld-mips-elf/pic-reloc-j.s: New test source.
	* testsuite/ld-mips-elf/pic-reloc-lui.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2018-11-27 16:34:03 +00:00
Maciej W. Rozycki aff68bd041 MIPS/LD: Continue processing with refused relocations in PIC code
Switch from `_bfd_error_handler' to `info->callbacks->einfo' with error
reporting concerning the use of position-dependent relocations such as
R_MIPS_HI16 or R_MIPS_26 in PIC code and continue processing so that any
subsequent link errors are also shown rather than the linker terminating
right away.  This can reduce user frustration where correcting one error
only reveals another one; instead all are shown together making them all
possible to investigate at once.  The use of the `%X' specifier causes
the linker to terminate unsuccessfully at the end of processing.

Also fix the message to say `cannot' rather than `can not'.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_check_relocs) <R_MIPS16_26>
	<R_MIPS_26, R_MICROMIPS_26_S1>: Use `info->callbacks->einfo'
	rather than `_bfd_error_handler' to report refused relocations
	in PIC code and continue processing.  Fix error message: `can
	not' -> `cannot'.
2018-11-27 16:34:03 +00:00
H.J. Lu 131a5a648d Initialize *uncompressed_align_pow_p to 0
Initialize *uncompressed_align_pow_p to 0 since *uncompressed_align_pow_p
is passed to bfd_is_section_compressed_with_header as uninitialized,

	PR binutils/23919
	* compress.c (bfd_is_section_compressed_with_header): Initialize
	*uncompressed_align_pow_p to 0.
2018-11-27 06:02:36 -08:00
Tamar Christina 9fca35fc34 AArch64: Fix regression in Cortex A53 erratum when PIE. (PR ld/23904)
The fix for PR ld/22263 causes TLS relocations using ADRP to be relaxed
into MOVZ, however this causes issues for the erratum code.

The erratum code scans the input sections looking for ADRP instructions
and notes their location in the stream.

It then later tries to find them again in order to generate the linker
stubs.  Due to the relaxation it instead finds a MOVZ and hard aborts.

Since this relaxation is a valid one, and in which case the erratum no
longer applies, it shouldn't abort but instead just continue.

This changes the TLS relaxation code such that when it finds an ADRP and
it relaxes it, it removes the erratum entry from the work list by changing
the stub type into none so the stub is ignored.

The entry is not actually removed as removal is a more expensive operation
and we have already allocated the memory anyway.

The clearing is done for IE->LE and GD->LE relaxations, and a testcase is
added for the IE case. The GD case I believe to be impossible to get together
with the erratum sequence due to the required BL which would break the sequence.
However to cover all basis I have added the guard there as well.

build on native hardware and regtested on
  aarch64-none-elf, aarch64-none-elf (32 bit host),
  aarch64-none-linux-gnu, aarch64-none-linux-gnu (32 bit host)

Cross-compiled and regtested on
  aarch64-none-linux-gnu, aarch64_be-none-linux-gnu

Testcase in PR23940 tested and works as expected now and benchmarks ran on A53
showing no regressions and no issues.

bfd/ChangeLog:

	PR ld/23904
	* elfnn-aarch64.c (_bfd_aarch64_adrp_p): Use existing constants.
	(_bfd_aarch64_erratum_843419_branch_to_stub): Use _bfd_aarch64_adrp_p.
	(struct erratum_835769_branch_to_stub_clear_data): New.
	(_bfd_aarch64_erratum_843419_clear_stub): New.
	(clear_erratum_843419_entry): New.
	(elfNN_aarch64_tls_relax): Use it.
	(elfNN_aarch64_relocate_section): Pass input_section.
	(aarch64_map_one_stub): Handle branch type none as valid.

ld/ChangeLog:

	PR ld/23904
	* testsuite/ld-aarch64/aarch64-elf.exp: Add erratum843419_tls_ie.
	* testsuite/ld-aarch64/erratum843419_tls_ie.d: New test.
	* testsuite/ld-aarch64/erratum843419_tls_ie.s: New test.
2018-11-27 12:42:22 +00:00
Mark Wielaard 4207142d6a Handle ELF compressed header alignment correctly by setting up the section alignment correctly for the Elf32_Chdr or Elf64_Chdr type and respect the ch_addralign field when decompressing the section data.
PR binutils/23919
binutils* readelf.c (dump_sections_as_strings): Remove bogus addralign check.
	(dump_sections_as_bytes): Likewise.
	(load_specific_debug_sections): Likewise.
	* testsuite/binutils-all/dw2-3.rS: Adjust alignment.
	* testsuite/binutils-all/dw2-3.rt: Likewise.

bfd	* bfd.c (bfd_update_compression_header): Explicitly set alignment.
	(bfd_check_compression_header): Add uncompressed_alignment_power
	argument. Check ch_addralign is a power of 2.
	* bfd-in2.h: Regenerated.
	* compress.c (bfd_compress_section_contents): Get and set
	orig_uncompressed_alignment_pow if section is decompressed.
	(bfd_is_section_compressed_with_header): Add and get
	uncompressed_align_pow_p argument.
	(bfd_is_section_compressed): Add uncompressed_align_power argument
	to bfd_is_section_compressed_with_header call.
	(bfd_init_section_decompress_status): Get and set
	uncompressed_alignment_power.
	* elf.c (_bfd_elf_make_section_from_shdr): Add
	uncompressed_align_power argument to
	bfd_is_section_compressed_with_header call.
2018-11-27 11:59:10 +00:00
Jozef Lawrynowicz ca94519e70 Fix linking MSP430 files created by gcc's LTO optimizer.
When invoking GCC with "-g -flto", the compiler will create LTO objects
with debug information. The objects created are "simple ELF" objects (see
libiberty/simple-object-elf.c) and do not have target-specific sections.

When the MSP430 linker sees one of these objects without a .MSP430.attributes
section it errors:

> error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses MSP430X instructions but /tmp/ccynqIwudebugobj uses unknown
> error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses the small code model whereas /tmp/ccynqIwudebugobj uses the unknown code model
> error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses the small data model whereas /tmp/ccynqIwudebugobj uses the unknown data model
> error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses the small code model but /tmp/ccynqIwudebugobj uses the unknown data model
> failed to merge target specific data of file /tmp/cc4LhbEI.ltrans0.ltrans.o

The following patch allows these debug LTO objects to be linked with other
MSP430 objects even if they do not have a .MSP430.attributes section.

bfd	* elf32-msp430.c (elf32_msp430_merge_mspabi_attributes): Do not
	error when .MSP430.attributes section is missing from objects
	created by LTO.
2018-11-21 16:21:25 +00:00
Jim Wilson 0242af4010 RISC-V: Improve linker error for FP mismatch.
bfd/
	* elfnn-riscv.c (riscv_float_abi_string): New.
	(_bfd_riscv_elf_merge_private_bfd_data): Use it for error message.
2018-11-13 15:56:29 -08:00
Bernhard M. Wiedemann dfbfec241a Correct comment concerning PE timestamp insertion.
* peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Correct comment
	concerning timestamp insertion.
2018-11-09 16:06:48 +00:00
Cupertino Miranda 20b233dc48 Fixed warning from previous patch. Added Changelog. 2018-11-09 15:53:30 +00:00
rhn d2eb0fb5a0 Stop corruption of ihex output shen addresses are sign extended.
PR 23699
	* ihex.c (ihex_write_object_contents): Check for sign extended
	addresses that cannot be supported in the ihex format.
2018-11-09 14:09:44 +00:00
Claudiu Zissulescu 0f2064107b [ARC] Fix local got entry list.
Fix a memory leak appearing when the local got entry list was constructed.

bfd/
xxxx-xx-xx  Claudiu Zissulescu  <claziss@synopsys.com>

	* arc-got.h (arc_get_local_got_ents): Revamp it; use
	elf_local_got_ents to store the local got list.
	(get_got_entry_list_for_symbo): Restructure it.
	* elf32-arc.c (elf_arc_relocate_section): Correct the call to
	get_got_entry_list_for_symbol.
2018-11-09 13:20:27 +02:00
Nick Clifton 0661ae2e53 Add updated French and Portuguese translations.
gas	* po/fr.po: Updated French translation.
bfd	* po/fr.po: Updated French translation.
	* po/pt.po: Updated Portuguese translation.
binutils* po/pt.po: Updated Portuguese translation.
2018-11-07 16:09:27 +00:00
Roman Bolshakov fc7b364aba Add support for new load commands added by Apple to the MACH-O file format.
bfd	* mach-o.h: Add new enums for BFD_MACH_O_PLATFORM_MACOS,
	BFD_MACH_O_PLATFORM_IOS, BFD_MACH_O_PLATFORM_TVOS,
	BFD_MACH_O_PLATFORM_WATCHOS, BFD_MACH_O_PLATFORM_BRIDGEOS,
	BFD_MACH_O_TOOL_CLANG, BFD_MACH_O_TOOL_SWIFT, BFD_MACH_O_TOOL_LD.
	(struct bfd_mach_o_note_command): New.
	(struct bfd_mach_o_build_version_tool): New.
	(struct bfd_mach_o_build_version_command): New.
	(bfd_mach_o_read_version_min): Don't split version into
	a few fields. Rename reserved to sdk.
	* mach-o.c (bfd_mach_o_read_version_min): Don't split version into a
	few fields. Rename reserved to sdk.
	(bfd_mach_o_read_command): Handle LC_VERSION_MIN_TVOS, LC_NOTE,
	LC_BUILD_VERSION.
	(bfd_mach_o_read_note): New.
	(bfd_mach_o_read_build_version): New.

	PR 23728
binutils* od-macho.c (printf_version): New.
	(dump_load_command): Use it to print version. Print sdk version. Print
	version info for watchOS and tvOS. Print LC_NOTE, LC_BUILD_VERSION.
	(dump_buld_version): New.
	(bfd_mach_o_platform_name): New
	(bfd_mach_o_tool_name): New

	* mach-o/external.h (mach_o_nversion_min_command_external): Rename
	reserved to sdk.
	(mach_o_note_command_external): New.
	(mach_o_build_version_command_external): New.
	* mach-o/loader.h (BFD_MACH_O_LC_VERSION_MIN_TVOS): Define.
	(BFD_MACH_O_LC_NOTE): Define.
2018-11-07 15:20:22 +00:00
Alan Modra 42d4c301c4 Regen bfd/configure
* configure: Regenerate.
2018-11-07 21:55:06 +10:30
Yoshinori Sato 8d3c78e473 rx: Add target rx-*-linux. 2018-11-07 17:18:05 +09:00
Nick Clifton ddea148b3d Add support for a couple of new Mach-O commands.
PR 23742
	* mach-o.c (bfd_mach_o_read_command): Accept and ignore
	BFD_MACH_O_LC_LINKER_OPTIONS and BFD_MACH_O_LC_BUILD_VERSION
	commands.

	* mach-o/loader.h: Add BFD_MACH_O_LC_BUILD_VERSION.
2018-11-06 17:17:43 +00:00
Alan Modra a4bcd73371 PR23850, strip should not discard/move .rela.plt in executable
strip/objcopy can't deal with alloc reloc sections, not .rela.dyn or
.rela.plt in a dynamic executable, or .rela.plt/.rela.iplt in a static
executable.  So, don't have BFD treat them as side-channel data
associated with the section they are relocating.

	PR 23850
	* elf.c (bfd_section_from_shdr): Treat SHF_ALLOC SHT_REL* sections
	in an executable or shared library as normal sections.
2018-11-02 13:48:08 +10:30
Renlin Li f32a4a5939 Don't create got section while processing TLS Local Exec relocations.
For Local Exec TLS model, the offset of the variable from the thread pointer
can be computed at static link time. This doesn't require GOT indirection.

The initial change is a bad fix for a problem during TLS GD -> LE relaxation.
The proper fix is to check whether _GLOBAL_OFFSET_TABLE_ is referenced,
create got section if yes.  And the fix is already in the repository.

bfd/

2018-10-31  Renlin Li  <renlin.li@arm.com>

    * elfnn-aarch64.c (elfNN_aarch64_check_relocs): Don't create got
    section for Local Exec TLS model.
2018-10-31 15:09:36 +00:00
H.J. Lu 0a640d7196 ELF: Hide symbols defined in discarded input sections
When assigning symbol version, we should hide debug symbols defined in
discarded sections from IR objects so that they can be removed later.

bfd/

	PR ld/23818
	* elflink.c (_bfd_elf_link_assign_sym_version): Hide symbols
	defined in discarded input sections.

ld/

	PR ld/23818
	* testsuite/ld-plugin/lto.exp: Run PR ld/23818 test.
	* testsuite/ld-plugin/pr23818.d: New file.
	* testsuite/ld-plugin/pr23818.t: Likewise.
	* testsuite/ld-plugin/pr23818a.c: Likewise.
	* testsuite/ld-plugin/pr23818b.c: Likewise.
2018-10-24 18:08:24 -07:00
Alan Modra 8c246a60c0 cmse_scan segfault
elf_sym_hashes for as-needed libs will be zeroed if the library is
found to be not needed.  More than that, the local symbols for such a
library should not be considered by cmse_scan.

	* elf32-arm.c (elf32_arm_size_stubs): Ignore as-needed libs that
	were not needed.
2018-10-24 23:38:52 +10:30
Alan Modra 45a0eaf770 PR23806, NULL pointer dereference in merge_strings
PR 23806
	* merge.c (_bfd_add_merge_section): Don't attempt to merge
	sections with ridiculously large alignments.
2018-10-23 21:09:09 +10:30
Alan Modra 102def4da8 PR23805, NULL pointer dereference in elf_link_input_bfd
PR 23805
	* elflink.c (elf_link_input_bfd): Don't segfault on finding
	STT_TLS symbols without any TLS sections.  Instead, change the
	symbol type to STT_NOTYPE.
2018-10-23 21:09:09 +10:30
Alan Modra ab419ddbb2 PR23804, buffer overflow in sec_merge_hash_lookup
PR 23804
	* merge.c (_bfd_add_merge_section): Don't attempt to merge
	sections where size is not a multiple of entsize.
2018-10-23 21:09:09 +10:30
Alan Modra ac85e67c05 PR23788, objcopy: failed to find link section
Symbol tables can change when a number of objcopy options are used.
I figure string tables are similarly changeable.

	PR 23788
	* elf.c (section_match): Don't require a size match for SHT_SYMTAB
	or SHT_STRTAB.
2018-10-20 19:46:43 +10:30
Alan Modra 4de5434b69 PR23653, ld SIGSEGVs when attempts to link sparc object with x86_64 library
This patch improves dynobj selection.  This allows the testcase in the
PR to proceed further before segfaulting due to other bugs in the
sparc backend.

../ld/ld-new --eh-frame-hdr -m elf_x86_64 -shared -o bug.so.5 bug.o ./libc.so.6 ./crtendS.o
../ld/ld-new: sparc architecture of input file `bug.o' is incompatible with i386:x86-64 output
../ld/ld-new: bug.o: in function `a':
bug.c:(.text+0x4): undefined reference to `_GLOBAL_OFFSET_TABLE_'
../ld/ld-new: bug.c:(.text+0x8): undefined reference to `_GLOBAL_OFFSET_TABLE_'
Segmentation fault

	PR 23653
	* elflink.c (_bfd_elf_link_create_dynstrtab): Match elf_object_id
	too when choosing dynobj.
2018-10-17 14:36:18 +10:30
Alan Modra 48dcd4ea06 Simplify PR23110 PE_DEBUG_DATA size checks
The negative size check can be rolled into the "exceeds space left in
section" check if that is done using an unsigned comparison.  We know
that "addr - section->vma" is never larger than section->size since
the section is found by find_section_by_vma.

	* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Simplify
	PE_DEBUG_DATA size checks.
2018-10-16 16:41:57 +10:30
Alan Modra 8df73d5cc3 PR23781, _bfd_pe_bfd_copy_private_bfd_data_common memory leak
PR 23781
	* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Free data
	before returning.
2018-10-16 16:41:57 +10:30
Alan Modra 0e0dd7f1e8 Re: BFD_INIT_MAGIC
I should know better than to introduce the first use of size_t in
bfd.h.

	PR 23534
	* init.c (bfd_init): Return an unsigned int.
	bfd-in2.h: Regenerate.
2018-10-16 09:03:41 +10:30
Alan Modra bf2dd8d7cf BFD_INIT_MAGIC
This patch performs a run-time test that a shared libbfd.so has been
compiled with the same size bfd_vma as that of apps using the library.
On a 32-bit host it is easily possible to have one libbfd.so compiled
to support 64-bit targets (or configured with --enable-64-bit-bfd)
while another only supports 32-bit targets.  The two libraries will
have differently sized bfd_vma types, and if the wrong one is loaded
all sorts of weird behaviour might be seen.

bfd/
	PR 23534
	* init.c (BFD_INIT_MAGIC): Define.
	(bfd_init): Return BFD_INIT_MAGIC.
	bfd-in2.h: Regenerate.
binutils/
	PR 23534
	* addr2line.c (main): Exit with fatal error if bfd_init
	returns an unexpected value.
	* ar.c (main): Likewise.
	* dlltool.c (identify_dll_for_implib): Likewise.
	* nm.c (main): Likewise.
	* objcopy.c (main): Likewise.
	* objdump.c (main): Likewise.
	* size.c (main): Likewise.
	* strings.c (main): Likewise.
	* windmc.c (main): Likewise.
	* windres.c (main): Likewise.
gas/
	PR 23534
	* as.c (main): Exit with fatal error if bfd_init returns an
	unexpected value.
ld/
	PR 23534
	* ldmain.c (main): Exit with fatal error if bfd_init returns
	an unexpected value.
2018-10-15 22:11:58 +10:30
Alan Modra 0930cb3021 _bfd_clear_contents bounds checking
This PR shows a fuzzed binary triggering a segfault via a bad
relocation in .debug_line.  It turns out that unlike normal
relocations applied to a section, the linker applies those with
symbols from discarded sections via _bfd_clear_contents without
checking that the relocation is within the section bounds.  The same
thing now happens when reading debug sections since commit
a4cd947aca, the PR23425 fix.

	PR 23770
	PR 23425
	* reloc.c (_bfd_clear_contents): Replace "location" param with
	"buf" and "off".  Bounds check "off".  Return status.
	* cofflink.c (_bfd_coff_generic_relocate_section): Update
	_bfd_clear_contents call.
	* elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Likewise.
	* elf32-arc.c (elf_arc_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-metag.c (metag_final_link_relocate): Likewise.
	* elf32-nds32.c (nds32_elf_get_relocated_section_contents): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-visium.c (visium_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-x86-64.c *(elf_x86_64_relocate_section): Likewise.
	* libbfd-in.h (_bfd_clear_contents): Update prototype.
	* libbfd.h: Regenerate.
2018-10-13 23:54:33 +10:30
Egeyar Bagcioglu 1c2649ed74 Do not place symbols into a discarded .dynsym
Prevents getting an error about dynamic symbols in sections indexed
64K+ when .dynsym is discarded.

	* elflink.c (elf_link_output_extsym): Do not place symbols into a
	discarded .dynsym.
2018-10-09 17:36:59 +10:30
H.J. Lu 80f3ac5d61 x86: Don't add GNU_PROPERTY_X86_FEATURE_2_NEEDED for -z separate-code
With

commit 64029e9368
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Oct 5 11:40:54 2018 +0930

    Separate header PT_LOAD for -z separate-code

there is no need to add a GNU_PROPERTY_X86_ISA_1_USED note to force
program header in in non-code PT_LOAD segment when -z separate-code
is used.

bfd/

	PR ld/23428
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Don't
	add GNU_PROPERTY_X86_FEATURE_2_NEEDED to force program header
	in non-code PT_LOAD segment.

ld/

	PR ld/23428
	* testsuite/ld-i386/property-x86-4a.d: Updated.
	* testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
2018-10-08 05:14:13 -07:00
Alan Modra 64029e9368 Separate header PT_LOAD for -z separate-code
This patch, along with previous patches in the series, supports
putting the ELF file header and program headers in a PT_LOAD without
sections.

Logic governing whether headers a loaded has changed a little:  The
primary reason to include headers is now the presence of
SIZEOF_HEADERS in a linker script.  However, to support scripts that
may have reserved space for headers by hand, we continue to add
headers whenever the first section address is past the end of headers
modulo page size.

include/
	* bfdlink.h (struct bfd_link_info): Add load_phdrs field.
bfd/
	* elf-nacl.c (nacl_modify_segment_map): Cope with header PT_LOAD
	lacking sections.
	* elf.c (_bfd_elf_map_sections_to_segments): Assume file and
	program headers are required when info->load_phdrs.  Reorganize
	code handling program headers.  Generate a mapping without
	sections just for file and program headers when -z separate-code
	would indicate they should be on a different page to the first
	section.
ld/
	* ldexp.c (fold_name <SIZEOF_HEADERS>): Set link_info.load_phdrs.
	* testsuite/ld-elf/loadaddr1.d: Pass -z noseparate-code.
	* testsuite/ld-elf/loadaddr2.d: Likewise.
	* testsuite/ld-i386/vxworks2.sd: Adjust expected output.
	* testsuite/ld-powerpc/vxworks2.sd: Likewise.
	* testsuite/ld-elf/overlay.d: Remove spu xfail.
	* testsuite/ld-spu/ovl.lnk: Don't use SIZEOF_HEADERS.
	* testsuite/ld-tic6x/dsbt-be.ld: Likewise.
	* testsuite/ld-tic6x/dsbt-inrange.ld: Likewise.
	* testsuite/ld-tic6x/dsbt-overflow.ld: Likewise.
	* testsuite/ld-tic6x/dsbt.ld: Likewise.
2018-10-08 20:26:08 +10:30
Alan Modra 5d69562788 Use p_vaddr_offset to set p_vaddr on segments without sections
p_vaddr is currently set from the first section vma if a segment has
sections, and to zero if a segment has no sections.  This means we
lose p_vaddr when objcopy'ing executables if a segment without
sections has a non-zero p_vaddr.

This patch saves p_vaddr to p_vaddr_offset, and to make the use of
p_vaddr_offset consistent, inverts the sign.  (It's now added to
section vma to get segment vaddr, and added to zero when there are no
sections.)

	* elf.c (assign_file_positions_for_load_sections): Set p_vaddr
	from m->p_vaddr_offset for segments without sections.  Invert
	sign of p_vaddr_offset.
	(rewrite_elf_program_header, copy_elf_program_header): Save
	old segment p_vaddr to p_vaddr_offset.  Invert sign of
	p_vaddr_offset.
2018-10-08 20:26:08 +10:30
Alan Modra 1b9e270b09 No PT_INTERP when .interp is zero size
Some targets don't set a default interpreter, resulting in an empty
.interp section unless --dynamic-linker is passed to ld.  A PT_INTERP
without a path is rather useless.

The testsuite change fixes a failure on microblaze-linux.

bfd/
	* elf.c (get_program_header_size): Don't count PT_INTERP if
	.interp is empty.
	(_bfd_elf_map_sections_to_segments): Don't create PT_INTERP if
	.interp is empty.
ld/
	* testsuite/ld-elf/pr22423.d: Pass --dynamic-linker to ld.
2018-10-08 20:26:08 +10:30
Alan Modra e0c3dfa2ee SPU overlay headers
Overlay PT_LOAD headers are moved early for reasons explained by
comments in spu_elf_modify_segment_map.  This patch fixes cases that
shouldn't occur in sane SPU executables.

	* elf32-spu.c (spu_elf_modify_segment_map): Don't insert
	overlays before segment containing headers.
2018-10-08 20:26:08 +10:30
Alan Modra 00bee008e9 Tidy elf_segment_map allocation
This cleans up elf_segment_map allocation when the section array is
empty.  "amt += (to - from - 1) * sizeof (asection *)", when "to" and
"from" are unsigned int results in an unsigned value inside the
parentheses.  When "to" and "from" are equal on a 64-bit host,
0xffffffff * 8 is added to "amt", not -8 as desired.

The patch also renames a variable for consistency with other functions
using a similar index.

	* elf.c (make_mapping): Cope with zero size array at end of
	struct elf_segment_map.
	(_bfd_elf_map_sections_to_segments): Likewise.
	(rewrite_elf_program_header, copy_elf_program_header): Likewise.
	(_bfd_elf_map_sections_to_segments): Rename phdr_index to hdr_index.
2018-10-08 20:26:08 +10:30
Alan Modra d1c86cff1e Set correct SHT_NOTE type for .note.spu_name
* elf32-spu.c (spu_elf_create_sections): Make .note.spu_name
	SHT_NOTE.
2018-10-05 20:04:10 +09:30
Stafford Horne c8e98e3692 or1k: Add the l.adrp insn and supporting relocations
This patch adds the new instruction and relocation as per proposal:
   https://openrisc.io/proposals/ladrp

This is to be added to the spec in an upcoming revision.  The new instruction
l.adrp loads the page offset of the current instruction offset by
a 21-bit immediate shifted left 13-bits.  This is meant to be used with
a 13-bit lower bit page offset.  This allows us to free up the got
register r16.

  l.adrp  r3, foo
  l.ori   r4, r3, po(foo)
  l.lbz   r5, po(foo)(r3)
  l.sb    po(foo)(r3), r6

The relocations we add are:

 - BFD_RELOC_OR1K_PLTA26	For PLT jump relocation with PLT entry
   asm: plta()			implemented using l.ardp, meaning
				no need for r16 (the GOT reg)

 - BFD_RELOC_OR1K_GOT_PG21	Upper 21-bit Page offset got address
   asm: got()
 - BFD_RELOC_OR1K_TLS_GD_PG21	Upper 21-bit Page offset with TLS General
   asm: tlsgd()			Dynamic calculation
 - BFD_RELOC_OR1K_TLS_LDM_PG21	Upper 21-bit Page offset with TLS local
   asm: tlsldm()		dynamic calculation
 - BFD_RELOC_OR1K_TLS_IE_PG21	Upper 21-bit Page offset with TLS Initial
   asm: gottp() 		Executable calculation
 - BFD_RELOC_OR1K_PCREL_PG21	Default relocation for disp21 (l.adrp
				instructions)

 - BFD_RELOC_OR1K_LO13		low 13-bit page offset relocation
   asm: po()			i.e. mem loads, addi etc
 - BFD_RELOC_OR1K_SLO13		low 13-bit page offset relocation
   asm: po()			i.e. mem stores, with split immediate
 - BFD_RELOC_OR1K_GOT_LO13,	low 13-bit page offset with GOT calcs
   asm: gotpo()
 - BFD_RELOC_OR1K_TLS_GD_LO13	Lower 13-bit offset with TLS GD calcs
   asm: tlsgdpo()
 - BFD_RELOC_OR1K_TLS_LDM_LO13	Lower 13-bit offset with TLS LD calcs
   asm: tlsldmpo()
 - BFD_RELOC_OR1K_TLS_IE_LO13	Lower 13-bit offset with TLS IE calcs
   asm: gottppo()

bfd/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* bfd-in2.h: Regenerated.
	* elf32-or1k.c: (or1k_elf_howto_table): Fix formatting for
	R_OR1K_PLT26, Add R_OR1K_PCREL_PG21, R_OR1K_GOT_PG21,
	R_OR1K_TLS_GD_PG21, R_OR1K_TLS_LDM_PG21, R_OR1K_TLS_IE_PG21,
	R_OR1K_LO13, R_OR1K_GOT_LO13, R_OR1K_TLS_GD_LO13, R_OR1K_TLS_LDM_LO13,
	R_OR1K_TLS_IE_LO13, R_OR1K_SLO13, R_OR1K_PLTA26.
	(or1k_reloc_map): Add BFD_RELOC_OR1K_PCREL_PG21,
	BFD_RELOC_OR1K_GOT_PG21, BFD_RELOC_OR1K_TLS_GD_PG21,
	BFD_RELOC_OR1K_TLS_LDM_PG21, BFD_RELOC_OR1K_TLS_IE_PG21,
	BFD_RELOC_OR1K_LO13, BFD_RELOC_OR1K_GOT_LO13,
	BFD_RELOC_OR1K_TLS_GD_LO13, BFD_RELOC_OR1K_TLS_GD_LO13,
	BFD_RELOC_OR1K_TLS_LDM_LO13, BFD_RELOC_OR1K_TLS_IE_LO13,
	BFD_RELOC_OR1K_SLO13, BFD_RELOC_OR1K_PLTA26.
	(elf_or1k_link_hash_table): Add field saw_plta.
	(or1k_final_link_relocate): Add value calculations for new relocations.
	(or1k_elf_relocate_section): Add section relocations for new
	relocations.
	(or1k_write_plt_entry): New function.
	(or1k_elf_finish_dynamic_sections): Add support for PLTA relocations
	using new l.adrp instruction.  Cleanup PLT relocation code generation.
	* libbfd.h: Regenerated.
	* reloc.c: Add BFD_RELOC_OR1K_PCREL_PG21, BFD_RELOC_OR1K_LO13,
	BFD_RELOC_OR1K_SLO13, BFD_RELOC_OR1K_GOT_PG21, BFD_RELOC_OR1K_GOT_LO13,
	BFD_RELOC_OR1K_PLTA26, BFD_RELOC_OR1K_TLS_GD_PG21,
	BFD_RELOC_OR1K_TLS_GD_LO13, BFD_RELOC_OR1K_TLS_LDM_PG21,
	BFD_RELOC_OR1K_TLS_LDM_LO13, BFD_RELOC_OR1K_TLS_IE_PG21,
	BFD_RELOC_OR1K_TLS_IE_LO13.

cpu/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* or1k.opc (parse_disp26): Add support for plta() relocations.
	(parse_disp21): New function.
	(or1k_rclass): New enum.
	(or1k_rtype): New enum.
	(or1k_imm16_relocs): Define new PO and SPO relocation mappings.
	(parse_reloc): Add new po(), gotpo() and gottppo() for LO13 relocations.
	(parse_imm16): Add support for the new 21bit and 13bit relocations.
	* or1korbis.cpu (f-disp26): Don't assume SI.
	(f-disp21): New pc-relative 21-bit 13 shifted to right.
	(insn-opcode): Add ADRP.
	(l-adrp): New instruction.

gas/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* config/tc-or1k.c (or1k_apply_fix): Add BFD_RELOC_OR1K_TLS_GD_PG21,
	BFD_RELOC_OR1K_TLS_GD_LO13, BFD_RELOC_OR1K_TLS_LDM_PG21,
	BFD_RELOC_OR1K_TLS_LDM_LO13, BFD_RELOC_OR1K_TLS_IE_PG21,
	BFD_RELOC_OR1K_TLS_IE_LO13.
	* testsuite/gas/or1k/allinsn.s: Add test for l.adrp.
	* testsuite/gas/or1k/allinsn.d: Add test results for new
	instructions.
	* testsuite/gas/or1k/reloc-1.s: Add tests to generate
	R_OR1K_PLTA26, R_OR1K_GOT_PG21, R_OR1K_TLS_GD_PG21, R_OR1K_TLS_LDM_PG21,
	R_OR1K_TLS_IE_PG21, R_OR1K_LO13, R_OR1K_GOT_LO13, R_OR1K_TLS_GD_LO13,
	R_OR1K_TLD_LDM_LO13, R_OR1K_TLS_IE_LO13, R_OR1K_LO13, R_OR1K_SLO13
	relocations.
	* testsuite/gas/or1k/reloc-1.d: Add relocation results for
	tests.
	* testsuite/gas/or1k/reloc-2.s: Add negative tests for store to
	gotpo().
	* testsuite/gas/or1k/reloc-2.l: Add expected error test results.

ld/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* testsuite/ld-or1k/or1k.exp: Add test cases for plt generation.
	* testsuite/ld-or1k/plt1.dd: New file.
	* testsuite/ld-or1k/plt1.s: New file.
	* testsuite/ld-or1k/plt1.x.dd: New file.
	* testsuite/ld-or1k/plta1.dd: New file.
	* testsuite/ld-or1k/plta1.s: New file.
	* testsuite/ld-or1k/pltlib.s: New file.

include/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* elf/or1k.h (elf_or1k_reloc_type): Add R_OR1K_PCREL_PG21,
	R_OR1K_GOT_PG21, R_OR1K_TLS_GD_PG21, R_OR1K_TLS_LDM_PG21,
	R_OR1K_TLS_IE_PG21, R_OR1K_LO13, R_OR1K_GOT_LO13,
	R_OR1K_TLS_GD_LO13, R_OR1K_TLS_LDM_LO13, R_OR1K_TLS_IE_LO13,
	R_OR1K_SLO13, R_OR1K_PLTA26.

opcodes/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* or1k-asm.c: Regenerated.
	* or1k-desc.c: Regenerated.
	* or1k-desc.h: Regenerated.
	* or1k-dis.c: Regenerated.
	* or1k-ibld.c: Regenerated.
	* or1k-opc.c: Regenerated.
	* or1k-opc.h: Regenerated.
	* or1k-opinst.c: Regenerated.
2018-10-05 11:41:41 +09:00
Stafford Horne f2c1801f62 or1k: Fix messages for relocations in shared libraries
Added checks include:

 - Do not allow relocations to global symbols using relocations which are
   meant for local symbol relocations.
 - Require the use of -fpic when compiling shared libraries.
 - Require zero addend for plt relocations.

bfd/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* elf32-or1k.c (or1k_elf_relocate_section): Add error for unknown
	relocations.  Add error for non zero addend with plt and got
	relocations.  Add error for got and plt references against dynamic, non
	local, symbols.  Add error when linking non shared liraries with
	flag_pic.
2018-10-05 11:41:41 +09:00
Richard Henderson 1c4f3780f7 or1k: Add relocations for high-signed and low-stores
This patch adds the following target relocations:

 - BFD_RELOC_HI16_S		High 16-bit relocation, for used with signed
   asm: ha()			lower.
 - BFD_RELOC_HI16_S_GOTOFF	High 16-bit GOT offset relocation for local
   asm: gotoffha()		symbols, for use with signed lower.
 - BFD_RELOC_OR1K_TLS_IE_AHI16	High 16-bit TLS relocation with initial
   asm: gottpoffha()		executable calculation, for use with signed
				lower.
 - BFD_RELOC_OR1K_TLS_LE_AHI16	High 16-bit TLS relocation for local executable
   asm: tpoffha()		variables, for use with signed lower.

 - BFD_RELOC_OR1K_SLO16		Split lower 16-bit relocation, used with
   asm: lo()			OpenRISC store instructions.
 - BFD_RELOC_OR1K_GOTOFF_SLO16	Split lower 16-bit GOT offset relocation for
   asm: gotofflo()		local symbols, used with OpenRISC store
				instructions.
 - BFD_RELOC_OR1K_TLS_LE_SLO16	Split lower 16-bit relocation for TLS local
   asm: tpofflo()		executable variables, used with OpenRISC store
				instructions.

bfd/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>
	    Stafford Horne  <shorne@gmail.com>

	* bfd-in2.h: Regenerated.
	* elf32-or1k.c (N_ONES): New macro.
	(or1k_elf_howto_table): Fix R_OR1K_PLT26 to complain on overflow.
	Add definitions for R_OR1K_TLS_TPOFF, R_OR1K_TLS_DTPOFF,
	R_OR1K_TLS_DTPMOD, R_OR1K_AHI16, R_OR1K_GOTOFF_AHI16,
	R_OR1K_TLS_IE_AHI16, R_OR1K_TLS_LE_AHI16, R_OR1K_SLO16,
	R_OR1K_GOTOFF_SLO16, R_OR1K_TLS_LE_SLO16.
	(or1k_reloc_map): Add entries for BFD_RELOC_HI16_S,
	BFD_RELOC_LO16_GOTOFF, BFD_RELOC_HI16_GOTOFF, BFD_RELOC_HI16_S_GOTOFF,
	BFD_RELOC_OR1K_TLS_IE_AHI16, BFD_RELOC_OR1K_TLS_LE_AHI16,
	BFD_RELOC_OR1K_SLO16, BFD_RELOC_OR1K_GOTOFF_SLO16,
	BFD_RELOC_OR1K_TLS_LE_SLO16.
	(or1k_reloc_type_lookup): Change search loop to start ad index 0 and
	also check results before returning.
	(or1k_reloc_name_lookup): Simplify loop to use R_OR1K_max as index
	limit.
	(or1k_final_link_relocate): New function.
	(or1k_elf_relocate_section): Add support for new AHI and SLO
	relocations.  Use or1k_final_link_relocate instead of generic
	_bfd_final_link_relocate.
	(or1k_elf_check_relocs): Add support for new AHI and SLO relocations.
	* reloc.c: Add new enums for BFD_RELOC_OR1K_SLO16,
	BFD_RELOC_OR1K_GOTOFF_SLO16, BFD_RELOC_OR1K_TLS_IE_AHI16,
	BFD_RELOC_OR1K_TLS_IE_AHI16, BFD_RELOC_OR1K_TLS_LE_AHI16,
	BFD_RELOC_OR1K_TLS_LE_SLO16.  Remove unused BFD_RELOC_OR1K_GOTOFF_HI16
	and BFD_RELOC_OR1K_GOTOFF_LO16.
	* libbfd.h: Regenerated.

cpu/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* or1k.opc: Add RTYPE_ enum.
	(INVALID_STORE_RELOC): New string.
	(or1k_imm16_relocs): New array array.
	(parse_reloc): New static function that just does the parsing.
	(parse_imm16): New static function for generic parsing.
	(parse_simm16): Change to just call parse_imm16.
	(parse_simm16_split): New function.
	(parse_uimm16): Change to call parse_imm16.
	(parse_uimm16_split): New function.
	* or1korbis.cpu (simm16-split): Change to use new simm16_split.
	(uimm16-split): Change to use new uimm16_split.

gas/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* testsuite/gas/or1k/allinsn.d (l_ha): Add result for ha() relocation.
	* testsuite/gas/or1k/allinsn.s (l_ha): Add test for ha() relocations.
	* testsuite/gas/or1k/allinsn.exp: Renamed to or1k.exp.
	* testsuite/gas/or1k/or1k.exp: Add reloc-2 list test.
	* testsuite/gas/or1k/reloc-1.d: New file.
	* testsuite/gas/or1k/reloc-1.s: New file.
	* testsuite/gas/or1k/reloc-2.l: New file.
	* testsuite/gas/or1k/reloc-2.s: New file.

include/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* elf/or1k.h (elf_or1k_reloc_type): Add R_OR1K_AHI16,
	R_OR1K_GOTOFF_AHI16, R_OR1K_TLS_IE_AHI16, R_OR1K_TLS_LE_AHI16,
	R_OR1K_SLO16, R_OR1K_GOTOFF_SLO16, R_OR1K_TLS_LE_SLO16.

ld/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* testsuite/ld-or1k/offsets1.d: New file.
	* testsuite/ld-or1k/offsets1.s: New file.
	* testsuite/ld-or1k/or1k.exp: New file.

opcodes/ChangeLog:

yyyy-mm-dd  Richard Henderson  <rth@twiddle.net>

	* or1k-asm.c: Regenerate.
2018-10-05 11:41:40 +09:00
Jim Wilson 3e1b4df89c RISC-V: Delete zero-size .tdata.dyn section.
bfd/
	* elfnn-riscv.c (riscv_elf_size_dynamic_sections): In dynobj->sections
	loop, handle htab->sdyntdata section.
2018-10-04 13:29:57 -07:00
Jose E. Marchesi dca0df07ae bfd: amend ChangeLog entry 2018-10-04 12:16:11 +02:00
Jose E. Marchesi 6d0a6093c5 bfd,sparc: fix the .dynsym sh_index when stripping all symbols in ld
The SPARC ELF BFD backend uses a hack in order to accomodate the
STT_REGISTER symbols mandated by the SPARC V9 ABI for 64-bit objects.
The hack works as follows:

- Early in `size_dynamic_symbols', it adds the dynamic STT_REGISTER
  symbols and the corresponding DT_SPARC_REGISTER tags if needed,
  i.e. if the input object has been annotated by the assembler to use
  any of the global registers requiring annotations by the ABI.

  The STT_REGISTER symbols are not local, but nevertheless they are
  added to the end of the dynlocal linked list (eek, yes) to be fixed
  "later".  This is done so the symbols are emitted in the symtab.

- Consequently, when the `sh_info' field of the .dynsym section is
  calculated in `bfd_elf_final_link' to be `local_dynsymcount + 1', it
  may have the wrong value, since the real first global symbol is the
  first STT_REGISTER symbol.

- However, this temporary inconsistency is fixed in the
  `elf64_sparc_output_arch_syms' backend hook: the sh_index is
  adjusted to its rightful value.  So all is well and good.

However the 2015 changeset

commit 8539e4e89e
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Jan 15 19:42:59 2015 +1030

    Fix ARM fail of gap test

    ld-elf/gap test was failing due to the ARM backend attempting to output
    arch symbols when ld -s (strip all symbols) is in force.  This patch
    stops that happening and tidies the code a little.

made the `elf_backend_output_arch_syms' backend hook to not be called
when all symbols are to be stripped.  This resulted in an incorrect
sh_index for .dynsym when a link is performed with -s (strip_all), in
64-bit sparc ELF objects.

This patch moves the sh_index adjusting code from the target
`output_arch_syms' to `finish_dynamic_sections'.  It also removes the
strip_all check from `elf64_sparc_output_arch_syms', as the function
is no longer called in that case.

Tested in sparc64-linux-gnu and sparc-linux-gnu.
No regressions observed.

bfd/ChangeLog:

2018-10-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* elf64-sparc.c (elf64_sparc_output_arch_syms): Do not correct the
	impact of STT_REGISTER symbols in the dynsym sh_index here...
	* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_sections): ... but
	do it here.
2018-10-04 11:58:39 +02:00
H.J. Lu 23e463ed7c ELF: Group PT_NOTE segments by section alignments
Alignments of SHT_NOTE sections can be 8 bytes for 64-bit ELF files.  We
should put all adjacent SHT_NOTE sections with the same section alignment
into a single PT_NOTE segment even when the section alignment != 4 bytes.
Also check SHT_NOTE section type instead of section name.

	PR ld/23658
	* elf.c (get_program_header_size): Put all adjacent SHT_NOTE
	sections with the same section alignment into a single PT_NOTE
	segment.  Check SHT_NOTE section type instead of section name.
	(_bfd_elf_map_sections_to_segments): Likewise.
2018-10-03 13:22:40 -07:00
Millan Wolff c8d3f93237 Fix the handling of inlined frames in DWARF debug info.
PR 23715
	* dwarf2.c (find_abstract_instance): Allow recursive invocations
	of find_abstract_instance to override the name variable.
2018-10-03 12:06:09 +01:00
Nick Clifton 8e90d6d2c2 Updated Portuguese translations for the bfd/ and binutils/ subdirectories. 2018-10-03 10:58:49 +01:00
Cupertino Miranda eb528ad18b [ARC] Entries to Changelog for previous commits. 2018-10-02 09:20:11 +01:00
H.J. Lu 79c1bf3c71 bfd: Use elfclass instead of bed->s->elfclass
elfclass has been set to bed->s->elfclass earlier.

	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Use
	elfclass instead of bed->s->elfclass.
2018-09-28 15:35:55 -07:00
Jim Wilson 5f9aecea0d RISC-V: Pc-rel to gp-rel relaxation function cleanup.
bfd/
	* elfnn-riscv.c (riscv_init_pcgp_relocs): Add explanatory comment.
	(riscv_free_pcgp_relocs, riscv_record_pcgp_reloc): Likewise.
	(riscv_find_pcgp_hi_reloc, riscv_reocrd_pcgp_lo_reloc): Likewise.
	(riscv_find_pcgp_lo_reloc): Likewise.
	(riscv_delete_pcgp_hi_reloc, riscv_use_pcgp_hi_reloc): Delete.
	(riscv_delete_pcgp_lo_reloc): Likewise.
	(_bfd_riscv_relax_pc): Don't call riscv_use_pcgp_hi_reloc. Replace
	calls to riscv_delete_pcgp_lo_reloc and riscv_delete_pcgp_hi_reloc
	with TRUE.  Mark abfd arg as ATTRIBUTE_UNUSED.
2018-09-27 17:16:34 -07:00
Jim Wilson 5ef2379329 RISC-V: Give error for RVE PLTs.
bfd/
	* elfnn-riscv.c (riscv_make_plt_header): New arg output_bfd.  Change
	return type to bfd_boolean.  If	EF_RISCV_RVE call _bfd_error_handler
	and return FALSE.  Return TRUE at end.
	(riscv_make_plt_entry): Likewise.
	(riscv_elf_finish_dynamic_symbol): Update call to riscv_make_plt_entry.
	(riscv_elf_finish_dynamic_sections): Update call to
	riscv_make_plt_header.
2018-09-25 13:13:23 -07:00
Jim Wilson a05f27b689 RISC-V: For PCREL_LO12, fix addend handling in auipc lookup.
bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_pc) <R_RISCV_PCREL_LO12_I>: New local
	hi_sec_off which is symbol address with addend subtracted.  Use in
	riscv_find_pcgp_hi_reloc and riscv_record_pcgp_lo_reloc calls.
2018-09-24 14:36:41 -07:00
Jim Wilson 551703cfd4 RISC-V: Allow pcrel_lo addends, error on addend overflow.
bfd/
	* elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Add check for reloc
	overflow with addend.  Use reloc_dangerous instead of reloc_overflow.
	Add strings for the two errors handled here.
	(riscv_elf_relocate_section) In case R_RISCV_PCREL_LO12_I, rewrite
	comment.  Only give error with addend when used with section symbol.
	In case bfd_reloc_dangerous, update error string.

	ld/
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run pcrel-lo-addend-2.
	* testsuite/ld-riscv/elf/ld-riscv-elf/pcrel-lo-addend-2.d: New.
	* testsuite/ld-riscv/elf/ld-riscv-elf/pcrel-lo-addend-2.s: New.
	* testsuite/ld-riscv/elf/ld-riscv-elf/pcrel-lo-addend.d: Update name
	and error string.
2018-09-24 14:05:32 -07:00
Jozef Lawrynowicz db72737006 Fix PR gdb/20948: --write option to GDB causes segmentation fault
When opening a BFD for update, as gdb --write does, modifications to
anything but the contents of sections is restricted.

Do not try to write back any ELF headers in this case.

bfd/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	PR gdb/20948
	* elf.c (_bfd_elf_write_object_contents): Return from function
	early if abfd->direction == both_direction.

gdb/testsuite/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	PR gdb/20948
	* gdb.base/write_mem.exp: New test.
	* gdb.base/write_mem.c: Likewise.
2018-09-24 06:20:17 -06:00
Simon Marchi a767a1c4d3 elf32-nds32: Don't define fls if it is provided by the system
The fls function already exists on macOS and FreeBSD (and probably others),
leading to this error:

/Users/simark/src/binutils-gdb/bfd/elf32-nds32.c:5074:1: error: static declaration of 'fls' follows non-static declaration
fls (register unsigned int x)
^
/usr/include/strings.h:87:6: note: previous declaration is here
int      fls(int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
         ^

Add a configure-time check for it, and only define it if the system doesn't
provide it.

bfd/ChangeLog:

	* configure.ac: Check for fls.
	* elf32-nds32.c (fls): Only define if !HAVE_FLS.
	* config.in: Re-generate.
	* configure: Re-generate.
2018-09-21 10:27:30 -04:00
Maciej W. Rozycki ed3162adc4 RS6000/BFD: Remove dead duplicate `config.bfd' target matchers
Remove duplicate `rs6000-*-aix5.[01]' and `rs6000-*-aix[5-9]*' target
configuration selectors meant to correspond to `powerpc64-*-aix5.[01]'
and `powerpc64-*-aix[5-9]*' respectively for the purpose of BFD target
vector selection in `config.bfd'.

These selectors were added with commit 9a9e2ca332 ("rs6000 xcoff bfd
config"), <https://sourceware.org/ml/binutils/2010-12/msg00372.html>,
and have been dead right from the beginning, because they appear twice
each in the case statement, which means the earlier instance of each
takes precedence and the other one is ignored.  Here ones that alias to
`powerpc-*-aix5.[01]' and `powerpc-*-aix[5-9]*' respectively immediately
above are used instead.

	bfd/
	* config.bfd <rs6000-*-aix5.[01], rs6000-*-aix[5-9]*>: Remove
	duplicate `case' selectors.
2018-09-20 15:49:00 +01:00
Nick Clifton fbaf61ad52 Andes Technology has good news for you, we plan to update the nds32 port of binutils on upstream!
We have not only removed all unsupported and obsolete code, but also supported lost of new features,
including better link-time relaxations and TLS implementations. Besides, the files generated by the
newly assembler and linker usually get higher performance and more optimized code size.

ld	* emultempl/nds32elf.em (hyper_relax): New variable.
	(nds32_elf_create_output_section_statements):
	the parameters of bfd_elf32_nds32_set_target_option
	(PARSE_AND_LIST_PROLOGUE, PARSE_AND_LIST_OPTIONS,
	PARSE_AND_LIST_ARGS_CASES): Add new option --mhyper-relax.
	* emultempl/nds32elf.em (nds32_elf_after_open): Updated.
	* emultempl/nds32elf.em (tls_desc_trampoline): New variable.
	* (nds32_elf_create_output_section_statements): Updated.
	* (nds32_elf_after_parse): Disable relaxations when PIC is enable.
	* (PARSE_AND_LIST_PROLOGUE, PARSE_AND_LIST_OPTIONS,
	PARSE_AND_LIST_ARGS_CASES): Add new option --m[no-]tlsdesc-trampoline.

include	* elf/nds32.h: Remove the unused target features.
	* dis-asm.h (disassemble_init_nds32): Declared.
	* elf/nds32.h (E_NDS32_NULL): Removed.
	(E_NDS32_HAS_DSP_INST, E_NDS32_HAS_ZOL): New.
	* opcode/nds32.h: Ident.
	(N32_SUB6, INSN_LW): New macros.
	(enum n32_opcodes): Updated.
	* elf/nds32.h: Doc fixes.
	* elf/nds32.h: Add R_NDS32_LSI.
	* elf/nds32.h: Add new relocations for TLS.

gas 	* config/tc-nds32.c: Remove the unused target features.
	(nds32_relax_relocs, md_pseudo_table, nds32_elf_record_fixup_exp,
	nds32_set_elf_flags_by_insn, nds32_insert_relax_entry,
	nds32_apply_fix): Likewise.
	(nds32_no_ex9_begin): Removed.
	* config/tc-nds32.c (add_mapping_symbol_for_align,
	make_mapping_symbol, add_mapping_symbol): New functions.
	* config/tc-nds32.h (enum mstate): New.
	(nds32_segment_info_type): Likewise.
	* configure.ac (--enable-dsp-ext, --enable-zol-ext): New options.
	* config.in: Regenerated.
	* configure: Regenerated.
	* config/tc-nds32.c (nds32_dx_regs):
	Set the value according to the configuration.
	(nds32_perf_ext, nds32_perf_ext2, nds32_string_ext, nds32_audio_ext):
	Likewise.
	(nds32_dsp_ext): New variable. Set the value according to the
	configuration.
	(nds32_zol_ext): Likewise.
	(asm_desc, nds32_pseudo_opcode_table): Make them static.
	(nds32_set_elf_flags_by_insn): Updated.
	(nds32_check_insn_available): Updated.
	(nds32_str_tolower): New function.
	* config/tc-nds32.c (relax_table): Updated.
	(md_begin): Updated.
	(md_assemble): Use XNEW macro to allocate space for `insn.info',
	and then remember to free it.
	(md_section_align): Cast (-1) to ValueT.
	(nds32_get_align): Cast (~0U) to addressT.
	(nds32_relax_branch_instructions): Updated.
	(md_convert_frag): Add new local variable `final_r_type'.
	(invalid_prev_frag): Add new bfd_boolean parameter `relax'.
	All callers changed.
	* config/tc-nds32.c (struct nds32_relocs_pattern): Add `insn' field.
	(struct nds32_hint_map): Add `option_list' field.
	(struct suffix_name, suffix_table): Remove the unused `pic' field.
	(do_pseudo_b, do_pseudo_bal): Remove the suffix checking.
	(do_pseudo_la_internal, do_pseudo_pushpopm): Indent.
	(relax_hint_bias, relax_hint_id_current): New static variables.
	(reset_bias, relax_hint_begin): New variables.
	(nds_itoa): New function.
	(CLEAN_REG, GET_OPCODE): New macros.
	(struct relax_hint_id): New.
	(nds32_relax_hint): For .relax_hint directive, we can use `begin'
	and `end' to mark the relax pattern without giving exactly id number.
	(nds32_elf_append_relax_relocs): Handle the case that the .relax_hint
	directives are attached to pseudo instruction.
	(nds32_elf_save_pseudo_pattern): Change the second parameter from
	instruction's opcode to byte code.
	(nds32_elf_build_relax_relation): Add new bfd_boolean parameter
	`pseudo_hint'.
	(nds32_lookup_pseudo_opcode): Fix the overflow issue.
	(enum nds32_insn_type): Add N32_RELAX_ALU1 and N32_RELAX_16BIT.
	(nds32_elf_record_fixup_exp, relax_ls_table, hint_map,
	nds32_find_reloc_table, nds32_match_hint_insn, nds32_parse_name):
	Updated.
	* config/tc-nds32.h (MAX_RELAX_NUM): Extend it to 6.
	(enum nds32_relax_hint_type): Merge NDS32_RELAX_HINT_LA and
	NDS32_RELAX_HINT_LS into NDS32_RELAX_HINT_LALS. Add
	NDS32_RELAX_HINT_LA_PLT, NDS32_RELAX_HINT_LA_GOT and
	NDS32_RELAX_HINT_LA_GOTOFF.
	* config/tc-nds32.h (relax_ls_table): Add floating load/store
	to gp relax pattern.
	(hint_map, nds32_find_reloc_table): Likewise.
	* configure.ac: Define NDS32_LINUX_TOOLCHAIN.
	* configure: Regenerated.
	* config.in: Regenerated.
	* config/tc-nds32.h (enum nds32_ramp): Updated.
	(enum nds32_relax_hint_type): Likewise.
	* config/tc-nds32.c: Include "errno.h" and "limits.h".
	(relax_ls_table): Add TLS relax patterns.
	(nds32_elf_append_relax_relocs): Attach BFD_RELOC_NDS32_GROUP on
	each instructions of TLS patterns.
	(nds32_elf_record_fixup_exp): Updated.
	(nds32_apply_fix): Likewise.
	(suffix_table): Add TLSDESC suffix.

binutils* testsuite/binutils-all/objcopy.exp: Set the unsupported reloc number
	from 215 to 255 for NDS32.

bfd	* elf32-nds32.c (nds32_elf_relax_loadstore):
	Remove the unused target features.
	(bfd_elf32_nds32_set_target_option): Remove the unused parameters.
	(nds32_elf_relax_piclo12, nds32_elf_relax_letlslo12,
	nds32_elf_relax_letlsadd, nds32_elf_relax_letlsls,
	nds32_elf_relax_pltgot_suff, nds32_elf_relax_got_suff
	nds32_elf_relax_gotoff_suff, calculate_plt_memory_address,
	calculate_plt_offset, calculate_got_memory_address,
	nds32_elf_check_dup_relocs): Removed.
	All callers changed.
	* elf32-nds32.h: Remove the unused macros and defines.
	(elf_nds32_link_hash_table): Remove the unused variable.
	(bfd_elf32_nds32_set_target_option): Update prototype.
	(nds32_elf_ex9_init): Removed.
	* elf32-nds32.c (nds32_convert_32_to_16): Updated.
	* elf32-nds32.c (HOWTO2, HOWTO3): Define new HOWTO macros
	to initialize array nds32_elf_howto_table in any order
	without lots of EMPTY_HOWTO.
	(nds32_reloc_map): Updated.
	* reloc.c: Add BFD_RELOC_NDS32_LSI.
	* bfd-in2.h: Regenerated.
	* bfd/libbfd.h: Regenerated.
	* elf32-nds32.c (nds32_elf_relax_howto_table): Add R_NDS32_LSI.
	(nds32_reloc_map): Likewise.
	(nds32_elf_relax_flsi): New function.
	(nds32_elf_relax_section): Support floating load/store relaxation.
	* elf32-nds32.c (NDS32_GUARD_SEC_P, elf32_nds32_local_gp_offset):
	New macro.
	(struct elf_nds32_link_hash_entry): New `offset_to_gp' field.
	(struct elf_nds32_obj_tdata): New `offset_to_gp' and `hdr_size' fields.
	(elf32_nds32_allocate_local_sym_info, nds32_elf_relax_guard,
	nds32_elf_is_target_special_symbol, nds32_elf_maybe_function_sym):
	New functions.
	(nds32_info_to_howto_rel): Add BFD_ASSERT.
	(bfd_elf32_bfd_reloc_type_table_lookup, nds32_elf_link_hash_newfunc,
	nds32_elf_link_hash_table_create, nds32_elf_relocate_section,
	nds32_elf_relax_loadstore, nds32_elf_relax_lo12, nds32_relax_adjust_label,
	bfd_elf32_nds32_set_target_option, nds32_fag_mark_relax): Updated.
	(nds32_elf_final_sda_base): Improve it to find the better gp value.
	(insert_nds32_elf_blank): Must consider `len' when inserting blanks.
	* elf32-nds32.h (bfd_elf32_nds32_set_target_option): Update prototype.
	(struct elf_nds32_link_hash_table): Add new variable `hyper_relax'.
	* elf32-nds32.c (elf32_nds32_allocate_dynrelocs): New function.
	(create_got_section): Likewise.
	(allocate_dynrelocs, nds32_elf_size_dynamic_sections,
	nds32_elf_relocate_section, nds32_elf_finish_dynamic_symbol): Updated.
	(nds32_elf_check_relocs): Fix the issue that the shared library may
	has TEXTREL entry in the dynamic section.
	(nds32_elf_create_dynamic_sections): Enable to call readonly_dynrelocs
	since the TEXTREL issue is fixed in the nds32_elf_check_relocs.
	(nds32_elf_finish_dynamic_sections): Update and add DT_RELASZ
	dynamic entry.
	(calculate_offset): Remove the unused parameter `pic_ext_target' and
	related codes.
	All callers changed.
	(elf_backend_dtrel_excludes_plt): Disable it temporarily since it
	will cause some errors for our test cases.
	* elf32-nds32.c (nds32_elf_merge_private_bfd_data): Allow to link the
	generic object.
	* reloc.c: Add TLS relocations.
	* libbfd.h: Regenerated.
	* bfd-in2.h: Regenerated.
	* elf32-nds32.h (struct section_id_list_t): New.
	(elf32_nds32_lookup_section_id, elf32_nds32_check_relax_group,
	elf32_nds32_unify_relax_group, nds32_elf_unify_tls_model):
	New prototypes.
	(elf32_nds32_compute_jump_table_size, elf32_nds32_local_tlsdesc_gotent):
	New macro.
	(nds32_insertion_sort, bfd_elf32_nds32_set_target_option,
	elf_nds32_link_hash_table): Updated.
	* elf32-nds32.c (enum elf_nds32_tls_type): New.
	(struct elf32_nds32_relax_group_t, struct relax_group_list_t): New.
	(elf32_nds32_add_dynreloc, patch_tls_desc_to_ie, get_tls_type,
	fls, ones32, list_insert, list_insert_sibling, dump_chain,
	elf32_nds32_check_relax_group, elf32_nds32_lookup_section_id,
	elf32_nds32_unify_relax_group, nds32_elf_unify_tls_model): New functions.
	(elf_nds32_obj_tdata): Add new fields.
	(elf32_nds32_relax_group_ptr, nds32_elf_local_tlsdesc_gotent): New macros.
	(nds32_elf_howto_table): Add TLS relocations.
	(nds32_reloc_map): Likewise.
	(nds32_elf_copy_indirect_symbol, nds32_elf_size_dynamic_sections,
	nds32_elf_finish_dynamic_symbol, elf32_nds32_allocate_local_sym_info,
	nds32_elf_relocate_section, bfd_elf32_nds32_set_target_option,
	nds32_elf_check_relocs, allocate_dynrelocs): Updated.
	(nds32_elf_relax_section): Call nds32_elf_unify_tls_model.
	(dtpoff_base): Rename it to `gottpof' and then update it.

opcodes	* nds32-asm.c (operand_fields): Remove the unused fields.
	(nds32_opcodes): Remove the unused instructions.
	* nds32-dis.c (nds32_ex9_info): Removed.
	(nds32_parse_opcode): Updated.
	(print_insn_nds32): Likewise.
	* nds32-asm.c (config.h, stdlib.h, string.h): New includes.
	(LEX_SET_FIELD, LEX_GET_FIELD): Update defines.
	(nds32_asm_init, build_operand_hash_table, build_keyword_hash_table,
	build_opcode_hash_table): New functions.
	(nds32_keyword_table, nds32_keyword_count_table, nds32_field_table,
	nds32_opcode_table): New.
	(hw_ktabs): Declare it to a pointer rather than an array.
	(build_hash_table): Removed.
	* nds32-asm.h (enum): Add SYN_INPUT, SYN_OUTPUT, SYN_LOPT,
	SYN_ROPT and upadte HW_GPR and HW_INT.
	* nds32-dis.c (keywords): Remove const.
	(match_field): New function.
	(nds32_parse_opcode): Updated.
	* disassemble.c (disassemble_init_for_target):
	Add disassemble_init_nds32.
	* nds32-dis.c (eum map_type): New.
	(nds32_private_data): Likewise.
	(get_mapping_symbol_type, is_mapping_symbol, nds32_symbol_is_valid,
	nds32_add_opcode_hash_table, disassemble_init_nds32): New functions.
	(print_insn_nds32): Updated.
	* nds32-asm.c (parse_aext_reg): Add new parameter.
	(parse_re, parse_re2, parse_aext_reg): Only reduced registers
	are allowed to use.
	All callers changed.
	* nds32-asm.c (keyword_usr, keyword_sr): Updated.
	(operand_fields): Add new fields.
	(nds32_opcodes): Add new instructions.
	(keyword_aridxi_mx): New keyword.
	* nds32-asm.h (enum): Add NASM_ATTR_DSP_ISAEXT, HW_AEXT_ARIDXI_MX
	and NASM_ATTR_ZOL.
	(ALU2_1, ALU2_2, ALU2_3): New macros.
	* nds32-dis.c (nds32_filter_unknown_insn): Updated.
2018-09-20 13:32:58 +01:00
Alan Modra cf93e9c2cf PR23685, buffer overflow
PR 23685
	* peXXigen.c (pe_print_edata): Correct export address table
	overflow checks.  Check dataoff against section size too.
2018-09-20 20:20:03 +09:30
Alan Modra 3083813299 Bug 23686, two segment faults in nm
Fixes the bugs exposed by the testcases in the PR, plus two more bugs
I noticed when looking at _bfd_stab_section_find_nearest_line.

	PR 23686
	* dwarf2.c (read_section): Error when attempting to malloc
	"(bfd_size_type) -1".
	* syms.c (_bfd_stab_section_find_nearest_line): Bounds check
	function_name.  Bounds check reloc address.  Formatting.  Ensure
	.stabstr zero terminated.
2018-09-20 15:33:45 +09:30
Nick Clifton 8ff71a9c80 Add a warning to the bfd library for when it encounters an ELF file with an invalid section size.
PR 23657
	* elfcode.h (elf_swap_shdr_in): Generate a warning message if an
	ELF section has contents and size larger than the file size.
2018-09-18 16:54:07 +01:00
Maciej W. Rozycki 47275900ad PR ld/21375: MIPS: Fix non-zero run-time value for undefined weaks
We have an issue in the MIPS backend, with the handling of undefined
hidden and internal weak symbols.  References to such symbols are
supposed to resolve to 0 according to the ELF gABI[1]:

"Unresolved weak symbols have a zero value."

and the 64-bit MIPS psABI[2]:

"If a symbol with one of these [hidden or internal] attributes has no
definition within the executable/DSO being linked, then it must be
resolved to allocated space if common, resolved to zero if weak, or an
error reported otherwise."

however if a GOT relocation is used, then a local GOT entry is created
and used to satisfy the reference.  Such an entry is then (in DSO and
PIE binaries) subject to the usual load-time relocation, which means a
non-zero value will be returned if the base address is non-zero.  This
will defeat the usual run-time sequence like:

void a (void) __attribute__ ((visibility ("hidden"), weak));

void
x (void)
{
  if (a)
    a ();
}

This can be reproduced with this simple code:

$ cat libtest.c
extern int a __attribute__ ((visibility ("hidden"), weak));

int *
x (void)
{
  return &a;
}
$ cat test.c

int *x (void);

int
main (void)
{
  printf ("a: %p\n", x ());

  return 0;
}
$ gcc -shared -fPIC -o libtest.so libtest.c
$ gcc -o test test.c -Wl,-rpath,$(pwd) libtest.so
$ ./test
a: 0x77184000
$

The usual approach targets take is making all the steps required to
assign a GOT entry for the symbol referred, and then leave its contents
at zero with no dynamic relocation attached, therefore ensuring that the
value does not change at load time.  However this is not going to work
with the implicitly relocated GOT the MIPS psABI specifies[3]:

"The dynamic linker relocates the global offset table by first adding
the difference between the base where the shared object is loaded and
the value of the dynamic tag DT_MIPS_BASE_ADDRESS to all local global
offset table entries."

and we cannot therefore use the local GOT part.

And we cannot offhand use the global part either, as the symbol would
then have to be exported and possibly wrongly preempt symbols in other
modules involved in the dynamic load, because as per the ELF gABI[1] we
are not allowed to enter a hidden or internal symbol into the dynamic
symbol table (and then use its associated GOT entry):

"A hidden symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object."

and:

"An internal symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object."

So we have to choose something else.

Our choice is further limited by the need for the reference associated
with the GOT relocation to stay within the signed 16-bit limit from the
GOT pointer base register, while being compliant with the ELF gABI and
the MIPS psABI.  However as Alan Modra has observed[4] one possibility
is to edit (relax) the code such that the GOT reference is removed
altogether.

Based on these observations then modify MIPS BFD linker backend code to:

1. Interpret code associated with GOT relocations and relax the usual LW
   or LD instructions into a corresponding immediate load operation that
   places the value of 0 in the intended register, while leaving the GOT
   entry allocated and initialized as usually.

2. Leave any other instructions associated with GOT relocations in place
   and instead redirect the reference to a global GOT entry associated
   with a special `__gnu_absolute_zero' symbol created for this purpose,
   whose value is 0, SHN_ABS section marks it absolute, binding is
   global and export class protected, ensuring that the locally provided
   value is always used at load time, and that the value is not
   relocated by the dynamic loader.

3. Adjust any high-part GOT relocation used, typically associated with
   a LUI instruction, accordingly, so that run-time consistency is
   maintained, either by resolving to the original entry if the
   instruction associated with the corresponding low-part GOT relocation
   has been relaxed to an immediate load (in which case the value loaded
   with LUI will be overwritten), or by also redirecting the reference
   to `__gnu_absolute_zero' to complete the GOT access sequence if that
   symbol has been used.

4. Add a target `elf_backend_hide_symbol' hook, for the three MIPS ABIs,
   which prevents the `__gnu_absolute_zero' symbol from being forced
   local, to ensure that the redirection works and the symbol remains
   global/protected with existing linker scripts unchanged.

5. Observing the issue with handling SHN_ABS symbols in the GNU dynamic
   loader, covered by glibc PR 19818, set the EI_ABIVERSION field in the
   ELF file header produced to 4 (ABI_ABSOLUTE) if `__gnu_absolute_zero'
   symbol has been produced and the target configured indicates the GNU
   operating system, so that broken versions of the GNU dynamic loader
   gracefully reject the file in loading rather than going astray.  Keep
   EI_ABIVERSION at the original value for other operating systems or if
   no `__gnu_absolute_zero' symbol has been made.

The name of the special `__gnu_absolute_zero' has no meaning other than
how a human reader can interpret it, as it is ignored in dynamic loading
in the handling of the scenarios concerned.  This is because the symbol
resolves locally, and it's only the symbol's attributes that matter so
that the associated GOT entry remains unchanged at load time.

Therefore the name is somewhat arbitrary, observing however the need to
use the name space reserved for the system so that it does not conflict
with a possible user symbol, and hence the leading underscore, and also
the `gnu' infix to denote a GNU feature.  Other implementations wishing
to address the problem in a similar way may choose a different name and
have the solution still work, possibly with a mixture of modules used in
a dynamic having symbols of different names provided, which will however
not interact with each other due to the protected export class.

The symbol can be referred explicitly, however the name is an internal
implementation detail rather than a part of the ABI, and therefore no
specific semantics is guaranteed.

One limitation of this change is that if `__gnu_absolute_zero' has been
already defined, then we do not wipe the old definition and all kinds of
odd behavior can result.  This is however like with other symbols we
internally define, such as `_GLOBAL_OFFSET_TABLE_' or `__rld_map', and
therefore left as a possible future enhancement.

As an optimization the relaxation of LW and LD instructions to a load of
immediate zero is always made, even SVR4 PIC code for code that will end
up in a regular (non-PIE) executable, because there is a cache advantage
with the avoidance of a load from the GOT, even if it is otherwise
guaranteed to remain zero.  It does not reliably happen though, due to a
symbol exportation issue affecting executables, covered by PR ld/21805.

One existing test case needs to be updated, as it triggers relaxation
introduced with this change and consequently linker output does not
match expectations anymore.  As we want to keep the original issue
covered with the test case modify it then to use the LWL instruction in
place of LW, and adjust the output expected accordingly.

References:

[1] "System V Application Binary Interface - DRAFT - 19 October 2010",
    The SCO Group, Section "Symbol Table",
    <http://www.sco.com/developers/gabi/2012-12-31/ch4.symtab.html>

[2] "64-bit ELF Object File Specification, Draft Version 2.5", MIPS
    Technologies / Silicon Graphics Computer Systems, Order Number
    007-4658-001, Section 2.5 "Symbol Table", p. 22,
    <http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf>

[3] "SYSTEM V APPLICATION BINARY INTERFACE, MIPS RISC Processor
    Supplement, 3rd Edition", Section "Global Offset Table", p. 5-10,
    <http://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf>

[4] "Undo dynamic symbol state after regular object sym type mismatch",
    <https://sourceware.org/ml/binutils/2017-07/msg00265.html>

	bfd/
	PR ld/21375
	* elfxx-mips.h (_bfd_mips_elf_hide_symbol): New prototype.
	(_bfd_mips_elf_linker_flags): Update prototype.
	* elf32-mips.c (elf_backend_hide_symbol): New macro.
	* elf64-mips.c (elf_backend_hide_symbol): Likewise.
	* elfn32-mips.c (elf_backend_hide_symbol): Likewise.
	* elfxx-mips.c (mips_elf_link_hash_table): Add
	`use_absolute_zero' and `gnu_target' members.
	(mips_elf_record_global_got_symbol): Call
	`_bfd_mips_elf_hide_symbol' rather than
	`_bfd_elf_link_hash_hide_symbol'.
	(mips_use_local_got_p): Return FALSE if the symbol is absolute.
	(mips_elf_obtain_contents): Reorder function.
	(mips_elf_nullify_got_load): New function.
	(mips_elf_calculate_relocation): Add `contents' parameter.
	Nullify GOT loads or if it is not possible, then redirect GOT
	relocations to the `__gnu_absolute_zero' symbol, for references
	that are supposed to resolve to zero.
	(mips_elf_define_absolute_zero): New function.
	(_bfd_mips_elf_check_relocs): Prepare for arrangements made in
	`mips_elf_calculate_relocation' for references made via the GOT
	that are supposed to resolve to zero.
	(_bfd_mips_elf_hide_symbol): New function.
	(_bfd_mips_elf_linker_flags): Add the `gnu_target' parameter,
	set the `gnu_target' member of the MIPS hash table.
	(MIPS_LIBC_ABI_ABSOLUTE): New enumeration constant.
	(_bfd_mips_post_process_headers): Use it.

	ld/
	PR ld/21375
	* emultempl/mipself.em: Set `gnu_target' according to ${target}.
	(mips_create_output_section_statements): Update call to
	`_bfd_mips_elf_linker_flags'.
	* testsuite/ld-mips-elf/pr21334.s: Use LWL rather than LW.
	* testsuite/ld-mips-elf/pr21334.dd: Update accordingly.
2018-09-14 20:22:56 +01:00
Maciej W. Rozycki 98e10ffadb MIPS/BFD: Factor out relocated field storing
Move code used to store the contents of a relocated field in output into
a separate function, `mips_elf_store_contents', complementing existing
`mips_elf_obtain_contents'.

	bfd/
	* elfxx-mips.c (mips_elf_store_contents): New function...
	(mips_elf_perform_relocation): ... factored out from here.
2018-09-14 20:22:56 +01:00
Lifang Xia fe75f42ee1 csky: Support PC relative diff relocation
Define DIFF_EXPR_OK to Support PC relative diff relocation,
and add CKCORE_PCREL32 relocation process

bfd/
        * elf32-csky.c (csky_elf_howto_table): Fill special_function of
        R_CKCORE_PCREL32.
        (csky_elf_relocate_section): Add R_CKCORE_PCREL32 process.
gas/
        * config/tc-csky.c (md_apply_fix): Transmit
        BFD_RELOC_32_PCREL to BFD_RELOC_CKCORE_PCREL32.
        (tc_gen_reloc): Trasmit BFD_RELOC_CKCORE_ADDR32 to
        BFD_RELOC_CKCORE_PCREL32 while pc-relative.
        * config/tc-csky.h (DIFF_EXPR_OK): Define to enable PC relative
        diff relocs.
2018-09-14 21:04:47 +08:00
Alan Modra a4cd947aca PR23425, unresolved symbol diagnostic
dwarf2.c code reasonably assumes that debug info is local to a file,
an assumption now violated by gcc, resulting in "DWARF error: invalid
abstract instance DIE ref" or wrong details when attempting to print
linker error messages with file, function and line reported.

This is because find_abstract_instance is only prepared to handle
DW_FORM_ref_addr when the .debug_info section referenced is in the
current file.  When that isn't the case, relocations to access another
file's .debug_info will typically be against a symbol defined at the
start of that .debug_info section, plus an addend.  Since the dwarf2.c
code only considers the current file's debug info, that symbol will be
undefined, resolving to zero.  In effect the ref_addr will wrongly
resolve to the current file's .debug_info.

This patch avoids the problem by treating relocations in debug
sections against undefined symbols in a similar manner to the way
relocations against symbols defined in discarded sections are
resolved.  They result in a zero value (except in .debug_ranges)
regardless of the addend.

	PR 23425
	* reloc.c (bfd_generic_get_relocated_section_contents): Zero reloc
	fields in debug sections when reloc is against an undefined symbol
	and called from bfd_simple_get_relocated_section_contents or
	similar.
	* dwarf2.c (find_abstract_instance): Return true for zero offset
	DW_FORM_ref_addr without returning values.
2018-09-14 21:21:28 +09:30
Alan Modra deee88e981 PR23570, AVR .noinit section defaults to PROGBITS
Revert commit 8744470dea and instead use the standard special_sections
support.

	PR 23570
bfd/
	* elf32-avr.c (elf_avr_special_sections): New.
	(elf_backend_special_sections): Define.
gas/
	* config/tc-avr.c: Revert 2018-09-03 change.
2018-09-06 14:13:00 +09:30
Jose E. Marchesi e920c014ec bfd, sparc: avoid duplicated error messages on invalid relocations.
This patch avoids a duplicated error message when an invalid
relocation number is read from an object file in sparc-* ELF targets:

$ strip -g test.o
strip: test.o: unsupported relocation type 0xd7
strip: test.o: unsupported relocation type 0xd7
strip: test.o: bad value

Tested in x86_64-linux-gnu, sparc64-linux-gnu and sparc-linux-gnu
targets.

bfd/ChangeLog:

2018-09-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* elfxx-sparc.c (_bfd_sparc_elf_info_to_howto): Do not issue an
	error when an invalid relocation is passed;  this is already done
	by `_bfd_sparc_elf_info_to_howto_ptr'.
2018-09-04 20:31:41 +02:00
Jose E. Marchesi 8410d65b77 bfd, sparc: issue an error when reading relocations with invalid symbol references.
The function `elf64_sparc_slurp_one_reloc_table' in elf64-sparc.c
currently checks that the symbol indexes read in the r_sym fields of
relocations are in range.  This is done for both dynamic and
non-dynamic symbols.  This avoids subsequent invalid memory accesses.
However, no error is issued to the user.

This patch makes BFD to issue an error when the read symbol index is
out of range, following the same behavior implemented in both the
generic ELF routines and other ELF backends (such as mips64).

Tested in x86_64-linux-gnu, sparc64-linux-gnu, and
--enable-targets=all.

2018-09-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

            * elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Issue an
            error when an invalid symbol index is retrieved in ELF64_R_SYM of
            a relocation seen in an input file.
2018-09-04 20:31:41 +02:00
Jozef Lawrynowicz 2542e49e21 PR23595, simple objcopy of executable failure for msp430-elf
VMA of the first section in the segment containing the ELF file header
(and possibly section headers too) can't be used to reliably find the
size of the headers plus padding.  What's really needed is sh_offset
of the first section assuming it has contents (vma does have a
relationship to sh_offset, but is only guaranteed in demand paged
executables).

If the first section is SHT_NOBITS and it hasn't been converted to
have file contents by the existence of a following SHT_PROGBITS
section in the same segment, the sh_offset value also isn't reliable.

	PR 23595
	elf.c (copy_elf_program_header): When first segment contains
	only the headers and SHT_NOBITS sections, use segment p_filesz
	to calculate header and padding size.  Use filepos of the first
	section otherwise.
2018-09-03 15:50:54 +09:30
H.J. Lu b986869b66 Allow an IR object with unknown architecture
An IR object may have an unknown architecture.  But it is compatible
with other architecture.

	PR ld/23600
	* archures.c (bfd_arch_get_compatible): Allow an IR object with
	unknown architecture.
2018-08-31 19:57:38 -07:00
Alan Modra 3d58e1fcfb PowerPC64 --emit-relocs support for notoc stubs
This patch uses the newly defined high-part REL16 relocs to emit
relocations on the notoc stubs as we already do for other stubs.

	* elf64-ppc.c (num_relocs_for_offset): New function.
	(emit_relocs_for_offset): New function.
	(use_global_in_relocs): New function, split out from..
	(ppc_build_one_stub): ..here.  Output relocations for notoc stubs.
	(ppc_size_one_stub): Calculate reloc count for notoc stubs.
	(ppc64_elf_size_stubs): Don't count undefined syms in stub_globals.
2018-08-31 22:15:05 +09:30
Alan Modra 4a9699735b PowerPC64 higher REL16 relocations
There are occasions where someone might want to build a 64-bit
pc-relative offset from 16-bit pieces.  This adds the necessary REL16
relocs corresponding to existing ADDR16 relocs that can be used to
build 64-bit absolute values.

include/
	* elf/ppc64.h (R_PPC64_REL16_HIGH, R_PPC64_REL16_HIGHA),
	(R_PPC64_REL16_HIGHER, R_PPC64_REL16_HIGHERA),
	(R_PPC64_REL16_HIGHEST, R_PPC64_REL16_HIGHESTA): Define.
	(R_PPC64_LO_DS_OPT, R_PPC64_16DX_HA): Bump value.
bfd/
	* reloc.c (BFD_RELOC_PPC64_REL16_HIGH, BFD_RELOC_PPC64_REL16_HIGHA),
	(BFD_RELOC_PPC64_REL16_HIGHER, BFD_RELOC_PPC64_REL16_HIGHERA),
	(BFD_RELOC_PPC64_REL16_HIGHEST, BFD_RELOC_PPC64_REL16_HIGHESTA):
	Define.
	* elf64-ppc.c (ppc64_elf_howto_raw): Add new REL16 howtos.
	(ppc64_elf_reloc_type_lookup): Translate new REL16 relocs.
	(ppc64_elf_check_relocs, ppc64_elf_relocate_section): Handle them.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
gas/
	* config/tc-ppc.h (TC_FORCE_RELOCATION_SUB_LOCAL): Allow ADDR16
	HIGH, HIGHA, HIGHER, HIGHERA, HIGHEST, and HIGHESTA relocs.
	Group 16-bit relocs.
	* config/tc-ppc.c (md_apply_fix): Translate those ADDR16 relocs
	to REL16 when pcrel.  Sort relocs.
2018-08-31 22:15:05 +09:30
Alan Modra f891966ff6 Rearrange ppc_size_one_stub and correct _notoc stub examples
This patch rearranges ppc_size_one_stub to make it a little easier to
compare against ppc_build_one_stub, and makes a few other random
changes that might help for future maintenance.  There should be no
functional changes here.

The patch also fixes code examples in comments.  A couple of "ori"
instructions lacked the source register operand, and "@high" is the
correct reloc modifier to use in a sequence building a 64-bit value.
(@hi reports overflow of a 32-bit signed value.)

	* elf64-ppc.c: Correct _notoc stub comments.
	(ppc_build_one_stub): Simplify output of branch for notoc
	long branch stub.  Don't include label offset of 8 bytes in
	"off" calculation for notoc plt stub.  Don't emit insns to get pc.
	(build_offset): Emit insns to get pc here instead.
	(size_offset): Add 4 extra insns.
	(plt_stub_size): Adjust for "off" and size_offset changes.
	(ppc_size_one_stub): Rearrange code into a switch, duplicating
	some to better match ppc_build_one_stub.
2018-08-31 22:15:05 +09:30
Chenghua Xu 9108bc33b1 [MIPS] Add Loongson 2K1000 proccessor support.
bfd/
	* archures.c (bfd_architecture): New machine
	bfd_mach_mips_gs264e.
	* bfd-in2.h (bfd_architecture): Likewise.
	* cpu-mips.c (enum I_xxx): Likewise.
	(arch_info_struct): Likewise.
	* elfxx-mips.c (_bfd_elf_mips_mach): Handle
	E_MIPS_MACH_GS264E.
	(mips_set_isa_flags): Likewise.
	(mips_mach_extensions): Map bfd_mach_mips_gs264e to
	bfd_mach_mips_gs464e extension.

binutils/
	* NEWS: Mention Loongson 2K1000 proccessor support.
	* readelf.c (get_machine_flags): Handle gs264e.

elfcpp/
	* mips.c (EF_MIPS_MACH): New E_MIPS_MACH_GS264E.

gas/
	* config/tc-mips.c (ISA_HAS_ODD_SINGLE_FPR): Exclude CPU_GS264E.
	(mips_cpu_info_table): Add gs264e descriptors.
	* doc/as.texi (march table): Add gs264e.

include/
	* elf/mips.h (E_MIPS_MACH_XXX): New E_MIPS_MACH_GS264E.
	* opcode/mips.h (CPU_XXX): New CPU_GS264E.

ld/
	* testsuite/ld-mips-elf/mips-elf-flags.exp: Run good_combination
	gs264e and gs464e.

opcodes/
	* mips-dis.c (mips_arch_choices): Add gs264e descriptors.
2018-08-29 20:55:25 +08:00
Chenghua Xu bd782c07b9 [MIPS] Add Loongson 3A2000/3A3000 proccessor support.
bfd/
	* archures.c (bfd_architecture): New machine
	bfd_mach_mips_gs464e.
	* bfd-in2.h (bfd_architecture): Likewise.
	* cpu-mips.c (enum I_xxx): Likewise.
	(arch_info_struct): Likewise.
	* elfxx-mips.c (_bfd_elf_mips_mach): Handle
	E_MIPS_MACH_GS464E.
	(mips_set_isa_flags): Likewise.
	(mips_mach_extensions): Map bfd_mach_mips_gs464e to
	bfd_mach_mips_gs464 extension.

binutils/
	* NEWS: Mention Loongson 3A2000/3A3000 proccessor support.
	* readelf.c (get_machine_flags): Handle gs464e.

elfcpp/
	* mips.c (EF_MIPS_MACH): New E_MIPS_MACH_GS464E.

gas/
	* config/tc-mips.c (ISA_HAS_ODD_SINGLE_FPR): Exclude CPU_GS464E.
	(mips_cpu_info_table): Add gs464e descriptors.
	* doc/as.texi (march table): Add gs464e.

include/
	* elf/mips.h (E_MIPS_MACH_XXX): New E_MIPS_MACH_GS464E.
	* opcode/mips.h (CPU_XXX): New CPU_GS464E.

ld/
	* testsuite/ld-mips-elf/mips-elf-flags.exp: Run good_combination
	gs464e and gs464.

opcodes/
	* mips-dis.c (mips_arch_choices): Add gs464e descriptors.
2018-08-29 20:43:19 +08:00
Chenghua Xu ac8cb70f36 [MIPS] Add Loongson 3A1000 proccessor support.
bfd/
	* archures.c (bfd_architecture): Rename
	bfd_mach_mips_loongson_3a to bfd_mach_mips_gs464.
	* bfd-in2.h (bfd_architecture): Likewise.
	* cpu-mips.c (enum I_xxx): Likewise.
	(arch_info_struct): Likewise.
	* elfxx-mips.c (_bfd_elf_mips_mach): Likewise.
	(mips_set_isa_flags): Likewise.
	(mips_mach_extensions): Likewise.
	(bfd_mips_isa_ext_mach): Likewise.
	(bfd_mips_isa_ext): Likewise.
	(print_mips_isa_ext): Delete AFL_EXT_LOONGSON_3A.

binutils/
	* NEWS: Mention Loongson 3A1000 proccessor support.
	* readelf.c (get_machine_flags): Rename loongson-3a to gs464.
	(print_mips_isa_ext): Delete AFL_EXT_LOONGSON_3A.

elfcpp/
	* mips.c (EF_MIPS_MACH): Rename E_MIPS_MACH_LS3A to
	E_MIPS_MACH_GS464.

gas/
	* config/tc-mips.c (ISA_HAS_ODD_SINGLE_FPR): Rename
	CPU_LOONGSON_3A to CPU_GS464.
	(mips_cpu_info_table): Add gs464 descriptors, Keep
	loongson3a as an alias of gs464 for compatibility.
	* doc/as.texi (march table): Rename loongson3a to gs464.
	* testsuite/gas/mips/loongson-3a-mmi.d: Set "ISA Extension"
	flag to None.

gold/
	* mips.cc (Mips_mach, add_machine_extensions, elf_mips_mach):
	Rename loongson3a to gs464.
	(mips_isa_ext_mach, mips_isa_ext): Delete loongson3a.
	(infer_abiflags): Use ases instead of isa_ext for infer ABI
flags.
	(elf_mips_mach_name): Rename loongson3a to gs464.

include/
	* elf/mips.h (E_MIPS_MACH_XXX): Rename E_MIPS_MACH_LS3A to
	E_MIPS_MACH_GS464.
	(AFL_EXT_XXX): Delete AFL_EXT_LOONGSON_3A.
	* opcode/mips.h (INSN_XXX): Delete INSN_LOONGSON_3A.
	(CPU_XXX): Rename CPU_LOONGSON_3A to CPU_GS464.
	* opcode/mips.h (mips_isa_table): Delete CPU_LOONGSON_3A case.

ld/
	* testsuite/ld-mips-elf/mips-elf-flags.exp: Rename loongson3a
	to gs464.

opcodes/
	* mips-dis.c (mips_arch_choices): Add gs464 descriptors, Keep
	loongson3a as an alias of gs464 for compatibility.
	* mips-opc.c (mips_opcodes): Change Comments.
2018-08-29 20:32:30 +08:00
Chenghua Xu a693765e23 [MIPS/GAS] Add Loongson EXT2 Instructions support.
bfd/
	* elfxx-mips.c (print_mips_ases): Add Loongson EXT2 extension.

binutils/
	* readelf.c (print_mips_ases): Add Loongson EXT2 extension.

gas/
	* NEWS: Mention Loongson EXTensions R2 (EXT2) support.
	* config/tc-mips.c (options): Add OPTION_LOONGSON_EXT2 and
	OPTION_NO_LOONGSON_EXT2.
	(md_longopts): Likewise.
	(mips_ases): Define availability for EXT.
	(mips_convert_ase_flags): Map ASE_LOONGSON_EXT2 to
	AFL_ASE_LOONGSON_EXT2.
	(md_show_usage): Add help for -mloongson-ext2 and
	-mno-loongson-ext2.
	* doc/as.texi: Document -mloongson-ext2, -mno-loongson-ext2.
	* doc/c-mips.texi: Document -mloongson-ext2, -mno-loongson-ext2,
	.set loongson-ext2 and .set noloongson-ext2.
	* testsuite/gas/mips/loongson-ext2.d: New test.
	* testsuite/gas/mips/loongson-ext2.s: New test.
	* testsuite/gas/mips/mips.exp: Run loongson-ext2 test.

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

opcodes/
	* mips-dis.c (parse_mips_ase_option): Handle -M loongson-ext
	option.
	(print_mips_disassembler_options): Document -M loongson-ext.
	* mips-opc.c (LEXT2): New macro.
	(mips_opcodes): Add cto, ctz, dcto, dctz instructions.
2018-08-29 20:08:58 +08:00
Chenghua Xu bdc6c06e3b [MIPS/GAS] Split Loongson EXT Instructions from loongson3a.
bfd/
	 * elfxx-mips.c (infer_mips_abiflags): Use ases instead of
	 isa_ext for infer ABI flags.
	 (print_mips_ases): Add Loongson EXT extension.

binutils/
	 * readelf.c (print_mips_ases): Add Loongson EXT extension.

elfcpp/
	 * mips.h (AFL_ASE_LOONGSON_EXT): New enum.

gas/
	 * NEWS: Mention Loongson EXTensions (EXT) support.
	 * config/tc-mips.c (options): Add OPTION_LOONGSON_EXT and
	 OPTION_NO_LOONGSON_EXT.
	 (md_longopts): Likewise.
	 (mips_ases): Define availability for EXT.
	 (mips_convert_ase_flags): Map ASE_LOONGSON_EXT to
	 AFL_ASE_LOONGSON_EXT.
	 (mips_cpu_info_table): Add ASE_LOONGSON_EXT for loongson3a.
	 (md_show_usage): Add help for -mloongson-ext and
	 -mno-loongson-ext.
	 * doc/as.texi: Document -mloongson-ext, -mno-loongson-ext.
	 * doc/c-mips.texi: Document -mloongson-ext, -mno-loongson-ext,
	 .set loongson-ext and .set noloongson-ext.
	 * testsuite/gas/mips/loongson-mmi.d: Add ASE flag.

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

opcodes/
	 * mips-dis.c (mips_arch_choices): Add EXT to loongson3a
	 descriptors.
	 (parse_mips_ase_option): Handle -M loongson-ext option.
	 (print_mips_disassembler_options): Document -M loongson-ext.
	 * mips-opc.c (IL3A): Delete.
	 * mips-opc.c (LEXT): New macro.
	 (mips_opcodes): Replace IL2F|IL3A marking with LEXT for EXT
	 instructions.
2018-08-29 19:57:39 +08:00
Chenghua Xu 716c08de28 [MIPS/GAS] Split Loongson CAM Instructions from loongson3a
bfd/
	* elfxx-mips.c (print_mips_ases): Add CAM extension.

binutils/
	* readelf.c (print_mips_ases): Add CAM extension.

gas/
	* NEWS: Mention Loongson Content Address Memory (CAM)
	support.
	* config/tc-mips.c (options): Add OPTION_LOONGSON_CAM and
	OPTION_NO_LOONGSON_CAM.
	(md_longopts): Likewise.
	(mips_ases): Define availability for CAM.
	(mips_convert_ase_flags): Map ASE_LOONGSON_CAM to
	AFL_ASE_LOONGSON_CAM.
	(mips_cpu_info_table): Add ASE_LOONGSON_CAM for loongson3a.
	(md_show_usage): Add help for -mloongson-cam and
	-mno-loongson-cam.
	* doc/as.texi: Document -mloongson-cam, -mno-loongson-cam.
	* doc/c-mips.texi: Document -mloongson-cam, -mno-loongson-cam,
	.set loongson-cam and .set noloongson-cam.
	* testsuite/gas/mips/loongson-3a-2.d: Move cam test to ...
	* testsuite/gas/mips/loongson-cam.d: Here.  Add ISA/ASE
	flag verification.
	* testsuite/gas/mips/loongson-3a-2.s: Move cam test to ...
	* testsuite/gas/mips/loongson-cam.s: Here.
	* testsuite/gas/mips/loongson-3a-mmi.d: Add ASE flag.
	* testsuite/gas/mips/mips.exp: Run loongson-cam test.

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

opcodes/
	* mips-dis.c (mips_arch_choices): Add CAM to loongson3a
	descriptors.
	(parse_mips_ase_option): Handle -M loongson-cam option.
	(print_mips_disassembler_options): Document -M loongson-cam.
	* mips-opc.c (LCAM): New macro.
	(mips_opcodes): Replace IL2F|IL3A marking with LCAM for CAM
	instructions.
2018-08-29 19:33:09 +08:00
H.J. Lu 90c745dc54 x86: Don't mask out the GNU_PROPERTY_X86_UINT32_VALID bit
Since only the GNU_PROPERTY_X86_UINT32_VALID bit may be set in data-only
relocatable objects which don't contain any instructions, linker
shouldn't mask out the GNU_PROPERTY_X86_UINT32_VALID bit when merging
GNU_PROPERTY_X86_XXX bits.  Otherwise, linker output doesn't contain
GNU_PROPERTY_X86_XXX property with any data-only relocatable inputs.
This patch keeps the GNU_PROPERTY_X86_UINT32_VALID bit and updates
readelf to print "<None>" if GNU_PROPERTY_X86_XXX property only has
the GNU_PROPERTY_X86_UINT32_VALID bit.

bfd/

	* elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Don't mask
	out the GNU_PROPERTY_X86_UINT32_VALID bit.

binutils/

	* readelf.c (decode_x86_isa): Print <None> if bitmask only
	contains the GNU_PROPERTY_X86_UINT32_VALID bit.
	(decode_x86_feature_1): Likewise.
	(decode_x86_feature_2): Likewise.
	(print_gnu_property_note): Don't mask out the
	GNU_PROPERTY_X86_UINT32_VALID bit.
	* testsuite/binutils-all/i386/pr21231b.d: Updated.
	* testsuite/binutils-all/x86-64/pr21231b.d: Likewise.

gas/

	* testsuite/gas/i386/i386.exp: Run property-1 and
	x86-64-property-1.
	* testsuite/gas/i386/property-1.d: New file.
	* testsuite/gas/i386/property-1.s: Likewise.
	* testsuite/gas/i386/x86-64-property-1.d: Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Run property-x86-5.
	* testsuite/ld-i386/property-x86-5.d: New file.
	* testsuite/ld-x86-64/property-x86-5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-5a.s: Likewise.
	* testsuite/ld-x86-64/property-x86-5b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run property-x86-5 and
	property-x86-5-x32.
2018-08-27 15:42:14 -07:00
H.J. Lu 7a815dd566 elf: Check for corrupt symbol version info
The BFD linker with PR ld/23499 may generate shared libraries with
corrupt symbol version info which leads to linker error when the
corrupt shared library is used:

/usr/bin/ld: bin/libKF5Service.so.5.49.0: _edata: invalid version 21 (max 0)
/usr/bin/ld: bin/libKF5Service.so.5.49.0: error adding symbols: bad value

Add check for corrupt symbol version info to objdump:

00000000000af005 g    D  .data	0000000000000000  <corrupt>   _edata

and readelf:

   728: 00000000000af005     0 NOTYPE  GLOBAL DEFAULT   25 _edata@<corrupt> (5)

bfd/

	PR ld/23499
	* elf.c (_bfd_elf_get_symbol_version_string): Return
	_("<corrupt>") for corrupt symbol version info.

binutils/

	PR ld/23499
	* readelf.c (get_symbol_version_string): Return _("<corrupt>")
	for corrupt symbol version info.
2018-08-25 06:18:06 -07:00
H.J. Lu a9eafb08b3 x86: Update GNU_PROPERTY_X86_XXX macros
This patch updates GNU_PROPERTY_X86_XXX macros:

1. GNU_PROPERTY_X86_UINT32_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_AND_LO      0xc0000002
 #define GNU_PROPERTY_X86_UINT32_AND_HI      0xc0007fff

2. GNU_PROPERTY_X86_UINT32_OR_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_LO    0xc0008000
 #define GNU_PROPERTY_X86_UINT32_OR_HI    0xc000ffff

3. GNU_PROPERTY_X86_UINT32_OR_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs and the property is
present in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_AND_LO   0xc0010000
 #define GNU_PROPERTY_X86_UINT32_OR_AND_HI   0xc0017fff

4. GNU_PROPERTY_X86_FEATURE_2_NEEDED, GNU_PROPERTY_X86_FEATURE_2_USED
and GNU_PROPERTY_X86_FEATURE_2_XXX bits.

GNU_PROPERTY_X86_FEATURE_1_AND is unchanged.  GNU_PROPERTY_X86_ISA_1_USED
and GNU_PROPERTY_X86_ISA_1_NEEDED are updated to better support targeted
processors since GNU_PROPERTY_X86_ISA_1_?86 aren't isn't very useful.
A new set of GNU_PROPERTY_X86_ISA_1_XXX bits are defined.  The previous
GNU_PROPERTY_X86_ISA_1_XXX macros are deprecated and renamed to
GNU_PROPERTY_X86_COMPAT_ISA_1_XXX.

bfd/

	* elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Handle
	X86_COMPAT_ISA_1_USED, X86_COMPAT_ISA_1_NEEDED,
	X86_UINT32_AND_LO, X86_UINT32_AND_HI, X86_UINT32_OR_LO,
	X86_UINT32_OR_HI, X86_UINT32_OR_AND_LO and X86_UINT32_OR_AND_HI
	instead of X86_ISA_1_USED, X86_ISA_1_NEEDED and X86_FEATURE_1_AND.
	(_bfd_x86_elf_merge_gnu_properties): Likewise.
	(_bfd_x86_elf_link_setup_gnu_properties): Add X86_FEATURE_2_NEEDED
	instead of X86_ISA_1_NEEDED.
	(_bfd_x86_elf_link_fixup_gnu_properties): Handle
	X86_COMPAT_ISA_1_USED, X86_COMPAT_ISA_1_NEEDED, X86_UINT32_AND_LO,
	X86_UINT32_AND_HI, X86_UINT32_OR_LO, X86_UINT32_OR_HI,
	X86_UINT32_OR_AND_LO and X86_UINT32_OR_AND_HI instead of
	X86_ISA_1_USED, X86_ISA_1_NEEDED and X86_FEATURE_1_AND.

binutils/

	* readelf.c (decode_x86_compat_isa): New function.
	(decode_x86_feature_2): Likewise.
	(decode_x86_isa): Updated for new X86_ISA_1_XXX bits.
	(decode_x86_feature): Renamed to ...
	(decode_x86_feature_1): This.  Remove the type argument.
	(print_gnu_property_note): Handle X86_COMPAT_ISA_1_USED,
	X86_COMPAT_ISA_1_NEEDED, X86_UINT32_AND_LO, X86_UINT32_AND_HI,
	X86_UINT32_OR_LO, X86_UINT32_OR_HI, X86_UINT32_OR_AND_LO and
	X86_UINT32_OR_AND_HI instead of X86_ISA_1_USED, X86_ISA_1_NEEDED
	and X86_FEATURE_1_AND.
	* testsuite/binutils-all/i386/pr21231b.s: Updated to the current
	GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED
	values.
	* testsuite/binutils-all/x86-64/pr21231b.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494b.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c.s: Likewise.
	* testsuite/binutils-all/i386/pr21231b.d: Updated.
	* testsuite/binutils-all/x86-64/pr21231b.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494e.d: Likewise.

include/

	* elf/common.h (GNU_PROPERTY_X86_ISA_1_USED): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_ISA_1_USED): This.
	(GNU_PROPERTY_X86_ISA_1_NEEDED): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED): This.
	(GNU_PROPERTY_X86_ISA_1_XXX): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_ISA_1_XXX): This.
	(GNU_PROPERTY_X86_UINT32_AND_LO): New.
	(GNU_PROPERTY_X86_UINT32_AND_HI): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_LO): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_HI): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_AND_LO): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_AND_HI): Likewise.
	(GNU_PROPERTY_X86_ISA_1_CMOV): Likewise.
	(GNU_PROPERTY_X86_ISA_1_SSE): Likewise.
	(GNU_PROPERTY_X86_ISA_1_SSE2): Likewise.
	(GNU_PROPERTY_X86_ISA_1_SSE3): Likewise.
	(GNU_PROPERTY_X86_ISA_1_SSSE3): Likewise.
	(GNU_PROPERTY_X86_ISA_1_SSE4_1): Likewise.
	(GNU_PROPERTY_X86_ISA_1_SSE4_2): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX2): Likewise.
	(GNU_PROPERTY_X86_ISA_1_FMA): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512F): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512CD): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512ER): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512PF): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512VL): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512DQ): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512BW): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512_BITALG): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512_IFMA): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512_VBMI): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2): Likewise.
	(GNU_PROPERTY_X86_ISA_1_AVX512_VNNI): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_X86): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_X87): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_MMX): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_XMM): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_YMM): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_ZMM): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_FXSR): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_XSAVE): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_XSAVEC): Likewise.
	(GNU_PROPERTY_X86_FEATURE_1_AND): Updated to
	(GNU_PROPERTY_X86_UINT32_AND_LO + 0).
	(GNU_PROPERTY_X86_ISA_1_NEEDED): Defined to
	(GNU_PROPERTY_X86_UINT32_OR_LO + 0).
	(GNU_PROPERTY_X86_FEATURE_2_NEEDED): New.  Defined to
	(GNU_PROPERTY_X86_UINT32_OR_LO + 1).
	(GNU_PROPERTY_X86_ISA_1_USED): Defined to
	(GNU_PROPERTY_X86_UINT32_OR_AND_LO + 0).
	(GNU_PROPERTY_X86_FEATURE_2_USED): New.  Defined to
	(GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1).

ld/

	* testsuite/ld-i386/i386.exp: Run pr23372c, pr23372d, pr23486c
	and pr23486d.
	* testsuite/ld-i386/pr23372a.s: Update comments.
	* testsuite/ld-i386/pr23372b.s: Likewise.
	* testsuite/ld-i386/pr23372c.s: Likewise.
	* testsuite/ld-x86-64/pr23372a.s: Likewise.
	* testsuite/ld-x86-64/pr23372b.s: Likewise.
	* testsuite/ld-x86-64/pr23372c.s: Likewise.
	* testsuite/ld-x86-64/pr23486a.s: Likewise.
	* testsuite/ld-x86-64/pr23486b.s: Likewise.
	* testsuite/ld-i386/pr23372c.d: New file.
	* testsuite/ld-i386/pr23372d.d: Likewise.
	* testsuite/ld-i386/pr23486c.d: Likewise.
	* testsuite/ld-i386/pr23486d.d: Likewise.
	* testsuite/ld-x86-64/pr23372c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372c.d: Likewise.
	* testsuite/ld-x86-64/pr23372d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372d.d: Likewise.
	* testsuite/ld-x86-64/pr23372d.s: Likewise.
	* testsuite/ld-x86-64/pr23372e.s: Likewise.
	* testsuite/ld-x86-64/pr23372f.s: Likewise.
	* testsuite/ld-x86-64/pr23486c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23486c.d: Likewise.
	* testsuite/ld-x86-64/pr23486c.s: Likewise.
	* testsuite/ld-x86-64/pr23486d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23486d.d: Likewise.
	* testsuite/ld-x86-64/pr23486d.s: Likewise.
	* testsuite/ld-i386/property-3.r: Updated.
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-i386/property-x86-3.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: Likewise.
	* testsuite/ld-x86-64/property-x86-3-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-3.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-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-i386/property-x86-1.S: Updated to the current
	GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED
	values.
	* testsuite/ld-i386/property-x86-2.S: Likewise.
	* testsuite/ld-i386/property-x86-3.s: Likewise.
	* testsuite/ld-x86-64/property-x86-1.S: Likewise.
	* testsuite/ld-x86-64/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/property-x86-3.s: Likewise.
	* ld/testsuite/ld-x86-64/x86-64.exp: Run pr23372c, pr23372c-x32,
	pr23372d, pr23372d-x32, pr23486c, pr23486c-x32, pr23486d and
	pr23486d-x32.
2018-08-24 04:42:15 -07:00
H.J. Lu aa7bca9b2e x86: Add GNU_PROPERTY_X86_UINT32_VALID
The older linker treats .note.gnu.property section as a generic note
and just concatenates all .note.gnu.property sections from the input
to the output.  On CET-enabled OS, the output of the older linker is
marked as CET enabled, but in fact, it is not CET enabled and it crashes
on CET-enabled machines.

This patch defines GNU_PROPERTY_X86_UINT32_VALID.  Linker is updated to
set the GNU_PROPERTY_X86_UINT32_VALID bit in GNU property note for
non-relocatable output to differentiate outputs from the older linker.

bfd/

	* elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Mask out the
	GNU_PROPERTY_X86_UINT32_VALID bit.
	(_bfd_x86_elf_link_fixup_gnu_properties): Set the
	GNU_PROPERTY_X86_UINT32_VALID bit for non-relocatable output.

binutils/

	* readelf.c (print_gnu_property_note): Check the
	GNU_PROPERTY_X86_UINT32_VALID bit for invalid GNU property note.

include/

	* elf/common.h (GNU_PROPERTY_X86_UINT32_VALID): New.
2018-08-24 04:38:02 -07:00
Zenith423 b0ceb98aec Avoid problems with plugins being loaded multiple times.
PR 23460
	* plugin.c (struct plugin_list_entry): New structure.
	(plugin_list): New variable.
	(try_load_plugin): Place opened plugins on a list.  Ensure that
	the refcount in the dynamic loader is kept at 1.
2018-08-23 16:22:56 +01:00
Alan Modra f53ad3cf2b PowerPC64 "call lacks nop"
The "-fPIC" and "-mcmodel=small" parts of these messages isn't always
true, so lets dispense with that and just report the type of stub
causing trouble.

	* elf64-ppc.c (ppc64_elf_relocate_section): Revise "call lacks
	nop" error message.
2018-08-24 00:23:27 +09:30
Nick Clifton 38cf70ca4d Replace unworkable code in HPPA relocs handelr with an assertion.
* elf64-hppa.c (elf_hppa_final_link_relocate): Replace unworkable
	code with an assertion.
2018-08-23 13:34:14 +01:00
Nick Clifton 334d4ced42 Prevent illegal memory access when processing COFF auxillary symbol information.
PR 23061
	* coffgen.c (coff_pointerize_aux): Add table_end parameter.  Use
	it to prevent walking off the end of the table.
	(coff_get_normalized_symtab): Pass internal_end pointer to
	coff_pointerize_aux.
2018-08-23 11:45:38 +01:00
Alan Modra d0abeec8d4 Fix "unresolved reloc" error for NOTOC relocs
* elf64-ppc.c (ppc64_elf_relocate_section): Don't miss clearing
	unresolved_reloc on ppc_stub_plt_call_notoc.
2018-08-23 13:54:24 +09:30
H.J. Lu 9eef060895 bfd/development.sh: Add experimental
Add experimental to indicate whether this is a release branch.

	PR ld/23536
	* development.sh (experimental): New.
2018-08-22 10:32:23 -07:00
Helge Deller 6f4286c4f7 Use the correct constants when setting the section type of HPPA unwind sections.
* elf-hppa.h (elf_hppa_fake_sections): Use SHT_PARISC_UNWIND as
	the section type of the .PARISC.unwind section on 64-bit binaries
	and SHT_PROGBITS for 32-bit binaries.  Add a comment about it.
	Add comment about the sh_entsize value.
2018-08-22 10:32:53 +01:00
Rafeal Auler 3da64fe404 Fix AArch64 stub layout algorithm to allow for the fact that section layut might change a stub's target location.
PR 23560
	* elfnn-aarch64.c (elfNN_aarch64_size_stubs): Always update the
	stub's target, since it may have been changed after the layout.
2018-08-22 10:04:09 +01:00
Alan Modra ebf983a444 Fix changelog entries 2018-08-22 16:38:55 +09:30
John Darrington 4e57b45639 S12Z: Rename reloc R_S12Z_UKNWN_3 to R_S12Z_EXT18 and implement according to recently inferred information about this reloc.
* bfd/elf32-s12z.c: (opru18_reloc): New function.
* bfd/elf32-s12z.c: (elf_s12z_howto_table): Adjust Howto according to new knowledge.
* include/elf/s12z.h: Rename R_S12Z_UKNWN_3 to R_S12Z_EXT18.
2018-08-21 19:24:21 +02:00
mephi42 ae19acf320 Fix running objcopy on Mach-O binaries.
PR binutils/23315
	* mach-o.c (bfd_mach_o_mangle_symbols): Update n_type even if
	data is already considered filled.
2018-08-21 16:34:56 +01:00
Alan Modra 46807bf451 PowerPC HOWTOs
These take up far too many lines in the files.  This patch introduces
a replacement for the HOWTO macro that simplifies the relow howto
initialization.  Apart from the two relocs mentioned in the ChangeLog,
no relocation howto is changed.

	* elf64-ppc.c (HOW): Define.
	(ONES): Delete.
	(ppc64_elf_howto_raw): Use HOW to initialize entries.
	* elf32-ppc.c (HOW): Define.
	(ppc_elf_howto_raw): Use HOW to initialize entries, updating
	R_PPC_VLE_REL15 and R_PPC_VLE_REL24 to use bitpos=0.
2018-08-21 14:59:53 +09:30
Alan Modra 706704c883 Pack reloc_howto_struct
This patch uses bitfields in reloc_howto_struct, reducing its size
from 80 to 40 bytes on 64-bit hosts and from 52 to 32 bytes on 32-bit
hosts (with a 32-bit bfd_vma).  I've also added a new "negate" field
rather than making the encoded "size" field do double duty as both
a size and a flag.

There was just one use of an encoded size of 8, which according to
bfd_get_reloc_size meant 16 bytes, in vms-alpha.c ALPHA_R_LINKAGE.
See git commit c3d8e071bf adding ALPHA_R_LINKAGE and git commit
8612a388f7 decoding size 8 in bfd_get_reloc_size.  Since no other part
of BFD handles 16 byte relocs, I've removed that encoding and special
cased the ALPHA_R_LINKAGE size in vms-alpha.c.

	* reloc.c (reloc_howto_type): Typedef.
	(bfd_symbol): Delete forward declaration.
	(struct reloc_howto_struct): Add "negate" field.  Make "size",
	"bitsize", "rightshift", "bitpos", "complain_on_overflow",
	"pc_relative", "partial_inplace", and "pcrel_offset" bitfields.
	Rearrange for better packing.  Revise comments.
	(HOWTO): Map to rearranged reloc_howto_struct.
	(bfd_get_reloc_size): Delete now unused cases.
	(read_reloc, write_reloc): Likewise.
	(apply_reloc, _bfd_relocate_contents): Test howto->negate
	rather than howto->size < 0 for negated relocation values.
	* coff-rs6000.c (xcoff_complain_overflow_bitfield_func): Avoid
	signed/unsigned warning.
	(xcoff_ppc_relocate_section): Delete "condition is always false"
	code.
	* coff64-rs6000.c (xcoff64_ppc_relocate_section): Likewise.
	* cpu-ns32k.c (do_ns32k_reloc): Adjust to suit reloc_howto_struct
	changes.
	* vms-alpha.c (_bfd_vms_write_etir, alpha_vms_slurp_relocs): Use
	size 16 for ALPHA_R_LINKAGE.
	(alpha_howto_table <ALPHA_R_LINKAGE>): Set encoded size and
	bitsize to zero.
	* bfd-in.h (reloc_howto_type): Delete.
	* bfd-in2.h: Regenerate.
2018-08-21 14:59:53 +09:30
Alan Modra 487096bf0b Delete NEWHOWTO and tidy some uses of reloc_howto_struct
NEWHOWTO was promised way back in 1991 (git commit e568362218).
I doubt it's ever going to be implemented.  This patch removes it,
and tidies some reloc howtos.  I was going to make some changes to
reloc_howto_struct, so I think it's important that all relocs howtos
are initialized with HOWTO.

	* reloc.c (HOWTO): Revise comment.
	(NEWHOWTO, HOWTO_PREPARE): Delete.
	* coff-arm.c (coff_arm_reloc_type_lookup): Replace const struc
	reloc_howto_struct with reloc_howto_type.
	* ns32knetbsd.c (MY_bfd_reloc_type_lookup): Likewise.
	* vms-alpha.c (alpha_vms_bfd_reloc_type_lookup): Likewise.
	* elf-hppa.h (HOW): Define.
	(elf_hppa_howto_table): Use it to simplify this table, correcting
	name of R_PARISC_LTOFF16WF, R_PARISC_LTOFF_FPTR64, and
	R_PARISC_LTOFF_FPTR16DF.
	* elf32-mep.c (MEPREL): Use HOWTO.
	* bfd-in2.h: Regenerate.
2018-08-21 14:59:53 +09:30
Alan Modra 865dcc8a4d Don't init array at run time
When it can be done at compile time.

	* mmo.c (valid_mmo_symbol_character_set): Initialize and make
	array const.
	(mmo_init): Don't init valid_mmo_symbol_character_set.
2018-08-20 09:54:20 +09:30
Alan Modra ba1c4c6fee Balance parentheses in expression
* rs6000-core.c (CORE_COMMONSZ): Balance parentheses in expression.
2018-08-20 09:45:02 +09:30
H.J. Lu bfb1e8c15a x86: Remove empty X86_FEATURE_1_AND property
There is no need to generate .note.gnu.property section with empty
X86_FEATURE_1_AND property.  This patch adds fixup_gnu_properties
to ELF linker backend so that x86 backend can remove it.

bfd/

	PR ld/23515
	* elf-bfd.h (elf_backend_data): Add fixup_gnu_properties.
	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Call
	backend fixup_gnu_properties if it isn't NULL.  Discard
	.note.gnu.property section if all properties have been removed.
	* elfxx-target.h (elf_backend_fixup_gnu_properties): New.
	(elfNN_bed): Initialize fixup_gnu_properties.
	* elfxx-x86.c (_bfd_x86_elf_link_fixup_gnu_properties): New
	function.
	* elfxx-x86.h (_bfd_x86_elf_link_fixup_gnu_properties): New
	prototype.
	(elf_backend_fixup_gnu_properties): New.

ld/

	PR ld/23515
	* testsuite/ld-i386/ibt-plt-2a.d: Updated.
	* testsuite/ld-i386/ibt-plt-2b.d: 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.
2018-08-17 03:54:16 -07:00
Alan Modra 2cdcc33021 Correct elf64-ppc.c linkage stub comment and formatting fixes
ppc_stub_long_branch_notoc will never need more than a 32-bit offset
for the r12 offset since the stub target must be in range of a
branch instruction.

	* elf64-ppc.c: Correct ppc_stub_long_branch_notoc example.
	Formatting.
2018-08-16 22:57:00 +09:30
H.J. Lu 98641896ad bfd: Move elf-properties.lo to BFD32_LIBS
commit 6404ab9937
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Aug 8 21:00:04 2018 -0700

    Convert .note.gnu.property section between ELF32 and ELF64

updated bfd_convert_section_size and bfd_convert_section_contents
in bfd.c to call _bfd_elf_convert_gnu_property_size and
_bfd_elf_convert_gnu_properties, which are defined in elf-properties.c.
It led to

bfd.c:2484: undefined reference to `_bfd_elf_convert_gnu_property_size'

for non-ELF targets.  Since elf-properties.c is a generic implementation
and doesn't reference any ELF specific functions directly, this patch
moves elf-properties.lo BFD32_LIBS.

Tested for many ELF and non-ELF targets.

	PR binutils/23494
	* Makefile.am (BFD32_LIBS): Add elf-properties.lo.
	(BFD32_LIBS_CFILES): Add elf-properties.c.
	(BFD32_BACKENDS): Remove elf-properties.lo.
	(BFD32_BACKENDS_CFILES): Remove elf-properties.c.
	* configure.ac (elf): Remove elf-properties.lo.
	* Makefile.in: Regenerated.
	* configure: Likewise.
2018-08-13 07:24:44 -07:00
H.J. Lu ab9e342807 x86: Properly add X86_ISA_1_NEEDED property
Existing properties may be removed during property merging.  We avoid
adding X86_ISA_1_NEEDED property only if existing properties won't be
removed.

bfd/

	PR ld/23428
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Don't
	add X86_ISA_1_NEEDED property only if existing properties won't
	be removed.

ld/

	PR ld/23428
	* testsuite/ld-elf/dummy.s: New file.
	* testsuite/ld-elf/linux-x86.S: Add X86_FEATURE_1_AND property.
	* testsuite/ld-elf/linux-x86.exp: Add dummy.s to pr23428.
2018-08-11 06:41:33 -07:00
Alan Modra 1dc9e2d63e Factor out common relocation processing
This patch factors out some code common to both bfd_perform_relocation
and bfd_install_relocation, in the process fixing the omission of
"case -1" in bfd_install_relocation.

	* reloc.c (bfd_get_reloc_size): Sort switch.
	(read_reloc, write_reloc, apply_reloc): New functions.
	(bfd_perform_relocation, bfd_install_relocation): Use apply_reloc.
	(_bfd_relocate_contents): Use read_reloc and write_reloc.
	(_bfd_clear_contents): Likewise.
2018-08-11 13:39:16 +09:30
John Darrington 7cf9ebc695 Deal with relocations which are 3 bytes in size
* reloc.c (_bfd_relocate_contents): Handle 3 byte relocs.
	(_bfd_clear_contents): Likewise.
	(bfd_perform_relocation): Likewise.
	(bfd_install_relocation): Likewise.
2018-08-11 11:11:39 +09:30
H.J. Lu 48e30f5238 Always clear h->verinfo.verdef when overriding a dynamic definition
When linker defines a symbol to override a dynamic definition, it should
always clear h->verinfo.verdef so that the symbol won't be associated
with the version information from the dynamic object.  This happened to
the symbol "_edata" when creating an unversioned dynamic object linking
against:

1. libKF5ConfigCore.so.5.49.0
2. libKF5CoreAddons.so.5.49.0
3. libKF5I18n.so.5.49.0
4. libKF5DBusAddons.so.5.49.0
5. libQt5Xml.so.5.11.1
6. libQt5DBus.so.5.11.1
7. libQt5Core.so.5.11.1

Among them

libQt5Xml.so.5.11.1
   299: 000000000003e000     0 NOTYPE  GLOBAL DEFAULT   18 _edata@@Qt_5
libQt5DBus.so.5.11.1
   597: 0000000000092018     0 NOTYPE  GLOBAL DEFAULT   18 _edata@@Qt_5
libQt5Core.so.5.11.1
  2292: 00000000004df640     0 NOTYPE  GLOBAL DEFAULT   21 _edata@Qt_5
  2293: 00000000004df640     0 NOTYPE  GLOBAL DEFAULT   21 _edata@Qt_5

The problem is triggered by 2 duplicated entries of _edata@Qt_5 in
libQt5Core.so.5.11.1 which was created by gold.  Before this commit,
ld created the dynamic object with "_edata" in its dynamic symbol table
which was linker defined and associated with the version information
from libQt5Core.so.5.11.1.  The code in question was there when the
binutils source was imported to sourceware.org.  When such a dynamic
object was used later, we got:

/usr/bin/ld: bin/libKF5Service.so.5.49.0: _edata: invalid version 21 (max 0)
/usr/bin/ld: bin/libKF5Service.so.5.49.0: error adding symbols: bad value

Tested with many ELF targets.

	PR ld/23499
	* elflink.c (bfd_elf_record_link_assignment): Always clear
	h->verinfo.verdef when overriding a dynamic definition.
2018-08-10 12:22:09 -07:00
H.J. Lu 9c973a29df Always use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE
For GNU_PROPERTY_STACK_SIZE, pr_datasz is the same as align_size, which
is 8 bytes for 64-bit ELF binaries and 4 bytes for 32-bit ELF binaries,
Use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE to convert
.note.gnu.property section.

bfd/

	PR binutils/23494
	* elf-properties.c (elf_get_gnu_property_section_size): Always
	use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE.
	(elf_write_gnu_properties): Likewise.

binutils/

	PR binutils/23494
	* testsuite/binutils-all/x86-64/pr23494c.s: New file.
	* testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494e.d: Likewise.
2018-08-10 08:14:24 -07:00
H.J. Lu 6404ab9937 Convert .note.gnu.property section between ELF32 and ELF64
.note.gnu.property section has different alignments and section
sizes for 32-bit and 64-bit ELF binaries.  This patch updated
bfd_convert_section_size and bfd_convert_section_contents to
properly convert .note.gnu.property section between 32-bit and
64-bit ELF binaries.

bfd/

	PR binutils/23494
	* bfd.c (bfd_convert_section_size): Check BFD_DECOMPRESS after
	calling _bfd_elf_convert_gnu_property_size to convert
	.note.gnu.property section size.
	(bfd_convert_section_contents): Check BFD_DECOMPRESS after
	calling _bfd_elf_convert_gnu_properties to convert
	.note.gnu.property section.
	* elf-bfd.h (_bfd_elf_convert_gnu_property_size): New prototype.
	(_bfd_elf_convert_gnu_properties): Likewise.
	* elf-properties.c (elf_get_gnu_property_section_size): New
	function.
	(elf_write_gnu_properties): Likewise.
	(_bfd_elf_convert_gnu_property_size): Likewise.
	(_bfd_elf_convert_gnu_properties): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Use
	elf_get_gnu_property_section_size and elf_write_gnu_properties.

binutils/

	PR binutils/23494
	* testsuite/binutils-all/x86-64/pr23494a-x32.d: New file.
	* testsuite/binutils-all/x86-64/pr23494a.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494b-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494b.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494b.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d.d: Likewise.
2018-08-08 21:00:18 -07:00
H.J. Lu f7309df20c x86: Properly merge GNU_PROPERTY_X86_ISA_1_USED
Without the GNU_PROPERTY_X86_ISA_1_USED property, all ISAs may be used.
If a bit in the GNU_PROPERTY_X86_ISA_1_USED property is unset, the
corresponding x86 instruction set isn’t used.  When merging properties
from 2 input files and one input file doesn't have the
GNU_PROPERTY_X86_ISA_1_USED property, the output file shouldn't have
it neither.  This patch removes the GNU_PROPERTY_X86_ISA_1_USED
property if an input file doesn't have it.

This patch replaces the GNU_PROPERTY_X86_ISA_1_USED property with the
GNU_PROPERTY_X86_ISA_1_NEEDED property which is the minimum ISA
requirement.

bfd/

	PR ld/23486
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Remove
	GNU_PROPERTY_X86_ISA_1_USED if an input file doesn't have it.
	(_bfd_x86_elf_link_setup_gnu_properties): Adding the
	GNU_PROPERTY_X86_ISA_1_NEEDED, instead of
	GNU_PROPERTY_X86_ISA_1_USED, property.

ld/

	PR ld/23486
	* testsuite/ld-i386/i386.exp: Run PR ld/23486 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr23486a.d: New file.
	* testsuite/ld-i386/pr23486b.d: Likewise.
	* testsuite/ld-x86-64/pr23486a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23486a.d: Likewise.
	* testsuite/ld-x86-64/pr23486a.s: Likewise.
	* testsuite/ld-x86-64/pr23486b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23486b.d: Likewise.
	* testsuite/ld-x86-64/pr23486b.s: Likewise.
	* testsuite/ld-i386/property-3.r: Remove "x86 ISA used".
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-i386/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: 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-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.
2018-08-08 06:09:28 -07:00
Alan Modra df136d64fa PowerPC64 EH info for _notoc linkage stubs
This patch generates EH info for the new _notoc linkage stubs, to
support unwinding from asynchronous signal handlers.  Unwinding
through the __tls_get_addr_opt stub was already supported, but that
was just a single stub.  With multiple stubs the EH opcodes need to be
emitted and sized when iterating over stubs, so this is done when
emitting and sizing the stub code.  Emitting the CIEs and FDEs is done
when sizing the stubs, as we did before in order to have the linker
generated FDEs indexed in .eh_frame_hdr.  I moved the final tweaks to
FDEs from ppc64_elf_finish_dynamic_sections to ppc64_elf_build_stubs
simply because it's tidier to be done with them at that point.

bfd/
	* elf64-ppc.c (struct map_stub): Delete tls_get_addr_opt_bctrl.
	Add lr_restore, eh_size and eh_base.
	(eh_advance, eh_advance_size): New functions.
	(build_tls_get_addr_stub): Emit EH info for stub.
	(ppc_build_one_stub): Likewise for _notoc stubs.
	(ppc_size_one_stub): Size EH info for stub.
	(group_sections): Init new map_stub fields.
	(stub_eh_frame_size): Delete.
	(ppc64_elf_size_stubs): Size EH info for stubs.  Set up dummy EH
	program for stubs.
	(ppc64_elf_build_stubs): Reinit new map_stub fields.  Set FDE
	offset to stub section here..
	(ppc64_elf_finish_dynamic_sections): ..rather than here.
ld/
	* testsuite/ld-powerpc/notoc.s: Generate some cfi.
	* testsuite/ld-powerpc/notoc.d: Adjust.
	* testsuite/ld-powerpc/notoc.wf: New file.
	* testsuite/ld-powerpc/powerpc.exp: Run "ext" and "notoc" tests
	as run_ld_link_tests rather than run_dump_test.
2018-08-07 18:43:55 +09:30
Alan Modra e81b4c933c __tls_get_addr_opt stubs and tocsave optimization
This patch fixes a bug in the handling of the __tls_get_addr_opt
stub.  Calls via this stub don't have a toc restoring instruction
following the "bl", and the stub itself doesn't have an initial toc
save instruction.  Thus it is incorrect to skip over the first
instruction when a __tls_get_addr call is marked with a tocsave
reloc.

	* elf64-ppc.c (ppc64_elf_relocate_section): Don't skip first
	instruction of __tls_get_addr_opt stub.
	(plt_stub_size): Omit ALWAYS_EMIT_R2SAVE condition when
	dealing with __tls_get_addr_opt stub.
	(build_tls_get_addr_stub, ppc_size_one_stub): Likewise.
2018-08-07 18:43:54 +09:30
Claudiu Zissulescu 6af0448446 [ARC] Update warning reporting.
MWDT compiler doesn't use eflags and makes use of 0x0c section. For
those, silence the gnu warning system.

bfd/
  Claudiu Zissulescu <claziss@synopsys.com>

        * elf32-arc.c (arc_elf_merge_private_bfd_data): Complain about
        efalgs only when in/out exists.
        (elf32_arc_section_from_shdr): Don't complain about 0x0c section
        type.  It is mwdt compiler specific.
2018-08-06 16:41:32 +03:00
claziss 2fd43d7870 [ARC] Update merging attributes.
Some attributes were ignored during merging. Fix that, and add some
errors.

bfd/
2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

	* elf32-arc.c (arc_elf_merge_attributes): Fix merge attributes.

ld/
2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

	* testsuite/ld-arc/attr-merge-6.d: New file.
	* testsuite/ld-arc/attr-merge-6a.s: Likewise.
	* testsuite/ld-arc/attr-merge-6b.s: Likewise.
	* testsuite/ld-arc/attr-merge-6bis.d: Likewise.
2018-08-06 16:41:32 +03:00
claziss db1e1b45b4 [ARC] Add Tag_ARC_ATR_version.
Add a new tag (Tag_ARC_ATR_version) used to indicate if current
attributes are interpreted in GNU way. This attribute is used by
Synopsys custom compiler to correctly identify and interpret the
object attributes section as generated by GNU tools.

gas/
2017-08-02  Claudiu Zissulescu <claziss@synopsys.com>

	* config/tc-arc.c (arc_set_public_attributes): Add
	Tag_ARC_ATR_version.
	(arc_convert_symbolic_attribute): Likewise.
	* testsuite/gas/arc/attr-arc600.d: Update test.
	* testsuite/gas/arc/attr-arc600_mul32x16.d: Likewise.
	* testsuite/gas/arc/attr-arc600_norm.d: Likewise.
	* testsuite/gas/arc/attr-arc601.d: Likewise.
	* testsuite/gas/arc/attr-arc601_mul32x16.d: Likewise.
	* testsuite/gas/arc/attr-arc601_mul64.d: Likewise.
	* testsuite/gas/arc/attr-arc601_norm.d: Likewise.
	* testsuite/gas/arc/attr-arc700.d: Likewise.
	* testsuite/gas/arc/attr-arcem.d: Likewise.
	* testsuite/gas/arc/attr-archs.d: Likewise.
	* testsuite/gas/arc/attr-autodetect-1.d: Likewise.
	* testsuite/gas/arc/attr-cpu-a601.d: Likewise.
	* testsuite/gas/arc/attr-cpu-a700.d: Likewise.
	* testsuite/gas/arc/attr-cpu-em.d: Likewise.
	* testsuite/gas/arc/attr-cpu-hs.d: Likewise.
	* testsuite/gas/arc/attr-em.d: Likewise.
	* testsuite/gas/arc/attr-em4.d: Likewise.
	* testsuite/gas/arc/attr-em4_dmips.d: Likewise.
	* testsuite/gas/arc/attr-em4_fpuda.d: Likewise.
	* testsuite/gas/arc/attr-em4_fpus.d: Likewise.
	* testsuite/gas/arc/attr-hs.d: Likewise.
	* testsuite/gas/arc/attr-hs34.d: Likewise.
	* testsuite/gas/arc/attr-hs38.d: Likewise.
	* testsuite/gas/arc/attr-hs38_linux.d: Likewise.
	* testsuite/gas/arc/attr-mul64.d: Likewise.
	* testsuite/gas/arc/attr-name.d: Likewise.
	* testsuite/gas/arc/attr-nps400.d: Likewise.
	* testsuite/gas/arc/attr-override-mcpu.d: Likewise.
	* testsuite/gas/arc/attr-quarkse_em.d: Likewise.

bfd/
2017-08-02  Claudiu Zissulescu <claziss@synopsys.com>

	* elf32-arc.c (arc_elf_merge_attributes): Handle
	Tag_ARC_ATR_version.

binutils/
2017-08-02  Claudiu Zissulescu <claziss@synopsys.com>

	* readelf.c (display_arc_attribute): Print Tag_ARC_ATR_version.

include/
2017-08-02  Claudiu Zissulescu <claziss@synopsys.com>

	* elf/arc.h (Tag_ARC_ATR_version): New tag.

ld/
2017-08-02  Claudiu Zissulescu <claziss@synopsys.com>

	* testsuite/ld-arc/attr-merge-0.d: Update test.
	* testsuite/ld-arc/attr-merge-1.d: Likewise.
	* testsuite/ld-arc/attr-merge-2.d: Likewise.
	* testsuite/ld-arc/attr-merge-3.d: Likewise.
	* testsuite/ld-arc/attr-merge-5.d: Likewise.
2018-08-06 16:41:32 +03:00
Alan Modra 05d0e962f0 R_PPC64_REL24_NOTOC support
R_PPC64_REL24_NOTOC is used on calls like "bl foo@notoc" to tell the
linker that linkage stubs for PLT calls or long branches can't use r2
for pic addressing.  Instead, new stubs that generate pc-relative
addresses are used.  One complication is that pc-relative offsets to
the PLT may need to be 64-bit in large programs, in contrast to the
toc-relative addressing used by older PLT linkage stubs where a 32-bit
offset is sufficient until the PLT itself exceeds 2G in size.

.eh_frame info to cover the _notoc stubs is yet to be implemented.

bfd/
	* elf64-ppc.c (ADDI_R12_R11, ADDI_R12_R12, LIS_R12),
	(ADDIS_R12_R11, ORIS_R12_R12_0, ORI_R12_R12_0),
	(SLDI_R12_R12_32, LDX_R12_R11_R12, ADD_R12_R11_R12): Define.
	(ppc64_elf_howto_raw): Add R_PPC64_REL24_NOTOC entry.
	(ppc64_elf_reloc_type_lookup): Support R_PPC64_REL24_NOTOC.
	(ppc_stub_type): Add ppc_stub_long_branch_notoc,
	ppc_stub_long_branch_both, ppc_stub_plt_branch_notoc,
	ppc_stub_plt_branch_both, ppc_stub_plt_call_notoc, and
	ppc_stub_plt_call_both.
	(is_branch_reloc): Add R_PPC64_REL24_NOTOC.
	(build_offset, size_offset): New functions.
	(plt_stub_size): Support plt_call_notoc and plt_call_both.
	(ppc_build_one_stub, ppc_size_one_stub): Support new stubs.
	(toc_adjusting_stub_needed): Handle R_PPC64_REL24_NOTOC.
	(ppc64_elf_size_stubs): Likewise, and new stubs.
	(ppc64_elf_build_stubs, ppc64_elf_relocate_section): Likewise.
	* reloc.c: Add BFD_RELOC_PPC64_REL24_NOTOC.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
gas/
	* config/tc-ppc.c (ppc_elf_suffix): Support @notoc.
	(ppc_force_relocation, ppc_fix_adjustable): Handle REL24_NOTOC.
ld/
	* testsuite/ld-powerpc/ext.d,
	* testsuite/ld-powerpc/ext.s,
	* testsuite/ld-powerpc/ext.lnk,
	* testsuite/ld-powerpc/notoc.d,
	* testsuite/ld-powerpc/notoc.s: New tests.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2018-08-05 12:11:51 +09:30
Alan Modra 3f6ff4799b Lose _r2off in powerpc64 stub names
Not a lot is conveyed by putting _r2off in a stub symbol that can't be
seen by inspecting the stub code or the toc restoring instruction
immediately after a call via such a stub.  Also, we don't distinguish
plt_call stub symbols from plt_call_r2save stub symbols, so this patch
makes long branch and plt branch stub symbols consistent with that
decision.

bfd/
	* elf64-ppc.c (ppc_build_one_stub): Lose "_r2off" in stub symbols.
ld/
	* testsuite/ld-powerpc/elfv2exe.d: Adjust for stub symbol change.
	* testsuite/ld-powerpc/tocopt6.d: Likewise.
2018-08-05 10:33:07 +09:30
Jim Wilson 13755f406d RISC-V: Fix TLS and --gc-sections conflict.
bfd/
	* elfnn-riscv.c (riscv_elf_create_dynamic_sections): For .tdata.dyn,
	add SEC_LINKER_CREATED flag.
2018-08-02 16:13:49 -07:00
Nick Clifton c25179e71f Suppress compile time warning message when compiling coff-rs6000.c with gcc v8.
* coff-rs6000.c (_bfd_xcoff_put_ldsymbol_name): Suppress warnings
	about potentially truncated strncpy operations.
	(_bfd_xcoff_put_symbol_name): Likewise.
2018-08-01 14:46:43 +01:00
Nick Clifton 4a9f7d653c Fix potential illegal memory access in AVR backend.
* elf32-avr.c (avr_stub_name): Check for a NULL return from
	bfd_malloc.
2018-08-01 14:42:37 +01:00
Nick Clifton 103da91bc0 Close resource leaks in the BFD library's plugin handler.
PR 23460
	* plugin.c (bfd_plugin_open_input): Close file descriptor if the
	call to fstat fails.
	(try_claim): Always close the file descriptor at the end of the
	function.
	(try_load_plugin): If a plugin has already been registered, then
	skip the dlopen and onload steps and go straight to claiming the
	file.  If these is an error, close the plugin.
2018-08-01 14:34:41 +01:00
Alan Modra 1aa4214141 PowerPC64 __tls_get_addr_opt stub .eh_frame fix
This patch sets stub_offset in ppc_size_one_stub rather than in
ppc_build_one_stub.  That allows the plt stub alignment to be done in
just ppc_size_one_stub rather than both functions.  The patch also
corrects the place where the alignment was done, fixing a possible
error in .eh_frame data, and tidies some offset calculations.

bfd/
	* elf64-ppc.c (plt_stub_pad): Delay plt_stub_size call until needed.
	(ppc_build_one_stub): Don't set stub_offset, instead assert that
	it is sane.  Don't adjust stub_offset for alignment.  Adjust size
	calculation.  Use "targ" temp when calculating offsets.
	(ppc_size_one_stub): Set stub_offset here.  Use "targ" temp when
	calculating offsets.  Adjust for alignment before setting
	tls_get_addr_opt_bctrl.
ld/
	* testsuite/ld-powerpc/powerpc.exp: Run tlsopt5 with plt alignment.
	* testsuite/ld-powerpc/tlsopt5.s: Add extra call.
	* testsuite/ld-powerpc/tlsopt5.wf: Adjust expected output.
	* testsuite/ld-powerpc/tlsopt5.d: Likewise.
2018-08-01 12:14:22 +09:30
Alan Modra cb86a42aba csky regen
bfd/
	* po/SRC-POTFILES.in: Regenerate.
gas/
	* po/POTFILES.in: Regenerate.
ld/
	* po/BLD-POTFILES.in: Regenerate.
opcodes/
	* po/POTFILES.in: Regenerate.
2018-08-01 10:32:56 +09:30
Nick Clifton a05b9f5e1e Prevent a seg-fault in the linker when trying to process SH object files with bogus relocs.
PR 22706
	* elf32-sh.c (sh_elf_relocate_section): When processing
	translation relocs, fail if the relocation offset is too small.
	Replace BFD_ASSERTs with more helpful error messages.
2018-07-30 13:58:15 +01:00
Andrew Jenner b8891f8d62 Add support for the C_SKY series of processors.
This patch series is a new binutils port for C-SKY processors, including support for both the V1 and V2 processor variants.  V1 is derived from the MCore architecture while V2 is substantially different, with mixed 16- and 32-bit instructions, a larger register set, a different (but overlapping) ABI, etc.  There is support for bare-metal ELF targets and Linux with both glibc and uClibc.

This code is being contributed jointly by C-SKY Microsystems and Mentor Graphics.  C-SKY is responsible for the technical content and has proposed Lifang Xia and Yunhai Shang as port maintainers.  (Note that C-SKY does have a corporate copyright assignment on file with the FSF.) Mentor Graphics' role has been cleaning up the code, adding documentation and additional test cases, etc, to address issues we anticipated reviewers would complain about.

bfd     * Makefile.am (ALL_MACHINES, ALL_MACHINES_CFILES): Add C-SKY.
        (BFD32_BACKENDS, BFD_BACKENDS_CFILES): Likewise.
        * Makefile.in: Regenerated.
        * archures.c (enum bfd_architecture): Add bfd_arch_csky and
        related bfd_mach defines.
        (bfd_csky_arch): Declare.
        (bfd_archures_list): Add C-SKY.
        * bfd-in.h (elf32_csky_build_stubs): Declare.
        (elf32_csky_size_stubs): Declare.
        (elf32_csky_next_input_section: Declare.
        (elf32_csky_setup_section_lists): Declare.
        * bfd-in2.h: Regenerated.
        * config.bfd: Add C-SKY.
        * configure.ac: Likewise.
        * configure: Regenerated.
        * cpu-csky.c: New file.
        * elf-bfd.h (enum elf_target_id): Add C-SKY.
        * elf32-csky.c: New file.
        * libbfd.h: Regenerated.
        * reloc.c: Add C-SKY relocations.
        * targets.c (csky_elf32_be_vec, csky_elf32_le_vec): Declare.
        (_bfd_target_vector): Add C-SKY target vector entries.

binutils* readelf.c: Include elf/csky.h.
        (guess_is_rela): Handle EM_CSKY.
        (dump_relocations): Likewise.
        (get_machine_name): Likewise.
        (is_32bit_abs_reloc): Likewise.

include  * dis-asm.h (csky_symbol_is_valid): Declare.
         * opcode/csky.h: New file.

opcodes  * Makefile.am (TARGET_LIBOPCODES_CFILES): Add csky-dis.c.
         * Makefile.in: Regenerated.
         * configure.ac: Add C-SKY.
         * configure: Regenerated.
         * csky-dis.c: New file.
         * csky-opc.h: New file.
         * disassemble.c (ARCH_csky): Define.
         (disassembler, disassemble_init_for_target): Add case for ARCH_csky.
         * disassemble.h (print_insn_csky, csky_get_disassembler): Declare.

gas      * Makefile.am (TARGET_CPU_CFILES): Add entry for C-SKY.
         (TARGET_CPU_HFILES, TARGET_ENV_HFILES): Likewise.
         * Makefile.in: Regenerated.
         * config/tc-csky.c: New file.
         * config/tc-csky.h: New file.
         * config/te-csky_abiv1.h: New file.
         * config/te-csky_abiv1_linux.h: New file.
         * config/te-csky_abiv2.h: New file.
         * config/te-csky_abiv2_linux.h: New file.
         * configure.tgt: Add C-SKY.
         * doc/Makefile.am (CPU_DOCS): Add entry for C-SKY.
         * doc/Makefile.in: Regenerated.
         * doc/all.texi: Set CSKY feature.
         * doc/as.texi (Overview): Add C-SKY options.
         (Machine Dependencies): Likewise.
         * doc/c-csky.texi: New file.
         * testsuite/gas/csky/*: New test cases.

ld      * Makefile.am (ALL_EMULATION_SOURCES): Add C-SKY emulations.
        (ecskyelf.c, ecskyelf_linux.c): New rules.
        * Makefile.in: Regenerated.
        * configure.tgt: Add C-SKY.
        * emulparams/cskyelf.sh: New file.
        * emulparams/cskyelf_linux.sh: New file.
        * emultempl/cskyelf.em: New file.
        * gen-doc.texi: Add C-SKY.
        * ld.texi: Likewise.
        (Options specific to C-SKY targets): New section.
        * testsuite/ld-csky/*: New tests.
2018-07-30 12:24:14 +01:00
John Darrington 469d3b57ce S12Z: Remove ELF_TARGET_ID macro
* elf32-s12z.c (ELF_TARGET_ID): Don't define.
2018-07-27 11:28:59 +09:30
John Darrington 370e4b5079 Add functions and macros to read and write 24 bit values.
* libbfd.c (bfd_getb24, bfd_getl24): New functions.
	(bfd_get_24, bfd_put_24): New macros.
	* bfd-in2.h: Regenerate.
2018-07-27 11:28:59 +09:30
John Darrington cd4d353f81 S12Z: Remove inappropriate comment.
* elf32-s12z.c (s12z_elf_set_mach_from_flags): Remove comment.
2018-07-27 11:28:59 +09:30
Alan Modra 33cb30a1f9 Implement PowerPC64 .localentry for value 1
This adds support for ".localentry 1", a new st_other
STO_PPC64_LOCAL_MASK encoding that signifies a function with a single
entry point like ".localentry 0", but unlike a ".localentry 0"
function does not preserve r2.

include/
	* elf/ppc64.h: Specify byte offset to local entry for values
	of two to six in STO_PPC64_LOCAL_MASK.  Clarify r2 return
	value for such functions when entering via global entry point.
	Specify meaning of a value of one in STO_PPC64_LOCAL_MASK.
bfd/
	* elf64-ppc.c (ppc64_elf_size_stubs): Use a ppc_stub_long_branch_r2off
	for calls to symbols with STO_PPC64_LOCAL_MASK bits set to 1.
gas/
	* config/tc-ppc.c (ppc_elf_localentry): Allow .localentry values
	of 1 and 7 to directly set value into STO_PPC64_LOCAL_MASK bits.
ld/testsuite/
	* ld-powerpc/elfv2.s: Add .localentry f5,1 testcase.
	* ld-powerpc/elfv2exe.d: Update.
	* ld-powerpc/elfv2so.d: Update.
2018-07-26 12:53:50 +09:30
Alan Modra 491993044b Enhance powerpc ld -r --relax
One of the ill effects of ld -r is to mash together sections.  That
can result in reduced icache performance at runtime due to unexpected
movement of code.  Another problem is that sections can become too
large to link on targets that have limited relative addressing.  ld -r
--relax attempts to overcome the large section problem for branches by
inserting trampolines, but the powerpc support added lots of
unnecessary trampolines.  This patch trims them somewhat.

bfd/
	* elf32-ppc.c (ppc_elf_relax_section): Ignore common or undef locals.
	Avoid trashing toff with added when used as a symbol index.
	Ignore R_PPC_PLTREL24 addends in unused example code.  Avoid
	creating unnecessary fixups when relocatable.
ld/
	* testsuite/ld-powerpc/big.s: New file.
	* testsuite/ld-powerpc/relaxrl.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run new test.
	* testsuite/ld-powerpc/relaxr.d: Adjust.
2018-07-25 16:52:58 +09:30
Alan Modra be3e27bb55 Suppress string diagnostics for pre-release GCC
Extends commit 898ade12ee to cover other targets.

	* elf32-arm.c (elf32_arm_nabi_write_core_note): Disable
	-Wstringop-truncation warning for gcc-8.0 too.
	* elf32-ppc.c (ppc_elf_write_core_note): Likewise.
	* elf64-ppc.c (ppc64_elf_write_core_note): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewise.
	* elf32-s390.c (elf_s390_write_core_note): Comment fix.
	* elf64-s390.c (elf_s390_write_core_note): Likewise.
2018-07-25 11:50:51 +09:30
Alan Modra 67ce483baa PR23430, Indices misspelled
PR 23430
include/
	* elf/common.h (SHT_SYMTAB_SHNDX): Fix comment typo.
bfd/
	* dwarf2.c (dwarf_debug_section_enum): Fix comment typo.
	* elf.c (bfd_section_from_shdr, elf_sort_sections): Likewise.
binutils/
	* elfcomm.h (struct archive_info): Rename uses_64bit_indicies
	to uses_64bit_indices.
	* elfcomm.c (setup_archive): Update uses of above.
	* readelf.c (process_archive): Likewise.
	(get_section_type_name): Rename indicies to indices.
	(get_32bit_elf_symbols, get_64bit_elf_symbols): Likewise.
	(process_section_groups): Likewise.
cpu/
	* or1kcommon.cpu (spr-reg-indices): Fix description typo.
opcodes/
	* or1k-desc.h: Regenerate.
2018-07-24 19:58:12 +09:30
Max Filippov f82863d797 xtensa: move dynamic relocations sections consistency check
The function elf_xtensa_finish_dynamic_sections checks that sizes of
sections .rela.dyn and .rela.plt match number of corresponding relocation
records, but the check is only done when .rela.plt is non-empty, so, e.g.
it is never run for the static PIE.
Rearrange the test so that .rela.dyn and .rela.plt are checked always.

bfd/
2018-07-23  Max Filippov  <jcmvbkbc@gmail.com>

	* elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Move
	relocation sections consistency check to always check both
	.rela.dyn and .rela.plt when they exist. Rearrange variable
	definition and assignment places.
2018-07-23 12:03:56 -07:00
Max Filippov 5d3a462f05 xtensa: fix relaxation of undefined weak references in shared objects
The change c451bb34ae ("xtensa: don't emit dynamic relocation for weak
undefined symbol") didn't properly handle shrinking of relocation
sections due to coalescing of references to a dynamic undefined weak
symbol in a shared object, which resulted in the following assertion
failure in ld when linking uClibc-ng libthread_db for xtensa:

  BFD (GNU Binutils) 2.31 internal error, aborting at elf32-xtensa.c:3269
  in elf_xtensa_finish_dynamic_sections

Shrink dynamic relocations section for dynamic undefined weak symbols
when linking a shared object.

bfd/
2018-07-23  Max Filippov  <jcmvbkbc@gmail.com>

	* elf32-xtensa.c (shrink_dynamic_reloc_sections): Shrink dynamic
	relocations section for dynamic undefined weak symbols when
	linking a shared object.
2018-07-23 12:02:53 -07:00
Tom Tromey 01bcaf636a Avoid ubsan complaint in BFD
I built gdb with ubsan and ran the test suite.

One complaint was due to bfd_get_elf_phdrs passing NULL to memcpy.
This patch avoids the complaint.

bfd/ChangeLog
2018-07-23  Tom Tromey  <tom@tromey.com>

	* elf.c (bfd_get_elf_phdrs): Don't call memcpy with size 0.
2018-07-23 08:14:00 -06:00
Eric Botcazou 2376f038d1 Initialize GOT slot for local symbol in non-PIC link.
On ARM/VxWorks 7, the R_ARM_TARGET2 relocation used for exception handling
is R_ARM_GOT_PREL; moreover in Ada you can define local exceptions. In this
case, you may end up with a GOT relocation against a local symbol in a
non-PIC link and the ARM linker leaves the GOT slot uninitialized, unlike
for example the i386 or the SPARC linkers in the same situation.

bfd/
	* elf32-arm.c (elf32_arm_final_link_relocate) <R_ARM_GOT32>: Small
	cleanup for the case of a global symbol that binds locally.  Also
	install a value in the GOT slot in the case of a local symbol in
	a non-PIC link.
2018-07-21 15:00:40 +02:00
H.J. Lu 241e64e3b4 x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed
When -z separate-code, which is enabled by default for Linux/x86, is
used to create executable, ld won't place any data in the code-only
PT_LOAD segment.  If there are no data sections placed before the
code-only PT_LOAD segment, the program headers won't be mapped into
any PT_LOAD segment.  When the executable tries to access it (based
on the program header address passed in AT_PHDR), it will lead to
segfault.  This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if
there may be no data sections before the text section so that the
first PT_LOAD segment won't be code-only and will contain the program
header.

Testcases are adjusted to either pass "-z noseparate-code" to ld or
discard the .note.gnu.property section.  A Linux/x86 run-time test is
added.

bfd/

	PR ld/23428
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the
	separate code program header is needed, make sure that the first
	read-only PT_LOAD segment has no code by adding a
	GNU_PROPERTY_X86_ISA_1_USED note.

ld/

	PR ld/23428
	* testsuite/ld-elf/linux-x86.S: New file.
	* testsuite/ld-elf/linux-x86.exp: Likewise.
	* testsuite/ld-elf/pr23428.c: Likewise.
	* testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld
	for Linux/x86 targets.
	* testsuite/ld-i386/abs-iamcu.d: Likewise.
	* testsuite/ld-i386/abs.d: Likewise.
	* testsuite/ld-i386/pr12718.d: Likewise.
	* testsuite/ld-i386/pr12921.d: Likewise.
	* testsuite/ld-x86-64/abs-k1om.d: Likewise.
	* testsuite/ld-x86-64/abs-l1om.d: Likewise.
	* testsuite/ld-x86-64/abs.d: Likewise.
	* testsuite/ld-x86-64/pr12718.d: Likewise.
	* testsuite/ld-x86-64/pr12921.d: Likewise.
	* testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property
	section.
	* testsuite/ld-scripts/print-memory-usage.t: Likewise.
	* testsuite/ld-scripts/size-2.t: Likewise.
	* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld
	to create executable if language is "asm".
2018-07-20 09:19:00 -07:00
Chenghua Xu 8095d2f70e MIPS/GAS: Split Loongson MMI Instructions from loongson2f/3a
The MMI instruction set has been implemented in many Loongson
processors.  There is a lot of software optimized for MMI.  This patch
splits MMI from loongson2f/3a, and adds GAS and disassembler options for
MMI instructions.

2018-07-20  Chenghua Xu  <paul.hua.gm@gmail.com>
            Maciej W. Rozycki  <macro@mips.com>

bfd/
	* elfxx-mips.c (print_mips_ases): Add MMI extension.

binutils/
	* readelf.c (print_mips_ases): Add MMI extension.

gas/
	* NEWS: Mention MultiMedia extensions Instructions (MMI)
	support.
	* config/tc-mips.c (options): Add OPTION_LOONGSON_MMI and
	OPTION_NO_LOONGSON_MMI.
	(md_longopts): Likewise.
	(mips_ases): Define availability for MMI.
	(mips_convert_ase_flags): Map ASE_LOONGSON_MMI to
	AFL_ASE_LOONGSON_MMI.
	(mips_cpu_info_table): Add ASE_LOONGSON_MMI for loongson2f/3a.
	(md_show_usage): Add help for -mloongson-mmi and
	-mno-loongson-mmi.
	* doc/as.texi: Document -mloongson-mmi, -mno-loongson-mmi.
	* doc/c-mips.texi: Document -mloongson-mmi, -mno-loongson-mmi,
	.set loongson-mmi and .set noloongson-mmi.
	* testsuite/gas/mips/loongson-2f.d: Move mmi test to ...
	* testsuite/gas/mips/loongson-2f-mmi.d: Here.  Add ISA/ASE
	flag verification.
	* testsuite/gas/mips/loongson-2f.s: Move mmi test to ...
	* testsuite/gas/mips/loongson-2f-mmi.s: Here.
	* testsuite/gas/mips/loongson-3a.d: Move mmi test to ...
	* testsuite/gas/mips/loongson-3a-mmi.d: Here.  Add ISA/ASE
	flag verification.
	* testsuite/gas/mips/loongson-3a.s: Move mmi test to ...
	* testsuite/gas/mips/loongson-3a-mmi.s: Here.
	* testsuite/gas/mips/mips.exp: Run loongson-2f-mmi and
	loongson-3a-mmi tests.

include/
	* elf/mips.h (AFL_ASE_MMI): New macro.
	(AFL_ASE_MASK): Update to include AFL_ASE_LOONGSON_MMI.
	* opcode/mips.h (ASE_LOONGSON_MMI): New macro.

opcodes/
	* mips-dis.c (mips_arch_choices): Add MMI to loongson2f and
	loongson3a descriptors.
	(parse_mips_ase_option): Handle -M loongson-mmi option.
	(print_mips_disassembler_options): Document -M loongson-mmi.
	* mips-opc.c (LMMI): New macro.
	(mips_opcodes): Replace IL2F|IL3A marking with LMMI for MMI
	instructions.
2018-07-20 13:21:33 +01:00
Maciej W. Rozycki db841b6fcd MIPS/LD: Fix crashing with a discarded dynamic relocation section
Fix a crash that occurs in `_bfd_mips_elf_finish_dynamic_sections' if a
dynamic relocation section has been created, but marked to be discarded
by an assignment to the /DISCARD/ output section in a linker script.
In that case the output section is the absolute section, which has no
ELF section data attached, so trying to set its `sh_size' parameter
causes a null pointer dereference.

This is only done as the value for the DT_RELSZ dynamic entry is being
set, so fix the problem by not creating DT_REL, DT_RELSZ or DT_RELENT
dynamic entries in the first place if the dynamic relocation section
will not be output, as with no dynamic relocation data present these
would not serve their purpose anyway.

Add a generic ELF test case to verify that no dynamic relocation data is
reported in the dynamic segment.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_size_dynamic_sections): Do not
	create DT_REL, DT_RELSZ or DT_RELENT dynamic entries if the
	dynamic relocation section will be discarded from output.
	(_bfd_mips_elf_finish_dynamic_sections) <DT_RELSZ>: Assert that
	the dynamic relocation section will be retained in output.

	ld/
	* testsuite/ld-elf/reloc-discard.d: New test.
	* testsuite/ld-elf/reloc-discard.ld: New test linker script.
	* testsuite/ld-elf/reloc-discard.s: New test source.
2018-07-20 13:21:33 +01:00
Maciej W. Rozycki d3554ec1ed BFD/XCOFF: Fix storage class setting for weak defined symbols
Fix an issue with commit 8602d4fea6 ("Add AIX weak support"),
<https://sourceware.org/ml/binutils/2009-03/msg00189.html>, and use the
correct condition to set the storage class for weak defined symbols.

The context here is as follows:

  else if ((h->root.type == bfd_link_hash_defined
            || h->root.type == bfd_link_hash_defweak)
           && h->smclas == XMC_XO)
    {
      BFD_ASSERT (bfd_is_abs_section (h->root.u.def.section));
      isym.n_value = h->root.u.def.value;
      isym.n_scnum = N_UNDEF;
      if (h->root.type == bfd_link_hash_undefweak
          && C_WEAKEXT == C_AIX_WEAKEXT)
        isym.n_sclass = C_WEAKEXT;
      else
        isym.n_sclass = C_EXT;
      aux.x_csect.x_smtyp = XTY_ER;
    }

so clearly the inner condition can never be true.  Correct the condition
then to check for the `bfd_link_hash_defweak' symbol type instead here,
and in a similar place a little further down in the same function.

	bfd/
	* xcofflink.c (xcoff_write_global_symbol): Fix symbol type
	checks for defined weak symbols.
2018-07-18 17:51:54 +01:00
Maciej W. Rozycki c691de6a16 BFD: Use `bfd_is_abs_symbol' to determine whether a symbol is absolute
Use `bfd_is_abs_symbol' to determine whether a symbol is absolute,
avoiding a problem with ordinary symbols defined in a linker script
outside an output section definition.  Such symbols have its owning
section set to the absolute section up to the final link phase.  A flag
has been added to the link hash to identify such symbols.  Rather than
checking the flag by hand, use the macro that does it uniformly for all
users.

	bfd/
	* elf32-nds32.c (nds32_elf_relax_loadstore): Use
	`bfd_is_abs_symbol' rather than `bfd_is_abs_section' in checking
	whether the symbol is absolute.
	(nds32_elf_relax_lo12): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	(elfNN_aarch64_check_relocs): Likewise.
	* xcofflink.c (xcoff_need_ldrel_p): Likewise.
	(bfd_xcoff_import_symbol): Likewise.
	(xcoff_write_global_symbol): Likewise.
2018-07-17 20:04:53 +01:00
Maciej W. Rozycki d5c928c053 LD: Export relative-from-absolute symbol marking to BFD
It is usually possible to tell absolute and ordinary symbols apart in
BFD throughout the link, by checking whether the section that owns the
symbol is absolute or not.

That however does not work for ordinary symbols defined in a linker
script outside an output section statement.  Initially such symbols are
entered into to the link hash as absolute symbols, owned by the absolute
section.  A flag is set in the internal linker expression defining such
symbols to tell the linker to convert them to section-relative ones in
the final phase of the link.  That flag is however not accessible to BFD
linker code, including BFD target code in particular.

Add a flag to the link hash then to copy the information held in the
linker expression.  Define a macro, `bfd_is_abs_symbol', for BFD code to
use where determining whether a symbol is absolute or ordinary is
required before the final link phase.

This macro will correctly identify the special `__ehdr_start' symbol as
ordinary throughout link, for example, even though early on it will be
assigned to the absolute section.  Of course this does not let BFD code
identify what the symbol's ultimate section will be before the final
link phase has converted this symbol (in `update_definedness').

	include/
	* bfdlink.h (bfd_link_hash_entry): Add `rel_from_abs' member.

	bfd/
	* linker.c (bfd_is_abs_symbol): New macro.
	* bfd-in2.h: Regenerate.

	ld/
	* ldexp.c (exp_fold_tree_1) <etree_assign, etree_provide>
	<etree_provided>: Copy expression's `rel_from_abs' flag to the
	link hash.
2018-07-17 20:04:53 +01:00
Edjunior Barbosa Machado cb2366c198 Add grok/write functions for new ppc core note sections
This patch adds functions for grokking and writing more register core
note sections (NT_PPC_TAR, NT_PPC_PPR, NT_PPC_DSCR, NT_PPC_EBB,
NT_PPC_PMU, NT_PPC_TM_CGPR, NT_PPC_TM_CFPR, NT_PPC_TM_CVMX,
NT_PPC_TM_CVSX, NT_PPC_TM_SPR, NT_PPC_TM_CTAR, NT_PPC_TM_CPPR,
NT_PPC_TM_CDSCR).

2018-07-16  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>

bfd/
	* elf-bfd.h (elfcore_write_ppc_tar): Add prototype.
	(elfcore_write_ppc_ppr): Likewise.
	(elfcore_write_ppc_dscr): Likewise.
	(elfcore_write_ppc_ebb): Likewise.
	(elfcore_write_ppc_pmu): Likewise.
	(elfcore_write_ppc_tm_cgpr): Likewise.
	(elfcore_write_ppc_tm_cfpr): Likewise.
	(elfcore_write_ppc_tm_cvmx): Likewise.
	(elfcore_write_ppc_tm_cvsx): Likewise.
	(elfcore_write_ppc_tm_spr): Likewise.
	(elfcore_write_ppc_tm_ctar): Likewise.
	(elfcore_write_ppc_tm_cppr): Likewise.
	(elfcore_write_ppc_tm_cdscr): Likewise.
	* elf.c (elfcore_write_ppc_tar): New function.
	(elfcore_write_ppc_ppr): Likewise.
	(elfcore_write_ppc_dscr): Likewise.
	(elfcore_write_ppc_ebb): Likewise.
	(elfcore_write_ppc_pmu): Likewise.
	(elfcore_write_ppc_tm_cgpr): Likewise.
	(elfcore_write_ppc_tm_cfpr): Likewise.
	(elfcore_write_ppc_tm_cvmx): Likewise.
	(elfcore_write_ppc_tm_cvsx): Likewise.
	(elfcore_write_ppc_tm_spr): Likewise.
	(elfcore_write_ppc_tm_ctar): Likewise.
	(elfcore_write_ppc_tm_cppr): Likewise.
	(elfcore_write_ppc_tm_cdscr): Likewise.
	(elfcore_write_register_note): Call them.
	(elfcore_grok_ppc_tar): New function.
	(elfcore_grok_ppc_ppr): Likewise.
	(elfcore_grok_ppc_dscr): Likewise.
	(elfcore_grok_ppc_ebb): Likewise.
	(elfcore_grok_ppc_pmu): Likewise.
	(elfcore_grok_ppc_tm_cgpr): Likewise.
	(elfcore_grok_ppc_tm_cfpr): Likewise.
	(elfcore_grok_ppc_tm_cvmx): Likewise.
	(elfcore_grok_ppc_tm_cvsx): Likewise.
	(elfcore_grok_ppc_tm_spr): Likewise.
	(elfcore_grok_ppc_tm_ctar): Likewise.
	(elfcore_grok_ppc_tm_cppr): Likewise.
	(elfcore_grok_ppc_tm_cdscr): Likewise.
	(elfcore_grok_note): Call them.
2018-07-16 16:01:34 -03:00
Maciej W. Rozycki 1cb83cac9a MIPS/BFD: Fix TLS relocation resolution for regular executables
Correct an issue with commit 0f20cc3522 ("TLS support for MIPS"),
<https://sourceware.org/ml/binutils/2005-02/msg00607.html>, where a
condition used to determine whether to use a dynamic symbol for GD, LD
and IE TLS dynamic relocations against a symbol that has been defined
locally has been incorrectly reversed.

It's executables rather than dynamic shared objects where no symbol is
required, because such symbols cannot be preempted and therefore their
values (thread pointer offsets) are fixed at the static link time as is
the associated module ID of the main executable, so the original
condition should have been `shared' instead of `!shared'.  This wrong
condition was then later converted from `!shared' to `!bfd_link_pic',
with commit 0e1862bb40 ("Add output_type to bfd_link_info").

Use the correct `bfd_link_dll' condition then, and adjust code for the
dynamic symbol index possibly being -1 as with symbols that have been
forced local, removing unnecessary dynamic relocations from dynamic
regular executables.  PIE executables are unaffected as the existing
condition excluded them by chance due to the conversion mentioned above.

Adjust test cases accordingly.

	bfd/
	* elfxx-mips.c (mips_tls_got_relocs): Use `bfd_link_dll' rather
	than `!bfd_link_pic' in determining the dynamic symbol index.
	Avoid the index of -1.
	(mips_elf_initialize_tls_slots): Likewise.  Flatten code by
	moving `dyn' to the beginning of the function block.

	ld/
	* testsuite/ld-mips-elf/tlsdyn-o32.d: Update test for dynamic
	relocation removal.
	* testsuite/ld-mips-elf/tlsdyn-o32.got: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-1.d: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-1.got: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-2.d: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-2.got: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-3.d: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-3.got: Likewise.
2018-07-11 17:44:45 +01:00
Maciej W. Rozycki 9143e72c6d PR ld/22570: MIPS/BFD: Fix TLS relocation resolution for PIE executables
Correct a commit 0e1862bb40 ("Add output_type to bfd_link_info") issue
and use `bfd_link_dll' rather than `bfd_link_pic' in determining whether
to fully resolve GD, LD and IE TLS relocations referring to symbols
locally defined rather than deferring them to the load time by means of
dynamic relocations.

Such symbols cannot be preempted in PIE executables, which are
necessarily PIC, and therefore their values (thread pointer offsets) are
fixed at the static link time as is the associated module ID of the main
executable.

Given the `tlsbin-o32.s' and `tlsdyn-o32.s' sources from our test suite
this removes the absolute TLS relocations from the static:

DYNAMIC RELOCATION RECORDS
OFFSET   TYPE              VALUE
00000000 R_MIPS_NONE       *ABS*
1000002c R_MIPS_TLS_TPREL32  *ABS*
10000030 R_MIPS_TLS_DTPMOD32  *ABS*
10000038 R_MIPS_TLS_DTPMOD32  *ABS*

and the dynamic:

DYNAMIC RELOCATION RECORDS
OFFSET   TYPE              VALUE
00000000 R_MIPS_NONE       *ABS*
1000002c R_MIPS_TLS_TPREL32  *ABS*
10000038 R_MIPS_TLS_DTPMOD32  *ABS*
10000044 R_MIPS_TLS_DTPMOD32  *ABS*
10000030 R_MIPS_TLS_DTPMOD32  tlsvar_gd
10000034 R_MIPS_TLS_DTPREL32  tlsvar_gd
10000040 R_MIPS_TLS_TPREL32  tlsvar_ie

PIE executable respectively, as reported by `objdump -R', and fills the
corresponding GOT slots with the values expected, as recorded with the
test cases added.  The new output from `objdump -R' is:

DYNAMIC RELOCATION RECORDS (none)

and:

DYNAMIC RELOCATION RECORDS
OFFSET   TYPE              VALUE
00000000 R_MIPS_NONE       *ABS*
10000030 R_MIPS_TLS_DTPMOD32  tlsvar_gd
10000034 R_MIPS_TLS_DTPREL32  tlsvar_gd
10000040 R_MIPS_TLS_TPREL32  tlsvar_ie

for the static and the dynamic executable respectively.

2018-07-11  Maciej W. Rozycki  <macro@mips.com>
            Rich Felker  <bugdal@aerifal.cx>

	bfd/
	PR ld/22570
	* elfxx-mips.c (mips_tls_got_relocs): Use `bfd_link_dll' rather
	than `bfd_link_pic' to determine whether dynamic relocations are
	to be produced.
	(mips_elf_initialize_tls_slots): Likewise.

	ld/
	PR ld/22570
	* testsuite/ld-mips-elf/tlsbin-pie-o32.d: New test.
	* testsuite/ld-mips-elf/tlsbin-pie-o32.got: New test.
	* testsuite/ld-mips-elf/tlsdyn-pie-o32.d: New test.
	* testsuite/ld-mips-elf/tlsdyn-pie-o32.got: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2018-07-11 17:44:45 +01:00
Maciej W. Rozycki 5270eddc6e BFD/ELF: Correct a `remove' global shadowing error for pre-4.8 GCC
Remove `-Wshadow' compilation errors:

cc1: warnings being treated as errors
.../bfd/elflink.c: In function 'bfd_elf_final_link':
.../bfd/elflink.c:11722: error: declaration of 'remove' shadows a global declaration
/usr/include/stdio.h:154: error: shadowed declaration is here

which for versions of GCC before 4.8 prevent support for ELF targets
from being built.  See also GCC PR c/53066.

	bfd/
	* elflink.c (bfd_elf_final_link): Rename `remove' local variable
	to `remove_section'.
2018-07-11 00:42:43 +01:00
Alan Modra 1594e052d4 xgate cleanup
elf32-xgate.c contains many functions that are only stubs and
elf32-xgate.h contains unused declarations.  While this might be
reasonable for the initial commit of a port with subsequent work
fleshing out the stubs, xgate has only had two minor target specific
patches since the initial commit over six years ago.  The rest of the
changes have been general maintenance work applied to all ELF targets,
and some of this work could have been avoided if the stubs hadn't been
there.  So this patch removes all the stubs.

I've kept the functionality of the old elf32_xgate_add_symbol_hook,
implemented in elf32_xgate_backend_symbol_processing.  Presumably,
that's to set the symbol st_target_internal flag for use in
elf32-m68hc1x.c:elf32_m68hc11_relocate_section.

The empty elf32_xgate_relocate_section meant that xgate had no linker.
Or at least, no linker relocation processing.  Deleting the
elf_backend_relocate_section define means the target will now use the
generic linker reloc processing.  How good that is will depend on the
accuracy of the reloc howtos..

I haven't updated the ld testsuite to xfail tests expected to fail
for generic elf targets.

bfd/
	* elf32-xgate.h: Delete.
	* elf32-xgate.c: Delete unnecessary forward declarations, add two
	that are now needed.
	(xgate_elf_bfd_link_hash_table_create)
	(xgate_elf_bfd_link_hash_table_free)
	(xgate_elf_set_mach_from_flags, struct xgate_scan_param)
	(stub_hash_newfunc, elf32_xgate_add_symbol_hook)
	(elf32_xgate_setup_section_lists, elf32_xgate_size_stubs)
	(elf32_xgate_build_stubs, elf32_xgate_check_relocs)
	(elf32_xgate_relocate_section, _bfd_xgate_elf_set_private_flags)
	(elf32_xgate_post_process_headers): Delete.
	(elf32_xgate_backend_symbol_processing): New function.
	(xgate_elf_ignore_reloc, xgate_elf_special_reloc)
	(_bfd_xgate_elf_print_private_bfd_data): Make static.
	(ELF_TARGET_ID, elf_info_to_howto, elf_backend_check_relocs)
	(elf_backend_relocate_section, elf_backend_object_p)
	(elf_backend_final_write_processing, elf_backend_can_gc_sections)
	(elf_backend_post_process_headers, elf_backend_add_symbol_hook)
	(bfd_elf32_bfd_link_hash_table_create)
	(bfd_elf32_bfd_set_private_flags)
	(xgate_stub_hash_lookup): Don't define.
	(elf_backend_symbol_processing): Define.
	* elf-bfd.h (elf_target_id): Delete XGATE_ELF_DATA.
ld/
	* emulparams/xgateelf.sh (TEMPLATE_NAME) Set to generic.
	(EXTRA_EM_FILE): Set to genelf.
2018-07-10 23:59:07 +09:30
Maciej W. Rozycki 4b8377e7db MIPS/BFD: Do not redirect to discarded lazy binding stubs
Correct a MIPS/BFD linker issue with dynamic symbol and corresponding
GOT entry values being redirected to lazy binding stubs where the stubs
section has been discarded by assigning to the `/DISCARD/' output
section in the linker script used.  The issue manifests itself by the
values entered being relative to the absolute section, which is what any
discarded sections are internally assigned in the linker.

For the `stub-dynsym-2.s' piece of code included as a test case with
this change this issue results in the dynamic symbol table and the GOT
looking like:

Symbol table '.dynsym' contains 3 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000010     0 FUNC    GLOBAL DEFAULT  UND bar
     2: 00000000     0 FUNC    GLOBAL DEFAULT  UND foo

Primary GOT:
 Canonical gp value: 00097ff0

 Reserved entries:
   Address     Access  Initial Purpose
  00090000 -32752(gp) 00000000 Lazy resolver
  00090004 -32748(gp) 80000000 Module pointer (GNU extension)

 Global entries:
   Address     Access  Initial Sym.Val. Type    Ndx Name
  00090008 -32744(gp) 00000010 00000010 FUNC    UND bar
  0009000c -32740(gp) 00000000 00000000 FUNC    UND foo

if assembled to regular MIPS code, or:

Symbol table '.dynsym' contains 3 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000d     0 FUNC    GLOBAL DEFAULT  UND bar
     2: 00000001     0 FUNC    GLOBAL DEFAULT  UND foo

Primary GOT:
 Canonical gp value: 00097ff0

 Reserved entries:
   Address     Access  Initial Purpose
  00090000 -32752(gp) 00000000 Lazy resolver
  00090004 -32748(gp) 80000000 Module pointer (GNU extension)

 Global entries:
   Address     Access  Initial Sym.Val. Type    Ndx Name
  00090008 -32744(gp) 0000000d 0000000d FUNC    UND bar
  0009000c -32740(gp) 00000001 00000001 FUNC    UND foo

if assembled to microMIPS code.  Symbol values and GOT entries record
the offset into the inexistent stubs section and the ISA bit rather than
zero, which would be the case if a lazy binding stub was not used for
other reasons, such as the value of the symbol being taken for a purpose
other than making a function call (e.g. an R_MIPS_GOT16 relocation).

Correct the issue by refraining from redirecting symbols to lazy binding
stubs if the stubs section is going to be discarded.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol): Don't set
	`->needs_lazy_stub' if the stubs output section is the absolute
	section.

	ld/
	* testsuite/ld-mips-elf/stub-dynsym-2.dd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-2.gd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-2.sd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-discard-2.gd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-discard-2.sd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-micromips-2.dd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-micromips-2.gd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-micromips-2.sd: New test.
	* testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.dd: New
	test.
	* testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.gd: New
	test.
	* testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.sd: New
	test.
	* testsuite/ld-mips-elf/stub-dynsym-2.ld: New test linker
	script.
	* testsuite/ld-mips-elf/stub-dynsym-discard-2.ld: New test
	linker script.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2018-07-09 21:30:44 +01:00
H.J. Lu 872899f1ef bfd: Use changequote for "i[3-7]86-*-linux-*"
Use changequote to match "i[3-7]86-*-linux-*", instead of
"i3-786-*-linux-*".

	PR ld/23388
	* configure.ac: Use changequote for "i[3-7]86-*-linux-*".
	* configure: Regenerated.
2018-07-09 06:51:17 -07:00
Alan Modra 61658d78f0 m68hc1* fixes
With config.sub now properly returning m68hc12-unknown-elf rather than
m68hc12-unknown-none, more ELF tests run.  This patch enables
STB_GNU_UNIQUE processing fixing some testsuite failures that probably
no m68hc12 user cares about, and removes some XPASSes.

bfd/
	* elf32-m68hc1x.c (elf32_m68hc11_post_process_headers): Call
	_bfd_elf_post_process_headers.
ld/
	* testsuite/ld-discard/extern.d: Remove m68hc12 xfail.
	* testsuite/ld-discard/start.d: Likewise.
	* testsuite/ld-discard/static.d: Likewise.
2018-07-09 17:27:35 +09:30
Max Filippov c451bb34ae xtensa: don't emit dynamic relocation for weak undefined symbol
Resolved reference to a weak undefined symbol in PIE must not have
a dynamic relative relocation against itself, otherwise the value of a
reference will be changed from 0 to the base of executable, breaking
code like the following:

  void weak_function (void);
  if (weak_function)
    weak_function ();

This fixes tests for PR ld/22269 and a number of PIE tests in xtensa gcc
testsuite.

bfd/
2018-07-06  Max Filippov  <jcmvbkbc@gmail.com>

	* elf32-xtensa.c (elf_xtensa_allocate_dynrelocs): Don't allocate
	space for dynamic relocation for undefined weak symbol.
	(elf_xtensa_relocate_section): Don't emit R_XTENSA_RELATIVE
	relocation for undefined weak symbols.
	(shrink_dynamic_reloc_sections): Don't shrink dynamic relocation
	section for relocations against undefined weak symbols.
2018-07-06 16:05:49 -07:00
Alan Hayward ad1cc4e492 Add checks for the NT_ARM_SVE section in a core file.
The NT_ARM_SVE section is documented here:
  https://github.com/torvalds/linux/blob/master/Documentation/arm64/sve.txt
  * A NT_ARM_SVE note will be added to each coredump for each thread of the
   dumped process.  The contents will be equivalent to the data that would have
   been read if a PTRACE_GETREGSET of NT_ARM_SVE were executed for each thread
   when the coredump was generated.

	* elf.c (elfcore_grok_aarch_sve): New function.
	(elfcore_grok_note): Check for Aarch64 SVE.
	(elfcore_write_aarch_sve): New function.
	(elfcore_write_register_note): Check for Aarch64 SVE.
	* elf-bfd.h(elfcore_grok_aarch_sve): New declaration.
2018-07-06 16:25:21 +01:00
Alan Modra fe75810f8e Fix diagnostic errors
Fixes a number of build errors like the following
.../elf32-arm.c: In function 'elf32_arm_nabi_write_core_note':
.../elf32-arm.c:2177: error: #pragma GCC diagnostic not allowed inside functions
.../elf32-arm.c:2186: error: #pragma GCC diagnostic not allowed inside functions
See the comment in diagnostics.h.

include/
	* diagnostics.h: Comment on macro usage.
bfd/
	* elf32-arm.c (elf32_arm_nabi_write_core_note): Don't use
	DIAGNOTIC_PUSH and DIAGNOSTIC_POP unconditionally.
	* elf32-ppc.c (ppc_elf_write_core_note): Likewise.
	* elf32-s390.c (elf_s390_write_core_note): Likewise.
	* elf64-ppc.c (ppc64_elf_write_core_note): Likewise.
	* elf64-s390.c (elf_s390_write_core_note): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewise.
2018-07-06 15:18:59 +09:30
Jim Wilson bb11866d6a RISC-V: Add riscv-*-* configure support, and minor cleanup.
bfd/
	* config.bfd (riscv32*-*-*): Renamed from riscv32-*-*.
	(riscv64*-*-*): Likewise.
	(riscv-*-*): Add as an alias for riscv32*-*-*.

	ld/
	* configure.tgt (riscv-*-*): Add as an alias for riscv32*-*-*.
2018-07-05 17:49:11 -07:00
H.J. Lu 56ad703d56 x86: Remove x86 ISA properties with empty bits
There is no need to generate x86 ISA properties with empty bits in
linker output.

bfd/

	PR ld/23372
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Remove x86
	ISA properties with empty bits.

ld/

	PR ld/23372
	* testsuite/ld-i386/i386.exp: Run pr23372a and pr23372b.
	* testsuite/ld-i386/pr23372a.d: New file.
	* testsuite/ld-i386/pr23372a.s: Likewise.
	* testsuite/ld-i386/pr23372b.d: Likewise.
	* testsuite/ld-i386/pr23372b.s: Likewise.
	* testsuite/ld-i386/pr23372c.s: Likewise.
	* testsuite/ld-x86-64/pr23372a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372a.d: Likewise.
	* testsuite/ld-x86-64/pr23372a.s: Likewise.
	* testsuite/ld-x86-64/pr23372b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372b.d: Likewise.
	* testsuite/ld-x86-64/pr23372b.s: Likewise.
	* testsuite/ld-x86-64/pr23372c.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr23372a, pr23372a-x32,
	pr23372b and pr23372b-x32.
2018-07-05 09:24:18 -07:00
Nick Clifton d8dab05495 Updated Russian, Bulgarian, and Brazilian Portuguese translations for various components of the binutuls.
ld	* po/bg.po: Updated Bulgarian translation.
	* po/pt_BR.po: Updated Brazilian Portuguese translation.

binutils* po/bg.po: Updated Bulgarian translation.

bfd,gas	* po/ru.po: Updated Russian translation.
2018-07-05 12:16:56 +01:00
Alan Modra 4a91d0ba30 Error for mismatched powerpc ABI tags
And report the two input files that are incompatible rather than
reporting that an input file is incompatible with the output.

bfd/
	* elf-bfd.h (_bfd_elf_ppc_merge_fp_attributes): Update prototype.
	* elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): Return error
	on mismatch.  Remove "warning: " from messages.  Track last bfd
	used to set tags.
	(ppc_elf_merge_obj_attributes): Likewise.  Handle status from
	_bfd_elf_ppc_merge_fp_attributes.
	* elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Handle status
	from _bfd_elf_ppc_merge_fp_attributes.
ld/
	* testsuite/ld-powerpc/attr-gnu-4-12.d: Update expected output.
	* testsuite/ld-powerpc/attr-gnu-4-13.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-21.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-23.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-31.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-32.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-8-23.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-12-21.d: Likewise.
2018-07-05 10:21:37 +09:30
H.J. Lu db40acb0be Also install diagnostics.h
Since bfd.h is an installed header, also install diagnostics.h.

	* Makefile.am (bfdinclude_HEADERS): Add $(INCDIR)/diagnostics.h.
	* Makefile.in: Regenerated.
2018-07-04 06:18:34 -07:00
Alan Modra b8a6ced796 Correct removal of .gnu.attributes
Setting SEC_EXCLUDE for empty .gnu.attributes is too late in the link
process for the linker to remove the section.  That must be done in
bfd_elf_final_link, as we do for removed group sections.

	* elflink.c (bfd_elf_final_link): Remove zero size .gnu.attributes
	sections.
2018-07-03 18:52:52 +09:30
Alan Modra 8d2c8c3d17 GNU attribute output on errors
.gnu.attributes entries from linker input files are merged to the
output file, the output having the union of compatible input
attributes.  Incompatible attributes generally cause a linker error
and no output.  However in some cases only a warning is emitted, and
one of the incompatible input attributes is passed on to the output.

PowerPC tends to emit warnings rather than errors, and the output
takes the first input attribute.  For example, if we have two input
files with Tag_GNU_Power_ABI_FP, the first with a value signifying
"double-precision hard float, IBM long double", the second with a
value signifying "double-precision hard float, IEEE long double",
we'll get a warning about incompatible long double types and the
output will say "double-precision hard float, IBM long double".
The output attribute of course isn't correct.  It would be correct to
specify "IBM and IEEE long double", but we don't have a way to
represent that currently.  While it would be possible to extend the
encoding, there isn't much gain in doing so.  A shared library
providing support for both long double types should link against
objects using either long double type without warning or error.  That
is what you'd get if such a shared library had no Tag_GNU_Power_ABI_FP
attribute.

So this patch provides a way for the backend to omit .gnu.attributes
tags from the output.

	* elf-bfd.h (ATTR_TYPE_FLAG_ERROR, ATTR_TYPE_HAS_ERROR): Define.
	* elf-attrs.c (is_default_attr): Handle ATTR_TYPE_HAS_ERROR.
	* elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): Use
	ATTR_TYPE_FLAG_INT_VAL.  Set ATTR_TYPE_HAS_ERROR on finding
	incompatible attribute.
	(ppc_elf_merge_obj_attributes): Likewise.  Return
	_bfd_elf_merge_object_attributes result.
	* elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Return
	_bfd_elf_merge_object_attributes result.
2018-07-03 16:46:54 +09:30
Alan Modra af0bfb9c42 Hide dynamic symbols in discarded sections
This is a followup to git commit 97196564c7 "Strip global symbol
defined in discarded section".  If a symbol defined in a discarded
section was dynamic, that patch left .dynsym with holes (ie. all zero
entries).  For example, the following from libstdc++.so:

Symbol table '.dynsym' contains 6090 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000000a74e0     0 SECTION LOCAL  DEFAULT   10
     2: 0000000000264180     0 SECTION LOCAL  DEFAULT   17
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_addUserCommitAction
     4: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_memcpyRtWn
     5: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
readelf: Warning: local symbol 5 found at index >= .dynsym's sh_info value of 3
     6: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
readelf: Warning: local symbol 6 found at index >= .dynsym's sh_info value of 3
[snip]

This patch removes the symbols from .dynsym too.

	PR 17550
	* elflink.c (_bfd_elf_fix_symbol_flags): Hide dynamic symbols
	in discarded sections.
2018-07-03 12:31:34 +09:30
Maciej W. Rozycki 12f09816ce MIPS/BFD: Make section GC work with `ict_irix5' targets
Prevent runtime procedure table symbols, produced with `ict_irix5' MIPS
targets, from being swept in section GC, fixing linker errors like:

./ld-new: tmpdir/dump: protected symbol `_procedure_table_size' isn't defined
./ld-new: final link failed: bad value

triggered whenever section GC is enabled with those targets and
consequently removing the following test suite failures:

FAIL: Build pr22649-2a.so
FAIL: Build pr22649-2c.so
FAIL: PR ld/20828 dynamic symbols with section GC (auxiliary shared library)
FAIL: PR ld/20828 dynamic symbols with section GC (plain)
FAIL: PR ld/20828 dynamic symbols with section GC (version script)
FAIL: PR ld/20828 dynamic symbols with section GC (versioned shared library)
FAIL: PR ld/20828 dynamic symbols with section GC (versioned)
FAIL: --gc-sections with .text._init
FAIL: pr20022

observed with `mips-elf', `tx39-elf', `mipsisa32-elf', `mipsisa64-elf',
`mipsel-elf', `mipsisa32el-elf', `mipsisa64el-elf', `mips64vr-elf',
`mips64vrel-elf', `mips64vr4300-elf', `mips64vr4300el-elf',
`mips-sgi-irix5' and `mips-rtems' targets, among others.  This fix makes
section GC usable with the affected targets.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_create_dynamic_sections): Set
	`mark' for symbols created from `mips_elf_dynsym_rtproc_names'
	list.
2018-07-02 23:57:22 +01:00
Maciej W. Rozycki 156f2c001e microMIPS/BFD: Add missing NewABI TLS and miscellaneous relocations
Complement commit df58fc944d ("MIPS: microMIPS ASE support"),
<https://sourceware.org/ml/binutils/2011-07/msg00198.html>, and add TLS
and a few miscellaneous relocations to NewABI microMIPS support, fixing
GAS assertion failures:

.../gas/testsuite/gas/mips/elf-rel28.s: Assembler messages:
.../gas/testsuite/gas/mips/elf-rel28.s:19: Internal error in append_insn at .../gas/config/tc-mips.c:7660.
Please report this bug.

observed if an attempt is made to assemble the `elf-rel28.s' test case
to microMIPS code.  The relocations are the same as with o32 support,
except for `partial_inplace' and `src_mask' updates for the respective
RELA variants.

	bfd/
	* elf64-mips.c (micromips_elf64_howto_table_rel): Add
	R_MICROMIPS_HI0_LO16, R_MICROMIPS_TLS_GD, R_MICROMIPS_TLS_LDM,
	R_MICROMIPS_TLS_DTPREL_HI16, R_MICROMIPS_TLS_DTPREL_LO16,
	R_MICROMIPS_TLS_GOTTPREL, R_MICROMIPS_TLS_TPREL_HI16,
	R_MICROMIPS_TLS_TPREL_LO16, R_MICROMIPS_GPREL7_S2 and
	R_MICROMIPS_PC23_S2 relocation entries.
	(micromips_elf64_howto_table_rela): Likewise.
	(micromips_reloc_map): Likewise.
	* elfn32-mips.c (elf_micromips_howto_table_rel): Likewise.
	(elf_micromips_howto_table_rela): Likewise.
	(micromips_reloc_map): Likewise.

	gas/
	* testsuite/gas/mips/elf-rel28-micromips-n32.d: New test.
	* testsuite/gas/mips/elf-rel28-micromips-n64.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.
2018-07-02 23:57:22 +01:00
H.J. Lu b638b5d57f x86-64: Clear the R_X86_64_converted_reloc_bit bit
We need to clear the R_X86_64_converted_reloc_bit bit after setting it
to avoid leaking it out by --emit-relocs.

bfd/

	PR ld/23324
	* elf64-x86-64.c (elf_x86_64_relocate_section): Clear the
	R_X86_64_converted_reloc_bit bit.

ld/

	PR ld/23324
	* testsuite/ld-x86-64/pr23324.s: New file.
	* testsuite/ld-x86-64/pr23324a.d: Likewise.
	* testsuite/ld-x86-64/pr23324b.d: Likewise.
2018-07-02 13:08:09 -07:00
Tom Tromey eac61af65b Allow BFD to recognize macOS universal libraries
Bug #13157 is about a gdb regression, where previously it could handle
universal libraries, but now cannot.

gdb isn't working for me on macOS for other reasons, so I wrote this
small test program to show the problem:

    #include <config.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <bfd.h>

    void
    die (const char *what)
    {
      fprintf (stderr, "die: %s\n", what);
      exit (1);
    }

    int
    main (int argc, char **argv)
    {
      bfd *file = bfd_openr (argv[1], NULL);
      if (file == NULL)
	die ("couldn't open");

      if (!bfd_check_format (file, bfd_archive))
	die ("not an archive");

      printf ("yay\n");

      bfd_close (file);
      return 0;
    }

Then I built a simple universal binary.  With git master BFD, I get:

    $ ./doit ./universal-exe
    die: not an archive

Jeff Muizelaar tracked this down to the BFD change for PR binutils/21787.
This patch changed bfd_generic_archive_p to sometimes reset the BFD's
"format" field.

However, simply changing bfd_generic_archive_p regressed the test case
in that bug.

Debugging PR binutils/21787 again, what I saw is that the mach-o
universal binary support acts like a bfd_archive but does not provide
a _close_and_cleanup function.  However, if a BFD appears as an
archive member, it must always remove its own entry from its parent's
map.  Otherwise, when the parent is destroyed, the already-destroyed
child BFD will be referenced.  mach-o does not use the usual archive
member support, so simply using _bfd_archive_close_and_cleanup (as
other targets do) will not work.

This patch fixes the problem by introducing a new
_bfd_unlink_from_archive_parent function, then arranging for it to be
called in the mach-o case.

Ok?

bfd/ChangeLog
2018-07-02  Jeff Muizelaar  <jrmuizel@gmail.com>
	    Tom Tromey  <tom@tromey.com>

	PR 13157
	PR 21787
	* mach-o.c (bfd_mach_o_fat_close_and_cleanup): New function.
	(bfd_mach_o_close_and_cleanup): Redefine.
	* archive.c (_bfd_unlink_from_archive_parent): New function,
	extracted from..
	(_bfd_archive_close_and_cleanup): ..here.
	(bfd_generic_archive_p): Do not clear archive's format.
	* libbfd-in.h (_bfd_unlink_from_archive_parent): Declare.
	* libbfd.h: Regenerate.
2018-07-02 08:24:32 -06:00
Thomas Preud'homme c0c468d562 [ARM] Update bfd's Tag_CPU_arch knowledge
BFD's bfd_get_mach () function returns a bfd specific value representing
the architecture of the target which is populated from the Tag_CPU_arch
build attribute value of that target. Among other users of that
interfacem, objdump which uses it to print the architecture version of
the binary being examinated and to decide what instruction is available
if run with "-m arm" via its own mapping from bfd_mach_arm_X values to
feature bits available.

However, both BFD and objdump's most recent known architecture is
Armv5TE. When encountering a newer architecture bfd_get_mach will return
bfd_mach_arm_unknown. This is unfortunate since objdump uses that value
to allow all instructions on all architectures which is already what it
does by default, making the "-m arm" trick useless.

This patch updates BFD and objdump's knowledge of Arm architecture
versions up to the latest Armv8-M Baseline and Mainline, Armv8-R and
Armv8.4-A architectures. Since several architecture versions (eg. 8.X-A)
share the same Tag_CPU_arch build attribute value and
bfd_mach_arm values, the mapping from bfd machine value to feature bits
need to return the most featureful feature bits that would yield the
given bfd machine value otherwise some instruction would not disassemble
under "-m arm" mode. The patch rework that mapping to make this clearer
and simplify writing the mapping rules. In particular, for simplicity
all FPU instructions are allowed in all cases.

Finally, the patch also rewrite the cpu_arch_ver table in GAS to use the
TAG_CPU_ARCH_X macros rather than hardcode their value.

2018-07-02  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* archures.c (bfd_mach_arm_5TEJ, bfd_mach_arm_6, bfd_mach_arm_6KZ,
	bfd_mach_arm_6T2, bfd_mach_arm_6K, bfd_mach_arm_7, bfd_mach_arm_6M,
	bfd_mach_arm_6SM, bfd_mach_arm_7EM, bfd_mach_arm_8, bfd_mach_arm_8R,
	bfd_mach_arm_8M_BASE, bfd_mach_arm_8M_MAIN): Define.
	* bfd-in2.h: Regenerate.
	* cpu-arm.c (arch_info_struct): Add entries for above new
	bfd_mach_arm values.
	* elf32-arm.c (bfd_arm_get_mach_from_attributes): Add Tag_CPU_arch to
	bfd_mach_arm mapping logic for pre Armv4 and Armv5TEJ and later
	architectures.  Force assert failure for any new Tag_CPU_arch value.

gas/
	* config/tc-arm.c (cpu_arch_ver): Use symbolic TAG_CPU_ARCH macros
	rather than hardcode their values.

ld/
	* arm-dis.c (select_arm_features): Fix typo in heading comment.  Allow
	all FPU features and add mapping from new bfd_mach_arm values to
	allowed CPU feature bits.

opcodes/
	* testsuite/ld-arm/tls-descrelax-be8.d: Add architecture version in
	expected result.
	* testsuite/ld-arm/tls-descrelax-v7.d: Likewise.
	* testsuite/ld-arm/tls-longplt-lib.d: Likewise.
	* testsuite/ld-arm/tls-longplt.d: Likewise.
2018-07-02 11:22:20 +01:00
Thomas Preud'homme a05a5b64cf Fix use of "command line X" in binutils doc
Binutils documentation uses a mix of spelling for the compound word
"command-line X". According to [1]:

"Sometimes compound words are written separately (nail polish),
sometimes with a hyphen (short-sighted) and sometimes as one word
(eyelashes). Often new compounds are written as two separate words and,
as they become more familiar, they are either connected with a hyphen
(-) or made into one word."

I think command-line X is common enough in our industry that the two
workds command and line should be connected. Since command-line is more
common than commandline, I propose to update binutils documentation to
consistently use "command-line" when this is used as an adjective to a
noun (eg. command-line argument, command-line switch, command-line
option and command-line flag). I've left occurences of "the command
line" as is. I've also left gdb, sim and readline alone and have only
touched public documentation (texi and NEWS files).

[1]
http://dictionary.cambridge.org/grammar/british-grammar/word-formation/compounds

2018-07-02  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* doc/bfdint.texi: Use command-line consistently when used in a
	compount word.
	* doc/bfdsumm.texi: Likewise.

binutils/
	* NEWS: Use command-line consistently when used in a compount word.
	* doc/binutils.texi: Likewise and fix trailing whitespace on same
	line.

gas/
	* NEWS: Use command-line consistently when used in a compount word.
	* doc/as.texi: Likewise.
	* doc/c-aarch64.texi: Likewise.
	* doc/c-alpha.texi: Likewise.
	* doc/c-arc.texi: Likewise.
	* doc/c-arm.texi: Likewise.
	* doc/c-avr.texi: Likewise.
	* doc/c-bfin.texi: Likewise.
	* doc/c-cris.texi: Likewise.
	* doc/c-epiphany.texi: Likewise.
	* doc/c-i386.texi: Likewise.
	* doc/c-ia64.texi: Likewise.
	* doc/c-lm32.texi: Likewise.
	* doc/c-m32r.texi: Likewise.
	* doc/c-m68k.texi: Likewise.
	* doc/c-mips.texi: Likewise.
	* doc/c-mmix.texi: Likewise.
	* doc/c-msp430.texi: Likewise.
	* doc/c-mt.texi: Likewise.
	* doc/c-nios2.texi: Likewise.
	* doc/c-ppc.texi: Likewise.
	* doc/c-pru.texi: Likewise.
	* doc/c-rl78.texi: Likewise.
	* doc/c-rx.texi: Likewise.
	* doc/c-tic6x.texi: Likewise.
	* doc/c-v850.texi: Likewise.
	* doc/c-vax.texi: Likewise.
	* doc/c-visium.texi: Likewise.
	* doc/c-xstormy16.texi: Likewise.
	* doc/c-xtensa.texi: Likewise.
	* doc/c-z80.texi: Likewise.
	* doc/c-z8k.texi: Likewise.
	* doc/internals.texi: Likewise.

gprof/
	* gprof.texi: Use command-line consistently when used in a compount
	word.

ld/
	* NEWS: Use command-line consistently when used in a compount word.
	* ld.texinfo: Likewise.
	* ldint.texinfo: Likewise.
2018-07-02 11:18:24 +01:00
Maciej W. Rozycki 262e07d011 MIPS/BFD: Remove extraneous undefined weak symbol visibility check
Remove an extraneous symbol visibility check made for undefined weak
symbols in determination whether an R_MIPS_REL32 dynamic relocation has
to be placed in output, complementing commit ad95120309 ("mips: Check
UNDEFWEAK_NO_DYNAMIC_RELOC").  That check duplicates one already made by
the UNDEFWEAK_NO_DYNAMIC_RELOC macro as a part of a broader condition
used to decide if to enter undefined weak symbols to the dynamic symbol
table or not.

	bfd/
	* elfxx-mips.c (allocate_dynrelocs): Remove extraneous symbol
	visibility check made for undefined weak symbols.
2018-06-29 15:45:28 +01:00
Nick Clifton 30aa13067f Updated translations.
gas	* po/uk.po: Updated Ukranian translation.
bfd	* po/uk.po: Updated Ukranian translation.
ld	* po/uk.po: Updated Ukranian translation.
gold	* po/uk.po: Updated Ukranian translation.

opcodes	* po/uk.po: Updated Ukranian translation.
	* po/de.po: Updated German translation.
	* po/pt_BR.po: Updated Brazilian Portuguese translation.

binutils* po/sv.po: Updated Swedish translation.
	* po/uk.po: Updated Ukranian translation.
2018-06-26 14:03:16 +01:00
Nick Clifton bb69498c61 Fix compile time warning message for the AArch64 BFD backend, about a possible attempt to call sprintf on a NULL buffer pointer.
* elfnn-aarch64.c (_bfd_aarch64_erratum_835769_stub_name): Check
	for malloc returning NULL.
	(_bfd_aarch64_erratum_843419_fixup): Check for
	_bfd_aarch64_erratum_835769_stub_name returning NULL.
2018-06-25 12:49:14 +01:00
Nick Clifton 71300e2c0c Regenerate configure and pot files with updated binutils version number. 2018-06-24 19:13:01 +01:00
Nick Clifton 5127f20732 Update version number on development (aka HEAD) branch. 2018-06-24 18:46:33 +01:00
Nick Clifton 719d828850 Add 2.30 branch notes to ChangeLogs and NEWS files. 2018-06-24 18:36:15 +01:00
Maciej W. Rozycki 1ced1a5f10 MIPS/BFD: Correct formatting of compact EH backend methods
Correct the formatting of `_bfd_mips_elf_compact_eh_encoding' and
`_bfd_mips_elf_cant_unwind_opcode' definitions which extend beyond 79
columns.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_compact_eh_encoding)
	(_bfd_mips_elf_cant_unwind_opcode): Correct formatting.
2018-06-21 21:40:57 +01:00
Maciej W. Rozycki 334cd8a780 MIPS/BFD: Keep EI_ABIVERSION setting together
Shuffle code in `_bfd_mips_post_process_headers' so that the setting of
the EI_ABIVERSION ELF file header field is complete before calling
`_bfd_elf_post_process_headers'.  This used to be the case, but was
changed with commit 351cdf24d2 ("[MIPS] Implement O32 FPXX, FP64 and
FP64A ABI extensions") for no reason.

	bfd/
	* elfxx-mips.c (_bfd_mips_post_process_headers): Keep
	EI_ABIVERSION setting together.
2018-06-21 21:40:56 +01:00
Maciej W. Rozycki bb29b84d8c MIPS/BFD: Use enumeration constants for EI_ABIVERSION
Define enumeration constants based on generated `libc-abis.h' from GNU
libc, adding a MIPS_ prefix as these are port-specific.  Use them to
replace magic numbers stored in the EI_ABIVERSION field of the ELF file
header.

	bfd/
	* elfxx-mips.c (MIPS_LIBC_ABI_DEFAULT, MIPS_LIBC_ABI_MIPS_PLT)
	(MIPS_LIBC_ABI_UNIQUE, MIPS_LIBC_ABI_MIPS_O32_FP64)
	(MIPS_LIBC_ABI_MAX): New enumeration constants.
	(_bfd_mips_post_process_headers): Use them in place of magic
	numbers.
2018-06-21 21:40:56 +01:00
Jim Wilson 25eb8346ac RISC-V: Fix 3 PIE related ld testsuite failures.
bfd/
	* elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Update comment.
	Use SYMBOL_REFERENCES_LOCAL.  Add asserts for h->got.offset.
2018-06-21 11:45:43 -07:00
Alan Modra d388f64333 Regen doc/Makefile.in
Also make the automake strictness "foreign".  My regeneration of the
three doc/Makefile.in files already had --foreign in the automake
invocation, so this just makes it explicit.

bfd/
	* doc/Makefile.am (AUTOMAKE_OPTIONS): Add "foreign".
	* doc/Makefile.in: Regenerate.
binutils/
	* doc/Makefile.am (AUTOMAKE_OPTIONS): Add "foreign".
	* doc/Makefile.in: Regenerate.
gas/
	* doc/Makefile.am (AUTOMAKE_OPTIONS): Add "foreign".
	* doc/Makefile.in: Regenerate.
zlib/
	* Makefile.in: Regenerate.
2018-06-21 23:00:05 +09:30
Nick Clifton 6077de0645 Fix potential illegal memroy access when using a build-id note with a negative size.
PR 23316
	* opncls.c (get_build_id): Check for a negative or excessive data
	size in the build-id note.
2018-06-20 16:30:05 +01:00
Renlin Li b939d8a0de [BFD][AARCH64]Properly truncate no overflow checking relocation value for load/store immediate.
bfd/ChangeLog:

2018-06-20  Renlin Li  <renlin.li@arm.com>

	* elfxx-aarch64.c (_bfd_aarch64_elf_resolve_relocation): Use PG_OFFSET
	to resolve BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC,
	BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC,
	BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC,
	BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC,
	BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC,
	BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC,
	BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC,
	BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC.

ld/ChangeLog:

2018-06-20 Renlin Li  <renlin.li@arm.com>

	* testsuite/ld-aarch64/emit-relocs-115.d: Update test with new value.
	* testsuite/ld-aarch64/emit-relocs-534.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-555.d: Likewise.
2018-06-20 14:47:37 +01:00
Nick Clifton c6643fcc05 Stop objcopy from corrupting mach-o files.
PR 23299
	* mach-o.c (cputype): New function.
	(cpusubtype): New function.
	(bfd_mach_o_bfd_print_private_data): New function.  Dispalys the
	values in the MACH-O file header.
	(bfd_mach_o_bfd_copy_private_header_data): Copy the cputype and
	cpusubtype fields from the input bfd's mach-o header to the output
	bfd.
	* mach-o-target.c (bfd_mach_o_bfd_print_private_bfd_data):
	Redefine to bfd_mach_o_bfd_print_private_data.
	* mach-o.h (bfd_mach_o_bfd_print_private_bfd_data): Prototype.
2018-06-20 10:43:00 +01:00
Maciej W. Rozycki 789ff5b6c2 PR ld/22966: Fix n64 MIPS `.got.plt' range checks
The addressable signed 32-bit range for n64 MIPS `.got.plt' references
is from 0xffffffff7fff8000 to 0x7fff7fff, due to how the composition of
an LUI and an LD instruction works for address calculation in the 64-bit
addressing mode, such as when CP0.Status.UX=1.

We currently have a range check in `mips_finish_exec_plt', however it is
not correct as it verifies that the `.got.plt' start address referred is
between 0xffffffff80000000 and 0x7fffffff.  It is also implemented as an
assertion rather than a proper error message despite that the situation
can be triggered by user input.  Additionally there is no check made for
individual `.got.plt' entries referred even though they can be out of
range while the `.got.plt' start address is not.

Fix all these problems and use the correct range for the check, limiting
it to n64 output files, and then issue a proper error message both in
`mips_finish_exec_plt' and in `_bfd_mips_elf_finish_dynamic_symbol',
suggesting the use of the `-Ttext-segment=...' option that will often
work and with the default linker scripts in particular.  Add suitable
tests covering boundary cases.

	bfd/
	PR ld/22966
	* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_symbol): Verify the
	`.got.plt' entry referred is in range.
	(mips_finish_exec_plt): Correct the range check for `.got.plt'
	start.  Replace the assertion used for that with a proper error
	message.

	ld/
	PR ld/22966
	* testsuite/ld-mips-elf/n64-plt-1.dd: New test.
	* testsuite/ld-mips-elf/n64-plt-1.gd: New test.
	* testsuite/ld-mips-elf/n64-plt-2.ed: New test.
	* testsuite/ld-mips-elf/n64-plt-3.ed: New test.
	* testsuite/ld-mips-elf/n64-plt-4.dd: New test.
	* testsuite/ld-mips-elf/n64-plt-4.gd: New test.
	* testsuite/ld-mips-elf/n64-plt-1.ld: New test linker script.
	* testsuite/ld-mips-elf/n64-plt-2.ld: New test linker script.
	* testsuite/ld-mips-elf/n64-plt-3.ld: New test linker script.
	* testsuite/ld-mips-elf/n64-plt-4.ld: New test linker script.
	* testsuite/ld-mips-elf/n64-plt.s: New test source.
	* testsuite/ld-mips-elf/n64-plt-lib.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2018-06-20 00:37:51 +01:00
Maciej W. Rozycki 6a382bcead MIPS/BFD: Fix `loc' formatting in `_bfd_mips_elf_finish_dynamic_symbol'
Fix a formatting fallout in `_bfd_mips_elf_finish_dynamic_symbol' from
commit ce558b89b1 ("Delete duplicate target short-cuts to dynamic
sections").

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_symbol): Fix
	formatting.
2018-06-20 00:37:51 +01:00
Simon Marchi d0ac1c4488 Bump to autoconf 2.69 and automake 1.15.1
When trying to run the update-gnulib.sh script in gdb, I get this:

Error: Wrong automake version (Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^      =:+{}]+)}/ at /opt/automake/1.11.1/bin/automake line 4113.), we need 1.11.1.
Aborting.

Apparently, it's an issue with a regex in automake that triggers a
warning starting with Perl 5.22.  It has been fixed in automake 1.15.1.
So I think it's a good excuse to bump the versions of autoconf and
automake used in the gnulib import.  And to avoid requiring multiple
builds of autoconf/automake, it was suggested that we bump the required
version of those tools for all binutils-gdb.

For autoconf, the 2.69 version is universally available, so it's an easy
choice.  For automake, different distros and distro versions have
different automake versions.  But 1.15.1 seems to be the most readily
available as a package.  In any case, it's easy to build it from source.

I removed the version checks from AUTOMAKE_OPTIONS and AC_PREREQ,
because I don't think they are useful in our case.  They only specify a
lower bound for the acceptable version of automake/autoconf.  That's
useful if you let the user choose the version of the tool they want to
use, but want to set a minimum version (because you use a feature that
was introduced in that version).  In our case, we force people to use a
specific version anyway.  For the autoconf version, we have the check in
config/override.m4 that enforces the version we want.  It will be one
less thing to update next time we change autotools version.

I hit a few categories of problems that required some changes.  They are
described below along with the chosen solutions.

Problem 1:

  configure.ac:17: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
  configure.ac:17: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation

Solution 1:

  Adjust the code based on the example at that URL.

Problem 2 (in zlib/):

  Makefile.am: error: required file './INSTALL' not found
  Makefile.am:   'automake --add-missing' can install 'INSTALL'
  Makefile.am: error: required file './NEWS' not found
  Makefile.am: error: required file './AUTHORS' not found
  Makefile.am: error: required file './COPYING' not found
  Makefile.am:   'automake --add-missing' can install 'COPYING'

Solution 2:

  Add the foreign option to AUTOMAKE_OPTIONS.

Problem 3:

  doc/Makefile.am:20: error: support for Cygnus-style trees has been removed

Solution 3:

  Remove the cygnus options.

Problem 4:

  Makefile.am:656: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')

Solution 4:

  Rename "INCLUDES = " to "AM_CPPFLAGS += " (because AM_CPPFLAGS is
  already defined earlier).

Problem 5:

  doc/Makefile.am:71: warning: suffix '.texinfo' for Texinfo files is discouraged; use '.texi' instead
  doc/Makefile.am: warning: Oops!
  doc/Makefile.am:     It appears this file (or files included by it) are triggering
  doc/Makefile.am:     an undocumented, soon-to-be-removed automake hack.
  doc/Makefile.am:     Future automake versions will no longer place in the builddir
  doc/Makefile.am:     (rather than in the srcdir) the generated '.info' files that
  doc/Makefile.am:     appear to be cleaned, by e.g. being listed in CLEANFILES or
  doc/Makefile.am:     DISTCLEANFILES.
  doc/Makefile.am:     If you want your '.info' files to be placed in the builddir
  doc/Makefile.am:     rather than in the srcdir, you have to use the shiny new
  doc/Makefile.am:     'info-in-builddir' automake option.

Solution 5:

  Rename .texinfo files to .texi.

Problem 6:

  doc/Makefile.am: warning: Oops!
  doc/Makefile.am:     It appears this file (or files included by it) are triggering
  doc/Makefile.am:     an undocumented, soon-to-be-removed automake hack.
  doc/Makefile.am:     Future automake versions will no longer place in the builddir
  doc/Makefile.am:     (rather than in the srcdir) the generated '.info' files that
  doc/Makefile.am:     appear to be cleaned, by e.g. being listed in CLEANFILES or
  doc/Makefile.am:     DISTCLEANFILES.
  doc/Makefile.am:     If you want your '.info' files to be placed in the builddir
  doc/Makefile.am:     rather than in the srcdir, you have to use the shiny new
  doc/Makefile.am:     'info-in-builddir' automake option.

Solution 6:

  Remove the hack at the bottom of doc/Makefile.am and use
  the info-in-builddir automake option.

Problem 7:

  doc/Makefile.am:35: error: required file '../texinfo.tex' not found
  doc/Makefile.am:35:   'automake --add-missing' can install 'texinfo.tex'

Solution 7:

  Use the no-texinfo.tex automake option.  We also have one in
  texinfo/texinfo.tex, not sure if we should point to that, or move it
  (or a newer version of it added with automake --add-missing) to
  top-level.

Problem 8:

  Makefile.am:131: warning: source file 'config/tc-aarch64.c' is in a subdirectory,
  Makefile.am:131: but option 'subdir-objects' is disabled
  automake: warning: possible forward-incompatibility.
  automake: At least a source file is in a subdirectory, but the 'subdir-objects'
  automake: automake option hasn't been enabled.  For now, the corresponding output
  automake: object file(s) will be placed in the top-level directory.  However,
  automake: this behaviour will change in future Automake versions: they will
  automake: unconditionally cause object files to be placed in the same subdirectory
  automake: of the corresponding sources.
  automake: You are advised to start using 'subdir-objects' option throughout your
  automake: project, to avoid future incompatibilities.

Solution 8:

  Use subdir-objects, that means adjusting references to some .o that will now
  be in config/.

Problem 9:

  configure.ac:375: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
  ../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from...
  ../../lib/autoconf/general.m4:2601: _AC_COMPILE_IFELSE is expanded from...
  ../../lib/autoconf/general.m4:2617: AC_COMPILE_IFELSE is expanded from...
  ../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from...
  ../../lib/autoconf/general.m4:2042: AC_CACHE_VAL is expanded from...
  ../../lib/autoconf/general.m4:2063: AC_CACHE_CHECK is expanded from...
  configure.ac:375: the top level

Solution 9:

  Use AC_LANG_SOURCE, or use proper quoting.

Problem 10 (in intl/):

  configure.ac:7: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
  /usr/share/aclocal/threadlib.m4:36: gl_THREADLIB_EARLY_BODY is expanded from...
  /usr/share/aclocal/threadlib.m4:29: gl_THREADLIB_EARLY is expanded from...
  /usr/share/aclocal/threadlib.m4:318: gl_THREADLIB is expanded from...
  /usr/share/aclocal/lock.m4:9: gl_LOCK is expanded from...
  /usr/share/aclocal/intl.m4:211: gt_INTL_SUBDIR_CORE is expanded from...
  /usr/share/aclocal/intl.m4:25: AM_INTL_SUBDIR is expanded from...
  /usr/share/aclocal/gettext.m4:57: AM_GNU_GETTEXT is expanded from...
  configure.ac:7: the top level

Solution 10:

  Add AC_USE_SYSTEM_EXTENSIONS in configure.ac.

ChangeLog:

	* libtool.m4: Use AC_LANG_SOURCE.
	* configure.ac: Remove AC_PREREQ, use AC_LANG_SOURCE.
	* README-maintainer-mode: Update version requirements.
	* ar-lib: New file.
	* test-driver: New file.
	* configure: Re-generate.

bfd/ChangeLog:

	* Makefile.am (AUTOMAKE_OPTIONS): Remove 1.11.
	(INCLUDES): Rename to ...
	(AM_CPPFLAGS): ... this.
	* configure.ac: Remove AC_PREREQ.
	* doc/Makefile.am (AUTOMAKE_OPTIONS): Remove 1.9, cygnus, add
	info-in-builddir no-texinfo.tex.
	(info_TEXINFOS): Rename bfd.texinfo to bfd.texi.
	* doc/bfd.texinfo: Rename to ...
	* doc/bfd.texi: ... this.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* config.in: Re-generate.
	* configure: Re-generate.
	* doc/Makefile.in: Re-generate.

binutils/ChangeLog:

	* configure.ac: Remove AC_PREREQ.
	* doc/Makefile.am (AUTOMAKE_OPTIONS): Remove cygnus, add
	info-in-builddir no-texinfo.tex.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* config.in: Re-generate.
	* configure: Re-generate.
	* doc/Makefile.in: Re-generate.

config/ChangeLog:

	* override.m4 (_GCC_AUTOCONF_VERSION): Bump from 2.64 to 2.69.

etc/ChangeLog:

	* configure.in: Remove AC_PREREQ.
	* configure: Re-generate.

gas/ChangeLog:

	* Makefile.am (AUTOMAKE_OPTIONS): Remove 1.11, add subdir-objects.
	(TARG_CPU_O, OBJ_FORMAT_O, ATOF_TARG_O): Add config/ prefix.
	* configure.ac (TARG_CPU_O, OBJ_FORMAT_O, ATOF_TARG_O, emfiles,
	extra_objects): Add config/ prefix.
	* doc/as.texinfo: Rename to...
	* doc/as.texi: ... this.
	* doc/Makefile.am: Rename as.texinfo to as.texi throughout.
	Remove DISTCLEANFILES hack.
	(AUTOMAKE_OPTIONS): Remove 1.8, cygnus, add no-texinfo.tex and
	info-in-builddir.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* config.in: Re-generate.
	* configure: Re-generate.
	* doc/Makefile.in: Re-generate.

gdb/ChangeLog:

	* common/common-defs.h (PACKAGE_NAME, PACKAGE_VERSION,
	PACKAGE_STRING, PACKAGE_TARNAME): Undefine.
	* configure.ac: Remove AC_PREREQ, add missing quoting.
	* gnulib/configure.ac: Modernize usage of
	AC_INIT/AM_INIT_AUTOMAKE.  Remove AC_PREREQ.
	* gnulib/update-gnulib.sh (AUTOCONF_VERSION): Bump to 2.69.
	(AUTOMAKE_VERSION): Bump to 1.15.1.
	* configure: Re-generate.
	* config.in: Re-generate.
	* aclocal.m4: Re-generate.
	* gnulib/aclocal.m4: Re-generate.
	* gnulib/config.in: Re-generate.
	* gnulib/configure: Re-generate.
	* gnulib/import/Makefile.in: Re-generate.

gdb/gdbserver/ChangeLog:

	* configure.ac: Remove AC_PREREQ, add missing quoting.
	* configure: Re-generate.
	* config.in: Re-generate.
	* aclocal.m4: Re-generate.

gdb/testsuite/ChangeLog:

	* configure.ac: Remove AC_PREREQ.
	* configure: Re-generate.

gold/ChangeLog:

	* configure.ac: Remove AC_PREREQ, add missing quoting and usage
	of AC_LANG_SOURCE.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* configure: Re-generate.
	* testsuite/Makefile.in: Re-generate.

gprof/ChangeLog:

	* configure.ac: Remove AC_PREREQ.
	* Makefile.am: Remove DISTCLEANFILES hack.
	(AUTOMAKE_OPTIONS): Remove 1.11, add info-in-builddir.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* configure: Re-generate.
	* gconfig.in: Re-generate.

intl/ChangeLog:

	* configure.ac: Add AC_USE_SYSTEM_EXTENSIONS, remove AC_PREREQ.
	* configure: Re-generate.
	* config.h.in: Re-generate.
	* aclocal.m4: Re-generate.

ld/ChangeLog:

	* configure.ac: Remove AC_PREREQ.
	* Makefile.am: Remove DISTCLEANFILES hack, rename ld.texinfo to
	ld.texi, ldint.texinfo to ldint.texi throughout.
	(AUTOMAKE_OPTIONS): Add info-in-builddir.
	* README: Rename ld.texinfo to ld.texi, ldint.texinfo to
	ldint.texi throughout.
	* gen-doc.texi: Likewise.
	* h8-doc.texi: Likewise.
	* ld.texinfo: Rename to ...
	* ld.texi: ... this.
	* ldint.texinfo: Rename to ...
	* ldint.texi: ... this.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* config.in: Re-generate.
	* configure: Re-generate.

libdecnumber/ChangeLog:

	* configure.ac: Remove AC_PREREQ.
	* configure: Re-generate.
	* aclocal.m4.

libiberty/ChangeLog:

	* configure.ac: Remove AC_PREREQ.
	* configure: Re-generate.
	* config.in: Re-generate.

opcodes/ChangeLog:

	* Makefile.am (AUTOMAKE_OPTIONS): Remove 1.11.
	* configure.ac: Remove AC_PREREQ.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* configure: Re-generate.

readline/ChangeLog.gdb:

	* configure: Re-generate.
	* examples/rlfe/configure: Re-generate.

sim/ChangeLog:

	* All configure.ac: Remove AC_PREREQ.
	* All configure: Re-generate.

zlib/ChangeLog.bin-gdb:

	* configure.ac: Modernize AC_INIT call, remove AC_PREREQ.
	* Makefile.am (AUTOMAKE_OPTIONS): Remove 1.8, cygnus, add
	foreign.
	* Makefile.in: Re-generate.
	* aclocal.m4: Re-generate.
	* configure: Re-generate.
2018-06-19 16:55:06 -04:00
Mephi ed1299fe46 Add support for the TLV relocation generated by LLVM for x86_64 MACH-O targets.
PR 23297
	* mach-o-x86-64.c (x86_64_howto_table): Add entry for
	BFD_RELOC_MACH_O_X86_64_RELOC_TLV.
	(bfd_mach_o_x86_64_canonicalize_one_reloc): Handle the new reloc.
	(bfd_mach_o_x86_64_swap_reloc_out): Likewise.
	* reloc.c (BFD_RELOC_MACH_O_X86_64_TV): New entry.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
2018-06-18 12:56:44 +01:00
Faraz Shahbazker 6f20c942c3 MIPS: Add Global INValidate ASE support
Add support for the Global INValidate Application Specific Extension
for Release 6 of the MIPS Architecture.

[1] "MIPS Architecture for Programmers Volume II-A: The MIPS32
    Instruction Set Manual", Imagination Technologies Ltd., Document
    Number: MD00086, Revision 6.06, December 15, 2016, Section 3.2
    "Alphabetical List of Instructions", pp. 187-191

bfd/
	* elfxx-mips.c (print_mips_ases): Add GINV extension.

binutils/
	* readelf.c (print_mips_ases): Add GINV extension.

gas/
	* NEWS: Mention MIPS Global INValidate ASE support.
	* config/tc-mips.c (options): Add OPTION_GINV and OPTION_NO_GINV.
	(md_longopts): Likewise.
	(mips_ases): Define availability for GINV.
	(mips_convert_ase_flags): Map ASE_GINV to AFL_ASE_GINV.
	(md_show_usage): Add help for -mginv and -mno-ginv.
	* doc/as.texinfo: Document -mginv, -mno-ginv.
	* doc/c-mips.texi: Document -mginv, -mno-ginv, .set ginv and
	.set noginv.
	* testsuite/gas/mips/ase-errors-1.s: Add error checks for GINV
	ASE.
	* testsuite/gas/mips/ase-errors-2.s: Likewise.
	* testsuite/gas/mips/ase-errors-1.l: Likewise.
	* testsuite/gas/mips/ase-errors-2.l: Likewise.
	* testsuite/gas/mips/ginv.d: New test.
	* testsuite/gas/mips/ginv-err.d: New test.
	* testsuite/gas/mips/ginv-err.l: New test stderr output.
	* testsuite/gas/mips/ginv.s: New test source.
	* testsuite/gas/mips/ginv-err.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

include/
	* elf/mips.h (AFL_ASE_GINV, AFL_ASE_RESERVED1): New macros.
	(AFL_ASE_MASK): Update to include AFL_ASE_GINV.
	* opcode/mips.h: Document "+\" operand format.
	(ASE_GINV): New macro.

opcodes/
	* mips-dis.c (mips_arch_choices): Add GINV to mips32r6 and
	mips64r6 descriptors.
	(parse_mips_ase_option): Handle -Mginv option.
	(print_mips_disassembler_options): Document -Mginv.
	* mips-opc.c (decode_mips_operand) <+\>: New operand format.
	(GINV): New macro.
	(mips_opcodes): Define ginvi and ginvt.
2018-06-14 21:34:49 +01:00
H.J. Lu 1f6f5dba57 elf: Check if the first symbol version is base version
Check VER_FLG_BASE instead of assuming that the first symbol version is
base version.

bfd/

	PR binutils/23267
	* elf.c (_bfd_elf_get_symbol_version_string): Check if the first
	symbol version is base version.

binutils/

	PR binutils/23267
	* readelf.c (get_symbol_version_string): Check if the first
	symbol version is base version.
2018-06-14 05:37:33 -07:00
Alan Modra 7f923b7fd2 ELF dynsyms
Many ELF targets arrange to emit a number of section symbols in
.dynsym for use by dynamic relocations.  This happens before the
dynamic relocations are output, and the need for those symbols
determined.  In most cases they are not needed.  A proper analysis of
the need for dynamic section symbols is target specific and tedious,
so this patch just excludes them in the obvious case when no
dynamic relocations are present.

The patch also runs the new pr23161 and pr23162 tests on more targets.

bfd/
	* elf-bfd.h (struct elf_link_hash_table): Add "dynamic_relocs".
	* elflink.c (_bfd_elf_init_2_index_sections): Comment fix.
	(_bfd_elf_add_dynamic_entry): Set "dynamic_relocs".
	(_bfd_elf_link_renumber_dynsyms): Exclude all section symbols when
	"dynamic_relocs" is not set.
	* elfxx-mips.c (count_section_dynsyms): Likewise.
ld/
	* testsuite/ld-elf/readelf.exp: Delete DUMP and selection of
	variant ver_def.vd.
	* testsuite/ld-elf/ver_def-tic6x.vd: Delete.
	* testsuite/ld-elf/shared.exp: Run most pr23161 and pr23162 tests for
	linux, nacl and gnu targets.
	* testsuite/ld-mips-elf/mips-elf.exp: Set base_syms to 1.
	* testsuite/ld-elf/pr23161a.rd: Don't check reloc type.  Allow any
	order of __bss_start, _edata and _end.
	* testsuite/ld-elf/pr23161b.rd: Don't check plt and dyn relocs.
	Allow and order of __bss_start, _edata and _end.
	* testsuite/ld-elf/pr23162.rd: Fail if __bss_start, _edata or _end
	relocs are present rather than testing for no relocations.
	* testsuite/ld-aarch64/gc-plt-relocs.d,
	* testsuite/ld-aarch64/ifunc-1-local.d,
	* testsuite/ld-aarch64/ifunc-1.d,
	* testsuite/ld-aarch64/ifunc-2-local.d,
	* testsuite/ld-aarch64/ifunc-2.d,
	* testsuite/ld-aarch64/ifunc-21.d,
	* testsuite/ld-aarch64/ifunc-3a.d,
	* testsuite/ld-arm/farcall-mixed-lib-v4t.d,
	* testsuite/ld-arm/farcall-mixed-lib.d,
	* testsuite/ld-arm/gc-hidden-1.d,
	* testsuite/ld-arm/tls-gdesc-got.d,
	* testsuite/ld-arm/tls-lib-loc.d,
	* testsuite/ld-arm/tls-longplt-lib.d,
	* testsuite/ld-arm/tls-thumb1.d,
	* testsuite/ld-cris/libdso-10.d,
	* testsuite/ld-cris/libdso-11.d,
	* testsuite/ld-cris/libdso-13b.d,
	* testsuite/ld-cris/libdso-14.d,
	* testsuite/ld-cris/libdso-15.d,
	* testsuite/ld-cris/pic-gc-72.d,
	* testsuite/ld-cris/pic-gc-73.d,
	* testsuite/ld-cris/tls-gc-71.d,
	* testsuite/ld-mips-elf/mips16-pic-4a.nd,
	* testsuite/ld-mips-elf/pic-and-nonpic-3a.dd,
	* testsuite/ld-mips-elf/pie-n32.d,
	* testsuite/ld-mips-elf/pie-n64.d,
	* testsuite/ld-mips-elf/pie-o32.d: Update for removed dynamic
	section symbols.
2018-06-14 11:32:01 +09:30
Alan Modra ff91d2f0e2 PR23282, Reinstate seek optimization
PR 23282
	* bfdio.c (bfd_seek): Optimize away seeks to current position.
2018-06-14 11:32:01 +09:30
Scott Egerton 730c31740a MIPS: Add CRC ASE support
Add support for the CRC Application Specific Extension for Release 6 of
the MIPS Architecture.

[1] "MIPS Architecture for Programmers Volume II-A: The MIPS32
    Instruction Set Manual", Imagination Technologies Ltd., Document
    Number: MD00086, Revision 6.06, December 15, 2016, Section 3.2
    "Alphabetical List of Instructions", pp. 143-148

[2] "MIPS Architecture for Programmers Volume II-A: The MIPS64
    Instruction Set Manual", Imagination Technologies Ltd., Document
    Number: MD00087, Revision 6.06, December 15, 2016, Section 3.2
    "Alphabetical List of Instructions", pp. 165-170

ChangeLog:

bfd/
2018-06-13  Scott Egerton  <scott.egerton@imgtec.com>
            Faraz Shahbazker  <Faraz.Shahbazker@mips.com>

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

binutils/
2018-06-13  Scott Egerton  <scott.egerton@imgtec.com>
            Faraz Shahbazker  <Faraz.Shahbazker@mips.com>

	* readelf.c (print_mips_ases): Add CRC.

gas/
2018-06-13  Scott Egerton  <scott.egerton@imgtec.com>
            Faraz Shahbazker  <Faraz.Shahbazker@mips.com>
            Maciej W. Rozycki  <macro@mips.com>

	* config/tc-mips.c (options): Add OPTION_CRC and OPTION_NO_CRC.
	(md_longopts): Likewise.
	(md_show_usage): Add help for -mcrc and -mno-crc.
	(mips_ases): Define availability for CRC and CRC64.
	(mips_convert_ase_flags): Map ASE_CRC to AFL_ASE_CRC.
	* doc/as.texinfo: Document -mcrc, -mno-crc.
	* doc/c-mips.texi: Document -mcrc, -mno-crc, .set crc and
	.set no-crc.
	* testsuite/gas/mips/ase-errors-1.l: Add error checks for CRC
	ASE.
	* testsuite/gas/mips/ase-errors-2.l: Likewise.
	* testsuite/gas/mips/ase-errors-1.s: Likewise.
	* testsuite/gas/mips/ase-errors-2.s: Likewise.
	* testsuite/gas/mips/crc.d: New test.
	* testsuite/gas/mips/crc64.d: New test.
	* testsuite/gas/mips/crc-err.d: New test.
	* testsuite/gas/mips/crc64-err.d: New test.
	* testsuite/gas/mips/crc-err.l: New test stderr output.
	* testsuite/gas/mips/crc64-err.l: New test stderr output.
	* testsuite/gas/mips/crc.s: New test source.
	* testsuite/gas/mips/crc64.s: New test source.
	* testsuite/gas/mips/crc-err.s: New test source.
	* testsuite/gas/mips/crc64-err.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

include/
2018-06-13  Scott Egerton  <scott.egerton@imgtec.com>
            Faraz Shahbazker  <Faraz.Shahbazker@mips.com>

	* elf/mips.h (AFL_ASE_CRC): New macro.
	(AFL_ASE_MASK): Update to include AFL_ASE_CRC.
	* opcode/mips.h (ASE_CRC): New macro.
	* opcode/mips.h (ASE_CRC64): Likewise.

opcodes/
2018-06-13  Scott Egerton  <scott.egerton@imgtec.com>
            Faraz Shahbazker  <Faraz.Shahbazker@mips.com>

	* mips-dis.c (mips_arch_choices): Add CRC and CRC64 ASEs.
	* mips-opc.c (CRC, CRC64): New macros.
	(mips_builtin_opcodes): Define crc32b, crc32h, crc32w,
	crc32cb, crc32ch and crc32cw for CRC.  Define crc32d and
	crc32cd for CRC64.
2018-06-13 15:39:05 +01:00
H.J. Lu ecf99cc092 ld/x86: Remove hidden _edata, __bss_start, and _end
There is no need to put hidden _edata, __bss_start, and _end in dynamic
symbol table in shared libraries.

bfd/

	PR ld/23161
	* elfxx-x86.c (elf_x86_hide_linker_defined): New function.
	(_bfd_x86_elf_link_check_relocs): Use it to hide hidden
	__bss_start, _end and _edata in shared libraries.

ld/

	PR ld/23161
	* testsuite/ld-elf/pr23161d.rd: Remove local _edata, __bss_start,
	and _end from dynamic symbol table.
2018-06-08 12:41:54 -07:00
Alan Modra 527278f336 TIC6X __c6xabi_DSBT_BASE
Adding an undefined __c6xabi_DSBT_BASE via an EXTERN in the linker
script isn't ideal, as the symbol is not always needed.  This patch
adds the undefined symbol on encountering relocations where it is
implicitly referenced.

bfd/
	* elf32-tic6x.c (elf32_tic6x_check_relocs): Reference
	__c6xabi_DSBT_BASE explicitly for R_C6000_SBR_* relocs.
ld/
	* emulparams/elf32_tic6x_le.sh (EXECUTABLE_SYMBOLS): Don't define.
2018-06-07 09:07:32 +09:30
Alan Modra 5c4ce239a3 Tidy bfdio to consistenly use containing archive
Archive element IO is performed on the file of the containing archive,
which leads to the BFD "where" field of archives and their elements
being out of sync with the real file position.  (We're talking
traditional archives here, not thin archives.)  The old bfd_seek code
recognized this by not attempting to optimize away seeks for
archives.  However, there was other code that could return bogus
results.  For example, cache.c limits the number of open files by
closing a file and remembering its state once the limit is reached.
If bfd_tell is called on an archive element when the containing
archive is closed, it will return an invalid file pointer.

It's possible to have a valid "where" field for archives by always
using and updating the containing archive BFD.  That's what this patch
does.  Note that cache.c used to find the containing archive BFD
anyway for the iostream, so we're not really doing extra work, just
transferring it up to the correct abstraction level.

The patch also gets rid of some hacks.  bfd_tell was called when
bfd_seek failed, in an attempt to correct "where".  That's got to be
papering over another problem, so that code has been removed.
bfd_read also had an "optimiziation" to return early when the number
of bytes was zero, and bfd_seek optimized calls that didn't move the
file pointer.  This was covering for a coff_slurp_line_table bug where
IO was attempted on a pe-dll BFD without an iovec.

	* bfd.c (struct bfd): Update comment on "where" usage.
	* bfdio.c (bfd_bwrite, bfd_stat): Use and update "iovec",
	"iostream", and "where" from containing archive file.  Return
	error on NULL iovec.
	(bfd_bread): Similarly, and return error attempted out of
	bounds archive element access.
	(bfd_tell, bfd_flush): Use and update "iovec", "iostream", and
	"where" from containing archive file.
	(bfd_seek): Likewise.  Return error on NULL iovec.  Don't
	attempt to optimize away seeks.  Don't paper over errors by
	calling bfd_tell.
	(bfd_get_mtime): Call bfd_stat rather than iovec->bstat.
	(bfd_get_size): Likewise.
	(bfd_mmap): Operate on and use iovec of containing archive
	file.  Return error on NULL iovec.
	* cache.c (bfd_cache_lookup_worker): Abort if working on
	archive element bfd.
	(cache_bread_1): Delete bfd parameter, add FILE* parameter.
	Don't ignore zero byte reads.
	(cache_bread): Look up FILE* in cache here.  Error on NULL
	lookup.
	(cache_bwrite): Rename "where" to "from".
	(cache_bmmap): Don't handle archive elements.
	* coffcode.h (coff_slurp_line_table): Exit early on zero
	lineno count.
	* bfd-in2.h: Regenerate.
2018-06-05 22:39:12 +09:30
Alan Modra 27b0767593 PR23254, ld.bfd mishandles file pointers while scanning archive
Best practice is to not mix lseek/read with fseek/fread on the same
underlying file descriptor, as not all stdio implementations will cope.
Since the plugin uses lseek/read while bfd uses fseek/fread this patch
reopens the file for exclusive use by the plugin rather than trying to
restore the file descriptor.  That allows the plugin to read the file
after plugin_call_claim_file too.

bfd/
	PR 23254
	* plugin.c (bfd_plugin_open_input): Allow for possibility of
	nested archives.  Open file again for plugin.
	(try_claim): Don't save and restore file position.  Close file
	if not claimed.
	* sysdep.h (O_BINARY): Define.
ld/
	PR 23254
	* plugin.c (plugin_call_claim_file): Revert 2016-07-19 patch.
	(plugin_object_p): Don't dup file descriptor.
2018-06-05 22:39:11 +09:30
Max Filippov 4b8e28c793 xtensa: use property tables for correct disassembly
xtensa disassembler does not use information from the .xt.prop sections
to switch between code/data disassembly in text sections. This may
result in incorrect disassembly when data is interpreted as code and
disassembler loses synchronization with instruction stream. Use .xt.prop
section information to correctly interpret code and data and synchronize
with instruction stream.

2018-06-04  Max Filippov  <jcmvbkbc@gmail.com>
bfd/
	* elf32-xtensa.c (xtensa_read_table_entries): Make global.
	(compute_fill_extra_space): Drop declaration. Rename function to
	xtensa_compute_fill_extra_space.
	(compute_ebb_actions, remove_dead_literal): Update references to
	compute_fill_extra_space.

include/
	* elf/xtensa.h (xtensa_read_table_entries)
	(xtensa_compute_fill_extra_space): New declarations.

opcodes/
	* xtensa-dis.c (bfd.h, elf/xtensa.h): New includes.
	(dis_private): Add new fields for property section tracking.
	(xtensa_coalesce_insn_tables, xtensa_find_table_entry)
	(xtensa_instruction_fits): New functions.
	(fetch_data): Bump minimal fetch size to 4.
	(print_insn_xtensa): Make struct dis_private static.
	Load and prepare property table on section change.
	Don't disassemble literals. Don't disassemble instructions that
	cross property table boundaries.
2018-06-04 10:38:55 -07:00
Max Filippov 8255c61b8a xtensa: add separate property sections option
It is currently not possible to correctly match .xt.prop information
for sections with identical VMA. Allow creation of separate property
sections in the BFD. Add assembler option --separate-prop-tables to
allow creation of separate property sections.

2018-06-04  Volodymyr Arbatov  <arbatov@cadence.com>
bfd/

	* elf32-xtensa.c (elf32xtensa_separate_props): New global
	variable.
	(xtensa_add_names): New function.
	(xtensa_property_section_name): Add new parameter
	separate_sections, use it to choose property section name.
	(xtensa_get_separate_property_section): New function.
	(xtensa_get_property_section): Invoke
	xtensa_get_separate_property_section to get individual property
	section if it exists, common property section otherwise.
	(xtensa_make_property_section): Pass elf32xtensa_separate_props
	to xtensa_property_section_name.

gas/
	* config/tc-xtensa.c (elf32xtensa_separate_props): New
	declaration.
	(option_separate_props, option_no_separate_props): New
	enumeration constants.
	(md_longopts): Add separate-prop-tables option.
	(md_parse_option): Add cases for option_separate_props and
	option_no_separate_props.
	(md_show_usage): Add help for [no-]separate-prop-tables options.
2018-06-04 10:36:39 -07:00
H.J. Lu 95da985446 Use DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION to silence GCC 8.1
GCC 8.1 warns about destination size with -Wstringop-truncation:

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

Use DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION to silence it.

bfd/

	PR binutils/23146
	* bfd-in.h: Include "diagnostics.h".
	* bfd-in2.h: Regenerated.
	* elf32-arm.c (elf32_arm_nabi_write_core_note): Use
	DIAGNOSTIC_PUSH, DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION and
	DIAGNOSTIC_POP to silence GCC 8.1 warnings with
	-Wstringop-truncation.
	* elf32-ppc.c (ppc_elf_write_core_note): Likewse.
	* elf32-s390.c (elf_s390_write_core_note): Likewse.
	* elf64-ppc.c (ppc64_elf_write_core_note): Likewse.
	* elf64-s390.c (elf_s390_write_core_note): Likewse.
	* elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewse.

include/

	* diagnostics.h (DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION): Always
	define for GCC.
2018-06-04 10:01:46 -07:00
Jim Wilson cf7a5066b9 RISC-V: Handle out-of-range calls to undefined weak.
bfd/
	PR ld/23244
	* elfnn-riscv.c (riscv_elf_relocate_section) <R_RISCV_CALL>: Check
	for and handle an undefined weak with no PLT.

	ld/
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run new weak ref tests.
	* testsuite/ld-riscv-elf/weakref.ld: New.
	* testsuite/ld-riscv-elf/weakref32.d: New.
	* testsuite/ld-riscv-elf/weakref32.s: New.
	* testsuite/ld-riscv-elf/weakref64.d: New.
	* testsuite/ld-riscv-elf/weakref64.s: New.
2018-06-03 15:42:29 -07:00
Jim Wilson 137b5cbd20 RISC-V: Fix symbol address problem with versioned symbols.
bfd/
	PR ld/22756
	* elfnn-riscv.c (riscv_relax_delete_bytes): Add versioned_hidden check
	to code that ignores duplicate symbols.
2018-06-03 14:44:44 -07:00
H.J. Lu 55e99962b2 Bump version number to 2.30.52
Bump version number to 2.30.52 since _bfd_link_hide_symbol has been added
to bfd_target.

bfd/

	* version.m4: Bump version to 2.30.52
	* configure: Regenerated.

binutils/

	* configure: Regenerated.

gas/

	* configure: Regenerated.

gprof/

	* configure: Regenerated.

ld/

	* configure: Regenerated.

opcodes/

	* configure: Regenerated.
2018-06-01 09:34:16 -07:00
Alan Modra 030157d8a6 Make _bfd_error_handler available outside libbfd
Needed when building libopcodes.so.

bfd/
	* bfd.c (_bfd_error_handler): Arrange for this function to be
	declared in bfd-in2.h.
	* libbfd-in.h (_bfd_error_handler): Don't declare.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
opcodes/
	* sysdep.h (_bfd_error_handler): Don't declare.
	* msp430-decode.opc: Include bfd.h.  Don't include ansidecl.h here.
	* rl78-decode.opc: Likewise.
	* msp430-decode.c: Regenerate.
	* rl78-decode.c: Regenerate.
2018-06-01 13:10:33 +09:30
Amaan Cheval 421acf1873 2018-05-30 Amaan Cheval <amaan.cheval@gmail.com>
* config.bfd (x86_64-*-*): Add pei-x86-64 target to x86_64-*-rtems*
	This is needed to generate UEFI application image files from ELFs.
2018-05-30 10:04:28 -05:00
H.J. Lu 92e68c1d65 x86-64: Add TLSDESC fields to elf_x86_lazy_plt_layout
ENDBR64 is added to the special TLSDESC entry, which is similar to the
PLT0 entry, in the x86-64 lazy procedure linkage table to support Intel
CET.  The NaCl PLT is different from the normal PLT.  This patch adds
plt_tlsdesc_entry, plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
plt_tlsdesc_got2_insn_end to elf_x86_lazy_plt_layout to support both
normal and NaCl TLSDESC entries.  This fixed

FAIL: TLS descriptor -fpic -shared transitions

for x86_64-nacl.

	* elf32-i386.c (elf_i386_lazy_plt): Add plt_tlsdesc_entry,
	plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
	plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
	plt_tlsdesc_got2_insn_end for TLSDESC entry.
	(elf_i386_lazy_ibt_plt): Likewise.
	(elf_i386_nacl_plt): Likewise.
	* elf64-x86-64.c (tlsdesc_plt_entry): Moved and renamed to ...
	(elf_x86_64_tlsdesc_plt_entry): This.
	(elf_x86_64_lazy_plt): Add plt_tlsdesc_entry,
	plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
	plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
	plt_tlsdesc_got2_insn_end for TLSDESC entry.
	(elf_x86_64_lazy_bnd_plt): Likewise.
	(elf_x86_64_lazy_ibt_plt): Likewise.
	(elf_x32_lazy_ibt_plt): Likewise.
	(elf_x86_64_nacl_plt): Likewise.
	(elf_x86_64_finish_dynamic_sections): Use plt_tlsdesc_entry,
	plt_tlsdesc_entry_size, plt_tlsdesc_got1_offset,
	plt_tlsdesc_got2_offset, plt_tlsdesc_got1_insn_end and
	plt_tlsdesc_got2_insn_end to update TLSDESC entry.
	* elfxx-x86.h (elf_x86_lazy_plt_layout): Update comments.
	Add plt_tlsdesc_entry, plt_tlsdesc_entry_size,
	plt_tlsdesc_got1_offset, plt_tlsdesc_got2_offset,
	plt_tlsdesc_got1_insn_end and plt_tlsdesc_got2_insn_end.
	(elf_x86_non_lazy_plt_layout): Update comments.
	(elf_x86_plt_layout): Likewise.
2018-05-28 10:46:16 -07:00
H.J. Lu ac98f9e227 ld: Unify STT_GNU_IFUNC handling
Take STT_GNU_IFUNC handling scattered across targets and gather it in
the generic ELF linker.

bfd/

	PR ld/23238
	* elf-s390-common.c (elf_s390_add_symbol_hook): Removed.
	* elf32-arc.c (elf_arc_add_symbol_hook): Likewise.
	(elf_backend_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	(elf_backend_add_symbol_hook): Likewise.
	* elf32-s390.c (elf_backend_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	(elf_backend_add_symbol_hook): Likewise.
	* elf64-s390.c (elf_backend_add_symbol_hook): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elfxx-aarch64.h (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	(elf_backend_add_symbol_hook): Likewise.
	* elf32-arm.c (elf32_arm_add_symbol_hook): Remove STT_GNU_IFUNC
	handling.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elflink.c (elf_link_add_object_symbols): Set
	elf_gnu_symbol_ifunc for STT_GNU_IFUNC symbols.

ld/

	PR ld/23238
	* testsuite/ld-ifunc/ifunc-26.d: New file.
	* testsuite/ld-ifunc/ifunc-26.s: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Run *.d tests without a
	working compiler.
2018-05-28 08:15:21 -07:00
H.J. Lu 099bb8fb97 ld: Add _bfd_elf_link_hide_sym_by_version
bfd_hide_sym_by_version can't be used to check if a versioned symbol is
hidden.  This patch adds _bfd_elf_link_hide_sym_by_version to support
both versioned and unversioned symbols by extracting versioned symbol
check from _bfd_elf_link_assign_sym_version.

bfd/

	PR ld/23194
	* elf-bfd.h (_bfd_elf_link_hide_sym_by_version): New.
	* elflink.c (_bfd_elf_link_hide_versioned_symbol): New function.
	Extracted from _bfd_elf_link_assign_sym_version.
	(_bfd_elf_link_hide_sym_by_version): New function.
	(_bfd_elf_link_assign_sym_version): Use
	_bfd_elf_link_hide_versioned_symbol.
	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Call
	_bfd_elf_link_hide_sym_by_version instead of
	bfd_hide_sym_by_version.  Don't check unversioned symbol.

ld/

	PR ld/23194
	* testsuite/ld-i386/pr23194.d: Expect only R_386_GLOB_DAT
	against foobar.
	* testsuite/ld-i386/pr23194.map: Add foobar.
	* testsuite/ld-x86-64/pr23194.map: Likewise.
	* testsuite/ld-i386/pr23194.s: Add a common foobar symbol.
	* testsuite/ld-x86-64/pr23194.s: Likewise.
	* testsuite/ld-x86-64/pr23194.d: Expect only R_X86_64_GLOB_DAT
	against foobar.
2018-05-26 04:27:24 -07:00
Alan Modra 277eb7f64a s12z regen
This patch regenerates a number of files that either were edited by
hand or not regenerated when s12z support was added to binutils.

bfd/
	* Makefile.in: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
gas/
	* po/POTFILES.in: Regenerate.
ld/
	* po/BLD-POTFILES.in: Regenerate.
opcodes/
	* Makefile.in: Regenerate.
	* po/POTFILES.in: Regenerate.
2018-05-25 16:05:30 +09:30
Alan Modra 629dabe3b7 Fix hidden visibility compiler test
Warnings from configure tests aren't usually checked.  gcc's
"visibility attribute not supported in this configuration" warning is
enabled by default so we don't need to add any warning flag except
-Werror.

	* configure.ac (bfd_cv_hidden): Run test with -Werror in CFLAGS.
	* configure: Regenerate.
2018-05-25 15:26:47 +09:30
H.J. Lu 9ef6d1e31f Add ATTRIBUTE_NONSTRING to ppc64_elf_write_core_note
This patch silences gcc8 -Wstringop-truncation warnings.

	* elf64-ppc.c (ppc64_elf_write_core_note): Add ATTRIBUTE_NONSTRING
	to data.
2018-05-23 10:15:11 -07:00
Alan Modra 215f527155 PR23207, hppa ld SIGSEGVs on invalid object files
The last patch was enough to cure the testcase, but not the original
object file.  This patch does the same for hppa as is done for ppc64,
simply test for the section belonging to a group.  I've also
restricted stubs to load, alloc, code sections.

	PR 23207
	* elf32-hppa.c (hppa_get_stub_entry): Return NULL when link_sec
	is NULL.
	(elf32_hppa_size_stubs): Only create stubs for load, alloc, code
	sections.
	(final_link_relocate): Revert last change.
2018-05-22 19:37:06 +09:30
Alan Modra 7455c018e4 PR23207, hppa ld SIGSEGVs on invalid object files
We don't create PLT call stubs for anything in non-alloc sections,
so it doesn't pay to go looking for them.  The problem is that
non-alloc sections aren't processed by group_sections and thus don't
get a link_sec set up for them.

	PR 23207
	* elf32-hppa.c (final_link_relocate): Don't look for plt call
	stubs in non-alloc sections.
2018-05-22 14:45:15 +09:30
H.J. Lu 34a87bb07a ld: Hide symbols defined by HIDDEN/PROVIDE_HIDDEN
There should be no difference in output for symbols defined by HIDDEN
or PROVIDE_HIDDEN assignments whether they are explicitly marked as
hidden or not.  This patch adds a new BFD function, bfd_link_hide_symbol,
to hide symbols defined by HIDDEN and PROVIDE_HIDDEN assignments.

bfd

	PR ld/23201
	* aout-target.h (MY_bfd_link_hide_symbol): New.
	* aout-tic30.c (MY_bfd_link_hide_symbol): Likewise.
	* binary.c (binary_bfd_link_hide_symbol): Likewise.
	* coff-alpha.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise.
	* coff-mips.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise.
	* coff-rs6000.c (_bfd_xcoff_bfd_link_hide_symbol): Likewise.
	* coffcode.h (coff_bfd_link_hide_symbol): Likewise.
	* elf-bfd.h (_bfd_elf_link_hide_symbol): Likewise.
	* elfxx-target.h (bfd_elfNN_bfd_link_hide_symbol): Likewise.
	* i386msdos.c (msdos_bfd_link_hide_symbol): Likewise.
	* ihex.c (ihex_bfd_link_hide_symbol): Likewise.
	* libbfd-in.h (_bfd_nolink_bfd_link_hide_symbol): Likewise.
	* linker.c (_bfd_generic_link_hide_symbol): Likewise.
	(bfd_link_hide_symbol): Likewise.
	* mach-o-target.c (bfd_mach_o_bfd_link_hide_symbol): Likewise.
	* mmo.c (mmo_bfd_link_hide_symbol): Likewise.
	* pef.c (bfd_pef_bfd_link_hide_symbol): Likewise.
	* plugin.c (bfd_plugin_bfd_link_hide_symbol): Likewise.
	* ppcboot.c (ppcboot_bfd_link_hide_symbol): Likewise.
	* som.c (som_bfd_link_hide_symbol): Likewise.
	* srec.c (srec_bfd_link_hide_symbol): Likewise.
	* tekhex.c (tekhex_bfd_link_hide_symbol): Likewise.
	* vms-alpha.c (vms_bfd_link_hide_symbol): Likewise.
	(alpha_vms_bfd_link_hide_symbol): Likewise.
	* xsym.c (bfd_sym_bfd_link_hide_symbol): Likewise.
	* coff64-rs6000.c (rs6000_xcoff64_vec): Add
	_bfd_generic_link_hide_symbol.
	(rs6000_xcoff64_aix_vec): Likewise.
	* elflink.c (bfd_elf_record_link_assignment): Don't make forced
	local symbol dynamic.
	(_bfd_elf_link_hide_symbol): New function.
	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
	check root.ldscript_def.
	* targets.c (bfd_target): Add _bfd_link_hide_symbol.
	(BFD_JUMP_TABLE_LINK): Add NAME##_bfd_link_hide_symbol.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

ld/

	PR ld/23201
	* ldexp.c (exp_fold_tree_1): Call bfd_link_hide_symbol to hide
	a symbol.
	* testsuite/ld-elf/provide-hidden-dynabs.nd: Removed.
	* testsuite/ld-elf/provide-hidden-dynsec.nd: Likewise.
	* testsuite/ld-elf/provide-hidden.exp: Replace
	provide-hidden-dynsec.nd with provide-hidden-sec.nd and
	provide-hidden-dyn.nd.  Replace provide-hidden-dynabs.nd with
	provide-hidden-abs.nd and provide-hidden-dyn.nd.
	* testsuite/ld-i386/pr23189.d: Expect no dynamic relocation.
	* testsuite/ld-x86-64/pr23189.d: Likewise.
2018-05-21 20:39:30 -07:00
H.J. Lu bae363f114 Mark section in a section group with SHF_GROUP
All sections in a section group should be marked with SHF_GROUP.  But
some tools generate broken objects without SHF_GROUP.  This patch fixes
them up for objcopy and strip.

	PR binutils/23199
	* elf.c (setup_group): Mark section in a section group with
	SHF_GROUP.
2018-05-21 19:25:33 -07:00
H.J. Lu 97373b2eba x86: Don't set eh->local_ref to 1 for versioned symbol
bfd_hide_sym_by_version can't be used to check if a versioned symbol is
hidden.  It has to be synced with _bfd_elf_link_assign_sym_version to
get the correct answer.

bfd/

	PR ld/23194
	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
	set eh->local_ref to 1 if a symbol is versioned and there is a
	version script.

ld/

	PR ld/23194
	* testsuite/ld-i386/i386.exp: Run pr23194.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr23194.d: New file.
	* testsuite/ld-i386/pr23194.map: Likewise.
	* testsuite/ld-i386/pr23194.s: Likewise.
	* testsuite/ld-x86-64/pr23194.d: Likewise.
	* testsuite/ld-x86-64/pr23194.map: Likewise.
	* testsuite/ld-x86-64/pr23194.s: Likewise.
2018-05-18 14:34:49 -07:00
Jim Wilson 7f99954970 RISC-V: Add RV32E support.
Kito Cheng  <kito.cheng@gmail.com>
	Monk Chiang  <sh.chiang04@gmail.com>

	bfd/
	* elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Handle
	EF_RISCV_RVE.

	binutils/
	* readelf.c (get_machine_flags): Handle EF_RISCV_RVE.

	gas/
	* config/tc-riscv.c (rve_abi): New.
	(riscv_set_options): Add rve field.  Initialize it.
	(riscv_set_rve) New function.
	(riscv_set_arch): Support 'e' ISA subset.
	(reg_lookup_internal): If rve, check register is available.
	(riscv_set_abi): New parameter rve.
	(md_parse_option): Pass new argument to riscv_set_abi.
	(riscv_after_parse_args): Call riscv_set_rve.  If rve_abi, set
	EF_RISCV_RVE.
	* doc/c-riscv.texi (-mabi): Document new ilp32e argument.

	include/
	* elf/riscv.h (EF_RISCV_RVE): New define.
2018-05-18 14:03:18 -07:00