public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Joseph Faulls <Joseph.Faulls@imgtec.com>
To: "palmer@rivosinc.com" <palmer@rivosinc.com>,
	"nelson@rivosinc.com" <nelson@rivosinc.com>
Cc: "binutils@sourceware.org" <binutils@sourceware.org>,
	"Maciej W. Rozycki" <macro@orcam.me.uk>
Subject: Re: [PATCH] RISC-V: Do not gp relax against an ABS symbol if it is far away.
Date: Wed, 23 Aug 2023 11:16:47 +0000	[thread overview]
Message-ID: <LO4P265MB5914004F34AAA81BE47FF32C801CA@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <LO4P265MB59144C9A915B70461B7A7012800DA@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM>

Ping - is changing all AUIPC/LW to LUI/ADDI/LW for absolute symbols the best way forward?

-----Original Message-----
From: Joseph Faulls 
Sent: Tuesday, August 8, 2023 11:38 AM
To: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: binutils@sourceware.org; palmer@rivosinc.com; nelson@rivosinc.com
Subject: Re: [PATCH] RISC-V: Do not gp relax against an ABS symbol if it is far away.

> What's the use case for using AUIPC/LW to load an absolute symbol?  
> Such symbols are not used in contexts where an address could 
> alternatively be expected, so the correct sequence, and in PIC or PIE 
> code indeed the only valid, for direct references from code is 
> LUI/ADDI

For my clarification, are you saying that the AUIPC/LW should never have been generated? If so, how is it possible for the compiler to know that the symbol referenced will be an absolute symbol?

Regardless, that's a good point, changing all AUIPC/LW to LUI/ADDI for absolute symbols makes sense to me. I could try and do this if it's good way forward, but I would like a second opinion first! Palmer, Nelson, what are your thoughts?

-----Original Message-----
From: Maciej W. Rozycki <macro@orcam.me.uk>
Sent: Tuesday, August 8, 2023 10:49 AM
To: Joseph Faulls <Joseph.Faulls@imgtec.com>
Cc: binutils@sourceware.org; palmer@rivosinc.com; nelson@rivosinc.com
Subject: Re: [PATCH] RISC-V: Do not gp relax against an ABS symbol if it is far away.

On Thu, 27 Jul 2023, Joseph Faulls wrote:

> Relaxations can cause the gp to move after it has been decided to gp 
> relax. Against an absolute symbol, the distance may change such that 
> the offset can no longer fit in the 12-bit immediate field.

 What's the use case for using AUIPC/LW to load an absolute symbol?  Such symbols are not used in contexts where an address could alternatively be expected, so the correct sequence, and in PIC or PIE code indeed the only valid, for direct references from code is LUI/ADDI.  Since you're fiddling with linker relaxation code here, you may well take the opportunity and relax it to LUI/ADDI, or ADDI alone if the value is small.  There may be an issue with RV64 objects if the value turns out outside the 32-bit range though, which will be a relocation overflow.

  Maciej

      parent reply	other threads:[~2023-08-23 11:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27 16:48 Joseph Faulls
2023-07-27 17:02 ` Andreas Schwab
2023-07-27 21:08 ` Palmer Dabbelt
2023-07-28  1:02   ` Nelson Chu
2023-07-28  1:15     ` Nelson Chu
2023-07-28  9:18       ` [EXTERNAL] " Joseph Faulls
2023-07-28 15:03         ` Palmer Dabbelt
2023-07-28 15:52           ` Joseph Faulls
2023-07-28 16:12             ` Palmer Dabbelt
2023-08-08  9:49 ` Maciej W. Rozycki
2023-08-08 10:38   ` [EXTERNAL] " Joseph Faulls
2023-08-08 12:04     ` Maciej W. Rozycki
2023-08-23 11:16     ` Joseph Faulls [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=LO4P265MB5914004F34AAA81BE47FF32C801CA@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM \
    --to=joseph.faulls@imgtec.com \
    --cc=binutils@sourceware.org \
    --cc=macro@orcam.me.uk \
    --cc=nelson@rivosinc.com \
    --cc=palmer@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).