From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7803) id 17BEA3858D37; Fri, 28 Apr 2023 06:28:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17BEA3858D37 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nelson Chu To: bfd-cvs@sourceware.org Subject: [binutils-gdb] RISC-V: Relax R_RISCV_[PCREL_]LO12_I/S to R_RISCV_GPREL_I/S for undefined weak. X-Act-Checkin: binutils-gdb X-Git-Author: Nelson Chu X-Git-Refname: refs/heads/master X-Git-Oldrev: e4452aa670e5cec9c78b241d3572c91170598965 X-Git-Newrev: a48ddc3b572eb7fd9325867c4946f6bbb1f9b5b4 Message-Id: <20230428062819.17BEA3858D37@sourceware.org> Date: Fri, 28 Apr 2023 06:28:19 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Apr 2023 06:28:19 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da48ddc3b572e= b7fd9325867c4946f6bbb1f9b5b4 commit a48ddc3b572eb7fd9325867c4946f6bbb1f9b5b4 Author: Nelson Chu Date: Fri Apr 21 16:28:38 2023 +0800 RISC-V: Relax R_RISCV_[PCREL_]LO12_I/S to R_RISCV_GPREL_I/S for undefin= ed weak. =20 bfd/ *elfnn-riscv.c (_bfd_riscv_relax_lui): For undefined weak symbo= l, just relax the R_RISCV_LO12_I/S to R_RISCV_GPREL_I/S, and then = don't update the rs1 to zero until relocate_section. (_bfd_riscv_relax_pc): Likewise, but for R_RISCV_PCREL_LO12_I/S. Diff: --- bfd/elfnn-riscv.c | 55 ++++++---------------------------------------------= ---- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index e90e36b58bb..499f51ee857 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -4552,27 +4552,11 @@ _bfd_riscv_relax_lui (bfd *abfd, switch (ELFNN_R_TYPE (rel->r_info)) { case R_RISCV_LO12_I: - if (undefined_weak) - { - /* Change the RS1 to zero. */ - bfd_vma insn =3D bfd_getl32 (contents + rel->r_offset); - insn &=3D ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - } - else - rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_I); + rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_I); return true; =20 case R_RISCV_LO12_S: - if (undefined_weak) - { - /* Change the RS1 to zero. */ - bfd_vma insn =3D bfd_getl32 (contents + rel->r_offset); - insn &=3D ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - } - else - rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_S); + rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_S); return true; =20 case R_RISCV_HI20: @@ -4737,7 +4721,6 @@ _bfd_riscv_relax_pc (bfd *abfd ATTRIBUTE_UNUSED, bool undefined_weak) { struct riscv_elf_link_hash_table *htab =3D riscv_elf_hash_table (link_in= fo); - bfd_byte *contents =3D elf_section_data (sec)->this_hdr.contents; bfd_vma gp =3D riscv_global_pointer_value (link_info); =20 BFD_ASSERT (rel->r_offset + 4 <=3D sec->size); @@ -4830,39 +4813,13 @@ _bfd_riscv_relax_pc (bfd *abfd ATTRIBUTE_UNUSED, switch (ELFNN_R_TYPE (rel->r_info)) { case R_RISCV_PCREL_LO12_I: - if (undefined_weak) - { - /* Change the RS1 to zero, and then modify the relocation - type to R_RISCV_LO12_I. */ - bfd_vma insn =3D bfd_getl32 (contents + rel->r_offset); - insn &=3D ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_LO12_I); - rel->r_addend =3D hi_reloc.hi_addend; - } - else - { - rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_I); - rel->r_addend +=3D hi_reloc.hi_addend; - } + rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_I); + rel->r_addend +=3D hi_reloc.hi_addend; return true; =20 case R_RISCV_PCREL_LO12_S: - if (undefined_weak) - { - /* Change the RS1 to zero, and then modify the relocation - type to R_RISCV_LO12_S. */ - bfd_vma insn =3D bfd_getl32 (contents + rel->r_offset); - insn &=3D ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_LO12_S); - rel->r_addend =3D hi_reloc.hi_addend; - } - else - { - rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_S); - rel->r_addend +=3D hi_reloc.hi_addend; - } + rel->r_info =3D ELFNN_R_INFO (sym, R_RISCV_GPREL_S); + rel->r_addend +=3D hi_reloc.hi_addend; return true; =20 case R_RISCV_PCREL_HI20: