When compiling glibc 2.3.1 I noticed problems with the readdir function for programs which were statically linked. On further investigation this turns out to be a bug in gcc. Some values are transferred from a buffer to some local variables, then the buffer is modified through a seperate pointer, and finally the values taken from the original buffer are compared to some values in the new buffer. However GCC (with -O3 option) doesn't seem to recognize that the old buffer is no longer available; it seems to assume that the two buffer pointers do not alias.
The function in question is __getdents from glibc, I have attached preprocessed source.
I have the generated assembly (with comments showing exactly where the problem occurs) as well, but can't seem to attach more than one file using this bug-reporting interface.
Custom linux distribution, Pentium3, kernel version 2.4.18. Binutils 2.13. Gcc version 3.2
gcc -S -O3 -fomit-frame-pointer getdents.i
State-Changed-Why: Not a bug. This code violates type-based aliasing rules.
Reopening to ...
Mark as a dup of bug 21920.
*** This bug has been marked as a duplicate of 21920 ***