Commit 073d679
Linker: Change to rust-lld for linking
When building for a custom or bare metal platform, it is often be more
useful to use the LLVM linker shipped with Rust (rust-lld). As Rust is
heavily integrated with LLVM, using LLVM's linker can result in smaller
and simpler binaries.
This change does two things,
- Changes the linker script (`layout.ld`) to:
- Correctly combine sections together
- Remove `BLOCK` as it does the same thing as `ALIGN`. See:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/expressions.html
- Changes `target.json` to use `rust-lld`
The results:
- The debug build now works!!
- The release binary is now smaller and simpler
- Size shrinks from 116 KB to 70 KB
- Stripped size shinks from 89 KB to 49 KB
- Number of sections shinks from 333 tp 10
- Program headers shrinks from 7 to 4
- The unnecessary dynamaic section, relocation section,
and `.dynsym` section are now gone.
- Symbol table entries shrink from 540 to 220
- We can now (potentially) use LTO
Testing:
- Ran with Firecrakcer using instructions in `README.md`
- All builds (before and after this change) kernel panic as
expected, due to the virtio block device reset issue.
- Ran with `cloud-hypervisor`; everything boots/works normally.
Signed-off-by: Joe Richey <[email protected]>1 parent bbcb868 commit 073d679
2 files changed
+13
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
21 | 19 | | |
22 | 20 | | |
0 commit comments