Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

"error: cortex-m-rt appears more than once in the dependency graph" #275

Closed
bugadani opened this issue Jul 3, 2020 · 9 comments · Fixed by #276
Closed

"error: cortex-m-rt appears more than once in the dependency graph" #275

bugadani opened this issue Jul 3, 2020 · 9 comments · Fixed by #276

Comments

@bugadani
Copy link

bugadani commented Jul 3, 2020

I've been reading some of the emitted ASM of my application, and I've found that "error: cortex-m-rt appears more than once in the dependency graph" is present in the generated binary (-O3) and is referenced 126 times (63 loads I think) in my assembly. What's up with that, if the error is only there for compile-time?

@adamgreig
Copy link
Member

That's odd, the string is the export name of an empty static variable so shouldn't end up in the actual binary output. Is it appearing in the output ELF file or the output raw binary (i.e. cargo objcopy --release -- -O binary test.bin)? What section is it in?

@bugadani
Copy link
Author

bugadani commented Jul 3, 2020

It seems it isn't present in the binary that objcopy gives me, which is weird because the assembly listing contains a lot of this:

	movw	r2, :lower16:"error: cortex-m-rt appears more than once in the dependency graph"
	mov	r0, r1
	movt	r2, :upper16:"error: cortex-m-rt appears more than once in the dependency graph"
	movs	r1, #1

@adamgreig
Copy link
Member

I think what's going on might be that because that variable is static and zero-sized, the next static variable is assigned to the same address, and when the disassembler tries to work out what symbol name to display, it picks the wrong one. How are you generating the assembly listing?

@bugadani
Copy link
Author

bugadani commented Jul 3, 2020

I'm using cargo rustc --release -- --emit asm

@adamgreig
Copy link
Member

How about if using cargo objdump --release -- -D? (or arm-none-eabi-objdump).

@bugadani
Copy link
Author

bugadani commented Jul 3, 2020

It looks like you are right about the symbol being assigned to something else, I see a lot of jumps to the symbol plus a random offset. Sounds odd, but it looks like a harmless quirk.

Although, in the disassembly by objdump, the symbol is listed in different context than when using emit asm... But I guess that's also some tool quirk.

@adamgreig
Copy link
Member

Probably the solution is to move to the Cargo.toml links key instead of this "linker hack". The links key didn't exist when the linker hack was added, but it's been in Cargo for a while now so we can probably swap to it and remove the linker hack.

@adamgreig
Copy link
Member

Unfortunately this doesn't look like something we can fix any time soon; eventually we can remove __ONCE__ after a few versions exist with the links key, but not before then. It doesn't look like it affects the generated binary written to a device at least.

One workaround for development purposes might be to add a small static to your firmware that ends up mapped to the ONCE address but isn't otherwise used, so that your other references to actual statics still disassemble correctly.

Since there's not much else to do now I'll close this issue; please re-open if further discussion is needed though. Thank you for reporting it!

@bugadani
Copy link
Author

bugadani commented Jul 9, 2020

It doesn't look like it affects the generated binary written to a device at least.

Fortunately, this does seem the case. Thank you for investigating.

bors bot added a commit that referenced this issue Jul 9, 2020
276: Replace __ONCE__ with Cargo links key r=jonas-schievink a=adamgreig

This would fix #275. We use the links key in cortex-m already [here](https://github.com/rust-embedded/cortex-m/blob/master/Cargo.toml#L16). See also rust-embedded/wg#467.

Co-authored-by: Adam Greig <adam@adamgreig.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants