From: "phasis68 (Heesob Park)" Date: 2012-04-23T17:02:46+09:00 Subject: [ruby-core:44541] [ruby-trunk - Bug #6333] Ruby 1.9.3 (P0, P125,P194) Segmentation fault when compiled with GCC 4.7.0 Issue #6333 has been updated by phasis68 (Heesob Park). I can reproduce this issue on mingw gcc 4.7.0. The point of segmentation fault is #902 of win32.c. return strcmp(key, *(const char *const *)elem); And I found the main reason is invalid szInternalCmds array initialization on GCC 4.7.0. I am not sure this is a bug of GCC 4.7.0, but GCC 4.7.0 cannot handle array initialization of string constant with point arithmetic properly. Consider the following code: #include int main() { static const char *const aa[] = {"foo"+1}; printf("aa[0] = %s\n",aa[0]); return 0; } I works fine on GCC 4.5.2 and 4.6.1 C:\work>gcc --version gcc (tdm-1) 4.5.2 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. C:\work>gcc a.c -oa.exe C:\work>a aa[0] = oo C:\work>gcc --version gcc (tdm-1) 4.6.1 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. C:\work>gcc a.c -oa.exe C:\work>a aa[0] = oo On GCC 4.7.0, it fails with segmentation fault. C:\work>gcc --version gcc (GCC) 4.7.0 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. C:\work>gcc a.c -oa.exe C:\work>a (error dialog) ---------------------------------------- Bug #6333: Ruby 1.9.3 (P0, P125,P194) Segmentation fault when compiled with GCC 4.7.0 https://bugs.ruby-lang.org/issues/6333#change-26091 Author: raylinn@gmail.com (ray linn) Status: Assigned Priority: Normal Assignee: luislavena (Luis Lavena) Category: Target version: ruby -v: ruby 1.9.3p194 (2012-04-20) [x64-mingw32] Compiled Ruby 1.9.3 with GCC 4.7.0 (MinGW64) , when miniruby.exe execute ./win32/mkexports.rb, Segmentation fault occurs, the error message is as following: CC = gcc LD = ld LDSHARED = gcc -shared CFLAGS = -Ofast -I/usr/local/include XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hi dden -DRUBY_EXPORT CPPFLAGS = -I/usr/local/icnlude -Ofast -I. -I.ext/include/x64-mingw32 -I./include -I. DLDFLAGS = -Wl,--enable-auto-image-base,--enable-auto-import -Wl,--out-i mplib=libx64-msvcrt-ruby191.dll.a x64-msvcrt-ruby191.def SOLIBS = x64-msvcrt-ruby191.res.o -lshell32 -lws2_32 -limagehlp generating x64-msvcrt-ruby191.def ./win32/mkexports.rb:143: [BUG] Segmentation fault ruby 1.9.3p194 (2012-04-20) [x64-mingw32] -- Control frame information ----------------------------------------------- c:td p:---- s:td b:td l:td d:td CFUNC :foreach c:td p:td s:td b:td l:td d:td METHOD ./win32/mkexports.rb:143 c:td p:td s:td b:td l:td d:td METHOD ./win32/mkexports.rb:85 c:td p:td s:td b:td l:tx d:tx METHOD ./win32/mkexports.rb:150 c:td p:td s:td b:td l:td d:td METHOD ./win32/mkexports.rb:159 c:td p:td s:td b:td l:tx d:tx METHOD ./win32/mkexports.rb:40 c:td p:---- s:td b:td l:td d:td FINISH c:td p:---- s:td b:td l:td d:td CFUNC :new c:td p:td s:td b:td l:td d:td METHOD ./win32/mkexports.rb:21 c:td p:td s:td b:td l:td d:td METHOD ./win32/mkexports.rb:25 c:td p:td s:td b:td l:tx d:td BLOCK ./win32/mkexports.rb:166 c:td p:---- s:td b:td l:td d:td FINISH c:td p:td s:td b:td l:tx d:tx TOP -- Ruby level backtrace information ---------------------------------------- ./win32/mkexports.rb:166:in `block in
' ./win32/mkexports.rb:25:in `extract' ./win32/mkexports.rb:21:in `create' ./win32/mkexports.rb:21:in `new' ./win32/mkexports.rb:40:in `initialize' ./win32/mkexports.rb:159:in `each_export' ./win32/mkexports.rb:150:in `each_export' ./win32/mkexports.rb:85:in `objdump' ./win32/mkexports.rb:143:in `each_line' ./win32/mkexports.rb:143:in `foreach' -- C level backtrace information ------------------------------------------- C:\windows\SYSTEM32\ntdll.dll(NtWaitForSingleObject+0xa) [0x0000000077B3135A] C:\windows\system32\KERNELBASE.dll(WaitForSingleObjectEx+0x9c) [0x000007FEFE0310 DC] [0x000000000056A574] [0x000000000043FAEB] [0x0000000000440996] [0x00000000004F7BA4] [0x0000000000587275] C:\windows\SYSTEM32\ntdll.dll(_C_specific_handler+0x9c) [0x0000000077AF85A8] C:\windows\SYSTEM32\ntdll.dll(RtlDecodePointer+0xbd) [0x0000000077B09D0D] C:\windows\SYSTEM32\ntdll.dll(RtlUnwindEx+0xbbf) [0x0000000077AF91AF] C:\windows\SYSTEM32\ntdll.dll(KiUserExceptionDispatcher+0x2e) [0x0000000077B3127 8] C:\windows\system32\msvcrt.dll(strcmp+0x43) [0x000007FEFE905963] C:\windows\system32\msvcrt.dll(bsearch+0x89) [0x000007FEFE8F47D9] [0x000000000057E52B] [0x0000000000477E3D] [0x0000000000478401] [0x0000000000478673] [0x0000000000478A55] [0x0000000000478F43] [0x0000000000565ACC] [0x000000000055DA6A] [0x0000000000560B05] [0x0000000000561CDE] [0x0000000000562EEA] [0x0000000000496CF4] [0x0000000000565ACC] [0x000000000055DA6A] [0x0000000000560B05] [0x0000000000561827] [0x000000000044D5A0] [0x00000000004470CE] [0x0000000000447188] [0x0000000000447557] [0x000000000044794B] [0x000000000058B6B7] [0x00000000004013C9] [0x00000000004014E8] C:\windows\system32\kernel32.dll(BaseThreadInitThunk+0xd) [0x000000007788652D] -- Other runtime information ----------------------------------------------- * Loaded script: ./win32/mkexports.rb * Loaded features: 0 enumerator.so 1 C:/msys/1.0/home/beta/ruby-1.9.3-p194/rbconfig.rb [NOTE] You may have encountered a bug in the Ruby interpreter or extension libraries. Bug reports are welcome. For details: http://www.ruby-lang.org/bugreport.html This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. make: *** [x64-msvcrt-ruby191.def] Error 3 just make clean, and roll back the GCC to 4.6.3, recompile (just type make, no reconfiguration), then everything is ok. change Ofast to O2, issue is still, and try P0, P125, P194, issue is the same. -- http://bugs.ruby-lang.org/