Commit Graph

4669 Commits

Author SHA1 Message Date
Ying Huang
d173146d9b MIPS: Change all E_MIPS_* to EF_MIPS_* 2023-11-10 14:03:17 +00:00
Tom de Vries
07a9e70911 [readelf] Handle unknown name of main in .gdb_index section
When compiling hello world and adding a v9 .gdb-index section:
...
$ gcc -g hello.c
$ gdb-add-index a.out
...
readelf shows it as:
...
Shortcut table:
Language of main: unknown: 0
Name of main: ^A
...

The documentation of gdb says about the "Name of main" that:
...
This value must be ignored if the value for the language of main is zero.
...

Implement this approach in display_gdb_index, such that we have instead:
...
Shortcut table:
Language of main: unknown: 0
Name of main: <unknown>
...

Tested on x86_64-linux.

Approved-By: Jan Beulich <jbeulich@suse.com>
2023-10-24 12:35:08 +02:00
Clément Chigot
be381d7175 objcopy: fix typo in --heap and --stack parser
The help says that <reserve> and <commit> should be separated by a ","
but the implementation is checking for ".". Having two numbers being
separated by a "." could be confusing, thus adjust the implementation to
match the help syntax.

binutils/ChangeLog:

	* objcopy.c (copy_main): Set separator to "," between <reserve>
	and <commit> for --heap and --stack.
	* doc/binutils.texi: Add <commit> for --heap and --stack.
2023-10-23 10:17:47 +02:00
Neal Frager
d605374748 bfd: microblaze: Add 32_NONE reloc type
This patch adds the R_MICROBLAZE_32_NONE relocation type.
This is a 32-bit reloc that stores the 32-bit pc relative
value in two words (with an imm instruction).

Add test case to gas test suite.

Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
2023-10-20 07:12:30 -07:00
Clément Chigot
9f9073e5b8 objcopy: Fix name of the field modified by pe_stack_reserve. 2023-10-16 10:37:23 +02:00
Alan Modra
f22f27f46c asan: null dereference in read_and_display_attr_value
This fixes multiple places in read_and_display_attr_value dealing with
range and location lists that can segfault when debug_info_p is NULL.
Fuzzed object files can contain arbitrary DW_FORMs.

	* dwarf.c (read_and_display_attr_value): Don't dereference NULL
	debug_info_p.
2023-10-10 22:17:29 +10:30
Tom de Vries
9847ba8f08 [readelf] Handle .gdb_index section version 9
Add the abilitity to print a v9 .gdb_index section.

The v9 section contains an extra table, which is printed as follows:
...
Shortcut table:
Language of main: Fortran 95
Name of main: contains_keyword
...

[ For the example, I used the exec of gdb test-case
gdb.fortran/nested-funcs-2-exp when running the test-case with target board
cc-with-gdb-index. ]

Tested on x86_64-linux.

Approved-By: Nick Clifton <nickc@redhat.com>
2023-10-10 10:26:40 +02:00
Michael J. Eager
a3f6124483 Revert "opcodes: microblaze: Add new bit-field instructions"
This reverts commit 6bbf249557.

Maciej W. Rozycki <macro@orcam.me.uk>:
 Yet it has caused numerous regressions:

microblaze-elf  +FAIL: unordered .debug_info references to .debug_ranges
microblaze-elf  +FAIL: binutils-all/pr26548
microblaze-elf  +FAIL: readelf -Wwi pr26548e (reason: unexpected output)
microblaze-elf  +FAIL: readelf --debug-dump=loc locview-1 (reason: unexpected output) Yet it has caused numerous regressions:
microblaze-elf  +FAIL: unordered .debug_info references to .debug_ranges
microblaze-elf  +FAIL: binutils-all/pr26548
microblaze-elf  +FAIL: readelf -Wwi pr26548e (reason: unexpected output)
...
2023-10-07 15:33:10 -07:00
Neal Frager
6bbf249557 opcodes: microblaze: Add new bit-field instructions
This patches adds new bsefi and bsifi instructions.
BSEFI- The instruction shall extract a bit field from a
register and place it right-adjusted in the destination register.
The other bits in the destination register shall be set to zero.
BSIFI- The instruction shall insert a right-adjusted bit field
from a register at another position in the destination register.
The rest of the bits in the destination register shall be unchanged.

Further documentation of these instructions can be found here:
https://docs.xilinx.com/v/u/en-US/ug984-vivado-microblaze-ref

This patch has been tested for years of AMD Xilinx Yocto
releases as part of the following patch set:

https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils

Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
Signed-off-by: Ibai Erkiaga <ibai.erkiaga-elorza@amd.com>
Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
2023-10-06 10:53:45 -07:00
A. Wilcox
c4e0d285cf Fix: addr2line testsuite fails when targeting PowerPC 64 big-endian with ELFv2 ABI
PR 30916
  * testsuite/binutils-all/addr2line.exp: Do not use PowerPC specific options when working with a MUSL target.
2023-10-05 14:49:51 +01:00
YunQiang Su
1c9b44fe07 MIPS: Fix `readelf -S bintest' test for n64 targets
Add a 64-bit traditional MIPS dump variant for the `readelf -S bintest'
test from binutils-all/readelf.exp, using a filename suffix according to
the rules set there, removing:

FAIL: readelf -S bintest

regressions with `mips64-linux-gnuabi64', `mips64el-linux-gnuabi64',
`mips64-openbsd', and `mips64el-openbsd' targets, which default to the
n64 ABI and consequently produce a section layout that is different from
what the generic dump pattern covers.

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>

	binutils/
	* testsuite/binutils-all/readelf.s-64-tmips: New test variant.
2023-10-03 12:41:02 +01:00
Vsevolod Alekseyev
8c7125feaa Fix: readelf..info misreports DW_FORM_loclistx, DW_FORM_rnglistx
PR 29267
  * dwarf.c (fetch_indexed_value): Delete. (fetch_indexed_offset): Correct base address calculation. (read_and_display_attr_value): Replace uses of fetch_indexed_value with fetch_indexed_offset.
2023-10-03 09:27:27 +01:00
H.J. Lu
832ca732b8 x86-64: Add -z mark-plt and -z nomark-plt
The PLT entry in executables and shared libraries contains an indirect
branch, like

 	jmp *foo@GOTPCREL(%rip)
	push $index_foo
	jmp .PLT0

or

	endbr64
 	jmp *foo@GOTPCREL(%rip)
 	NOP padding

which is used to branch to the function, foo, defined in another object.
Each R_X86_64_JUMP_SLOT relocation has a corresponding PLT entry.

The dynamic tags have been added to the x86-64 psABI to mark such PLT
entries:

6d824a52a4

Add an x86-64 linker option, -z mark-plt, to mark PLT entries with

 #define DT_X86_64_PLT     (DT_LOPROC + 0)
 #define DT_X86_64_PLTSZ   (DT_LOPROC + 1)
 #define DT_X86_64_PLTENT  (DT_LOPROC + 3)

1. DT_X86_64_PLT: The address of the procedure linkage table.
2. DT_X86_64_PLTSZ: The total size, in bytes, of the procedure linkage
table.
3. DT_X86_64_PLTENT: The size, in bytes, of a procedure linkage table
entry.

and set the r_addend field of the R_X86_64_JUMP_SLOT relocation to the
memory offset of the indirect branch instruction.  The dynamic linker
can use these tags to update the PLT section to direct branch.

bfd/

	* elf-linker-x86.h (elf_linker_x86_params): Add mark_plt.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Set the
	r_addend of R_X86_64_JUMP_SLOT to the indirect branch offset
	in PLT entry for -z mark-plt.
	* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Add
	DT_X86_64_PLT, DT_X86_64_PLTSZ and DT_X86_64_PLTENT for
	-z mark-plt.
	(_bfd_x86_elf_finish_dynamic_sections): Set DT_X86_64_PLT,
	DT_X86_64_PLTSZ and DT_X86_64_PLTENT.
	(_bfd_x86_elf_get_synthetic_symtab): Ignore addend for
	JUMP_SLOT relocation.
	(_bfd_x86_elf_link_setup_gnu_properties): Set
	plt_indirect_branch_offset.
	* elfxx-x86.h (elf_x86_plt_layout): Add plt_indirect_branch_offset.

binutils/

	* readelf.c (get_x86_64_dynamic_type): New function.
	(get_dynamic_type): Call get_x86_64_dynamic_type.

include/

	* elf/x86-64.h (DT_X86_64_PLT): New.
	(DT_X86_64_PLTSZ): Likewise.
	(DT_X86_64_PLTENT): Likewise.

ld/

	* ld.texi: Document -z mark-plt and -z nomark-plt.
	* emulparams/elf32_x86_64.sh: Source x86-64-plt.sh.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/x86-64-plt.sh: New file.
	* testsuite/ld-x86-64/mark-plt-1.s: Likewise.
	* testsuite/ld-x86-64/mark-plt-1a-x32.d: Likewise.
	* testsuite/ld-x86-64/mark-plt-1a.d: Likewise.
	* testsuite/ld-x86-64/mark-plt-1b-x32.d: Likewise.
	* testsuite/ld-x86-64/mark-plt-1b.d: Likewise.
	* testsuite/ld-x86-64/mark-plt-1c-x32.d: Likewise.
	* testsuite/ld-x86-64/mark-plt-1c.d: Likewise.
	* testsuite/ld-x86-64/mark-plt-1d-x32.d: Likewise.
	* testsuite/ld-x86-64/mark-plt-1d.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run -z mark-plt tests.
2023-09-29 07:58:53 -07:00
Nick Clifton
68510906a9 Update README file's installation instructions 2023-09-29 11:23:25 +01:00
Frederic Cambus
73b22419ed Add support to readelf for the PT_OPENBSD_NOBTCFI segment type. 2023-09-28 13:39:01 +01:00
Aaron Merey
28bc495137 config/debuginfod.m4: Add check for libdebuginfod 0.188
Add check for libdebuginfod 0.188 in AC_DEBUGINFOD and if found
define macro HAVE_LIBDEBUGINFOD_FIND_SECTION.

This macro indicates support for downloading ELF sections from
debuginfod servers.
2023-09-27 15:11:13 -04:00
Nick Clifton
854f72b36d Fix a snafu in the new tests for reproducible archives that assumed a umask of 22. 2023-09-26 16:27:28 +01:00
Nick Clifton
6f56739807 Allow the use of SOURCE_DATE_EPOCH in the timestamps for members of static archives.
(For some reason this commit was not applied at the time that the patch was approved).
2023-09-26 14:07:23 +01:00
Vsevolod Alekseyev
84102ebc29 Fix readelf's display of dwarf v5 range lists
PR 30792
  * dwarf.h (struct debug_info): Remove range_versions field.
  * dwarf.c (fetch_indexed_offset): New function. (read_and_display_attr_value): Use it for DW_FORM_rnglistx. Remove code to initialise range_versions. (skip_attribute): New function. (read_bases): Read and reccord all range and address bases in a CU. (process_debug_info): Call read_bases. (display_debug_rnglists): Rename to display_debug_rnglists_unit_header and only display the range list header information. (display_debug_ranges): Adjust.
2023-09-25 18:01:31 +01:00
Claudiu Zissulescu
f14cd06ba4 Revert "arc: Update NEWS files"
This reverts commit a47d304b12.
2023-09-25 17:01:47 +03:00
Claudiu Zissulescu
a47d304b12 arc: Update NEWS files
Add ARCv3 support in NEWS files.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2023-09-25 11:33:12 +03:00
Claudiu Zissulescu
f0a3c3dd52 arc: Update binutils arc predicate for tests.
binutils/testsuite/binutils-all
xxxx-xx-xx  Claudiu Zissulescu  <claziss@synopsys.com>

	* binutils/testsuite/binutils-all/arc/objdump.exp: Update predicate.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2023-09-25 10:32:52 +03:00
Alan Modra
765a0c0a86 readelf.c 'ext' may be used uninitialized
* readelf.c (display_lto_symtab): Init ext.
2023-09-20 08:23:48 +09:30
Nick Clifton
b6ac461ace readelf: Add option to display the names of sections referenced by symbols.
PR 30684
  * readelf.c (extra_sym_info): New variable. (section_name_valid): Also check for filedata being NULL. (section_name_print): Delete. (section_index_real): New function.  Returns true if the given section index references a real section. (print_symbol): Rename to print_sumbol_name. (printable_section_name): Use a rotating array of static buffers for the return string. (printable_section_name_from_index): Merge code from dump_relocations and get_symbol_index_type into here. (long_option_values): Add OPTION_NO_EXTRA_SYM_INFO. (options): Add "extra-sym-info" and "no-extra-sym-info". (usage): Mention new options. (parse_args): Parse new options. (get_symbol_index_type): Delete. (print_dynamic_symbol_size): Rename to print_symbol_size. (print_dynamic_symbol): Rename to print_symbol. (print_symbol_table_heading): New function. (process_symbol_table): Use new function.
  * doc/binutils.texi: Document the new option.
  * NEWS: Mention the new feature.
2023-09-05 11:08:23 +01:00
Nicolas Boulenguez
eb5b52158f PR30806, CPPFLAGS are missing for bfd/chew, syslex_wrap and sysinfo
PR 30806
bfd/
	* doc/local.mk (doc/chew.stamp): Add CPPFLAGS_FOR_BUILD.
	* Makefile.in: Regenerate.
binutils/
	* Makefile.am (syslex_wrap.@OBJEXT@): Add CPPFLAGS_FOR_BUILD.
	(sysinfo.@OBJEXT@): Likewise.
	* Makefile.in: Regenerate.
2023-09-01 09:18:05 +09:30
Alan Modra
aa1e22eb8d objdump: Free sorted_syms on error path
* objdump.c (disassemble_data): Free sorted_syms before returning.
2023-08-30 11:22:23 +09:30
Alan Modra
0283863037 binutils/dwarf.c abbrev list leak
* dwarf.c (process_debug_info): Call free_abrev_list on
	return paths.
2023-08-30 11:22:23 +09:30
Alan Modra
a422bb9db1 Re: readelf/objdump: Handle DWARF info with mixed types of range section
PR 30791
	* dwarf.c (free_debug_information): Free range_versions.
2023-08-30 11:22:23 +09:30
Nicolas Boulenguez
90de8f9c80 readelf: typos in user messages 2023-08-29 16:04:47 +01:00
Nick Clifton
d367563d55 Correct PR number in previous delta 2023-08-23 11:40:59 +01:00
Nick Clifton
589d38af0d readelf/objdump: Handle DWARF info with mixed types of range section.
PR 30791
  * dwarf.h (debug_info): Add range_versions field.
  * dwarf.c (read_and_display_attr_value): When recording a range arribute also ecord the dwarf version number.
  (is_range_list_for_this_section): New function.
  (display_debug_ranges): Only show debug ranges whose version is suitable for the secction being displayed.
2023-08-23 11:36:25 +01:00
Alan Modra
8c8145a43e bfd_get_symbol_leading_char vs. ""
Some places matching the first char of a string against
bfd_get_symbol_leading_char, which may be zero, didn't check for the
string being "".  This patch adds the check to stop accesses past the
end of the string and potential buffer overruns.
The dlltool one was found by oss-fuzz quite a while ago.

bfd/
	* cofflink.c (_bfd_coff_link_input_bfd): Ensure a zero
	bfd_get_symbol_leading_char doesn't lead to accessing past the
	zero string terminator.
	* linker.c (bfd_wrapped_link_hash_lookup): Likewise.
	(unwrap_hash_lookup): Likewise.
binutils/
	* dlltool.c (scan_filtered_symbols): Ensure a zero
	bfd_get_symbol_leading_char doesn't lead to accessing past the
	zero string terminator.
2023-08-23 10:07:45 +09:30
Alan Modra
8032f75b29 objdump: file name table entry count check
Fuzzers have found that objdump -W takes a really long time if
the entry count uleb is ridiculously large, and format attributes
don't consume data (which doesn't make sense for a table of names).

	* dwarf.c (display_formatted_table): Sanity check count of
	table entries.
2023-08-22 11:41:37 +09:30
Alan Modra
bb8b2f633e Re: kvx: New port.
Add files submitted on the mailing list but somehow not committed.
2023-08-22 09:35:55 +09:30
Luis Machado
11e3488d3f aarch64/sme2: Teach binutils/BFD about the NT_ARM_ZT register set
The Scalable Matrix Extension v2 (SME2) defines a new register, ZT0, that
the Linux Kernel handles through a new NT_ARM_ZT register set.

Teach binutils/BFD about it so that gdb can make use of it for reading
and writing core files.  This also enables readelf/objdump to show the
correct identification for the NT_ARM_ZT register set.

Validated under Fast Models.
2023-08-21 12:43:43 +01:00
Paul Iannetta
6e712424f5 kvx: New port. 2023-08-16 14:22:54 +01:00
Alan Modra
9381cdb1fb Remove fall-back prune_warnings
No one should be using versions of dejagnu without prune_warnings,
which was available in 1996 (dejagnu-1.3).

binutils/
	* testsuite/lib/binutils-common.exp: Remove fallback prune_warnings.
gas/
	* testsuite/lib/gas-defs.exp: Remove fallback prune_warnings.
2023-08-14 17:07:19 +09:30
Alan Modra
6a6859cbff regen config
This regenerates config files changed by the previous 44 commits.
Note that subject lines in these commits mostly match the gcc git
originating commit.
2023-08-12 10:27:57 +09:30
Alan Modra
e416bd75c3 warn unused result for bfd IO functions
This patch fixes all the warnings I found in bfd, binutils and ld,
plus some bitrotted COFF_GO32 code that tried to allocate -168ul
bytes.  When the malloc fail was reported these testsuite fails
resulted:

i386-go32  +FAIL: go32 stub
i386-go32  +ERROR: tcl error sourcing /home/alan/src/binutils-gdb/ld/testsuite/ld-i386/i386.exp.
i386-go32  +ERROR: couldn't open "tmpdir/go32stub": no such file or directory
i386-go32  +FAIL: ld-scripts/sane1
i386-go32  +FAIL: ld-scripts/assign-loc
i386-go32  +FAIL: ld-scripts/pr18963

This does result in some warnings in gdb which are fixed in a followup
patch.

bfd/
	* bfdio.c (bfd_read, bfd_write): Add ATTRIBUTE_WARN_UNUSED_RESULT.
	(bfd_tell, bfd_stat, bfd_seek, bfd_mmap): Likewise.
	* bfd-in2.h: Regenerate.
	* coff-rs6000.c (xcoff_write_armap_big) Don't ignore bfd_write
	return value.
	(xcoff_generate_rtinit): Likewise.  Also free data_buffer and
	string_table before returning.
	* coff64-rs6000.c (xcoff64_generate_rtinit): Likewise.
	* coff-stgo32.c (go32exe_check_format): Don't ignore bfd_seek
	return value.
	* coffcode.h (coff_apply_checksum): Don't ignore bfd_write return.
	(coff_write_object_contents <COFF_GO32>): Likewise, and bfd_malloc.
	Fix bitrotted code to look for first section with non-zero filepos.
	* elf64-ia64-vms.c (elf64_vms_write_shdrs_and_ehdr): Don't ignore
	bfd_seek or bfd_write return values.
	* pef.c (bfd_pef_scan_section): Likewise.
	(bfd_pef_read_header, bfd_pef_xlib_read_header): Likewise.
	* vms-misc.c (_bfd_vms_output_end): Likewise.  Return status.
	* vms.h (_bfd_vms_output_end): Update prototype.
	* vms-alpha.c: Pass _bfd_vms_output_end status up call chains.
	* wasm-module.c (wasm_compute_custom_section_file_position): Don't
	ignore bfd_seek or bfd_write return values.
	(wasm_compute_section_file_positions): Likewise.
	* xsym.c (bfd_sym_scan): Don't ignore bfd_seek return value.
	(bfd_sym_read_name_table): Likewise.
binutils/
	* ar.c (print_contents, extract_file): Don't ignore bfd_seek
	return value.
ld/
	* pdb.c (create_section_contrib_substream): Don't ignore bfd_seek
	return value.
	(create_section_header_stream): Likewise.
	* pe-dll.c (pe_get16, pe_get32): Add fail param to return results
	from bfd_seek and bfd_read.
	(pe_implied_import_dll): Handle these fails, and other bfd_seek
	and bfd_read return values.
2023-08-11 16:36:11 +09:30
Alan Modra
226f9f4fad Rename bfd_bread and bfd_bwrite
These were renamed from bfd_read and bfd_write back in 2001 when they
lost an unnecessary parameter.  Rename them back, and get rid of a few
casts that are only needed without prototyped functions (K&R C).
2023-08-09 08:48:09 +09:30
Alan Modra
f8c4789c7f readelf sprintf optimisation
This replaces sprintf and strcat calls with stpcpy, and makes use of
sprintf return value rather than using strlen, for get_machine_flags.

decode_NDS32_machine_flags made use of snprintf, which is arguably the
"correct" way to do things if there can be a buffer overflow.  In this
case I don't think there can be, the buffer is 1k in size which is at
least 5 times more than needed.  What's more, snprintf returns the
count of chars that would be output given no buffer limit, which means
code like
  r += snprintf (buf + r, size - r, ...);
  r += snprintf (buf + r, size - r, ...);
is just wrong.  There needs to be a check on the return value in order
to prevent buf + r being out of bounds for the second snprintf call.

BTW, if you look closely you'll see the return value of the decode
functions is unused.  I admit to getting a little carried away with
writing "out = stpcpy (out, ...):" in each of the decode functions and
didn't notice that until get_machine_flags was trimmed down to a much
smaller size.  When I did notice, I decided it's not such a bad thing.

	* readelf.c (decode_ARC_machine_flags, decode_ARM_machine_flags),
	(decode_AVR_machine_flags, decode_NDS32_machine_flags),
	(decode_AMDGPU_machine_flags): Use stpcpy and sprintf return
	value.  Return end of string.
	(decode_BLACKFIN_machine_flags, decode_FRV_machine_flags),
	(decode_IA64_machine_flags, decode_LOONGARCH_machine_flags),
	(decode_M68K_machine_flags, decode_MeP_machine_flags),
	(decode_MIPS_machine_flags, decode_MSP430_machine_flags),
	(decode_PARISC_machine_flags, decode_RISCV_machine_flags),
	(decode_RL78_machine_flags, decode_RX_machine_flags),
	(decode_SH_machine_flags, decode_SPARC_machine_flags),
	(decode_V800_machine_flags, decode_V850_machine_flags),
	(decode_Z80_machine_flags): New functions, split out from..
	(get_machine_flags): ..here.  Similarly use stpcpy.
2023-08-03 21:20:33 +09:30
Alan Modra
ad923ded82 binutils sprintf optimisation
Avoid the use of sprintf with a "%s" format string, replacing with
strcpy or stpcpy.  Use sprintf return value rather than a later
strlen.  Don't use strcat where we can keep track of the end of a
string output buffer.

	* dlltool.c (look_for_prog): memcpy prefix and strcpy prog_name.
	* dllwrap.c (look_for_prog): Likewise.
	* resrc.c (look_for_default): Likewise.  Add quotes with memmove
	rather than allocating another buffer.
	* size.c (size_number): Use sprintf return value.
	* stabs.c (parse_stab_argtypes): Likewise.
	* windmc.c (write_bin): Likewes, and use stpcpy.
	* wrstabs.c: Similarly throughout.
2023-08-03 21:20:33 +09:30
Alan Modra
137f6bc0da resrc: sprintf sanitizer null destination pointer
* resrc.c (read_rc_file): Use stpcpy rather than sprintf
	followed by strlen.  Tidy.
2023-08-03 21:19:54 +09:30
Alan Modra
e2e7c52613 dlltool: sprintf sanitizer null destination pointer
* dlltool.c (gen_lib_file): Avoid bogus sanitizer error.
2023-08-03 21:19:54 +09:30
Alan Modra
d191eacb7b wrstabs: sprintf sanitizer null destination pointer
gcc-2.12 seems to be ignoring __attribute__((__returns_nonnull__))
on xmalloc.

	* wrstabs.c (stab_method_type): Use stpcpy rather than sprintf
	or strcat.
2023-08-03 21:19:54 +09:30
Alan Modra
760fb390fd objdump, nm: sprintf sanitizer null destination pointer
Seen on Ubuntu 23.04 x86_64-linux using gcc-12.2 and gcc-12.3 with
CFLAGS="-m32 -g -O2 -fsanitize=address,undefined".

  CC       objdump.o
In file included from /usr/include/stdio.h:906,
                 from /home/alan/src/binutils-gdb/binutils/sysdep.h:24,
                 from /home/alan/src/binutils-gdb/binutils/objdump.c:51:
In function 'sprintf',
    inlined from 'display_utf8' at /home/alan/src/binutils-gdb/binutils/objdump.c:621:14,
    inlined from 'sanitize_string.part.0' at /home/alan/src/binutils-gdb/binutils/objdump.c:742:11:
/usr/include/bits/stdio2.h:30:10: error: null destination pointer [-Werror=format-overflow=]
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

The warning is bogus of course.  xmalloc is guaranteed to return
non-NULL, but apparently this isn't seen in display_utf6.  The same
doesn't happen with -m64, maybe due to inlining differences, I haven't
investigated fully.  Easily avoided as we hardly need to use sprintf
for a single char, or a two char string.

	* objdump.c (display_utf8): Avoid bogus sprintf sanitizer warning.
	Use hex ESC to switch back to default colour.
	(sanitize_string): Comment.  Bump buffer size by one.  Fix overlong
	line.
	* nm.c (display_utf8, sanitize_string): As above.
2023-08-03 21:19:04 +09:30
Sam James
b5c37946cc Revert "2.41 Release sources"
This reverts commit 675b9d612c.

See https://sourceware.org/pipermail/binutils/2023-August/128761.html.
2023-08-02 12:06:23 +01:00
Nick Clifton
675b9d612c 2.41 Release sources 2023-08-02 09:23:36 +01:00
Alan Modra
b6456e91d4 Don't declare xmalloc or xrealloc in bucomm.h
It's better to include the proper header, which has declarations with
various attributes.  Commit 096aefc040 in 1994 introduced this wart.

	* bucomm.h (xmalloc, xrealloc): Delete declaration.
	* od-macho.c: Include libiberty.h.
	* od-xcoff.c: Include libiberty.h.
2023-08-02 07:53:26 +09:30
Nick Clifton
b99a969343 Fix "--only-keep-debug for ELF relocatables" binutils test for compilers which add .debug_macro sections to object files.
PR 30699
  * binutils/testsuite/binutils-all/objcopy.exp (keep_debug_symbols_for_elf_relocatable): Do not add sections containing the string "debug_" to the list of non-debug sections.
2023-08-01 14:40:08 +01:00
Nick Clifton
0251080cb8 Add note to check that all changes have been pushed before creating the source tarballs 2023-08-01 10:41:58 +01:00
Jose E. Marchesi
1e18ffc991 bpf: include, bfd, opcodes: add EF_BPF_CPUVER ELF header flags
This patch adds support for EF_BPF_CPUVER bits in the ELF
machine-dependent header flags.  These bits encode the BPF CPU
version for which the object file has been compiled for.

The BPF assembler is updated so it annotates the object files it
generates with these bits.

The BPF disassembler is updated so it honors EF_BPF_CPUVER to use the
appropriate ISA version if the user didn't specify an explicit ISA
version in the command line.  Note that a value of zero in
EF_BPF_CPUVER is interpreted by the disassembler as "use the later
supported version" (the BPF CPU versions start with v1.)

The readelf utility is updated to pretty print EF_BPF_CPUVER when it
prints out the ELF header:

   $ readelf -h a.out
   ELF Header:
     ...
     Flags:                             0x4, CPU Version: 4

Tested in bpf-unknown-none.

include/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* elf/bpf.h (EF_BPF_CPUVER): Define.
	* opcode/bpf.h (BPF_XBPF): Change from 0xf to 0xff so it fits in
	EF_BPF_CPUVER.

binutils/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* readelf.c (get_machine_flags): Recognize and pretty print BPF
	machine flags.

opcodes/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* bpf-dis.c: Initialize asm_bpf_version to -1.
	(print_insn_bpf): Set BPF ISA version from the cpu version ELF
	header flags if no explicit version set in the command line.
	* disassemble.c (disassemble_init_for_target): Remove unused code.

gas/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* config/tc-bpf.h (elf_tc_final_processing): Define.
	* config/tc-bpf.c (bpf_elf_final_processing): New function.
2023-07-30 22:39:30 +02:00
Nick Clifton
82be476a08 Update how to make a release document after the 2.41 release 2023-07-30 16:07:09 +01:00
YunQiang Su
29c108c961 MIPS: Support `-gnuabi64' target triplet suffix for 64-bit Linux targets
Make the n64 ABI the default for 64-bit Linux targets specified with
`-gnuabi64' suffix included in the target triplet, for configurations
such as the Debian mips64el and mips64r6el ports.  Adjust testsuite
configuration accordingly.

There are the following regressions with the new target triplet:

mips64-linux-gnuabi64  +FAIL: readelf -S bintest
mips64-linux-gnuabi64  +FAIL: MIPS reloc estimation 1
mips64el-linux-gnuabi64  +FAIL: readelf -S bintest
mips64el-linux-gnuabi64  +FAIL: MIPS reloc estimation 1

The `readelf' issue comes from a difference in section headers produced
that the `binutils/testsuite/binutils-all/readelf.s-64' pattern template
does not match.  While there has been a precedent it does not appear to
me that there is a clear advantage from adding more and more variations
to the template rather than forking the existing template into multiple
ones for a more exact match.  So this is best deferred to a separate
discussion.

The MIPS reloc estimation issue is an actual bug in `objdump', which
discards a number of trailing entries from output here for n64 composed
relocations:

DYNAMIC RELOCATION RECORDS
OFFSET           TYPE              VALUE
0000000000000000 R_MIPS_NONE       *ABS*
0000000000000000 R_MIPS_NONE       *ABS*

and consequently `ld/testsuite/ld-mips-elf/reloc-estimate-1.d' does not
match even though ELF output produced is correct according to `readelf':

Relocation section '.rel.dyn' at offset 0x10400 contains 2 entries:
  Offset          Info           Type           Sym. Value    Sym. Name
000000000000  000000000000 R_MIPS_NONE
                    Type2: R_MIPS_NONE
                    Type3: R_MIPS_NONE
000000010000  000300001203 R_MIPS_REL32      0000000000010010 foo@@V2
                    Type2: R_MIPS_64
                    Type3: R_MIPS_NONE

As a genuine bug this has to be handled separately.

Co-Authored by: Maciej W. Rozycki <macro@orcam.me.uk>

	bfd/
	* config.bfd: Add `mips64*el-*-linux*-gnuabi64' and
	`mips64*-*-linux*-gnuabi64' targets.

	binutils/
	* testsuite/binutils-all/mips/mips.exp: Handle `*-*-*-gnuabi64'
	targets.
	* testsuite/binutils-all/objcopy.exp: Handle
	`mips64*-*-*-gnuabi64' targets.
	* testsuite/binutils-all/remove-relocs-01.d: Likewise.
	* testsuite/binutils-all/remove-relocs-04.d: Likewise.
	* testsuite/binutils-all/remove-relocs-05.d: Likewise.
	* testsuite/binutils-all/remove-relocs-06.d: Likewise.

	gas/
	* configure.ac: Handle `mips64*-linux-gnuabi64' targets.
	* configure: Regenerate.
	* testsuite/gas/mips/compact-eh-eb-7.d: Handle
	`mips64*-*-*-gnuabi64' targets.
	* testsuite/gas/mips/compact-eh-el-7.d: Likewise.

	ld/
	* configure.tgt: Add `mips64*el-*-linux-gnuabi64' and
	`mips64*-*-linux-gnuabi64' targets.
	* testsuite/ld-undefined/undefined.exp: Handle
	`mips64*-*-*-gnuabi64' targets.
	* testsuite/ld-mips-elf/attr-gnu-4-10.d: Likewise.
	* testsuite/ld-mips-elf/compact-eh6.d: Likewise.
	* testsuite/ld-mips-elf/mips-elf.exp: Handle `*-*-*-gnuabi64'
	targets.
2023-07-28 06:00:37 +01:00
YunQiang Su
ed4dca900c testsuite: Handle composed R_MIPS_NONE relocations
MIPS n64 ABI has a peculiarity where all relocations are composed of
three, with subsequent relocation types set to R_MIPS_NONE if further
calculation is not required.  Example output produced by `readelf' and
`objdump' for such relocations is:

  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  000800000002 R_MIPS_32         0000000000000000 foo + 0
                    Type2: R_MIPS_NONE
                    Type3: R_MIPS_NONE

and:

OFFSET           TYPE              VALUE
0000000000000000 R_MIPS_32         foo
0000000000000000 R_MIPS_NONE       *ABS*
0000000000000000 R_MIPS_NONE       *ABS*

respectively.  The presence of these extra R_MIPS_NONE entries is not
relevant for generic or even some MIPS tests, so optionally match them
with the respective dump patterns, also discarding `xfail' annotation
for MIPS/OpenBSD targets from gas/elf/missing-build-notes.d, removing
these regressions:

mips64-openbsd  -FAIL: readelf -r bintest
mips64-openbsd  -FAIL: forward expression
mips64-openbsd  -FAIL: assignment tests
mips64-openbsd  -FAIL: gas/all/none
mips64-openbsd  -XFAIL: gas/elf/missing-build-notes
mips64-openbsd  -FAIL: macro test 2
mips64-openbsd  -FAIL: macro irp
mips64-openbsd  -FAIL: macro rept
mips64-openbsd  -FAIL: nested irp/irpc/rept
mips64-openbsd  -FAIL: macro vararg
mips64-openbsd  -FAIL: mips jalx
mips64-openbsd  -FAIL: ST Microelectronics Loongson-2F workarounds of Jump Instruction issue
mips64el-openbsd  -FAIL: readelf -r bintest
mips64el-openbsd  -FAIL: forward expression
mips64el-openbsd  -FAIL: assignment tests
mips64el-openbsd  -FAIL: gas/all/none
mips64el-openbsd  -XFAIL: gas/elf/missing-build-notes
mips64el-openbsd  -FAIL: macro test 2
mips64el-openbsd  -FAIL: macro irp
mips64el-openbsd  -FAIL: macro rept
mips64el-openbsd  -FAIL: nested irp/irpc/rept
mips64el-openbsd  -FAIL: macro vararg
mips64el-openbsd  -FAIL: mips jalx
mips64el-openbsd  -FAIL: ST Microelectronics Loongson-2F workarounds of Jump Instruction issue

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>

	binutils/
	* testsuite/binutils-all/readelf.r-64: Optionally match extra
	R_MIPS_NONE pairs.

	gas/
	* testsuite/gas/all/assign.d: Optionally match extra
	R_MIPS_NONE pairs.
	* testsuite/gas/all/fwdexp.d: Likewise.
	* testsuite/gas/all/none.d: Likewise.
	* testsuite/gas/macros/irp.d: Likewise.
	* testsuite/gas/macros/repeat.d: Likewise.
	* testsuite/gas/macros/rept.d: Likewise.
	* testsuite/gas/macros/test2.d: Likewise.
	* testsuite/gas/macros/vararg.d: Likewise.
	* testsuite/gas/mips/compact-eh-eb-1.d: Likewise.
	* testsuite/gas/mips/compact-eh-eb-2.d: Likewise.
	* testsuite/gas/mips/compact-eh-eb-3.d: Likewise.
	* testsuite/gas/mips/compact-eh-eb-4.d: Likewise.
	* testsuite/gas/mips/compact-eh-eb-5.d: Likewise.
	* testsuite/gas/mips/compact-eh-eb-6.d: Likewise.
	* testsuite/gas/mips/compact-eh-el-1.d: Likewise.
	* testsuite/gas/mips/compact-eh-el-2.d: Likewise.
	* testsuite/gas/mips/compact-eh-el-3.d: Likewise.
	* testsuite/gas/mips/compact-eh-el-4.d: Likewise.
	* testsuite/gas/mips/compact-eh-el-5.d: Likewise.
	* testsuite/gas/mips/compact-eh-el-6.d: Likewise.
	* testsuite/gas/mips/loongson-2f-3.d: Likewise.
	* testsuite/gas/mips/mips-jalx.d: Likewise.
	* testsuite/gas/elf/missing-build-notes.d: Likewise.  Remove
	the `xfail' tag.

	ld/
	* testsuite/ld-mips-elf/reloc-estimate-1.d: Optionally match
	extra R_MIPS_NONE pairs.
2023-07-28 06:00:36 +01:00
YunQiang Su
60ec8306db testsuite: Also discard the `.MIPS.options' section
Also discard the `.MIPS.options' section, used with n64 MIPS binaries,
along with similar other MIPS sections (`.reginfo', `.MIPS.abiflags')
not relevant for the test cases concerned, fixing these regressions:

mips64-openbsd  -FAIL: ld-elf/group3a
mips64-openbsd  -FAIL: ld-elf/group3b
mips64-openbsd  -FAIL: Place orphan sections (map file check)
mips64-openbsd  -FAIL: ld-elf/orphan-region
mips64-openbsd  -FAIL: ld-elf/orphan
mips64-openbsd  -FAIL: overlay size (map file check)
mips64-openbsd  -FAIL: overlay size
mips64el-openbsd  -FAIL: ld-elf/group3a
mips64el-openbsd  -FAIL: ld-elf/group3b
mips64el-openbsd  -FAIL: Place orphan sections (map file check)
mips64el-openbsd  -FAIL: ld-elf/orphan-region
mips64el-openbsd  -FAIL: ld-elf/orphan
mips64el-openbsd  -FAIL: overlay size (map file check)
mips64el-openbsd  -FAIL: overlay size

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>

	binutils/
	* testsuite/binutils-all/strip-3.d: Add `-R .MIPS.options' to
	the `strip' tag.

	ld/
	* testsuite/ld-elf/group.ld: Also discard `.MIPS.options'.
	* testsuite/ld-elf/orphan-region.ld: Likewise.
	* testsuite/ld-elf/orphan.ld: Likewise.
	* testsuite/ld-mips-elf/got-page-1.ld: Likewise.
	* testsuite/ld-scripts/overlay-size.t: Likewise.
2023-07-28 06:00:36 +01:00
Maciej W. Rozycki
cc66ad2d2a Revert "MIPS: support mips*64 as CPU and gnuabi64 as ABI"
This reverts commit 32f1c80375.  It had
two unrelated changes lumped together, one of which changed the meaning
of the `mipsisa64*-*-linux*' target triplets, which was not properly
evaluated.
2023-07-28 06:00:36 +01:00
Alan Modra
41c8b9f097 coff/pe/xcoff and --extract-symbols
This fixes failure of the "extract symbols" test for rs6000, where
--extract-symbols generates a non-zero sized .text.  By the look of
coffcode.h the same problem might occur for coff/pe too, but doesn't
happen to trigger a test failure.

bfd/
	* coffcode.h (coff_compute_section_file_positions): Don't
	adjust size of !SEC_LOAD sections.
binutils/
	* objcopy.c (setup_section): Clear SEC_LOAD for --extract-symbol.
2023-07-28 14:11:27 +09:30
Johannes Schauer Marin Rodrigues
6badd1020f objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unreproducible.
bfd
  * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): If inserting a timestamp, use the value held in the SOURCE_DATE_EPOCH environment variable, if it is defined.
binutils
  * doc/binutils.texi (objcopy): Document change in behaviour of objcopy's --preserve-dates command line option.
ld
  * pe-dll.c (fill_edata): If inserting a timestamp, use the value held in the SOURCE_DATE_EPOCH environment variable, if it is defined.
  * ld.texi (--insert-timestamp): Document change in behaviour.
2023-07-24 16:59:19 +01:00
Alan Modra
b7bf7f1b8f Tidy binutils configure
Separate out some of the defines from the block handling windows
support, so they don't get lost.  Delete an unused variable.
2023-07-19 11:06:22 +09:30
Alan Modra
eb84343a1d Build all the objdump extensions with --enable-targets=all
Only the xcoff and pe extensions were enabled.  Build the lot, and fix
some more printf format problems when the host is 32-bit.

	* configure.ac (od_vectors): Set up for --enable-targets=all.
	* configure: Regenerate.
	* od-elf32_avr.c (elf32_avr_dump_mem_usage): Correct format
	specifier vs. arg mismatch.
	(elf32_avr_dump_avr_prop): Likewise.
2023-07-19 10:46:59 +09:30
Nick Clifton
fdc60e8cf6 Updated Swedish translation for the binutils subdirectory 2023-07-18 17:12:25 +01:00
Alan Modra
6d872a1a80 More tidies to objcopy archive handling
This makes sure copy_archive exits with ibfd and obfd closed.  Error
paths didn't do that, leading to memory leaks.  None of this matters
very much.

	* objcopy.c (copy_archive): bfd_close ibfd and obfd on error
	return paths.  Remove braces around "list" free.
	(copy_file): Don't close invalid file descriptor.
2023-07-14 11:53:48 +09:30
Alan Modra
1052fb3ecb Re: Keeping track of rs6000-coff archive element pointers
bfd/
	* coff-rs6000.c (add_range): Revise comment, noting possible fail.
	(_bfd_xcoff_openr_next_archived_file): Start with clean ranges.
binutils/
	* bfdtest1.c: Enhance to catch errors on second scan.
2023-07-12 09:31:40 +09:30
Fangrui Song
5e24da908d PR30592 objcopy: allow --set-section-flags to add or remove SHF_X86_64_LARGE
For example, objcopy --set-section-flags .data=alloc,large will add
SHF_X86_64_LARGE to the .data section.  Omitting "large" will drop the
SHF_X86_64_LARGE flag.

The bfd_section flag is named generically, SEC_ELF_LARGE, in case other
processors want to follow SHF_X86_64_LARGE.  SEC_ELF_LARGE has the same
value as SEC_TIC54X_BLOCK used by coff.

bfd/
    * section.c: Define SEC_ELF_LARGE.
    * bfd-in2.h: Regenerate.
    * elf64-x86-64.c (elf_x86_64_section_flags, elf_x86_64_fake_sections,
    elf_x86_64_copy_private_section_data): New.

binutils/
    * NEWS: Mention the new feature for objcopy.
    * doc/binutils.texi: Mention "large".
    * objcopy.c (parse_flags): Parse "large".
    (check_new_section_flags): Error if "large" is used with a
    non-x86-64 ELF target.
    * testsuite/binutils-all/x86-64/large-sections.d: New.
    * testsuite/binutils-all/x86-64/large-sections.s: New.
    * testsuite/binutils-all/x86-64/large-sections-i386.d: New.
    * testsuite/binutils-all/x86-64/large-sections-2.d: New.
    * testsuite/binutils-all/x86-64/large-sections-2-x32.d: New.
2023-07-09 10:57:19 -07:00
Claudiu Zissulescu
13aa307c9a arc: Update/Add ARCv3 support.
The ARC HS5x and ARC HS6x processors are based on the new ARCv3 ISA
that implements a full range of 32-bit and 64-bit instructions.  These
processors feature a high-speed 10-stage, dual-issue pipeline that
offers increased utilization of functional units with a limited
increase in power and area.  The HS5x processors feature a 32-bit
pipeline that can execute all ARCv3 32-bit instructions, while the
HS6x processors feature a full 64-bit pipeline and register file that
can execute both 32-bit and 64-bit instructions.  In addition, the ARC
HS6x supports 64-bit virtual and 52-bit physical address spaces to
enable direct addressing of current and future large memories, as well
as 128-bit loads and stores for efficient data movement.

This readelf patch updates/adds Synopsys ARCv3 machine name fileds and
supported relocations.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2023-07-07 13:08:04 +03:00
Nick Clifton
3baacfd61d Udated Freach and Romainian translations for various sub-directories 2023-07-07 09:40:20 +01:00
Nick Clifton
dd78c0a824 Minor updates to release readme 2023-07-07 09:39:16 +01:00
Nick Clifton
a34339a82f Updated Ukranian, Romanian and German translations for various sub-directories 2023-07-04 11:55:27 +01:00
Nick Clifton
0d368ae540 Update after creating 2.41 branch 2023-07-03 13:41:02 +01:00
Nick Clifton
87485f5349 Change version number to 2.41.50 and regenerate files 2023-07-03 11:54:06 +01:00
Nick Clifton
d501d38488 Add markers for the 2.41 branch 2023-07-03 11:12:15 +01:00
WANG Xuerui
0ed3ac2f4a binutils: NEWS: Announce LoongArch changes in the 2.41 cycle
binutils/ChangeLog:

	* NEWS: Mention LoongArch changes for 2.41.

Signed-off-by: WANG Xuerui <git@xen0n.name>
2023-07-03 09:00:48 +08:00
Christoph Müllner
9fdc1b157b binutils: NEWS: Announce new RISC-V vector crypto extensions
This commit adds the recently added support of the RISC-V vector crypto
extensions to the NEWS file.

binutils/ChangeLog:

	* NEWS: Announce new RISC-V vector crypto extensions.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2023-07-01 07:32:20 -06:00
Philipp Tomsich
e507570754 binutils: NEWS: announce new RISC-V extensions
We picked up support for a few new extensions over the last weeks
(this may need further updating prior to the next release), list them
in the NEWS file.

binutils/ChangeLog:

	* binutils/NEWS: announce suuport for the new RISC-V
          extensions (Zicond, Zfa, XVentanaCondOps).

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2023-06-30 16:02:17 +02:00
Nick Clifton
3713e829be strings: Improve code to detect excessively large minimum string lengths.
PR 30598
  * strings.c (set_string_min): New function. (main): Use it. (print_unicode_stream): Calculate buffer size using a size_t.
2023-06-30 13:54:03 +01:00
Nick Clifton
0d1cd7d978 Prevent an illegal memory access when running the strings program with an excessively lerge minimum string length.
PR 30595
  * strings.c (main): Check for an excessively large minimum string length.
2023-06-30 11:18:42 +01:00
Indu Bhagat
a47cd2a1cd binutils/NEWS: announce SFrame version 2 as the new default 2023-06-29 16:32:26 -07:00
H.J. Lu
1ad1b8865c binutils: Add a --strip-section-headers test
PR ld/25617
	* testsuite/binutils-all/objcopy.exp: Run strip-section-headers-1.
	* testsuite/binutils-all/strip-section-headers-1.d: New file.
2023-06-29 10:29:47 -07:00
H.J. Lu
02c1ba6c94 ELF: Discard non-alloc sections without section header
Discard non-alloc sections when section headers are stripped.

bfd/

	PR ld/25617
	* elf.c (_bfd_elf_assign_file_positions_for_non_load): Skip
	non-load sections without section header.
	(_bfd_elf_write_object_contents): Don't set the sh_name field
	without section header.  Write out the .shstrtab section only
	if its sh_offset field isn't -1.

binutils/

	PR ld/25617
	* objcopy.c (is_strip_section_1): Remove non-alloc sections for
	--strip-section-headers.

ld/

	PR ld/25617
	* ldlang.c (lang_discard_section_p): Discard non-alloc sections
	if we are stripping section headers.
2023-06-29 10:29:47 -07:00
Kaylee Blake
96cc7918c1 ELF: Strip section header in ELF objects
Section header isn't mandatory on ELF executable nor shared library.
This patch adds a new linker option, -z nosectionheader, to omit ELF
section header, a new objcopy and strip option, --strip-section-headers,
to remove ELF section headers.

bfd/

2023-06-06  H.J. Lu  <hongjiu.lu@intel.com>
	    Kaylee Blake  <klkblake@gmail.com>

	PR ld/25617
	* bfd.c (BFD_NO_SECTION_HEADER): New.
	(BFD_FLAGS_SAVED): Add BFD_NO_SECTION_HEADER.
	(BFD_FLAGS_FOR_BFD_USE_MASK): Likewise.
	* elfcode.h (elf_swap_ehdr_out): Omit section header with
	BFD_NO_SECTION_HEADER.
	(elf_write_shdrs_and_ehdr): Likewise.
	* elfxx-target.h (TARGET_BIG_SYM): Add BFD_NO_SECTION_HEADER
	to object_flags.
	(TARGET_LITTLE_SYM): Likewise.
	* bfd-in2.h: Regenerated.

binutils/

2023-06-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/25617
	* NEWS: Mention --strip-section-headers for objcopy and strip.
	* objcopy.c (strip_section_headers): New.
	(command_line_switch): Add OPTION_STRIP_SECTION_HEADERS.
	(strip_options): Add --strip-section-headers.
	(copy_options): Likewise.
	(copy_usage): Add --strip-section-headers.
	(strip_usage): Likewise.
	(copy_object): Handle --strip-section-headers for ELF files.
	(strip_main): Handle OPTION_STRIP_SECTION_HEADERS.
	(copy_main): Likewise.
	* doc/binutils.texi: Document --strip-section-headers for objcopy
	and strip.

ld/

2023-06-06  H.J. Lu  <hongjiu.lu@intel.com>
	    Kaylee Blake  <klkblake@gmail.com>

	PR ld/25617
	* NEWS: Mention -z nosectionheader.
	* emultempl/elf.em: Support -z sectionheader and
	-z nosectionheader.
	* ld.h (ld_config_type): Add no_section_header.
	* ld.texi: Document -z sectionheader and -z nosectionheader.
	* ldlang.c (ldlang_open_output): Handle
	config.no_section_header.
	* lexsup.c (parse_args): Enable --strip-all with
	-z nosectionheader.  Disallow -r with -z nosectionheader.
	(elf_static_list_options): Add -z sectionheader and
	-z nosectionheader.
2023-06-29 10:29:46 -07:00
Matthias Klose
fa2b501cdc Ignore --prefix-file-map compiler option whist running testsuite. 2023-06-29 14:44:52 +01:00
Matthias Klose
96127db593 ignore lto-wrapper warnings for lto builds.
I see these warnings from time to time, when configuring a build with  --enable-pgo-build=lto, I haven't yet found out why I see these sometime, and  why not. E.g. https://gcc.gnu.org/PR109241. Just ignore these when they appear  in test cases. lto-wrapper: warning: using serial compilation of N LTRANS jobs
2023-06-29 14:30:55 +01:00
Indu Bhagat
fa3d73ebf3 binutils/NEWS: add note about upcoming libsframe changes
Some of these changes update the ABI in an incompatible way.
2023-06-27 12:01:56 -07:00
Nick Clifton
15d842846d Add note about adding ChangeLog.git to src-release.sh 2023-06-27 10:15:51 +01:00
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
Alan Modra
695c322803 coffgrok access of u.auxent.x_sym.x_tagndx.p
u.auxent.x_sym.x_tagndx is a union.  The p field is only valid when
fix_tag is set.  This patch fixes code in coffgrok.c that accessed the
field without first checking fix_tag, and removes a whole lot of code
validating bogus pointers to prevent segfaults (which no longer
happen, I checked the referenced PR 17512 testcases).  The patch also
documents this in the fix_tag comment, makes is_sym a bitfield, and
sorts the selecter fields a little.

bfd/
	* coffcode.h (combined_entry_type): Make is_sym a bitfield.
	Sort and comment on union selectors.
	* libcoff.h: Regenerate.
binutils/
	* coffgrok.c (do_type): Make aux a combined_entry_type.  Test
	fix_tag before accessing u.auxent.x_sym.x_tagndx.p.  Remove
	now unnecessary pointer bounds checking.
2023-03-27 21:58:46 +10:30
Frederic Cambus
80251d4185 Add support to readelf for the PT_OPENBSD_MUTABLE segment type.
binutils * readelf.c (get_segment_type): Handle PT_OPENBSD_MUTABLE segment type.
include  * elf/common.h (PT_OPENBSD_MUTABLE): Define.
2023-03-23 15:19:38 +00:00
Alan Modra
75831f18a0 Another sanity check for read_section_stabs_debugging_info
* rddbg.c (read_section_stabs_debugging_info): Ignore invalid
	stab sections with size less than 12 bytes.
2023-03-19 22:19:19 +10:30
Clément Chigot
e263a66b01 readelf: add support for QNT_STACK note subsections
QNX provides some .note subsections. QNT_STACK is the one controling
the stack allocation.

bfd/ChangeLog:

	* elf.c (BFD_QNT_CORE_INFO): Delete.
	(BFD_QNT_CORE_STATUS): Likewise.
	(BFD_QNT_CORE_GREG): Likewise.
	(BFD_QNT_CORE_FPREG): Likewise.
	(elfcore_grok_nto_note): Replace BFD_QNT_* by QNT_*.

binutils/ChangeLog:

	* readelf.c (get_qnx_elfcore_note_type): New function.
	(print_qnx_note): New function.
	(process_note): Add support for QNX support.

include/ChangeLog:

	* elf/common.h (QNT_DEBUG_FULLPATH): New define.
	(QNT_DEBUG_RELOC): New define.
	(QNT_STACK): New define.
	(QNT_GENERATOR): New define.
	(QNT_DEFAULT_LIB): New define.
	(QNT_CORE_SYSINFO): New define.
	(QNT_CORE_INFO): New define.
	(QNT_CORE_STATUS): New define.
	(QNT_CORE_GREG): New define.
	(QNT_CORE_FPREG): New define.
	(QNT_LINK_MAP): New define.
2023-03-16 15:01:05 +01:00
Alan Modra
d56e433a79 Re: Sanity check read_section_stabs_debugging_info
* rddbg.c (read_section_stabs_debugging_info): Don't segfault on
	zero size string section.
2023-03-16 11:11:44 +10:30
Nick Clifton
97b75c421f Prevent an over large memory allocation in readelf when parsing a corrupt DWARF file.
PR 30227
  * dwarf.c (process_cu_tu_index): Prevent excessive memory allocation when nused is large and ncols is zero.
2023-03-14 13:15:12 +00:00
Nick Clifton
7506fc9bf1 Adjust the decoded line output to fit into 80 columns.
PR 30216
  * dwarf.c (display_debug_lines_decoded): Reduce space for filenames.
  * testsuite/binutils-all/dw5.W: Adjust expected output.
  * testsuite/binutils-all/objdump.WL: Adjust expected output.
2023-03-14 12:21:13 +00:00
Alan Modra
c8b3d02c49 objdump segfault after symbol table error
This memcpy segfaults if symcount is -1 (=> syms is NULL).
      memcpy (sorted_syms, symcount ? syms : dynsyms,
	      sorted_symcount * sizeof (asymbol *));

	* objdump.c (slurp_symtab): Don't leave symcount as -1 after
	an error.
	(slurp_dynamic_symtab): Likewise for dynsymcount.
2023-03-14 12:19:28 +10:30
Alan Modra
746598e07f Sanity check read_section_stabs_debugging_info
* rddbg.c (read_section_stabs_debugging_info): Exclude sections
	without contents.  Use bfd_malloc_and_get_section.  Don't alloc
	one extra for strings.
2023-03-14 12:19:09 +10:30
Alan Modra
093b56776f objdump: report no section contents
objdump's read_section is never used for bss-style sections, so to
plug a hole that fuzzers have found, exclude sections without
SEC_HAS_CONTENTS.

	* objdump.c (read_section): Report and return an error on
	a no contents section.
2023-03-09 22:48:06 +10:30
Alan Modra
160f200778 Re: Move nm.c cached line number info to bfd usrdata
Commit e3f450f393 resulted in a nm -l segfault on object files
without undefined symbols.  Fix that, and be paranoid about bfd
section count changing.

	* nm.c (struct lineno_cache): Add seccount.
	(free_lineno_cache): Don't segfault on NULL lc->relocs.
	(print_symbol): Stash section count when creating arrays.
2023-03-08 11:24:55 +10:30
Alan Modra
ffdfc835dd Downgrade objdump fatal errors to non-fatal
* objdump.c (slurp_symtab): Replace bfd_fatal calls with calls
	to my_bfd_nonfatal.
	(slurp_dynamic_symtab, disassemble_section): Likewise.
	(disassemble_data): Replace fatal call with non_fatal call, and
	set exit_status.  Don't error on non-existent dynamic relocs.
	Don't call bfd_fatal on bfd_canonicalize_dynamic_reloc error.
	(dump_ctf, dump_section_sframe): Replace bfd_fatal calls with
	calls to my_bfd_nonfatal and clean up memory.
	(dump_relocs_in_section): Don't call bfd_fatal on errors.
	(dump_dynamic_relocs): Likewise.
	(display_any_bfd): Make archive nesting too depp non_fatal.
2023-03-06 13:11:22 +10:30
Alan Modra
5db0367e1b Downgrade addr2line fatal errors to non-fatal
* addr2line.c (slurp_symtab): Don't exit on errors.
	(process_file): Likewise.
2023-03-06 13:11:22 +10:30
Alan Modra
86a2562b09 Downgrade nm fatal errors to non-fatal
Many of the fatal errors in nm ought to be recoverable.  This patch
downgrades most of them.  The ones that are left are most likely due
to memory allocation failures.

	* nm.c (print_symdef_entry): Don't bomb with a fatal error
	on a corrupted archive symbol table.
	(filter_symbols): Silently omit symbols that return NULL
	from bfd_minisymbol_to_symbol rather than giving a fatal
	error.
	(display_rel_file): Don't give a fatal error on
	bfd_read_minisymbols returning an error, or on not being able
	to read dynamic symbols for synth syms.
	(display_archive): Downgrade bfd_openr_next_archived_file
	error.
	(display_file): Don't bomb on a bfd_close failure.
2023-03-06 13:11:10 +10:30
Alan Modra
e3f450f393 Move nm.c cached line number info to bfd usrdata
Replace the static variables used by nm to cache line number info
with a struct attached to the bfd.  Cleaner, and it avoids any concern
that lineno_cache_bfd is somehow left pointing at memory for a closed
bfd and that memory is later reused for another bfd, not that I think
this is possible.  Also don't bomb via bfd_fatal on errors getting
the line number info, just omit the line numbers.

	* nm.c (struct lineno_cache): Rename from get_relocs_info.
	Add symcount.
	(lineno_cache_bfd, lineno_cache_rel_bfd): Delete.
	(get_relocs): Adjust for struct rename.  Don't call bfd_fatal
	on errors.
	(free_lineno_cache): New function.
	(print_symbol): Use lineno_cache in place of statics.  Don't
	call bfd_fatal on errors reading symbols, just omit the line
	info.
	(display_archive, display_file): Call free_lineno_cache.
2023-03-06 10:42:36 +10:30
Alan Modra
a734d906cc Correct objdump command line error handling
bfd_nonfatal is used when a bfd error is to be printed.  That's not
the case for command line errors.

	* objdump.c (nonfatal): Rename to my_bfd_nonfatal.
	(main): Use non_fatal and call usage on unrecognized arg errors.
	Don't set exit_status when calling usage.
2023-03-06 10:42:22 +10:30
Alan Modra
945efa5c53 Tidy type handling in binutils/rdcoff.c
There isn't really any good reason for code in rdcoff.c to distinguish
between "basic" types and any other type.  This patch dispenses with
the array reserved for basic types and instead handles all types using
coff_get_slot, simplifying the code.

	* rdcoff.c (struct coff_types, coff_slots): Merge.  Delete
	coff_slots.
	(T_MAX): Delete.
	(parse_coff_base_type): Use coff_get_slot to store baseic types.
	(coff_get_slot, parse_coff_type, parse_coff_base_type),
	(parse_coff_struct_type, parse_coff_enum_type),
	(parse_coff_symbol, parse_coff): Pass types as coff_types**.
2023-03-03 12:31:24 +10:30
Alan Modra
de357ff4e4 binutils coff type list
As for commit 72d225ef9c, handle type numbers starting anywhere.

	PR 17512
	* rdcoff.c (struct coff_slots): Add base_index.
	(coff_get_slot): Delete pr17512 excessively large slot check.
	Don't allocate entire array from 0 to type number, allocate a
	sparse array.
2023-03-03 10:35:54 +10:30
Clément Chigot
2b69325792 testsuite: prune DOS drive letter in test outputs
On DOS systems, absolute paths start with the drive letter. This can
trigger failures in the regexp from dump tests, especially for those
checking for warnings or errors. They are usually skipping everything
before the first ":" as it has to be the file path.
  | [^:]*: warning: ...

In order to avoid modifying many regexps to allow such drive letters,
prune them from all the outputs if they are found at the beginning of
a line.

binutils/ChangeLog:

	* testsuite/lib/binutils-common.exp (prune_dump_output): New
	(run_dump_test): Use it.

ld/ChangeLog:

	* testsuite/ld-elf/noinit-sections-2.l: Remove DOS drive letter
	handler.
2023-02-24 14:35:10 +01:00
Alan Modra
5e39600a69 set bfd_error on make_tempname or make_tempdir failure
* bucomm.c (make_tempname, make_tempdir): Set bfd_error on error.
2023-02-22 12:04:07 +10:30
Alan Modra
c65f94a07a Re: objdump read_section_stabs
Also fix ubsan "applying zero offset to null pointer".

	* objdump.c (print_section_stabs): Avoid ubsan warning.
2023-02-22 10:01:10 +10:30
Alan Modra
45b36294d6 Re: objdump read_section_stabs
Commit f9c36cc995 changed (and renamed) read_section_stabs with one
difference in overall behaviour.  Previously read_section_stabs would
return a NULL for an empty section, which was then treated the same as
a missing section.  Now an empty section is recognized and dumped.
This leads to NULL stabp and stabs_end in print_section_stabs.  Since
stabs_end - STABSIZE is then a pointer to a very large address, the
test "stabp < stabs_end - STABSIZE" succeeds.

	* objdump.c (print_section_stabs): Correct STABSIZE comparison.
2023-02-22 09:18:25 +10:30
Alan Modra
5f497256be ld test asciz and ascii fails
Fix these fails:
alpha-dec-vms  +FAIL: ld-scripts/asciz
alpha-dec-vms  +FAIL: ld-scripts/ascii
i386-go32  +FAIL: ld-scripts/asciz
sh-coff  +FAIL: ld-scripts/asciz

It's better to positively select targets for .section support than to
try to exclude all targets that don't.  Make a new is_coff_format so
we can easily select such.

binutils/
	* testsuite/lib/binutils-common.exp (is_coff_format): New.
ld/
	* testsuite/ld-scripts/ascii.d: Use is_elf_format and
	is_coff_format to select targets, exclude ti coff.
	* testsuite/ld-scripts/asciz.d: Likewise.  Accept trailing zeros.
2023-02-17 15:19:47 +10:30
Alan Modra
7ed4ad59e9 Delete PROGRESS macros
I don't see much point in cluttering the source with the PROGRESS
macros, which of course do nothing at all with the definitions in
progress.h.  progress.h is unchanged apart from the copyright comment
since commit d4d4c53c68 in 1994.

binutils/
	* ar.c: Don't include progress.h, or invoke PROGRESS macros.
	* nm.c: Likewise.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
gas/
	* as.h: Don't include progress.h.
	* as.c: Don't invoke PROGRESS macros.
	* write.c: Likewise.
include/
	* progress.h: Delete.
ld/
	* ldmain.c: Don't include progress.h, or invoke PROGRESS macros.
2023-02-16 21:00:50 +10:30
Alan Modra
f9c36cc995 objdump read_section_stabs
This function is used to read sections other than stabs, and there is
now another version of it that extracts different info from the bfd
section.  Rename it and return the bfd section instead of assorted
fields of the bfd section.

	* objcopy.c (read_section): Renamed from read_section_stabs.
	Delete size_ptr and entsize_ptr params, add contents param.
	Return asection pointer.  Don't unnecessarily free contents on
	failure from bfd_malloc_and_get_section.
	(find_stabs_section): Use read_section.
	(dump_ctf, dump_section_sframe): Likewise.
	(read_section_sframe): Delete.
2023-02-15 22:03:30 +10:30
Alan Modra
11066c2aab objdump -G memory leak
* objdump.c (find_stabs_section): Free stabs.
2023-02-15 22:03:30 +10:30
Alan Modra
72d225ef9c binutils stabs type list
Fuzzers have found that specifying a large stab type number results in
lots of memory being requested, as the list is extended with a 16
element array at a time until we reach the given stab type.  It also
takes a long time.  Of course normal sane stab types use small
positive integers, but it's not hard to modify the code to handle type
numbers starting anyhere.

	* stabs.c (struct stab_types): Add base_index.
	(stab_find_slot): Simplify filenum check.  Delete type number
	check.  Don't allocate entire array from 0 to type number,
	allocate a sparse array.
2023-02-15 13:05:28 +10:30
Andrew Burgess
77be725744 opcodes/mips: disassemble unknown micromips instructions as two shorts
Before commit:

  commit 2438b771ee
  Date:   Wed Nov 2 15:53:43 2022 +0000

      opcodes/mips: use .word/.short for undefined instructions

unknown 32-bit microMIPS instructions were disassembled as a raw
32-bit number with no '.word' directive.  The above commit changed
this and added a '.word' directive before the 32-bit number.

It was pointed out on the mailing list, that for microMIPS it would be
better to display such 32-bit instructions using a '.short' directive
followed by two 16-bit values.

This commit updates the mips disassembler to do this, and adds a new
test that validates this output.
2023-02-13 12:05:32 +00:00
Alan Modra
3eef3b2c2d objcopy memory leaks
This fixes some objcopy memory leaks.  commit 450da4bd38 used
xatexit to tidy most of the hash table memory, but of course that's
ineffective without a call to xexit.  The other major memory leak
happens if there is an error of some sort writing the output file, due
to not closing the input file and thus not freeing memory attached to
the bfd.

	* objcopy.c (copy_file): Don't return when bfd_close of output
	gives an error, always bfd_close input too.
	(main): Call xexit.
2023-02-13 12:53:31 +10:30
Alan Modra
0a3137ce4c objdump -D of bss sections and -s with -j
There is some inconsistency between the behaviour of objdump -D and
objdump -s, both supposedly operating on all sections by default.
objdump -s ignores bss sections, while objdump -D dissassembles the
zeros.  Fix this by making objdump -D ignore bss sections too.

Furthermore, "objdump -s -j .bss" doesn't dump .bss as it should,
since the user is specifically asking to look at all those zeros.

This change does find some tests that used objdump -D with expected
output in bss-style sections.  I've updated all the msp430 tests that
just wanted to find a non-empty section to look at section headers
instead, making the tests slightly more stringent.  The ppc xcoff and
spu tests are fixed by adding -j options to objdump, which makes the
tests somewhat more lenient.

binutils/
	* objdump.c (disassemble_section): Ignore sections without
	contents, unless overridden by -j.
	(dump_section): Allow -j to override the default of not
	displaying sections without contents.
	* doc/binutils.texi (objdump options): Update -D, -s and -j
	description.
gas/
	* testsuite/gas/ppc/xcoff-tls-32.d: Select wanted objdump
	sections with -j.
	* testsuite/gas/ppc/xcoff-tls-64.d: Likewise.
ld/
	* testsuite/ld-msp430-elf/main-bss-lower.d,
	* testsuite/ld-msp430-elf/main-bss-upper.d,
	* testsuite/ld-msp430-elf/main-const-lower.d,
	* testsuite/ld-msp430-elf/main-const-upper.d,
	* testsuite/ld-msp430-elf/main-text-lower.d,
	* testsuite/ld-msp430-elf/main-text-upper.d,
	* testsuite/ld-msp430-elf/main-var-lower.d,
	* testsuite/ld-msp430-elf/main-var-upper.d: Expect -wh output.
	* testsuite/ld-msp430-elf/msp430-elf.exp: Use objdump -wh
	rather than objdump -D or objdump -d with tests checking for
	non-empty given sections.
	* testsuite/ld-spu/ear.d,
	* testsuite/ld-spu/icache1.d,
	* testsuite/ld-spu/ovl.d,
	* testsuite/ld-spu/ovl2.d: Select wanted objdump sections.
2023-02-11 16:43:54 +10:30
Tom Tromey
93c8054387 Add full display feature to dwarf-mode.el
I've found that I often use dwarf-mode with relatively small test
files.  In this situation, it's handy to be able to expand all the
DWARF, rather than moving to each "..." separately and using C-u C-m.

This patch implements this feature.  It also makes a couple of other
minor changes:

* I removed a stale FIXME from dwarf-mode.  In practice I find I often
  use "g" to restore the buffer to a pristine state; checking the file
  mtime would work against this.

* I tightened the regexp in dwarf-insert-substructure.  This prevents
  the C-m binding from trying to re-read a DIE which has already been
  expanded.

* Finally, I've bumped the dwarf-mode version number so that this
  version can easily be installed using package.el.

2023-02-09  Tom Tromey  <tromey@adacore.com>

	* dwarf-mode.el: Bump version to 1.8.
	(dwarf-insert-substructure): Tighten regexp.
	(dwarf-refresh-all): New defun.
	(dwarf-mode-map): Bind "A" to dwarf-refresh-all.
	(dwarf-mode): Remove old FIXME.
2023-02-09 13:50:21 -07:00
Alan Modra
87d206578e Clear cached file size when bfd changed to BFD_IN_MEMORY
If file size is calculated by bfd_get_file_size, as it is by
_bfd_alloc_and_read calls in coff_object_p, then it is cached and when
pe_ILF_build_a_bfd converts an archive entry over to BFD_IN_MEMORY,
the file size is no longer valid.  Found when attempting objdump -t on
a very small (27 bytes) ILF file and hitting the pr24707 fix (commit
781152ec18).  So, clear file size when setting BFD_IN_MEMORY on bfds
that may have been read.  (It's not necessary in writable bfds,
because caching is ignored by bfd_get_size when bfd_write_p.)

I also think the PR 24707 fix is no longer neeeded.  All of the
testcases in that PR and in PR24712 are caught earlier by file size
checks when reading the symbols from file.  So I'm reverting that fix,
which just compared the size of an array of symbol pointers against
file size.  That's only valid if on-disk symbols are larger than a
host pointer, so the test is better done in format-specific code.

bfd/
	* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Clear cached
	file size when making a BFD_IN_MEMORY bfd.
	* opncls.c (bfd_make_readable): Likewise.
	* peicode.h (pe_ILF_build_a_bfd): Likewise.
binutils/
	PR 24707
	* objdump.c (slurp_symtab): Revert PR24707 fix.  Tidy.
	(slurp_dynamic_symtab): Tidy.
2023-02-09 09:39:45 +10:30
Nick Clifton
3a8be578d6 Fix documentation of the 'n' symbol type displayed by nm.
PR 30080 * doc/binutils.texi (nm): Update description of the 'n' symbol type.
2023-02-07 11:41:28 +00:00
Jan Beulich
0655669b86 RISC-V: don't disassemble unrecognized insns as .byte
Insn width granularity being 16 bits, producing byte granular output
isn't very useful. With there being a way to specific otherwise
unknown insns to the assembler, use that same representation (to be
precise: its <length>,<encoding> flavor) for disassembly.
2023-02-03 08:20:32 +01:00
Nick Clifton
be527f283a Updated Swedish translation for the binutils sub-directory 2023-01-31 13:02:20 +00:00
Alan Modra
6296342ec4 PR 30060, ASAN error in bfd_cache_close
After bfd_close nothing should access bfd memory.  Now that bfd_close
always tidies up even after an error, attempting to tidy the cached
bfd list by calling bfd_cache_close is wrong and not needed.

	PR 30060
	* ar.c (remove_output): Don't call bfd_cache_close.
	(output_bfd): Delete.
	* arsup.c (ar_end): Call bfd_close_all_done, not bfd_cache_close.
2023-01-31 15:18:04 +10:30
Alan Modra
9884676d9d testsuite XPASSes
This adjusts the testsuite to get rid of a number of XPASSes that have
appeared.  Someone might like to look into a better patch for the s390
change.

aarch64-pe  XPASS: weak symbols
arm-nacl  XPASS: rgn-over8
mcore-pe  XPASS: ld-scripts/provide-8
mips64-linux-gnuabi64  XPASS: vers4
mips64-linux-gnuabi64  XPASS: vers4b
mips-linux-gnu  XPASS: vers4
mips-linux-gnu  XPASS: vers4b
s390-linux-gnu  XPASS: undefined line
sh4-linux-gnu  XPASS: --gc-sections with __start_SECTIONNAME
sh-coff  XPASS: objcopy object (simple copy)
sh-coff  XPASS: objcopy executable (pr25662)

binutils/
	* testsuite/binutils-all/objcopy.exp: Don't xfail "simple
	copy" and "pr25662" on sh-*-coff.  Remove all non-ELF xfails
	on "ELF unknown section type" test.
ld/
	* testsuite/ld-elfvers/vers.exp (vers4, vers4b): Don't xfail
	all mips, just xfail mips irix.
	* testsuite/ld-gc/pr19161.d: Don't xfail sh.
	* testsuite/ld-scripts/rgn-over8-ok.d: Don't xfail nacl.
	* testsuite/ld-scripts/weak.exp: Don't xfail aarch64-pe.
	* testsuite/ld-undefined/undefined.exp: Conditionally xfail
	"undefined line" depending on gcc version for s390.
2023-01-31 15:18:04 +10:30
Nick Clifton
b960c86c1e Updated Swedish translation for the binutils sub-directory 2023-01-23 10:53:12 +00:00
Vladislav Khmelevsky
7e538762c2 Fix objdump --reloc for specific symbol
If objdump is used with both --disassemble=symbol and --reloc options
skip relocations that have addresses before the symbol, so that they
are not displayed.
2023-01-23 12:51:10 +10:30
Indu Bhagat
57ffc61c6d Upload SFrame spec files as well
binutils/
	* README-how-to-make-a-release: Include sframe-spec html and pdf
	files.
2023-01-20 11:14:11 -08:00
Nick Clifton
94e76498c3 Speed up objcopy's note merging.
PR 29993
  * objcopy.c (merge_gnu_build_notes): Remember the last non-deleted note in order to speed up the scan for matching notes.
2023-01-18 11:32:21 +00:00
Nick Clifton
f75c8fc014 Update release making howto 2023-01-16 11:31:39 +00:00
Nick Clifton
69373ba164 Updated translations for the gas and binutils sub-directories 2023-01-16 10:45:38 +00:00
Nick Clifton
311578da0f Update how-to-make-a-release file now that the 2.40 release is out 2023-01-14 15:37:20 +00:00
Alan Modra
2070fc67ba Remove myself as hppa32 maintainer
Reflects the reality that I haven't done much on hppa32 for years.
2023-01-12 17:20:21 +10:30
Mark Harmstone
16fea92ccd Add aarch64-w64-mingw32 target
This adds a mingw target for aarch64, including windres and dlltool.

Note that the old value of jmp_aarch64_bytes was wrong, and this does
the same thing as MSVC does.
2023-01-10 23:30:49 +00:00
Nick Clifton
4004cf8331 Updated transaltions for the gprof and binutils sub-directories 2023-01-09 10:24:13 +00:00
Alan Modra
02da71ee20 PR29972, inconsistent format specification in singular form
PR 29972
	* readelf.c (process_dynamic_section): Correct format string.
2023-01-08 13:10:16 +10:30
Alan Modra
22a95e1a37 Make coff backend data read-only
The bfd_coff_backend_data struct should be read-only, the only thing
preventing this is that objcopy writes to one of the fields,
_bfd_coff_long_section_names.  This patch creates a copy of the field
in bfd coff_obj_tdata, which makes more sense anyway.  When enabling
long section names the intent is to do so for a particular bfd, not
for all bfds that might happen to be using the target xvec.

bfd/
	* coffcode.h: Update coff long section name comment.
	(bfd_coff_set_long_section_names_allowed): Use macro accessor
	to set flag.
	(bfd_coff_set_long_section_names_disallowed): Tidy.
	(coff_backend_info): Return a const pointer.
	(bfd_coff_std_swap_table, ticoff0_swap_table, ticoff1_swap_table),
	(bigobj_swap_table): Make const.
	(bfd_coff_long_section_names): Use tdata copy.
	(coff_mkobject): Set long_section_names from coff_backend_info.
	* coff-go32.c (_bfd_go32_mkobject): Likewise.
	* peicode.h (pe_mkobject): Likewise.
	* coff-sh.c (bfd_coff_small_swap_table): Make const.
	* libcoff-in.h (struct coff_tdata): Add long_section_names,
	reorder fields.
	* libcoff.h: Regenerate.
binutils/
	* objcopy.c (set_long_section_mode): Move earlier in file.
	(copy_object): Call set_long_section_mode here, after setting
	output format.
	(copy_file): Don't call set_long_section_mode.
2023-01-06 21:06:15 +10:30
Nick Clifton
c362d5978e Remove Stephen Casner as the PDP11 maintainer. 2023-01-05 14:40:16 +00:00
Indu Bhagat
aa036eccf0 MAINTAINERS: add myself as maintainer of libsframe
binutils/
	* MAINTAINERS: Add myself as maintainer of libsframe.
2023-01-04 11:42:11 -08:00
Alan Modra
fa19218f8b objcopy fuzzed pe out of memory
This occurs when attempting to read back a section from the output
file in _bfd_XX_bfd_copy_private_bfd_data_common.  The copy of the
section failed size sanity checking, thus it won't be written.

	* objcopy.c (copy_object): Return false if copy_section or
	copy_relocations_in_section fails.
2023-01-04 23:52:26 +10:30
Alan Modra
3bba9d9329 fuzzed file timeout
objcopy of archive, element containing an object with a fuzzed section
size far exceeding the element size.  copy_section detects this, but
the temp file is laid out for the large section.  It can take a long
time to write terabytes of sparse file, a waste of time when it will
be deleted.

	* objcopy.c (copy_archive): Don't write element contents after
	bad status result from copy_object.
2023-01-04 23:52:26 +10:30
Nick Clifton
11982f9f8b Updated translations for various languages and sub-directories 2023-01-03 11:32:42 +00:00
Luis Machado
a8f175d9d0 Add new NT_ARM_ZA and NT_ARM_SSVE register set constants. 2023-01-03 11:15:26 +00:00
Alan Modra
3002e78a7d obsolete target tidy
Delete a few files only used for obsolete targets, and tidy config,
xfails and other pieces of support specific to those targets.  And
since I was editing target triplets in test files, fix the nm
alpha-linuxecoff fails.
2023-01-02 14:03:22 +10:30
Alan Modra
d87bef3a7b Update year range in copyright notice of binutils files
The newer update-copyright.py fixes file encoding too, removing cr/lf
on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and
embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2023-01-01 21:50:11 +10:30
Nick Clifton
d41af08c0b Update version numbers in howto-make-a-release document 2022-12-31 13:01:40 +00:00
Nick Clifton
96e786d198 Update version number and regenerate files 2022-12-31 12:23:00 +00:00
Nick Clifton
a72b07181d Add markers for 2.40 branch 2022-12-31 12:05:28 +00:00
Nick Clifton
826eed8027 Updated Romanian translation for the binutils sub-directory 2022-12-31 08:55:31 +00:00
Alan Modra
a984f112b0 PR29948, heap-buffer-overflow in display_debug_lines_decoded
This fixes a couple of places in display_debug_lines_decoded that were
off by one in checking DWARF5 .debug_line directory indices.  It also
displays the DWARF5 entry 0 for the program current directory rather
than "." as is done for pre-DWARF5.  I decided against displaying
DW_AT_comp_dir for pre-DWARF5 since I figure it is better for readelf
to minimally interpret debug info.

binutils/
	PR 29948
	* dwarf.c (display_debug_lines_decoded): Display the given
	directory entry 0 for DWARF5.  Properly check directory index
	against number of entries in the table.  Revert to using
	unsigned int for n_directories and associated variables.
	Correct warning messages.
gas/
	* testsuite/gas/elf/dwarf-5-loc0.d: Update.
2022-12-30 21:31:19 +10:30
Nick Clifton
75393a2d54 Fix an attempt to allocate an unreasonably large amount of memory when parsing a corrupt ELF file.
PR  29924
	* objdump.c (load_specific_debug_section): Check for excessively
	large sections.
2022-12-21 11:51:23 +00:00
Tom Tromey
0d120726bd Avoid compiler warning in dwarf-do-refresh
The Emacs 28 compiler warns about dwarf-mode.el:

Warning (comp): dwarf-mode.el:180:32: Warning: Unused lexical argument `ignore'

This is easily fixed by prepending "_" to the parameter's name.

binutils/ChangeLog
2022-12-19  Tom Tromey  <tromey@adacore.com>

	* dwarf-mode.el (dwarf-do-refresh): Avoid compiler warning.
2022-12-19 09:46:54 -07:00
Alan Modra
956bc7a29f Tidy PR29893 and PR29908 fix
PR 29893
	PR 29908
	* dwarf.c (display_debug_addr): Combine dwarf5 unit_length checks.
	Delete dead code.
2022-12-19 22:30:36 +10:30