From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: "open list:MIPS" <linux-mips@vger.kernel.org>,
binutils@sourceware.org, gcc@gcc.gnu.org, syq@debian.org,
Matthew Fortune <mfortune@gmail.com>
Subject: Re: HELP: MIPS PC Relative Addressing
Date: Wed, 24 Feb 2021 18:30:45 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.21.2102241813420.1900@angie.orcam.me.uk> (raw)
In-Reply-To: <3ddc0595-c443-868e-c0a4-08ae8934f116@flygoat.com>
On Wed, 24 Feb 2021, Jiaxun Yang wrote:
> For RISC-V, %pcrel_lo shall point to the label of corresponding %pcrel_hi,
> like
>
> .LA0:
> auipc a0, %pcrel_hi(sym)
> addi a0, a0, %pcrel_lo(.LA0)
I commented on it once, in the course of the FDPIC design project, and I
find it broken by design. Sadly it has made it into the RISC-V psABI and
it is hard to revert at this time, too many places have started relying on
it.
> However, for MIPS %pcrel_lo simply calculate LO16 of the symbol to current
> PC, thus PC relative addressing will look like:
>
> .LA0:
> auipc a0, %pcrel_hi(sym)
> .LA1:
> addi a0, %pcrel_lo(sym + (.LA1 - .LA0))
>
> I found it's very difficult for GCC to generate this kind of pcrel_lo
> expression,
> RTX label_ref can't be lower into such LOW_SUM expression.
You may want to use composed relocations to refer to .LA1 (R_MIPS_32) and
.LA0 (R_MIPS_SUB). There may or may not be linker updates needed; unlike
the RISC-V one the MIPS BFD backend already supports composed relocations
with the usual ELF gABI semantics. It would be good to switch to RELA at
this point universally too; none of new stuff will work with old linkers
anyway.
HTH,
Maciej
next prev parent reply other threads:[~2021-02-24 17:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-24 14:18 Jiaxun Yang
2021-02-24 17:30 ` Maciej W. Rozycki [this message]
2021-02-24 21:46 ` Jim Wilson
2021-02-24 22:00 ` Maciej W. Rozycki
2021-02-25 0:55 ` Jiaxun Yang
2021-02-27 16:45 ` Maciej W. Rozycki
2021-02-24 21:40 ` Jim Wilson
2021-02-25 0:48 ` Jiaxun Yang
2021-02-25 2:57 ` Maciej W. Rozycki
2021-02-25 3:09 ` Jiaxun Yang
2021-02-25 22:30 ` Maciej W. Rozycki
2021-03-02 7:23 ` Jiaxun Yang
2021-03-02 15:30 ` Maciej W. Rozycki
2021-03-04 3:33 ` Jiaxun Yang
2021-03-04 16:54 ` Maciej W. Rozycki
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=alpine.DEB.2.21.2102241813420.1900@angie.orcam.me.uk \
--to=macro@orcam.me.uk \
--cc=binutils@sourceware.org \
--cc=gcc@gcc.gnu.org \
--cc=jiaxun.yang@flygoat.com \
--cc=linux-mips@vger.kernel.org \
--cc=mfortune@gmail.com \
--cc=syq@debian.org \
/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).