aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNelson Chu <nelson@rivosinc.com>2025-08-21 12:33:03 +0800
committerNelson Chu <nelson@rivosinc.com>2025-09-04 16:32:44 +0800
commit672a326e2c1a0eb5e318637df205fcdf10cc48a0 (patch)
tree48feb63fb0af9562a3e6a4756400936b334aa431
parentcea397848b868c62993864dbef684877bceef1fc (diff)
downloadbinutils-672a326e2c1a0eb5e318637df205fcdf10cc48a0.zip
binutils-672a326e2c1a0eb5e318637df205fcdf10cc48a0.tar.gz
binutils-672a326e2c1a0eb5e318637df205fcdf10cc48a0.tar.bz2
RISC-V: Don't overwrite got entry to zero for IRELATIVE/RELATIVE relocation
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.
-rw-r--r--bfd/elfnn-riscv.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index af08f7d..6ff6432 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -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