Replace ld.lld with nac3ld for non-host targets #292
No reviewers
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/nac3#292
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "occheung/nac3:nac3ld"
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?
Description
This PR adds the
nac3ld
module to NAC3. Non-host targets (i.e. ARM & RISC-V) are supported. A list of PRs are needed to make nac3ld functional.Related PRs
#291, ARTIQ PR 1889
GOT/PLT prevention
ARM
By default, LLVM generates short branch veneer for branches. It can result in the lack of jump range when dealing with large binary. Since a short branch veneer only takes 1 instruction, it is not possible to find an inplace workaround that can reliabily jump to any address. With this patch, the
long-calls
LLVM feature is enabled to generate long branch veener. PLT is unnecessary in this case, as the range of a long branch veneer can cover the entire address space.See patches regarding
R_ARM_TARGET2
relocation & linkage demotion for GOT preventions.RISC-V
RISC-V codegen always accounts for the possibility that the required address could be store in a very far away address. Therefore, PLT/GOT related relocations is constructed using 2 instructions:
Instead of performing the relocation truthfully, it does the following workarounds:
The same relocation is propagated to the runtime linker if it is not resolvable (i.e. symbols without defined value). The same workaround is performed in the mainline ARTIQ runtime linker patch to the NAC3 branch.
Test
The nac3devices example in mainline ARTIQ can be linked successfully by both the static linker (nac3ld) and the runtime linker in both Kasli & Kasli-SOC.
We don't want to write to a file when using nac3ld - the code was previously written like this because (sadly) files are the only way to communicate with the regular linkers.
da4504a208
to80120a5229
80120a5229
to65e152dd66
65e152d.
Identical to da4504a & 80120a5, but repushed because of spelling and not merging properly.
compile_method_to_file
used to be a sub-function ofcompile_method_to_mem
. It leads to file write incompile_method_to_mem
when linking with nac3ld.This commit factors out the part which makes the module into a separate function
compile_method
, which takes a closure that completes the linking part (using ld.lld or nac3ld).Performance:
Measured the time taken to run
artiq_compile
on thenac3devices.py
example on mainline ARTIQ. Completed 100 trials for each result. The mean & standard deviation on RISC-V & ARM targets are tabulated below.0ad389f52f
to50ed04b787
Replaced the unsafe code in
dwarf.rs
using ByteOrder. Performance of RISC-V targets improved.Rebased to master after 0ad389f5.