[PATCH v2 2/2] RISC-V: Don't allocate dynamic relocation if it's section was discarded
Nelson Chu
nelson@rivosinc.com
Tue Jul 22 06:35:04 GMT 2025
Committed, thanks.
Nelson
On Thu, Jul 3, 2025 at 11:16 AM Nelson Chu <nelson@rivosinc.com> wrote:
> ---
> bfd/elfnn-riscv.c | 2 ++
> ld/testsuite/ld-riscv-elf/discard.s | 45 +++++++++++++++++++++++++++++
> 2 files changed, 47 insertions(+)
>
> diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
> index 26efe87d687..8f6a33a14ba 100644
> --- a/bfd/elfnn-riscv.c
> +++ b/bfd/elfnn-riscv.c
> @@ -1632,6 +1632,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h,
> void *inf)
> /* Finally, allocate space. */
> for (p = h->dyn_relocs; p != NULL; p = p->next)
> {
> + if (discarded_section (p->sec))
> + continue;
> asection *sreloc = elf_section_data (p->sec)->sreloc;
> sreloc->size += p->count * sizeof (ElfNN_External_Rela);
> }
> diff --git a/ld/testsuite/ld-riscv-elf/discard.s
> b/ld/testsuite/ld-riscv-elf/discard.s
> index 8dd15a83906..f03ea2b4590 100644
> --- a/ld/testsuite/ld-riscv-elf/discard.s
> +++ b/ld/testsuite/ld-riscv-elf/discard.s
> @@ -13,8 +13,53 @@ sym_local:
> sym_global:
> nop
>
> +.global sym_hidden
> +.hidden sym_hidden
> +sym_hidden:
> + nop
> +
> +.global sym_global_abs
> +.set sym_global_abs, 42
> +
> +.global sym_weak_undef
> +.weak sym_weak_undef
> +
> +# Got
> +
> .section .discard.got_local, "ax"
> la x1, sym_local
>
> .section .discard.got_global, "ax"
> la x1, sym_global
> +
> +# Data
> +
> +.section .discard.local,"a"
> +.p2align 1
> +discard_local:
> +.quad sym_local
> +
> +.section .discard.global,"a"
> +.p2align 1
> +discard_global:
> +.quad sym_global
> +
> +.section .discard.hidden,"a"
> +.p2align 1
> +discard_hidden:
> +.quad sym_hidden
> +
> +.section .discard.global_abs,"a"
> +.p2align 1
> +discard_global_abs:
> +.quad sym_global_abs
> +
> +.section .discard.weak_undef,"a"
> +.p2align 1
> +discard_weak_undef:
> +.quad sym_weak_undef
> +
> +.section .discard._DYNAMIC,"a"
> +.p2align 1
> +discard_DYNAMIC:
> +.quad _DYNAMIC
> --
> 2.39.5 (Apple Git-154)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20250722/a8b14f26/attachment.htm>
More information about the Binutils
mailing list