Commit Graph

8827 Commits

Author SHA1 Message Date
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