Description
The mips64 port currently fails to handle calls to SDYNIMPORT
symbols, even when external linking is in use, since it emits R_MIPS_26
relocations, resulting in "relocation truncated to fit" warnings. An equivalent call from assembly when compiled with LLVM results in the following:
0: df990000 ld t9,0(gp)
4: 0320f809 jalr t9
8: 00000000 nop
Furthermore, two relocations are produced for the external symbol - a R_MIPS_CALL16
relocation for the ld
instruction and a R_MIPS_JALR
relocation for the jalr
instruction.
There are a couple of additional things to note here - firstly, PIC code requires that register 25 (t9
) contains the address of the called function, which is why this register is used here. Secondly, when the external linker performs the R_MIPS_CALL16 relocation is is done with an expected gp
register value, which is loaded by the dynamic linker. Unfortunately, Go currently uses this register and clobbers the value placed in it by the dynamic linker, breaking the relocation.
This means there are effectively two things to solve:
-
Currently a
CALL
translates to a singleJAL
instruction with anR_CALLMIPS
(akaR_MIPS_26
) relocation - given that the assembler does not know if this is an internal function or anSDYNIMPORT
symbol, the easiest option is to likely produce trampolines for theSDYNIMPORT
calls, modelling the above assembly and generating the two matching relocations. -
In order for these relocations to work we likely have to avoid clobbering the
gp
register - one option may be to change Go'sREGSB
register (as was done fortp
onriscv64
). The other is to save the value of thegp
register at start up and restore thegp
value before calling anSDYNIMPORT
, switching it back to Go's value after the call returns.
I've got a proof of concept working with external linking, trampoline generation and gp
register save/restore on openbsd/mips64
(I'll make this available soon) - in the mean time, I'm interested in feedback and/or other suggestions on these issues/approach, before I proceed further.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status