home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / d / gcc / specs.bug / text0000.txt < prev   
Encoding:
Text File  |  1995-10-10  |  2.5 KB  |  96 lines

  1. gcc 2.6.3 or 2.7.0 can generate incorrect code for the '86
  2. architecture when used with the -O2 switch but not
  3. -fno-strength-reduce (and by default, the kernel is compiled with just
  4. this combination).  The following patch enables -fno-strength-reduce
  5. all the time.  (Thanks to Jurgen Botz <jbotz@mtholyoke.edu>.)  
  6.  
  7. A test program follows.
  8.  
  9.                          - Jim Van Zandt
  10.  
  11. ===================================================================
  12. --- 1.1    1995/09/04 01:26:00
  13. +++ /usr/lib/gcc-lib/i486-linux/2.6.3/specs    1995/09/04 15:11:29
  14. @@ -8,10 +8,10 @@
  15.  %{!m386:-D__i486__} %{posix:-D_POSIX_SOURCE}
  16.  
  17.  *cc1:
  18. -
  19. +-fno-strength-reduce
  20.  
  21.  *cc1plus:
  22. -
  23. +-fno-strength-reduce
  24.  
  25.  *endfile:
  26.  
  27. /*
  28. Article 12633 of comp.os.linux.development.system:
  29. Path: linus.mitre.org!blanket.mitre.org!agate!howland.reston.ans.net!news.sprintlink.net!in2.uu.net!news.iii.net!iii2.iii.net!not-for-mail
  30. From: craigs@iii2.iii.net (Craig Shrimpton)
  31. Newsgroups: comp.os.linux.development.system
  32. Subject: GCC bug : Does your kernel have a time bomb?
  33. Date: 31 Aug 1995 18:38:53 -0400
  34. Organization: iii.net
  35. Lines: 51
  36. Message-ID: <425dlt$doq@iii2.iii.net>
  37. NNTP-Posting-Host: iii2.iii.net
  38. X-Newsreader: TIN [version 1.2 PL2]
  39.  
  40. Greetings,
  41.  
  42. Today a potentially serious gcc bug has been brought to my attention.  
  43. This bug concerns the -O2 optimization flag that is supplied by default 
  44. in the kernel distributions.  If you use -O2 optimization without also 
  45. specifying -fno-strength-reduce, computations against arrays in loops 
  46. can, under certain conditions, return incorrect results.  It concerns me 
  47. greatly since this bug has gone undetected for a long time.  Its 
  48. potential to cause wierd inconsistencies is rather astounding.  The 
  49. following C program demonstrates the bug.  This bug will manifest itself 
  50. whenever B >= whatever number is subtracted from i.
  51.  
  52. Please review this program and post suggestions.  I sincerely hope that 
  53. I'm wrong about this because this situation could occur in the kernel under 
  54. many instances.
  55.  
  56. Compile this program as follows:
  57.  
  58. gcc -O2 -o try try.c 
  59.  
  60. and then as:
  61.  
  62. gcc -O2 -fno-strength-reduce -o try try.c
  63.  
  64. The problem will become readily apparent.
  65.  
  66. -Craig
  67.  
  68. [ I've changed 'test' to 'try' to avoid conflict with /usr/bin/test -jrv ]
  69.  
  70. ----------------------------- try.c -------------------------------
  71. */
  72.  
  73. #include <stdio.h>
  74. int A[3];
  75. unsigned int B = 3;
  76.  
  77. void printit(void)
  78. {
  79. int i;
  80. for(i = 0; i < B; i++)
  81.    fprintf(stdout, "A[%d] = %d\n", i, A[i]);
  82. }
  83.  
  84. int main()
  85. {
  86. int i;
  87. for(i = 0; i < B; i++)
  88.    A[i] = i - 3;
  89. printit();
  90. return 0;
  91. }
  92.  
  93.  
  94.  
  95.  
  96.