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

region 'FLASH' already defined #413

Open
dimpolo opened this issue Oct 19, 2021 · 4 comments
Open

region 'FLASH' already defined #413

dimpolo opened this issue Oct 19, 2021 · 4 comments

Comments

@dimpolo
Copy link
Contributor

dimpolo commented Oct 19, 2021

I seem to have stumbled accross this issue region 'FLASH' already defined but the thread is closed by now.
The proposed fix (using the GNU linker) does work for me.

I wonder if I'm doing something wrong or if there's a bug here.
I set up a reproduction here:
https://github.com/dimpolo/linkerbug
The goal would be to have a bootloader sit at the first 32K of FLASH and the main application at the 32K after.

Steps to reproduce:

git clone https://github.com/dimpolo/linkerbug.git
cd linkerbug/bootloader
cargo build
@allexoll
Copy link

having the same issue, switching to GNU-ld fixed it too.

@allexoll
Copy link

if that helps finding where this issue is coming, having a second workspace with self-tests and its own .cargo/config.toml that would include link.x again. Rust-lld accepts it but it fails building, where gnu-ld fails building, alerting that link.x has been included twice.

@adamgreig
Copy link
Member

Are you setting the linker file using build.rs, .cargo/config.toml, or both? Setting RUSTFLAGS should only take effect once, I thought, so that if you have two competing .cargo/config.toml only one of them should win... but perhaps if one side is using build.rs and the other also sets RUSTFLAGS it will end up doubly including link.x?

@allexoll
Copy link

sorry my previous comment was not very readable,

The linker file memory.x is created and added in the build.rs in a similar fashion as what's done in stm32l0xx-hal.

The structure is as follow:

├── .cargo
│   └── config.toml
├── Cargo.toml
├── build.rs
├── examples
│   └── gpio.rs
├── self-tests
│   ├── .cargo
│   │   └── config.toml
│   ├── Cargo.toml
│   ├── README.md
│   └── tests
│       ├── gpio-input-floating.rs
│       ├── ...
│   ├── gpio.rs
│   ├── lib.rs
│   ├── ...

The error I had was happening when i was using rust-lld, because both config.toml in .cargo/ and in self-tests/.cargo/ would add the -Tlink.x option. so building the self test would include link.x twice, which would include memory.x twice and so FLASH region would be already defined the second time. switching to gnu-ld would raise a warning saying that link.x was included twice, and so i found what was the issue. i just removed the rust flags from self-tests/.cargo/.config.toml and switched back to rust-lld and that fixed the issue. i'm not sure if there is anything that could have been done there to help prevent that, or to give a more explicit error message.

Hope this is more clear this time!

@adamgreig adamgreig transferred this issue from rust-embedded/cortex-m-rt Jan 23, 2022
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

No branches or pull requests

3 participants