Commit Graph

18471 Commits

Author SHA1 Message Date
GDB Administrator
39f02ae4ad Automatic date update in version.in 2023-06-19 00:00:12 +00:00
GDB Administrator
2156c51d71 Automatic date update in version.in 2023-06-18 00:00:07 +00:00
GDB Administrator
6a4058a606 Automatic date update in version.in 2023-06-17 00:00:11 +00:00
mengqinggang
d2fddb6d78 LoongArch: Fix ld "undefined reference" error with --enable-shared
Because _bfd_read_unsigned_leb128 is hidden visibility, so it can't
  be referenced out of shared object.

  The new function loongarch_get_uleb128_length just used to call
  _bfd_read_unsigned_leb128.

bfd/ChangeLog:

	* elfxx-loongarch.c (loongarch_get_uleb128_length): New function.
	* elfxx-loongarch.h (loongarch_get_uleb128_length): New function.

gas/ChangeLog:

	* config/tc-loongarch.c (md_apply_fix): Use
	loongarch_get_uleb128_length.
2023-06-16 17:32:02 +08:00
GDB Administrator
fb0894b2b3 Automatic date update in version.in 2023-06-16 00:00:08 +00:00
David Guillen Fandos
df18f71b56 Add MIPS Allegrex CPU as a MIPS2-based CPU
The Allegrex CPU was created by Sony Interactive Entertainment to power
their portable console, the PlayStation Portable.
The pspdev organization maintains all sorts of tools to create software
for said device including documentation.

Signed-off-by: David Guillen Fandos <david@davidgf.net>
2023-06-15 04:45:03 +01:00
Maciej W. Rozycki
dbad690493 Revert "MIPS: default r6 if vendor is img"
This reverts commit be0d391f22.  It was
applied unapproved.
2023-06-15 04:45:03 +01:00
Alan Modra
6a28a3c200 vms write_archive memory leaks
This fixes two memory leaks in the vms archive handling.

	* vms-lib.c (_bfd_vms_lib_build_map): Free input symbols.
	(_bfd_vms_lib_write_archive_contents): Free archive map symbols.
2023-06-15 10:11:56 +09:30
GDB Administrator
87642f6311 Automatic date update in version.in 2023-06-15 00:00:08 +00:00
Alan Modra
6f860418d5 asprintf memory leaks
A number of backends want to return bfd_reloc_dangerous messaqes from
relocation special_function, and construct the message using asprintf.
Such messages are not freed anywhere, leading to small memory leaks
inside libbfd.  To limit the leaks, I'd implemented a static buffer in
the ppc backends that was freed before use in asprintf output.  This
patch extends that scheme to other backends using a shared static
buffer and goes further in freeing the buffer on any bfd_close.

The patch also fixes a few other cases where asprintf output was not
freed after use.

bfd/
	* bfd.c (_input_error_msg): Make global and rename to..
	(_bfd_error_buf): ..this.
	(bfd_asprintf): New function.
	(bfd_errmsg): Use bfd_asprintf.
	* opncls.c (bfd_close_all_done): Free _buf_error_buf.
	* elf32-arm.c (find_thumb_glue, find_arm_glue): Use bfd_asprintf.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_unhandled_reloc): Likewise.
	* elf64-ppc.c (ppc64_elf_unhandled_reloc): Likewise.
	* elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Likewise.
	(riscv_elf_relocate_section): Likewise.
	* libbfd.h: Regenerate.
gas/
	* read.c (read_end): Free current_name and current_label.
	(do_s_func): Likewise on error path.  strdup label.
ld/
	* pe-dll.c (make_head, make_tail, make_one),
	(make_singleton_name_thunk, make_import_fixup_entry),
	(make_runtime_pseudo_reloc),
	(pe_create_runtime_relocator_reference: Free oname after use.
2023-06-14 14:24:50 +09:30
Alan Modra
48375c36dc Re: bfd/elf.c strtab memory leak
There are other places that leak the strtab.

	* elf.c (_bfd_elf_compute_section_file_positions): Free strtab
	on error paths.
2023-06-14 14:24:33 +09:30
GDB Administrator
3bedac2939 Automatic date update in version.in 2023-06-14 00:00:11 +00:00
GDB Administrator
1e888ec928 Automatic date update in version.in 2023-06-13 00:00:17 +00:00
GDB Administrator
26d812a2aa Automatic date update in version.in 2023-06-12 00:00:10 +00:00
GDB Administrator
5bd1073178 Automatic date update in version.in 2023-06-11 00:00:09 +00:00
GDB Administrator
3e27e91062 Automatic date update in version.in 2023-06-10 00:00:12 +00:00
Alan Modra
ce3ab55fa7 ecoff find_nearest_line and final link leaks
Freeing ecoff_debug_info "pointers to the unswapped symbolic info"
isn't a simple matter, due to differing allocation strategies.  In
_bfd_ecoff_slurp_symbolic_info the pointers are to objalloc memory.
In the ecoff linker they are to separately malloc'd memory.  In gas we
have most (obj-elf) or all (obj-ecoff) into a single malloc'd buffer.

This patch fixes the leaks for binutils and ld, leaving the gas leaks
for another day.  The mips elf backend already had this covered, and
the ecoff backend had a pointer, raw_syments used as a flag, so most
of the patch is moving these around a little so they are accessible
for both ecoff and elf.

include/
	* coff/ecoff.h (struct ecoff_debug_info): Add alloc_syments.
bfd/
	* libecoff.h (struct ecoff_tdata): Delete raw_syments.
	* elfxx-mips.c (free_ecoff_debug): Delete.  Replace uses with
	_bfd_ecoff_free_ecoff_debug_info.
	(_bfd_mips_elf_final_link): Init debug.alloc_syments.
	* ecofflink.c (_bfd_ecoff_free_ecoff_debug_info): New function.
	* ecoff.c (_bfd_ecoff_bfd_free_cached_info): Call
	_bfd_ecoff_free_ecoff_debug_info.
	(_bfd_ecoff_slurp_symbolic_info): Replace uses of raw_syments
	with alloc_syments.
	(ecoff_final_link_debug_accumulate): Likewise.  Use
	_bfd_ecoff_free_ecoff_debug_info.
	(_bfd_ecoff_bfd_copy_private_bfd_data): Set alloc_syments for
	copied output.
	* elf64-alpha.c (elf64_alpha_read_ecoff_info): Use
	_bfd_ecoff_free_ecoff_debug_info.
	* libbfd-in.h (_bfd_ecoff_free_ecoff_debug_info): Declare.
	* libbfd.h: Regenerate.
gas/
	* config/obj-ecoff.c (ecoff_frob_file): Set alloc_syments.
	* config/obj-elf.c (elf_frob_file_after_relocs): Likewise.
2023-06-09 12:56:12 +09:30
GDB Administrator
8fd82abda0 Automatic date update in version.in 2023-06-09 00:01:06 +00:00
Alan Modra
12f7174bf0 Re: _bfd_free_cached_info
Oops, another leak caused by not defining the correct macro.

	* elf32-mips.c: Define bfd_elf32_bfd_free_cached_info.
	* elfn32-mips.c: Likewise.
	* elf64-mips.c: Define bfd_elf64_bfd_free_cached_info.
2023-06-08 10:37:40 +09:30
Alan Modra
09d757a5c2 Re: _bfd_free_cached_info
ELF targets with target-specific free_cache_info functions need to
call _bfd_elf_free_cached_info, not _bfd_generic_bfd_free_cached_info.

	* elf64-ppc.c (ppc64_elf_free_cached_info): Call
	_bfd_elf_free_cached_info.
	* elfnn-aarch64.c (elfNN_aarch64_bfd_free_cached_info): Likewise.
2023-06-08 10:31:45 +09:30
GDB Administrator
16476ac950 Automatic date update in version.in 2023-06-08 00:00:46 +00:00
Nick Clifton
064ad3ea5e Add extra linker warning message about discrepancies between normal and common symbols.
PR 30499
  bfd * elflink.c (elf_link_add_object_symbols): Add a message indicating that alignment and size discrepancies between the definition of common symbols and normal symbols are serious and should be investigated.
  ld  * testsuite/ld-elfcomm/elfcomm.exp: Update regexps to match new output from the linker.
2023-06-07 14:30:13 +01:00
Alan Modra
ba75d1c55c _bfd_free_cached_info
doc/bfdint.texi and comments in the aout and som code about this
function are just wrong, and its name is not very apt.  Better would
be _bfd_mostly_destroy, and we certainly should not be saying anything
about the possibility of later recreating anything lost by this
function.  What's more, if _bfd_free_cached_info is called when
creating an archive map to reduce memory usage by throwing away
symbols, the target _close_and_cleanup function won't have access to
tdata or section bfd_user_data to tidy memory.  This means most of the
target _close_and_cleanup function won't do anything, and therefore
sometimes will result in memory leaks.

This patch fixes the documentation problems and moves most of the
target _close_and_cleanup code to target _bfd_free_cached_info.
Another notable change is that bfd_generic_bfd_free_cached_info is now
defined as _bfd_free_cached_info rather than _bfd_bool_bfd_true,
ie. the default now frees objalloc memory.
2023-06-07 14:16:06 +09:30
Alan Modra
0a22a8f27d Memory leaks in bfd/vms-lib.c
* vms-lib.c (vms_lib_read_index): Free malloc'd memory on error
	return paths.
	(vms_write_index, _bfd_vms_lib_write_archive_contents): Likewise.
2023-06-07 11:05:12 +09:30
Alan Modra
c7e6669a5b bfd/elf.c strtab memory leak
* elf.c (_bfd_elf_compute_section_file_positions): Free strtab
	on set_group_contents failure return path.
2023-06-07 11:05:11 +09:30
GDB Administrator
d5b46032b8 Automatic date update in version.in 2023-06-07 00:00:47 +00:00
GDB Administrator
92deb60f27 Automatic date update in version.in 2023-06-06 00:01:04 +00:00
H.J. Lu
3f60b98298 ELF: Don't warn an empty PT_LOAD with the program headers
When rewriting the program headers, don't warn an empty PT_LOAD with the
program headers.

bfd/

	PR binutils/30508
	* elf.c (rewrite_elf_program_header): Don't warn if an empty
	PT_LOAD contains the program headers.

ld/

	PR binutils/30508
	* testsuite/ld-elf/pr30508.d: New file.
	* testsuite/ld-elf/pr30508.s: Likewise.
2023-06-05 08:21:21 -07:00
Alan Modra
fc998e4cb7 bfd_error_on_input messages
bfd_errmsg uses asprintf for bfd_error_on_input, which means we
currently leak memory.  Keep a static pointer to the message and free
it in various places to minimise the leaks.
bfd_set_input_error (NULL, bfd_error_no_error) is a way to free up the
last string if that matters.

	* bfd.c (input_error_msg): New static var.
	(bfd_set_input_error): Free it here..
	(bfd_init): ..and here..
	(bfd_errmsg): ..and here.  Use it for asprintf output.
2023-06-05 16:47:44 +09:30
Alan Modra
6fc018e9e5 Yet another ecoff fuzzed object fix
* ecoff.c (_bfd_ecoff_slurp_symbol_table): Sanity check fdr_ptr
	csym against remaining space for symbols.  Error on out of bounds
	fdr_ptr fields.
2023-06-05 16:47:44 +09:30
YunQiang Su
be0d391f22 MIPS: default r6 if vendor is img
This behavior is used by downstream toolchain since 2014.
We also set the default ABI for mips*-img-elf to O32.
The previous value is NO_ABI, which is not good default ABI.

We don't support mips64*-img* due to GCC doesn't support it,
and We believe that the multilib should be used for this case.
2023-06-05 11:00:14 +08:00
GDB Administrator
fa1ccf7895 Automatic date update in version.in 2023-06-05 00:00:39 +00:00
GDB Administrator
a366c78c1b Automatic date update in version.in 2023-06-04 00:00:34 +00:00
Alan Modra
c6e6e3ab2b Re: More ecoff sanity checks
Yet another fuzzer fix.

	* ecoff.c (ecoff_slurp_symbolic_header <FIX>): Zero counts when
	associated pointer is zero.
	(_bfd_ecoff_slurp_symbolic_info): Remove now unnecessary check.
2023-06-03 17:17:37 +09:30
GDB Administrator
26cc2053e2 Automatic date update in version.in 2023-06-03 00:00:39 +00:00
Alan Modra
63188cb5c3 Re: bfd_close and target free_cached_memory
_bfd_delete_bfd can be called early, before the target xvec is set up.

	* opncls.c (_bfd_delete_bfd): Don't segfault on NULL xvec.
2023-06-02 09:41:49 +09:30
Alan Modra
e0ce6dde97 Re: More ecoff sanity checks
Another fix for fuzzed object files, exhibiting as a segfault in
nm.c filter_symbols when accessing a symbol name.

	* ecoff.c (_bfd_ecoff_slurp_symbol_table): Sanity check
	fdr_ptr->issBase, and tighten sym.iss check.
2023-06-02 09:41:49 +09:30
GDB Administrator
cf6522cb2f Automatic date update in version.in 2023-06-02 00:01:12 +00:00
Nelson Chu
20ef84ed2a [PR ld/22263][PR ld/24676] RISC-V: Avoid spurious R_RISCV_NONE for TLS GD/IE.
For TLS GD/IE, add the same condition with the relocate_section in the
allocate_dynrelocs, to make sure we won't reserve redundant spaces
for dynamic relocations since the conservative estimatation.

After applying this patch, ld seems no longer generate the spurious
R_RISCV_NONE for pr22263-1 test, and the test in pr24676.

bfd/
	PR ld/22263
	PR ld/24676
	* elfnn-riscv.c (RISCV_TLS_GD_IE_NEED_DYN_RELOC): New defined.
	Set NEED_RELOC to true if TLS GD/IE needs dynamic relocations,
	and INDX will be the dynamic index.
	(allocate_dynrelocs): Don't reserve extra spaces in the rela.got
	if RISCV_TLS_GD_IE_NEED_DYN_RELOC set need_reloc to false.  This
	condition needs to be same as relocate_section.
	(relocate_section): Likewise, use the same condition as
	allocate_dynrelocs.
2023-06-01 12:23:49 +08:00
Alan Modra
6313825cbf Harden PowerPC64 OPD handling against fuzzers
PowerPC64 ELFv1 object files should have at most one .opd section, and
OPD handling in elf64-ppc.c makes use of this fact by caching some
.opd section info in the per-object bfd.tdata.  This was done to avoid
another word in the target specific section data.  Of course, fuzzers
don't respect the ABI, and even non-malicious users can accidentally
create multiple .opd sections.  So it is better to avoid possible
buffer overflows and other confusion when OPD handling for a second
.opd section references data for the first .opd section, by keeping
the data per-section.

The patch also fixes a memory leak, and a corner case where I think we
could hit an assertion in opd_entry_value or read out of bounds in
ppc64_elf_branch_reloc doing a final link producing non-ppc64 output.
(It's a really rare corner case because not only would you need to be
linking ppc64 objects to non-ppc64 output, you'd also need a branch
reloc symbol to be defined in a .opd section of a non-ppc64 input.)

	* elf64-ppc.c (is_ppc64_elf): Move earlier in file.
	(ppc64_elf_branch_reloc): Check symbol bfd before accessing
	ppc64 elf specific data structures.
	(struct ppc64_elf_obj_tdata): Move opd union..
	(struct _ppc64_elf_section_data): ..to here.
	(ppc64_elf_before_check_relocs): Allow for opd sec_type
	already set to sec_opd.
	(ppc64_elf_check_relocs): Only set sec_type to sec_toc when
	unset.  Error for unexpected toc relocs.
	(opd_entry_value): Return -1 when non-ppc64 rather than
	asserting.  Check and set sec_type too.  Adjust for changed
	location of contents and relocs.
	(ppc64_elf_relocate_section): Adjust for changed location of
	cached .opd relocs.
	(ppc64_elf_free_cached_info): New function.
	(bfd_elf64_bfd_free_cached_info): Define.
2023-06-01 09:52:07 +09:30
Alan Modra
8261abd513 bfd_close and target free_cached_memory
bfd_free_cached_info is used in just one place in archive.c, which
means most times we reach bfd_close the function isn't called.  On the
other hand, if bfd_free_cached_info is called we can't do much on the
bfd since it loses all its obj_alloc memory.  This restricts what can
be done in a target _close_and_cleanup.  In particular you can't look
at sections, which leads to duplication of code in target
close_and_cleanup and free_cached_info, eg. elfnn-aarch64.c.

	* opncls.c (_bfd_delete_bfd): Call bfd_free_cached_info.
	* elfnn-aarch64.c (elfNN_aarch64_close_and_cleanup): Delete.
	(bfd_elfNN_close_and_cleanup): Don't define.
	* som.c (som_bfd_free_cached_info): Don't call
	_bfd_generic_close_and_cleanup here.
	(som_close_and_cleanup): Define as _bfd_generic_close_and_cleanup.
2023-06-01 09:51:59 +09:30
Alan Modra
90fd5049bd section_by_target_index memory leak
The rs6000 backend can call coff_section_from_bfd_index from its
object_p function via coff_set_alignment_hook.  If the object doesn't
match, or another target matches too, then the hash table needs to be
freed via a cleanup.

	* coffgen.c (coff_object_cleanup): New function.
	(coff_real_object_p): Return coff_object_cleanup, and call on
	failure path.  Move declaration to..
	* libcoff-in.h: ..here.
	(coff_object_cleanup): Declare.
	* coff-stgo32.c (go32exe_cleanup): Call coff_object_cleanup.
	(go32exe_check_format): Adjust assertion.
	* libcoff.h: Regenerate.
2023-06-01 09:51:59 +09:30
Alan Modra
d18f60c747 Remove BFD_FAIL in cpu-sh.c
The assertions in cpu-sh.c can be triggered by passing bogus values
in disassemble_info.mach.  This doesn't cause any bfd misbehaviour.

	* cpu-sh.c (sh_get_arch_from_bfd_mach): Remove BFD_FAIL.
	(sh_get_arch_up_from_bfd_mach): Likewise.
2023-06-01 09:51:59 +09:30
GDB Administrator
f38f7ef965 Automatic date update in version.in 2023-06-01 00:00:39 +00:00
Tristan Gingold
768d1d879b pe/coff - add support for base64 encoded long section names
PR 30444
  * coffcode.h (coff_write_object_contents): Handle base64 encoding on PE.  Also check for too large string table.
  * coffgen.c (extract_long_section_name): New function extracted from ... (make_a_section_from_file): ... here.  Add support for base64 long section names. (decode_base64): New function.
2023-05-31 11:20:55 +01:00
Nick Clifton
a15891aaea Fix printf formating issues in elfxx-loongarch64.c 2023-05-31 10:21:40 +01:00
GDB Administrator
2fee907cfd Automatic date update in version.in 2023-05-31 00:00:47 +00:00
mengqinggang
7ad9de1188 LoongArch: opcodes: Add support for linker relaxation.
Set gas default to enable relax.

opcodes/ChangeLog:

	* loongarch-opc.c (struct loongarch_ASEs_option): New member relax
	with the default value 1.
2023-05-30 19:56:43 +08:00
mengqinggang
1b6fccd28d LoongArch: bfd: Add support for linker relaxation.
Add relax support and related relocs in bfd.

bfd/ChangeLog:

	* bfd-in2.h: Add relocs related to relax.
	* elfnn-loongarch.c (struct loongarch_elf_link_hash_table): New integer
	pointer (data_segment_phase) to monitor the data segment phase.
	(loongarch_elf_check_relocs): Swap B21/B26 reloc sequence.
	(loongarch_elf_adjust_dynamic_symbol): Fix code format.
	(loongarch_reloc_rewrite_imm_insn): Fix function call.
	(perform_relocation): Handle new relocs related to relax.
	(RELOCATE_CALC_PC32_HI20): Fix code format.
	(RELOCATE_CALC_PC64_HI32): Likewise.
	(loongarch_elf_relocate_section): Handle new relocs related to relax.
	(loongarch_relax_delete_bytes): New function.
	(loongarch_relax_pcala_addi): Likewise.
	(loongarch_relax_pcala_ld): Likewise.
	(bfd_elfNN_loongarch_set_data_segment_info): Likewise.
	(loongarch_relax_align): Likewise.
	(loongarch_elf_relax_section): Likewise.
	(bfd_elfNN_bfd_relax_section): New macro define.
	* elfxx-loongarch.c (reloc_bits): New bfd point parameter.
	(reloc_bits_b16): Likewise.
	(reloc_bits_b21): Likewise.
	(reloc_bits_b26): Likewise.
	(loongarch_adjust_reloc_bitsfield): Likewise.
	(reloc_bits_pcrel20_s2): New function.
	(loongarch_elf_add_sub_reloc): Likewise.
	(loongarch_elf_add_sub_reloc_uleb128): Likewise.
	(loongarch_write_unsigned_leb128): New function.
	* elfxx-loongarch.h (loongarch_adjust_reloc_bitsfield): New bfd point
	parameter.
	(bfd_elf32_loongarch_set_data_segment_info): New declare.
	(bfd_elf64_loongarch_set_data_segment_info): Likewise.
	(loongarch_write_unsigned_leb128): Likewise.
	* libbfd.h: Add relocs related to relax.
	* reloc.c: Add relocs related to relax.
2023-05-30 19:56:41 +08:00
GDB Administrator
93ec7cca41 Automatic date update in version.in 2023-05-30 00:00:40 +00:00