4 ms·
If one properly specifies the input, output, and clobber constraints to the asm statement, there is no need for the volatile keyword in any of this.
by compiler-guy 2y ago
If one properly specifies the input, output, and clobber constraints to the asm statement, there is no need for the volatile keyword in any of this.
- jcalvinowens 2y agoI don't think that's correct for the sys_exit() call with no outputs: the compiler doesn't know the syscall instruction has side effects, I think it would be within its rights to omit that asm statement without volatile. Adding an output and code to consume the result seems like a waste of space in .text, it doesn't return. It reminds me of a funny little bug in ARM Linux, fixed by adding volatile to an asm statement: https://lore.kernel.org/lkml/92a00580828a1bdf96e7e36545f6d229809af04f.1722154575.git.calvin@wbinvd.org/ https://lore.kernel.org/lkml/92a00580828a1bdf96e7e36545f6d22...
- jcalvinowens 2y agoWell, neither have outputs, doh, so they both need volatile don't they? Adding an output for the %rax result would prevent the call from being omitted without volatile (assuming it is actually consumed by something), but it could still be reordered, right? I suppose with general syscalls that might be okay, but certainly not with sys_exit(). They also need memory clobbers, but I don't think memory clobbers would necessarily prevent reordering? In the case of the ARM bug though, it did: https://lore.kernel.org/lkml/Zqa4SAyPKPuaXdgg@mozart.vkv.me/ https://lore.kernel.org/lkml/Zqa4SAyPKPuaXdgg@mozart.vkv.me/