public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* MIPS: the method of getting GOT address for PIC code
@ 2023-08-25  7:16 YunQiang Su
  2024-01-15  6:04 ` YunQiang Su
  0 siblings, 1 reply; 2+ messages in thread
From: YunQiang Su @ 2023-08-25  7:16 UTC (permalink / raw)
  To: apinski--- via Gcc-patches

When working on LLVM, I found this problem
https://github.com/llvm/llvm-project/issues/64974.
Maybe it's time for us to reconsider the way of getting GOT address
for PIC code.

1.Background[1]:
All of the accessing of global variables and normal function calls
needs help from GOT.
So normally, the first 3 instructions of a function are to compute the
address of GOT.
Normally like:
        lui     $gp,%hi(_gp_disp)
        addiu   $gp,$gp,%lo(_gp_disp)
        addu    $gp,$gp,$t9
These 3 instructions load the value of _gp_disp, which is a link-time
constant value,
and add them with $t9, which normally contains the address of the
current function.

So, why $t9? The reason is that the pre-R6 MIPS lacks instructions to
get the PC value.
Thus, the ABI defines that, the caller should call functions with
jr/jarl $t9. So the callee
can get the address of itself by $t9.

2. What's my proposal?
2.1 For MIPSr6, its has instructions to get the current PC value, so
we can use them,
which can gain performance improvement.

2.2 For pre-R6, in fact, it can get the value of PC with NAL
instruction [2], while the performance will be some worse. For the
worst case, the decreasing of performance will be 20%-40%
My plan for pre-R6, is to add a non-default option to use NAL to get
the address of GOT.
Some software, like Linux kernel (for Kalsr support) will need it.

Any suggestions?

[1] https://refspecs.linuxfoundation.org/elf/mipsabi.pdf
[2] https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00087-2B-MIPS64BIS-AFP-6.06.pdf
Page 404


-- 
YunQiang Su

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-15  6:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-25  7:16 MIPS: the method of getting GOT address for PIC code YunQiang Su
2024-01-15  6:04 ` YunQiang Su

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).