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

inline-asm feature causes compile errors on cortex-m0 (samd21) #267

Closed
taurr opened this issue Sep 30, 2020 · 11 comments
Closed

inline-asm feature causes compile errors on cortex-m0 (samd21) #267

taurr opened this issue Sep 30, 2020 · 11 comments

Comments

@taurr
Copy link

taurr commented Sep 30, 2020

Using version 0.6.3 with feature inline-asm enabled causes compile errors:

error: invalid instruction, any one of the following would fix this:
  --> /home/johnny/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.3/src/asm.rs:39:13
   |
39 |             llvm_asm!("1:
   |             ^
   |
note: instantiated into assembly here
  --> <inline asm>:3:19
   |
3  |                   subs r1, $1
   |                   ^

note: instruction requires: thumb2
  --> /home/johnny/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.3/src/asm.rs:39:13
   |
39 |             llvm_asm!("1:
   |             ^
   |
note: instantiated into assembly here
  --> <inline asm>:3:19
   |
3  |                   subs r1, $1
   |                   ^

note: invalid operand for instruction
  --> /home/johnny/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.3/src/asm.rs:39:13
   |
39 |             llvm_asm!("1:
   |             ^
   |
note: instantiated into assembly here
  --> <inline asm>:3:28
   |
3  |                   subs r1, $1
   |                            ^

note: operand must be an immediate in the range [0,255]
  --> /home/johnny/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.3/src/asm.rs:39:13
   |
39 |             llvm_asm!("1:
   |             ^
   |
note: instantiated into assembly here
  --> <inline asm>:3:28
   |
3  |                   subs r1, $1
   |                            ^

note: operand must be a register in range [r0, r7]
  --> /home/johnny/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.3/src/asm.rs:39:13
   |
39 |             llvm_asm!("1:
   |             ^
   |
note: instantiated into assembly here
  --> <inline asm>:3:28
   |
3  |                   subs r1, $1
   |                            ^

error: aborting due to previous error

error: could not compile `atsamd-hal`
@adamgreig adamgreig transferred this issue from rust-embedded/wg Sep 30, 2020
@adamgreig
Copy link
Member

It looks like this issue was about the cortex-m crate, so I've transferred it here. What Rust version are you using, and what target are you building for (in your .cargo/config.toml file or --target command line argument)?

@taurr
Copy link
Author

taurr commented Sep 30, 2020

@adamgreig here's a little more info...

  • rustc 1.48.0-nightly (8b4085359 2020-09-23)
  • target: thumbv6m-none-eabi

Regarding the target, specifically I'm doing firmware for a atsamd21g18.

@adamgreig
Copy link
Member

Thanks for the info. I can reproduce the error on today's nightly-2020-09-29 and as far back as nightly-2020-08-28 but it's not present on nightly-2020-08-01, so this looks like a change or regression in nightly sometime in August. As a workaround you should be able to use 2020-08-01 (rustup install nightly-2020-08-01 --profile minimal; rustup target add thumbv6m-none-eabi --toolchain nightly-2020-08-01; cargo +nightly-2020-08-01 build).

@jonas-schievink, any ideas?

@jonas-schievink
Copy link
Contributor

Seems like a rustc regression, yeah. If you can bisect to a nightly we should be able to nail down the PR that caused it (was the LLVM upgrade in that range?).

That said, this doesn't seem like something that will be fixed, since asm! is now a thing.

@adamgreig
Copy link
Member

Ok, the last nightly that worked is nightly-2020-08-23 (rustc 1.47.0-nightly (663d2f5cd 2020-08-22)) and the first nightly that fails is nightly-2020-08-24 (rustc 1.47.0-nightly (5180f3da5 2020-08-23)).

@jonas-schievink
Copy link
Contributor

jonas-schievink commented Sep 30, 2020

Commits in that range: rust-lang/rust@663d2f5...5180f3d

Looks like the LLVM 11 upgrade is indeed what caused this

@Disasm
Copy link
Member

Disasm commented Sep 30, 2020

It doesn't look like a rustc bug to me. One should be careful writing inlined asm code as it could be inlined into a code with different thumbness. You can't use some instructions both in ARM and Thumb mode when they do not exist in both modes.
I see two possible solutions:

  • do not inline this delay code at all
  • write code universal enough to support both modes

@adamgreig
Copy link
Member

But this is a thumbv6m-none-eabi target; it only runs thumb code and doesn't support ARM mode, so why would that be the issue here?

@Disasm
Copy link
Member

Disasm commented Sep 30, 2020

Hmm, you're right. Disregard my note then.

bors bot added a commit that referenced this issue Oct 20, 2020
274: Drop AT&T syntax from inline asm r=jonas-schievink a=thalesfragoso

This was breaking compilation on thumbv6 targets and miscompiling on thumbv7.

Fixes #272 
Fixes #267 

Co-authored-by: Thales Fragoso <thales.fragosoz@gmail.com>
bors bot added a commit that referenced this issue Oct 26, 2020
274: Drop AT&T syntax from inline asm r=therealprof a=thalesfragoso

This was breaking compilation on thumbv6 targets and miscompiling on thumbv7.

Fixes #272 
Fixes #267 

Co-authored-by: Thales Fragoso <thales.fragosoz@gmail.com>
@jonas-schievink
Copy link
Contributor

This should be fixed in cortex-m 0.7

@thalesfragoso
Copy link
Member

And also on 0.6.4, not sure why this wasn't close automatically. Anyways, thanks for the report.

adamgreig pushed a commit that referenced this issue Jan 12, 2022
287: Fix common uses of INSERT AFTER with .bss and .text r=adamgreig a=mattico

Fixes #267 
Fixes #266

This fixes two related issues.

1. Named sections are often inserted after `.bss` or `.text` in order to have them handled as if they were part of that section. Defining the start/end symbols outside of the section allows this to work.
2. Uninitialized C statics will end up as common symbols which end up in the COMMON input section. If this section is orphaned, it will likely end up placed after `.bss`. C code often expects these statics to be zero initialized. The first change would cause these symbols to be placed before `__ebss` so they will get zeroed by the reset handler. Explicitly placing the common symbols into `.bss` ensures this happens. Users who want uninitialized symbols should use the `.uninit` section.

See rust-embedded/cortex-m-rt#287 (comment)

Co-authored-by: Matt Ickstadt <mattico8@gmail.com>
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

5 participants