From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7803) id 2974A3858C2D; Fri, 28 Apr 2023 06:28:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2974A3858C2D 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: Enable x0 base relaxation for relax_pc even if --no-relax-gp. X-Act-Checkin: binutils-gdb X-Git-Author: Nelson Chu X-Git-Refname: refs/heads/master X-Git-Oldrev: a48ddc3b572eb7fd9325867c4946f6bbb1f9b5b4 X-Git-Newrev: 03e63766ef099ba85d8917c9f179441ae086375e Message-Id: <20230428062824.2974A3858C2D@sourceware.org> Date: Fri, 28 Apr 2023 06:28:24 +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:24 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D03e63766ef09= 9ba85d8917c9f179441ae086375e commit 03e63766ef099ba85d8917c9f179441ae086375e Author: Nelson Chu Date: Fri Apr 21 16:28:39 2023 +0800 RISC-V: Enable x0 base relaxation for relax_pc even if --no-relax-gp. =20 Let --no-relax-gp only disable the gp relaxation for lui and pcrel relaxations, since x0 base and gp relaxations are different optimizatio= ns in fact, but just use the same function to handle. =20 bfd/ * elfnn-riscv.c (_bfd_riscv_relax_pc): Like _bfd_riscv_relax_lu= i, set gp to zero when --no-relax-gp, then we should still keep the x0 base relaxation. (_bfd_riscv_relax_section): Enable _bfd_riscv_relax_pc when --no-relax-gp, we will disable the gp relaxation in the _bfd_riscv_relax_pc. Diff: --- bfd/elfnn-riscv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 499f51ee857..a23b91ac15c 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -4508,6 +4508,7 @@ _bfd_riscv_relax_lui (bfd *abfd, { 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; + /* Can relax to x0 even when gp relaxation is disabled. */ bfd_vma gp =3D htab->params->relax_gp ? riscv_global_pointer_value (link_info) : 0; @@ -4721,7 +4722,10 @@ _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_vma gp =3D riscv_global_pointer_value (link_info); + /* Can relax to x0 even when gp relaxation is disabled. */ + bfd_vma gp =3D htab->params->relax_gp + ? riscv_global_pointer_value (link_info) + : 0; =20 BFD_ASSERT (rel->r_offset + 4 <=3D sec->size); =20 @@ -4942,7 +4946,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec, || type =3D=3D R_RISCV_TPREL_LO12_I || type =3D=3D R_RISCV_TPREL_LO12_S) relax_func =3D _bfd_riscv_relax_tls_le; - else if (!bfd_link_pic (info) && htab->params->relax_gp + else if (!bfd_link_pic (info) && (type =3D=3D R_RISCV_PCREL_HI20 || type =3D=3D R_RISCV_PCREL_LO12_I || type =3D=3D R_RISCV_PCREL_LO12_S))