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

flip-link does not respect memory.x overrides #43

Closed
japaric opened this issue Jun 21, 2021 · 3 comments
Closed

flip-link does not respect memory.x overrides #43

japaric opened this issue Jun 21, 2021 · 3 comments
Labels
dificulty: easy Pretty easy to solve priority: high High priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes type: bug Something isn't working

Comments

@japaric
Copy link
Member

japaric commented Jun 21, 2021

Steps to reproduce

  1. Instantiate the app-template for the nRF52840 (add nrf52840-hal as a dependency).

  2. Create a memory.x override

$ # run hal crate build script -> puts memory.x in target
$ cargo check --lib

$ cp `fd memory.x target` .

$ # halve the amount of RAM
$ $EDIT memory.x
$ bat memory.x
MEMORY
{
  FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
  RAM : ORIGIN = 0x20000000, LENGTH = 128K
}
  1. Inspect produced binaries
$ # `touch` = force relinking; or use `cargo clean`
$ touch src/bin/hello.rs
$ cargo size --bin hello -- -A -x
hello  :
section                size         addr
.vector_table         0x100          0x0
.text                0x145c        0x100
.rodata               0x4ac       0x155c
.data                  0x30   0x2003fbc8
.bss                    0x8   0x2003fbf8
.uninit               0x400   0x2003fc00

$ cargo nm --bin hello -- --demangle --numeric-sort | rg stack
2003fbc8 A _stack_start

Both binary tools indicate that flip-link thinks the RAM size is 256 KiB (0x4_0000) even though the memory.x override indicates 128 KiB

  1. Compare against rust-lld (disable flip-link)
$ $EDIT .cargo/config.toml
$ bat .cargo/config.toml
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-run --chip nrf52840"
rustflags = [
  # "-C", "linker=flip-link", # <- disabled
  "-C", "link-arg=-Tlink.x",
  "-C", "link-arg=-Tdefmt.x",
  "-C", "link-arg=--nmagic",
]

$ cargo size --bin hello -- -A -x
hello  :
section                size         addr
.vector_table         0x100          0x0
.text                0x145c        0x100
.rodata               0x4ac       0x155c
.data                  0x30   0x20000000
.bss                    0x8   0x20000030
.uninit               0x400   0x20000038

$ cargo nm --bin hello -- --demangle --numeric-sort | rg stack
20020000 A _stack_start

rust-lld respects the memory.x override and uses 128 KiB as the size of the RAM region

Meta

flip-link version

$ cargo install --list | rg ^flip-link
flip-link v0.1.4:
@japaric japaric added type: bug Something isn't working priority: high High priority for the Knurling team labels Jun 21, 2021
@japaric
Copy link
Member Author

japaric commented Jun 21, 2021

I don't know if this is documented in LD/LLD docs but from what I've seen linker scripts are searched for in the "linker search path". The first (highest precedence) entry in the linker search path is the current directory; other entries are specified via the -L flag.

When looking for the MEMORY entry in linker scripts, flip-link should follow the above (MEMORY.x in current directory should take precedence over the one in the target directory)

@japaric
Copy link
Member Author

japaric commented Mar 23, 2022

update: fixed in #63 but not in latest crates.io release (v0.1.5)

@japaric
Copy link
Member Author

japaric commented Mar 24, 2022

flip-link v0.1.6 has been released and includes this fix

@japaric japaric closed this as completed Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dificulty: easy Pretty easy to solve priority: high High priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants