* [binutils-gdb] RISC-V: Enable x0 base relaxation for relax_pc even if --no-relax-gp.
@ 2023-04-28 6:28 Nelson Chu
0 siblings, 0 replies; only message in thread
From: Nelson Chu @ 2023-04-28 6:28 UTC (permalink / raw)
To: bfd-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=03e63766ef099ba85d8917c9f179441ae086375e
commit 03e63766ef099ba85d8917c9f179441ae086375e
Author: Nelson Chu <nelson@rivosinc.com>
Date: Fri Apr 21 16:28:39 2023 +0800
RISC-V: Enable x0 base relaxation for relax_pc even if --no-relax-gp.
Let --no-relax-gp only disable the gp relaxation for lui and pcrel
relaxations, since x0 base and gp relaxations are different optimizations
in fact, but just use the same function to handle.
bfd/
* elfnn-riscv.c (_bfd_riscv_relax_pc): Like _bfd_riscv_relax_lui,
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 = riscv_elf_hash_table (link_info);
bfd_byte *contents = elf_section_data (sec)->this_hdr.contents;
+ /* Can relax to x0 even when gp relaxation is disabled. */
bfd_vma gp = 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 = riscv_elf_hash_table (link_info);
- bfd_vma gp = riscv_global_pointer_value (link_info);
+ /* Can relax to x0 even when gp relaxation is disabled. */
+ bfd_vma gp = htab->params->relax_gp
+ ? riscv_global_pointer_value (link_info)
+ : 0;
BFD_ASSERT (rel->r_offset + 4 <= sec->size);
@@ -4942,7 +4946,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
|| type == R_RISCV_TPREL_LO12_I
|| type == R_RISCV_TPREL_LO12_S)
relax_func = _bfd_riscv_relax_tls_le;
- else if (!bfd_link_pic (info) && htab->params->relax_gp
+ else if (!bfd_link_pic (info)
&& (type == R_RISCV_PCREL_HI20
|| type == R_RISCV_PCREL_LO12_I
|| type == R_RISCV_PCREL_LO12_S))
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-28 6:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 6:28 [binutils-gdb] RISC-V: Enable x0 base relaxation for relax_pc even if --no-relax-gp Nelson Chu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).