Octocontrabass wrote:
simeonz wrote:
What do you mean by "free to optimize"? If you mean that "__attribute__((optimize("-fno-omit-frame-pointer")))" is not ANSI C, then you are obviously correct. But neither is "stack pointer". You couldn't busy loop without going outside the canonical C.
I mean that GCC is free to generate ESP-relative addresses regardless of optimization parameters, and there is no specific guarantee that -fno-omit-frame-pointer will prevent it from doing so.
What do you mean by "no specific guarantee"? Doesn't gcc currently guarantee the exact semantics of those options, even if the disabling flags are not always described explicitly. But take "fno-defer-pop" for example, which is documented. It has strict meaning. Not like say, using "inline" specifier to a function definition. I am not questioning that these options may not be reliable for future use, but even the linux kernel uses "-fno-omit-frame-pointer" to get proper traces, and may be a few other things.
Octocontrabass wrote:
simeonz wrote:
You relax the constraint and it happens to work. How could remark about behavior volatility and offer this suggestion? I agree that using the operand constraints is a better fix per se. "=r" would be a stricter constraint, and could/should work.
Relaxing the constraint is an optimization. The bug fix is ensuring that ESP-relative addresses will be calculated correctly if GCC chooses to use them. Intel specifies that POP with a memory operand using ESP as a base register will increment ESP before calculating the effective address. Combined with the previous decrement from PUSH, the result is that an effective address with ESP will be calculated the way GCC expects.
The subtle change didn't capture my attention. Yes, this will work better. Again, undeniably better solution then mine.