Skip to content

Link with LLD#18

Merged
alevy merged 2 commits into
tock:masterfrom
torfmaster:feature/lld
Mar 18, 2018
Merged

Link with LLD#18
alevy merged 2 commits into
tock:masterfrom
torfmaster:feature/lld

Conversation

@Woyten

@Woyten Woyten commented Mar 13, 2018

Copy link
Copy Markdown
Contributor

This PR uses lld as the proposed linker for libtock. Using lld has a couple of advantages:

  • We get rid of arm-none-eabi-ld as an external build tool. lld, in contrast, is shipped with Rust (rust: Import LLD for linking wasm objects rust-lang/rust#48125) and, therefore, does not require any additional installation steps.
  • lld supports any target that LLVM supports.
  • According to https://lld.llvm.org, lld is super fast.
  • The resulting elf file contains a lot of sections that were missing when using arm-none-eabi-ld, such as the .bss section. My guess is that proper relocation will be possible with lld.

Note: You might need to remove $HOME/.xargo before building anything.

Comment thread layout.ld
FLASH (rx) : ORIGIN = 0x80000000, LENGTH = PROG_LENGTH
SRAM (RWX) : ORIGIN = 0x00000000, LENGTH = RAM_LENGTH
FLASH (rx) : ORIGIN = 0x80000000, LENGTH = 0x0040000
SRAM (RWX) : ORIGIN = 0x00000000, LENGTH = 0x0010000

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to inline those to make lld happy.

Comment thread thumbv7em-tock-eabi.json
"linker-flavor": "ld.lld",
"linker-is-gnu": true,
"disable-redzone": true,
"pre-link-args": {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why but the pre-link-args section stopped having any effect on the linker, so I had to move that part to .cargo/config.

@alevy

alevy commented Mar 13, 2018

Copy link
Copy Markdown
Member

This is awesome, we need this too because it's a prerequisite to dealing with global variables (gnu ld doesn't know how to link LLVM's pic strategies that we need to use).

Will take a look soon, but high level if it works for the example apps I think we should merge and deal with bugs as they arise

@bradjc

bradjc commented Mar 17, 2018

Copy link
Copy Markdown
Contributor

Seems like efl2tbf doesn't work with the new output files. When running blink I now get a panic: tock/tock#817

@Woyten

Woyten commented Mar 18, 2018

Copy link
Copy Markdown
Contributor Author

We tested LLD on our NRF52DK on three different PCs running Ubuntu Linux.
What OS are you using?
Could you try running the code on an NRF52DK board?
Did you run git submodule update to get the newest xargo version?

@bradjc

bradjc commented Mar 18, 2018

Copy link
Copy Markdown
Contributor

I on Mac, but I don't have a nRF52dk board. I updated the submodule to the correct commit (it has some change in a cargo.lock file but is otherwise the same).

$ cargo --version
cargo 0.26.0-nightly (1d6dfea44 2018-01-26)

I have no idea what linker script it is using, but it doesn't seem to be layout.ld in the repo.

What does the output of tockloader inspect-tab look like for you?

@Woyten

Woyten commented Mar 18, 2018

Copy link
Copy Markdown
Contributor Author

If your repo is clean except for xargo/Cargo.lock (see japaric/xargo#201) the checkout should be fine.

The intention is that layout.ld of the libtock root is used. Before this PR, the script was referenced in the linker arguments section of thumbv7em-tock-eabi.json. But since LLD is used the linker arguments stopped working. Therefore, I moved them to .cargo/config which works for us.

My outputs:

$ cargo --version
cargo 0.26.0-nightly (1d6dfea44 2018-01-26)
$ rustc --version
rustc 1.26.0-nightly (c9334404f 2018-03-05)
$ tockloader inspect-tab target/blink.tab
Inspecting TABs...
TAB: blink
  build-date: 2018-03-18 16:44:11+00:00
  only-for-boards: 
  tab-version: 1
  supported architectures: cortex-m4
  TBF Header
    package_name          : blink
    version               :        2
    checksum              :            0x6e4c6c2d
    flags                 :        1          0x1
      enabled             : Yes
      sticky              : No
    header_size           :       44         0x2c
    init_fn_offset        :       37         0x25
    minimum_ram_size      :     4096       0x1000
    protected_size        :        0          0x0
    total_size            :     4096       0x1000

@bradjc

bradjc commented Mar 18, 2018

Copy link
Copy Markdown
Contributor

I can't explain this but with a new checkout it works. #thanksrust

@bradjc

bradjc commented Mar 18, 2018

Copy link
Copy Markdown
Contributor

I can't get this to work if I have the repo inside my /Users/bradjc/git folder. So that's cool.

@alevy
alevy merged commit c242e7f into tock:master Mar 18, 2018
@alevy

alevy commented Mar 18, 2018

Copy link
Copy Markdown
Member

@bradjc is it possible you have some sort of git ignore rule somewhere in your tree?

@bradjc

bradjc commented Mar 18, 2018

Copy link
Copy Markdown
Contributor

Ok don't be dumb and set the RUSTFLAGS variable in your shell.

@Woyten
Woyten deleted the feature/lld branch March 18, 2018 18:43
@Woyten

Woyten commented Mar 23, 2018

Copy link
Copy Markdown
Contributor Author

@bradjc Can the pr/18 branch be deleted?

bors Bot added a commit to japaric/xargo that referenced this pull request Mar 26, 2018
201: Update Cargo.lock r=japaric a=Woyten

Since #200, `Cargo.lock` is considered dirty after Xargo has been built. This is particularly annoying when using Xargo as a Git submodule such as in tock/libtock-rs#18.

This PR updates `Cargo.lock` s.t. it will no longer be considered dirty after building Xargo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants