4750 Commits

Author SHA1 Message Date
Jan Beulich
4fa9476ad2 objcopy: also check --file-alignment option argument
... to be a power of two, just like --section-alignment does.
2025-04-04 10:25:31 +02:00
Jan Beulich
379535a2e6 binutils: run objcopy set-section-alignment also for COFF
There's no reason to limit this to just ELF. TI C30 and Z8k don't encode
section alignment in the section entries though (which can't be quite
right, or there would need to be another means by which to express
alignment needs), so --set-section-alignment simply has no effect there.
2025-04-04 10:25:16 +02:00
Jan Beulich
43ea7d00a7 objcopy: constrain --section-alignment to PE binaries again
PR binutils/32732

The --set-section-alignment option is what ought to be used on object
files; --section-alignment should be affecting PE binaries only, and
only the value stored in the header. Sections don't individually have
alignment recorded there; see 6f8f6017a0c4 ("PR27567, Linking PE files
adds alignment section flags to executables").

Undo the core part of 121a3f4b4f4a ("Update objcopy's
--section-alignment option so that it sets the alignment flag on..."),
which includes removing the testcase again, while leaving all secondary
changes in place. (Note that the testcase did fail anyway for
i?86-interix, with objdump saying "option -P/--private not supported by
this file".)
2025-04-04 10:24:56 +02:00
Jan Beulich
cc0693d394 ar/objcopy: harmonize .exe suffix stripping
With it only being the tail of the name which wants checking, using
lbasename() isn't helpful. Mirror what objcopy.c:main() does to ar.c,
merely chaning the plain int of the local variable to size_t.
2025-04-04 10:20:31 +02:00
Jan Beulich
25a0668a95 binutils: properly split ar and ranlib
By not linking the exact same object file twice, in particular ranlib can
benefit quite a bit from the compiler eliminating dead code.
2025-04-04 10:20:14 +02:00
Jan Beulich
2fb3d389d8 binutils: properly split objcopy and strip
By not linking the exact same object file twice, in particular strip can
benefit quite a bit from the compiler eliminating dead code.
2025-04-04 10:19:51 +02:00
Alan Modra
6c3458a8b7 PR32829, SEGV on objdump function debug_type_samep
u.kenum is always non-NULL, see debug_make_enum_type.

	PR 32829
	* debug.c (debug_type_samep): Correct incomplete enum test.
	(debug_write_type): Remove dead code.
2025-04-01 23:45:46 +10:30
Clément Chigot
71320db650 binutils/testsuite: don't tail the same input and output file
The output file could be created before the input is gathered by tail,
erasing the later before it's being proceeded.

This happened on rare cases when performing remote tests on
Ubuntu 24.04.
2025-04-01 10:14:54 +02:00
Clément Chigot
c27e4f5273 binutils/testsuite: move objdump test output into tmpdir
"objdump.out" is a testsuite trace and thus should be created within the
tmpdir.
2025-04-01 10:14:54 +02:00
Marek Pikuła
b667765b2c doc/riscv: Add description of disassembler options
Up to this point, no mention of RISC-V-specific disassembler options was
mentioned in binutils documentation. This patch includes description for
all of the currently supported options.

Signed-off-by: Marek Pikuła <m.pikula@partner.samsung.com>
2025-03-28 09:20:41 +08:00
WANG Xuerui
6d1823dc89 LoongArch: Fix disassembly option parsing stopping at the first option
Turns out the return value of parse_loongarch_dis_option acts as an
error code, and previously the function always signified failure with
a non-zero return value, making only the first disassembly option get
to take effect.

Fix by adding the missing `return 0`'s to the two success code paths.

Signed-off-by: WANG Xuerui <git@xen0n.name>
2025-03-26 15:49:58 +08:00
Jan Beulich
daf53ffeaa strip: don't corrupt PE binary's section/file alignment
Section and file alignment are supposed to remain unaltered when PE
binaries are stripped. While this is the case when they're strip-ed
individually, passing multiple such files to strip would reset the
two values to their defaults in all but the first of those binaries.
2025-03-21 08:33:58 +01:00
Nick Clifton
7f6cdc6a9e
Updated translations for BFD and BINUTILS sub-directories 2025-03-18 12:25:19 +00:00
Nelson Chu
614d1b72ce gas/NEW: Updated news related to mapping symbol and extensions for risc-v 2025-03-18 13:42:02 +08:00
Jan Beulich
cdd8492b05 objdump: permit disassembling multiple individual functions
Compilers may split functions, e.g. into a "hot" and "cold" part, or
they may emit special case instantiations (e.g. as a result of IPA). It
can be helpful to be able to disassemble all of the parts or clones in
one go. Permit using "--disassemble=" multiple times.
2025-03-07 11:24:19 +01:00
Jan Beulich
60e254b701 objdump: properly disassemble successive functions of the same name
... when only their symbol was requested for disassembly. Addressing the
respective FIXME is as easy as coverting the "else" there to an if()
with the opposite condition, thus accounting for the disabling the
original if() may have effected.
2025-03-07 11:23:13 +01:00
Matthieu Longo
3f8f380190 clean-up readelf: simplify and flatten body of process_attributes
- use find_section_by_type() instead of a for-loop.
- reindent the whole function accordingly.
- move declaration of variables nearer from their usage.
- prune else branch by using a goto in the error case.

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 6d3ec65a8a1..878012da8f0 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -19268,42 +19268,32 @@ process_attributes (Filedata * filedata,
                    unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
                    unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
 {
-  Elf_Internal_Shdr * sect;
-  unsigned i;
-  bool res = true;
-
   /* Find the section header so that we get the size.  */
-  for (i = 0, sect = filedata->section_headers;
-       i < filedata->file_header.e_shnum;
-       i++, sect++)
-    {
-      unsigned char * contents;
-      unsigned char * p;
+  Elf_Internal_Shdr * sect = find_section_by_type (filedata, proc_type);
+  if (sect == NULL)
+    sect = find_section_by_type (filedata, SHT_GNU_ATTRIBUTES);

-      if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
-       continue;
+  if (sect == NULL)
+    /* No section, exit without error.  */
+    return true;

-      contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1,
-                                             sect->sh_size, _("attributes"));
+  unsigned char * contents = (unsigned char *)
+    get_data (NULL, filedata, sect->sh_offset, 1, sect->sh_size, _("attributes"));
   if (contents == NULL)
-       {
-         res = false;
-         continue;
-       }
+    return false;

-      p = contents;
+  bool res = true;
+  unsigned char * p = contents;
   /* The first character is the version of the attributes.
      Currently only version 1, (aka 'A') is recognised here.  */
   if (*p != 'A')
     {
       printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
       res = false;
+      goto free_data;
     }
-      else
-       {
-         uint64_t section_len;

-         section_len = sect->sh_size - 1;
+  uint64_t section_len = sect->sh_size - 1;
   p++;

   while (section_len > 0)
@@ -19456,10 +19446,9 @@ process_attributes (Filedata * filedata,
            attr_len = 0;
        }
     }
-       }

+free_data:
   free (contents);
-    }

   return res;
 }
2025-03-04 11:02:03 +00:00
Matthieu Longo
1efbe98a4d clean-up: fix conflicting symbol with unknown from bfd/elf-bfd.h 2025-03-04 11:02:02 +00:00
Matthieu Longo
5d526bdf5f clean-up: fix annoying spaces in binutils/readelf.c 2025-03-04 11:02:02 +00:00
Tom Tromey
ef8975b494 Display entry offset for .debug_names
Since commit ad6dde5aaae ("gdb/dwarf: write offset to parent entry for
DW_IDX_parent"), gdb now emits a .debug_names where the DW_IDX_parent
attribute refers to the parent entry's offset -- previously, due to
some confusion in the standard, gdb used the index of the parent's
name table entry.

This patch changes the .debug_names display code to display each
entry's offset.  This makes it easy to refer from a DW_IDX_parent to
the correct entry.

The new output looks like this:

[...]
Symbol table:
[  1] circular1: <0><1> DW_TAG_module DW_IDX_compile_unit=1 DW_IDX_die_offset=<0x19> DW_IDX_GNU_language=19
[...]
[  6] found: <0x28><2> DW_TAG_subprogram DW_IDX_compile_unit=1 DW_IDX_die_offset=<0x38> DW_IDX_GNU_language=19 DW_IDX_parent=<0x0>

Here you can see that DW_IDX_parent=0 refers to "circular1: <0>".
2025-03-03 21:04:07 -07:00
Alan Modra
a8a9fc7429 objdump: is_same_section
This fixes a deficiency in commit 660df28acfa1, which should have used
the same logic as that in sym_ok.  Ideally both places would not
compare section names, but it can be a little tricky to match a
section in the real object file with a section in a debug file.
Extend commit 39f0547e554d to use section name, vma and size.

	* objcopy (is_same_section): New function.
	(compare_symbols, sym_ok): Use it here.
2025-03-04 08:23:16 +10:30
Alan Modra
7166166ec0 rescoff: ensure file is PE
read_coff_rsrc makes one check on object file contents, the existence
of a .rsrc section.  It doesn't check that the file is PE but blindly
accesses bfd pe_data.  Fix that by adding the necessary checks.
Also, the "resources nest too deep" error isn't an overrun, ie. the
"address out of bounds" message isn't correct.  Fix that too.
2025-03-04 08:23:16 +10:30
Alan Modra
11b6914ce6 windres: delete function forward declaraions
Most of these were not needed, and moving a few functions around
removes the need for any.
2025-03-04 08:23:16 +10:30
Nick Alcock
bf89fce0cf
readelf, objdump: fix ctf dict leak
ctf_archive_next returns an opened dict, which must be closed by the caller.

Thanks to Alan Modra for spotting this.

binutils/
	* objdump.c (dump_ctf): Close dict.
	* readelf.c (dump_section_as_ctf): Likewise.
2025-02-28 14:16:29 +00:00
Jonas 'Sortie' Termansen
a3177d19fb Remove unnecessary non-standard & unportable inclusions.
<memory.h> is not needed and not standardized and is just an alias for
<string.h>.

<sys/param.h> is not needed and not standardized and contains a kitchen
sink of various unportable definitions not agreed upon and best done
manually or through other headers.

These fixes are needed to compile binutils on Sortix and other operating
systems with a strict POSIX.1-2024 libc without obsolete features.

Signed-off-by: Jonas 'Sortie' Termansen <sortie@maxsi.org>
2025-02-28 13:24:50 +00:00
Nick Clifton
c619e92beb
objdump: Inform users if RELR relocs are present in a file when using the -r or -R options and no regular relocs are present.
PR 32459
2025-02-24 13:44:45 +00:00
Jan Beulich
2b0a62b17f IQ2000: drop maintainer
After I found his email bouncing, Stan, via private communication which
Nick helped with, has indicated that - having retired - he won't any
longer fulfill the maintainer role here.
2025-02-21 10:28:46 +01:00
Tom Tromey
3fddd4e758 Fix "compilation unit" matching in dwarf-font-lock-keywords
Today I learned that, at least on my system (Fedora 40), the printf
"%#x" format will produce "0" rather than "0x0" when given 0 as an
argument.

This causes dwarf-mode.el to not correctly fontify the very first
"Compilation Unit" line it sees.

This patch adapts dwarf-mode.el.  As always, this patch bumps the
version number for easier installation.

I am checking this in.
2025-02-20 09:45:25 -07:00
Alan Modra
cb1861cb8f bintuils/dwarf.c indentation fixes
plus a few other formatting fixes.
2025-02-19 23:11:23 +10:30
Alan Modra
e51fdff7d2 binutils/dwarf.c debug_information leak
It is possible with fuzzed files to have num_debug_info_entries zero
after allocating space for debug_information, leading to multiple
allocations.

	* dwarf.c (process_debug_info): Don't test num_debug_info_entries
	to determine whether debug_information has been allocated,
	test alloc_num_debug_info_entries.
2025-02-19 23:03:11 +10:30
Alan Modra
ba6ad3a18c PR32716, objdump -i memory leak
PR binutils/32716
	* bucomm.c (display_info): Free arg.info.
2025-02-19 08:01:13 +10:30
Alan Modra
619f863c55 dlltool memory leaks
dlltool copies strings with strdup all over the place, seeming to take
the attitude that anything might be modified.  That leads to lots of
memory leaks.  Fixing the leaks by removing the strdup calls of course
means you need to take good care that strings *aren't* modified.  This
isn't as easy as it sounds due to functions like xlate that have
const char* params but then manage to modify the strings.  I've fixed
xlate, but if I've missed something somewhere then this patch likely
will break dlltool.  Testsuite coverage of dlltool isn't good.

The leaks in defparse.y are small.  It also is a little work to verify
that all the strings I'm freeing in defparse.y are in fact malloc'd,
which is no doubt why the leaks are there.

Using bfd_xalloc in make_one_lib_file and functions called from there
results in memory being freed automatically at the bfd_close in
make_one_lib_file, without any fuss.

The patch also makes use of xasprintf to replace xmalloc followed by
sprintf.

	* defparse.y (opt_name2): Free incoming ID strings after
	adding prefix/suffix.
	* dlltool.c (struct ifunct): Constify char* fields.
	(struct iheadt, struct dlist): Likewise.
	(set_dll_name_from_def,	def_heapsize, def_stacksize),
	(def_section, assemble_file): Use xasprintf.
	(def_name, def_library): Free dll_name and name.
	(def_description, new_directove): Don't strdup incoming args.
	(append_import): Likewise.
	(def_import): Free module after appending dllext.
	(run): Free temp_base.
	(scan_filtered_symbols): Don't segfault on NULL strchr return.
	Remove unnecessary strdup.
	(scan_drectve_symbols): Likewise.  Constify pointers.
	Use bfd_malloc_and_get_section.  Use xmemdup.
	(add_excludes): Use xasprintf and xstrdup.
	(gen_exp_file): Free xlate return.  Constify pointer to suit
	struct changes.  Free copy.
	(xlate): Always copy arg.  Use xasprintf and xstrdup.
	(make_imp_label): Add bfd arg.  Use bfd_xalloc.
	(gen_lib_file): Adjust to suit.
	(make_one_lib_file): Likewise.  Use bfd_xalloc for section data
	and relocs.  Simplify code calling xlate, and free xlate return.
	(dll_name_list_free_contents): Flatten recursion.
	(mangle_defs): Free d_export_vec.
	(main): Formatting.  Use xasprintf.
	* resres.c (write_res_id): Free section data.
2025-02-14 09:11:23 +10:30
Alan Modra
dd39a8c388 Fix typo in objdump info/man page 2025-02-10 09:03:06 +10:30
Nick Clifton
2470de6c0c
Update with latest changes to src-release.sh 2025-02-04 11:50:32 +00:00
Nick Clifton
f5d5d53e80
Remove a couple of entries in the binutils MAINTAINERS file 2025-01-30 16:01:02 +00:00
Nick Clifton
50505c486e
More updated translations 2025-01-21 10:48:02 +00:00
Alan Modra
592819f718 run_dump_test warning/error regexp
This allows you to specify a run_dump_test warning that may or may not
be present using
warning: (warning_text_goes_here)?
ie. the regexp matches an empty string.
2025-01-21 08:42:44 +10:30
Nick Clifton
8ae7da3ae8
Update translations for various sub-directories 2025-01-20 16:19:22 +00:00
Nick Clifton
639dc893ab
Update release readme for gold-in-branches change 2025-01-20 16:18:36 +00:00
Nick Clifton
876bcbeb43
Update how-to-make-a-release document after creating the 2.44 branch 2025-01-20 10:29:59 +00:00
Nick Clifton
8c7653ab09
Change version to 2.44.50 and regenerate files 2025-01-19 12:40:46 +00:00
Nick Clifton
572920f968
Add name of 2.44 branch 2025-01-19 12:09:35 +00:00
Nick Clifton
b49d12e2c5
Add markers for bihnutils 2.44 branch 2025-01-19 12:09:01 +00:00
Vladimir Mezentsev
b715bf1f35 gprofng: update binutils/NEWS for 2.44
ChangeLog
2025-01-16  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* binutils/NEWS: Updated.
2025-01-17 08:26:46 -08:00
Nick Clifton
978dae651e
Have readelf sanitize the program interpreter string before displaying it. 2025-01-16 15:48:40 +00:00
Alan Modra
1439d7d5f3 Fix known minor objdump leak
* objdump.c (main): Free disassembler_options.
2025-01-15 22:19:31 +10:30
Alan Modra
baac6c221e PR32560 stack-buffer-overflow at objdump disassemble_bytes
There's always someone pushing the boundaries.

	PR 32560
	* objdump.c (MAX_INSN_WIDTH): Define.
	(insn_width): Make it an unsigned long.
	(disassemble_bytes): Use MAX_INSN_WIDTH to size buffer.
	(main <OPTION_INSN_WIDTH>): Restrict size of insn_width.
2025-01-15 19:18:46 +10:30
Adhemerval Zanella
80dc29527f ld: Add --enable-memory-seal configure option
Add --enable-memory-seal linker configure option to enable memory
sealing (GNU_PROPERTY_MEMORY_SEAL) by default.

Change-Id: I4ce4ff33657f0f09b1ceb06210b6fcaa501f1799
2025-01-14 13:18:52 -03:00
Adhemerval Zanella
4d890484df elf: Add GNU_PROPERTY_MEMORY_SEAL gnu property
The GNU_PROPERTY_MEMORY_SEAL gnu property is a way to mark binaries
to be memory sealed by the loader, to avoid further changes of
PT_LOAD segments (such as unmapping or change permission flags).
This is done along with Linux kernel (the mseal syscall [1]), and
C runtime supports to instruct the kernel on the correct time during
program startup (for instance, after RELRO handling).  This support
is added along the glibc support to handle the new gnu property [2].

This is a opt-in security features, like other security hardening
ones like NX-stack or RELRO.

The new property is ignored if present on ET_REL objects, and only
added on ET_EXEC/ET_DYN if the linker option is used.  A gnu property
is used instead of DT_FLAGS_1 flag to allow memory sealing to work
with ET_EXEC without PT_DYNAMIC support (at least on glibc some ports
still do no support static-pie).

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8be7258aad44b5e25977a98db136f677fa6f4370
[2] https://sourceware.org/pipermail/libc-alpha/2024-September/160291.html

Change-Id: Id47fadabecd24be0e83cff45653f7ce9a900ecf4
2025-01-14 13:18:43 -03:00
Matthieu Longo
c4ab4dd7bd aarch64 DWARF: add new CFI directive for PAuth_LR
This patch adds a new CFI directive (cfi_negate_ra_state_with_pc) which
set an additional bit in the RA state to inform that RA was signed with
SP but also PC as an additional diversifier.

RA state | Description
0b00     | Return address not signed (default if no cfi_negate_ra_state*)
0b01     | Return address signed with SP (cfi_negate_ra_state)
0b10     | Invalid state
0b11     | Return address signed with SP+PC (cfi_negate_ra_state_with_pc)

Approved-by: Indu Bhagat <indu.bhagat@oracle.com>
Approved-by: Jan Beulich <jbeulich@suse.com>
2025-01-14 10:53:21 +00:00