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

Weird behavior with trivial 'idle' function #29

Closed
idubrov opened this issue May 26, 2017 · 3 comments
Closed

Weird behavior with trivial 'idle' function #29

idubrov opened this issue May 26, 2017 · 3 comments

Comments

@idubrov
Copy link

idubrov commented May 26, 2017

I'm observing weird behavior if I have a very trivial idle function (just an infinite loop): "init" function gets called twice.

What I observe is that:

  1. Second time init is called ::cortex_m::register::primask::read().is_active() returns true (which means interrupts are enabled, as I understand).
  2. If "idle" is trivial, I cannot set breakpoint to it (optimized away by compiler?)
  3. If "idle" is not trivial (loop with NOP or hprintln! at the beginning), everything works as expected.

I inserted breakpoint just before the "idle(p0, t0);" invocation and here is what I see in GDB:

0x80007a4 <x2_feed::main+8>                     bkpt   0x0000 ; Breakpoint I inserted just before the "idle" call
; Hey, where is my infinite loop?
; I think this piece of code is "closure" that calls "init'... That kind of explains it                                                                                                                                             
0x80007a6 <x2_feed::main::{{closure}}>          push   {r7, lr}                                                                                                                                        
0x80007a8 <x2_feed::main::{{closure}}+2>        mov    r7, sp                                                                                                                                          
0x80007aa <x2_feed::main::{{closure}}+4>        movw   r0, #8594       ; 0x2192

(this is probably not RTFM issue per se)

@japaric
Copy link
Collaborator

japaric commented May 26, 2017

I'm observing weird behavior if I have a very trivial idle function (just an infinite loop)

It may be a known LLVM misoptimization where LLVM replaces the function call with an "undef" value in LLVM IR. Does the problem goes away if you add impurity to the idle function? Something like ptr::read_volatile.

@japaric
Copy link
Collaborator

japaric commented May 26, 2017

@idubrov
Copy link
Author

idubrov commented May 26, 2017

Yeah, it looks like that's what it is. Thanks!

@idubrov idubrov closed this as completed May 26, 2017
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

2 participants