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

Simon Atanasyan via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 29 13:18:32 PST 2016


Hi,

Sorry for delay with reply.

It looks like now thunks can be implemented as a synthetic sections.
In that case we give flexible solution and will be able to put thunks
before/after related sections, using different alignment etc. As far
as I know BFD linker uses the same approach at least for MIPS thunks.
I will try to implement this idea.

On Thu, Sep 8, 2016 at 1:44 AM, Rui Ueyama <ruiu at google.com> wrote:
> This seems to be a reasonable optimization, and I don't have any particular
> concern about implementing it.
>
> On Wed, Sep 7, 2016 at 6:58 AM, Simon Atanasyan <simon at atanasyan.com> wrote:
>>
>> 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