[llvm-dev] [LLD] Writing thunks before the corresponding section

Simon Atanasyan via llvm-dev llvm-dev at lists.llvm.org
Wed Sep 7 06:58:49 PDT 2016


Hi,

MIPS LA25 thunk is used to call PIC function from non-PIC code.
Usually it contains three instructions:

lui   $25, %hi(func)
addiu $25, $25, %lo(func)
j     func

We can write such thunk in an arbitrary place of the generated file.
But if a PIC function requires the thunk is the first routine in a
section, we can optimize the code and escape jump instruction. To do
so we just write the following thunk right before the PIC routine.

lui   $25, %hi(func)
addiu $25, $25, %lo(func)

In fact GNU bfd/gold linkers write all MIPS LA25 thunks required for
the section "A" into a separate input section "S" and put section "S"
before "A". The last thunk in the section "S" might have an optimized
two-instructions form.

I would like to implement such optimization in LLD. My question is
about ARM thunks - is it okay to write them before corresponding input
section not after like LLD does now?

-- 
Simon Atanasyan


More information about the llvm-dev mailing list