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

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

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 llvm-project/Writer.cpp at main · llvm/llvm-project · GitHub then sections are sorted according to rank in llvm-project/Writer.cpp at main · llvm/llvm-project · GitHub 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

There was a feature request about dumping an internal linker script
51309 – `--verbose` should generate and dump out a linker script based on built-in rules 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 :slight_smile: