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

Consider using Cargo's links feature to ensure use only once #137

Closed
jamesmunns opened this issue Mar 16, 2019 · 5 comments · Fixed by #140
Closed

Consider using Cargo's links feature to ensure use only once #137

jamesmunns opened this issue Mar 16, 2019 · 5 comments · Fixed by #140

Comments

@jamesmunns
Copy link
Member

Currently cortex-m uses an unmangled variable to prevent multiple crates being linked in that redefine CORE_PERIPHERALS.

Cargo now has a feature called links that addresses this.

@little-arhat
Copy link

little-arhat commented Apr 23, 2019

And how do I deal with this issue now?

I've have dependency on cortex-m: "=0.5.8", and dependency on cortex-m-log: "0.4.0" and everything worked fine for me, until suddenly some other crate brought cortex-m 0.6.0 and linker started to complain:

warning: Linking globals named 'CORE_PERIPHERALS': symbol multiply defined!

error: failed to load bc of "cortex_m.31bpwv5e-cgu.0":

looking at Cargo.lock I see that 0.6.0 is brough by cortex-m-semihosting (that cortex-m-log depends on):

[[package]]
name = "cortex-m-semihosting"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "cortex-m 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "cortex-m-log"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "cortex-m 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "cortex-m-semihosting 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

cortex-m-log defines cortex-m dependency as cortex-m = ">= 0.5.8, < 0.7", and I have cortex-m = {version = "=0.5.8", features = ["inline-asm", "const-fn"]}, so I'm a bit surprised that 0.6.0 appeared in Cargo.lock.

(of course I can edit Cargo.lock and so on, but I'm surprised that I have to deal with this. I also wonder, what is the recommended way to deal with this, as I imagine some crates will be updated sooner than later to use 0.6.0).

@jamesmunns
Copy link
Member Author

@little-arhat this issue is a little different than what you are reporting, but I have run into this too.

I have had problems where despite the >=5.8,<0.7 stuff, cargo decided to pick cortex-m 0.5.8 AND 0.6. I manually edited the Cargo.lock and it was happy, but this doesn't seem optimal.

I even selected cortex-m = "=0.5.8" in my top level crate, but cortex-m-semihosting (a sub-sub-dep) still decided to pull in 0.6.

I "fixed" this locally by editing:

[[package]]
name = "cortex-m-semihosting"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "cortex-m 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

to

[[package]]
name = "cortex-m-semihosting"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "cortex-m 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

Which seemed to work after a rebuild (and mentions of cortex-m 0.6.0 were automatically removed by cargo), but this is sub-optimal behavior. CC @rust-embedded/cortex-m

@little-arhat
Copy link

@jamesmunns thanks, that what I did as well, doesn't look pretty, indeed.

I guess links feature will not help in this case, as it will prevent linking, but will not alter solver behaviour (which is, I guess, responsible for the mess we're in %) ).

bors bot added a commit that referenced this issue Apr 24, 2019
140: Cargo.toml: Add `links = "cortex-m"` r=therealprof a=jonas-schievink

This prevents linking multiple versions of `cortex-m` together, which would be
unsound. Currently it uses a `#[no_mangle]` static for this, which isn't always
reliable.

Fixes #137

Co-authored-by: Jonas Schievink <[email protected]>
@little-arhat
Copy link

@jamesmunns I've created cargo issue for this, btw: rust-lang/cargo#6876

@Eh2406
Copy link

Eh2406 commented May 2, 2019

BTW links dose efact the resolver rust-lang/cargo#4978

bors bot added a commit that referenced this issue Jun 6, 2019
140: Cargo.toml: Add `links = "cortex-m"` r=therealprof a=jonas-schievink

This prevents linking multiple versions of `cortex-m` together, which would be
unsound. Currently it uses a `#[no_mangle]` static for this, which isn't always
reliable.

Fixes #137

Co-authored-by: Jonas Schievink <[email protected]>
@bors bors bot closed this as completed in #140 Jun 6, 2019
adamgreig pushed a commit that referenced this issue Jan 12, 2022
adamgreig pushed a commit that referenced this issue Jan 12, 2022
146: Mention interrupt attribute in main crate docs r=korken89 a=birkenfeld

Fixes #137

Co-authored-by: Georg Brandl <[email protected]>
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 a pull request may close this issue.

3 participants