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

Rui Ueyama via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 30 13:39:33 PST 2016


Sure. One thing I want to remind you is that there is a place in Writer.cpp
where we assume all synthetic sections were appended to end of Sections
list. Look for `llvm::reverse`. If you add synthetic section thunks right
before/after non-synthetic sections, you also want to change that.

On Tue, Nov 29, 2016 at 1:18 PM, Simon Atanasyan <simon at atanasyan.com>
wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161130/56cfae7d/attachment.html>


More information about the llvm-dev mailing list