User account creation filtered due to spam.

Bug 49104 - bootstrap failure on AMD K6-2 with illegal instruction (cmove) in stage2
Summary: bootstrap failure on AMD K6-2 with illegal instruction (cmove) in stage2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-21 17:41 UTC by Reinhard Foerster
Modified: 2011-05-22 19:19 UTC (History)
1 user (show)

See Also:
Host: i586-linux
Target: i586-linux
Build: i586-linux
Known to work: 4.5.3
Known to fail: 4.6.0
Last reconfirmed: 2011-05-22 18:04:30


Attachments
preprocessed lex.c (39.42 KB, application/gzip)
2011-05-22 11:09 UTC, Reinhard Foerster
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Reinhard Foerster 2011-05-21 17:41:57 UTC
I get the error in 4.6.0 and 4.6-20110520. 4.5.3 is fine.

$ ../gcc-4.6-20110520/configure --prefix=/usr/pkg/gcc-4.6 \
--enable-languages=c --disable-nls --disable-multilib --disable-lto \
--enable-checking=release --with-system-zlib

$ make bootstrap
...
Configuring stage 2 in i586-pc-linux-gnu/libgcc
configure: creating cache ./config.cache
checking for --enable-version-specific-runtime-libs... no
checking for a BSD-compatible install... /usr/bin/install -c
checking for gawk... gawk
checking build system type... i586-pc-linux-gnu
checking host system type... i586-pc-linux-gnu
checking for i586-pc-linux-gnu-ar... ar
checking for i586-pc-linux-gnu-lipo... lipo
checking for i586-pc-linux-gnu-nm... /home/rf11/src/build1/./gcc/nm
checking for i586-pc-linux-gnu-ranlib... ranlib
checking for i586-pc-linux-gnu-strip... strip
checking whether ln -s works... yes
checking for i586-pc-linux-gnu-gcc... /home/rf11/src/build1/./gcc/xgcc -B/home/rf11/src/build1/./gcc/ -B/usr/pkg/gcc-4.6/i586-pc-linux-gnu/bin/ -B/usr/pkg/gcc-4.6/i586-pc-linux-gnu/lib/ -isystem /usr/pkg/gcc-4.6/i586-pc-linux-gnu/include -isystem /usr/pkg/gcc-4.6/i586-pc-linux-gnu/sys-include
checking for suffix of object files... configure: error: in `/home/rf11/src/build1/i586-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[2]: *** [configure-stage2-target-libgcc] Error 1
make[2]: Leaving directory `/home/rf11/src/build1'
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory `/home/rf11/src/build1'
make: *** [bootstrap] Error 2

from ./i586-pc-linux-gnu/libgcc/config.log:
configure:3268: /home/rf11/src/build1/./gcc/xgcc -B/home/rf11/src/build1/./gcc/ -B/usr/pkg/gcc-4.6/i586-pc-linux-gnu/bin/ -B/usr/pkg/gcc-4.6/i586-pc-linux-gnu/lib/ -isystem /usr/pkg/gcc-4.6/i586-pc-linux-gnu/include -isystem /usr/pkg/gcc-4.6/i586-pc-linux-gnu/sys-include    -c -g -O2  conftest.c >&5
xgcc: internal compiler error: Illegal instruction (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
configure:3272: $? = 4
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU C Runtime Library"
| #define PACKAGE_TARNAME "libgcc"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU C Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgcc/"
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:3286: error: in `/home/rf11/src/build1/i586-pc-linux-gnu/libgcc':
configure:3289: error: cannot compute suffix of object files: cannot compile


The illegal insn is at the end of init_vectorized_lexer() in cc1:

Program received signal SIGILL, Illegal instruction.
0x086f977c in init_vectorized_lexer ()
(gdb) disas init_vectorized_lexer
...
0x086f9745 <init_vectorized_lexer+101>: cpuid
0x086f9747 <init_vectorized_lexer+103>: test   %eax,%eax
0x086f9749 <init_vectorized_lexer+105>: je     0x86f96fa <init_vectorized_lexer+26>
0x086f974b <init_vectorized_lexer+107>: mov    $0x1,%eax
0x086f9750 <init_vectorized_lexer+112>: mov    $0x86f65b0,%esi
0x086f9755 <init_vectorized_lexer+117>: cpuid  
0x086f9757 <init_vectorized_lexer+119>: and    $0x100000,%ecx
0x086f975d <init_vectorized_lexer+125>: jne    0x86f973a <init_vectorized_lexer+90>
0x086f975f <init_vectorized_lexer+127>: mov    $0x86f6530,%esi
0x086f9764 <init_vectorized_lexer+132>: test   $0x4000000,%edx
0x086f976a <init_vectorized_lexer+138>: jne    0x86f973a <init_vectorized_lexer+90>
0x086f976c <init_vectorized_lexer+140>: mov    $0x86f64c0,%esi
0x086f9771 <init_vectorized_lexer+145>: mov    $0x86f6060,%eax
0x086f9776 <init_vectorized_lexer+150>: and    $0x2000000,%edx
0x086f977c <init_vectorized_lexer+156>: cmove  %eax,%esi
0x086f977f <init_vectorized_lexer+159>: jmp    0x86f973a <init_vectorized_lexer+90>

$ cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 8
model name      : AMD-K6(tm) 3D processor
stepping        : 12
cpu MHz         : 400.922
cache size      : 64 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr cx8 pge mmx syscall 3dnow k6_mtrr
bogomips        : 801.84
clflush size    : 32
cache_alignment : 32
address sizes   : 32 bits physical, 32 bits virtual


  Reinhard
Comment 1 Reinhard Foerster 2011-05-22 11:09:24 UTC
Created attachment 24324 [details]
preprocessed lex.c
Comment 2 Reinhard Foerster 2011-05-22 11:18:42 UTC
init_vectorized_lexer() is in libcpp/lex.c which is compiled in stage2 by:

/home/rf11/src/build1/./prev-gcc/xgcc -B/home/rf11/src/build1/./prev-gcc/ -B/usr/pkg/gcc-4.6/i586-pc-linux-gnu/bin/ -B/usr/pkg/gcc-4.6/i586-pc-linux-gnu/bin/ -B/usr/pkg/gcc-4.6/i586-pc-linux-gnu/lib/ -isystem /usr/pkg/gcc-4.6/i586-pc-linux-gnu/include -isystem /usr/pkg/gcc-4.6/i586-pc-linux-gnu/sys-include     -I../../gcc-4.6-20110520/libcpp -I. -I../../gcc-4.6-20110520/libcpp/../include -I../../gcc-4.6-20110520/libcpp/include  -g -O2 -fomit-frame-pointer -gtoggle -W -Wall -Wwrite-strings -Wmissing-format-attribute -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wc++-compat -pedantic -Wno-long-long  -I../../gcc-4.6-20110520/libcpp -I. -I../../gcc-4.6-20110520/libcpp/../include -I../../gcc-4.6-20110520/libcpp/include  -c -o lex.o -MT lex.o -MMD -MP -MF .deps/lex.Tpo ../../gcc-4.6-20110520/libcpp/lex.c

Adding "-Q --help=target|grep arch" to the command i get "-march=pentium". Seems to be ok on my i586-linux target. The compiler should not generate cmov* instructions. I get 14 cmov* in the whole file.

Adding -march=i386 or -march=i486 doesn't help. Without -O2 most but not
all (13 of 14) cmov* go away.
Comment 3 Mikael Pettersson 2011-05-22 14:25:51 UTC
I believe this is a dupe of PR48743.  Please check if the second proposed patch for PR48743 solves your problem.
Comment 4 Uroš Bizjak 2011-05-22 18:04:30 UTC
No, the problem is in search_line_mmx (lex.c), compiled with SSE option.  This option also enables CMOVE instruction, so we have protect usage of search_line_mmx with following patch:

--cut here--
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 174030)
+++ libcpp/lex.c	(working copy)
@@ -480,7 +480,7 @@
 static void __attribute__((constructor))
 init_vectorized_lexer (void)
 {
-  unsigned dummy, ecx = 0, edx = 0;
+  unsigned dummy, ecx = 0, edx = 0, edx_e = 0;
   search_line_fast_type impl = search_line_acc_char;
   int minimum = 0;
 
@@ -488,7 +488,7 @@
   minimum = 3;
 #elif defined(__SSE2__)
   minimum = 2;
-#elif defined(__SSE__) || defined(__3dNOW_A__)
+#elif defined(__SSE__)
   minimum = 1;
 #endif
 
@@ -503,9 +503,9 @@
       else if (minimum == 1 || (edx & bit_SSE))
 	impl = search_line_mmx;
     }
-  else if (__get_cpuid (0x80000001, &dummy, &dummy, &dummy, &edx))
+  else if (__get_cpuid (0x80000001, &dummy, &dummy, &dummy, &edx_e))
     {
-      if (minimum == 1 || edx & bit_3DNOWP)
+      if (minimum == 1 || (edx_e & bit_3DNOWP && edx & bit_CMOV))
 	impl = search_line_mmx;
     }
 
--cut here--

Reinhard, can you please test the above patch?
Comment 5 Uroš Bizjak 2011-05-22 18:45:30 UTC
Actually, PMOVMSKB belongs to "AMD extensions to MMX" instruction set, so we should check MMXEXT bit (see PR 48743).

bit_CMOVE can be also checked in %edx as returned from 0x8000 0001 function.

Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 174030)
+++ libcpp/lex.c	(working copy)
@@ -488,7 +488,7 @@
   minimum = 3;
 #elif defined(__SSE2__)
   minimum = 2;
-#elif defined(__SSE__) || defined(__3dNOW_A__)
+#elif defined(__SSE__)
   minimum = 1;
 #endif
 
@@ -505,7 +505,7 @@
     }
   else if (__get_cpuid (0x80000001, &dummy, &dummy, &dummy, &edx))
     {
-      if (minimum == 1 || edx & bit_3DNOWP)
+      if (minimum == 1 || (edx & (bit_MMXEXT | bit_CMOV)))
 	impl = search_line_mmx;
     }
Comment 6 uros 2011-05-22 18:53:35 UTC
Author: uros
Date: Sun May 22 18:53:32 2011
New Revision: 174032

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174032
Log:
	PR target/49104
	* config/i386/cpuid.h (bit_MMXEXT): New define.

libcpp/ChangeLog:

2011-05-22  Uros Bizjak  <ubizjak@gmail.com>

	PR target/49104
	* lex.c (init_vectorized_lexer): Do not set "minimum" when __3dNOW_A__
	is defined.  Check bit_MMXEXT and bit_CMOV to use search_line_mmx.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/cpuid.h
    trunk/libcpp/ChangeLog
    trunk/libcpp/lex.c
Comment 7 uros 2011-05-22 19:14:54 UTC
Author: uros
Date: Sun May 22 19:14:50 2011
New Revision: 174038

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174038
Log:
	PR target/49104
	* config/i386/cpuid.h (bit_MMXEXT): New define.

libcpp/ChangeLog:

2011-05-22  Uros Bizjak  <ubizjak@gmail.com>

	PR target/49104
	* lex.c (init_vectorized_lexer): Do not set "minimum" when __3dNOW_A__
	is defined.  Check bit_MMXEXT and bit_CMOV to use search_line_mmx.


Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/i386/cpuid.h
    branches/gcc-4_6-branch/libcpp/ChangeLog
    branches/gcc-4_6-branch/libcpp/lex.c
Comment 8 Uroš Bizjak 2011-05-22 19:19:13 UTC
Fixed. (The compare in the patch in comment #5 was also fixed ;) )