[llvm-dev] Seeking help on LLD and extending ELF

Dobby HouseElf via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 12 14:40:17 PDT 2020


 Thank you, Peter for the detailed answer and all the pointers. I'll look up LLD presentations.
Best regards!
    On Wednesday, August 12, 2020, 01:10:52 AM PDT, Peter Smith <peter.smith at arm.com> wrote:  
 
 Hello,

There isn't any existing guide that I'm aware of. What you'll need to do in the code will be heavily dependent on what you need the custom ELF section to do. For example if the contents of the section are largely determined at compile/assembly time and the linker just collates and relocates them probably won't need much code in LLD. If the sections need custom processing or even generation at link time then a SyntheticSection is a good model.

My advice would be to look at how LLD handles something like EHFrameSection or MergeSyntheticSection as these handle data coming in from the compiler/assembler, so they aren't 100% linker generated, yet they have custom processing outside of just resolving relocations. SyntheticSections like the PLT/GOT are entirely linker generated as a result of relocations.

In LLD typically you'll find most of the code changes in:
InputFiles.cpp (Do I need to do anything at file load time to handle my custom section)
Writer.cpp (The majority of the linker "back-end", where SyntheticSections are created)
SyntheticSections.cpp (The custom code for the SyntheticSections lives here)

For the vast majority of the time you'll be looking in lld/ELF and if you are making target specific changes in one of the Arch subdirectories.

You'll also find llvm/include/llvm/BinaryFormat/ELF useful if you are adding custom section flags and types. In general it is a good idea to add support for any new section type to llvm-readobj, llvm-objdump and elf2yaml, yaml2elf to make writing tests easier.

I don't have much more time to go into detail. In general if you get stuck, ask here and we'll do our best to help. The more specific the question the better.

Peter

p.s.
There have been a few LLD presentations at the LLVM developer meetings and at other conferences like FOSDEM. I'm sure a quick web-search will find them.

________________________________________
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Dobby HouseElf via llvm-dev <llvm-dev at lists.llvm.org>
Sent: 11 August 2020 21:03
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] Seeking help on LLD and extending ELF

Hi all,

I am experimenting with extending ELF. I want to add a custom ELF section, something similar to a 'SyntheticSection'. However, I'm not able to find documentation / doxygen for LLD code.
Are there any existing examples of adding custom ELF sections at link time in LLVM framework? Is it possible?
Any pointers?

Thanks in advance!
Cheers!


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200812/b847f2ac/attachment.html>


More information about the llvm-dev mailing list