Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link with LLD #18

Merged
merged 2 commits into from
Mar 18, 2018
Merged

Link with LLD #18

merged 2 commits into from
Mar 18, 2018

Conversation

Woyten
Copy link
Contributor

@Woyten Woyten commented Mar 13, 2018

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.

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
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.

"linker-is-gnu": true,
"disable-redzone": true,
"pre-link-args": {
Copy link
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
Copy link
Member

alevy commented Mar 13, 2018

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
Copy link
Contributor

bradjc commented Mar 17, 2018

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

@Woyten
Copy link
Contributor Author

Woyten commented Mar 18, 2018

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
Copy link
Contributor

bradjc commented Mar 18, 2018

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
Copy link
Contributor Author

Woyten commented Mar 18, 2018

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
Copy link
Contributor

bradjc commented Mar 18, 2018

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

@bradjc
Copy link
Contributor

bradjc commented Mar 18, 2018

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
Copy link
Member

alevy commented Mar 18, 2018

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

@bradjc
Copy link
Contributor

bradjc commented Mar 18, 2018

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
Copy link
Contributor Author

Woyten commented Mar 23, 2018

@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