get rid of LLD #18
Labels
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/nac3#18
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently we are creating temporary files and calling ld.lld as a subprocess. This is not very clean and may also impact performance due to unnecessary filesystem access (on Windoze this also potentially goes through the antivirus).
I inherited this approach from the current ARTIQ compiler because it is known to work and simple to implement - not much of the infrastructure seems to be in place for using lld from Rust and documentation is scarce.
Still, the LLD documentation claims
You can embed LLD to your program by linking against it and calling the linker’s entry point function lld::elf::link.
function defined here: https://github.com/llvm/llvm-project/blob/main/lld/ELF/Driver.cpp
It's a bit silly, we'd still have to create temporary files and pass command line arguments into the library function call... maybe LLVM would accept a patch that improves the situation...
lld even has zero support for reading anything from the standard input.
Alternatively we can perhaps link at the LLVM IR level with
module.link_in_module()
:use lld as a libraryto get rid of LLDSeems we are going towards that.
The runtime could perhaps accept both ELF formats, it is sometimes useful to switch between legacy ARTIQ and NAC3 during debugging without reflashing the device.
An incomplete prototype to accept simple kernel objects (e.g. blinky).
It is probably better to add a PLT for symbols that might need rebinding in runtime.
Maybe not. This is the function they use to read the files into memory buffers:
b1d9136da1/lld/ELF/Driver.cpp (L210)
Maybe we could somehow modify lld to pass memory buffers into it? It might be easier than modifying our runtime to accept object files instead of ELF...
@occheung What is the issue with more complex kernels?
@pca006132 I don't see a good justification for adding all this LLD bloat; plus many parts of LLD will need modifications to support specifying the linker script and other options. What function does LLD really perform in our case? We are only "linking" one object file.
https://github.com/occheung/artiq/tree/dyld-obj
Pushed the modifications of runtime to the dyld-obj branch of my artiq fork from the nac3 branch.
libdyld is practically rewritten while mostly keeping the original interfaces.
So far the memory layout of the loaded image is as such:
The PT_LOAD, PT_GNU_EH_FRAME and .eh_Frame_hdr are there for llvm-libunwind to work properly.
The compacted section table is to allow RELA section sections to match its target PROGBITS section. Loading RELA into the image is probably unnecssary.
Tried raising an exception in the following code (no particular reason of choosing DMAError):
Got a traceback as the following:
Note: DMA is still not supported as the PLT generation is not programmed in.
Also, .eh_frame and .eh_frame_hdr are in dwarf format. Maybe we should factor out the code for reading/writing dwarf (from
libeh/dwarf.rs
) and perhaps name it libdwarf like artiq-zynq.So far I just make a copy in libdyld and modify as needed.
Those look problematic. What is
.LBB1_7
about? Maybellvm-addr2line
gets confused when reading the backtrace?What is the connection between DMA and PLT?
Let's try to get this for prealpha - seems to be the only remaining issue on Windows (MSYS2 lld breaks when called by NAC3 for some reason, so installing it isn't a quick workaround), and supporting Windows would significantly increase the user base for testing.
Regarding problem with lld on Windows: Can we compile lld in our LLVM build? Does that work?
Maybe - but LLD is bloated anyway and we should ditch it. I don't see a good reason for having a linker when we have only one object file.
If the linker was small and well-written it would be acceptable, but LLD is neither. And GNU LD is even worse.
And especially so on Windows where:
You could fit an entire Linux distro in the space taken by LLD.
This is exactly what happens:
And this is with MachO support disabled (as it didn't compile), which I had to do by editing the source, since it doesn't even have options to disable this sort of feature.
I'll see if simply copying
ld.lld.exe
actually works, maybe 70MB of additional bloat and questionable LLVM code is an acceptable temporary workaround.It doesn't...
Just needs .exe suffix.
We probably want to get rid of the PLT which is slowing things down (such as RTIO speed), and the GOT which is unnecessary. Since the ARTIQ runtime only loads one copy of the library, direct
.text
and.data
relocations have no disadvantage.The legacy compiler also uses the PLT, so this will be a runtime speed improvement over it.
#292