Re: HELP: MIPS PC Relative Addressing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



在 2021/2/25 上午1:30, Maciej W. Rozycki 写道:
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.

Thanks for your hint;-)

I'm unsure about how should we express composed relocations in assembly :-/

MIPS N32/N64 ABI is already using RELA, do you mean switch to RELA for o32
as well?

Thanks.

- Jiaxun


  HTH,

   Maciej




[Index of Archives]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux