]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Don't allocate dynamic relocation if it's section was discarded
authorNelson Chu <nelson@rivosinc.com>
Thu, 3 Jul 2025 03:16:25 +0000 (11:16 +0800)
committerNelson Chu <nelson@rivosinc.com>
Tue, 22 Jul 2025 06:26:45 +0000 (14:26 +0800)
bfd/elfnn-riscv.c
ld/testsuite/ld-riscv-elf/discard.s

index 84f121c1b14e22699e0bc046a955032425f97aad..af08f7d46f66cdd12b90d185888ad005f915ab87 100644 (file)
@@ -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);
     }
index 8dd15a83906fcd5ab8f6dc879889e4ecf065bf1b..f03ea2b459020785688b9545e47365f6a452be9a 100644 (file)
@@ -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