Bug 48677

Summary: cpp.exe broken ?
Product: gcc Reporter: ralphengels <ralphengels>
Component: preprocessorAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: major CC: jsm28, mikpelinux
Priority: P3    
Version: 4.6.0   
Target Milestone: 4.6.1   
Host: Target:
Build: i686-w64-mingw32 Known to work:
Known to fail: Last reconfirmed:
Attachments: screenshot of gdb output

Description ralphengels@gmail.com 2011-04-19 06:55:20 UTC
hello im not sure if it has happened to others but im running head first into something really annoying with the new gcc-4.6.0 package.

i maintain two packages for i686-w64-mingw32 and x86_64-w64-mingw32.

latest version i build was 4.5.2 and it works flawlessly but i was kinda looking forward to the new version with plugin support for mingw.

unfortunatly it seems something broke with the changes causing cpp.exe to crash when executed (i686-w64-mingw32) a quick run through gdb points to lbasename.c 

in this section   

  /* Skip over a possible disk name.  */
  if (ISALPHA(name[0]) && name[1] == ':') // crashes here
	name += 2;

the x86_64-w64-mingw32 builds cpp.exe doesnt crash but outputs nothing.

i noticed a lot of changes in the libiberty code so maybe a bug ?

heres the commands i use for bootstrapping it allthough i tried several switches.

../src/gcc-4.6.0/configure \
--build=i686-w64-mingw32 --enable-libgomp \
--enable-cloog-backend=isl --enable-languages=c,c++,lto,fortran,objc,obj-c++ \
--enable-lto --enable-checking=release \
--disable-werror --disable-werror-allways \
--disable-win32-registry --enable-version-specific-runtime-libs \
--enable-fully-dynamic-string --prefix=/mingw32 \
--with-sysroot=/mingw32 --with-gnu-ld --with-gnu-as \
--disable-multilib \
CFLAGS="-mtune=generic" \
BOOT_CFLAGS="-mtune=generic" \
CFLAGS_FOR_TARGET="-mtune=generic" \
CXXFLAGS="-mthreads -mtune=generic" \
BOOT_CXXFLAGS="-mthreads -mtune=generic" \
CXXFLAGS_FOR_TARGET="-mthreads -mtune=generic" \
LFLAGS="-flto -fwhopr=2 -s" \
BOOT_LFLAGS="-flto -fwhopr=2 -s" \
LFLAGS_FOR_TARGET="-flto -fwhopr=2 -s" && make

btw im on win7 64.
Comment 1 Jonathan Wakely 2011-04-19 08:45:23 UTC
(In reply to comment #0)
> 
> unfortunatly it seems something broke with the changes causing cpp.exe to crash
> when executed (i686-w64-mingw32) a quick run through gdb points to lbasename.c 

Does it crash in all cases, whatever arguments you give it, or only sometimes?

> in this section   
> 
>   /* Skip over a possible disk name.  */
>   if (ISALPHA(name[0]) && name[1] == ':') // crashes here
>     name += 2;

Why does it crash? is name null? is it less than two characters?
Comment 2 ralphengels@gmail.com 2011-04-19 09:41:45 UTC
in all cases im afraid.

i tried skipping over null names but the crash persists, no output either i just get the usual windows box with cpp.exe has stopped working.

the reason why i noticed it in the first place was that codeblocks popped a warning about cpp not working every time it tried to parse from my project files.

tbh. im not sure where the bug started from. i remember doing a build of an earlier svn version before release and there cpp was working but i cant remember the version number.

i can upload the executable if you want to give it a try with debugging.

ralph
Comment 3 ralphengels@gmail.com 2011-04-20 08:48:38 UTC
Created attachment 24055 [details]
screenshot of gdb output

screenshot of gdb's output.

hope it helps.
Comment 4 Jonathan Wakely 2011-04-20 09:10:21 UTC
gdb's output is just text, wouldn't it have been easier to paste 4 lines of text instead of a 700KB screenshot showing your entire desktop?!

You never answered my question about whether name is null. That screenshot shows it has the value 0xbaadf00d which indicates uninitialized memory from the Windows heap
Comment 5 ralphengels@gmail.com 2011-04-20 09:30:51 UTC
sorry about that its just i have no idea how to copy the text from gdb's console window.

about checking if name = null im not sure how i should go about it ?

something like if (name[0] == NULL) print some error ?.
Comment 6 Jonathan Wakely 2011-04-20 09:32:56 UTC
it's not null. it has the value 0xbaadf00d.
Comment 7 Jonathan Wakely 2011-04-20 09:34:16 UTC
(In reply to comment #5)
> sorry about that its just i have no idea how to copy the text from gdb's
> console window.

right-click, choose "Select All", hit Enter
Comment 8 ralphengels@gmail.com 2011-04-20 10:00:24 UTC
my bad i ran cpp.exe by pulling it directly into gdb (had to use a command prompt).

heres the output.

-	0x417f90	<lbasename>:		mov    0x4(%esp),%eax
-	0x417f94	<lbasename+4>:		movzbl (%eax),%edx // breaks here
-	0x417f97	<lbasename+7>:		movzbl %dl,%ecx
	0x417f9a	<lbasename+10>:		movzwl 0x445b20(%ecx,%ecx,1),%ecx
-	0x417fa2	<lbasename+18>:		and    $0x88,%ecx
-	0x417fa8	<lbasename+24>:		je     0x417fb0 <lbasename+32>
-	0x417faa	<lbasename+26>:		cmpb   $0x3a,0x1(%eax)
-	0x417fae	<lbasename+30>:		je     0x417fe0 <lbasename+80>
-	0x417fb0	<lbasename+32>:		test   %dl,%dl
-	0x417fb2	<lbasename+34>:		je     0x417fcc <lbasename+60>
-	0x417fb4	<lbasename+36>:		lea    0x1(%eax),%ecx
-	0x417fb7	<lbasename+39>:		cmp    $0x5c,%dl
-	0x417fba	<lbasename+42>:		je     0x417fd0 <lbasename+64>
-	0x417fbc	<lbasename+44>:		cmp    $0x2f,%dl
-	0x417fbf	<lbasename+47>:		je     0x417fd0 <lbasename+64>
-	0x417fc1	<lbasename+49>:		add    $0x1,%ecx
-	0x417fc4	<lbasename+52>:		movzbl -0x1(%ecx),%edx
-	0x417fc8	<lbasename+56>:		test   %dl,%dl
-	0x417fca	<lbasename+58>:		jne    0x417fb7 <lbasename+39>
-	0x417fcc	<lbasename+60>:		repz ret 
-	0x417fce	<lbasename+62>:		xchg   %ax,%ax
-	0x417fd0	<lbasename+64>:		mov    %ecx,%eax
-	0x417fd2	<lbasename+66>:		add    $0x1,%ecx
-	0x417fd5	<lbasename+69>:		movzbl -0x1(%ecx),%edx
-	0x417fd9	<lbasename+73>:		test   %dl,%dl
-	0x417fdb	<lbasename+75>:		jne    0x417fb7 <lbasename+39>
-	0x417fdd	<lbasename+77>:		jmp    0x417fcc <lbasename+60>
-	0x417fdf	<lbasename+79>:		nop
-	0x417fe0	<lbasename+80>:		movzbl 0x2(%eax),%edx
-	0x417fe4	<lbasename+84>:		add    $0x2,%eax
-	0x417fe7	<lbasename+87>:		jmp    0x417fb0 <lbasename+32>
-	0x417fe9	<lbasename+89>:		nop
-	0x417fea	<lbasename+90>:		nop
-	0x417feb	<lbasename+91>:		nop
-	0x417fec	<lbasename+92>:		nop
-	0x417fed	<lbasename+93>:		nop
-	0x417fee	<lbasename+94>:		nop
-	0x417fef	<lbasename+95>:		nop

in code

 	179	int mainCRTStartup (void)
-	180	{
 	181	  int ret = 255;
 	182	#ifdef __SEH__
 	183	  asm ("\t.l_start:\n"
 	184	    "\t.seh_handler __C_specific_handler, @except\n"
 	185	    "\t.seh_handlerdata\n"
 	186	    "\t.long 1\n"
 	187	    "\t.rva .l_start, .l_end, _gnu_exception_handler ,.l_end\n"
 	188	    "\t.text"
 	189	    );
 	190	#endif

im pretty new to gdb so bear with me.
Comment 9 ralphengels@gmail.com 2011-04-20 15:17:40 UTC
if its any help i noticed that cpp.exe seems to have a dependency on libstdc++6.dll "somewhere" since dependency walker says it doesnt but it barfs pretty loudly if its not there. 

strange thing is the libstdc++6.dll it wants is the gcc-4.6.0 one (which isnt even built yet) so i had to copy an earlier build to path for it to pick it up.

ill try a static build to see if it still throws the error.
Comment 10 ralphengels@gmail.com 2011-04-20 22:48:54 UTC
hmm it seems im getting closer to iron out where the bug appears. 

 	3880	#if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
 	3881	  /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
 	3882	     then consider it to relocate with the rest of the GCC installation
 	3883	     if GCC_EXEC_PREFIX is set.
 	3884	     ``make_relative_prefix'' is not compiled for VMS, so don't call it.  */
-	3885	  if (target_system_root && !target_system_root_changed && gcc_exec_prefix)
 	3886	    {
-	3887	      char *tmp_prefix = get_relative_prefix (decoded_options[0].arg, // decoded_options throws the BADF00D according to gdb
 	3888						      standard_bindir_prefix,
 	3889						      target_system_root);
-	3890	      if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
 	3891		{
-	3892		  target_system_root = tmp_prefix;
-	3893		  target_system_root_changed = 1;
 	3894		}
 	3895	    }
 	3896	#endif

if i do a memory dump on the call to decoded_options in insight the first 10 registers show {0xbaadf00d} funny name btw. 

maybe a bad pointer somewhere ?
Comment 11 ralphengels@gmail.com 2011-04-21 15:45:13 UTC
ok it seems to be related to sysroots i tried compiling without --with-sysroot and cpp.exe works then. 

question would then be if its an error on my part ? i use sysinternals junction to create the /mingw32/mingw directory for sysroot as a reparse point but i tried just copying the relevant lib and include dirs instead and its still the same error so im not sure.
Comment 12 ralphengels@gmail.com 2011-04-21 16:18:17 UTC
ok it works ! but damn this is strange i had to encase the path to the sysroot directory in quotes and use the windows path instead of the posix path variant.

../src/gcc-4.6.0/configure \
--build=i686-w64-mingw32 --enable-libgomp \
--enable-cloog-backend=isl --enable-languages=c,c++,lto,fortran,objc,obj-c++ \
--enable-lto --enable-checking=release \
--disable-werror --disable-werror-allways \
--disable-win32-registry --enable-version-specific-runtime-libs \
--enable-fully-dynamic-string --prefix=/mingw32 \
--with-gnu-ld --with-gnu-as \
--with-sysroot="c:/codeblocks/mingw32" --disable-multilib \
CFLAGS="-mtune=generic" \
BOOT_CFLAGS="-mtune=generic" \
CFLAGS_FOR_TARGET="-mtune=generic" \
CXXFLAGS="-mthreads -mtune=generic" \
BOOT_CXXFLAGS="-mthreads -mtune=generic" \
CXXFLAGS_FOR_TARGET="-mthreads -mtune=generic" \
LFLAGS="-flto -fwhopr=2 -s" \
BOOT_LFLAGS="-flto -fwhopr=2 -s" \
LFLAGS_FOR_TARGET="-flto -fwhopr=2 -s" && make -j8 && make DESTDIR=/e/gcc32 install
Comment 13 ralphengels@gmail.com 2011-05-15 01:37:13 UTC
took me quite a while but i found the bug.

in gcc/cppspec.c

  /* If we don't need to edit the command line, we can bail early.  */
  new_argc = argc + need_E + read_stdin + !!lang_c_here + !!lang_S_here;

  if (new_argc == argc && !o_here) return;

  new_decoded_options = XNEWVEC (struct cl_decoded_option, new_argc);

  /* old one */
//new_decoded_options[0] = new_decoded_options[0];

  /* new one */
  new_decoded_options[0] = decoded_options[0];

i figured it was a bug in command processing after a while so i compared with an older working release and this was what seemed out of place.

can you confirm this ?
Comment 14 ralphengels@gmail.com 2011-05-15 11:20:25 UTC
well cpp seems to work now so im changing it to fixed unless someone disagress ?.
Comment 15 Mikael Pettersson 2011-05-15 11:32:40 UTC
Looks like a typo introduced by r163459.  Author CC:d.

The typo is still present on trunk so I don't think you should have closed this as fixed.
Comment 16 ralphengels@gmail.com 2011-05-15 12:29:29 UTC
ok ill leave it open.

still one bug im running in to but not sure its related to this one.

the 64 bit build of 4.6.0 cannot bootstrap itself collect2 ld error 116.

the 32 bit one works fine though, i seem to recall hearing it being related to a binutils bug but not sure.
Comment 17 Joseph S. Myers 2011-05-16 18:34:34 UTC
Author: jsm28
Date: Mon May 16 18:34:31 2011
New Revision: 173801

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173801
Log:
	PR preprocessor/48677
	* cppspec.c (lang_specific_driver): Set new_decoded_options[0]
	from decoded_options[0], not from itself.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cppspec.c
Comment 18 Joseph S. Myers 2011-05-16 21:23:18 UTC
Author: jsm28
Date: Mon May 16 21:23:14 2011
New Revision: 173808

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173808
Log:
	PR preprocessor/48677
	* cppspec.c (lang_specific_driver): Set new_decoded_options[0]
	from decoded_options[0], not from itself.

Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/cppspec.c
Comment 19 Joseph S. Myers 2011-05-16 22:09:38 UTC
Fixed for 4.6.1 and 4.7.