Commit graph

17263 commits

Author SHA1 Message Date
Alan Modra
cfabce5ba1 asan: abort in wasm_scan_name_function_section
Macros like READ_LEB128 in wasm-module.c that alter control flow are
evil.  Maintainers will break your code if you have hidden ways to
reach labels.

	* wasm-module.c (wasm_scan_name_function_section): Don't
	attempt to bfd_release NULL.
2021-12-17 16:01:34 +10:30
Alan Modra
9b54b56185 asan: heap-buffer-overflow in bpf_elf_generic_reloc
The bpf reloc howtos are a bit weird, using bitpos to specify an
offset from r_offset that is outside the size of the reloc as given by
howto.size.  That means bfd_get_reloc_size gives the wrong answer for
range checking, and thus bfd_reloc_offset_in_range can't be used.

	* elf64-bpf.c (bpf_elf_generic_reloc): Handle bitpos offset reloc
	range checking.
2021-12-17 16:01:34 +10:30
Alan Modra
b39de8897a ubsan: bfd.c:2519:8: shift exponent 34 is too large
* bfd.c (bfd_update_compression_header): Avoid integer overflow.
2021-12-17 16:01:17 +10:30
Alan Modra
00d44f7f2f asan: buffer overflow in mmo_get_symbols
* mmo.c (mmo_get_symbols): Error on symbol name exceeding max length.
2021-12-17 16:01:14 +10:30
Alan Modra
8ef22662dc asan: buffer overflow in elfnn-aarch64.c get_plt_type
We can't assume .dynamic is a multiple of ElfNN_External_Dyn, at least
not when presented with fuzzed object files.

	* elfnn-aarch64.c (get_plt_type): Don't access past end of
	improperly sized .dynamic.
2021-12-17 16:01:13 +10:30
GDB Administrator
240eab1e59 Automatic date update in version.in 2021-12-17 00:00:15 +00:00
Nelson Chu
23ff54c27d RISC-V: Support svinval extension with frozen version 1.0.
According to the privileged spec, there are five new instructions for
svinval extension.  Two of them (HINVAL.VVMA and HINVAL.GVMA) need to
enable the hypervisor extension.  But there is no implementation of
hypervisor extension in mainline for now, so let's consider the related
issues later.

                31..25  24..20 19..15 14..12 11...7 6..2  1..0
sinval.vma      0001011 rs2    rs1    000    00000  11100 11
sfence.w.inval  0001100 00000  00000  000    00000  11100 11
sfence.inval.ir 0001100 00001  00000  000    00000  11100 11
hinval.vvma     0010011 rs2    rs1    000    00000  11100 11
hinval.gvma     0110011 rs2    rs1    000    00000  11100 11

This patch is cherry-picked from the riscv integration branch since the
svinval extension is frozen for now.  Besides, we fix the funct7 encodings
of hinval.vvma and hinval.gvma, from 0x0011011 and 0x0111011 to 0x0010011
and 0x0110011.

bfd/
	* elfxx-riscv.c (riscv_supported_std_s_ext): Added svinval.
	(riscv_multi_subset_supports): Handle INSN_CLASS_SVINVAL.
gas/
	* testsuite/gas/riscv/svinval.d: New testcase.
	* testsuite/gas/riscv/svinval.s: Likewise.
include/
	* opcode/riscv-opc.h: Added encodings for svinval.
	* opcode/riscv.h (enum riscv_insn_class): Added INSN_CLASS_SVINVAL.
opcodes/
	* riscv-opc.c (riscv_opcodes): Added svinval instructions.
2021-12-16 16:04:53 +08:00
Mike Frysinger
444cc278b9 bfd: unify texi generation rules
The logic between these rules are extremely similar, so unify them
into a single variable by leveraging make $@ and $< variables.

Also add automake silent rule support while we're here.
2021-12-16 02:34:58 -05:00
Alan Modra
05f62e0c9a Re: Fix an undefined behaviour in the BFD library's DWARF parser
Using an unsigned int cast (to 32 bits) on a pointer difference (of
possibly 64 bits) is wrong.  Even though it will work on all real
object files, the fuzzers will eventually find this hole.

	PR 28687
	* dwarf1.c (parse_die): Cast pointer difference to size_t.
	Catch another possible pointer overflow.
2021-12-16 14:38:47 +10:30
GDB Administrator
da72876cc5 Automatic date update in version.in 2021-12-16 00:00:11 +00:00
Alan Modra
161cdabc39 PR28691, validate dwarf attribute form
PR28691 is a fuzzing PR that triggers a non-problem of "output changes
per run" with PIEs and/or different compilers.  I've closed similar
PRs before as wontfix, but I guess there will be no end of this type
of PR.  The trigger is an attribute that usually takes one of the
offset/constant reference DW_FORMs being given an indexed string
DW_FORM.  The bfd reader doesn't support indexed strings and returns
an error string instead.  The address of the string varies with PIE
runs and/or compiler, and we allow that address to appear in output.
Fix this by validating integer attribute forms, as we do for string
form attributes.

	PR 28691
	* dwarf2.c (is_str_attr): Rename to..
	(is_str_form): ..this.  Change param type.  Update calls.
	(is_int_form): New function.
	(read_attribute_value): Handle DW_FORM_addrx2.
	(find_abstract_instance): Validate form when using attr.u.val.
	(scan_unit_for_symbols, parse_comp_unit): Likewise.
2021-12-16 08:57:57 +10:30
Nikita Popov
4d3605c8ca Fix an undefined behaviour in the BFD library's DWARF parser.
PR 28687
	* dwarf1.c (parse_die): Fix undefined behaviour in range tests.
2021-12-15 17:49:23 +00:00
GDB Administrator
d5c9473176 Automatic date update in version.in 2021-12-15 00:00:14 +00:00
Alan Modra
47cf88952a loongarch32 build failure on 32-bit host
gas/config/tc-loongarch.c: In function ‘assember_macro_helper’:
gas/config/tc-loongarch.c:915:28: error: right shift count >= width of type [-Werror=shift-count-overflow]
  915 |       hi32 = insn->args[1] >> 32;
      |                            ^~

One possible fix is to make offsetT a 64-bit type for loongarch32.
This also makes bfd/targmatch.h (generated from bfd/config.bfd)
consistent since the loongarch32 match is inside #ifdef BFD64.

	* config.bfd (loongarch32-*): Set want64.
2021-12-15 09:21:12 +10:30
Alan Modra
eda0ddeb26 XCOFF C_STSYM test failure on 32-bit host
This test was failing here and on another similar symbol:
[  4](sec  1)(fl 0x00)(ty   0)(scl 143) (nx 0) 0x05d1745d11745d21 .bs
where correct output is
[  4](sec  1)(fl 0x00)(ty   0)(scl 143) (nx 0) 0x000000000000000a .bs

The problem is caused by a 32-bit host pointer being sign-extended
when stored into a 64-bit bfd_vma, and then that value not being
trimmed back to 32 bits when used.  The following belt-and-braces
patch fixes both the store and subsequent reads.

	* coffcode.h (coff_slurp_symbol_table): Do not sign extend
	when storing a host pointer to syment.n_value.
	* coffgen.c (coff_get_symbol_info): Cast syment.n_value to a
	bfd_hostptr_t before using in arithmetic.
	(coff_print_symbol): Likewise.
2021-12-15 08:23:10 +10:30
Simon Marchi
9bc8e54b1f bfd: fix -Wunused errors with clang 13+
Clang 13 and 14 produce some -Wunused-but-set-{variable,parameter} for
situations where gcc doesn't.  In particular, when a variable is set and
then used in a way to update its own value.  For example, if `i` is only
used in this way:

  int i = 2;
  i++;
  i = i + 1;

gcc won't warn, but clang will.

Fix all such errors found in an --enable-targets=all build.  It would be
important for somebody who knows what they're doing to just make sure
that these variables can indeed be deleted, and that there a no cases
where it's a bug, and the variable should actually be used.

The first instance of this error fix by this patch is:

      CC       elf32-score.lo
    /home/simark/src/binutils-gdb/bfd/elf32-score.c:450:11: error: variable 'relocation' set but not used [-Werror,-Wunused-but-set-variable]
      bfd_vma relocation;
              ^

Change-Id: I2f233ce20352645cf388aff3dfa08a651d21a6b6
2021-12-14 08:47:48 -05:00
GDB Administrator
527b8861cd Automatic date update in version.in 2021-12-14 00:00:11 +00:00
GDB Administrator
0ca813c3d5 Automatic date update in version.in 2021-12-13 00:00:11 +00:00
GDB Administrator
2749ac1339 Automatic date update in version.in 2021-12-12 00:00:07 +00:00
Alan Modra
1563e7179a Don't edit bogus sh_link on reading relocatable objects (Oracle fix)
This reverts a 1995 fix to handle bogus object files.  Presumably such
object files have long gone.

	* elf.c (bfd_section_from_shdr): Remove old hack for Oracle
	libraries.
2021-12-11 11:09:47 +10:30
GDB Administrator
edce4d8c6a Automatic date update in version.in 2021-12-11 00:00:05 +00:00
GDB Administrator
55ac06caf9 Automatic date update in version.in 2021-12-10 00:00:18 +00:00
Alan Modra
b243230f64 PR28674, objdump crash
Not returning an error indication here leaves the attribute
uninitialised, which then leads to intemperate behaviour.

	PR 28674
	* dwarf2.c (read_attribute_value): Return NULL on trying to read
	past end of attributes.
2021-12-10 08:33:12 +10:30
Alan Modra
b6d1f70cc7 Set sh_link for reloc sections created as normal sections
binutils-all/strip-13 and binutils-all/strip-14 tests create
SHT_REL/SHT_RELA sections by hand.  These don't have sh_link set to
the .symtab section as they should, leading to readelf warnings if you
happen to be looking at the object files.

	* elf.c (assign_section_numbers): Formatting.  Set sh_link for
	reloc sections created as normal sections in relocatable
	objects.
2021-12-10 08:33:12 +10:30
Nelson Chu
de3a913df6 RISC-V: Clarify the behavior of .option arch directive.
* To be consistent with -march option, removed the "=" operator when
user want to reset the whole architecture string.  So the formats are,

.option arch, +<extension><version>, ...
.option arch, -<extension>
.option arch, <ISA string>

* Don't allow to add or remove the base extensions in the .option arch
directive.  Instead, users should reset the whole architecture string
while they want to change the base extension.

* The operator "+" won't update the version of extension, if the
extension is already in the subset list.

bfd/
	* elfxx-riscv.c (riscv_add_subset): Don't update the version
	if the extension is already in the subset list.
	(riscv_update_subset): To be consistent with -march option,
	removed the "=" operator when user want to reset the whole
	architecture string.  Besides, Don't allow to add or remove
	the base extensions in the .option arch directive.
gas/
	* testsuite/gas/riscv/option-arch-01.s: Updated since we cannot
	add or remove the base extensions in the .option arch directive.
	* testsuite/gas/riscv/option-arch-02.s: Likewise.
	* testsuite/gas/riscv/option-arch-fail.l: Likewise.
	* testsuite/gas/riscv/option-arch-fail.s: Likewise.
	* testsuite/gas/riscv/option-arch-01a.d: Set -misa-spec=2.2.
	* testsuite/gas/riscv/option-arch-01b.d: Likewise.
	* testsuite/gas/riscv/option-arch-02.d: Updated since the .option
	arch, + won't change the version of extension, if the extension is
	already in the subset list.
	* testsuite/gas/riscv/option-arch-03.s: Removed the "=" operator
	when resetting the whole architecture string.
2021-12-09 15:55:04 +08:00
GDB Administrator
9aecb5778d Automatic date update in version.in 2021-12-09 00:00:07 +00:00
Fangrui Song
a619b58721 bfd_section_from_shdr: Support SHT_RELR sections
If a.so contains an SHT_RELR section, objcopy a.so will fail with:

    a.so: unknown type [0x13] section `.relr.dyn'

This change allows objcopy to work.

bfd/
    * elf.c (bfd_section_from_shdr): Support SHT_RELR.
2021-12-08 20:36:42 +10:30
GDB Administrator
abca192fed Automatic date update in version.in 2021-12-08 00:00:15 +00:00
GDB Administrator
21ce5fa063 Automatic date update in version.in 2021-12-07 00:00:10 +00:00
GDB Administrator
2427f3b09e Automatic date update in version.in 2021-12-06 00:00:13 +00:00
GDB Administrator
e8f6cf14c9 Automatic date update in version.in 2021-12-05 00:00:14 +00:00
Mike Frysinger
17ebe20800 bfd: unify header generation rules
The logic between these rules are extremely similar, so unify them
into a single variable.
2021-12-03 20:06:58 -05:00
Mike Frysinger
0f34c35dd9 bfd: move header updates up a directory
The rules for rebuilding the bfd headers live in the doc/ subdir
(most likely) because they rely on the chew & related tools.  But
we can collapse them into the main Makefile while keeping the tools
in the doc subdir easily enough.  This makes the code simpler and
allows for rebuilding them in parallel.

Also add automake silent rule support while we're here.
2021-12-03 20:03:05 -05:00
Mike Frysinger
f52ee74fea bfd: convert bfdver.h to silent automake rules 2021-12-03 19:57:22 -05:00
GDB Administrator
d4172973cb Automatic date update in version.in 2021-12-04 00:00:15 +00:00
GDB Administrator
13bb461986 Automatic date update in version.in 2021-12-03 00:00:15 +00:00
H.J. Lu
794f2bba0f x86: Skip __[start|stop]_SECNAME for --gc-sections -z start-stop-gc
Don't convert memory load to immediate load on __start_SECNAME and
__stop_SECNAME for --gc-sections -z start-stop-gc if all SECNAME
sections been garbage collected.

bfd/

	PR ld/27491
	* elf32-i386.c (elf_i386_convert_load_reloc): Skip __start_SECNAME
	and __stop_SECNAME for --gc-sections -z start-stop-gc if the input
	section been garbage collected.
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise.
	* elfxx-x86.h (elf_x86_start_stop_gc_p): New function.

ld/
	PR ld/27491
	* testsuite/ld-i386/i386.exp: Run PR ld/27491 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr27491-1.s: New file.
	* testsuite/ld-i386/pr27491-1a.d: Likewise.
	* testsuite/ld-i386/pr27491-1b.d: Likewise.
	* testsuite/ld-i386/pr27491-1c.d: Likewise.
	* testsuite/ld-i386/pr27491-2.d: Likewise.
	* testsuite/ld-i386/pr27491-2.s: Likewise.
	* testsuite/ld-i386/pr27491-3.d: Likewise.
	* testsuite/ld-i386/pr27491-3.s: Likewise.
	* testsuite/ld-i386/pr27491-4.d: Likewise.
	* testsuite/ld-i386/pr27491-4a.s: Likewise.
	* testsuite/ld-i386/pr27491-4b.s: Likewise.
	* testsuite/ld-x86-64/pr27491-1.s: Likewise.
	* testsuite/ld-x86-64/pr27491-1a.d: Likewise.
	* testsuite/ld-x86-64/pr27491-1b.d: Likewise.
	* testsuite/ld-x86-64/pr27491-1c.d: Likewise.
	* testsuite/ld-x86-64/pr27491-2.d: Likewise.
	* testsuite/ld-x86-64/pr27491-2.s: Likewise.
	* testsuite/ld-x86-64/pr27491-3.d: Likewise.
	* testsuite/ld-x86-64/pr27491-3.s: Likewise.
	* testsuite/ld-x86-64/pr27491-4.d: Likewise.
	* testsuite/ld-x86-64/pr27491-4a.s: Likewise.
	* testsuite/ld-x86-64/pr27491-4b.s: Likewise.
2021-12-02 03:55:10 -08:00
Mike Frysinger
c808def421 bfd: delete unused proto settings
These have been around for decades but don't appear to be used, and
trying to build them (e.g. `make archive.p archive.ip`) doesn't work,
so just delete it all.
2021-12-01 23:50:05 -05:00
GDB Administrator
b18c2bb9f3 Automatic date update in version.in 2021-12-02 00:00:11 +00:00
GDB Administrator
b70f818d7d Automatic date update in version.in 2021-12-01 00:00:09 +00:00
Mike Frysinger
75ea503ef0 bfd: enable silent build rules
Also add $(AM_V_xxx) to various manual rules in here.
2021-11-29 20:26:26 -05:00
GDB Administrator
9832d223d6 Automatic date update in version.in 2021-11-30 00:00:11 +00:00
GDB Administrator
dba322be6e Automatic date update in version.in 2021-11-29 00:00:09 +00:00
GDB Administrator
8be0a6307c Automatic date update in version.in 2021-11-28 00:00:10 +00:00
GDB Administrator
fd02ad8772 Automatic date update in version.in 2021-11-27 00:00:09 +00:00
GDB Administrator
decca804f8 Automatic date update in version.in 2021-11-26 00:00:10 +00:00
Jan W. Jagersma
423e91d347 coff-go32: consistent 16-byte section alignment
Section alignment for coff-go32 is inconsistent - The '.text' and
'.data' sections are 16-byte aligned, but named sections '.text.*' and
'.data.*' are only 4-byte aligned.  '.gnu.linkonce.r.*' is aligned to
16 bytes, yet '.rodata' and '.rodata.*' are aligned to 4 bytes.  For
'.bss' all input sections are only aligned to 4 bytes.

This primarily can cause trouble when using SSE instructions, which
require their memory operands to be aligned to 16-byte boundaries.

This patch solves the issue simply by setting the section alignment
to 16 bytes, for all code and data sections referenced in the default
linker script.

	* coff-go32.c (COFF_SECTION_ALIGNMENT_ENTRIES):  Use partial
	name match for .text, .data.  Add entries for .const, .rodata,
	.bss, .gnu.linkonce.b.
2021-11-25 23:19:58 +10:30
Alan Modra
32384aa396 Re: AArch64: Add support for AArch64 EFI (efi-*-aarch64)
Commit b69c9d41e8 edited bfd/Makefile.in rather than using automake,
which meant a typo in Makefile.am was not discovered and other
differences in Makefile.in are seen with a proper regeneration.  One
difference was lack of an empty line between the pe-aarch64igen.c rule
and the following $(BFD32_LIBS) etc. dependency rule, in the
regenerated file.  Not that it matters for proper "make" behaviour,
but it's nicer with a line between those rules.  Moving the rule
earlier seems to cure the missing empty line.

	* Makefile.am (BFD64_BACKENDS): Correct typo.
	(BFD_H_DEPS, LOCAL_H_DEPS): Move earlier.  Move rule using these
	deps earlier too.
	* Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
2021-11-25 22:44:56 +10:30
GDB Administrator
2b1538656b Automatic date update in version.in 2021-11-25 00:00:11 +00:00
GDB Administrator
95db489df6 Automatic date update in version.in 2021-11-24 00:00:08 +00:00