This repository was archived by the owner on Jan 24, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 24, 2022. It is now read-only.
LLD support (AKA LLD *almost* works out of the box) #53
Copy link
Copy link
Closed
Description
If you switch the linker from arm-none-eabi-ld to ld.lld you'll get the following error:
$ ld.lld --version
LLD 7.0.0 (https://github.com/llvm-mirror/lld 527f7fd20d23a54ae30ccdf5071312b24e28776b) (compatible with GNU linkers)
$ xargo build
error: linking with `ld.lld` failed: exit code: 1
|
= note: "ld.lld" (..)
= note: ld.lld: error: $PWD/target/thumbv7em-none-eabihf/debug/build/cortex-m-rt-f07298b7bbb47f59/out/link.x:92: NOLOAD expected, but got INFO
>>> .debug_gdb_scripts _stext (INFO) : {
>>> ^But if you modify this crate link.x like this:
/* a rustc hack will force the program to read the first byte of this section,
so we'll set the (fake) start address of this section to something we're
sure can be read at runtime: the start of the .text section */
- .debug_gdb_scripts _stext (INFO) : {
+ .debug_gdb_scripts _stext (NOLOAD) : {
KEEP(*(.debug_gdb_scripts))
- }
+ } > FLASHPrograms link correctly. The resulting binaries are well formed and debug information works. 🎉
However, this results in an artifical increase of size of the text section as reported by arm-none-eabi-size:
$ # before (linked with GNU ld)
$ arm-none-eabi-size (..)
text data bss dec hex filename
1300 0 0 1300 514 (..)
$ arm-none-eabi-size -Ax (..)
section size addr
.vector_table 0x188 0x8000000
.text 0x384 0x8000188
.rodata 0x8 0x800050c
.bss 0x0 0x20000000
.data 0x0 0x20000000
.debug_gdb_scripts 0x88 0x8000188
$ # after (linked with GNU ld)
$ arm-none-eabi-size (..)
text data bss dec hex filename
1436 0 0 1436 59c (..)
$ arm-none-eabi-size -Ax (..)
section size addr
.vector_table 0x188 0x8000000
.text 0x384 0x8000188
.rodata 0x8 0x800050c
.bss 0x0 0x20000000
.data 0x0 0x20000000
.debug_gdb_scripts 0x88 0x8000188 <- NOTE overlaps with .text
$ # after (linked with LLVM lld)
$ arm-none-eabi-size (..)
text data bss dec hex filename
1436 0 0 1436 59c (..)
$ arm-none-eabi-size -Ax (..)
section size addr
.vector_table 0x188 0x8000000
.text 0x384 0x8000188
.rodata 0x8 0x800050c
.bss 0x0 0x20000000
.data 0x0 0x20000000
.got 0x0 0x20000000
.debug_gdb_scripts 0x88 0x8000514 <- NOTE comes after .textThis is just an error in the report though. The .debug_gdb_scripts doesn't end up in FLASH even with the linker script changes.
> # GDB console after flashing the binary linked using LLD
> x/12x 0x8000514
0x8000514 <__rustc_debug_gdb_scripts_section__>: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x8000524 <__rustc_debug_gdb_scripts_section__+16>: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x8000534 <__rustc_debug_gdb_scripts_section__+32>: 0xffffffff 0xffffffff 0xffffffff 0xffffffffThis issue is to gauge interested in adding LLD support right now (by applying the above diff).
Alternatively we can hold off until LLD lands in rustc (hopefully sometime this year) since it's only then when we'll be able to drop the dependency on a external linker (arm-none-eabi-ld).
Metadata
Metadata
Assignees
Labels
No labels
Activity
japaric commentedon Feb 10, 2018
update: Once PR rust-lang/rust#48125 lands a standalone LLD (version 6.0) binary will ship with the Rust distribution on some (all?) tier 1 platforms. We'll be able to use that lld to link ARM Cortex-M binaries so we should revisit this issue after that PR lands.
japaric commentedon Mar 9, 2018
Update: LLD is now being shipped with the Rust toolchain. You'll need Xargo v0.3.11 to be able to use it though.
I was testing this again and had to patch things a bit more after #43 landed:
(This actually breaks cortex-m-rt-ld but it doesn't matter right now as I'm just testing LLD)
It seems to me that LLD is producing bad binaries in some cases: when flashing the allocator example from cortex-m-quickstart v0.2.5 I get a segfault in OpenOCD:
I was wondering if this was a bug in the LLD version shipped with the toolchain so I tried a more recent version and I got this error:
which I don't understand because the program does fit in Flash memory -- GNU LD can link it within the memory constraints.
So I went back to inspect the binary linked using rustc's LLD (version 6.0).
This shows that indeed
.rodata, which spans[0x80064f0, 0x8007cf3], is overlapping with the load memory of.data, which starts at address0x08007cee. This doesn't occur in the binary linked using GNU LD; there the LMA is equal to the end address of.rodata(no overlap).So it seems that LLD is not ready for prime time yet. It would be great to report this issue or see if it has already been reported in LLVM's bug tracker. Unfortunately, I won't have time to follow up on that.
japaric commentedon Apr 6, 2018
Turns out the overlap problem I mentioned above also occurs with GNU LD in some scenarios (I don't know the exact cause). However, #63 fixes the issue for both LD and LLD. Will re-test LLD in a bit.
add LLD support
add LLD support
jcsoo commentedon Apr 23, 2018
I'm still seeing the overlap problem when there is static data. I was able to reproduce using cortex-m-quickstart with the following changes:
.cargo/config
Cargo.toml
examples/minimal.rs
So .rodata is [0x800007a0, 0x800007a4] and .data starts at [0x080007a2].
Looking at the symbol table in detail:
The last function in .text is [0x08000790, 0x0800079e] (core::cell::UnsafeCell::get())
The first (and only) entry in .data is
which presumably is being loaded from [0x0800079e, 0x080007a2] if _sidata
is [0x080007a2,...], but this conflicts with .rodata at [0x800007a0, 0x800007a4], which is causing the problems.
So it looks like lld is not respecting the .rodata alignment when writing out the initializer.
japaric commentedon Apr 23, 2018
This appears to be fixed in the latest LLD (
LLD 7.0.0 (git://github.com/llvm-mirror/lld.git 31f297161e44ba84e5e257a9213e32dc73b540e3) (compatible with GNU linkers)). I get:(with rustc LLD I get
080007a2 A _sidata)We probably only have to backport the fix.