3 ms·
> To reproduce, build the attached program with "gcc -pthread test.c" and run it on a 5.2 or later kernel compiled with GCC 9 (if the kernel is compiled with GC
by saagarjha 7y ago
> To reproduce, build the attached program with "gcc -pthread test.c" and run it on a 5.2 or later kernel compiled with GCC 9 (if the kernel is compiled with GCC 8, it does not reproduce).
I wonder if this is a compiler bug or a new optimization that broke the code.
- asveikau 7y agoFrom the link, it seems like GCC 8 does not cache a read from a variable, and has more memory access to read it, while GCC 9 reads that variable from a register every time. (Maybe from a corrupted register?)
- zaarn 7y agoFrom what I can tell, the issue is that GCC9 stores the result of a pointer dereference in a register to reuse on each loop operation but the loop operation needs to dereference the pointer each time to work correctly.
- Asooka 7y agoSounds like it needs to be volatile then, or rather whatever atomic memory read the kernel has.
- zaarn 7y agoProbably volatile. Likely doesn't need to be atomic, just needs to prevent the compiler from optimizing the code into bugs.
- asveikau 7y agoNo, it sounds like it needs the kernel not to corrupt the value. There is nothing wrong with leaving the value in the register.
- wahern 7y agoI believe the aforementioned pointer caching is in the kernel--it's the pointer to the FP register state which is cached across preemption points in the kernel.
- asveikau 7y agoOk I see, that's a good point. Was not spelled out this well in the bug tracker comment. (If it is now it wasn't when I read it.)
- zaarn 7y agoProbably a mix of both; when developing a kernel, you constantly fight against the compiler trying to be smart and optiziming things out of your code, inlining things, caching data, etc. In this case, it might be necessary to do a volatile read in case that flag has changed, forcing the compiler to reload it.