]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Don't overwrite got entry to zero for IRELATIVE/RELATIVE relocation
authorNelson Chu <nelson@rivosinc.com>
Thu, 21 Aug 2025 04:33:03 +0000 (12:33 +0800)
committerNelson Chu <nelson@rivosinc.com>
Thu, 4 Sep 2025 08:32:44 +0000 (16:32 +0800)
Even the final result is correct since we encode the relocation into r_addend,
so glibc won't need to get the content of got entry when resolving relative
relocation, it still werid that finish_dynamic_symbol cleans what we filled in
the relocate_section.

bfd/elfnn-riscv.c

index af08f7d46f66cdd12b90d185888ad005f915ab87..6ff64325f8583a238703dc52b04333cf68e74a1f 100644 (file)
@@ -3605,19 +3605,13 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
              else
                {
                  /* Generate R_RISCV_NN.  */
-                 BFD_ASSERT ((h->got.offset & 1) == 0);
-                 BFD_ASSERT (h->dynindx != -1);
-                 rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_NN);
-                 rela.r_addend = 0;
+                 goto do_reloc_nn;
                }
            }
          else if (bfd_link_pic (info))
            {
              /* Generate R_RISCV_NN.  */
-             BFD_ASSERT ((h->got.offset & 1) == 0);
-             BFD_ASSERT (h->dynindx != -1);
-             rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_NN);
-             rela.r_addend = 0;
+             goto do_reloc_nn;
            }
          else
            {
@@ -3655,15 +3649,15 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
        }
       else
        {
+  do_reloc_nn:
          BFD_ASSERT ((h->got.offset & 1) == 0);
          BFD_ASSERT (h->dynindx != -1);
          rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_NN);
          rela.r_addend = 0;
+         bfd_put_NN (output_bfd, 0,
+                     sgot->contents + (h->got.offset & ~(bfd_vma) 1));
        }
 
-      bfd_put_NN (output_bfd, 0,
-                 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
-
       if (use_elf_append_rela)
        riscv_elf_append_rela (output_bfd, srela, &rela);
       else