Commit graph

17274 commits

Author SHA1 Message Date
Alan Modra
c5967f38de PR28530, Hang in objdump on machine with 196GB RAM
Investigating the PR28530 testcase, which has a fuzzed compression
header with an enormous size, I noticed that decompress_contents is
broken when the size doesn't fit in strm.avail_out.  It wouldn't be
too hard to support larger sizes (patches welcome!) but for now just
stop decompress_contents from returning rubbish.

	PR 28530
	* compress.c (decompress_contents): Fail when uncompressed_size
	is too big.
	(bfd_init_section_decompress_status): Likewise.
2021-11-05 14:15:18 +10:30
Alan Modra
a3c0896d80 asan: alpha-vms: objdump buffer overflows
* vms-alpha.c (evax_bfd_print_desc): Sanity check buffer access.
	(evax_bfd_print_valspec, evax_bfd_print_typspec): Likewise.
	(evax_bfd_print_dst): Likewise.
2021-11-05 14:15:18 +10:30
GDB Administrator
831105b6d9 Automatic date update in version.in 2021-11-05 00:00:30 +00:00
H.J. Lu
33d3e18ed7 Revert "bfd: Always check sections with the corrupt size"
This reverts commit e0f7ea9143.
2021-11-04 08:07:09 -07:00
H.J. Lu
e0f7ea9143 bfd: Always check sections with the corrupt size
Always check sections with the corrupt size for non-MMO files.  Skip MMO
files for compress_status == COMPRESS_SECTION_NONE since MMO has special
handling for COMPRESS_SECTION_NONE.

	PR binutils/28530
	* compress.c (bfd_get_full_section_contents): Always check
	sections with the corrupt size.
2021-11-04 06:57:32 -07:00
Nelson Chu
edc77c591a RISC-V: Clarify the behavior of .option rvc or norvc.
Add/Remove the rvc extension to/from the riscv_subsets once the
.option rvc/norvc is set.  So that we don't need to always check
the riscv_opts.rvc in the riscv_subset_supports, just call the
riscv_lookup_subset to search the subset list is enough.

Besides, we will need to dump the instructions according to the
elf architecture attributes.  That means the dis-assembler needs
to parse the architecture string from the elf attribute before
dumping any instructions, and also needs to recognized the
INSN_CLASS* classes from riscv_opcodes.  Therefore, I suppose
some functions will need to be moved from gas/config/tc-riscv.c
to bfd/elfxx-riscv.c, including riscv_multi_subset_supports and
riscv_subset_supports.  This is one of the reasons why we need
this patch.

This patch passes the gcc/binutils regressions of rv32emc-elf,
rv32i-elf, rv64gc-elf and rv64gc-linux toolchains.

bfd/
	* elfxx-riscv.c (riscv_remove_subset): Remove the extension
	from the subset list.
	(riscv_update_subset): Add/Remove an extension to/from the
	subset list.  This is used for the .option rvc or norvc.
	* elfxx-riscv.h: Added the extern bool riscv_update_subset.
gas/
	* config/tc-riscv.c (riscv_set_options): Removed the unused
	rve flag.
	(riscv_opts): Likewise.
	(riscv_set_rve): Removed.
	(riscv_subset_supports): Removed the riscv_opts.rvc check.
	(riscv_set_arch): Don't need to call riscv_set_rve.
	(reg_lookup_internal): Call riscv_subset_supports to check
	whether the rve is supported.
	(s_riscv_option): Add/Remove the rvc extension to/from the
	subset list once the .option rvc/norvc is set.
2021-11-04 17:46:09 +08:00
GDB Administrator
8f01568908 Automatic date update in version.in 2021-11-04 00:00:14 +00:00
Alan Modra
a442059f66 PR28523, ld.bfd created undefined symbols on ppc64
This patch removes any fake (linker created) function descriptor
symbol if its code entry symbol isn't dynamic, to ensure bogus dynamic
symbols are not created.  The change to func_desc_adjust requires that
it be run only once, which means ppc64_elf_tls_setup can't call it for
just a few selected symbols.

	PR 28523
	* elf64-ppc.c (func_desc_adjust): If a function entry sym is
	not dynamic and has no plt entry, hide any associated fake
	function descriptor symbol.
	(ppc64_elf_edit): Move func_desc_adjust iteration over syms to..
	(ppc64_elf_tls_setup): ..here.
2021-11-03 10:46:29 +10:30
GDB Administrator
b480ee76e4 Automatic date update in version.in 2021-11-03 00:00:18 +00:00
GDB Administrator
317db249c7 Automatic date update in version.in 2021-11-02 00:00:17 +00:00
Alan Modra
c908dea26f macho-o archive sanity checks
Anti-fuzzing checks.

	* mach-o.c (bfd_mach_o_fat_archive_p): Sanity check entry offset
	and size against file size.
2021-11-01 22:30:33 +10:30
Przemyslaw Wirkus
3197e593d8 arm: add armv9-a architecture to -march
Update also include:
	+ New value of Tag_CPU_arch EABI attribute (22) is added.
	+ Updated missing Tag_CPU_arch EABI attributes.
	+ Updated how we combine archs 'v4t_plus_v6_m' as this mechanism
	  have to handle new Armv9 as well.

Regression tested on `arm-none-eabi` cross Binutils and no issues.

bfd/

	* archures.c: Define bfd_mach_arm_9.
	* bfd-in2.h (bfd_mach_arm_9): Define bfd_mach_arm_9.
	* cpu-arm.c: Add 'armv9-a' option to -march.
	* elf32-arm.c (using_thumb2_bl): Update assert check.
	(arch_has_arm_nop): Add TAG_CPU_ARCH_V9.
	(bfd_arm_get_mach_from_attributes): Add case for TAG_CPU_ARCH_V9.
	Update assert.
	(tag_cpu_arch_combine): Updated table.
	(v9): New table..

binutils/

	* readelf.c (arm_attr_tag_CPU_arch): Update with

elfcpp/

	* arm.h: Update TAG_CPU_ARCH_ enums with correct values.

gas/

	* NEWS: Update docs.
	* config/tc-arm.c (get_aeabi_cpu_arch_from_fset): Return Armv9-a
	for -amarch=all.
	(aeabi_set_public_attributes): Update assert.
	* doc/c-arm.texi: Update docs.
	* testsuite/gas/arm/armv9-a_arch.d: New test.
	* testsuite/gas/arm/attr-march-all.d: Update test with v9.

include/

	* elf/arm.h Update TAG_CPU_ARCH_ defines with correct values.
	* opcode/arm.h (ARM_EXT3_V9A): New macro.
	(ARM_ARCH_NONE): Updated with arm_feature_set.core size.
	(FPU_NONE): Updated.
	(ARM_ANY): Updated.
	(ARM_ARCH_UNKNOWN): New macro.
	(ARM_FEATURE_LOW): Updated.
	(ARM_FEATURE_CORE): Updated.
	(ARM_FEATURE_CORE_LOW): Updated.
	(ARM_FEATURE_CORE_HIGH): Updated.
	(ARM_FEATURE_COPROC): Updated.
	(ARM_FEATURE): Updated.
	(ARM_FEATURE_ALL): New macro.

opcodes/

	* arm-dis.c (select_arm_features): Support bfd_mach_arm_9.
	Also Update bfd_mach_arm_unknown to use new macro ARM_ARCH_UNKNOWN.
2021-11-01 10:51:03 +00:00
GDB Administrator
e7360783ae Automatic date update in version.in 2021-11-01 00:00:19 +00:00
Alan Modra
590abc168f Don't include coff/pe.h in coff-x86_64.c
This (and other) code from coffcode.h is broken for x86_64_coff_vec,
and has been ever since support was added in 2006 commit 99ad839030
Here, bfd_coff_aoutsz must match coff_swap_aouthdr_out otherwise we
end up writing garbage.

      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
	 include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
      char * buff;
      bfd_size_type amount = bfd_coff_aoutsz (abfd);

      buff = (char *) bfd_malloc (amount);
      if (buff == NULL)
	return false;

      coff_swap_aouthdr_out (abfd, & internal_a, buff);
      amount = bfd_bwrite (buff, amount, abfd);

We have removed support for --target=x86_64-coff, likely because it
never worked properly, but still produce coff-x86_64.o with
--enable-targets=all.  This means objcopy can recognize x86_64 COFF
files but will write garbage to the output file, a fact found by
fuzzers.  I suspect x86_64 COFF is still broken after this fix, and
mention of coff-x86_64.* should be removed from bfd/Makefile.am.

	* coff-x86_64.c: Don't include coff/pe.h.
	(COFF_WITH_pex64): Don't define here.
	* pe-x86_64.c: Include coff/pe.h and other headers.
	(PEI_HEADERS): Define.
2021-10-31 11:42:52 +10:30
Alan Modra
1c5e9d8d8c Re: PR28420, ecoff fuzzing failures
sym_ptr_ptr NULL results in segfaults.

	PR 28420
	* ecoff.c (ecoff_slurp_reloc_table): Don't leave sym_ptr_ptr NULL.
2021-10-31 11:42:08 +10:30
Alan Modra
9216910ed8 ubsan: alpha-vms: undefined shift
* vms-alpha.c (evax_bfd_print_image): Shift left 1u.
2021-10-31 11:41:39 +10:30
Alan Modra
3c8ed65a5d PR28518: signed integer overflow & free on unmalloced address
PR 28518
	* vms-alpha.c (build_module_list): Don't lose malloc buffer address.
	Use unsigned variables.
2021-10-31 10:57:52 +10:30
GDB Administrator
fb9f44d410 Automatic date update in version.in 2021-10-31 00:00:09 +00:00
GDB Administrator
4a3a56c5f3 Automatic date update in version.in 2021-10-30 00:00:26 +00:00
Alan Modra
c45c3dba8c ELF core file size checks
Catch fuzzed segments where p_offset + p_filesz wraps, and limit error
output.

	* elfcore.h (elf_core_file_p): Rewrite segment checks using
	bfd_get_file_size.  Set read_only on file size errors.
	* elfcode.h (elf_swap_shdr_in): Don't repeat error message.
2021-10-29 17:22:32 +10:30
Alan Modra
c82ebeb7e6 obcopy vs. files with silly section alignment
We already ignore stupid segment alignment when rewriting headers,
ignore section alignment too.

	* elf.c (rewrite_elf_program_header): Ignore section alignment
	power greater than 62.
2021-10-29 15:48:22 +10:30
GDB Administrator
208eb58158 Automatic date update in version.in 2021-10-29 00:00:18 +00:00
Alan Modra
0a0ff9d931 asan: mmo: NULL dereferenc in mmo_xore_32
mmo_get_loc can return NULL.  It's commented even, and that the caller
then must handle a split field.  mmo_xore_* don't handle split fields,
instead just segfault.  Stop that happening, and refuse to recognise
fuzzed mmo files that trigger this problem.

	* mmo.c (mmo_get_loc): Don't declare inline.
	(mmo_xore_64, mmo_xore_32, mmo_xore_16): Remove forward decls.
	Return pointer, don't dereference NULL.
	(mmo_scan): Return error on mmo_get_loc returning NULL.
2021-10-28 13:25:57 +10:30
Alan Modra
42eec46f23 bfd: remove use of INLINE
No need to use anything fancy, plain inline works just as well.

	* bfd-in.h (INLINE): Don't define.
	* bfd-in2.h: Regenerate.
	* aoutx.h: Replace use of INLINE with inline.
	* elf-eh-frame.c: Likewise.
	* elf32-score7.c: Likewise.
	* elfxx-mips.c: Likewise.
	* ihex.c: Likewise.
	* mach-o.c: Likewise.
	* mmo.c: Likewise.
2021-10-28 13:24:37 +10:30
GDB Administrator
9fc9dbc28b Automatic date update in version.in 2021-10-28 00:00:16 +00:00
Alan Modra
94852430d6 asan: alpha-vms: buffer overflows
Yet more anti-fuzzer sanity checking

	* vms-alpha.c (evax_bfd_print_egsd): Sanity check record and
	name lengths before access.
	(evax_bfd_print_etir_stc_ir, evax_bfd_print_etir): Likewise.
2021-10-28 07:40:49 +10:30
GDB Administrator
28c26ce5fd Automatic date update in version.in 2021-10-27 00:00:18 +00:00
GDB Administrator
3976e96a02 Automatic date update in version.in 2021-10-26 00:00:12 +00:00
Alan Modra
1e5a28be0f ubsan: _bfd_xcoff64_swap_aux_in left shift of negative value
* coff64-rs6000.c (_bfd_xcoff64_swap_aux_in): Use bfd_vma for h.
2021-10-25 11:41:52 +10:30
Alan Modra
b920bc3722 asan: evax_bfd_print_image buffer overflow
* vms-alpha.c (evax_bfd_print_image): Sanity check printing of
	"image activator fixup" section.
	(evax_bfd_print_relocation_records): Sanity check buffer offsets.
	(evax_bfd_print_address_fixups): Likewise.
	(evax_bfd_print_reference_fixups): Likewise.
2021-10-25 10:33:26 +10:30
GDB Administrator
30459fe4ef Automatic date update in version.in 2021-10-25 00:00:17 +00:00
Alan Modra
1ed0032b40 asan: c4x, c54x coff_canonicalize_reloc buffer overflow
Sometimes the investigation of a fuzzing bug report leads into areas
you'd rather not go.  In this instance by the time I'd figured out the
real cause was a target variant that had never been properly supported
in binutils, the time needed to fix it was less than the time needed
to rip it out.

	* coffcode.h (coff_set_alignment_hook): Call bfd_coff_swap_reloc_in
	not coff_swap_reloc_in.
	(coff_slurp_reloc_table): Likewise.  Don't use RELOC type.
	(ticoff0_swap_table): Use coff_swap_reloc_v0_out and
	coff_swap_reloc_v0_in.
	* coffswap.h (coff_swap_reloc_v0_in, coff_swap_reloc_v0_out): New.
	* coff-tic54x.c (tic54x_lookup_howto): Don't abort.
	* coffgen.c (coff_get_normalized_symtab): Use PTR_ADD.
	* bfd-in.h (PTR_ADD, NPTR_ADD): Avoid warnings when passing an
	expression.
	* bfd-in2.h: Regenerate.
2021-10-24 22:05:51 +10:30
Alan Modra
e028124942 asan: arm-darwin: buffer overflow
PR 21813
	* mach-o-arm.c (bfd_mach_o_arm_canonicalize_one_reloc): Sanity
	check PAIR reloc in other branch of condition as was done for
	PR21813.  Formatting.  Delete debug printf.
2021-10-24 21:45:23 +10:30
Alan Modra
3f9661f12a asan: aout: heap buffer overflow
* aoutx.h (aout_get_external_symbols): Sanity check before writing
	zero index entry.  Remove outdated comment.
	* pdp11.c (aout_get_external_symbols): Likewise.
2021-10-24 21:36:32 +10:30
liuzhensong
e214f8db56 LoongArch bfd support
2021-10-22  Chenghua Xu  <xuchenghua@loongson.cn>
	    Zhensong Liu  <liuzhensong@loongson.cn>
	    Weinan Liu  <liuweinan@loongson.cn>
bfd/
	* Makefile.am: Add LoongArch.
	* archures.c: Likewise.
	* config.bfd: Likewise.
	* configure.ac: Likewise.
	* cpu-loongarch.c: New.
	* elf-bfd.h: Add LoongArch.
	* elf.c: Add LoongArch elfcore_grok_xxx.
	* elfnn-loongarch.c: New.
	* elfxx-loongarch.c: New.
	* elfxx-loongarch.h: New.
	* reloc.c: Add LoongArch BFD RELOC ENUM.
	* targets.c: Add LoongArch target.
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* configure: Regenerate.
	* libbfd.h: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.

include/
	* elf/common.h: Add NT_LARCH_{CPUCFG,CSR,LSX,LASX}.
	* elf/loongarch.h: New.
2021-10-24 21:36:31 +10:30
GDB Administrator
e515d93264 Automatic date update in version.in 2021-10-24 00:00:16 +00:00
GDB Administrator
eaf4a97352 Automatic date update in version.in 2021-10-23 00:00:18 +00:00
Lewis Revill
9abcdc10b2 RISC-V: Don't separate pcgp relaxation to another relax pass.
Commit abd20cb637 and
ebdcad3fdd introduced additional
complexity into the paths run by the RISC-V relaxation pass in order to
resolve the issue of accurately keeping track of pcrel_hi and pcrel_lo
pairs. The first commit split up relaxation of these relocs into a pass
which occurred after other relaxations in order to prevent the situation
where bytes were deleted in between a pcrel_lo/pcrel_hi pair, inhibiting
our ability to find the corresponding pcrel_hi relocation from the
address attached to the pcrel_lo.

Since the relaxation was split into two passes the 'again' parameter
could not be used to perform the entire relaxation process again and so
the second commit added a way to restart ldelf_map_segments, thus
starting the whole process again.

Unfortunately this process could not account for the fact that we were
not finished with the relaxation process so in some cases - such as the
case where code would not fit in a memory region before the
R_RISCV_ALIGN relocation was relaxed - sanity checks in generic code
would fail.

This patch fixes all three of these concerns by reverting back to a
system of having only one target relax pass but updating entries in the
table of pcrel_hi/pcrel_lo relocs every time any bytes are deleted. Thus
we can keep track of the pairs accurately, and we can use the 'again'
parameter to restart the entire target relax pass, behaving in the way
that generic code expects. Unfortunately we must still have an
additional pass to delay deleting AUIPC bytes to avoid ambiguity between
pcrel_hi relocs stored in the table after deletion. This pass can only
be run once so we may potentially miss out on relaxation opportunities
but this is likely to be rare.

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

bfd/
	* elfnn-riscv.c (riscv_elf_link_hash_table): Removed restart_relax.
	(riscv_elf_link_hash_table_create): Updated.
	(riscv_relax_delete_bytes): Moved after the riscv_update_pcgp_relocs.
	Update the pcgp_relocs table whenever bytes are deleted.
	(riscv_update_pcgp_relocs): Add function to update the section
	offset of pcrel_hi and pcrel_lo, and also update the symbol value
	of pcrel_hi.
	(_bfd_riscv_relax_call): Need to update the pcgp_relocs table
	when deleting codes.
	(_bfd_riscv_relax_lui): Likewise.
	(_bfd_riscv_relax_tls_le): Likewise.
	(_bfd_riscv_relax_align): Once we've handled an R_RISCV_ALIGN,
	we can't relax anything else, so set the sec->sec_flg0 to true.
	Besides, we don't need to update the pcgp_relocs table at this
	stage, so just pass NULL pointer as the pcgp_relocs table for
	riscv_relax_delete_bytes.
	(_bfd_riscv_relax_section): Use only one pass for all target
	relaxations.
	(_bfd_riscv_relax_delete): Likewise, we don't need to update
	the pcgp_relocs table at this stage, and don't need to set
	the `again' since restart_relax mechanism is abandoned.
	(bfd_elfNN_riscv_restart_relax_sections): Removed.
	(_bfd_riscv_relax_section): Updated.
	* elfxx-riscv.h (bfd_elf32_riscv_restart_relax_sections): Removed.
	(bfd_elf64_riscv_restart_relax_sections): Likewise.
ld/
	* emultempl/riscvelf.em: Revert restart_relax changes and set
	relax_pass to 3.
	* testsuite/ld-riscv-elf/align-small-region.d: New testcase.
	* testsuite/ld-riscv-elf/align-small-region.ld: Likewise.
	* testsuite/ld-riscv-elf/align-small-region.s: Likewise.
	* testsuite/ld-riscv-elf/restart-relax.d: Removed sine the
	restart_relax mechanism is abandoned.
	* testsuite/ld-riscv-elf/restart-relax.s: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2021-10-22 16:44:37 +08:00
GDB Administrator
46276d3ca2 Automatic date update in version.in 2021-10-22 00:00:17 +00:00
GDB Administrator
f4efb229b7 Automatic date update in version.in 2021-10-21 00:00:22 +00:00
GDB Administrator
e43321cab2 Automatic date update in version.in 2021-10-20 00:00:09 +00:00
Nick Clifton
cf487499e0 Fix a potential illegal memory access when testing for a special LTO symbol name.
bfd	* linker.c (_bfd_generic_link_add_one_symbol): Test for a NULL
	name before checking to see if the symbol is __gnu_lto_slim.
	* archive.c (_bfd_compute_and_write_armap): Likewise.
binutils
	* nm.c (filter_symbols): Test for a NULL name before checking to
	see if the symbol is __gnu_lto_slim.
	* objcopy.c (filter_symbols): Likewise.
2021-10-19 16:02:49 +01:00
GDB Administrator
d4ef5e75c7 Automatic date update in version.in 2021-10-19 00:00:14 +00:00
GDB Administrator
19b9612448 Automatic date update in version.in 2021-10-18 00:00:08 +00:00
GDB Administrator
31629daee5 Automatic date update in version.in 2021-10-17 00:00:19 +00:00
GDB Administrator
8457023a80 Automatic date update in version.in 2021-10-16 00:00:15 +00:00
GDB Administrator
f9ebf60b6f Automatic date update in version.in 2021-10-15 00:00:12 +00:00
GDB Administrator
cdb6026064 Automatic date update in version.in 2021-10-14 00:00:12 +00:00
GDB Administrator
777b054cf9 Automatic date update in version.in 2021-10-13 00:00:06 +00:00
GDB Administrator
255a531196 Automatic date update in version.in 2021-10-12 00:00:15 +00:00