[PATCH] RISC-V: PR30237, don't add PT_RISCV_ATTRIBUTES in objcopy/strip
Sungjoon Moon
sumoon@seoulsaram.org
Thu Dec 25 15:06:00 GMT 2025
LLD < 17 doesn't create PT_RISCV_ATTRIBUTES. Adding a program header
to an existing binary breaks layout when space wasn't reserved,
failing with "not enough room for program headers".
Skip when info == NULL, like SPU, S390, and HPPA.
bfd/
PR 30237
elfnn-riscv.c (riscv_elf_additional_program_headers): Return 0
hen info == NULL.
(riscv_elf_modify_segment_map): Likewise, return true.
Signed-off-by: Sungjoon Moon <sumoon@seoulsaram.org>
---
bfd/elfnn-riscv.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 345b3bb96fd..330017eb616 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -5872,10 +5872,13 @@ riscv_elf_is_target_special_symbol (bfd *abfd, asymbol *sym)
static int
riscv_elf_additional_program_headers (bfd *abfd,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
+ struct bfd_link_info *info)
{
int ret = 0;
+ if (info == NULL)
+ return 0;
+
/* See if we need a PT_RISCV_ATTRIBUTES segment. */
if (bfd_get_section_by_name (abfd, RISCV_ATTRIBUTES_SECTION_NAME))
++ret;
@@ -5885,12 +5888,15 @@ riscv_elf_additional_program_headers (bfd *abfd,
static bool
riscv_elf_modify_segment_map (bfd *abfd,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
+ struct bfd_link_info *info)
{
asection *s;
struct elf_segment_map *m, **pm;
size_t amt;
+ if (info == NULL)
+ return true;
+
/* If there is a .riscv.attributes section, we need a PT_RISCV_ATTRIBUTES
segment. */
s = bfd_get_section_by_name (abfd, RISCV_ATTRIBUTES_SECTION_NAME);
--
2.52.0
More information about the Binutils
mailing list