]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
strip: Treat slim GCC/LLVM IR objects the same
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 12 Aug 2025 19:02:08 +0000 (12:02 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 15 Aug 2025 01:12:36 +0000 (18:12 -0700)
commit9b383903e73cd01f2fbe9728d0c31fea765ba8d6
treeb8f340b8dbf1d8f45da4bf31f859b3b8baed9dd8
parentb8e690ef9e3f17e000acf5063daa016b660c6022
strip: Treat slim GCC/LLVM IR objects the same

Slim LLVM IR object is a standalone file whose first 4 bytes are 'B',
'C', 0xc0, 0xde.  GCC IR object is regular ELF object with sections
whose names start with .gnu.lto_.* or .gnu.debuglto_.*.  GCC IR object
uses a .gnu.lto_.lto.<some_hash> section to encode the LTO bytecode
information:

struct lto_section
{
  int16_t major_version;
  int16_t minor_version;
  unsigned char slim_object;

  /* Flags is a private field that is not defined publicly.  */
  uint16_t flags;
};

In slim GCC IR object, the slim_object field is non-zero.  Strip should
treat slim GCC/LLVM IR objects the same.  Since strip won't change slim
LLVM IR objects, it should leave slim GCC IR object unchanged even when
asked to remove all IR objects:

1. Set the lto_type field to lto_slim_ir_object for slim LLVM IR object.
2. Always copy slim IR object as unknown object.

bfd/

PR binutils/33271
* format.c (bfd_set_lto_type): Set the lto_type field to
lto_slim_ir_object for slim LLVM IR object.

binutils/

PR binutils/33271
* objcopy.c (lto_sections_removed): Removed.
(copy_archive): Always copy slim IR object as unknown object.
(copy_file): Likewise.
(strip_main): Updated.

ld/

PR binutils/33271
* testsuite/ld-plugin/lto-binutils.exp: Don't check if fat IR is
available when running slim IR tests.
* testsuite/ld-plugin/strip-1a-s-all.nd: Expect full symbol list.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/format.c
binutils/objcopy.c
ld/testsuite/ld-plugin/lto-binutils.exp
ld/testsuite/ld-plugin/strip-1a-s-all.nd