From: Nelson Chu Date: Thu, 21 Aug 2025 04:33:03 +0000 (+0800) Subject: RISC-V: Don't overwrite got entry to zero for IRELATIVE/RELATIVE relocation X-Git-Tag: gdb-17-branchpoint~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=672a326e2c1a0eb5e318637df205fcdf10cc48a0;p=thirdparty%2Fbinutils-gdb.git 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. --- diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index af08f7d46f6..6ff64325f85 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