[llvm-dev] Default linker script used by lld

1,718 views
Skip to first unread message

jingduanyang via llvm-dev

unread,
Oct 25, 2021, 7:54:33 AM10/25/21
to llvm...@lists.llvm.org, Weiwei (weiwei, Compiler), Zhangwen(Esan)

Hi,

 

Does anyone know the default linker script used by lld? This might be a silly question but I googled everywhere and couldn’t find an answer…

 

Thanks,

Duanyang

Peter Smith via llvm-dev

unread,
Oct 25, 2021, 12:19:46 PM10/25/21
to jingduanyang, llvm...@lists.llvm.org, Weiwei (weiwei, Compiler), Zhangwen(Esan)

LLD, doesn’t have a built-in linker script in the same way as GNU ld.bfd does.

 

Input Sections are mapped to OutputSections via a simple function https://github.com/llvm/llvm-project/blob/main/lld/ELF/Writer.cpp#L98 then sections are sorted according to rank in https://github.com/llvm/llvm-project/blob/main/lld/ELF/Writer.cpp#L98 hopefully the comments in those files will help reverse engineer a script that looks similar.

 

In practice the default linker behaviour will most significantly differ from ld.bfd by sorting ro-data before ro-code rather than after. This tends towards 3 PT_LOAD program headers ro, ro+exec, rw.

 

Hope that helps

 

Peter

Fāng-ruì Sòng via llvm-dev

unread,
Oct 25, 2021, 1:19:05 PM10/25/21
to Peter Smith, llvm...@lists.llvm.org, Weiwei (weiwei, Compiler), Zhangwen(Esan)
On Mon, Oct 25, 2021 at 9:19 AM Peter Smith via llvm-dev
<llvm...@lists.llvm.org> wrote:
>
> LLD, doesn’t have a built-in linker script in the same way as GNU ld.bfd does.
>
>
>
> Input Sections are mapped to OutputSections via a simple function https://github.com/llvm/llvm-project/blob/main/lld/ELF/Writer.cpp#L98 then sections are sorted according to rank in https://github.com/llvm/llvm-project/blob/main/lld/ELF/Writer.cpp#L98 hopefully the comments in those files will help reverse engineer a script that looks similar.
>
>
>
> In practice the default linker behaviour will most significantly differ from ld.bfd by sorting ro-data before ro-code rather than after. This tends towards 3 PT_LOAD program headers ro, ro+exec, rw.
>
>
>
> Hope that helps
>
>
>
> Peter

I noted down some linker script differences in
https://maskray.me/blog/2020-12-19-lld-and-gnu-linker-incompatibilities

There was a feature request about dumping an internal linker script
https://bugs.llvm.org/show_bug.cgi?id=51309 but it would significantly
increase complexity without justifiable benefit. In addition, some
built-in processing cannot be serialized into a linker script. So I
closed it :)

>
>
> From: llvm-dev <llvm-dev...@lists.llvm.org> On Behalf Of jingduanyang via llvm-dev
> Sent: 25 October 2021 12:54
> To: llvm...@lists.llvm.org
> Cc: Weiwei (weiwei, Compiler) <weiw...@huawei.com>; Zhangwen(Esan) <zwzhangw...@huawei.com>
> Subject: [llvm-dev] Default linker script used by lld
>
>
>
> Hi,
>
>
>
> Does anyone know the default linker script used by lld? This might be a silly question but I googled everywhere and couldn’t find an answer…
>
>
>
> Thanks,
>
> Duanyang
>

> _______________________________________________
> LLVM Developers mailing list
> llvm...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

--
宋方睿
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Reply all
Reply to author
Forward
0 new messages