Skip to content

UB in inline-asm delay function #195

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

Closed
ByteNacked opened this issue Feb 11, 2020 · 3 comments
Closed

UB in inline-asm delay function #195

ByteNacked opened this issue Feb 11, 2020 · 3 comments
Labels

Comments

@ByteNacked
Copy link

UB in higher opt levels with inline-asm feature, caused by forgotten asm clobber in asm::delay function.

Example fix:

asm!("1:
      nop
      subs $0, $$1
      bne.n 1b"
      : "+r"(_n / 4 + 1)
      :
      :
      : "cpsr" // <= Added here
      : "volatile");
@jonas-schievink
Copy link
Contributor

Oh, you need to clobber the status register explicitly? That seems very easy to forget, we should audit all asm for this.

@adamgreig
Copy link
Member

I've done an audit of all occurrences of asm! I could find in rust-embedded and this is the only instance I found which updates the condition flags. Should the fix be cpsr or cc clobber?

@therealprof
Copy link
Contributor

cspr should be the right one since it's the name of the register containing the condition flags on ARM. cc is some GCC architecture independent magic name to indicate the register holding the condition flags, but I'm not even sure it's universally applicable to non-GCC inline assembly...

bors bot added a commit that referenced this issue Mar 15, 2020
200: Add CPSR to asm::delay's clobber flags. Fixes #195 r=therealprof a=adamgreig



Co-authored-by: Adam Greig <[email protected]>
bors bot added a commit that referenced this issue Mar 15, 2020
200: Add CPSR to asm::delay's clobber flags. Fixes #195 r=therealprof a=adamgreig



Co-authored-by: Adam Greig <[email protected]>
@bors bors bot closed this as completed in e106d4a Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants