Bug#289884: Problem with compiler optimization (now with a patch)

Marc Pignat marc.pignat at hevs.ch
Thu May 27 06:29:14 UTC 2010


Hi!

I think I've found the (very bad) joke!

I've extracted the code which detect alignment failures into a test/try.c, then I tried it :

gcc -O0 -Wall -o try try.c && ./try
write failed (ef0000be)
pooky:~/test# gcc -O -Wall -o try try.c && ./try
pooky:~/test# gcc -O1 -Wall -o try try.c && ./try
pooky:~/test# gcc -O2 -Wall -o try try.c && ./try
pooky:~/test# gcc -O3 -Wall -o try try.c && ./try

Only the -O0 fails... the compiler seems to have optimized away most of our test!!!

My proposed solution is to use the 'volatile' keyword to make sure the compiler
will really do the job.

Please note that it does not work with -O3, but the configure script compile with
-O2, so this should be fine.

At this time I've only tested the Configure scripts, which now detects the
align problem on ARM. I'm compiling the whole thing to check if the md5 bug
goes away!

I hope this will fix this *5 years* old bug, and the upstream bug as well!

Best regards


Marc

---
 Configure |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Configure b/Configure
index 01fa3c0..19327b7 100755
--- a/Configure
+++ b/Configure
@@ -18549,8 +18549,8 @@ $signal_t bletch(int s) { exit(4); }
 #endif
 int main() {
 #if BYTEORDER == 0x1234 || BYTEORDER == 0x4321
-    U8 buf[8];
-    U32 *up;
+    volatile U8 buf[8];
+    volatile U32 *up;
     int i;
 
     if (sizeof(U32) != 4) {
-- 
1.7.1







More information about the Perl-maintainers mailing list