Commit Graph

9029 Commits

Author SHA1 Message Date
Alan Modra 1f4361a77b _bfd_mul_overflow
This patch removes the bfd_alloc2 series of memory allocation functions,
replacing them with __builtin_mul_overflow followed by bfd_alloc.  Why
do that?  Well, a followup patch will implement _bfd_alloc_and_read
and I don't want to implement alloc2 variants as well.

	* coffcode.h (buy_and_read, coff_slurp_line_table),
	(coff_slurp_symbol_table, coff_slurp_reloc_table): Replace
	bfd_[z][m]alloc2 calls with _bfd_mul_overflow followed by the
	corresponding bfd_alloc call.  Adjust variables to suit.
	* coffgen.c (_bfd_coff_get_external_symbols): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_symbolic_info),
	(_bfd_ecoff_slurp_symbol_table, READ): Likewise.
	* elf.c (bfd_elf_get_elf_syms, setup_group, bfd_section_from_shdr),
	(swap_out_syms, _bfd_elf_slurp_version_tables): Likewise.
	* elf32-m32c.c (m32c_elf_relax_section): Likewise.
	* elf32-rl78.c (rl78_elf_relax_section): Likewise.
	* elf32-rx.c (elf32_rx_relax_section): Likewise.
	* elf64-alpha.c (READ): Likewise.
	* elfcode.h (elf_object_p, elf_write_relocs, elf_write_shdrs_and_ehdr),
	(elf_slurp_symbol_table, elf_slurp_reloc_table),
	(bfd_from_remote_memory): Likewise.
	* elfcore.h (core_find_build_id): Likewise.
	* elfxx-mips.c (READ): Likewise.
	* mach-o.c (bfd_mach_o_mangle_sections),
	(bfd_mach_o_read_symtab_symbols, bfd_mach_o_read_thread),
	(bfd_mach_o_read_dysymtab, bfd_mach_o_flatten_sections),
	(bfd_mach_o_scan, bfd_mach_o_fat_archive_p): Likewise.
	* som.c (setup_sections, som_prep_for_fixups)
	(som_build_and_write_symbol_table, som_slurp_symbol_table),
	(som_slurp_reloc_table, som_bfd_count_ar_symbols),
	(som_bfd_fill_in_ar_symbols, som_slurp_armap),
	(som_bfd_ar_write_symbol_stuff): Likewise.
	* vms-alpha.c (vector_grow1): Likewise.
	* vms-lib.c (vms_add_index): Likewise.
	* wasm-module.c (wasm_scan_name_function_section): Likewise.
	* libbfd.c (bfd_malloc2, bfd_realloc2, bfd_zmalloc2): Delete.
	* opncls.c (bfd_alloc2, bfd_zalloc2): Delete.
	* libbfd-in.h (bfd_malloc2, bfd_realloc2, bfd_zmalloc2),
	(bfd_alloc2, bfd_zalloc2): Delete.
	(_bfd_mul_overflow): Define.
	* libbfd.h: Regenerate.
2020-02-19 13:15:06 +10:30
Alan Modra 446f7ed5ab alloc2 used unnecessarily
The bfd_alloc2 series of functions were invented to handle cases where
nmemb * size can overflow.  This patch changes some places where the
calculation can't overflow.

	* elf.c (bfd_section_from_shdr): Use bfd_zalloc rather than
	bfd_zalloc2.
	(assign_section_numbers): Likewise.
	(elf_map_symbols): Likewise, and bfd_alloc rather than bfd_alloc2.
	(_bfd_elf_map_sections_to_segments): Use bfd_malloc rather than
	bfd_malloc2, size_t amt, and unsigned tls_count.
	(rewrite_elf_program_header): Use bfd_malloc and size_t amt.
	* elflink.c (elf_create_symbuf): Use bfd_malloc.
	(elf_output_implib): Use bfd_alloc.
2020-02-19 13:14:45 +10:30
Alan Modra b03202e32c bfd_get_size cache
We have calls to bfd_get_size when swapping in ELF section headers.
Since object files can have a large number of sections, it's worth
caching the file size rather than making lots of stat system calls.

	* bfd.c (struct bfd): Move format and direction to other
	bitfields.  Add "size".
	* bfdio.c (bfd_get_size): Cache size when not writing file.
	* opncls.c (bfd_get_debug_link_info_1): Allow for bfd_get_size
	returning zero, ie. unknown.
	(bfd_get_alt_debug_link_info): Likewise.
	* bfd-in2.h: Regenerate.
2020-02-19 13:14:28 +10:30
Alan Modra 7c5fa58ea9 bfd_get_file_size calls
bfd_get_file_size can return 0, meaning the file size is unknown.

	* coffgen.c (_bfd_coff_get_external_symbols): Don't call
	bfd_get_file_size twice.
	(_bfd_coff_read_string_table): Allow for bfd_get_file_size
	zero, ie. unknown, return.
	* elf-attrs.c (_bfd_elf_parse_attributes): Likewise.
	* elfcode.h (elf_swap_shdr_in): Likewise.
	(elf_object_p): Don't call bfd_get_file_size twice and correct
	file size check.
2020-02-19 13:14:05 +10:30
Alan Modra 96d3b80f54 Check return status of memory alloc functions
This fixes a number of places that call a memory allocation function
without checking for a NULL return before using.

	* mach-o.c (bfd_mach_o_flatten_sections): Return a bfd_boolean,
	FALSE if memory alloc fails.  Adjust calls.
	* som.c (som_prep_for_fixups): Likewise.
	* vms-alpha.c (alpha_vms_add_fixup_lp, alpha_vms_add_fixup_ca),
	(alpha_vms_add_fixup_qr, alpha_vms_add_fixup_lr),
	(alpha_vms_add_lw_reloc, alpha_vms_add_qw_reloc): Likewise.
	* som.c (som_build_and_write_symbol_table): Return via error_return
	on seek failure.
	* vms-alpha.c (VEC_APPEND): Adjust for vector_grow1 changes.
	(VEC_APPEND_EL): Delete.
	(vector_grow1): Return pointer to element.  Catch overflow.
	Return NULL on memory allocation failure.
	(alpha_vms_add_fixup_lp): Replace VEC_APPEND_EL with VEC_APPEND.
	(alpha_vms_add_fixup_ca): Likewise.
	(alpha_vms_link_add_object_symbols): Check VEC_APPEND result
	before using.
	* elf.c (bfd_section_from_shdr): Check bfd_zalloc2 result.
2020-02-19 13:12:52 +10:30
Alan Modra 986f078366 bfd_size_type to size_t
bfd_size_type was invented a long time ago in the K&R days.  Many
places in binutils ought to be using size_t instead (and there are
lots of places that use long or unsigned long that really ought to use
size_t too).  Note that you can't change everything over to size_t: A
32-bit host needs a larger type than size_t to support reading and
processing of 64-bit ELF object files.  This patch just tidies some
of the more obvious uses of bfd_size_type that could be size_t.  There
no doubt are more lurking in the source.  Incidentally, practically
all functions used for output of object files can use size_t and don't
need to worry about overflow of size expressions.  If you have
something like
  symcount * sizeof (void *)
when symcount is counting symbols already in memory then you know that
this expression can't overflow since the size of a symbol in memory is
larger by far than that of a pointer.

	* aix386-core.c (aix386_core_file_p): Use size_t for "amt".
	* aout-target.h (object_p): Likewise.
	* aout-tic30.c (tic30_aout_object_p): Likewise.
	* aoutx.h (some_aout_object_p, mkobject, make_empty_symbol),
	(emit_stringtab, write_syms, link_hash_table_create),
	(aout_link_write_other_symbol): Likewise.
	* archive.c (_bfd_generic_mkarchive, bfd_generic_archive_p),
	(bfd_ar_hdr_from_filesystem, _bfd_write_archive_contents),
	(_bfd_compute_and_write_armap): Likewise.
	* archures.c (bfd_arch_list): Likewise.
	* bfd.c (bfd_record_phdr): Likewise.
	* binary.c (binary_canonicalize_symtab): Likewise.
	* cisco-core.c (cisco_core_file_validate): Likewise.
	* coff-arm.c (coff_arm_link_hash_table_create, find_thumb_glue),
	(find_arm_glue, record_arm_to_thumb_glue),
	(record_thumb_to_arm_glue): Likewise.
	* coff-ppc.c (ppc_coff_link_hash_table_create, record_toc),
	(ppc_allocate_toc_section): Likewise.
	* coff-rs6000.c (_bfd_xcoff_mkobject, _bfd_xcoff_archive_p): Likewise.
	* coff-sh.c (sh_relax_section): Likewise.
	* coff64-rs6000.c (xcoff64_archive_p): Likewise.
	* coffcode.h (handle_COMDAT, coff_new_section_hook),
	(coff_set_alignment_hook, coff_mkobject),
	(coff_compute_section_file_positions): Likewise.
	* coffgen.c (coff_make_empty_symbol, coff_bfd_make_debug_symbol),
	(coff_find_nearest_line_with_names),
	( bfd_coff_set_symbol_class): Likewise.
	* cofflink.c (_bfd_coff_link_hash_table_create),
	(_bfd_coff_link_input_bfd): Likewise.
	* dwarf1.c (alloc_dwarf1_unit, alloc_dwarf1_func): Likewise.
	* dwarf2.c (read_abbrevs, read_attribute_value, add_line_info),
	(build_line_info_table, sort_line_sequences),
	(line_info_add_include_dir, line_info_add_file_name),
	(decode_line_info, scan_unit_for_symbols, parse_comp_unit),
	(place_sections, _bfd_dwarf2_slurp_debug_info): Likewise.
	* ecoff.c (_bfd_ecoff_mkobject, _bfd_ecoff_make_empty_symbol),
	(_bfd_ecoff_find_nearest_line),
	(_bfd_ecoff_bfd_link_hash_table_create): Likewise.
	* ecofflink.c (bfd_ecoff_debug_init): Likewise.
	* elf-hppa.h (_bfd_elf_hppa_gen_reloc_type): Likewise.
	* elf-m10300.c (mn10300_elf_relax_section),
	(elf32_mn10300_link_hash_table_create): Likewise.
	* elf-strtab.c (_bfd_elf_strtab_init): Likewise.
	* elf.c (make_mapping, copy_elf_program_header): Likewise.
	* elf32-arm.c (elf32_arm_link_hash_table_create),
	(elf32_arm_setup_section_lists, elf32_arm_check_relocs),
	(elf32_arm_new_section_hook): Likewise.
	* elf32-avr.c (elf_avr_new_section_hook),
	(elf32_avr_link_hash_table_create, get_local_syms),
	(elf32_avr_setup_section_lists): Likewise.
	* elf32-bfin.c (bfinfdpic_elf_link_hash_table_create),
	(bfin_link_hash_table_create): Likewise.
	* elf32-cr16.c (elf32_cr16_link_hash_table_create): Likewise.
	* elf32-cris.c (elf_cris_link_hash_table_create): Likewise.
	* elf32-csky.c (csky_elf_link_hash_table_create),
	(csky_elf_check_relocs, elf32_csky_setup_section_lists): Likewise.
	* elf32-frv.c (frvfdpic_elf_link_hash_table_create): Likewise.
	* elf32-hppa.c (elf32_hppa_link_hash_table_create),
	(elf32_hppa_setup_section_lists, get_local_syms): Likewise.
	* elf32-i386.c (elf_i386_check_relocs): Likewise.
	* elf32-lm32.c (lm32_elf_link_hash_table_create): Likewise.
	* elf32-m32r.c (m32r_elf_link_hash_table_create),
	(m32r_elf_check_relocs): Likewise.
	* elf32-m68hc1x.c (m68hc11_elf_hash_table_create),
	(elf32_m68hc11_setup_section_lists),
	(elf32_m68hc11_size_stubs): Likewise.
	* elf32-m68k.c (elf_m68k_link_hash_table_create): Likewise.
	* elf32-metag.c (elf_metag_link_hash_table_create),
	(elf_metag_setup_section_lists): Likewise.
	* elf32-microblaze.c (microblaze_elf_link_hash_table_create),
	(microblaze_elf_check_relocs): Likewise.
	* elf32-nds32.c (nds32_elf_link_hash_table_create),
	(nds32_elf_check_relocs): Likewise.
	* elf32-nios2.c (nios2_elf32_setup_section_lists),
	(get_local_syms, nios2_elf32_check_relocs),
	(nios2_elf32_link_hash_table_create): Likewise.
	* elf32-or1k.c (or1k_elf_link_hash_table_create),
	(or1k_elf_check_relocs): Likewise.
	* elf32-ppc.c (ppc_elf_modify_segment_map, update_plt_info): Likewise.
	* elf32-pru.c (pru_elf32_link_hash_table_create): Likewise.
	* elf32-s390.c (elf_s390_link_hash_table_create),
	(elf_s390_check_relocs): Likewise.
	* elf32-score.c (score_elf_create_got_section),
	(s3_elf32_score_new_section_hook),
	(elf32_score_link_hash_table_create): Likewise.
	* elf32-score7.c (score_elf_create_got_section),
	(s7_elf32_score_new_section_hook): Likewise.
	* elf32-sh.c (sh_elf_link_hash_table_create),
	(sh_elf_check_relocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_link_hash_table_create),
	(elf32_tic6x_new_section_hook, elf32_tic6x_check_relocs): Likewise.
	* elf32-tilepro.c (tilepro_elf_link_hash_table_create),
	(tilepro_elf_check_relocs): Likewise.
	* elf32-v850.c (remember_hi16s_reloc): Likewise.
	* elf32-vax.c (elf_vax_link_hash_table_create): Likewise.
	* elf32-xtensa.c (elf_xtensa_link_hash_table_create),
	(elf_xtensa_new_section_hook): Likewise.
	* elf64-alpha.c (elf64_alpha_bfd_link_hash_table_create),
	(get_got_entry, elf64_alpha_check_relocs): Likewise.
	* elf64-hppa.c (elf64_hppa_hash_table_create): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_object_p): Likewise.
	* elf64-mmix.c (mmix_elf_new_section_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_new_section_hook),
	(ppc64_elf_link_hash_table_create, update_local_sym_info),
	(update_plt_info, ppc64_elf_check_relocs): Likewise.
	* elf64-s390.c (elf_s390_link_hash_table_create),
	(elf_s390_check_relocs): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elflink.c (bfd_elf_link_record_local_dynamic_symbol),
	(_bfd_elf_link_find_version_dependencies, elf_link_add_object_symbols),
	(elf_link_add_archive_symbols, compute_bucket_count),
	(bfd_elf_size_dynsym_hash_dynstr, _bfd_elf_link_hash_table_create),
	(bfd_elf_get_bfd_needed_list, elf_link_swap_symbols_out),
	(bfd_elf_final_link): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_link_hash_table_create),
	(elfNN_aarch64_setup_section_lists, elfNN_aarch64_check_relocs),
	(elfNN_aarch64_new_section_hook): Likewise.
	* elfnn-ia64.c (elfNN_ia64_object_p): Likewise.
	* elfnn-riscv.c (riscv_elf_link_hash_table_create),
	(riscv_elf_check_relocs): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_new_section_hook),
	(_bfd_mips_elf_add_symbol_hook, _bfd_mips_elf_check_relocs),
	(_bfd_mips_elf_modify_segment_map, _bfd_mips_elf_set_section_contents),
	(_bfd_mips_elf_link_hash_table_create): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_link_hash_table_create),
	(_bfd_sparc_elf_check_relocs),
	(_bfd_sparc_elf_new_section_hook): Likewise.
	* elfxx-tilegx.c (tilegx_elf_link_hash_table_create),
	(tilegx_elf_check_relocs): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Likewise.
	* format.c (bfd_check_format_matches): Likewise.
	* hash.c (_bfd_stringtab_init): Likewise.
	* ihex.c (ihex_scan): Likewise.
	* irix-core.c (irix_core_core_file_p): Likewise.
	* linker.c (bfd_wrapped_link_hash_lookup),
	(_bfd_generic_link_hash_table_create),
	(_bfd_generic_reloc_link_order): Likewise.
	* lynx-core.c (lynx_core_file_p): Likewise.
	* netbsd-core.c (netbsd_core_file_p): Likewise.
	* osf-core.c (osf_core_core_file_p): Likewise.
	* pdp11.c (some_aout_object_p, mkobject, make_empty_symbol),
	(link_hash_table_create, aout_link_write_other_symbol): Likewise.
	* peXXigen.c (_bfd_XX_bfd_copy_private_section_data): Likewise.
	* peicode.h (pe_mkobject): Likewise.
	* ppcboot.c (ppcboot_mkobject, ppcboot_canonicalize_symtab): Likewise.
	* ptrace-core.c (ptrace_unix_core_file_p): Likewise.
	* sco5-core.c (read_uarea): Likewise.
	* som.c (hppa_som_gen_reloc_type, som_object_p, som_prep_headers),
	(som_write_fixups, som_write_space_strings, som_write_symbol_strings),
	(som_finish_writing, som_canonicalize_symtab, som_new_section_hook),
	(som_bfd_copy_private_section_data, bfd_som_set_section_attributes),
	(bfd_som_attach_aux_hdr, som_write_armap): Likewise.
	* srec.c (srec_scan): Likewise.
	* syms.c (_bfd_generic_make_empty_symbol): Likewise.
	* targets.c (bfd_target_list): Likewise.
	* tekhex.c (first_phase, tekhex_sizeof_headers): Likewise.
	* trad-core.c (trad_unix_core_file_p): Likewise.
	* vms-alpha.c (vms_initialize, alpha_vms_bfd_link_hash_table_create),
	(vms_new_section_hook): Likewise.
	* wasm-module.c (wasm_make_empty_symbol): Likewise.
	* xcofflink.c (xcoff_get_section_contents),
	(_bfd_xcoff_bfd_link_hash_table_create, xcoff_set_import_path),
	(xcoff_find_function, bfd_xcoff_link_record_set, xcoff_build_ldsym),
	(bfd_xcoff_size_dynamic_sections, xcoff_link_input_bfd): Likewise.
2020-02-19 13:12:00 +10:30
Alan Modra 2d0e121701 c99 elfxx-riscv.c fix
We can't use c99 without enabling c99 support for older compilers
that don't enable c99 by default.  So if you want to use c99 contructs
in binutils you'll need to first arrange for -std=c99 to be passed to
older compilers.

	* elfxx-riscv.c (riscv_multi_letter_ext_valid_p): Don't use C99.
2020-02-19 13:11:17 +10:30
H.J. Lu 99845b3b77 plugin: Search bfd-plugins directories only once
try_load_plugin is updated to take either plugin name or plugin entry.
load_plugin is updated to search bfd-plugins directories first to build
a list of plugins and call try_load_plugin with each plugin on the list.
When --plugin is used, the plugin list only has one entry.

	* plugin.c (try_load_plugin): Make plugin_list_iter an argument
	and use it if it isn't NULL.  Remove has_plugin_p argument.  Add
	a build_list_p argument.  Don't search plugin_list.  Short circuit
	when building the plugin list.
	(has_plugin): Renamed to has_plugin_list.
	(bfd_plugin_set_plugin): Don't set has_plugin.
	(bfd_plugin_specified_p): Check plugin_list instead.
	(build_plugin_list): New function.
	(load_plugin): Call build_plugin_list and use plugin_list.
2020-02-13 03:18:13 -08:00
H.J. Lu 22fe7df8c9 Plugin: Treat each object as independent
Since plugin treats each object as independent, we must do a fresh dlopen
of plugin for each object.

	PR binutils/25355
	* plugin.c (try_claim): Always clean up for LTO wrapper.
	(try_load_plugin): Treat each object as independent.  Create a
	copy for plugin name.
2020-02-11 15:36:31 -08:00
Nick Clifton c675ec1e76 Fix building the bfd/elf32-msp430.c file on a 32-bit host.
* elf32-msp430.c (msp430_final_link_relocate): Always use longs
	for addresses in print statements.
	(msp430_elf_relax_delete_bytes): Likewise.
	(msp430_elf_relax_add_words): Likewise.
	(msp430_elf_relax_section): Likewise.
2020-02-11 12:38:41 +00:00
H.J. Lu 1d07a805c8 Clear plugin_data memory
Clear plugin_data memory since it may be uninitialized.

	* plugin.c (add_symbols): Clear plugin_data memory.
2020-02-11 04:27:27 -08:00
H.J. Lu 0aa99dcd70 Use GCC LTO wrapper to get real symbols from LTO IR objects
GCC LTO wrapper is needed to extract real symbols from LTO IR objects.
This patch does the following:

1. Set up GCC LTO wrapper for each LTO IR object.
2. Run GCC LTO wrapper to get the real object.
3. Extract symbol info from the real object.
4. Cleanup afterwards.

bfd/

	PR binutils/25355
	* configure.ac (HAVE_EXECUTABLE_SUFFIX): New AC_DEFINE.
	(EXECUTABLE_SUFFIX): Likewise.
	* config.in: Regenerated.
	* configure: Likewise.
	* plugin.c (bfd_plugin_close_and_cleanup): Removed.
	(plugin_list_entry): Add all_symbols_read, cleanup_handler,
	gcc, lto_wrapper, resolution_file, resolution_option, gcc_env,
	real_bfd, real_nsyms, real_syms, lto_nsyms and lto_syms.
	(get_lto_wrapper): New.
	(setup_lto_wrapper_env): Likewise.
	(current_plugin): Likewise.
	(register_all_symbols_read): Likewise.
	(register_cleanup): Likewise.
	(get_symbols): Likewise.
	(add_input_file): Likewise.
	(bfd_plugin_close_and_cleanup): Likewise.
	(claim_file): Removed.
	(register_claim_file): Set current_plugin->claim_file.
	(add_symbols): Make a copy of LTO symbols.  Set lto_nsyms and
	lto_syms in current_plugin.
	(try_claim): Use current_plugin->claim_file.  Call LTO plugin
	all_symbols_read handler.  Copy real symbols to plugin_data.
	Call LTO plugin cleanup handler.  Clean up for LTO wrapper.
	(try_load_plugin): Don't reuse the previous plugin for LTO
	wrapper.  Set up GCC LTO wrapper if possible.  Don't set
	plugin_list_iter->claim_file.
	(bfd_plugin_canonicalize_symtab): Use real LTO symbols if
	possible.
	* plugin.h (plugin_data_struct): Add real_bfd, real_nsyms and
	real_syms.

ld/

	PR binutils/25355
	* testsuite/ld-plugin/lto.exp: Run PR binutils/25355 test.
	* testsuite/ld-plugin/pr25355.c: New file.
	* testsuite/ld-plugin/pr25355.d: Likewise.
	* testsuite/lib/ld-lib.exp (run_cc_link_tests): Support compile
	only dump.
2020-02-10 19:01:53 -08:00
Jozef Lawrynowicz ac4280dad0 MSP430: Enable relaxation of jump instructions to hard-coded pcrel offsets
This patch fixes execution failures which occur when the BR in a
sequence such as:
  J<cond> 1f
  BR
  1:
is relaxed to a JMP, and the pc-relative offset for the destination of
the J<cond> instruction is hard-coded to be 2 words ahead of the
instruction.
The hard-coded offset will cause execution to jump 1 word ahead of where
it should actually go.

Instead we now detect the hard-coded offset is one we inserted earlier,
and invert the condition, allowing us to remove the BR entirely.

bfd/ChangeLog:

2020-02-10  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* elf32-msp430.c (msp430_elf_relax_section): Before relaxing a branch,
	check if previous instruction matches a conditional jump inserted
	earlier. Invert conditional jump and delete branch in this case.
2020-02-10 20:42:36 +00:00
Jozef Lawrynowicz 8d6cb116f4 MSP430: Enable relaxation of relocs in JMP instructions
This patch fixes relocation overflows caused by an inability to relax
unconditional JMP instructions to BR instructions.

bfd/ChangeLog:

2020-02-10  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* elf32-msp430.c (msp430_elf_relax_add_two_words): Rename to
	msp430_elf_relax_add_words. Support insertion of either one or two
	words.
	(msp430_elf_relax_section): Catch opcode of 0x3c00 when relocation
	needs to be grown. Handle insertion of branch instruction to replace
	jump.
2020-02-10 20:35:52 +00:00
Jozef Lawrynowicz d60f54486a MSP430: Add printf statements to assist with debugging during relaxation
bfd/ChangeLog:

2020-02-10  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* elf32-msp430.c (msp430_final_link_relocate): Add printf statements for
	debugging relocations.
	(msp430_elf_relax_delete_bytes): Likewise.
	(msp430_elf_relax_add_two_words): Likewise.
	(msp430_elf_relax_section): Likewise.
2020-02-10 20:29:40 +00:00
Alan Modra e1f85e11f5 z80 comments in archures.c
bfd-in2.h didn't match what was in archures.c and reloc.c.  This
fixes overlong comment lines and regenerates bfd-in2.h.

	* archures.c: Wrap overlong z80 comments.
	* bfd-in2.h: Regenerate.
2020-02-10 15:28:23 +10:30
Sergey Belyashov 9fc0b501af Add support for the GBZ80 and Z80N variants of the Z80 architecture, and add DWARF debug info support to the Z80 assembler.
PR 25469
bfd	* archures.c: Add GBZ80 and Z80N machine values.
	* reloc.c: Add BFD_RELOC_Z80_16_BE.
	* coff-z80.c: Add support for new reloc.
	* coffcode.h: Add support for new machine values.
	* cpu-z80.c: Add support for new machine names.
	* elf32-z80.c: Add support for new reloc.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

binutils* readelf.c (get_machine_flags): Add support for Z80N machine
	number.

gas	* config/tc-z80.c: Add -gbz80 command line option to generate code
	for the GameBoy Z80.  Add support for generating DWARF.
	* config/tc-z80.h: Add support for DWARF debug information
	generation.
	* doc/c-z80.texi: Document new command line option.
	* testsuite/gas/z80/gbz80_all.d: New file.
	* testsuite/gas/z80/gbz80_all.s: New file.
	* testsuite/gas/z80/z80.exp: Run the new tests.
	* testsuite/gas/z80/z80n_all.d: New file.
	* testsuite/gas/z80/z80n_all.s: New file.
	* testsuite/gas/z80/z80n_reloc.d: New file.

include	* coff/internal.h (R_IMM16BE): Define.
	* elf/z80.h (EF_Z80_MACH_Z80N): Define.
	(R_Z80_16_BE): New reloc.

ld	* emulparams/elf32z80.sh: Use z80 emulation.
	* emultempl/z80.em: Make generic to both COFF and ELF Z80 emulations.
	* emultempl/z80elf.em: Delete.
	* testsuite/ld-elf/pr22450.d: Expect to fail for the Z80.
	* testsuite/ld-elf/sec64k.exp: Fix Z80 assembly.
	* testsuite/ld-unique/pr21529.s: Avoid register name conflict.
	* testsuite/ld-unique/unique.s: Likewise.
	* testsuite/ld-unique/unique_empty.s: Likewise.
	* testsuite/ld-unique/unique_shared.s: Likewise.
	* testsuite/ld-unique/unique.d: Updated expected output.
	* testsuite/ld-z80/arch_z80n.d: New file.
	* testsuite/ld-z80/comb_arch_z80_z80n.d: New file.
	* testsuite/ld-z80/labels.s: Add more labels.
	* testsuite/ld-z80/relocs.s: Add more reloc tests.
	* testsuite/ld-z80/relocs_f_z80n.d: New file

opcodes	* z80-dis.c: Add support for GBZ80 opcodes.
2020-02-07 14:53:46 +00:00
Nick Clifton 9984857cfd Stop the BFD library from complaining if a segment has no sections attached to it.
PR 23932
	* elf.c (rewrite_elf_program_header): Do not complain if no
	sections are mapped to a segment.
2020-02-07 12:55:05 +00:00
H.J. Lu 5242a0a000 ld: Issue an error for GC on __patchable_function_entries section
__patchable_function_entries section is generated by a compiler with
-fpatchable-function-entry=XX.  The assembly code looks like this:

---
	.text
	.globl	_start
	.type	_start, %function
_start:
	.section __patchable_function_entries,"aw",%progbits
	.dc.a	.LPFE1
	.text
.LPFE1:
	.byte 0
---

But --gc-sections will silently remove __patchable_function_entries
section and generate corrupt result.  This patch disallows garbage
collection on __patchable_function_entries section without linked-to
section.

bfd/

	PR ld/25490
	* elflink.c (_bfd_elf_gc_mark_extra_sections): Issue an error
	for garbage collection on __patchable_function_entries section
	without linked-to section.

ld/

	PR ld/25490
	* testsuite/ld-elf/pr25490-1.d: New file.
	* testsuite/ld-elf/pr25490-1.s: Likewise.
2020-02-06 19:40:38 -08:00
H.J. Lu b7d0721677 ELF: Support the section flag 'o' in .section directive
As shown in

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

--gc-sections will silently remove __patchable_function_entries section
and generate corrupt result.  This patch adds the section flag 'o' to
.section directive:

.section __patchable_function_entries,"awo",@progbits,foo
.section __patchable_function_entries,"awoG",@progbits,foo,foo,comdat
.section __patchable_function_entries,"awo",@progbits,bar,unique,4
.section __patchable_function_entries,"awoG",@progbits,foo,foo,comdat,unique,1

which specifies the symbol name which the section references.  Assmebler
will set its elf_linked_to_section to a local section where the symbol
is defined.

Linker is updated to call mark_hook if gc_mark of any of its linked-to
sections is set after all sections, except for backend specific ones,
have been garbage collected.

bfd/

	PR gas/25381
	* bfd-in2.h: Regenerated.
	* elflink.c (_bfd_elf_gc_mark_extra_sections): Call mark_hook
	on section if gc_mark of any of its linked-to sections is set
	and don't set gc_mark again.
	* section.c (asection): Add linked_to_symbol_name to map_head
	union.

gas/

	PR gas/25381
	* config/obj-elf.c (get_section): Also check
	linked_to_symbol_name.
	(obj_elf_change_section): Also set map_head.linked_to_symbol_name.
	(obj_elf_parse_section_letters): Handle the 'o' flag.
	(build_group_lists): Renamed to ...
	(build_additional_section_info): This.  Set elf_linked_to_section
	from map_head.linked_to_symbol_name.
	(elf_adjust_symtab): Updated.
	* config/obj-elf.h (elf_section_match): Add linked_to_symbol_name.
	* doc/as.texi: Document the 'o' flag.
	* testsuite/gas/elf/elf.exp: Run PR gas/25381 tests.
	* testsuite/gas/elf/section18.d: New file.
	* testsuite/gas/elf/section18.s: Likewise.
	* testsuite/gas/elf/section19.d: Likewise.
	* testsuite/gas/elf/section19.s: Likewise.
	* testsuite/gas/elf/section20.d: Likewise.
	* testsuite/gas/elf/section20.s: Likewise.
	* testsuite/gas/elf/section21.d: Likewise.
	* testsuite/gas/elf/section21.l: Likewise.
	* testsuite/gas/elf/section21.s: Likewise.

ld/

	PR ld/24526
	PR ld/25021
	PR ld/25490
	* testsuite/ld-elf/elf.exp: Run PR ld/25490 tests.
	* testsuite/ld-elf/pr24526.d: New file.
	* testsuite/ld-elf/pr24526.s: Likewise.
	* testsuite/ld-elf/pr25021.d: Likewise.
	* testsuite/ld-elf/pr25021.s: Likewise.
	* testsuite/ld-elf/pr25490-2-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-2-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-2-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-2.s: Likewise.
	* testsuite/ld-elf/pr25490-3-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-3-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-3-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-3.s: Likewise.
	* testsuite/ld-elf/pr25490-4-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-4-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-4-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-4.s: Likewise.
	* testsuite/ld-elf/pr25490-5-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-5-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-5-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-5.s: Likewise.
	* testsuite/ld-elf/pr25490-6-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-6-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-6-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-6.s: Likewise.
2020-02-06 18:05:10 -08:00
Maciej W. Rozycki b93a662bcf V850/BFD: Fix uninitialized `insn[4]' with R_V850_LONGJUMP warning
Correctly point at `insn[2]' rather than `insn[4]' in determining that
the third instruction from where an R_V850_LONGJUMP relocation points at
is not a recognized one, fixing a problem with commit 86aba9dbfa ("Add
linker relaxation to v850 toolchain") resulting in a build failure like:

.../bfd/elf32-v850.c: In function 'v850_elf_relax_section':
.../bfd/elf32-v850.c:3854:5: error: 'insn[4]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 3854 |     _bfd_error_handler
      |     ^~~~~~~~~~~~~~~~~~
 3855 |       /* xgettext:c-format */
      |       ~~~~~~~~~~~~~~~~~~~~~~~
 3856 |       (_("%pB: %#" PRIx64 ": warning: %s points to "
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3857 |          "unrecognized insn %#x"),
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~
 3858 |        abfd,
      |        ~~~~~
 3859 |        (uint64_t) (irel->r_offset + no_match),
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3860 |        "R_V850_LONGJUMP",
      |        ~~~~~~~~~~~~~~~~~~
 3861 |        insn[no_match]);
      |        ~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:1608: recipe for target 'elf32-v850.lo' failed
make[4]: *** [elf32-v850.lo] Error 1

with GCC 10.

	bfd/
	* elf32-v850.c (v850_elf_relax_section): Fix the index used for
	reporting an unrecognized instruction with R_V850_LONGJUMP.
2020-02-06 13:38:31 +00:00
Alan Modra 6df4c9c2ff Re: Support fusion for ELFv2 stubs
git commit 397998fc32 changed the stubs but not the comments.

	* elf64-ppc.c (ppc_stub_plt_branch): Match comment with reality.
2020-02-05 07:12:48 +10:30
Alan Modra 24872cb302 Minor fix for R_PPC_VLE_ADDR20
It is incorrect to "continue" in the ppc_elf_relocate_section reloc
processing loop except when editing or deleting relocs.  The normal
loop processing arranges to write the relocs if shuffling them over a
deleted entry.  Deleting only happens for debug sections currently and
those sections won't contain R_PPC_VLE_ADDR20 relocs, so this patch
doesn't fix a bug that would trigger with any normal object file.

	* elf32-ppc.c (ppc_elf_relocate_section): After applying
	R_PPC_VLE_ADDR20, goto copy_reloc.
2020-02-04 21:56:29 +10:30
H.J. Lu ef4627faba section.c: Fix typo in comments (withe -> with)
* bfd-in2.h: Regenerated.
	* section.c (SEC_ASSEMBLER_SECTION_ID): Fix a typo in comments.
2020-02-02 17:14:12 -08:00
H.J. Lu a8c4d40b57 ELF: Add support for unique section ID to assembler
Clang's integrated assembler supports multiple section with the same
name:

	.section .text,"ax",@progbits,unique,1
	nop
	.section .text,"ax",@progbits,unique,2
	nop

"unique,N" assigns the number, N, as the section ID, to a section.  The
valid values of the section ID are between 0 and 4294967295.  It can be
used to distinguish different sections with the same section name.

This is useful with -fno-unique-section-names -ffunction-sections.
-ffunction-sections by default generates .text.foo, .text.bar, etc.
Using the same string can save lots of space in .strtab.

This patch adds section_id to bfd_section and reuses the linker
internal bit in BFD section flags, SEC_LINKER_CREATED, for assmebler
internal use to mark valid section_id.  It also updates objdump to
compare section pointers if 2 sections comes from the same file since
2 different sections can have the same section name.

bfd/

	PR gas/25380
	* bfd-in2.h: Regenerated.
	* ecoff.c (bfd_debug_section): Add section_id.
	* section.c (bfd_section): Add section_id.
	(SEC_ASSEMBLER_SECTION_ID): New.
	(BFD_FAKE_SECTION): Add section_id.

binutils/

	PR gas/25380
	* objdump.c (sym_ok): Return FALSE if 2 sections are in the
	same file with different section pointers.

gas/

	PR gas/25380
	* config/obj-elf.c (section_match): Removed.
	(get_section): Also match SEC_ASSEMBLER_SECTION_ID and
	section_id.
	(obj_elf_change_section): Replace info and group_name arguments
	with match_p.  Also update the section ID and flags from match_p.
	(obj_elf_section): Handle "unique,N".  Update call to
	obj_elf_change_section.
	* config/obj-elf.h (elf_section_match): New.
	(obj_elf_change_section): Updated.
	* config/tc-arm.c (start_unwind_section): Update call to
	obj_elf_change_section.
	* config/tc-ia64.c (obj_elf_vms_common): Likewise.
	* config/tc-microblaze.c (microblaze_s_data): Likewise.
	(microblaze_s_sdata): Likewise.
	(microblaze_s_rdata): Likewise.
	(microblaze_s_bss): Likewise.
	* config/tc-mips.c (s_change_section): Likewise.
	* config/tc-msp430.c (msp430_profiler): Likewise.
	* config/tc-rx.c (parse_rx_section): Likewise.
	* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
	* doc/as.texi: Document "unique,N" in .section directive.
	* testsuite/gas/elf/elf.exp: Run "unique,N" tests.
	* testsuite/gas/elf/section15.d: New file.
	* testsuite/gas/elf/section15.s: Likewise.
	* testsuite/gas/elf/section16.s: Likewise.
	* testsuite/gas/elf/section16a.d: Likewise.
	* testsuite/gas/elf/section16b.d: Likewise.
	* testsuite/gas/elf/section17.d: Likewise.
	* testsuite/gas/elf/section17.l: Likewise.
	* testsuite/gas/elf/section17.s: Likewise.
	* testsuite/gas/i386/unique.d: Likewise.
	* testsuite/gas/i386/unique.s: Likewise.
	* testsuite/gas/i386/x86-64-unique.d: Likewise.
	* testsuite/gas/i386/i386.exp: Run unique and x86-64-unique.

ld/

	PR gas/25380
	* testsuite/ld-i386/pr22001-1c.S: Use "unique,N" in .section
	directives.
	* testsuite/ld-i386/tls-gd1.S: Likewise.
	* testsuite/ld-x86-64/pr21481b.S: Likewise.
2020-02-02 17:08:01 -08:00
Nick Clifton 5a9212a11c Move pending obsolete targets onto the definitely obsolete list 2020-02-01 13:13:14 +00:00
Sandra Loosemore e7cbe0c4a4 nios2: Add BFD support for GOT-relative DW_EH_PE_datarel encodings
There's already existing logic to handle this on other targets, so
this patch just makes nios2 use it.

2020-01-31  Sandra Loosemore  <sandra@codesourcery.com>

	bfd/
	* elf-eh-frame.c (_bfd_elf_write_section_eh_frame): DW_EH_PE_datarel
	encodings are relative to the GOT on nios2, too.
2020-01-31 10:34:42 -08:00
Alan Modra 72ebe8c528 Tidy bfd.pot
This patch removes the leak of Nick's source directory into bfd.pot,
and emits #line for some generated files so that those files aren't
referenced by comments in the .pot file.  You can see both of these
effects in the following diff.  I've also removed use of an
unnecessary temp file in the make rules.

@@ -92,10 +92,8 @@ msgstr ""
 #: elf64-nfp.c:238 elf64-ppc.c:1014 elf64-ppc.c:1349 elf64-ppc.c:1358
 #: elf64-s390.c:328 elf64-s390.c:378 elf64-x86-64.c:285 elfn32-mips.c:3786
 #: elfxx-ia64.c:324 elfxx-riscv.c:955 elfxx-sparc.c:589 elfxx-sparc.c:639
-#: elfxx-tilegx.c:912 elfxx-tilegx.c:952
-#: /work/sources/binutils/current/bfd/elfnn-aarch64.c:2215
-#: /work/sources/binutils/current/bfd/elfnn-aarch64.c:2313 elf32-ia64.c:214
-#: elf32-ia64.c:3862 elf64-ia64.c:214 elf64-ia64.c:3862
+#: elfxx-tilegx.c:912 elfxx-tilegx.c:952 elfnn-aarch64.c:2215
+#: elfnn-aarch64.c:2313 elfnn-ia64.c:214 elfnn-ia64.c:3862
 #, c-format
 msgid "%pB: unsupported relocation type %#x"
 msgstr ""

	* Makefile.am (elf32-target.h, elf64-target.h): Don't use a temp
	file.  Use $< and $@ in rules.
	(elf32-aarch64.c, elf64-aarch64.c): Likewise.
	(elf32-ia64.c, elf64-ia64.c): Likewise.
	(elf32-riscv.c, elf64-riscv.c): Likewise.
	(peigen.c, pepigen.c, pex64igen.c): Likewise.
	(elf32-aarch64.c, elf64-aarch64.c): Don't emit $srcdir on #line.
	(elf32-riscv.c, elf64-riscv.c): Likewise, and use $(SED).
	(elf32-ia64.c, elf64-ia64.c): Do emit #line.
	(peigen.c, pepigen.c, pex64igen.c): Likewise.
	* Makefile.in: Regenerate.
2020-01-31 10:47:46 +10:30
Alan Modra 327301a460 OOM in setup_group
We alloc, seek and read using section sizes in object files.  Fuzzed
objects can have silly sizes, but that's OK if the system supports
memory over-commit.  The read fails because we hit EOF and that
usually results in a graceful exit.

But if we memset before the read then the invalid size results in
attempting to write to a huge number of memory pages, and an eventual
Out Of Memory after probably swapping like crazy.  So don't memset.
There really isn't a need to clear the section contents anyway.  All
bytes are written with a good object file by the read and following
loop converting section index in target order to ELF section header
pointer, and the only untidy bytes are the 4 bytes past the group
flags when pointers are 8 bytes.  Those don't matter but the patch
clears them for anyone poking around in a debugger.  On error paths
it's as good to free section contents as it is to clear them.

Noticed when looking at PR4110 fourth test case.

	PR 4110
	* elf.c (setup_group): Don't clear entire section contents,
	just the padding after group flags.  Release alloc'd memory
	after a seek or read failure.
2020-01-31 10:47:46 +10:30
Jon Turney b5d36aaa8a
Identify reproducible builds in 'objdump -p' output for PE files
These are produced by MSVC when the '/Brepro' flag is used.

To quote from the PE specification [1]:

"The presence of an entry of type IMAGE_DEBUG_TYPE_REPRO indicates the
PE file is built in a way to achieve determinism or reproducibility. If
the input does not change, the output PE file is guaranteed to be
bit-for-bit identical no matter when or where the PE is produced.
Various date/time stamp fields in the PE file are filled with part or
all the bits from a calculated hash value that uses PE file content as
input, and therefore no longer represent the actual date and time when a
PE file or related specific data within the PE is produced. The raw data
of this debug entry may be empty, or may contain a calculated hash value
preceded by a four-byte value that represents the hash value length."

[1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format

bfd/ChangeLog:

2020-01-16  Jon Turney  <jon.turney@dronecode.org.uk>

	* peXXigen.c (pe_is_repro): New function.
	(_bfd_XX_print_private_bfd_data_common): Note timestamp is
	actually a build hash if PE_IMAGE_DEBUG_TYPE_REPRO is present.
2020-01-30 13:06:27 +00:00
Jon Turney 1957ab1030
Add some new PE_IMAGE_DEBUG_TYPE values
IMAGE_DEBUG_TYPE_REPRO is defined in the latest version of the PE
specification [1]. The others are defined in Windows SDK headers and/or
reported by DUMPBIN.

[1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format

bfd/ChangeLog:

2020-01-16  Jon Turney  <jon.turney@dronecode.org.uk>

	* peXXigen.c (debug_type_names): Add names for new debug data type
	values.

include/ChangeLog:

2020-01-16  Jon Turney  <jon.turney@dronecode.org.uk>

	* coff/internal.h (PE_IMAGE_DEBUG_TYPE_VC_FEATURE)
	(PE_IMAGE_DEBUG_TYPE_POGO, PE_IMAGE_DEBUG_TYPE_ILTCG)
	(PE_IMAGE_DEBUG_TYPE_MPX, PE_IMAGE_DEBUG_TYPE_REPRO): Add.
2020-01-30 13:06:26 +00:00
Jon Turney 87b2920fc5
Bugfixes for pe_print_debugdata()
Use a separate iteration variable for inner loop (😊).  This
generally prevented any debug directory entries after a
IMAGE_DEBUG_TYPE_CODEVIEW entry from being reported.

Don't leak the memory allocated for the section containing the debug
directory.

bfd/ChangeLog:

2020-01-16  Jon Turney  <jon.turney@dronecode.org.uk>

	* peXXigen.c (pe_print_debugdata): Fix the iteration variable for
	inner loop.  Fix a memory leak.
2020-01-30 13:06:24 +00:00
Alan Modra 72913831fc Remove need to clear obj_coff_keep_syms in coff object_p
* coffgen.c (coff_real_object_p): Don't clear obj_coff_keep_syms
	or obj_coff_keep_strings here.
	(coff_get_normalized_symtab): Free external syms directly.
	* xcofflink.c (xcoff_link_input_bfd): Restore obj_coff_keep_syms
	on error exit path.
2020-01-30 17:06:35 +10:30
Jim Wilson c35d018b1a RISC-V: Fix gdbserver problem with handling arch strings.
Maciej reported a problem found by his RISC-V gdbserver port.
warning: while parsing target description (at line 4): Target description specified unknown architecture "riscv:rv64id"
warning: Could not load XML target description; ignoring

We only have two arches defined, riscv:rv32 and riscv:rv64.  Both bfd and
gdb are creating arch strings that have extension letters added to the base
architecture.  The bfd_default_scan function requires an exact match, so
these strings fail to map to a bfd_arch.  I think we should ignore the
extension letters in a RISC-V specific scan function.

	bfd/
	* cpu-riscv.c (riscv_scan): New.
	(N): Change bfd_default_scan to riscv_scan.

Change-Id: I096476705e1da5cb8934c5005b1eed2a8989f7a7
2020-01-27 15:19:30 -08:00
Andreas Schwab 086b06f3c9 Remove cpu-plugin.c
After commit 999d6dff80 cpu-plugin.c is no longer begin used.

	* Makefile.am (ALL_MACHINES): Remove cpu-plugin.lo.
	(ALL_MACHINES_CFILES): Remove cpu-plugin.c.
	* Makefile.in: Regenerate.
	* cpu-plugin.c: Remove.
	* archures.c (enum bfd_architecture): Remove bfd_arch_plugin.
	(bfd_plugin_arch): Remove declaration.
	* bfd-in2.h: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
2020-01-27 14:31:29 +01:00
Alan Modra 3024a17ae0 Mark all weak aliases for copy relocations
bfd/
	PR ld/25458
	* elflink.c (_bfd_elf_gc_mark_rsec): Mark all weak aliases.
ld/
	PR ld/25458
	* testsuite/ld-elf/pr25458.map: New file.
	* testsuite/ld-elf/pr25458.rd: Likewise.
	* testsuite/ld-elf/pr25458a.s: Likewise.
	* testsuite/ld-elf/pr25458b.s: Likewise.
	* testsuite/ld-elf/shared.exp: Run PR ld/25458 test.
2020-01-27 10:53:00 +10:30
Jim Wilson b5f998b2dd RISC-V: Minor cleanup for s extension support.
Looking at older versions of the patch, I confirmed that the odd comment
I referred to earlier was indeed from the removal of the sx support.  It
also explains an oddly formatted switch statement.  This patch fixes both
minor problems.

	bfd/
	* elfxx-riscv.c (riscv_get_prefix_class): Format s case like others.
	(riscv_parse_prefixed_ext): Fix s extension comment and reword to
	avoid over long line.

Change-Id: I1cb62e4a16188270f029b6376e4b1684000d6c7a
2020-01-24 14:24:09 -08:00
Nick Clifton caa31cfad6 Fix an illegal call to free() when copying a PE format file.
PR 25447
	* coffgen.c (_bfd_coff_close_and_cleanup): Do not clear the keep
	syms and keep strings flags as these may have been set in order to
	prevent a bogus call to free.
2020-01-24 13:19:48 +00:00
Nick Clifton 24e648d4b8 Updated translations for various binutils sub-directories. 2020-01-23 14:33:36 +00:00
Alan Modra 67641dd326 PR25444, Floating point exception in _bfd_elf_compute_section_file_positions
PR 25444
	* elf.c (assign_file_positions_for_load_sections): Avoid divide
	by zero when p_align is zero.
2020-01-23 19:53:25 +10:30
Jim Wilson 403d1bd91d RISC-V: Change -march parsing.
bfd/
	2020-01-22  Maxim Blinov  <maxim.blinov@embecosm.com>
	* bfd/elfnn-riscv.c (riscv_skip_prefix): New.
	(riscv_prefix_cmp): Likewise.
	(riscv_non_std_ext_p): Deleted.
	(riscv_std_sv_ext_p): Likewise.
	(riscv_non_std_sv_ext_p): Likewise.
	(riscv_merge_non_std_and_sv_ext): Rename to...
	(riscv_merge_multi_letter_ext): and modified to use riscv_prefix_cmp.
	(riscv_merge_arch_attr_info): Replace 3 calls to
	riscv_merge_non_std_and_sv_ext with single call to
	riscv_merge_multi_letter_ext.
	* bfd/elfxx-riscv.c (riscv_parse_std_ext): Break if we
	encounter a 'z' prefix.
	(riscv_get_prefix_class): New function, return prefix class based
	on first few characters of input string.
	(riscv_parse_config): New structure to factor out minor differences
	in extension class parsing behaviour.
	(riscv_parse_sv_or_non_std_ext): Rename to...
	(riscv_parse_prefixed_ext): and parameterise with
	riscv_parse_config.
	(riscv_std_z_ext_strtab, riscv_std_s_ext_strtab): New.
	(riscv_multi_letter_ext_valid_p): New.
	(riscv_ext_x_valid_p, riscv_ext_z_valid_p, riscv_ext_s_valid_p): New.
	(riscv_parse_subset): Delegate all non-single-letter parsing work
	to riscv_parse_prefixed_ext.
	* bfd/elfxx-riscv.h (riscv_isa_ext_class): New type.
	(riscv_get_prefix_class): Declare.

	gas/
	2020-01-22  Maxim Blinov  <maxim.blinov@embecosm.com>
	* testsuite/gas/riscv/march-ok-s.d: sx is no longer valid and
	s exts must be known, so rename *ok* to *fail*.
	* testsuite/gas/riscv/march-ok-sx.d: Likewise.
	* testsuite/gas/riscv/march-ok-s-with-version: Likewise.
	* testsuite/gas/riscv/march-fail-s.l: Expected error messages for
	above change.
	* testsuite/gas/riscv/march-fail-sx.l: Likewise.
	* testsuite/gas/riscv/march-fail-sx-with-version.l: Likewise.

Change-Id: Ic4d91a13d055a10d30ab28752a380a669b59f29c
2020-01-22 16:45:04 -08:00
Alan Modra a804e4760a PowerPC64 tls_get_addr_desc static support
This provides a linker generated __tls_get_addr_desc wrapper function
preserving registers around a __tls_get_addr call.  The idea being to
support __tls_get_addr_desc without requiring a glibc update.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add tga_group.
	(ppc64_elf_archive_symbol_lookup): Extract __tls_get_addr_opt for
	__tls_get_addr_desc.
	(ppc64_elf_size_stubs): Add section for linker generated
	__tls_get_addr_desc wrapper function.  Loop at least once if
	generating this function.
	(emit_tga_desc, emit_tga_desc_eh_frame): New functions.
	(ppc64_elf_build_stubs): Generate __tls_get_addr_desc.
ld/
	* testsuite/ld-powerpc/tlsdesc3.d,
	* testsuite/ld-powerpc/tlsdesc3.wf,
	* testsuite/ld-powerpc/tlsdesc4.d,
	* testsuite/ld-powerpc/tlsdesc4.s,
	* testsuite/ld-powerpc/tlsdesc4.wf: New tests.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2020-01-22 17:14:08 +10:30
Alan Modra 9e7028aa1e PowerPC64 __tls_get_addr_desc
This implements register saving and restoring in the __tls_get_addr
call stub, so that when glibc supports the optimized tls call stub gcc
can generate code that assumes only r0, r12 and of course r3 are
changed on a __tls_get_addr call.  When gcc expects __tls_get_addr
calls to preserve registers the call will be to __tls_get_addr_desc,
which will be translated by the linker to a call to __tls_get_addr_opt.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add no_tls_get_addr_regsave.
	* elf64-ppc.c (struct ppc_link_hash_table): Add tga_desc and
	tga_desc_fd.
	(is_tls_get_addr): Match tga_desc and tga_desc_df too.
	(STDU_R1_0R1, ADDI_R1_R1): Define.
	(tls_get_addr_prologue, tls_get_addr_epilogue): New functions.
	(ppc64_elf_tls_setup): Set up tga_desc and tga_desc_fd.  Indirect
	tga_desc_fd to opt_fd, and tga_desc to opt.  Set
	no_tls_get_addr_regsave.
	(branch_reloc_hash_match): Add hash3 and hash4.
	(ppc64_elf_tls_optimize): Handle tga_desc_fd and tga_desc too.
	(ppc64_elf_size_dynamic_sections): Likewise.
	(ppc64_elf_relocate_section): Likewise.
	(plt_stub_size, build_plt_stub): Likewise.  Size regsave
	__tls_get_addr stub.
	(build_tls_get_addr_stub): Build regsave __tls_get_addr stub and
	eh_frame.
	(ppc_size_one_stub): Handle tga_desc_fd and tga_desc too.  Size
	eh_frame for regsave __tls_get_addr.
gas/
	* config/tc-ppc.c (parse_tls_arg): Handle tls arg for
	__tls_get_addr_desc and __tls_get_addr_opt.
ld/
	* emultempl/ppc64elf.em (ppc64_opt, PARSE_AND_LIST_LONGOPTS),
	(PARSE_AND_LIST_OPTIONS, PARSE_AND_LIST_ARGS_CASES): Support
	--tls-get-addr-regsave and --no-tls-get-addr-regsave.
	(params): Init new field.
	* ld.texi (--tls-get-addr-regsave, --no-tls-get-addr-regsave):
	Document.
	* testsuite/ld-powerpc/tlsdesc.s,
	* testsuite/ld-powerpc/tlsdesc.d,
	* testsuite/ld-powerpc/tlsdesc.wf,
	* testsuite/ld-powerpc/tlsdesc2.d,
	* testsuite/ld-powerpc/tlsdesc2.wf,
	* testsuite/ld-powerpc/tlsexenors.d,
	* testsuite/ld-powerpc/tlsexenors.r,
	* testsuite/ld-powerpc/tlsexers.d,
	* testsuite/ld-powerpc/tlsexers.r,
	* testsuite/ld-powerpc/tlsexetocnors.d,
	* testsuite/ld-powerpc/tlsexetocrs.d,
	* testsuite/ld-powerpc/tlsexetocrs.r,
	* testsuite/ld-powerpc/tlsopt6.d,
	* testsuite/ld-powerpc/tlsopt6.wf: New.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
2020-01-22 17:14:08 +10:30
Alan Modra abc489c64a PowerPC64 TLS optimization fix
When linking with --no-tls-optimize the linker doesn't generate a call
or long branch stub to __tls_get_addr in some circumstances, giving:

relocation truncated to fit: R_PPC64_REL24 against symbol `__tls_get_addr'

	* elf64-ppc.c (ppc64_elf_size_stubs): Correct condition under
	which __tls_get_addr calls will be eliminated.
2020-01-22 17:14:08 +10:30
Nick Clifton 26916852e1 Updated translations for various binutils sub-directories 2020-01-20 15:10:23 +00:00
H.J. Lu 14470f0755 x86-64: Fix TLSDESC relaxation for x32
For x32, we must encode "lea x@TLSDESC(%rip), %reg" with a REX prefix
even if it isn't required.  Otherwise linker can’t safely perform
GDesc -> IE/LE optimization.  X32 TLSDESC sequences can be:

40 8d 05 00 00 00 00	rex lea	x@TLSDESC(%rip), %reg
...
67 ff 10		call	*x@TLSCALL(%eax)

or the same sequence as LP64:

48 8d 05 00 00 00 00	lea	foo@TLSDESC(%rip), %reg
...
ff 10			call	*foo@TLSCALL(%rax)

We need to support both sequences for x32.  For both GDesc -> IE/LE
transitions,

67 ff 10		call	*x@TLSCALL(%eax)

should relaxed to

0f 1f 00		nopl	(%rax)

For GDesc -> LE transition,

40 8d 05 00 00 00 00	rex lea	x@TLSDESC(%rip), %reg

should relaxed to

40 c7 c0 fc ff ff ff	rex movl $x@tpoff, %reg

For GDesc -> IE transition,

40 8d 05 00 00 00 00	rex lea	x@TLSDESC(%rip), %reg

should relaxed to

40 8b 05 00 00 00 00	rex movl x@gottpoff(%rip), %eax

bfd/

	PR ld/25416
	* elf64-x86-64.c (elf_x86_64_check_tls_transition): Support
	"rex leal x@tlsdesc(%rip), %reg" and "call *x@tlsdesc(%eax)" in
	X32 mode.
	(elf_x86_64_relocate_section): In x32 mode, for GDesc -> LE
	transition, relax "rex leal x@tlsdesc(%rip), %reg" to
	"rex movl $x@tpoff, %reg", for GDesc -> IE transition, relax
	"rex leal x@tlsdesc(%rip), %reg" to
	"rex movl x@gottpoff(%rip), %eax".  For both transitions, relax
	"call *(%eax)" to "nopl (%rax)".

gas/

	PR ld/25416
	* config/tc-i386.c (output_insn): Add a dummy REX_OPCODE prefix
	for lea with R_X86_64_GOTPC32_TLSDESC relocation when generating
	x32 object.
	* testsuite/gas/i386/ilp32/x32-tls.d: Updated.
	* testsuite/gas/i386/ilp32/x32-tls.s: Add tests for lea with
	R_X86_64_GOTPC32_TLSDESC relocation.

ld/

	PR ld/25416
	* testsuite/ld-x86-64/pr25416-1.s: New file
	* testsuite/ld-x86-64/pr25416-1a.d: Likewise.
	* testsuite/ld-x86-64/pr25416-1b.d: Likewise.
	* testsuite/ld-x86-64/pr25416-1.s: Likewise.
	* testsuite/ld-x86-64/pr25416-2.s: Likewise.
	* testsuite/ld-x86-64/pr25416-2a.d: Likewise.
	* testsuite/ld-x86-64/pr25416-2b.d: Likewise.
	* testsuite/ld-x86-64/pr25416-3.d: Likewise.
	* testsuite/ld-x86-64/pr25416-3.s: Likewise.
	* testsuite/ld-x86-64/pr25416-4.d: Likewise.
	* testsuite/ld-x86-64/pr25416-4.s: Likewise.
	* testsuite/ld-x86-64/pr25416-5a.c: Likewise.
	* testsuite/ld-x86-64/pr25416-5b.s: Likewise.
	* testsuite/ld-x86-64/pr25416-5c.s: Likewise.
	* testsuite/ld-x86-64/pr25416-5d.s: Likewise.
	* testsuite/ld-x86-64/pr25416-5e.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/25416 tests.
2020-01-20 07:01:07 -08:00
Alan Modra b9ca1af69e Don't touch r11 in __tls_get_addr stub
This modifies the special __tls_get_addr stub that checks for a
tlsdesc style __tls_index entry and returns early.  Not using r11
isn't much benefit at the moment but a followup patch will preserve
regs around the first call to __tls_get_addr when the __tls_index
entry isn't yet set up for an early return.

bfd/
	* elf64-ppc.c (LD_R11_0R3, CMPDI_R11_0, STD_R11_0R1, LD_R11_0R1),
	(MTLR_R11): Don't define.
	(LD_R0_0R3, CMPDI_R0_0): Define.
	(build_tls_get_addr_stub): Don't use r11 in stub.
ld/
	* testsuite/ld-powerpc/tlsexe.d: Match new __tls_get_addr stub.
	* testsuite/ld-powerpc/tlsexeno.d: Likewise.
	* testsuite/ld-powerpc/tlsexetoc.d: Likewise.
	* testsuite/ld-powerpc/tlsexetocno.d: Likewise.
	* testsuite/ld-powerpc/tlsopt5.d: Likewise.
2020-01-20 18:58:05 +10:30
Alan Modra ed7007c18a PowerPC64 ppc_elf_hash_entry, defined_sym_val, is_tls_get_addr
* elf64-ppc.c (ppc_elf_hash_entry): New function, use throughout file.
	(defined_sym_val, is_tls_get_addr): Likewise.
2020-01-20 16:54:19 +10:30
Nick Clifton 1b1bb2c67b Update version to 2.34.50. Regenerate configure and .pot files. 2020-01-18 14:12:07 +00:00
Nick Clifton ae77468624 Add markers for 2.34 branch to the NEWS files and ChangeLogs. 2020-01-18 13:50:25 +00:00
Christian Biesinger 07f1f3aa53 Fix spelling errors
seperate -> separate

bfd/ChangeLog:

2020-01-17  Christian Biesinger  <cbiesinger@google.com>

	* coff-arm.c: Fix spelling error (seperate).
	* elfxx-riscv.c (riscv_parse_sv_or_non_std_ext): Fix spelling
	error (seperate).
	* sysdep.h (strnlen): Fix spelling error (seperate).

opcodes/ChangeLog:

2020-01-17  Christian Biesinger  <cbiesinger@google.com>

	* opintl.h: Fix spelling error (seperate).

sim/arm/ChangeLog:

2020-01-17  Christian Biesinger  <cbiesinger@google.com>

	* iwmmxt.c: Fix spelling error (seperate).

Change-Id: I55e5f47bcf3cf3533d2acb7ad338f1be0d5f30f9
2020-01-17 12:34:03 -06:00
Lars Brinkhoff 0d1cc75df1 Set the default page size of the PDP11 target to 8192 bytes.
PR 20694
bfd	* pdp11.c (TARGET_PAGE_SIZE): Set to 8192.

ld	* temulparams/pdp11.sh (TARGET_PAGE_SIZE): Set to 8192.
2020-01-15 14:18:54 +00:00
Alan Modra e1c6cf618c PR25384, PowerPC64 ELFv1 copy relocs against function symbols
Function symbols of course don't normally want .dynbss copies but
with some old versions of gcc they are needed to copy the function
descriptor.  This patch restricts the cases where they are useful to
compilers using dot-symbols, and enables the warning regardless of
whether a PLT entry is emitted in the executable.  PLTs in shared
libraries are affected by a .dynbss copy in the executable.

bfd/
	PR 25384
	* elf64-ppc.c (ELIMINATE_COPY_RELOCS): Update comment.
	(ppc64_elf_adjust_dynamic_symbol): Don't allow .dynbss copies
	of function symbols unless dot symbols are present.  Do warn
	whenever one is created, regardles of whether a PLT entry is
	also emitted for the function symbol.
ld/
	* testsuite/ld-powerpc/ambiguousv1b.d: Adjust expected output.
	* testsuite/ld-powerpc/funref.s: Align func_tab.
	* testsuite/ld-powerpc/funref2.s: Likewise.
	* testsuite/ld-powerpc/funv1.s: Add dot symbols.
2020-01-15 12:29:21 +10:30
Alan Modra ef4e5ba50c som: Don't loop forever reading symbol chains
* som.c (som_bfd_count_ar_symbols): Error when file position
	of symbols on chains is not strictly increasing.
2020-01-14 11:02:37 +10:30
Alan Modra 8ab484c23b ubsan: alpha-vms: segv
I thought the fuzzers were really going overboard by defining
VMS_DEBUG but that wasn't the case.  VMS_DEBUG is defined by
default.  Let's not do that, and fix the segv as well.

	* vms.h (VMS_DEBUG): Define as 0.
	* vms-alpha.c (image_write): Move debug output after bounds check.
	Tidy bounds check.
	(_bfd_vms_slurp_eihd): Warning fix.
	(_bfd_vms_slurp_etir): Init variables to avoid bogus warnings.
2020-01-14 11:02:28 +10:30
Alan Modra b50ef514ff ubsan: alpha-vma: timeout
* vms-alpha.c (_bfd_vms_slurp_egsd): Ensure minimum size even
	for "ignored" records.
2020-01-13 12:12:05 +10:30
Alan Modra 0c0adcc524 Memory leaks and ineffective bounds checking in wasm_scan
It's always a bad idea to perform arithmetic on an unknown value read
from an object file before comparing against bounds.  Code like the
following attempting to bounds check "len", a 64-bit value, isn't
effective because the pointer arithmetic ignores the high 32 bits when
compiled for a 32-bit host.

      READ_LEB128 (len, p, end);
      if (p + len < p || p + len > end)
        goto error_return;

Instead, perform any arithmetic on known values where we don't need to
worry about overflows:

      READ_LEB128 (len, p, end);
      if (len > (size_t) (end - p))
        goto error_return;

I'll note that this check does do things the right way:

  READ_LEB128 (symcount, p, end);
  /* Sanity check: each symbol has at least two bytes.  */
  if (symcount > payload_size / 2)
    return FALSE;

"symcount * 2 > payload_size" would be wrong since the multiply could
overflow.

	* wasm-module.c (wasm_scan_name_function_section): Formatting.
	Delete asect name check.  Move asect NULL check to wasm_object_p.
	Correct bounds check of sizes against end.  Replace uses of
	bfd_zalloc with bfd_alloc, zeroing only necessary bytes.  Use
	just one bfd_release.
	(wasm_scan): Don't use malloc/strdup for section names,
	bfd_alloc instead.  Simplify code prefixing section name.
	Formatting.  Don't attempt to free memory here..
	(wasm_object_p): ..do so here.  Formatting.
2020-01-13 12:12:05 +10:30
Szabolcs Nagy 7f02673206 [PR ld/22269] arm: Avoid dynamic relocs for undefweak symbols in static PIE
With static PIE linking undefined weak symbols are resolved to 0, so no
dynamic relocation is needed for them. The UNDEFWEAK_NO_DYNAMIC_RELOC
macro was introduced so this case can be handled easily, but it was not
applied consistently in the first attempt to fix ld/22269 for arm:

  commit 95b03e4ad6
  arm: Check UNDEFWEAK_NO_DYNAMIC_RELOC

This patch fixes spurious relative relocs in static PIE binaries against
GOT entries created for undefined weak symbols on arm*-*, this fixes

FAIL: pr22269-1 (static pie undefined weak)

bfd/ChangeLog:

	PR ld/22269
	* elf32-arm.c (elf32_arm_final_link_relocate): Use
	UNDEFWEAK_NO_DYNAMIC_RELOC.
	(allocate_dynrelocs_for_symbol): Likewise.
2020-01-10 14:16:05 +00:00
Tamar Christina 8cd0e5e931 AArch64: Revert setting of elf class in linker stub.
This changes the fix to PR 25210 by removing the ELF class change.
As it turns out the correct change was only the change in compress.c.

Everything else is unneeded and setting the elf class is making the linker
behave very oddly under LTO.  The first stub is correctly written out but for
the rest the suddenly don't have a pointer to the stub section anymore.

This caused SPEC to fail as the program would branch to the stub and it wouldn't
be filled in.

Committed to master under the trivial rule as this is partially reverting a previous commit.

bfd/ChangeLog:

	PR 25210
	* elfnn-aarch64.c (_bfd_aarch64_create_stub_section): Remove elfclass.
2020-01-10 13:51:08 +00:00
Alan Modra 71780f455f ubsan: alpha-coff: signed integer overflow
* coff-alpha.c (alpha_ecoff_object_p): Calculate size in bfd_size_type.
2020-01-10 17:32:33 +10:30
Nick Clifton b899eb3bb8 Fix an illegal memory access triggered when trying to examine an input file containing corrupt compressed sections.
PR 25221
	* bfd.c (bfd_convert_section_contents): Check for a compress
	header size that is larger than the actual section size.
2020-01-09 15:49:08 +00:00
Alan Modra 4c6ee6465a PR25351 .ARM.attributes not found for symbol
PR 25351
	* elflink.c (bfd_elf_final_link): Call _bfd_fix_excluded_sec_syms
	after removing sections.
2020-01-08 21:21:17 +10:30
Jim Wilson 85f7836470 RISC-V: Fix weak function call reloc overflow on llvm build.
bfd/
	PR 25205
	* elfnn-riscv.c (riscv_elf_relocate_section) <R_RISCV_CALL>: Add
	check for !bfd_link_pic (info).
	<R_RISCV_CALL_PLT>: Move next to R_RISCV_CALL.
	<R_RISCV_JAL>: Add comment.
	(_bfd_riscv_relax_section): For plt.offset check, add check for
	bfd_link_pic (info).  Add comment.

Change-Id: Ie769bc3d5adf096a51df5cc12efe3d50e80acb8f
2020-01-06 15:34:50 -08:00
Alan Modra 49078ece04 bfd_check_format: ignore errors from coff_real_object_p
Since 1993-11-05 git commit c188b0bec3, bfd_check_format has failed
if any of the target object_p functions returns false with any error
but bfd_error_wrong_format.  That's just weird.  There is really no
reason why coff_real_object_p should be fixed to only return that
error instead of numerous other possible errors.  Even an out of
memory condition for one target doesn't necessarily mean other targets
can't match, assuming the failing target nicely returns all memory it
might have used.

	* format.c (bfd_check_format_matches): Ignore bfd_error on target
	match failures.  Don't init to bfd_error_wrong_format before
	calling _bfd_check_format.
2020-01-06 21:53:51 +10:30
Alan Modra ab356be74c alpha-vms: don't exit on stack underflow/overflow
BFD is not supposed to exit or abort on anything the user can do.

	* vms-alpha.c (_bfd_vms_push, _bfd_vms_pop): Return pass/fail
	status rather than exiting on stack overflow or underflow.
	(_bfd_vms_slurp_etir): Adjust to suit.
2020-01-06 21:53:51 +10:30
Alan Modra 85d8681747 som_bfd_fill_in_ar_symbols buffer overflow
* som.c (som_bfd_fill_in_ar_symbols): Bounds check som_dict index.
2020-01-06 21:53:51 +10:30
Alan Modra 3e6aa7751a Basic error checking for mach-o
Fixes lots of places the fuzzers are going to find, and the one they
already hit.

	* mach-o.c (bfd_mach_o_read_dylinker): Don't read past end of
	command.  Check name offset is within command.
	(bfd_mach_o_read_dylib, bfd_mach_o_read_prebound_dylib),
	(bfd_mach_o_read_prebind_cksum, bfd_mach_o_read_twolevel_hints),
	(bfd_mach_o_read_fvmlib, bfd_mach_o_read_dysymtab),
	(bfd_mach_o_read_symtab, bfd_mach_o_read_uuid),
	(bfd_mach_o_read_linkedit, bfd_mach_o_read_str),
	(bfd_mach_o_read_dyld_info, bfd_mach_o_read_version_min),
	(bfd_mach_o_read_encryption_info, bfd_mach_o_read_source_version),
	(bfd_mach_o_read_encryption_info_64, bfd_mach_o_read_main),
	(bfd_mach_o_read_note, bfd_mach_o_read_build_version),
	(bfd_mach_o_read_segment): Similarly.
	(bfd_mach_o_read_thread): Properly bound check thread struct.
	Don't repeat checks on second loop.
	(bfd_mach_o_read_command): Fail on invalid command length.
2020-01-06 21:53:51 +10:30
Alan Modra ea933f17c3 Release bfd_alloc memory in bfd_check_format_matches
It's a little tricky.  We can release any memory back when we have a
match failure, but after a match success which we might want to
preserve for later use the high water mark must change to that of the
matched bfd.

	* format.c (bfd_check_format_matches): Add preserve_match.
	Save initial bfd state in "preserve", matched bfd state in
	"preserve_match".  Save just the first match.  Release
	bfd_alloc memory.  Restore and finish preserved state as
	appropriate on all function exit paths.
2020-01-04 19:20:33 +10:30
Alan Modra f24bdec486 mmo tdata leak
malloc'd tdata isn't freed.

	* mmo.c (mmo_mkobject): Allocate tdata with bfd_zalloc.
2020-01-04 19:20:33 +10:30
Alan Modra 991fb595e3 coff: free malloc'd memory on successful target match too
object_p functions cannot allocate memory by malloc and not free it
before returning.  Even a successful target match may not be the best
match.  If a match isn't used then those malloc'd blocks won't be
freed.

	* coffgen.c (coff_real_object_p): Free malloc'd memory on target
	match too.
2020-01-04 18:53:07 +10:30
Nick Clifton f2a3559d54 Fix potential illegal memory access when parsing a corrupt PEF format file.
PR 25307
	(bfd_pef_parse_function_stubs): Correct the test that ensures that
	there is enough data remaining in the code buffer before
	attempting to read a function stub.
2020-01-03 16:17:53 +00:00
Nick Clifton 7a0fb7be96 Fix potential illegal memory access failures in the BFD library by ensuring that the return value from bfd_malloc() is checked before it is used.
PR 25308
	* elf-properties.c (_bfd_elf_convert_gnu_properties): Check the
	return value from bfd_malloc.
	* elf32-arm.c (bfd_elf32_arm_vfp11_fix_veneer_locations): Likewise.
	(bfd_elf32_arm_stm32l4xx_fix_veneer_locations): Likewise.
	(elf32_arm_filter_cmse_symbols): Likewise.
	(elf32_arm_write_section): Likewise.
	* mach-o.c (bfd_mach_o_core_fetch_environment): Likewise.
	(bfd_mach_o_follow_dsym): Likewise.
	* pef.c (bfd_pef_print_loader_section): Likewise.
	(bfd_pef_scan_start_address): Likewise.
	(bfd_pef_parse_function_stubs): Likewise.
	(bfd_pef_parse_symbols): Likewise.
2020-01-03 14:41:02 +00:00
Sergei Trofimovich b26a3d5827 Fix ld/PR25316 for the ia64 target by refusing to support binary merging.
ld/PR25316
	* elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
        on binary inputs ld/PR25316.
        (is_ia64_elf): new helper to filter on ia64 objects.
2020-01-03 11:21:00 +00:00
Jan Beulich 4bb7a87e74 Mach-O: misc build adjustments
Oldish gcc warns about local variables shadowing outer scope ones.
Additionally %lx is not (always) suitable to print the result of
bfd_get_32().
2020-01-03 10:11:50 +01:00
Sergey Belyashov 6655dba246 Add support for the GBZ80, Z180, and eZ80 variants of the Z80 architecure. Add an ELF based target for these as well.
PR 25224
bfd	* Makefile.am: Add z80-elf target support.
	* configure.ac: Likewise.
	* targets.c: Likewise.
	* config.bfd: Add z80-elf target support and new arches: ez80 and z180.
	* elf32-z80.c: New file.
	* archures.c: Add new z80 architectures: eZ80 and Z180.
	* coffcode.h: Likewise.
	* cpu-z80.c: Likewise.
	* bfd-in2.h: Likewise plus additional Z80 relocations.
	* coff-z80.c: Add new relocations for Z80 target and local label check.

gas	* config/tc-z80.c: Add new architectures: Z180 and eZ80. Add support
	for assembler code generated by SDCC. Add new relocation types. Add
	z80-elf target support.
	* config/tc-z80.h: Add z80-elf target support. Enable dollar local
	labels. Local labels starts from ".L".
	* testsuite/gas/all/fwdexp.d: Fix failure due to symbol conflict.
	* testsuite/gas/all/fwdexp.s: Likewise.
	* testsuite/gas/z80/suffix.d: Fix failure on ELF target.
	* testsuite/gas/z80/z80.exp: Add new tests
	* testsuite/gas/z80/dollar.d: New file.
	* testsuite/gas/z80/dollar.s: New file.
	* testsuite/gas/z80/ez80_adl_all.d: New file.
	* testsuite/gas/z80/ez80_adl_all.s: New file.
	* testsuite/gas/z80/ez80_adl_suf.d: New file.
	* testsuite/gas/z80/ez80_isuf.s: New file.
	* testsuite/gas/z80/ez80_z80_all.d: New file.
	* testsuite/gas/z80/ez80_z80_all.s: New file.
	* testsuite/gas/z80/ez80_z80_suf.d: New file.
	* testsuite/gas/z80/r800_extra.d: New file.
	* testsuite/gas/z80/r800_extra.s: New file.
	* testsuite/gas/z80/r800_ii8.d: New file.
	* testsuite/gas/z80/r800_z80_doc.d: New file.
	* testsuite/gas/z80/z180.d: New file.
	* testsuite/gas/z80/z180.s: New file.
	* testsuite/gas/z80/z180_z80_doc.d: New file.
	* testsuite/gas/z80/z80_doc.d: New file.
	* testsuite/gas/z80/z80_doc.s: New file.
	* testsuite/gas/z80/z80_ii8.d: New file.
	* testsuite/gas/z80/z80_ii8.s: New file.
	* testsuite/gas/z80/z80_in_f_c.d: New file.
	* testsuite/gas/z80/z80_in_f_c.s: New file.
	* testsuite/gas/z80/z80_op_ii_ld.d: New file.
	* testsuite/gas/z80/z80_op_ii_ld.s: New file.
	* testsuite/gas/z80/z80_out_c_0.d: New file.
	* testsuite/gas/z80/z80_out_c_0.s: New file.
	* testsuite/gas/z80/z80_reloc.d: New file.
	* testsuite/gas/z80/z80_reloc.s: New file.
	* testsuite/gas/z80/z80_sli.d: New file.
	* testsuite/gas/z80/z80_sli.s: New file.

ld	* Makefile.am: Add new target z80-elf
	* configure.tgt: Likewise.
	* emultempl/z80.em: Add support for eZ80 and Z180 architectures.
	* emulparams/elf32z80.sh: New file.
	* emultempl/z80elf.em: Likewise.
	* testsuite/ld-z80/arch_ez80_adl.d: Likewise.
	* testsuite/ld-z80/arch_ez80_z80.d: Likewise.
	* testsuite/ld-z80/arch_r800.d: Likewise.
	* testsuite/ld-z80/arch_z180.d: Likewise.
	* testsuite/ld-z80/arch_z80.d: Likewise.
	* testsuite/ld-z80/comb_arch_ez80_z80.d: Likewise.
	* testsuite/ld-z80/comb_arch_z180.d: Likewise.
	* testsuite/ld-z80/labels.s: Likewise.
	* testsuite/ld-z80/relocs.s: Likewise.
	* testsuite/ld-z80/relocs_b_ez80.d: Likewise.
	* testsuite/ld-z80/relocs_b_z80.d: Likewise.
	* testsuite/ld-z80/relocs_f_z80.d: Likewise.
	* testsuite/ld-z80/z80.exp: Likewise.

opcodes	* z80-dis.c: Add support for eZ80 and Z80 instructions.
2020-01-02 14:14:59 +00:00
Tamar Christina 0db131fb83 AArch64: Set the correct ELF class for AArch64 stubs (PR/25210)
This fixes PR 25210 by specifying the the correct ELF class for AArch64 stubs.
After doing this the stub section starts behaving like a normal object file
loaded from disk.  That is SEC_LINKER_CREATED causes us to have to write the
section manually.

This flag was added as a fix for PR 24753.  I believe that
fix to still be correct as linker created sections don't have a size on disk
and it fixes the Arm bootstrap regression. But in this case specifying the
correct section class also makes the stub section not be considered by
compress.c.

So I'm partially revert this change so that we don't have to manage the section
manually as implied by SEC_LINKER_CREATED.

bfd/ChangeLog:

	PR 25210
	PR 24753
	* elfnn-aarch64.c (_bfd_aarch64_create_stub_section): Set ELF class.

ld/ChangeLog:

	PR 25210
	PR 24753
	* emultempl/aarch64elf.em (elf${ELFSIZE}_aarch64_add_stub_section):
	Remove SEC_LINKER_CREATED.
	* testsuite/ld-aarch64/aarch64-elf.exp: Add erratum835769-843419.
	* testsuite/ld-aarch64/erratum835769-843419.d: New test.
2020-01-02 14:08:27 +00:00
Alan Modra b14ce8bfe1 Re: Update year range in copyright notice of binutils files
Add the ChangeLog entry.
2020-01-01 18:55:18 +10:30
Alan Modra 0b11474080 ChangeLog rotation 2020-01-01 18:12:08 +10:30
Alan Modra bf31e60440 asan: alpha-vms: Heap-buffer-overflow
This fixes yet more errors in the alpha-vms buffer size checks.

	* vms-alpha.c (_bfd_vms_slurp_eisd): Don't overflow when checking
	offset.  Don't overflow when checking rec_size, and do allow
	rec_size to the end of the buffer.  Ensure eisd->type can be
	accessed, not just the first 32 bytes.  Don't call
	_bfd_vms_save_counted_string with zero length remaining.  Fail
	on empty string section name.
	(_bfd_vms_slurp_egsd): Formatting.  Catch more reads past end
	of record size.  Correct remaining length calculation.  Fail
	on empty string section name.  Consolidate error paths.
2019-12-31 23:30:21 +10:30
Alan Modra a7ac9aa525 vms-alpha.c object_p memory leaks
* vms-alpha.c (alpha_vms_free_private): New function, extracted..
	(vms_close_and_cleanup): ..from here.
	(alpha_vms_object_p): Call alpha_vms_free_private on failure.
2019-12-30 23:50:35 +10:30
Alan Modra 37d5ab199b coff object_p memory leaks
* coffgen.c (coff_real_object_p): Free malloc'd memory on failure.
2019-12-30 23:50:35 +10:30
Alan Modra 6a89db5c95 archive.c bfd_zalloc
Quite a few bfd_zalloc calls are wasting time clearing memory, and
should be bfd_alloc instead.

	* archive.c (do_slurp_bsd_armap): Use bfd_alloc rather than
	bfd_zalloc when memory is all written after the call.
	(do_slurp_coff_armap): Likewise.  Set bfd_error on ridiculously
	large allocations that overflow bfd_size_type.  Use just one
	bfd_release on error exit.
	(_bfd_slurp_extended_name_table): Use bfd_alloc for extended_names,
	clear last byte rather than the entire array.  Use bfd_alloc for
	string table.  Rearrange and simplify code copying file names.
2019-12-30 13:29:24 +10:30
Alan Modra 401e101e02 ubsan: alpha-vms: shift exponent is too large
* vms-alpha.c (_bfd_vms_slurp_egsd): Make base_addr a bfd_vma.
	Limit alignment power.  Correct and simplify alignment expression.
	(evax_bfd_print_relocation_records): Avoid signed shift left.
2019-12-29 21:26:00 +10:30
Alan Modra 37d2e9c7b1 asan: alpha-vms: memory leaks
* vms-misc.c (_bfd_vms_save_sized_string): Add abfd param, make
	size a size_t.  Use bfd_alloc rather than bfd_malloc.
	(_bfd_vms_save_counted_string): Similarly.
	* vms.h (_bfd_vms_save_sized_string): Update prototype.
	(_bfd_vms_save_counted_string): Likewise.
	* vms-alpha.c (_bfd_vms_slurp_ehdr): Adjust
	_bfd_vms_save_counted_string and bfd_vms_save_sized_string calls.
	(_bfd_vms_slurp_egsd, parse_module): Likewise.
	(_bfd_vms_slurp_eisd): Likewise.  Check return status.
	(alpha_vms_bfd_link_hash_table_free): New function.
	(alpha_vms_bfd_link_hash_table_create): Arrange to call it.
	(vms_close_and_cleanup): Free more memory.  Don't release tdata.
2019-12-29 21:26:00 +10:30
Alan Modra f5d35bb7a5 coff_close_and_cleanup
Fixes leaks in _bfd_coff_get_external_symbols and
_bfd_coff_read_string_table.

	* coffcode.h (coff_close_and_cleanup): Redefine to..
	* coffgen.c (_bfd_coff_close_and_cleanup): ..this.  New function.
	* libcoff-in.h (_bfd_coff_close_and_cleanup): Declare.
	* libcoff.h: Regenerate.
2019-12-29 21:26:00 +10:30
Alan Modra a6e5765ff1 PR15350, Fix compressed debug sections for PE targets
PR 15350
	* bfd.c (bfd_update_compression_header): Write zlib header for
	formats other than ELF too.
2019-12-29 21:25:39 +10:30
Alan Modra e5af216040 asan: som: heap-buffer-overflow
Triggered by overflow of size calulation resulting in a too small
buffer.  The testcase found one of the som_bfd_count_ar_symbols
problems.

	* som.c (setup_sections): Don't overflow space_strings_size.  Use
	bfd_malloc2 to catch overflow of size calculation.
	(som_prep_for_fixups): Use bfd_zalloc2 to catch overflow of size
	calculation.
	(som_build_and_write_symbol_table): Similarly use bfd_zmalloc2.
	(som_slurp_symbol_table): Similarly use bfd_zmalloc2, bfd_malloc2,
	and bfd_zalloc2.
	(bfd_som_attach_aux_hdr): Use size_t vars for string length.
	(som_bfd_count_ar_symbols): Use bfd_malloc2 to catch overflow of
	size calculation.  Use size_t vars for length and catch overflow.
	(som_slurp_armap): Use bfd_alloc2 to catch overflow of size
	calculation.
	(som_bfd_ar_write_symbol_stuff): Similarly use bfd_zmalloc2 and
	bfd_malloc2.  Perform size calculations in bfd_size_type.
2019-12-26 17:49:03 +10:30
Hannes Domani f5311f2509 pe_bfd_read_buildid memory leak
* peicode.h (pe_bfd_read_buildid): Free data.
2019-12-26 12:38:49 +10:30
Alan Modra 2c0e48e5b7 asan: vms-alpha: heap-buffer-overflow
Two buffer overflows, and some over restrictive length checks.

	* vms-alpha.c (add_symbol): Add "max" parameter.  Error on string
	length larger than max.
	(_bfd_vms_slurp_egsd): Ensure record is at least large enough to
	read string length byte, error if not.  Pass size to add_symbol.
	(_bfd_vms_slurp_etir): Don't read past end of buffer when reading
	type and length.  Allow read of last byte in buffer.
2019-12-23 18:06:23 +10:30
Alan Modra 27c1c4271a ubsan: wasm: shift is too large for 64-bit type 'bfd_vma'
bfd/
	* wasm-module.c (wasm_read_leb128): Don't allow oversize shifts.
	Catch value overflow.  Sign extend only on terminating byte.
opcodes/
	* wasm32-dis.c (wasm_read_leb128): Don't allow oversize shifts.
	Catch value overflow.  Sign extend only on terminating byte.
2019-12-23 17:58:09 +10:30
Alan Modra e76832f125 ubsan: xtensa: left shift cannot be represented in type 'int'
* xtensa-isa.c (xtensa_insnbuf_from_chars): Avoid signed overflow.
2019-12-20 13:36:06 +10:30
Alan Modra 15d2859fdd ubsan: hppa: left shift of negative value
bfd/
	* libhppa.h (hppa_field_adjust, bfd_hppa_insn2fmt): Delete forward
	declaration.  Move ATTRIBUTE_UNUSED to definition.
	(sign_extend, low_sign_extend, sign_unext, low_sign_unext),
	(re_assemble_3, re_assemble_12, re_assemble_14, re_assemble_16),
	(re_assemble_17, re_assemble_21, re_assemble_22): Likewise.  Make
	args and return value unsigned.  Use unsigned variables.
	(hppa_rebuild_insn): Similarly.
opcodes/
	* hppa-dis.c (extract_16, extract_21, print_insn_hppa): Use
	unsigned variables.
2019-12-20 13:36:06 +10:30
Alan Modra 9d78076ef8 bfd_check_format memory leak
* format.c (bfd_check_format_matches): Free matching_vector when
	not returning matching target strings.
2019-12-20 13:36:06 +10:30
Alan Modra fcc5d04f92 coff-alpha memory leak
* coff-alpha.c (alpha_ecoff_read_ar_hdr): Free ar_hdr on error return.
2019-12-20 13:36:06 +10:30
Alan Modra 228c8f4be0 xcoff slurp_armap bounds checking
"count * 8 >= size" might overflow, "count >= size / 8" doesn't.

	* coff-rs6000.c (_bfd_xcoff_slurp_armap): Don't overflow when
	checking symbol count against section size.  Guard against strlen
	running off end of buffer by allocating one more byte and zeroing.
	* coff64-rs6000.c (xcoff64_slurp_armap): Likewise.
2019-12-19 21:52:47 +10:30
Alan Modra 9ad9b810c3 PowerPC, use size_t rather than long for indices
This is fussing about nothing really but since I was looking at signed
vs. unsigned issues, I decided to use the correct types here.

	* elf32-ppc.c (ppc_elf_get_synthetic_symtab): Use size_t for vars.
	* elf64-ppc.c (sym_exists_at): Use size_t for lo, hi and mid.
2019-12-19 15:27:00 +10:30
Alan Modra 2365f8d70c Yet more signed overflow fixes
* elf-bfd.h (ELF_LOCAL_SYMBOL_HASH): Avoid signed overflow.
	* elf32-hppa.c (final_link_relocate): Likewise.
	* elf32-ppc.c (_bfd_elf_ppc_at_tls_transform): Likewise.
	(_bfd_elf_ppc_at_tprel_transform, is_insn_ds_form): Likewise.
	(is_insn_dq_form, ppc_elf_relocate_section): Likewise.
	* elf64-ppc.c (ok_lo_toc_insn, ppc64_elf_edit_toc): Likewise.
	(ppc64_elf_relocate_section): Likewise.
	* elfxx-mips.c (mips_elf_perform_relocation): Likewise.
	* netbsd.h (N_SET_FLAGS): Likewise.
2019-12-18 18:38:13 +10:30
Alan Modra 5b660084e2 Remove tic80 support
This is one way of fixing ubsan bug reports, just delete the code.

The assembler support was removed back in 2005 along with other
non-BFD assemblers, but somehow the remainder of the port stayed in.

bfd/
	* coff-tic80.c: Delete file.
	* cpu-tic80.c: Delete file.
	* archures.c: Remove tic80 support.
	* coffcode.h: Likewise.
	* coffswap.h: Likewise.
	* targets.c: Likewise.
	* config.bfd: Likewise.
	* configure.ac: Likewise.
	* Makefile.am: Likewise.
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* configure: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
binutils/
	* testsuite/binutils-all/objcopy.exp: Remove tic80 support.
	* testsuite/binutils-all/objdump.exp: Likewise.
gas/
	* doc/as.texi: Remove mention of tic80.
include/
	* coff/tic80.h: Delete file.
	* opcode/tic80.h: Delete file.
ld/
	* emulparams/tic80coff.sh: Delete file.
	* scripttempl/tic80coff.sc: Delete file.
	* configure.tgt: Remove tic80 support.
	* Makefile.am: Likewise.
	* Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
opcodes/
	* tic80-dis.c: Delete file.
	* tic80-opc.c: Delete file.
	* disassemble.c: Remove tic80 support.
	* disassemble.h: Likewise.
	* Makefile.am: Likewise.
	* configure.ac: Likewise.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* po/POTFILES.in: Regenerate.
2019-12-17 16:36:54 +10:30
Alan Modra 0bc3450e22 Set no file contents PT_LOAD p_offset to first page
PR 25237
	* elf.c (assign_file_positions_for_load_sections): Attempt to
	keep meaningless p_offset for PT_LOAD segments without file
	contents within file size.
2019-12-13 21:23:15 +10:30
Alan Modra 199d46bebb Remove duplicate cast
* libbfd.c (bfd_get): Don't cast result of bfd_get_8.
	* bfd-in2.h: Regenerate.
2019-12-12 16:46:30 +10:30
Alan Modra 13c9c48599 bfd signed overflow fixes
Aimed at quietening ubsan.

include/
	* opcode/mmix.h (PUSHGO_INSN_BYTE): Make unsigned.
	(GO_INSN_BYTE, SETL_INSN_BYTE, INCML_INSN_BYTE, INCMH_INSN_BYTE),
	(INCH_INSN_BYTE, SWYM_INSN_BYTE, JMP_INSN_BYTE): Likewise.
bfd/
	* elf32-rx.c (elf32_rx_relax_section): Avoid signed overflow.
	* libaout.h (N_SET_INFO, N_SET_FLAGS): Likewise.
	* netbsd.h (write_object_contents): Likewise.
	* elf32-arm.c (bfd_elf32_arm_vfp11_erratum_scan): Likewise.
	* libhppa.h (HPPA_R_CONSTANT): Don't signed extend with shifts.
	(stm32l4xx_create_replacing_stub_vldm): Don't truncate high bits
	with shifts.
	* elf32-nds32.h (R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG): Define
	using 1u shifted left.  Ditto for other macros.
	* mmo.c (LOP): Make unsigned.
2019-12-11 21:14:19 +10:30
Alan Modra 09c7848734 Make bfd_get_8 return a bfd_vma like other bfd_get_* functions
And similarly for bfd_get_signed_8.

bfd/
	* libbfd.c (bfd_get_8): Return a bfd_vma.
	(bfd_get_signed_8): Return a bfd_signed_vma.
	* bfd-in2.h: Regenerate.
binutils/
	* od-xcoff.c (dump_dumpx_core): Adjust for bfd_h_get_8 change.
2019-12-11 21:14:19 +10:30
Alan Modra 567607c11f ubsan: xtensa: left shift cannot be represented in type 'int'
In Operand_soffsetx4_decode:
  soffsetx4_0 = 0x4 + ((((int) offset_0 << 14) >> 14) << 2);
and other places.

Don't sign extend with shifts!  This file also has many occurrences of
truncation via shifts, which aren't a problem due to using uint32, but
I dislike on principle enough to fix.

	* xtensa-modules.c (Field_* functions): Don't mask using shifts.
	(Operand_soffsetx4_decode, Operand_simm4_decode),
	(Operand_simm8_decode, Operand_simm8x256_decode),
	(Operand_simm12b_decode, Operand_label8_decode),
	(Operand_label12_decode, Operand_soffset_decode),
	(Operand_xt_wbr15_label_decode, Operand_xt_wbr18_label_decode): Don't
	sign extend using shifts.
	(Operand_immrx4_decode, Operand_uimm16x4_decode): Avoid UB in
	constant.
2019-12-11 11:35:14 +10:30
Alan Modra 8ff23dba80 ubsan: ia64: left shift of negative value
Here, since val is signed:
   *valuep = (val << scale);

	* cpu-ia64-opc.c (ext_imms_scaled): Avoid undefined left shift
	of negative values by using unsigned vars.
2019-12-11 11:33:36 +10:30
Alan Modra 5fa370e437 PR25236, common sym versioning
In cases where a relocatable object file has a common symbol, no other
file has a definition, and there is a matching common symbol found in
a shared library then ld will output a definition using the largest of
size and alignment for the commons.  This patch fixes a bug in ld that
ignored common symbols when assigning versions, resulting in such
symbols being given VER_NDX_LOCAL versions.

	PR 25236
	* elflink.c (_bfd_elf_link_assign_sym_version): Assign versions
	for ELF_COMMON_DEF_P symbols.
	(elf_link_output_extsym, _bfd_elf_add_default_symbol): Adjust to
	suit.
2019-12-07 16:21:01 +10:30
Sandra Loosemore bce7c9d6fb Only give FDE encoding warnings if --eh-frame-hdr was specified.
This bug was observed on nios2-linux-gnu with some C++ programs
linked with -pie or -shared.  The nios2 ABI doesn't include appropriate
relocations in this instance and GCC is also being patched not to pass
--eh-frame-hdr to the linker in those cases.

2019-12-05  Sandra Loosemore  <sandra@codesourcery.com>

        bfd/
        * elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Make
        FDE encoding warning conditional.
2019-12-05 13:20:12 -08:00
Nick Clifton a23e9ba17f Fix a problem computing the size fields in the PE format header.
PR 25029
	* peXXigen.c (_bfd_XXi_swap_aouthdr_out): Ignore empty sections
	when computing the sizes stored in the headers.
2019-12-05 13:56:07 +00:00
Alan Modra e63ef0954d PR25230, addr2line fails on dwz output
This patch remedies the following DW_FORM_GNU_ref_alt related problem:
      /* FIXME: Do we need to locate the correct CU, in a similar
        fashion to the code in the DW_FORM_ref_addr case above ?  */
Without the correct CU the wrong abbrevs are used, resulting in
errors and/or wrong file names.

There is scope for further work here.  Parsing of CUs should be a two
step process, with the first stage just finding the bounds of the CU.
This would allow find_abstract_instance to quickly find the CU
referenced by DW_FORM_ref_addr or DW_FORM_GNU_ref_alt, then take the
second stage of CU parsing where abbrevs, ranges and suchlike consume
time and memory.  As it is, we just process CUs from the start of
.debug_info until we find the one of interest.  The testcase in the PR
takes 98G of virtual memory.

	PR 25230
	* dwarf2.c (struct dwarf2_debug_file): Add line_table and
	abbrev_offsets.
	(struct abbrev_offset_entry): New.
	(hash_abbrev, eq_abbrev, del_abbrev): New functions.
	(read_abbrevs): Check whether we have already read abbrevs at
	given offset, and add new offset/abbrev to hash table.
	(decode_line_info): Keep line table at offset zero in file struct.
	Return this for a cu reusing the same dir/file list.
	(find_abstract_instance): Find cu for DW_FORM_GNU_ref_alt.
	(_bfd_dwarf2_slurp_debug_info): Create offset/abbrev hash tables.
	(_bfd_dwarf2_cleanup_debug_info): Adjust deletion of lines and
	abbrevs.
2019-12-03 17:30:58 +10:30
Alan Modra 99b06c600f PR25230, dwarf2.c per file stash
This is just moving things around, in preparation for parsing alt
file debug_info.

	PR 25230
	* dwarf2.c (struct dwarf2_debug_file): New struct.
	(struct dwarf2_debug): Delete fields now in dwarf2_debug_file.
	Add f, alt fields.
	(struct comp_unit): Add file field.
	(read_indirect_string, read_indirect_line_string): Adjust to suit.
	(read_alt_indirect_string, read_alt_indirect_ref): Likewise.
	(read_debug_ranges, find_abstract_instance, read_rangelist): Likewise.
	(_bfd_dwarf2_stash_syms, place_sections): Likewise.
	(stash_maybe_update_info_hash_tablse): Likewise.
	(stash_verify_info_hash_table): Likewise.
	(_bfd_dwarf2_slurp_debug_info): Likewise.
	(_bfd_dwarf2_find_symbol_bias): Likewise.
	(_bfd_dwarf2_find_nearest_line): Likewise.
	(_bfd_dwarf2_cleanup_debug_info): Likewise.
	(read_abbrevs): Add file param and adjust.  Update calls.
	(stash_comp_unit): Likewise.
	(decode_line_info): Delete stash param and adjust.  Update calls.
	(comp_unit_find_nearest_line): Likewise.
	(comp_unit_maybe_decode_line_info): Likewise.
	(comp_unit_find_line): Likewise.
	(parse_comp_unit): Add file and info_ptr param and adjust.  Update
	calls.
2019-12-03 16:27:29 +10:30
Alan Modra 019cc8758a dwarf2.c: read_abbrevs fail cleanup, and offset checking
read_section does offset checking, reporting an error on out of
bounds.  There's no need to duplicate the check in functions calling
read_section.  Also, I spotted a place where a pointer difference
expression was being cast to unsigned int, possibly truncating
relevant bits on a 64-bit host.

	* dwarf2.c (read_indirect_string): Don't duplicate offset check
	done in read_section.
	(read_indirect_line_string): Likewise.
	(read_alt_indirect_string): Likewise.
	(read_alt_indirect_ref): Likewise.
	(read_abbrevs): Likewise.  Free memory on all failure paths.
	Use correct unsigned type for pointer difference comparison.
2019-12-03 16:05:40 +10:30
Alan Modra 1b8e12713b dwarf2.c stash->sec_info_ptr and stash->sec
These are unused.  Remove them.  Also fix the wrong sort of 0 being
returned from read_alt_indirect_ref.

	* dwarf2.c (struct dwarf2_debug): Update comments.  Remove sec
	and sec_info_ptr.
	(_bfd_dwarf2_slurp_debug_info): Don't set sec or sec_info_ptr.
	(stash_comp_unit): Likewise.
	(read_alt_indirect_ref): Return NULL not FALSE.
2019-12-03 16:03:20 +10:30
Alan Modra 2247a609df _bfd_dwarf2_find_nearest_line comment fix
These lines should have been removed along with the addr_size parameter.

	* dwarf2.c (_bfd_dwarf2_find_nearest_line): Correct function comment.
2019-12-03 16:00:48 +10:30
Alan Modra 7f3bf38453 PR23652, Use symbols from debug bfd for _bfd_elf_find_function properly
There were a number of problems with the previous patch.  Firstly,
_bfd_dwarf2_stash_syms didn't do anything when the original file had
dynamic symbols, and secondly, info found by the symbol search didn't
make it out of _bfd_elf_find_nearest_line except in the case of DWARF
functions without external linkage.

	PR 23652
	* dwarf2.c (_bfd_dwarf2_stash_syms): Break out of loop on finding
	matching section.
	(_bfd_dwarf2_find_nearest_line): Return an int, with value 2 when
	returning info from the symbol table.  Do the _bfd_elf_find_function
	search also when !found.  Call _bfd_dwarf2_stash_syms regardless of
	symbols.
	* elf64-alpha.c (elf64_alpha_find_nearest_line): Accept dwarf2
	result of 1 only.
	* elfxx-mips.c (_bfd_mips_elf_find_nearest_line): Likewise.
	* libbfd-in.h (_bfd_dwarf2_find_nearest_line): Update prototype.
	* libbfd.h: Regenerate.
2019-11-27 19:10:11 +10:30
Alan Modra e76790600a PR23652, Use symbols from debug bfd for _bfd_elf_find_function
Sometimes DWARF info for a function is incomplete, and the function
can be retrieved by examining symbols.  However, when separate debug
files are used it may be that the original file is completely
stripped of symbols.  This patch teaches BFD to look at symbols from
the debug file in that case.

The patch also removes arm_elf_find_function, instead implementing
elf_backend_maybe_function_sym.  arm_elf_find_function was written
before the generic _bfd_elf_find_function called maybe_function_sym.
aarch64 copied arm, so that file gets the same treatment.  There is
some chance this will speed up arm and aarch64 lookup of function/line.

	PR 23652
	* dwarf2.c (_bfd_dwarf2_stash_syms): New function.
	(_bfd_dwarf2_find_nearest_line): Use it here, passing syms to
	_bfd_elf_find_function.  Call _bfd_elf_find_function in cases
	where _bfd_elf_find_nearest_line would do so.
	* elf.c (_bfd_elf_find_nearest_line): Omit _bfd_elf_find_function
	for dwarf2.
	* elfxx-mips.c (_bfd_mips_elf_find_nearest_line): Similarly.  Tidy.
	* elf32-arm.c (elf32_arm_maybe_function_sym): New function.
	(elf_backend_maybe_function_sym): Define.
	(arm_elf_find_function, elf32_arm_find_nearest_line): Delete.
	(bfd_elf32_find_nearest_line): Don't define.
	* elfnn-aarch64.c (elfNN_aarch64_maybe_function_sym): New function.
	(elf_backend_maybe_function_sym): Define.
	(aarch64_elf_find_function, elfNN_aarch64_find_nearest_line): Delete.
	(bfd_elfNN_find_nearest_line): Don't define.
2019-11-27 12:06:29 +10:30
Alan Modra 96e2dbda08 Correct R_SH_IND12W handling
Using bfd_vma for insn is to avoid having to worry about sign
propagation in expressions involving insn and sym_value when bfd_vma
is not the same as unsigned long.

	* elf32-sh.c (sh_reloc): Use a bfd_vma insn.
	(sh_reloc <R_SH_IND12W>): Divide calculated relocation value
	by two before applying to insn.  Correct overflow test.
	* coff-sh.c (sh_reloc): Likewise.
2019-11-27 11:58:17 +10:30
Nick Clifton 239b426b11 Fix comparison operations in SH code that trigger warning in clang.
* elf32-sh.c (sh_elf_reloc): Use a signed_vma when checking for a
	negative relocated value.
	* coff-sh.c (sh_reloc): Likewise.
2019-11-26 14:06:12 +00:00
Alan Modra bb2942085c Pass section when available to bfd_octets_per_byte
and other tidies.  I think it's better to default to passing the
section to bfd_octets_per_byte, even in cases where we know it won't
make a difference.

A number of the coff reloc functions used bfd_octets_per_byte wrongly,
not factoring it into the offset into the data buffer.  As it happens,
the targets using those files always had bfd_octets_per_byte equal to
one, so there wasn't any detectable wrong behaviour.  However, it is
wrong in the source and might cause trouble for anyone creating a new
target.  Besides fixing that, the patch also defines OCTETS_PER_BYTE
as one in target files where that is appropriate.

bfd/
	* archures.c (bfd_octets_per_byte): Tail call
	bfd_arch_mach_octets_per_byte.
	* coff-arm.c (OCTETS_PER_BYTE): Define.
	(coff_arm_reloc): Introduce new "octets" temp.  Use OCTETS_PER_BYTE
	with section.  Correct "addr".  Remove ATTRIBUTE_UNUSED.
	* coff-i386.c (coff_i386_reloc): Similarly.
	* coff-mips.c (mips_reflo_reloc): Similarly.
	* coff-x86_64.c (coff_amd64_reloc): Similarly.
	* elf32-msp430.c (OCTETS_PER_BYTE): Define.
	(rl78_sym_diff_handler): Use OCTETS_PER_BYTE, with section.
	* elf32-nds32.c (nds32_elf_get_relocated_section_contents): Similarly.
	* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Similarly.
	* elf32-pru.c (pru_elf32_do_ldi32_relocate): Similarly.
	* elf32-s12z.c (opru18_reloc): Similarly.
	* elf32-sh.c (sh_elf_reloc): Similarly.
	* elf32-spu.c (spu_elf_rel9): Similarly.
	* elf32-xtensa.c (bfd_elf_xtensa_reloc): Similarly.
	* elf64-ppc.c (ppc64_elf_ha_reloc, ppc64_elf_brtaken_reloc),
	(ppc64_elf_toc64_reloc): Similarly.
	* bfd.c (bfd_get_section_limit): Pass section to bfd_octets_per_byte.
	* cofflink.c (_bfd_coff_link_input_bfd),
	(_bfd_coff_reloc_link_order): Likewise.
	* elf.c (_bfd_elf_section_offset): Likewise.
	* elflink.c (resolve_section, bfd_elf_perform_complex_relocation),
	(elf_link_input_bfd, elf_reloc_link_order, elf_fixup_link_order),
	(bfd_elf_final_link): Likewise.
	* elf.c (_bfd_elf_make_section_from_shdr): Don't strncmp twice
	to set SEC_ELF_OCTETS.
	* reloc.c (bfd_perform_relocation): Tidy SEC_ELF_OCTETS special case.
	(bfd_install_relocation): Likewise.
	(_bfd_final_link_relocate): Don't recalculate octets.
	* syms.c (_bfd_stab_section_find_nearest_line): Introduc new
	"octets" temp.
	* bfd-in2.h: Regenerate.
ld/
	* ldexp.c (fold_name): Pass section to bfd_octets_per_byte.
	* ldlang.c (init_opb): Don't call bfd_arch_mach_octets_per_byte
	unnecessarily.
2019-11-25 14:32:19 +10:30
Christian Eggers 618265039f Introduce new section flag: SEC_ELF_OCTETS
All symbols, sizes and relocations in this section are octets instead of
bytes.  Required for DWARF debug sections as DWARF information is
organized in octets, not bytes.

bfd/
	* section.c (struct bfd_section): New flag SEC_ELF_OCTETS.
	* archures.c (bfd_octets_per_byte): New parameter sec.
	If section is not NULL and SEC_ELF_OCTETS is set, one octet es
	returned [ELF targets only].
	* bfd.c (bfd_get_section_limit): Provide section parameter to
	bfd_octets_per_byte.
	* bfd-in2.h: regenerate.
	* binary.c (binary_set_section_contents): Move call to
	bfd_octets_per_byte into section loop. Provide section parameter
	to bfd_octets_per_byte.
	* coff-arm.c (coff_arm_reloc): Provide section parameter
	to bfd_octets_per_byte.
	* coff-i386.c (coff_i386_reloc): likewise.
	* coff-mips.c (mips_reflo_reloc): likewise.
	* coff-x86_64.c (coff_amd64_reloc): likewise.
	* cofflink.c (_bfd_coff_link_input_bfd): likewise.
	(_bfd_coff_reloc_link_order): likewise.
	* elf.c (_bfd_elf_section_offset): likewise.
	(_bfd_elf_make_section_from_shdr): likewise.
	Set SEC_ELF_OCTETS for sections with names .gnu.build.attributes,
	.debug*, .zdebug* and .note.gnu*.
	* elf32-msp430.c (rl78_sym_diff_handler): Provide section parameter
	to bfd_octets_per_byte.
	* elf32-nds.c (nds32_elf_get_relocated_section_contents): likewise.
	* elf32-ppc.c (ppc_elf_addr16_ha_reloc): likewise.
	* elf32-pru.c (pru_elf32_do_ldi32_relocate): likewise.
	* elf32-s12z.c (opru18_reloc): likewise.
	* elf32-sh.c (sh_elf_reloc): likewise.
	* elf32-spu.c (spu_elf_rel9): likewise.
	* elf32-xtensa.c (bfd_elf_xtensa_reloc): likewise
	* elf64-ppc.c (ppc64_elf_brtaken_reloc): likewise.
	(ppc64_elf_addr16_ha_reloc): likewise.
	(ppc64_elf_toc64_reloc): likewise.
	* elflink.c (bfd_elf_final_link): likewise.
	(bfd_elf_perform_complex_relocation): likewise.
	(elf_fixup_link_order): likewise.
	(elf_link_input_bfd): likewise.
	(elf_link_sort_relocs): likewise.
	(elf_reloc_link_order): likewise.
	(resolve_section): likewise.
	* linker.c (_bfd_generic_reloc_link_order): likewise.
	(bfd_generic_define_common_symbol): likewise.
	(default_data_link_order): likewise.
	(default_indirect_link_order): likewise.
	* srec.c (srec_set_section_contents): likewise.
	(srec_write_section): likewise.
	* syms.c (_bfd_stab_section_find_nearest_line): likewise.
	* reloc.c (_bfd_final_link_relocate): likewise.
	(bfd_generic_get_relocated_section_contents): likewise.
	(bfd_install_relocation): likewise.
	For section which have SEC_ELF_OCTETS set, multiply output_base
	and output_offset with bfd_octets_per_byte.
	(bfd_perform_relocation): likewise.
include/
	* coff/ti.h (GET_SCNHDR_SIZE, PUT_SCNHDR_SIZE, GET_SCN_SCNLEN),
	(PUT_SCN_SCNLEN): Adjust bfd_octets_per_byte calls.
binutils/
	* objdump.c (disassemble_data): Provide section parameter to
	bfd_octets_per_byte.
	(dump_section): likewise
	(dump_section_header): likewise. Show SEC_ELF_OCTETS flag if set.
gas/
	* as.h: Define SEC_OCTETS as SEC_ELF_OCTETS if OBJ_ELF.
	* dwarf2dbg.c: (dwarf2_finish): Set section flag SEC_OCTETS for
	.debug_line, .debug_info, .debug_abbrev, .debug_aranges, .debug_str
	and .debug_ranges sections.
	* write.c (maybe_generate_build_notes): Set section flag
	SEC_OCTETS for .gnu.build.attributes section.
	* frags.c (frag_now_fix): Don't divide by OCTETS_PER_BYTE if
	SEC_OCTETS is set.
	* symbols.c (resolve_symbol_value): Likewise.
ld/
	* ldexp.c (fold_name): Provide section parameter to
	bfd_octets_per_byte.
	* ldlang (init_opb): New argument s. Set opb_shift to 0 if
	SEC_ELF_OCTETS for the current section is set.
	(print_input_section): Pass current section to init_opb.
	(print_data_statement,print_reloc_statement,
	print_padding_statement): Likewise.
	(lang_check_section_addresses): Call init_opb for each
	section.
	(lang_size_sections_1,lang_size_sections_1,
	lang_do_assignments_1): Likewise.
	(lang_process): Pass NULL to init_opb.
2019-11-25 14:32:19 +10:30
Alan Modra 73d5efd7e1 ARM cmse_scan segfault
This code in elf_link_add_object_symbols:

      ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed);
      if (ret < 0)
	goto error_return;

      /* If we have already included this dynamic object in the
	 link, just ignore it.  There is no reason to include a
	 particular dynamic object more than once.  */
      if (ret > 0)
	return TRUE;

prevents a shared library from being loaded twice by ensuring that any
library soname doesn't match the soname of one already loaded.  This
happens before sym_hashes are allocated, which leaves sym_hashes NULL.

cmse_scan looks at library symbols, and when attempting to look up a
global symbol will segfault if sym_hashes is zero.

	* elf32-arm.c (elf32_arm_size_stubs): Exclude dynamic library
	BFDs that have not been loaded.
2019-11-21 21:08:30 +10:30
Alan Modra f14080d440 PR25197, assertion fail coffgen.c
The testcase in this PR triggered "BFD_ASSERT (p2->is_sym)" by
sneakily generating a C_FILE sym whose value pointed into auxents.
The fix then is in the last changed line of this patch, to check
p->is_sym as well as p->u.syment.n_sclass.  The other changes fix
various overflow checks that weren't as solid as they could be.

	PR 25197
	* coffgen.c (coff_find_nearest_line_with_names): Check that C_FILE
	u.syment.n_value does point at another C_FILE sym and not into
	some auxent that happens to look like a C_FILE.  Properly check
	for integer overflow and avoid possible pointer wrap-around.
	Simplify pr17512 checks.
2019-11-19 12:31:22 +10:30
Alan Modra 94698d0198 PR25200, SIGSEGV in _bfd_elf_validate_reloc
PR 25200
	* reloc.c (bfd_default_reloc_type_lookup): Don't BFD_FAIL.
	* elf.c (_bfd_elf_validate_reloc): Don't segfault on NULL howto.
2019-11-19 07:35:05 +10:30
Alan Modra ed7e9d0bda elf_backend_init_file_header
This patch renames elf_backend_post_process_headers and moves the
prep_headers code into the new function.  Naming the backend functions
elf_backend_init_file_header and elf_backend_modify_headers makes it
clear which function is called first.

	* elf-bfd.h (struct elf_backend_data <elf_backend_init_file_header>):
	Rename from elf_backend_post_process_headers.
	(_bfd_elf_post_process_headers): Delete.
	(_bfd_elf_init_file_header): Declare.
	* elf.c (_bfd_elf_compute_section_file_positions): Call new function
	in place of prep_headers and elf_backend_post_process_headers.
	(_bfd_elf_init_file_header): Renamed from prep_headers with
	updated args and made global.  Delete dead code.
	(_bfd_elf_post_process_headers): Delete.
	* elf32-arm.c (elf32_arm_init_file_header): Rename from
	elf32_arm_post_process_headers and call _bfd_elf_init_file_header.
	Return status.
	(elf_backend_init_file_header): Define.
	(elf_backend_post_process_headers): Don't define.
	* elf32-i386.c (elf_i386_fbsd_init_file_header): Similarly.
	* elf32-m68hc1x.c (elf32_m68hc11_init_file_header): Similarly.
	* elf32-metag.c (elf_metag_init_file_header): Similarly.
	* elf32-spu.c (spu_elf_init_file_header
	* elf32-visium.c (visium_elf_init_file_header
	* elf64-alpha.c (elf64_alpha_fbsd_init_file_header
	* elf64-hppa.c (elf64_hppa_init_file_header
	* elf64-ia64-vms.c (elf64_vms_init_file_header
	* elfnn-aarch64.c (elfNN_aarch64_init_file_header
	* elfnn-ia64.c (elfNN_hpux_init_file_header
	* elfxx-mips.c (_bfd_mips_init_file_header
	* elfxx-mips.h (_bfd_mips_post_process_headers): Delete.
	(_bfd_mips_init_file_header): Declare.
	(elf_backend_post_process_headers): Delete.
	(elf_backend_init_file_header): Define.
	* elfxx-target.h (elf_backend_post_process_headers): Delete.
	(elf_backend_init_file_header): Define and use.
	* elf32-m68hc12.c (elf_backend_init_file_header): Define.
	(elf_backend_post_process_headers): Don't define.
	* elf32-m68hc1x.h (elf32_m68hc11_post_process_headers): Delete.
	(elf32_m68hc11_init_file_header): Declare.
	* elf32-ppc.c (elf_backend_post_process_headers): Remove
	unnecessary undef.
2019-11-18 22:06:09 +10:30
Alan Modra 6d6c25c8ea elf_backend_modify_headers
This patch renames elf_backend_modify_program_headers and moves the
elf.c code tweaking the ELF file header for -pie -Ttext-segment to a
new function, _bfd_elf_modify_headers, which then becomes the default
elf_backed_modify_headers and is called from any other target
elf_backed_modify_headers.

	* elf-bfd.h (struct elf_backend_data <elf_backend_modify_headers>):
	Rename from elf_backend_modify_program_headers.
	(_bfd_elf_modify_headers): Declare.
	* elf.c (assign_file_positions_except_relocs): Set
	elf_program_header_size.  Always call elf_backend_modify_headers.
	Extract code modifying file header..
	(_bfd_elf_modify_headers): ..to here.  New function.
	* elf32-arm.c (elf_backend_modify_headers): Renamed from
	elf_backend_modify_program_headers.
	* elf32-i386.c: Similarly.
	* elf64-x86-64.c: Similarly.
	* elfxx-target.h: Similarly.  Default elf_backend_modify_headers
	to _bfd_elf_modify_headers.
	* elf-nacl.h (nacl_modify_headers): Rename from
	nacl_modify_program_headers.
	* elf-nacl.c (nacl_modify_headers): Rename from
	nacl_modify_program_headers and call _bfd_elf_modify_headers.
	* elf32-rx.c (elf32_rx_modify_headers): Similarly.
	* elf32-spu.c (spu_elf_modify_headers): Similarly.
	* elfnn-ia64.c (elfNN_ia64_modify_headers): Similarly.
	* elf32-sh.c (elf_backend_modify_program_headers): Don't undef.
2019-11-18 22:06:09 +10:30
Alan Modra 9aea1e3137 PR25196, abort in rewrite_elf_program_header
This patch introduces a new "sorry, cannot handle this file" bfd error
status.  The idea is to use this error in cases where bfd hasn't found
a bfd_bad_value error, ie. an input file or set of options that are
invalid, but rather an input file that is simply too difficult to
process.  Typically this might happen with fuzzed object files such as
the one in the PR, a wildly improbable core file.  Some things are
just not worth wasting time over to fix "properly".

	PR 25196
	* bfd.c (bfd_error_type): Add bfd_error_sorry.
	(bfd_errmsgs): Likewise.
	* elf.c (rewrite_elf_program_header): Don't abort on confused
	lma/alignment.  Replace bfd_error_bad_value with bfd_error_sorry.
	(_bfd_elf_validate_reloc): Use bfd_error_sorry.
	(_bfd_elf_final_write_processing): Likewise.
	* bfd-in2.h: Regenerate.
2019-11-18 22:06:09 +10:30
Jim Wilson c6261a00c3 RISC-V: Fix ld relax failure with calls and align directives.
Make _bfd_riscv_relax_call handle section alignment padding same as
the _bfd_riscv_relax_lui and _bfd_riscv_relax_pc functions already
do.  Use the max section alignment if section boundaries are crossed,
otherwise the alignment of the containing section.

	bfd/
	PR 25181
	* elfnn-riscv.c (_bfd_riscv_relax_call): Always add max_alignment to
	foff.  If sym_sec->output_section and sec->output_section are the same
	and not *ABS* then set max_alignment to that section's alignment.

	ld/
	PR 25181
	* testsuite/ld-riscv-elf/call-relax-0.s: New file.
	* testsuite/ld-riscv-elf/call-relax-1.s: New file.
	* testsuite/ld-riscv-elf/call-relax-2.s: New file.
	* testsuite/ld-riscv-elf/call-relax-3.s: New file.
	* testsuite/ld-riscv-elf/call-relax.d: New test.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run call-relax test.

Change-Id: Iaf65cee52345abf1955f36e8e72c4f6cc0db8d9a
2019-11-12 15:53:22 -08:00
Alan Modra 595d3787e9 Remove CR16C support
I think it is past time to remove CR16C support.  CR16C was added in
2004, and only for ld.  gas and binutils support is lacking, and there
have been no commits to bfd/elf32-cr16c.c other than warning fixes or
global maintainers making changes to all targets.  I see no maintainer
listed for CR16C, and no commits from anyone at NSC supporting the
target.  Furthermore, at the time the CR16 support was added in 2007,
config.sub was changed upstream to no longer recognise cr16c as a
valid cpu.  That means the CR16C ld support is only available as a
secondary target by configuring with, for example,
--enable-targets=all or --enable-targets=cr16c-unknown-elf.  No
testing of the CR16C target is possible.

include/
	* elf/cr16c.h: Delete.
bfd/
	* cpu-cr16c.c: Delete.
	* elf32-cr16c.c: Delete.
	* Makefile.am,
	* archures.c,
	* config.bfd,
	* configure.ac,
	* reloc.c,
	* targets.c: Remove cr16c support.
	* Makefile.in,
	* bfd-in2.h,
	* configure,
	* libbfd.h,
	* po/SRC-POTFILES.in: Regenerate.
ld/
	* emulparams/elf32cr16c.sh: Delete.
	* scripttempl/elf32cr16c.sc: Delete.
	* Makefile.am,
	* configure.tgt: Remove cr16c support.
	* NEWS: Mention removal of cr16c.
	* Makefile.in,
	* po/BLD-POTFILES.in: Regenerate.
2019-11-07 20:09:20 +10:30
Tim R?hsen 3a70f7e8e3 Fix memory allocation and release problems in the bfd documentation processor.
* doc/chew.c (add_to_definition): Use correct type when
	calculating size of array reallocation.
	(nextword): Always initialise the word return parameter.
	(compile): Check return value of nextword().
2019-11-05 16:03:07 +00:00
Keith Seitz 864619bb2e Add the ability to the BFD library to read build-ids from core flies.
* elf-bfd.h (elf_backend_data) <elf_backend_core_find_build_id>:
	New field.
	(_bfd_elf32_core_find_build_id, _bfd_elf64_core_find_build_id):
	New functions.
	(elf_read_notes): Add declaration.
	* elf.c (elf_read_notes): Move elf-bfd.h.
	(_bfd_elf_core_find_build_id): New function.
	(bfd_section_from_phdr): Scan core file PT_LOAD segments for
	build-id if none is known.
	(elf_parse_notes): For core files, scan for notes.
	* elfcore.h (elf_core_file_matches_executable_p): If both
	BFDs have identical build-ids, then they match.
	(_bfd_elf_core_find_build_id): New function.
	* elfxx-target.h (elf_backend_core_find_build_id): Define.
	(elfNN_bed): Add elf_backend_core_find_build_id.
2019-10-30 12:23:16 +00:00
Andrew Eikum 70cf683455 When copying pe format files, copy the dos_message array, rather than re-initiialising it.
* libcoff-in.h (struct pe_tdata): Add dos_message field.
	* libcoff.h: Regenerate.
	* peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Copy the
	dos_message field rather than initialising it.
	(_bfd_XX_bfd_copy_private_bfd_data_common): Copy the dos_message
	field.
	* peicode.h (pe_mkobject): Initialise the dos_message field.
	(pe_mkobject_hook): Copy the dos_message field.
	(pe_bfd_object_p): Copy the dos_message field.
2019-10-29 17:07:03 +00:00
Alan Modra 30fe183248 PR4499, assign file positions assumes segment offsets increasing
This rewrites much of assign_file_positions_for_non_load_sections to
allow objcopy and strip to handle cases like that in PR4499 where
program headers were not in their usual position immediately after the
ELF file header, and PT_LOAD headers were not sorted by paddr.

	PR 4499
include/
	* elf/internal.h (struct elf_segment_map): Delete header_size.
	Add no_sort_lma and idx.
bfd/
	* elf-nacl.c (nacl_modify_segment_map): Set no_sort_lma for all
	PT_LOAD segments.
	* elf32-spu.c (spu_elf_modify_segment_map): Likewise on overlay
	PT_LOAD segments.
	* elf.c (elf_sort_segments): New function.
	(assign_file_positions_except_relocs): Use shortcuts to elfheader
	and elf_tdata.  Seek to e_phoff not sizeof_ehdr to write program
	headers.  Move PT_PHDR check..
	(assign_file_positions_for_non_load_sections): ..and code setting
	PT_PHDR p_vaddr and p_paddr, and code setting __ehdr_start value..
	(assign_file_positions_for_load_sections): ..to here.  Sort
	PT_LOAD headers.  Delete header_pad code.  Use actual number of
	headers rather than allocated in calculating size for program
	headers.  Don't assume program headers follow ELF file header.
	Simplify pt_load_count code.  Only set "off" for PT_LOAD or
	PT_NOTE in cores.
	(rewrite_elf_program_header): Set p_vaddr_offset for segments
	that include file and program headers.
	(copy_elf_program_header): Likewise, replacing header_size code.
2019-10-25 13:30:05 +10:30
Alan Modra 95cc7c169c ar P support
This patch extends "ar P" to allow creation of normal (as distinct
from thin) archives with full path names.

	PR 452
	PR 25104
bfd/
	* archive.c (normalize): Return file unchanged when
	BFD_ARCHIVE_FULL_PATH.
	(_bfd_construct_extended_name_table): Pass abfd, the output
	bfd, to normalize.
	(_bfd_archive_bsd44_construct_extended_name_table): Likewise.
	* bfd.c (struct bfd): Make flags a full flagword.
	(BFD_ARCHIVE_FULL_PATH): Define.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c (write_archive): Set BFD_ARCHIVE_FULL_PATH.
	* doc/binutils.texi (extract from archive): Mention
	restrictions when extracting from archives with full paths.
	(ar P): Update to current P support.
	(ar -X32_64): Fix spelling.
2019-10-21 16:13:39 +10:30
John David Anglin 2c9e9550ca [bfd] Provide 8-byte minimum alignment for .plt section
This change increases the default alignment for the .plt section
	from 4 bytes to 8 bytes.  When function descriptors are 8-byte
	aligned, they can be updated atomically on 32-bit hppa.  This
	helps with ordering issues on SMP machines.  It also ensures
	that descriptors reside on the same cache line.  This reduces
	the probability of a double TLB miss in a call.

	2019-10-20  John David Anglin  <danglin@gcc.gnu.org>

		* elf32-hppa.c (elf32_hppa_size_dynamic_sections): Provide 8-byte
		minimum alignment for .plt section.
2019-10-20 12:01:58 -04:00
John David Anglin 18338fcee6 [bfd] Revise import stubs on hppa.
This commit updates the import stubs to leave the pointer to the
	function descriptor in register %r22.  This provides a backup
	mechanism for _dl_runtime_resolve to fixup descriptors during
	lazy binding.

	bfd/ChangeLog
	2019-10-19  John David Anglin  <danglin@gcc.gnu.org>

		* elf32-hppa.c: Revise import stub sequences.
		(LONG_BRANCH_STUB_SIZE): Define.
		(LONG_BRANCH_SHARED_STUB_SIZE): Define.
		(IMPORT_STUB_SIZE): Define.
		(IMPORT_SHARED_STUB_SIZE): Define.
		(EXPORT_STUB_SIZE): Define.
		(plt_stub): Revise to not use register %r22.
		(LDO_R1_R22): Define.
		(LDW_R22_R21): Define.
		(LDW_R22_R19): Define.
		(hppa_build_one_stub): Update stub generation and use new defines.
		(hppa_size_one_stub): Likewise.
2019-10-19 13:52:23 -04:00
Jim Wilson 330a6637a5 RISC-V: Report unresolved relocation error via linker's callback function.
Two patches from Nelson Chu.

It is better to use the linker's callback functions to handle the link time
error when relocating.  The unresolved relocation error can be regarded as
an unsupported relocation.  To make user easier to understand different errors,
we need to extend the current error message format of the callback function
since the format is fixed.

	bfd/
	* elfnn-riscv.c (riscv_elf_relocate_section): Use asprintf to extend
	the error message if needed, and then store the result into the
	`msg_buf`.  Finally, remember to free the unused `msg_buf`.  All error
	message for the dangerous relocation should be set before we call the
	callback function.  If we miss the error message since linker runs out
	of memory, we should set the default error message for the error.

	ld/
	* testsuite/ld-riscv-elf/lib-nopic-01a.s: Create the shared library
	lib-nopic-01a.so, it will be linked with lib-nopic-01b.s.
	* testsuite/ld-riscv-elf/lib-nopic-01b.s: Add new test for the
	unresolved relocation.  Link the non-pic code into a shared library
	may cause the error.
	* testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run the new test only when
	the shared library is supported.

R_RISCV_CALL, R_RISCV_JAL and R_RISCV_RVC_JUMP are pc-relative relocation.
For now, we do not allow the object with these relocation links into a shared
library since the referenced symbols may be loaded to the places that too far
from the pc.  We can improve the error message for these unsupported relocation
to notice user that they should recompile their code with `fPIC`.

	bfd/
	* elfnn-riscv.c (riscv_elf_relocate_section): Report the error message
	that user should recompile their code with `fPIC` when linking non-pic
	code into shared library.

	ld/
	* testsuite/ld-riscv-elf/lib-nopic-01b.d: Update the error message.

Change-Id: Ib3347a0a6fa1c2b20a9647c314d5bec2c322ff04
2019-10-17 15:38:27 -07:00
Alan Modra 22216541c1 PR13616, linker should pad executable sections with nops, not zeros
This implements padding of orphan executable sections for PowerPC.
Of course, the simple implementation of bfd_arch_ppc_nop_fill and
removing the NOP definition didn't work, with powerpc64 hitting a
testsuite failure linking to S-records.  That's because the srec
target is BFD_ENDIAN_UNKNOWN so the test of bfd_big_endian (abfd) in
default_data_link_order therefore returned false, resulting in a
little-endian nop pattern.  The rest of the patch fixes that problem
by adding a new field to bfd_link_info that can be used to determine
actual endianness on targets like srec.

	PR 13616
include/
	* bfdlink.h (struct bfd_link_info <big_endian>): New field.
bfd/
	* cpu-powerpc.c (bfd_arch_ppc_nop_fill): New function, use it
	for all ppc arch info.
	* linker.c (default_data_link_order): Pass info->big_endian to
	arch_info->fill function.
ld/
	* emulparams/elf64lppc.sh (NOP): Don't define.
	* emulparams/elf64ppc.sh (NOP): Don't define.
	* ldwrite.c (build_link_order): Use link_info.big_endian.  Move
	code determining endian to use for data_statement to..
	* ldemul.c (after_open_default): ..here.  Set link_info.big_endian.
2019-10-16 23:07:27 +10:30
Alan Modra 9b142ddb4a m68hc1x: better arg checking for reloc_warning
* elf32-m68hc1x.c (reloc_warning): Add printf attribute.
	(elf32_m68hc11_relocate_section): Don't use a variable for format
	strings.  Delete some unnecessary xgettext:c-format comments.
2019-10-15 23:25:11 +10:30
Alan Modra 9a73315161 remove more xmalloc in bfd
Also fixes m68hc1x printf arguments which would have bombed when
compiling on a 32-bit host with --enable-64-bit-bfd.

bfd/
	PR 24955
	* elf32-arm.c (set_cmse_veneer_addr_from_implib): Use bfd_malloc
	rather than xmalloc.
	* elf32-m68hc1x.c (reloc_warning): New function.
	(elf32_m68hc11_relocate_section): Use it here.  Cast bfd_vma values
	corresponding to %lx in format strings.
	* elf32-nds32.c (nds32_insertion_sort): Use a stack temporary.
gas/
	* config/tc-nds32.c (nds32_set_section_relocs): Use relocs and n
	parameters rather than equivalent sec->orelocation and
	sec->reloc_count.  Don't sort for n <= 1.  Tidy.
2019-10-15 16:50:32 +10:30
Alan Modra 779f2ae733 PR25100, Compile fails in elf64-ppc.c because of single equal sign instead of double equal for comparison
PR 25100
	* elf64-ppc.c (sfpr_define): Delete dead code that triggered a warning.
2019-10-15 16:01:05 +10:30
Alan Modra ed481f9799 Simplify power of two test
* bfd.c (bfd_check_compression_header): Check for powers of two
	with x == (x & -x).
2019-10-15 16:00:54 +10:30
Alan Modra 47f6ff2f9e qsort: syms.c stab sorting
* syms.c (struct indexentry): Add idx field.
	(cmpindexentry): Final sort on idx.
	(_bfd_stab_section_find_nearest_line): Set idx.
2019-10-14 16:47:13 +10:30
Alan Modra 8025b0554c qsort: dwarf2.c
This patch ensures qsort stability in line and function sorting done
in dwarf2.c.  For the line sequences we make use of an existing field
that isn't used until later, as a monotonic counter for the qsort.

	* dwarf2.c (struct lookup_funcinfo): Add idx field.
	(compare_lookup_funcinfos): Perform final sort on idx.
	(build_lookup_funcinfo_table): Set idx.
	(compare_sequences): Perform final sort on num_lines.
	(build_line_info_table): Set num_lines and line_info_lookup earlier.
	(sort_line_sequences): Set num_lines for sort.
2019-10-14 16:47:13 +10:30
Alan Modra 3a3f4bf76a qsort: elf_link_add_object_symbols weak aliases
This particular sort almost certainly does not need to be stable for
the ELF linker to work correctly.  However it is conceivable that an
unstable sort could affect linker output, and thus different output be
seen with differing qsort implementations.  The argument goes like
this:  Given more than one strong alias symbol of equal section, value,
and size, the aliases will compare equal by elf_sort_symbol and thus
which one is chosen as the "real" symbol to be made dynamic depends on
qsort.  Why would anyone define two symbols at the same address?
Well, sometimes the fact that there are more than one strong alias
symbol is due to linker script symbols like __bss_start being made
dynamic.  This will match the first symbol defined in .bss if it
doesn't have correct size, and forgetting to properly set size and
type of symbols isn't as rare as it should be.

This patch adds some more heuristics to elf_sort_symbol.

	* elflink.c (elf_sort_symbol): Sort on type and name as well.
	(elf_link_add_object_symbols): Style fix.
2019-10-14 16:47:13 +10:30
Alan Modra 48db329734 qsort: elf_sort_sections use of target_index
elf_sort_sections tried to ensure a stable qsort by using target_index
as the final comparison, but target_index hasn't been set by anything
at the time elf_sort_sections was run.  This patch arrange to have
target_index set.

	* elf.c (_bfd_elf_map_sections_to_segments): Init target_index
	for sections about to be sorted.
	(assign_file_positions_for_load_sections): Likewise.
	(elf_sort_sections): Don't bother optimising both TOEND case.
	* elflink.c (bfd_elf_final_link): Reset target_index.
2019-10-14 16:47:13 +10:30
Alan Modra 8c1c5e5de4 qsort: SHF_LINK_ORDER section sort
The linker SHF_LINK_ORDER section sorting had a number of defects.
1) The ordering was by VMA, which won't work with overlays.  LMA is
   better.
2) Zero size sections can result in two sections at the same LMA/VMA.
   When only one of the two sections at the same LMA is zero size,
   that one must be first.
3) Warnings given by elf_get_linked_section_vma won't ever be emitted
   since elf_object_p warns and excludes objects with zero sh_link on
   a SHF_LINK_ORDER section.
4) Section offset was adjusted down rather than up by section
   alignment, possibly creating overlapping sections.
5) Finding the linked section did so the hard way, rather than simply
   using elf_linked_to_section.

	* elflink.c (elf_get_linked_section_vma): Delete.
	(compare_link_order): Use elf_linked_to_section and sort by lma,
	size, and id.
	(elf_fixup_link_order): Use size_t variables where appropriate.
	Make use of elf_linked_to_section.  Formatting.  Properly align
	sections.
2019-10-14 16:47:13 +10:30
Alan Modra dcea6a95d7 qsort issues
qsort isn't guaranteed to be a stable sort, that is, elements
comparing equal according to the comparison function may be reordered
relative to their original ordering.  Of course sometimes you may not
care, but even in those cases it is good to force some ordering
(ie. not have the comparison function return 0) so that linker output
is reproducible over different libc qsort implementations.

One way to make qsort stable (which the glibc manual incorrectly says
is the only way) is to augment the elements being sorted with a
monotonic counter of some kind, and use that counter as the final
arbiter of ordering in the comparison function.

Another way is to set up an array of pointers into the array of
elements, first pointer to first element, second pointer to second
element and so so, and sort the pointer array rather than the element
array.  Final arbiter in the comparison function then is the pointer
difference.  This works well with, for example, the symbol pointers
returned by _bfd_elf_canonicalize_symtab which point into a symbol
array.

This patch fixes a few places where sorting by symbol pointers is
appropriate, and adds comments where qsort stability is a non-issue.

	* elf-strtab.c (strrevcmp): Comment.
	* merge.c (strrevcmp): Likewise.
	* elf64-ppc.c (compare_symbols): Correct final pointer comparison.
	Comment on why comparing pointers ensures a stable sort.
	* elflink.c (struct elf_symbol): Add void* to union.
	(elf_sort_elf_symbol): Ensure a stable sort with pointer comparison.
	(elf_sym_name_compare): Likewise.
	(bfd_elf_match_symbols_in_sections): Style fix.
	(elf_link_sort_cmp1): Comment.
2019-10-14 16:47:12 +10:30
Alan Modra ec9bd0a22d PR24955, libbfd terminating program on out of memory (part2)
PR 24955
	* elflink.c (elf_output_implib): Don't use xmalloc.  Don't ignore
	return value of bfd_alloc2.
	* peXXigen.c (_bfd_XXi_write_codeview_record): Don't use xmalloc.
	* pef.c (bfd_pef_print_symbol): Likewise.  Don't ignore return
	value of bfd_get_section_contents.
	* som.c (som_write_space_strings): Don't use xmalloc.
	(som_write_symbol_strings): Likewise.
2019-10-14 16:47:12 +10:30
Max Filippov e168da45a2 bfd/dwarf2.c: fix assertion failure in comp_unit_hash_info
stash_maybe_enable_info_hash_tables sets
stash->info_hash_status = STASH_INFO_HASH_ON;
regardless of the result of stash_maybe_update_info_hash_tables call. In
case it fails this results in repeated invocation of comp_unit_hash_info
for the same comp unit and assertion failure in this function.

Only set stash->info_hash_status = STASH_INFO_HASH_ON; when
stash_maybe_update_info_hash_tables is successful.

bfd/
2019-10-11  Max Filippov  <jcmvbkbc@gmail.com>

	* dwarf2.c (stash_maybe_enable_info_hash_tables): Only set
	stash->info_hash_status = STASH_INFO_HASH_ON when
	stash_maybe_update_info_hash_tables succeeds.
2019-10-11 09:02:37 -07:00
Alan Modra 336bfbeb18 PR25070, SEGV in function _bfd_dwarf2_find_nearest_line
Evil testcase with two debug info sections, with sizes of 2aaaabac4ec1
and ffffd5555453b140 result in a total size of 1.  Reading the first
section of course overflows the buffer and tramples on other memory.

	PR 25070
	* dwarf2.c (_bfd_dwarf2_slurp_debug_info): Catch overflow of
	total_size calculation.
2019-10-09 13:28:20 +10:30
Alan Modra 063c511bd7 PR25078, stack overflow in function find_abstract_instance
PR 25078
	* dwarf2.c (find_abstract_instance): Delete orig_info_ptr, add
	recur_count.  Error on recur_count reaching 100 rather than
	info_ptr matching orig_info_ptr.  Adjust calls.
2019-10-09 00:20:28 +10:30
Jozef Lawrynowicz c0ea7c52e1 Add support for new functionality in the msp430 backend of GCC.
This functionality will generate a new GNU object attribute for the "data region"
has been added. This object attribute is used
mark whether the compiler has generated code assuming that data could be in the
upper or lower memory regions.

Code which assumes data is always in the lower memory region is incompatible
with code which uses the full memory range for data.

The patch also adds a new assembler directive ".mspabi_attribute" to handle the
existing MSPABI object attributes. GCC will now emit both .gnu_attribute and
.mspabi_attribute directives to indicate what options the source file was
compiled with.

The assembler will now check the values set in these directives against the
options that the it has been invoked with. If there is a discrepancy, the
assembler will exit with an error.

bfd	* elf32-msp430.c (elf32_msp430_merge_mspabi_attributes): Rename to..
	(elf32_msp430_merge_msp430_attributes): Add support for merging the GNU
	object attribute for data region.

binutils* readelf.c (display_msp430_gnu_attribute): New.
	(process_arch_specific): Use msp430 specific handler for GNU
	attributes.

gas	* config/tc-msp430.c (md_parse_option): Set lower_data_region_only to
	FALSE if the data region is set to "upper", "either" or "none".
	(msp430_object_attribute): New.
	(md_pseudo_table): Handle .mspabi_attribute and .gnu_attribute.
	(msp430_md_end): Replace hard-coded attribute values with enums.
	Handle data region object attribute.
	* doc/as.texi: Document MSP430 Data Region object attribute.
	* doc/c-msp430.texi: Document the .mspabi_attribute directive.
	* testsuite/gas/msp430/attr-430-small-bad.d: New test.
	* testsuite/gas/msp430/attr-430-small-bad.l: New test.
	* testsuite/gas/msp430/attr-430-small-good.d: New test.
	* testsuite/gas/msp430/attr-430-small.s: New test.
	* testsuite/gas/msp430/attr-430x-large-any-bad.d: New test.
	* testsuite/gas/msp430/attr-430x-large-any-bad.l: New test.
	* testsuite/gas/msp430/attr-430x-large-any-good.d: New test.
	* testsuite/gas/msp430/attr-430x-large-any.s: New test.
	* testsuite/gas/msp430/attr-430x-large-lower-bad.d: New test.
	* testsuite/gas/msp430/attr-430x-large-lower-bad.l: New test.
	* testsuite/gas/msp430/attr-430x-large-lower-good.d: New test.
	* testsuite/gas/msp430/attr-430x-large-lower.s: New test.
	* testsuite/gas/msp430/msp430.exp: Run new tests.

include	* elf/msp430.h: Add enums for MSPABI and GNU object attribute tag names
	and values.

ld	* testsuite/ld-msp430-elf/attr-gnu-main.s: New test.
	* testsuite/ld-msp430-elf/attr-gnu-obj.s: New test.
	* testsuite/ld-msp430-elf/attr-gnu-region-lower-upper.d: New test.
	* testsuite/ld-msp430-elf/attr-gnu-region-lower.d: New test.
	* testsuite/ld-msp430-elf/attr-gnu-region-upper.d: New test.
	* testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
2019-10-07 16:34:31 +01:00
Alan Modra 93370e8e7b Re: PowerPC PIC vs. DLL TLS issues
A bug crept into commit f749f26eea, which could cause linker
segfaults when creating PIEs.  This patch fixes it.

	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Do allocate
	space for local got non-tls relocs when PIE.
2019-10-07 23:23:21 +10:30
Alan Modra 847d518374 Bogus "final link failed" messages
This patch is a result of noticing messages like the following:
tmpdir/tls32.o: in function `_start':
(.text+0x1c): unresolvable R_PPC_REL24 relocation against symbol `__tls_get_addr_opt'
./ld-new: final link failed: symbol needs debug section which does not exist

The "needs debug section" comes from attempting to use debug info to
find source line information to print the first error message.  That
error isn't of interest to the user, and any previous bfd_error value
which might be of interest is overwritten.  So save and restore
bfd_error around the fancy error reporting code.

That still doesn't leave us with a clean bfd_error.  Now we get
./ld-new: final link failed: nonrepresentable section on output
An unresolvable relocation surely doesn't mean there is some bfd
section that ld doesn't know how to output!  Digging into that showed
a _bfd_elf_section_from_bfd_section failure attempting to find an elf
section correcsponding to ".interp".  So don't go looking for elf
sections on linker created bfd sections.

And then fix the linker testsuite which expected the bogus message..

bfd/
	* elflink.c (elf_fixup_link_order): Don't attempt to find
	an elf_section for linker created bfd sections.
ld/
	* ldmisc.c (vfinfo): Save and restore bfd_error around bfd
	function calls that might set it.
	* testsuite/ld-elf/indirect.exp: Don't expect "nonrepresentable
	section" message.
2019-10-07 13:37:23 +10:30
Alan Modra 7d04a20ae4 PowerPC TLS miscounting PLT for __tls_get_addr
ppc*_elf_tls_optimize decrements the PLT refcount for __tls_get_addr
when a GD or LD sequence can be optimized.  Without tls marker relocs
this must be done when processing the argument setup relocations.
With marker relocs it's better done when processing the marker reloc.
But don't count them both ways.

Seen as "unresolvable R_PPC_REL24 relocation against symbol
`__tls_get_addr_opt'" (and other branch relocs).

	* elf32-ppc.c (ppc_elf_tls_optimize): Don't process R_PPC_TLSLD
	with non-local symbol.  Don't double count __tls_get_addr calls
	with marker relocs.
	* elf64-ppc.c (ppc64_elf_tls_optimize): Likewise.
2019-10-07 13:21:02 +10:30
Alan Modra 9737e8af48 PowerPC section flag tidy
has_tls_get_addr_call is no longer named correctly as the flag is
only set on finding a __tls_get_addr call without tlsld/tlsgd marker
relocations.

	* elf32-ppc.c (nomark_tls_get_addr): Rename from has_tls_get_addr_call
	throughout.
	* elf64-ppc.c (nomark_tls_get_addr): Likewise.
2019-10-07 13:18:32 +10:30
Alan Modra f749f26eea PowerPC PIC vs. DLL TLS issues
1) GOT entries generated for any of the GOT TLS relocations don't need
dynamic relocations for locally defined symbols in PIEs.  In the case
of a tls_index doubleword, the dtpmod entry is known to be 1, and the
dtprel entry is also known at link time and relative.  Similarly,
dtprel and tprel words are known at link time and relative.  (GOT
entries for other than TLS symbols are not relative and thus need
dynamic relocations in PIEs.)
2) Local dynamic TLS code is really only meant for accesses local to
the current binary.  There was a cheapskate test for this before using
the common tlsld_got slot, but the test wasn't exactly correct and
might confuse anyone looking at the code.  The proper test,
SYMBOL_REFERENCES_LOCAL isn't so expensive that it should be avoided.
3) The same cheap test for local syms when optimising TLS sequences
should be SYMBOL_REFERENCES_LOCAL too.

bfd/
	* elf64-ppc.c (ppc64_elf_check_relocs): Move initialisation of vars.
	(ppc64_elf_tls_optimize): Correct is_local condition.
	(allocate_got): Don't reserve dynamic relocations for any of the
	tls got relocs in PIEs when the symbol is local.
	(allocate_dynrelocs): Correct validity test for local sym using
	tlsld_got slot.
	(ppc64_elf_size_dynamic_sections): Don't reserve dynamic relocations
	for any of the tls got relocs in PIEs.
	(ppc64_elf_layout_multitoc): Likewise.
	(ppc64_elf_relocate_section): Correct validity test for local sym
	using tlsld_got slot.  Don't emit dynamic relocations for any of
	the tls got relocs in PIEs when the symbol is local.
	* elf32-ppc.c (ppc_elf_tls_optimize): Correct is_local condition.
	(got_relocs_needed): Delete.
	(allocate_dynrelocs): Correct validity test for local sym using
	tlsld_got slot.  Don't reserve dynamic relocations for any of the
	tls got relocs in PIEs when the symbol is local.
	(ppc_elf_size_dynamic_sections): Don't reserve dynamic relocations
	for any of the tls got relocs in PIEs.
	(ppc_elf_relocate_section): Correct validity test for local sym
	using tlsld_got slot.  Don't emit dynamic relocations for any of
	the tls got relocs in PIEs when the symbol is local.
ld/
	* testsuite/ld-powerpc/tlsso.d: Adjust to suit tlsld_got usage change.
	* testsuite/ld-powerpc/tlsso.g: Likewise.
	* testsuite/ld-powerpc/tlsso.r: Likewise.
	* testsuite/ld-powerpc/tlsso32.d: Likewise.
	* testsuite/ld-powerpc/tlsso32.g: Likewise.
	* testsuite/ld-powerpc/tlsso32.r: Likewise.
2019-10-04 22:53:56 +09:30
Szabolcs Nagy 9cb09e33e0 [PR ld/22263][PR ld/25056] arm: Avoid dynamic TLS relocs in PIE
Dynamic relocs are only needed in an executable for TLS symbols if
those are defined in an external module and even then TLS access
can be relaxed to use IE model instead of GD.

Several bfd_link_pic checks are turned into bfd_link_dll checks
to fix TLS handling in PIE, for the same fix some other targets
used !bfd_link_executable checks, but that includes relocatable
objects so dll seems safer (in most cases either should work, since
dynamic relocations are not applied in relocatable objects).

On arm* fixes
FAIL: Build pr22263-1

bfd/

	PR ld/22263
	PR ld/25056
	* elf32-arm.c (elf32_arm_tls_transition): Use bfd_link_dll instead of
	bfd_link_pic for TLS checks.
	(elf32_arm_final_link_relocate): Likewise.
	(allocate_dynrelocs_for_symbol): Likewise.
2019-10-04 10:57:00 +01:00
Szabolcs Nagy b627f56244 [PR ld/25062] arm: sign extend the addend of R_ARM_TLS_GOTDESC
On 64-bit host the 32-bit addend was loaded without sign extension into
an unsigned long.

bfd/ChangeLog:

	PR ld/25062
	* elf32-arm.c (elf32_arm_final_link_relocate): Sign extend data.

ld/ChangeLog:

	PR ld/25062
	* testsuite/ld-arm/arm-elf.exp: Update.
	* testsuite/ld-arm/tls-gdesc-neg.d: New test.
	* testsuite/ld-arm/tls-gdesc-neg.s: New test.
2019-10-04 10:54:16 +01:00
Nick Alcock 1ff6de0312 bfd, ld: add CTF section linking
This is quite complicated because the CTF section's contents depend on
the final contents of the symtab and strtab, because it has two sections
whose contents are shuffled to be in 1:1 correspondence with the symtab,
and an internal strtab that gets deduplicated against the ELF strtab
(with offsets adjusted to point into the ELF strtab instead).  It is
also compressed if large enough, so its size depends on its contents!

So we cannot construct it as early as most sections: we cannot even
*begin* construction until after the symtab and strtab are finalized.
Thankfully there is already one section treated similarly: compressed
debugging sections: the only differences are that compressed debugging
sections have extra handling to deal with their changing name if
compressed (CTF sections are always called ".ctf" for now, though we
have reserved ".ctf.*" against future use), and that compressed
debugging sections have previously-uncompressed content which has to be
stashed away for later compression, while CTF sections have no content
at all until we generate it (very late).

BFD also cannot do the link itself: libctf knows how to do it, and BFD
cannot call libctf directly because libctf already depends on bfd for
file I/O.  So we have to use a pair of callbacks, one, examine_strtab,
which allows a caller to examine the symtab and strtab after
finalization (called from elf_link_swap_symbols_out(), right before the
symtabs are written, and after the strtab has been finalized), and one
which actually does the emission (called emit_ctf simply because it is
grouped with a bunch of section-specific late-emission function calls at
the bottom of bfd_elf_final_link, and a section-specific name seems best
for that).  emit_ctf is actually called *twice*: once from lang_process
if the emulation suggests that this bfd target does not examine the
symtab or strtab, and once via a bfd callback if it does.  (This means
that non-ELF targets still get CTF emitted, even though the late CTF
emission stage is never called for them).

v2: merged with non-ELF support patch: slight commit message
    adjustments.
v3: do not spend time merging CTF, or crash, if the CTF section is
    explicitly discarded.  Do not try to merge or compress CTF unless
    linking.
v4: add CTF_COMPRESSION_THRESHOLD.  Annul the freed input ctf_file_t's
    after writeout: set SEC_IN_MEMORY on the output contents so a future
    bfd enhancement knows it could free it.  Add SEC_LINKER_CREATED |
    SEC_KEEP to avoid having to add .ctf to the linker script.  Drop
    now-unnecessary ldlang.h-level elf-bfd.h include and hackery around
    it.  Adapt to elf32.em->elf.em and elf-generic.em->ldelf*.c
    changes.
v5: fix tabdamage.  Drop #inclusions in .h files: include in .c files,
    .em files, and use struct forwards instead.  Use bfd_section_is_ctf
    inline function rather than SECTION_IS_CTF macro.  Move a few
    comments.

	* Makefile.def (dependencies): all-ld depends on all-libctf.
	* Makefile.in: Regenerated.

include/
	* bfdlink.h (elf_strtab_hash): New forward.
	(elf_sym_strtab): Likewise.
	(struct bfd_link_callbacks <examine_strtab>): New.
	(struct bfd_link_callbacks <emit_ctf>): Likewise.

bfd/
	* elf-bfd.h (bfd_section_is_ctf): New inline function.
	* elf.c (special_sections_c): Add ".ctf".
	(assign_file_positions_for_non_load_sections): Note that
	compressed debugging sections etc are not assigned here.  Treat
	CTF sections like SEC_ELF_COMPRESS sections when is_linker_output:
	sh_offset -1.
	(assign_file_positions_except_relocs): Likewise.
	(find_section_in_list): Note that debugging and CTF sections, as
	well as reloc sections, are assigned later.
	(_bfd_elf_assign_file_positions_for_non_load): CTF sections get
	their size and contents updated.
	(_bfd_elf_set_section_contents): Skip CTF sections: unlike
	compressed sections, they have no uncompressed content to copy at
	this stage.
	* elflink.c (elf_link_swap_symbols_out): Call the examine_strtab
	callback right before the strtab is written out.
	(bfd_elf_final_link): Don't cache the section contents of CTF
	sections: they are not populated yet.  Call the emit_ctf callback
	right at the end, after all the symbols and strings are flushed
	out.

ld/
	* ldlang.h: (struct lang_input_statement_struct): Add the_ctf.
	(struct elf_sym_strtab): Add forward.
	(struct elf_strtab_hash): Likewise.
	(ldlang_ctf_apply_strsym): Declare.
	(ldlang_write_ctf_late): Likewise.
	* ldemul.h (ldemul_emit_ctf_early): New.
	(ldemul_examine_strtab_for_ctf): Likewise.
	(ld_emulation_xfer_type) <emit_ctf_early>: Likewise.
	(ld_emulation_xfer_type) <examine_strtab_for_ctf>: Likewise.
	* ldemul.c (ldemul_emit_ctf_early): New.
	(ldemul_examine_strtab_for_ctf): Likewise.
	* ldlang.c: Include ctf-api.h.
	(CTF_COMPRESSION_THRESHOLD): New.
	(ctf_output): New. Initialized in...
	(ldlang_open_ctf): ... this new function.  Open all the CTF
	sections in the input files: mark them non-loaded and empty
	so as not to copy their contents to the output, but linker-created
	so the section gets created in the target.
	(ldlang_merge_ctf): New, merge types via ctf_link_add_ctf and
	ctf_link.
	(ldlang_ctf_apply_strsym): New, an examine_strtab callback: wrap
	ldemul_examine_strtab_for_ctf.
	(lang_write_ctf): New, write out the CTF section.
	(ldlang_write_ctf_late): New, late call via bfd's emit_ctf hook.
	(lang_process): Call ldlang_open_ctf, ldlang_merge_ctf, and
	lang_write_ctf.
	* ldmain.c (link_callbacks): Add ldlang_ctf_apply_strsym,
	ldlang_write_ctf_late.
	* emultempl/aix.em: Add ctf-api.h.
	* emultempl/armcoff.em: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/elf.em: Likewise.
	* emultempl/generic.em: Likewise.
	* emultempl/linux.em: Likewise.
	* emultempl/msp430.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ticoff.em: Likewise.
	* emultempl/vanilla.em: Likewise.
	* ldcref.c: Likewise.
	* ldctor.c: Likewise.
	* ldelf.c: Likewise.
	* ldelfgen.c: Likewise.
	* ldemul.c: Likewise.
	* ldexp.c: Likewise.
	* ldfile.c: Likewise.
	* ldgram.c: Likewise.
	* ldlex.l: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* ldver.c: Likewise.
	* ldwrite.c: Likewise.
	* lexsup.c: Likewise.
	* mri.c: Likewise.
	* pe-dll.c: Likewise.
	* plugin.c: Likewise.

	* ldelfgen.c (ldelf_emit_ctf_early): New.
	(ldelf_examine_strtab_for_ctf): tell libctf about the symtab and
	strtab.
	(struct ctf_strsym_iter_cb_arg): New, state to do so.
	(ldelf_ctf_strtab_iter_cb): New: tell libctf about
	each string in the strtab in turn.
	(ldelf_ctf_symbols_iter_cb): New, tell libctf
	about each symbol in the symtab in turn.
	* ldelfgen.h (struct elf_sym_strtab): Add forward.
	(struct elf_strtab_hash): Likewise.
	(struct ctf_file): Likewise.
	(ldelf_emit_ctf_early): Declare.
	(ldelf_examine_strtab_for_ctf): Likewise.
	* emultempl/elf-generic.em (LDEMUL_EMIT_CTF_EARLY): Set it.
	(LDEMUL_EXAMINE_STRTAB_FOR_CTF): Likewise.
	* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
	emit_ctf_early and examine_strtab_for_ctf, NULL by default.
	* emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/linux.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/vanilla.em (ld_vanilla_emulation): Likewise.

	* Makefile.am: Pull in libctf (and zlib, a transitive requirement
	for compressed CTF section emission).  Pass it on to DejaGNU.
	* configure.ac: Add AM_ZLIB.
	* aclocal.m4: Added zlib.m4.
	* Makefile.in: Regenerated.
	* testsuite/ld-bootstrap/bootstrap.exp: Use it when relinking ld.
2019-10-03 17:04:56 +01:00
Nick Alcock 22ccb84954 bfd: new functions for getting strings out of a strtab
The CTF linking process wants to deduplicate the CTF strtab against the
ELF strtab, for which it needs to know the number of strings in the
strtab and it needs to be able to extract them one by one.

The BFD strtab functions only support returning the
size-or-section-length of the strtab (with _bfd_elf_strtab_size)
and returning the offset (but not string!) and decrementing the refcount
at the same time.

So add new functions _bfd_elf_strtab_len (that just returns the length
in strings of the strtab, never the section size) and bfd_elf_strtab_str
(which returns the string at a given strtab index, and its offset,
without touching the refcount).

It is probably a mistake to use _bfd_elf_strtab_str in particular before
_bfd_elf_strtab_finalize is called, and will not produce useful output
if you do so.

v5: fix tabdamage.

bfd/
	* elf-strtab.c (_bfd_elf_strtab_len): New.
	(_bfd_elf_strtab_str): Likewise.
	* bfd-elf.h: Declare them.
2019-10-03 17:04:55 +01:00
Nick Alcock 6d5944fca6 libctf, bfd: fix ctf_bfdopen_ctfsect opening symbol and string sections
The code in ctf_bfdopen_ctfsect (which is the ultimate place where you
end up if you use ctf_open to open a CTF file and pull in the ELF string
and symbol tables) was written before it was possible to actually test
it, since the linker was not written.  Now it is, it turns out that the
previous code was completely nonfunctional: it assumed that you could
load the symbol table via bfd_section_from_elf_index (...,elf_onesymtab())
and the string table via bfd_section_from_elf_index on the sh_link.

Unfortunately BFD loads neither of these sections in the conventional
fashion it uses for most others: the symbol table is immediately
converted into internal form (which is useless for our purposes, since
we also have to work in the absence of BFD for readelf, etc) and the
string table is loaded specially via bfd_elf_get_str_section which is
private to bfd/elf.c.

So make this function public, export it in elf-bfd.h, and use it from
libctf, which does something similar to what bfd_elf_sym_name and
bfd_elf_string_from_elf_section do.  Similarly, load the symbol table
manually using bfd_elf_get_elf_syms and throw away the internal form
it generates for us (we never use it).

BFD allocates the strtab for us via bfd_alloc, so we can leave BFD to
deallocate it: we allocate the symbol table ourselves before calling
bfd_elf_get_elf_syms, so we still have to free it.

Also change the rules around what you are allowed to provide: It is
useful to provide a string section but no symbol table, because CTF
sections can legitimately have no function info or data object sections
while relying on the ELF strtab for some of their strings.  So allow
that combination.

v4: adjust to upstream changes.  ctf_bfdopen_ctfsect's first parameter
    is potentially unused again (if BFD is not in use for this link
    due to not supporting an ELF target).
v5: fix tabdamage.

bfd/
	* elf-bfd.h (bfd_elf_get_str_section): Add.
	* elf.c (bfd_elf_get_str_section): No longer static.

libctf/
	* ctf-open-bfd.c: Add <assert.h>.
	(ctf_bfdopen_ctfsect): Open string and symbol tables using
	techniques borrowed from bfd_elf_sym_name.
	(ctf_new_archive_internal): Improve comment.
	* ctf-archive.c (ctf_arc_close): Do not free the ctfi_strsect.
	* ctf-open.c (ctf_bufopen): Allow opening with a string section but
	no symbol section, but not vice versa.
2019-10-03 17:04:55 +01:00
Alan Modra 41f37a6fb7 PR24262, plugin search dir doesn't respect --libdir
bfd/
	PR 24262
	* Makefile.am (AM_CPPFLAGS): Add -DLIBDIR.
	* plugin.c (load_plugin): Search both ${libdir}/bfd-plugins and
	${bindir}/../lib/bfd-plugins if different.
	* Makefile.in: Regenerate.
ld/
	PR 24262
	* ld.texi (-plugin): Revert 2019-03-15 change.
2019-09-26 19:51:18 +09:30
Alan Modra ec73ddcd43 PowerPC64 dynamic symbol tweaks
In check_relocs, bfd_link_pic true means ld is producing a shared
library or a position independent executable.  !bfd_link_pic means a
fixed position (ie. static) executable since the relocatable linking
case is excluded.  So it is appropriate to continue using bfd_link_pic
when testing whether non-pcrelative relocations should be dynamic, and
!bfd_link_pic for the special case of ifunc in static executables.
However, -Bsymbolic shouldn't affect PIEs (they are executables so
none of their symbols should be overridden) and PIEs can support copy
relocations, thus bfd_link_executable should be used in those cases
rather than bfd_link_pic.

I've also removed the test of ELIMINATE_COPY_RELOCS in check_relocs.
We can sort out what to do regarding copy relocs later, which allows
the code in check_relocs to be simplified.

	* elf64-ppc.c (ppc64_elf_check_relocs): Use bfd_link_executable
	in choosing between different actions for shared library and
	non-shared library cases.  Delete ELIMINATE_COPY_RELOCS test.
	(dec_dynrel_count): Likewise.  Account for ifunc special case.
	(ppc64_elf_adjust_dynamic_symbol): Copy relocs are for executables,
	not non-pic.
	(allocate_dynrelocs): Comment fixes.  Delete ELIMINATE_COPY_RELOCS
	test.
2019-09-23 23:49:25 +09:30
Alan Modra b06252c2b1 bfd Makefile update
* Makefile.am (SOURCE_HFILES): Add many missing .h files.
	* Makefile.in: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
2019-09-23 10:27:22 +09:30
Alan Modra 640197ac27 linker bfd.h tidy
bfd/
	* bfd-in.h (bfd_symbol, bfd_section_already_linked),
	(bfd_elf_version_tree): Delete forward declarations.
	Move other forward decls and remaining elf function decl later.
	(bfd_section_already_linked_table_init),
	(bfd_section_already_linked_table_free),
	(_bfd_handle_already_linked, _bfd_nearby_section),
	(_bfd_fix_excluded_sec_syms): Move to bfdlink.h.
include/
	* bfdlink.h (struct bfd_section_already_linked): Forward declare.
	(bfd_section_already_linked_table_init),
	(bfd_section_already_linked_table_free),
	(_bfd_handle_already_linked, _bfd_nearby_section),
	(_bfd_fix_excluded_sec_syms): Declare.
2019-09-23 10:27:22 +09:30
Alan Modra 0ba9378a2a ecoff bfd.h tidy
bfd/
	* bfd-in.h: Move ecoff function declarations..
	* ecoff-bfd.h: ..to here, new file.
	* ecoff.c: Include ecoff-bfd.h.
	* ecofflink.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elfxx-mips.c: Likewise.
	* bfd-in2.h: Regenerate.
gas/
	* config/obj-ecoff.c: Include ecoff-bfd.h.
	* config/obj-elf.c: Likewise.
2019-09-23 10:27:22 +09:30
Alan Modra 0b4453c791 elf bfd.h tidy
bfd/
	* bfd-in.h (enum notice_asneeded_action): Move to bfdlink.h.
	Move most other elf declarations..
	* elf-bfd.h: ..to here.
	* bfd-in2.h: Regenerate.
include/
	* bfdlink.h (enum notice_asneeded_action): Define.
ld/
	* deffilep.y: Include bfdlink.h.
	* ldelf.c: Likewise.
	* ldelfgen.c: Likewise.
	* ldver.c: Likewise.
	* mri.c: Likewise.
	* emultempl/irix.em: Don't include ld.h, ldmain.h, libiberty.h.
	Comment.
2019-09-23 10:27:22 +09:30
Alan Modra f5c5b7c124 m68k bfd.h tidy
bfd/
	* bfd-in.h: Move m68k function declaration..
	* cpu-m68k.h: ..to here, new file..
	* elf32-m68k.h: ..and here, new file.
	* elf32-m68k.c: Include cpu-m68k.h and elf32-m68k.h.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/m68kelf.em: Include elf32-m68k.h.
opcodes/
	* m68k-dis.c: Include cpu-m68k.h
2019-09-23 10:27:22 +09:30
Alan Modra 8410a6589d bfin bfd.h tidy
bfd/
	* bfd-in.h: Move bfin function declaration..
	* elf32-bfin.h: ..to here, new file.
	* elf32-bfin.c: Include elf32-bfin.h.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/bfin.em: Include elf32-bfin.h.
2019-09-23 10:27:21 +09:30
Alan Modra ca05ca5e2d cr16 bfd.h tidy
bfd/
	* bfd-in.h: Move cr16 function declaration..
	* elf32-cr16.h: ..to here, new file.
	* elf32-cr16.c: Include elf32-cr16.h.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/cr16elf.em: Include elf32-cr16.h.
2019-09-23 10:27:21 +09:30
Alan Modra 530f61204c obsoleted bfd.h tidy
* bfd-in.h (bfd_sunos_get_needed_list),
	(bfd_sunos_record_link_assignment),
	(bfd_sunos_size_dynamic_sections),
	(bfd_i386linux_size_dynamic_sections),
	(bfd_sparclinux_size_dynamic_sections): Delete obsolete decls.
	* bfd-in2.h: Regenerate.
2019-09-23 10:27:21 +09:30
Alan Modra 6ea7de3237 xcoff bfd.h tidy
bfd/
	* bfd-in.h: Move xcoff function declarations..
	* xcofflink.h: ..to here, new file.
	* xcofflink.c: Include xcofflink.h.
	* coff-rs6000.c (bfd_xcoff_ar_archive_set_magic): Delete unused func.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/aix.em: Include xcofflink.h.
2019-09-23 10:27:21 +09:30
Alan Modra aa739c59d3 coff bfd.h tidy
bfd/
	* bfd-in.h: Delete coff forward refs and move coff declaration..
	* coff-bfd.h: ..to here.
	* bfd-in2.h: Regenerate.
binutils/
	* dlltool.c: Include coff-bfd.h.
2019-09-23 10:27:21 +09:30
Alan Modra f37164d78b arm bfd.h tidy
bfd/
	* bfd-in.h: Move arm declaraions..
	* cpu-arm.h: ..to here, new file..
	* coff-arm.h: ..and here, new file..
	* elf32-arm.h: ..and here, new file.
	* cpu-arm.c: Include cpu-arm.h.
	* coff-arm.c: Include cpu-arm.h and coff-arm.h.
	* elf32-arm.c: Include cpu-arm.h and elf32-arm.h.
	* pe-arm.c: Move function rename defines later.
	* pe-arm-wince.c: Likewise and include sysdep.h and bfd.h early.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-arm.c: Include cpu-arm.h.
ld/
	* emultempl/armelf.em: Include elf32-arm.h.
	* emultempl/pe.em: Move func defines later and include coff-arm.h.
2019-09-23 10:27:21 +09:30
Alan Modra 79c2ce54e1 tic6x bfd.h tidy
* bfd-in.h: Move tic6x function declaration..
	* elf32-tic6x.h: ..to here.
	* bfd-in2.h: Regenerate.
2019-09-23 10:27:21 +09:30
Alan Modra a8bfaadbb4 aarch64 bfd.h tidy
bfd/
	* bfd-in.h: Move aarch64 declarations and defines..
	* cpu-aarch64.h: ..to here, new file..
	* elfxx-aarch64.h: ..and here.
	* cpu-aarch64.c: Include cpu-aarch64.h.
	* elfnn-aarch64.c: Likewise.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/aarch64elf.em: Include elfxx-aarch64.h.
2019-09-23 10:27:21 +09:30
Alan Modra c348479ddd tic54x bfd.h tidy
* bfd-in.h: Delete ticoff function declarations.
	* coff-tic54x.c (bfd_ticoff_set_section_load_page),
	(bfd_ticoff_get_section_load_page): Make static.
	* bfd-in2.h: Regenerate.
2019-09-23 10:27:21 +09:30
Alan Modra ca437b1b5f h8300 bfd.h tidy
* bfd-in.h: Move h8300 function declaration to..
	* cpu-h8300.h: ..here, new file.
	* cpu-h8300.c: Include cpu-h8300.h.
	* elf32-h8300.c: Likewise.
	* bfd-in2.h: Regenerate.
2019-09-23 10:27:21 +09:30
Alan Modra 3352ae9900 ia64 bfd.h tidy
bfd/
	* bfd-in.h: Move ia64 function declarations..
	* elfxx-ia64.h: ..to here.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/ia64elf.em: Include elfxx-ia64.h.
2019-09-23 10:27:21 +09:30
Alan Modra d48d68b618 v850 bfd.h tidy
bfd/
	* bfd-in.h: Move v850 function declarations..
	* elf32-v850.h: ..to here, new file.
	* elf32-v850.c: Include elf32-v850.h.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/v850elf.em: Include elf32-v850.h.
2019-09-23 10:27:20 +09:30
Alan Modra 7beeaeb8c6 mips bfd.h tidy
bfd/
	* bfd-in.h: Move mips function declaration to..
	* elfxx-mips.h: ..here.
	* bfd-in2.h: Regenerate.
opcodes/
	* mips-dis.c: Include elfxx-mips.h.  Move "elf-bfd.h" and
	"elf/mips.h" earlier.
2019-09-23 10:27:20 +09:30
Alan Modra 6e67e6b05a csky bfd.h tidy
bfd/
	* bfd-in.h: Move csky function declarations to..
	* elf32-csky.h: ..here, new file.
	* elf32-csky.c: Include elf32-csky.h.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/cskyelf.em: Include elf32-csky.h.
2019-09-23 10:27:20 +09:30
Jim Wilson 9d1da81b26 RISC-V: Optimize lui and auipc relaxations for undefweak symbol.
For the lui and auipc relaxations, since the symbol value of an undefined weak
symbol is always be zero, we can optimize the patterns into a single LI/MV/ADDI
instruction.

	bfd/
	* elfnn-riscv.c (riscv_pcgp_hi_reloc): Add new field undefined_weak.
	(riscv_record_pcgp_hi_reloc): New parameter undefined_weak.
	Set undefined_weak field from it.
	(relax_func_t): New parameter undefined_weak.
	(_bfd_riscv_relax_call): New ignored parameter undefined_weak.
	(_bfd_riscv_relax_tls_le): Likewise.
	(_bfd_riscv_relax_align): Likewise.
	(_bfd_riscv_relax_delete): Likewise.
	(_bfd_riscv_relax_lui): New parameter undefined_weak.  If true,
	allow relaxing.  For LO12* relocs, set rs1 to x0 when undefined_weak.
	(_bfd_riscv_relax_pc): New parameter undefined_weak.  For LO12* relocs,
	set undefined_weak from hi_reloc.  If true, allow relaxing.  For LO12*
	relocs, set rs1 to x0 when undefined_weak and change to non-pcrel
	reloc.
	(_bfd_riscv_relax_section): New local undefined_weak.  Set for
	undef weak relocs that can be relaxed.  Pass to relax_func call.

	ld/
	* testsuite/ld-riscv-elf/weakref32.s: Add relaxable undef weak code.
	* testsuite/ld-riscv-elf/weakref64.s: Likewise.
	* testsuite/ld-riscv-elf/weakref32.d: Updated.
	* testsuite/ld-riscv-elf/weakref64.d: Updated.
2019-09-20 15:01:20 -07:00
Alan Modra a48931cc2d bfd macro conversion to inline functions, section
This one exposed a bug in tic6x gas, found with inline function
parameter type checking.  struct bfd_section and struct bfd_symbol
both have a flags field, so bfd_is_com_section (symbol) compiled OK
when bfd_is_com_section was a macro but didn't special case common
symbols.

bfd/
	* bfd-in.h (bfd_section_name, bfd_section_size, bfd_section_vma),
	(bfd_section_lma, bfd_section_alignment, bfd_section_flags),
	(bfd_section_userdata, bfd_is_com_section, discarded_section),
	(bfd_get_section_limit_octets, bfd_get_section_limit): Delete macros.
	* bfd.c (bfd_get_section_limit_octets, bfd_get_section_limit),
	(bfd_section_list_remove, bfd_section_list_append),
	(bfd_section_list_prepend, bfd_section_list_insert_after),
	(bfd_section_list_insert_before, bfd_section_removed_from_list):
	New inline functions.
	* section.c (bfd_is_und_section, bfd_is_abs_section),
	(bfd_is_ind_section, bfd_is_const_section, bfd_section_list_remove),
	(bfd_section_list_append, bfd_section_list_prepend),
	(bfd_section_list_insert_after, bfd_section_list_insert_before),
	(bfd_section_removed_from_list): Delete macros.
	(bfd_section_name, bfd_section_size, bfd_section_vma),
	(bfd_section_lma, bfd_section_alignment, bfd_section_flags),
	(bfd_section_userdata, bfd_is_com_section, bfd_is_und_section),
	(bfd_is_abs_section, bfd_is_ind_section, bfd_is_const_section),
	(discarded_section): New inline functions.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-tic6x.c (tc_gen_reloc): Correct common symbol check.
ld/
	* emultempl/xtensaelf.em (xtensa_get_section_deps): Comment.
	Use bfd_section_userdata.
	(xtensa_set_section_deps): Use bfd_set_section_userdata.
	* ldlang.c (lang_output_section_get): Use bfd_section_userdata.
	(sort_def_symbol): Likewise, and bfd_set_section_userdata.
	(init_os): Use bfd_set_section_userdata.
	(print_all_symbols): Use bfd_section_userdata.
	* ldlang.h (get_userdata): Delete.
2019-09-20 18:04:03 +09:30
Alan Modra af30dc128b bfd macro conversion to inline functions, asymbol
* bfd-in.h (bfd_asymbol_section, bfd_asymbol_value, bfd_asymbol_name),
	(bfd_asymbol_bfd, bfd_asymbol_flavour, bfd_set_asymbol_name): Delete.
	* bfd.c (bfd_asymbol_section, bfd_asymbol_value, bfd_asymbol_name),
	(bfd_asymbol_bfd, bfd_set_asymbol_name): New inline functions.
	* targets.c (bfd_asymbol_flavour): Likewise.
	* bfd-in2.h: Regenerate.
2019-09-20 18:04:02 +09:30
Alan Modra 00f93c4492 bfd macro conversion to inline functions
This converts some of the macros that access struct bfd fields to
inline functions.

bfd/
	* archive.c (bfd_generic_archive_p): Use bfd_set_thin_archive.
	* bfd-in.h (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_target, bfd_get_flavour, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian, bfd_header_little_endian),
	(bfd_get_file_flags, bfd_applicable_file_flags),
	(bfd_applicable_section_flags, bfd_has_map, bfd_is_thin_archive),
	(bfd_valid_reloc_types, bfd_usrdata, bfd_get_start_address),
	(bfd_get_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_get_dynamic_symcount, bfd_get_symbol_leading_char): Delete.
	* bfd/bfd.c (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_file_flags, bfd_get_start_address, bfd_get_symcount),
	(bfd_get_dynamic_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_has_map, bfd_is_thin_archive, bfd_set_thin_archive),
	(bfd_usrdata, bfd_set_usrdata): New inline functions.
	* targets.c (bfd_get_target, bfd_get_flavour),
	(bfd_applicable_file_flags, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian),
	(bfd_header_little_endian, bfd_applicable_section_flags),
	(bfd_get_symbol_leading_char): New inline functions.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c (write_archive): Use bfd_set_thin_archive.
gdb/
	* gdb_bfd.c (gdb_bfd_ref, gdb_bfd_unref): Use bfd_set_usrdata.
	* dwarf2read.c (dwarf2_read_gdb_index, dwarf2_read_debug_names),
	(read_indirect_string_from_dwz): Use bfd accessor.
	* dwarf2read.h (struct dwz_file <filename>): Likewise.
	* machoread.c (macho_symfile_read_all_oso): Likewise.
	* solib.c (solib_bfd_open): Likewise.
ld/
	* ldelf.c (ldelf_after_open, ldelf_place_orphan
	* ldlang.c (walk_wild_file, lang_process): Use bfd_usrdata.
	(load_symbols, ldlang_add_file): Use bfd_set_usrdata.
	* ldmain.c (add_archive_element): Use bfd_usrdata.
	* ldlang.h (bfd_input_just_syms): New inline function.
	* emultempl/aarch64elf.em (build_section_lists): Use it.
	* emultempl/mmo.em (mmo_place_orphan): Likewise.
	* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/ppc64elf.em (build_section_lists): Likewise.
sim/
	* ppc/emul_generic.c (emul_add_tree_options): Delete old bfd code.
2019-09-20 18:04:02 +09:30
Alan Modra e59a100122 PowerPC64, error on unsupported dynamic relocation
This patch corrects the set of dynamic relocations recognised by gold
as supported by glibc, and teaches ld.bfd to report an error similar
to the gold error.  Note that ld --noinhibit-exec can be used to
produce an output, supporting older ld with newer glibc if the set of
supported glibc dynamic relocations changes.

bfd/
	* elf64-ppc.c (ppc64_glibc_dynamic_reloc): New function.
	(ppc64_elf_relocate_section): Error if emitting unsupported
	dynamic relocations.
gold/
	* powerpc.cc (Target_powerpc::Scan::check_non_pic): Move REL24
	to 32-bit supported.
2019-09-20 12:51:19 +09:30
Alan Modra fd3619828e bfd_section_* macros
This large patch removes the unnecessary bfd parameter from various
bfd section macros and functions.  The bfd is hardly ever used and if
needed for the bfd_set_section_* or bfd_rename_section functions can
be found via section->owner except for the com, und, abs, and ind
std_section special sections.  Those sections shouldn't be modified
anyway.

The patch also removes various bfd_get_section_<field> macros,
replacing their use with bfd_section_<field>, and adds
bfd_set_section_lma.  I've also fixed a minor bug in gas where
compressed section renaming was done directly rather than calling
bfd_rename_section.  This would have broken bfd_get_section_by_name
and similar functions, but that hardly mattered at such a late stage
in gas processing.

bfd/
	* bfd-in.h (bfd_get_section_name, bfd_get_section_vma),
	(bfd_get_section_lma, bfd_get_section_alignment),
	(bfd_get_section_size, bfd_get_section_flags),
	(bfd_get_section_userdata): Delete.
	(bfd_section_name, bfd_section_size, bfd_section_vma),
	(bfd_section_lma, bfd_section_alignment): Lose bfd parameter.
	(bfd_section_flags, bfd_section_userdata): New.
	(bfd_is_com_section): Rename parameter.
	* section.c (bfd_set_section_userdata, bfd_set_section_vma),
	(bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section),
	(bfd_set_section_size): Delete bfd parameter, rename section parameter.
	(bfd_set_section_lma): New.
	* bfd-in2.h: Regenerate.
	* mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param,
	update callers.
	* aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c,
	* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
	* compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h,
	* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c,
	* elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c,
	* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
	* elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c,
	* elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c,
	* elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c,
	* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c,
	* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
	* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
	* elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c,
	* elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
	* elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
	* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c,
	* elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
	* elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c,
	* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
	* elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c,
	* elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c,
	* mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c,
	* peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c,
	* xcofflink.c: Update throughout for bfd section macro and function
	changes.
binutils/
	* addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c,
	* objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c,
	* od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c,
	* resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update
	throughout for bfd section macro and function changes.
gas/
	* as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c,
	* read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c,
	* config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c,
	* config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c,
	* config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c,
	* config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c,
	* config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c,
	* config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c,
	* config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c,
	* config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c,
	* config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c,
	* config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c,
	* config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c,
	* config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c,
	* config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c,
	* config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c,
	* config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c,
	* config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c,
	* config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c,
	* config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c,
	* config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c,
	* config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c,
	* config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for
	bfd section macro and function changes.
	* write.c (compress_debug): Use bfd_rename_section.
gdb/
	* aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c,
	* coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c,
	* dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c,
	* exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h,
	* hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c,
	* i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c,
	* maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c,
	* mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c,
	* objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c,
	* ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c,
	* rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c,
	* s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c,
	* solib-spu.c, * solib-svr4.c, * solib-target.c,
	* spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c,
	* symmisc.c, * symtab.c, * target.c, * windows-nat.c,
	* xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c,
	* mi/mi-interp.c: Update throughout for bfd section macro and
	function changes.
	* gcore (gcore_create_callback): Use bfd_set_section_lma.
	* spu-tdep.c (spu_overlay_new_objfile): Likewise.
gprof/
	* corefile.c, * symtab.c: Update throughout for bfd section
	macro and function changes.
ld/
	* ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c,
	* emultempl/aarch64elf.em, * emultempl/aix.em,
	* emultempl/armcoff.em, * emultempl/armelf.em,
	* emultempl/cr16elf.em, * emultempl/cskyelf.em,
	* emultempl/m68hc1xelf.em, * emultempl/m68kelf.em,
	* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
	* emultempl/mmo.em, * emultempl/msp430.em,
	* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
	* emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update
	throughout for bfd section macro and function changes.
libctf/
	* ctf-open-bfd.c: Update throughout for bfd section macro changes.
opcodes/
	* arc-ext.c: Update throughout for bfd section macro changes.
sim/
	* common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c,
	* erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c,
	* m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c,
	* rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c,
	* rx/trace.c: Update throughout for bfd section macro changes.
2019-09-19 09:40:13 +09:30
Alan Modra e6f7f6d14f bfd_asymbol_* macros
The main point of this patch is to give bfd_get_section a better name,
bfd_asymbol_section.

bfd/
	* bfd-in.h (bfd_asymbol_section): Rename from bfd_get_section.
	(bfd_get_output_section): Delete.
	(bfd_asymbol_base): Delete.
	(bfd_asymbol_section, bfd_asymbol_value, bfd_asymbol_name),
	(bfd_asymbol_bfd, bfd_asymbol_flavour): Tidy.
	(bfd_set_asymbol_name): New macro.
	* bfd-in2.h: Regenerate.
	* aout-cris.c: Update throughout to use bfd_asymbol_section.
	* aoutx.h: Likewise.
	* cofflink.c: Likewise.
	* dwarf2.c: Likewise.
	* ecoff.c: Likewise.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-mips.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elfn32-mips.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* linker.c: Likewise.
	* pdp11.c: Likewise.
	* elf64-mmix.c (mmix_elf_reloc): Expand bfd_get_output_section.
binutils/
	* nm.c: Update bfd_get_section to bfd_asymbol_section throughout.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
	* rdcoff.c: Likewise.
	* objcopy.c (create_new_symbol): Use bfd_set_asymbol_name.
	(filter_symbols): Likewise.
gas/
	* symbols.c (S_IS_LOCAL): Update bfd_get_section to
	bfd_asymbol_section.
gdb/
	* arm-tdep.c (arm_record_special_symbol): Update bfd_get_section
	to bfd_asymbol_section.
ld/
	* ldcref.c (check_reloc_refs): Update bfd_get_section to
	bfd_asymbol_section.
2019-09-18 23:07:31 +09:30
Simon Marchi e0b2a78c83 Re-generate many configure and Makefile.in files
I get some spurious changes when running autoconf/automake for various
projects in the tree.  This is likely because they were generated using
distro-patched tools last time.

I ran `autoreconf -f` in the various automake projects of the
binutils-gdb tree, and this is the result.  The tools I am using have
been compiled from source, from the upstream release.

bfd/ChangeLog:

	* Makefile.in: Re-generate.
	* configure: Re-generate.
	* doc/Makefile.in: Re-generate.

binutils/ChangeLog:

	* Makefile.in: Re-generate.
	* configure: Re-generate.
	* doc/Makefile.in: Re-generate.

gas/ChangeLog:

	* Makefile.in: Re-generate.
	* configure: Re-generate.
	* doc/Makefile.in: Re-generate.

gold/ChangeLog:

	* testsuite/Makefile.in: Re-generate.

gprof/ChangeLog:

	* Makefile.in: Re-generate.
	* configure: Re-generate.

ld/ChangeLog:

	* Makefile.in: Re-generate.
	* configure: Re-generate.

opcodes/ChangeLog:

	* Makefile.in: Re-generate.
	* configure: Re-generate.
2019-09-18 09:09:15 -04:00
Alan Modra ed48ec2e6e Don't use bfd_get_* macro to set bfd fields
* aoutx.h (slurp_symbol_table): Don't set symcount using bfd_get
	macros.
	* pdp11.c (slurp_symbol_table): Likewise.
	* som.c (som_slurp_symbol_table): Likewise.
	* coff-ppc.c (ppc_bfd_coff_final_link): Likewise.
	* coffcode.h (coff_slurp_symbol_table): Likewise.
	* cofflink.c (_bfd_coff_final_link): Likewise.
	* ecoff.c (ecoff_slurp_symbolic_header): Likewise.
	(_bfd_ecoff_slurp_symbolic_info): Likewise.
	(_bfd_ecoff_slurp_symbol_table): Likewise.
	(_bfd_ecoff_bfd_final_link): Likewise.
	* elf.c (_bfd_elf_canonicalize_symtab): Likewise.
	* elflink.c (elf_link_output_symstrtab): Likewise.
	(bfd_elf_final_link): Likewise.
	* peicode.h (pe_ILF_build_a_bfd): Likewise.
	* xcofflink.c (_bfd_xcoff_bfd_final_link): Likewise.
	* aoutx.h (some_aout_object_p, slurp_symbol_table): Don't set
	start_address or symcount using bfd_get macros.
	* coffgen.c (coff_real_object_p): Likewise.
	* pdp11.c (some_aout_object_p, slurp_symbol_table): Likewise.
	* som.c (som_object_setup, som_slurp_symbol_table): Likewise.
	* elfcore.h (elf_core_file_p): Don't set start_address using
	bfd_get macro.
	* elf.c (_bfd_elf_canonicalize_dynamic_symtab): Don't set dynsymcount
	using bfd_get macro.
	* bfd.c (bfd_set_file_flags): Don't set flags using bfd_get macro.
	* linker.c (bfd_generic_link_read_symbols): Don't set outsymbols
	or symcount using bfd_get macros.
	(_bfd_generic_final_link, generic_add_output_symbol): Likewise.
	* syms.c (bfd_set_symtab): Likewise.
	* vms-alpha.c (alpha_vms_bfd_final_link): Likewise.
	* archive.c (do_slurp_bsd_armap): Don't set has_armap using
	bfd_has_map macro.
	(do_slurp_coff_armap, bfd_slurp_armap): Likewise.
	* archive64.c (_bfd_archive_64_bit_slurp_armap): Likewise.
	* coff-rs6000.c (_bfd_xcoff_slurp_armap): Likewise.
	* coff64-rs6000.c (xcoff64_slurp_armap): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_armap): Likewise.
	* som.c (som_slurp_armap): Likewise.
2019-09-18 22:21:58 +09:30
Alan Modra 01c2b26160 Constify bfd_octets_per_byte and related functions
* archures.c (bfd_get_arch): Make param const.
	(bfd_get_mach, bfd_arch_bits_per_byte): Likewise.
	(bfd_arch_bits_per_address, bfd_octets_per_byte): Likewise.
	* bfd-in2.h: Regenerate.
2019-09-18 22:20:13 +09:30
Alan Modra 1d38e9d14c Constify target name, reloc name, and carsym name
bfd/
	* bfd-in.h (carsym.name): Make const.
	* reloc.c (struct reloc_howto_struct.name): Likewise.
	* targets.c (bfd_target.name): Likewise.!
	* bfd.c (bfd_get_sign_extend_vma): Make variable const.
	* som.c (som_bfd_fill_in_ar_symbols): Use an intermediary variable
	when setting carsym.name.
	* bfd-in2.h: Regenerate.
gdb/
	* amd64-dicos-tdep.c (amd64_dicos_osabi_sniffer): Constify target.
	* i386-cygwin-tdep.c (i386_cygwin_init_abi): Likewise.
	* i386-dicos-tdep.c (i386_dicos_osabi_sniffer): Likewise.
ld/
	* ldlang.c (stricpy, strcut, name_compare): Constify params.
	(get_first_input_target): Make return and "target" const.
2019-09-18 21:32:51 +09:30
Alan Modra 90d92a632a Use bfd_set_filename more
Fixes a few leaks in bfd and ld.

bfd/
	* mach-o.c (bfd_mach_o_fat_member_init): Likewise.  Replace
	xstrdup and xmalloc with bfd_strdup and bfd_malloc.  Return an
	error status.  Adjust calls.
	* vms-lib.c (_bfd_vms_lib_get_module): Test mhd->id earlier.
	Close bfd on failure.  Replace xstrdup/bfd_alloc use with
	bfd_malloc.  Use bfd_set_filename.
gdb/
	* solib-spu.c (spu_bfd_open): Use bfd_set_filename.
	* spu-linux-nat.c (spu_bfd_open): Likewise.
ld/
	* emultempl/pe.em (after_open): Use bfd_set_filename.
	* emultempl/pep.em (after_open): Use bfd_set_filename.
2019-09-18 21:32:51 +09:30
Alan Modra 1bdd8facfb PowerPC64, support medium model access to common symbols
Some versions of clang apparently generate non-PIC on powerpc64le to
access common symbols.  Since a common symbol and a strong definition
with the same name should resolve to the strong definition we have the
possibility of non-PIC attempting to access shared library variables.
This is really a clanger since powerpc64le is supposed to be PIC by
default, but let's see if ld can cope by generating .dynbss copies.

	* elf64-ppc.c (must_be_dyn_reloc): Return 0 for TOC16 relocs.
	(ppc64_elf_check_relocs): Support dynamic/copy relocs for TOC16.
	(ppc64_elf_adjust_dynamic_symbol): Don't keep dynamic reloc when
	needs_copy even if all relocs are in rw sections.
	(dec_dynrel_count): Handle TOC16 relocs.
	(ppc64_elf_relocate_section): Support dynamic relocs for TOC16.
	(ppc64_elf_finish_dynamic_symbol): Adjust to handle needs_copy
	semantic change.
2019-09-18 21:32:51 +09:30
Phil Blundell bb6959602b Update version to 2.33.50 and regenerate configure scripts. 2019-09-16 11:03:53 +01:00
Tom Tromey 64b2d4a0a4 Introduce bfd_set_filename
This introduces a new bfd_set_filename function, which is then used in
various spots in gdb.  This allows for the removal of some casts.

bfd/ChangeLog
2019-09-11  Tom Tromey  <tom@tromey.com>

	* opncls.c (bfd_set_filename): New function.
	* bfd-in2.h: Regenerate.

gdb/ChangeLog
2019-09-11  Tom Tromey  <tom@tromey.com>

	* symfile-mem.c (symbol_file_add_from_memory): Use
	bfd_set_filename.
	* solib-darwin.c (darwin_bfd_open): Use bfd_set_filename.
	* solib-aix.c (solib_aix_bfd_open): Use bfd_set_filename.
2019-09-11 07:02:46 -06:00
Alan Modra cb7f4b298e Tidy ld/ldmisc.c
The idea here is to not use elf-bfd.h and coff-bfd.h in generic linker
code.

bfd/
	* targets.c (struct bfd_target): Add _bfd_group_name.
	(BFD_JUMP_TABLE): Likewise.
	* coffgen.c (bfd_coff_group_name): New function.
	* elf.c (bfd_elf_group_name): New function.
	* linker.c (_bfd_nolink_bfd_group_name): New function.
	* section.c (bfd_generic_group_name): New function.
	* elf-bfd.h (bfd_elf_group_name): Declare.
	* libbfd-in.h (_bfd_nolink_bfd_group_name): Declare.
	* libcoff-in.h (bfd_coff_group_name): Declare.
	* aout-target.h (MY_bfd_group_name): Define.
	* aout-tic30.c (MY_bfd_group_name): Define.
	* bfd.c (bfd_group_name): Define.
	* binary.c (binary_bfd_group_name): Define.
	* coff-alpha.c (_bfd_ecoff_bfd_group_name): Define.
	* coff-mips.c (_bfd_ecoff_bfd_group_name): Define.
	* coff-rs6000.c (_bfd_xcoff_bfd_group_name): Define.
	* coffcode.h (coff_bfd_group_name): Define.
	* elfxx-target.h (bfd_elfNN_bfd_group_name): Define.
	* i386msdos.c (msdos_bfd_group_name): Define.
	* ihex.c (ihex_bfd_group_name): Define.
	* mach-o-target.c (bfd_mach_o_bfd_group_name): Define.
	* mmo.c (mmo_bfd_group_name): Define.
	* pef.c (bfd_pef_bfd_group_name): Define.
	* plugin.c (bfd_plugin_bfd_group_name): Define.
	* ppcboot.c (ppcboot_bfd_group_name): Define.
	* som.c (som_bfd_group_name): Define.
	* srec.c (srec_bfd_group_name): Define.
	* tekhex.c (tekhex_bfd_group_name): Define.
	* verilog.c (verilog_bfd_group_name): Define.
	* vms-alpha.c (vms_bfd_group_name, alpha_vms_bfd_group_name): Define.
	* xsym.c (bfd_sym_bfd_group_name): Define.
	* coff64-rs6000.c (rs6000_xcoff64_vec): Init new field.
	(rs6000_xcoff64_aix_vec): Likewise.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* libcoff.h: Regenerate.
ld/
	* ldmisc.c: Don't #include elf-bfd.h or coff-bfd.h.
	(vfinfo): Use bfd_group_name.
2019-09-11 13:43:29 +09:30
Nick Clifton aebcfb76fc Enhance the disassembler so that it will reliably determine whether a reloc applies to the middle of the next insn.
PR 24907
binutils* objdump.c (null_print): New function.
	(disassemble_bytes): Delete previous_octets local and replace with
	a test of the max_reloc_offset_into_insn field of the
	bfd_arch_info structure.  If a reloc is a potential match for the
	next insn, then perform a dummy disassembly in order to calculate
	its real length.

bfd	* archures.c (bfd_arch_info_type): Add max_reloc_offset_into_insn
	field.
	(bfd_default_arch_struct): Initialise the new field.
	* bfd-in2.h: Regenerate.
	* cpu-aarch64.c: Initialise the new field.
	* cpu-alpha.c: Likewise.
	* cpu-arc.c: Likewise.
	* cpu-arm.c: Likewise.
	* cpu-avr.c: Likewise.
	* cpu-bfin.c: Likewise.
	* cpu-bpf.c: Likewise.
	* cpu-cr16.c: Likewise.
	* cpu-cr16c.c: Likewise.
	* cpu-cris.c: Likewise.
	* cpu-crx.c: Likewise.
	* cpu-csky.c: Likewise.
	* cpu-d10v.c: Likewise.
	* cpu-d30v.c: Likewise.
	* cpu-dlx.c: Likewise.
	* cpu-epiphany.c: Likewise.
	* cpu-fr30.c: Likewise.
	* cpu-frv.c: Likewise.
	* cpu-ft32.c: Likewise.
	* cpu-h8300.c: Likewise.
	* cpu-hppa.c: Likewise.
	* cpu-i386.c: Likewise.
	* cpu-ia64.c: Likewise.
	* cpu-iamcu.c: Likewise.
	* cpu-ip2k.c: Likewise.
	* cpu-iq2000.c: Likewise.
	* cpu-k1om.c: Likewise.
	* cpu-l1om.c: Likewise.
	* cpu-lm32.c: Likewise.
	* cpu-m10200.c: Likewise.
	* cpu-m10300.c: Likewise.
	* cpu-m32c.c: Likewise.
	* cpu-m32r.c: Likewise.
	* cpu-m68hc11.c: Likewise.
	* cpu-m68hc12.c: Likewise.
	* cpu-m68k.c: Likewise.
	* cpu-m9s12x.c: Likewise.
	* cpu-m9s12xg.c: Likewise.
	* cpu-mcore.c: Likewise.
	* cpu-mep.c: Likewise.
	* cpu-metag.c: Likewise.
	* cpu-microblaze.c: Likewise.
	* cpu-mips.c: Likewise.
	* cpu-mmix.c: Likewise.
	* cpu-moxie.c: Likewise.
	* cpu-msp430.c: Likewise.
	* cpu-mt.c: Likewise.
	* cpu-nds32.c: Likewise.
	* cpu-nfp.c: Likewise.
	* cpu-nios2.c: Likewise.
	* cpu-ns32k.c: Likewise.
	* cpu-or1k.c: Likewise.
	* cpu-pdp11.c: Likewise.
	* cpu-pj.c: Likewise.
	* cpu-plugin.c: Likewise.
	* cpu-powerpc.c: Likewise.
	* cpu-pru.c: Likewise.
	* cpu-riscv.c: Likewise.
	* cpu-rl78.c: Likewise.
	* cpu-rs6000.c: Likewise.
	* cpu-rx.c: Likewise.
	* cpu-s12z.c: Likewise.
	* cpu-s390.c: Likewise.
	* cpu-score.c: Likewise.
	* cpu-sh.c: Likewise.
	* cpu-sparc.c: Likewise.
	* cpu-spu.c: Likewise.
	* cpu-tic30.c: Likewise.
	* cpu-tic4x.c: Likewise.
	* cpu-tic54x.c: Likewise.
	* cpu-tic6x.c: Likewise.
	* cpu-tic80.c: Likewise.
	* cpu-tilegx.c: Likewise.
	* cpu-tilepro.c: Likewise.
	* cpu-v850.c: Likewise.
	* cpu-v850_rh850.c: Likewise.
	* cpu-vax.c: Likewise.
	* cpu-visium.c: Likewise.
	* cpu-wasm32.c: Likewise.
	* cpu-xc16x.c: Likewise.
	* cpu-xgate.c: Likewise.
	* cpu-xstormy16.c: Likewise.
	* cpu-xtensa.c: Likewise.
	* cpu-z80.c: Likewise.
	* cpu-z8k.c: Likewise.

gas	* testsuite/gas/arm/pr24907.s: New test.
	* testsuite/gas/arm/pr24907.d: Expected disassembly.
2019-09-10 15:20:58 +01:00
Phil Blundell 60391a255b Add markers for 2.33 branch to NEWS and ChangeLog files. 2019-09-09 10:27:40 +01:00
Alan Modra b16c44debc bfd_get_filename
This macro says:
/* Cast from const char * to char * so that caller can assign to
   a char * without a warning.  */

I reckon that isn't such a good idea since it can result in char*
variables where const char* is appropriate.  Not very many places
need the char* cast.

bfd/
	* aout-target.h (object_p): Formatting.
	* bfd-in.h (bfd_get_filename): Don't cast to char*.
	* corefile.c (generic_core_file_matches_executable_p): Constify
	variables and remove cast.
	* bfd-in2.h: Regenerate.
binutils/
	* nm.c (print_object_filename_bsd, print_object_filename_sysv),
	(print_object_filename_posix, print_archive_filename_bsd),
	(print_archive_filename_sysv, print_archive_filename_posix),
	(print_archive_member_bsd, print_archive_member_sysv),
	(print_archive_member_posix): Constify parameter.
	(struct output_fns <print_object_filename, print_archive_filename>),
	(<print_archive_member>): Likewise.
	* objcopy.c (copy_archive): Add cast for make_tempdir.
ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_search_needed): Constify
	variable.
	* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
gdb/
	* coffread.c (coff_symfile_read): Constify filename variable.
	* dbxread.c (dbx_symfile_init, coffstab_build_psymtabs),
	(elfstab_build_psymtabs, stabsect_build_psymtabs): Likewise.
	* gdb_bfd.c (gdb_bfd_close_or_warn): Likewise.
	* solib.c (reload_shared_libraries_1): Likewise.
	* symfile.c (reread_symbols): Likewise.
	* solib-aix.c (solib_aix_bfd_open): Add cast for xfree of filename.
	* solib-darwin.c (darwin_bfd_open): Likewise.
	* symfile-mem.c (symbol_file_add_from_memory): Likewise.
sim/cris/
	* sim-if.c (sim_open): Constify filename variable.
2019-09-06 12:22:59 +09:30