detecting missing early clobber in asm statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

missing early clobbers in ASM statements are quite often source of hard-to-debug miscompiles, since the register allocation changes between optimised and debug code. It is also not traceable by tools like valgrind, since there is no use of uninitialised value.

Common buggy code looks like:
__asm__ (
"add    %l0, %l1, %l2\n\t"
"addc %h0, %h1, %h2\n\t" : "=r"(sum) : "r"(op1), "r"(op2) : "cc");

where the compiler might use the same register for "sum" as for "op1" or "op2".

This kind of bugs appears in gcc code as well - https://gcc.gnu.org/PR78262


Now, how to check for this issue? I was thinking about writing a script that reads a preprocessed code and checks if any output operand (%0) apears lexically before any input operand (which would not catch all cases, but might be a good first step).

Is there some gcc dump I could use where gcc indicates that it used the same register for "asm" output and input? Or even better, let the gcc dump all asm statemets - possibly limited to those where there is no early clobber on output operands?

Thanks,
Zdenek



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux