On Tue, Oct 17, 2017 at 11:13:36AM +0200, David Brown wrote: > My solution to this > particular ordering problem is: > > uint32_t status; > asm volatile ("mrs %0, PRIMASK" : "=r" (status) :: ); > asm volatile ("cpsid i" :: "" (status) :); > > foo(); > > asm volatile ("msr PRIMASK, %0" :: "r" (status) : ); And that only works for you because you have foo() separately compiled. If it was inlined (say with LTO) its instructions could move anywhere. That is without changing a character in your source code; your program simply does not mean what you think it means. Segher