Project

General

Profile

Actions

Bug #6333

closed

Ruby 1.9.3 (P0, P125,P194) Segmentation fault when compiled with GCC 4.7.0

Added by raylinn@gmail.com (ray linn) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3p194 (2012-04-20) [x64-mingw32]
Backport:
[ruby-core:44505]

Description

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 <main>' ./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.


Files

gcc470-on-win.patch (2.68 KB) gcc470-on-win.patch mame (Yusuke Endoh), 04/23/2012 07:34 PM

Updated by mame (Yusuke Endoh) over 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to luislavena (Luis Lavena)
  • Priority changed from 6 to Normal

Hello,

I cannot reproduce this issue with gcc 4.7.0 + Ubuntu + Ruby trunk.
Luis, could you please check this?

--
Yusuke Endoh

Updated by phasis68 (Heesob Park) over 12 years ago

I guess this issue is related with http://bugs.ruby-lang.org/issues/5407

I think that CFLAGS should have "-fno-omit-frame-pointer" flag.

Updated by raylinn@gmail.com (ray linn) over 12 years ago

phasis68 (Heesob Park) wrote:

I guess this issue is related with http://bugs.ruby-lang.org/issues/5407

I think that CFLAGS should have "-fno-omit-frame-pointer" flag.

I configured as the following, but issue is still.

$ ./configure --build=x86_64-w64-mingw32 CFLAGS="-O2 -fno-omit-frame-pointer -I
/usr/local/include" LDFLAGS="-L/usr/local/lib" --enable-shared

Here could download the GCC 4.7.0 for Windows
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/ray_linn/

Updated by phasis68 (Heesob Park) over 12 years ago

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 <stdio.h>
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)

Updated by mame (Yusuke Endoh) over 12 years ago

Hello,

phasis68 (Heesob Park) wrote:

And I found the main reason is invalid szInternalCmds array initialization on GCC 4.7.0.

Good catch! Could you please test the patch attached?

--
Yusuke Endoh

Updated by phasis68 (Heesob Park) over 12 years ago

I confirmed that I can succeeded to build the patch applied Ruby 1.9.3-p194 with GCC 4.7.0 (MinGW32) without segmentation fault.

Actions #7

Updated by usa (Usaku NAKAMURA) over 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35435.
ray, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • win32/win32.c (szInternalCmds, internal_match, internal_cmd_match):
    get rid of a segmentation fault with GCC 4.7.0.
    reported by (ray linn) at [ruby-core:44505]
    [Bug #6333], and patched by mame.

  • test/ruby/test_system.rb (TestSystem#test_system): test for it.

Updated by usa (Usaku NAKAMURA) over 12 years ago

Thank you everyone, especially, Park-san.

Updated by raylinn@gmail.com (ray linn) over 12 years ago

GCC also corrected this issue.

Regards.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0