Commit Graph

4434 Commits

Author SHA1 Message Date
Nick Clifton
340640f710 Prune linker warnings about an executable stack being created with the -z execstack option.
* testsuite/lib/binutils-common.exp (prune_warnings_extra): Prune warnings about -z execstack creating an executable stack.
2023-06-21 12:10:03 +01:00
Maciej W. Rozycki
9012d7819c binutils/NEWS: Mention Sony Allegrex MIPS CPU support
Mention the addition of Sony Allegrex processor support to the MIPS port.

	binutils/
	* NEWS: Mention Sony Allegrex MIPS CPU support.
2023-06-15 15:17:38 +01: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
13527d85af Revert "MIPS: fix r6 testsuites"
This reverts commit ffc528aed5.  It was
applied unapproved.
2023-06-15 04:45:03 +01:00
Maciej W. Rozycki
3c0afdb789 Revert "MIPS: fix -gnuabi64 testsuite"
This reverts commit cb81e84c72.  It was
applied unapproved.
2023-06-15 04:45:03 +01:00
Alan Modra
ca5321d49a readelf/objdump remember_state memory leaks
* dwarf.c (display_debug_frames <DW_CFA_restore_state>): Do free
	invalid remember_state.
2023-06-09 12:56:12 +09:30
Alan Modra
f5c0d77088 objcopy memory leaks after errors
These aren't important at all, but tidy them in case they obscure
other more important leaks.

	* objcopy (copy_file): Close input bfd after errors.
2023-06-07 11:05:11 +09:30
Alan Modra
d3f340763b Re: loongarch readelf support
Commit 89c70cd358 apparently results in a bogus "value may be used
uninitialized" warning with some combination of compiler and
optimisation options.

	* readelf.c (target_specific_reloc_handling): Init value.
2023-06-06 20:09:39 +09:30
YunQiang Su
cb81e84c72 MIPS: fix -gnuabi64 testsuite
Test on:
	mips64-linux-gnuabi64
	mips64el-linux-gnuabi64
	mipsisa64-linux-gnuabi64
	mipsisa64el-linux-gnuabi64
	mipsisa64r2-linux-gnuabi64
	mipsisa64r2el-linux-gnuabi64
	mipsisa64r6-linux-gnuabi64
	mipsisa64r6el-linux-gnuabi64
2023-06-05 11:00:15 +08:00
YunQiang Su
ffc528aed5 MIPS: fix r6 testsuites
Introduce
	run_dump_test_o32l
	run_dump_test_n32l
	run_dump_test_n64l
Which use `-march=from-abi` for pre-R6 testcases,
like micromips/mips16e etc.

For cases doesn't use run_dump_test_*, we use
	-mips32r2 for micromips32
	-mips1 for mips16-32
	-march=from-abi for testcases to o32/n32/n64 both/all.

Replace `addi` with `addiu` for some cases for both r6 and pre-R6.

Introduce some new testcases for r6 with FPXX/FP64.
Introduce new testcase: comdat-reloc-r6.

Skip `default` in mips_arch_list_matching if triple is mipsisa*, due to:
  1)it will cannot match mipsr6@*.d: since mips32rN/mips64rN
    will always be used, it won't be a problem.
  2)some test think -march=mips64rN will alway true for mipsisa64rN,
    which is not true now.

This patch fix testsuite for all r6-default gnu triples:
  mipsisa32r6-linux-gnu
  mipsisa32r6el-linux-gnu
  mips-img-linux-gnu
  mipsel-img-linux-gnu
  mipsisa64r6-linux-gnu
  mipsisa64r6el-linux-gnu
2023-06-05 11:00:14 +08:00
Alan Modra
89c70cd358 Re: loongarch readelf support
Another segfault.

	* readelf.c (target_specific_reloc_handling): Sanity check
	loongarch reloc r_offset.
2023-06-03 17:17:57 +09:30
Alan Modra
74a965d8e0 loongarch readelf support
This fixes two buffer overflows found by fuzzers.

	* readelf.c (target_specific_reloc_handling): Sanity check
	loongarch reloc symbol index.  Don't apply reloc after errors.
	Reduce translation work of "invalid symbol index" error message.
2023-06-02 09:41:49 +09:30
Alan Modra
56e4ccc924 Minor objcopy optimisation for copy_relocations_in_section
* objcopy (copy_relocations_in_section): Don't read the relocs
	for STRIP_ALL if keep_specific_htab is empty.
2023-06-02 09:41:49 +09:30
Nick Clifton
10d6a2b1a0 Improve header information displayed with objdump -P for PE binaries.
* od-pe.c (targ_info): New array.
  (get_target_specific_info): New function.
  (decode_machine_number): Retire.  Use get_target_specific_info instead.
  (is_pe_object_magic): Likewise.
  (dump_pe_file_header): Display more information.
  Rework layout to be similar to that from 'objdump -p'.
  Add code to handle larger than normnal AOUT headers.
2023-05-30 15:43:24 +01:00
mengqinggang
7624446235 LoongArch: binutils: Add support for linker relaxation.
Add support for relocs related to relax to readelf.

binutils/ChangeLog:

	* readelf.c (target_specific_reloc_handling): Handle ULEB128 reloc.
	(is_32bit_inplace_add_reloc): Handle new reloc.
	(is_32bit_inplace_sub_reloc): Likewise.
	(is_64bit_inplace_add_reloc): Likewise.
	(is_64bit_inplace_sub_reloc): Likewise.
	(is_16bit_inplace_add_reloc): Likewise.
	(is_16bit_inplace_sub_reloc): Likewise.
	(is_8bit_inplace_add_reloc): Likewise.
	(is_8bit_inplace_sub_reloc): Likewise.
	(is_6bit_inplace_sub_reloc): Likewise.
	(is_6bit_inplace_add_reloc): New function.
	(apply_relocations): Handle new reloc.
	* testsuite/binutils-all/readelf.exp: Add -mno-relax option
	for LoongArch.
2023-05-30 19:56:45 +08:00
Nick Clifton
7b9e7db083 Add support for an ARMMAGIC value of 0xa00 to the PE dumper. 2023-05-30 11:42:16 +01:00
Alan Modra
796029320e arm-pe objdump -P
arm-pe looks to be a very old PE implementation, incompatible with
current arm-wince-pe.  arm-pe has different relocations and uses
ARMMAGIC which has this comment: "I just made this up".  Well, OK, I
don't know the history but it was probably before Microsoft "just made
up" their constants for ARM windows CE.

This patch supports objdump -P for arm-pe, and another magic constant
that may appear in object files.  (I don't think binutils generates
files using ARMV7PEMAGIC aka IMAGE_FILE_MACHINE_ARMNT.)

	* od-pe.c (is_pe_object_magic): Handle IMAGE_FILE_MACHINE_ARMNT
	and ARMMAGIC.
2023-05-30 12:59:55 +09:30
Alan Modra
9fa2b95974 Regen binutils POTFILES.in
for od-pe.c
2023-05-30 12:51:07 +09:30
Nick Clifton
45b8517aae Enhance objdump's --private option so that it can display the contents of PE format files.
* od-pe.c: New file: Dumps fields in PE format headers.
  * configure.ac (od_vectors): Add objdump_private_desc_pe for PE format targets. (od_files): Add od-pe for PE format targets.
  * configure: Regenerate.
  * Makefile.am (CFILES): Add od-pe.c (EXTRA_objdump_SOURCE): Likewise.
  * Makefile.in: Generate.
  * NEWS: Mention the new feature.
  * doc/binutils.texi: Document the new support.
  * objdump.c (wide_output): Change from local to global.
  * objdump.h (wide_output): Prototype. (objdump_private_desc_pe): Prototype.
  * testsuite/binutils-all/objdump.exp: Add a test of the new feature.
2023-05-26 15:41:20 +01:00
Alan Modra
7529ff1fcd PR29189, dlltool delaylibs corrupt float/double arguments
PR 29189
	* dlltool.c (i386_x64_trampoline): Save and restore xmm0-5.  Make
	use of parameter save area for integer arg regs.  Comment.
2023-05-25 16:57:16 +09:30
Alan Modra
bc227f4ccb Re: readelf: Support SHT_RELR/DT_RELR for -r
Revert value of DT_ENCODING to as it was before commit a7fd118627, and
adjust readelf.

include/
	* elf/common.h (DT_ENCODING): Set back to 32.
binutils/
	* readelf.c (struct filedata): Don't size dynamic_info array
	using DT_ENCODING.
2023-05-22 17:25:36 +09:30
Kuan-Lin Chen
f1cd8b94e7 RISC-V: Support subtraction of .uleb128.
96d6e190e9

There are some known limitations for now,

* Do not shrink the length of the uleb128 value, even if the value is reduced
after relaxations.  Also reports error if the length grows up.

* The R_RISCV_SET_ULEB128 needs to be paired with and be placed before the
R_RISCV_SUB_ULEB128.

bfd/
	* bfd-in2.h: Regenerated.
	* elfnn-riscv.c (perform_relocation): Perform R_RISCV_SUB_ULEB128 and
	R_RISCV_SET_ULEB128 relocations.  Do not shrink the length of the
	uleb128 value, and report error if the length grows up.  Called the
	generic functions, _bfd_read_unsigned_leb128 and _bfd_write_unsigned_leb128,
	to encode the uleb128 into the section contents.
	(riscv_elf_relocate_section): Make sure that the R_RISCV_SET_ULEB128
	must be paired with and be placed before the R_RISCV_SUB_ULEB128.
	* elfxx-riscv.c (howto_table): Added R_RISCV_SUB_ULEB128 and
	R_RISCV_SET_ULEB128.
	(riscv_reloc_map): Likewise.
	(riscv_elf_ignore_reloc): New function.
	* libbfd.h: Regenerated.
	* reloc.c (BFD_RELOC_RISCV_SET_ULEB128, BFD_RELOC_RISCV_SUB_ULEB128):
	New relocations to support .uleb128 subtraction.
gas/
	* config/tc-riscv.c (md_apply_fix): Added BFD_RELOC_RISCV_SET_ULEB128
	and BFD_RELOC_RISCV_SUB_ULEB128.
	(s_riscv_leb128): Updated to allow uleb128 subtraction.
	(riscv_insert_uleb128_fixes): New function, scan uleb128 subtraction
	expressions and insert fixups for them.
	(riscv_md_finish): Called riscv_insert_uleb128_fixes for all sections.
include/
	* elf/riscv.h ((R_RISCV_SET_ULEB128, (R_RISCV_SUB_ULEB128): Defined.
ld/
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
	* testsuite/ld-riscv-elf/uleb128*: New testcase for uleb128 subtraction.
binutils/
	* testsuite/binutils-all/nm.exp: Updated since RISCV supports .uleb128.
2023-05-19 16:24:10 +08:00
Alan Modra
6109320673 Re: stack overflow in debug_write_type
Apparently u.kindirect->slot can point at a NULL.

	* debug.c (debug_write_type): Don't segfault on NULL indirect.
2023-05-10 23:10:19 +09:30
Enze Li
d9cc4b060d Correct a spelling mistake in the binutils README file. 2023-05-09 11:44:22 +01:00
Alan Modra
55a75aae9d stack overflow in debug_write_type
Another fuzzer attack.  This one was a "set" with elements using an
indirect type pointing back at the set.  The existing recursion check
only prevented simple recursion.

	* debug.c (struct debug_type_s): Add mark.
	(debug_write_type): Set mark and check before recursing into
	indirect types.
2023-05-09 17:11:46 +09:30
Nick Clifton
b545d4239b Remove Dimity Diky as MSP430 maintainer. 2023-05-02 13:33:53 +01:00
Alan Modra
4a8635cbec binutils runtest $CC
I noticed in the binutile Makefile that runtest is being invoked with
CC, CC_FOR_BUILD and other compiler related flags in the environment.
That doesn't work.  Those variables ought to be passed on the runtest
command line.

After fixing that I had some fails due to binutils testprog.c now
being compiled with the default "-g -O2" picked up in
CFLAGS_FOR_TARGET.  Hack around that by passing -O0.

Also, with the binutils testsuite now taking notice of CC_FOR_TARGET,
I found a couple of debuginfod.exp fails with one of my compilers that
happened to be built without --debug-id being enabled by default.

	* Makefile.am (check-DEJAGNU): Pass $CC and other variable on
	the runtest command line rather than futilely in the
	environment.  Add -O0 to CFLAGS_FOR_TARGET.
	* Makefile.in: Regenerate.
	* testsuite/binutils-all/debuginfod.exp: Compile testprog.c
	with -Wl,--build-id.
2023-04-26 10:32:07 +09:30
Alan Modra
c1eb3cd205 objcopy of archives tidy
This makes sure the input element bfd is closed before exiting the
loop copying elements.

	* objcopy.c (copy_archive): Rename output_bfd to output_element.
	Localise last_element.  Close this_element in more error cases.
2023-04-24 20:59:38 +09:30
YunQiang Su
32f1c80375 MIPS: support mips*64 as CPU and gnuabi64 as ABI
For MIPS64r6 ports, Debian as an example, `mipsisa64r6el` is
used as the cpu name in triple.
Let's recognize them by `mips*64*(el)`.

For 64bit Ports, like Debian's mips64el and mips64r6el ports,
`gnuabi64` is used as the abi section.
Let's use N64 abi by default for the triple with gnuabi64.
2023-04-23 14:32:43 +08:00
Nick Clifton
8e7785b4bd Add a SECURITY.txt file describing the GNU Binutils' project's stance on security related bugs. 2023-04-20 16:52:11 +01:00
Alan Modra
329dd2b6fc ubsan: signed integer overflow in display_debug_lines_raw
This one was caused by me unnecessarily promoting an "int adv" to
"int64_t adv".  The expression overflowing was 4259 + 9223372036854775807
with the left number being unsigned int.

	* dwarf.h (DWARF2_Internal_LineInfo): Replace unsigned short
	with uint16_t and unsigned char with uint8_t.  Make li_line_base
	an int8_t.
	* dwarf.c (display_debug_lines_raw): Revert "adv" back to an int.
2023-04-20 09:03:53 +09:30
Nick Clifton
28ab94f51d Fix: readelf: loc_offset XX too big
PR 30355
  * dwarf.c (read_and_display_attr_value): Correctly handle DW_loclistx attributes that index a version 5 .debug_loclists section.
2023-04-19 11:48:24 +01:00
Alan Modra
341eba4f9d objdump use of uninitialised value in pr_string_field
PR 30365
	* rdcoff.c (parse_coff_struct_type): Leave bitsize zero when no
	auxents.
2023-04-18 10:24:41 +09:30
Alan Modra
34d63622f6 objdump buffer overflow in fetch_indexed_string
PR 30361
	* dwarf.c (fetch_indexed_string): Sanity check string index.
2023-04-18 10:24:40 +09:30
Nick Clifton
c53c6186c8 Make the .rsrc section read only.
PR 30142
  * peXXigen.c (_bfd_XXi_swap_scnhdr_out): Do not force the .rsrc section to be writeable.
  * rescoff.c (write_coff_file): Add the SEC_READONLY flag to the .rsrc section.
2023-04-17 17:19:21 +01:00
Nick Clifton
7bb9e56c6a Replace an assertion in the dwarf code with a warning message.
PR 30327
  * dwarf.c (read_and_display_attr_value): Warn if the number of views is greater than the number of locations.
2023-04-11 17:24:09 +01:00
Nick Clifton
9f1c612b7c Fix an attempt to allocate an excessive amount of memory when parsing a corrupt DWARF file.
PR 30313
  * dwarf.c (display_debug_lines_decoded): Check for an overlarge number of files or directories.
2023-04-11 16:14:23 +01:00
Nick Clifton
688fe114cd Fix a potential illegal memory access when displaying corrupt DWARF information.
PR 30312
  * dwarf.c (prealloc_cu_tu_list): Always allocate at least one entry.
2023-04-11 15:59:07 +01:00
Nick Clifton
45f5fe468b Fix an attempt to allocate an overlarge amount of memory when decoding a corrupt ELF format file.
PR 30311
  * readelf.c (uncompress_section_contents): Check for a suspiciously large uncompressed size.
2023-04-11 15:30:02 +01:00
Alan Modra
11aa9f628e Re: objcopy write_debugging_info memory leaks
Oops, tried to free too much

	* wrstabs.c (write_stabs_in_sections_debugging_info): Don't
	free strings.
2023-04-06 21:27:54 +09:30
Alan Modra
a5f3ca4823 objdump print_debugging_info memory leaks
Fix memory leaks and do a general tidy of the code for printing coff
and stabs debug.

	* prdbg.c: Delete unnneeded forward function declarations.
	Delete unnecessary casts throughout.  Free all strings
	returned from pop_type throughout file.
	(struct pr_stack): Delete "num_parents".  Replace tests for
	"num_parents" non-zero with tests of "parents" non-NULL
	throughout.  Free "parents" before assigning, and set to NULL
	after freeing.  Remove const from "method".  Always strdup
	strings assigned to method, and free before assigning.
	(print_debugging_info): Free info.stack and info.filename.
2023-04-06 09:52:17 +09:30
Alan Modra
ff93c7b1a2 objdump -g on gcc COFF/PE files
objdump -g can't be used much.  Trying to dump PE files invariably
seems to run into "debug_name_type: no current file" or similar
errors, because parse_coff expects a C_FILE symbol to be the first
symbol.  Dumping -gstabs output works since the N_SO stab is present.
Pre-setting the file name won't hurt stabs dumping.

	* rddbg.c (read_debugging_info): Call debug_set_filename.
2023-04-06 09:51:38 +09:30
Alan Modra
41e6ffcecb objcopy write_debugging_info memory leaks
The old stabs code didn't bother too much about freeing memory.
This patch corrects that and avoids some dubious copying of strings.

	* objcopy.c (write_debugging_info): Free both strings and
	syms on failure to create sections.
	* wrstabs.c: Delete unnecessary forward declarations and casts
	throughout file.
	(stab_write_symbol_and_free): New function.  Use it
	throughout, simplifying return paths.
	(stab_push_string): Don't strdup string.  Use it thoughout
	for malloced strings.
	(stab_push_string_dup): New function.  Use it throughout for
	strings in auto buffers.
	(write_stabs_in_sections_debugging_info): Free malloced memory.
	(stab_enum_type): Increase buffer sizing for worst case.
	(stab_range_type, stab_array_type): Reduce buffer size.
	(stab_set_type): Likewise.
	(stab_method_type): Free args on error return.  Correct
	buffer size.
	(stab_struct_field): Fix memory leaks.
	(stab_class_static_member, stab_class_baseclass): Likewise.
	(stab_start_class_type): Likewise.  Correct buffer size.
	(stab_class_start_method): Correct buffer size.
	(stab_class_method_var): Free memory on error return.
	(stab_start_function): Fix "rettype" memory leak.
2023-04-06 09:51:38 +09:30
Alan Modra
19cacf6729 Use bfd_alloc memory for read_debugging_info storage
Trying to free malloc'd memory used by the stabs and coff debug info
parsers is complicated, and traversing the trees generated requires a
lot of code.  It's better to bfd_alloc the memory which allows it all
to be freed without fuss when the bfd is closed.  In the process of
doing this I reverted most of commit a633691333.

Some of the stabs handling code grows arrays of pointers with realloc,
to deal with arbitrary numbers of fields, function args, etc.  The
code still does that but copies over to bfd_alloc memory when
finished.  The alternative is to parse twice, once to size, then again
to populate the arrays.  I think that complication is unwarranted.

Note that there is a greater than zero chance this patch breaks
something, eg. that I missed an attempt to free obj_alloc memory.
Also it seems there are no tests in the binutils testsuite aimed at
exercising objdump --debugging.

	* budbg.h (finish_stab, parse_stab): Update prototypes
	* debug.c: Include bucomm.h.
	(struct debug_handle): Add "abfd" field.
	(debug_init): Add "abfd" param.  bfd_alloc handle.
	(debug_xalloc, debug_xzalloc): New functions.  Use throughout
	in place of xmalloc and memset.
	(debug_start_source): Remove "name_used" param.
	* debug.h (debug_init, debug_start_source): Update prototypes.
	(debug_xalloc, debug_xzalloc): Declare.
	* objcopy.c (copy_object): Don't free dhandle.
	* objdump.c (dump_bfd): Likewise.
	* rdcoff.c (coff_get_slot): Add dhandle arg.  debug_xzalloc
	memory in place of xcalloc.  Update callers.
	(parse_coff_struct_type): Don't leak on error return.  Copy
	fields over to debug_xalloc memory.
	(parse_coff_enum_type): Copy names and vals over the
	debug_xalloc memory.
	* rddbg.c (read_debugging_info): Adjust debug_init call.
	Don't free dhandle.
	(read_section_stabs_debugging_info): Don't free shandle.
	Adjust parse_stab call.  Call finish_stab on error return.
	(read_symbol_stabs_debugging_info): Similarly.
	* stabs.c (savestring): Delete unnecessary forward declaration.
	Add dhandle param.  debug_xalloc memory.  Update callers.
	(start_stab): Delete unnecessary casts.
	(finish_stab): Add "emit" param.  Free file_types, so_string,
	and stabs handle.
	(parse_stab): Delete string_used param.  Revert code dealing
	with string_used.  Copy so_string passed to debug_set_filename
	and stored as main_filename to debug_xalloc memory.  Similarly
	for string passed to debug_start_source and push_bincl.  Copy
	args to debug_xalloc memory.  Don't leak args.
	(parse_stab_enum_type): Copy names and values to debug_xalloc
	memory.  Don't free name.
	(parse_stab_struct_type): Don't free fields.
	(parse_stab_baseclasses): Delete unnecessary cast.
	(parse_stab_struct_fields): Return debug_xalloc fields.
	(parse_stab_cpp_abbrev): Use debug_xalloc for _vb$ type name.
	(parse_stab_one_struct_field): Don't free name.
	(parse_stab_members): Copy variants and methods to
	debug_xalloc memory.  Don't free name or argtypes.
	(parse_stab_argtypes): Use debug_xalloc memory for physname
	and args.
	(push_bincl): Add dhandle param.  Use debug_xalloc memory.
	(stab_record_variable): Use debug_xalloc memory.
	(stab_emit_pending_vars): Don't free var list.
	(stab_find_slot): Add dhandle param.  Use debug_xzalloc
	memory.  Update all callers.
	(stab_find_tagged_type): Don't free name.  Use debug_xzalloc.
	(stab_demangle_qualified): Don't free name.
	(stab_demangle_template): Don't free s1.
	(stab_demangle_args): Tidy pvarargs refs.  Copy *pargs on
	success to debug_xalloc memory, free on failure.
	(stab_demangle_fund_type): Don't free name.
	(stab_demangle_v3_arglist): Copy args to debug_xalloc memory.
	Don't free dt.
2023-04-04 12:47:56 +09:30
Alan Modra
a633691333 rddbg.c stabs FIXMEs
This should sort out some very old FIXMEs in code handling stabs
debug info.  Necessary if we are to fuss over freeing up memory before
objdump and objcopy exit.  It is of course better from a user
viewpoint to *not* free memory, which takes some time, and leave that
to process exit.  The only reason to do so is that having many memory
leaks in binutils/ code tends to hide leaks in bfd/ or opcodes/, which
we should care about.

	* budbg.h (parse_stab): Update prototype.
	* debug.h (debug_start_source): Update prototype.
	* debug.c (debug_start_source): Add name_used.  Set if stashed.
	* rddbg.c (read_symbol_stabs_debugging_info): Always malloc
	stab string passed to parse_stab.  Free stab string when
	unreferenced.
	(read_section_stabs_debugging_info): Likewise, and strings
	section contents.
	* stabs.c (parse_stab): Add string_used param.  Set if string
	stashed.  Pass to debug_start_source.  Realloc file_types
	array rather that using malloc.  Clarify comment about
	debug_make_indirect_type.
2023-04-03 07:29:35 +09:30
Alan Modra
31991eaaee Memory leak in process_abbrev_set
We may have added some abbrevs to the list before hitting an error.
Free the list elements too.  free_abbrev_list returns list->next so we
need to init it earlier to avoid an uninitialised memory access.

	* dwarf.c (process_abbrev_set): Call free_abbrev_list on errors.
	Set list->next earlier.
2023-04-03 07:29:01 +09:30
Nick Clifton
8d17c53b8d Fix an illegal memory access triggered by parsing corrupt DWARF info.
PR 30284
  * dwarf.c (read_and_display_attr_value): Detect and ignore negative base values.
2023-03-30 11:04:53 +01:00
Alan Modra
45fec14c02 Tidy leaked objcopy memory
* objcopy.c (delete_symbol_htabs): Also free symbols.
	(write_debugging_info): Free strings and syms once written.
	* wrstabs.c (write_stabs_in_sections_debugging_info): memset
	entire info struct.  Free hash tables before returning.  Free
	syms on error return.
2023-03-30 15:18:02 +10:30
Alan Modra
a2276a6d67 Tidy memory on addr2line failures
* addr2line.c (process_file): Close bfd on error paths.
2023-03-30 15:18:02 +10:30
Alan Modra
a2c7ca15a5 Use stdint types in coff internal_auxent
long is a poor choice of type to store 32-bit values read from
objects files by H_GET_32.  H_GET_32 doesn't sign extend so tests like
that in gdb/coffread.c for "negative" values won't work if long is
larger than 32 bits.  If long is 32-bit then code needs to be careful
to not accidentally index negative array elements.  (I'd rather see a
segfault on an unmapped 4G array index than silently reading bogus
data.)  long is also a poor choice for x_sect.s_scnlen, which might
have 64-bit values.  It's better to use unsigned exact width types to
avoid surprises.

I decided to change the field names too, which makes most of this
patch simply renaming.  Besides that there are a few places where
casts are no longer needed, and where printf format strings or tests
need adjusting.

include/
	* coff/internal.h (union internal_auxent): Use unsigned stdint
	types.  Rename l fields to u32 and u64 as appropriate.
bfd/
	* coff-bfd.c,
	* coff-rs6000.c,
	* coff64-rs6000.c,
	* coffcode.h,
	* coffgen.c,
	* cofflink.c,
	* coffswap.h,
	* peXXigen.c,
	* xcofflink.c: Adjust to suit internal_auxent changes.
binutils/
	* rdcoff.c: Adjust to suit internal_auxent changes.
gas/
	* config/obj-coff.h,
	* config/tc-ppc.c: Adjust to suit internal_auxent changes.
gdb/
	* coffread.c,
	* xcoffread.c: Adjust to suit internal_auxent changes.
ld/
	* pe-dll.c: Adjust to suit internal_auxent changes.
2023-03-27 21:58:46 +10:30