[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread ktietz at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

Kai Tietz ktietz at gcc dot gnu.org changed:

   What|Removed |Added

 CC||ktietz at gcc dot gnu.org

--- Comment #1 from Kai Tietz ktietz at gcc dot gnu.org 2011-06-29 15:16:49 
UTC ---
Hmm, I can't confirm this. Do you have a testcase for this?
As far as I know has msvcrt's setjmp function an hidden argument, which should
be for 32-bit NULL.  This might be here the real issue.


[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread jojelino at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

--- Comment #2 from gee jojelino at gmail dot com 2011-06-29 17:08:41 UTC ---
Created attachment 24635
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24635
testcase

i hope it would be helpful
GNU gdb (GDB) 7.3.50.20110610-cvs
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type show copying
and show warranty for details.
This GDB was configured as i686-pc-cygwin.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...

warning: the current range check setting does not match the language.


warning: the current type check setting does not match the language.

Whether backtraces should continue past the entry point of a program is off.
Reading symbols from /tmp/a...done.
(gdb) r
Starting program: /tmp/a
[New Thread 9616.0x1628]

Program received signal SIGSEGV, Segmentation fault.
0x77b66502 in msvcrt!_abnormal_termination ()
   from /cygdrive/c/WINDOWS/system32/msvcrt.dll
(gdb) bt
#0  0x77b66502 in msvcrt!_abnormal_termination ()
   from /cygdrive/c/WINDOWS/system32/msvcrt.dll
#1  0x77b6ac67 in strerror () from /cygdrive/c/WINDOWS/system32/msvcrt.dll
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) disassemble
Dump of assembler code for function msvcrt!_abnormal_termination:
   0x77b664cf +0: xor%eax,%eax
   0x77b664d1 +2: mov%fs:0x0,%ecx
   0x77b664d8 +9: cmpl   $0x77b66424,0x4(%ecx)
   0x77b664df +16:jne0x77b664f1 msvcrt!_abnormal_termination+34
   0x77b664e1 +18:mov0xc(%ecx),%edx
   0x77b664e4 +21:mov0xc(%edx),%edx
   0x77b664e7 +24:cmp%edx,0x8(%ecx)
   0x77b664ea +27:jne0x77b664f1 msvcrt!_abnormal_termination+34
   0x77b664ec +29:mov$0x1,%eax
   0x77b664f1 +34:ret
   0x77b664f2 +35:push   %ebx
   0x77b664f3 +36:push   %ecx
   0x77b664f4 +37:mov$0x77b919b0,%ebx
   0x77b664f9 +42:jmp0x77b66505 msvcrt!_abnormal_termination+54
   0x77b664fb +44:push   %ebx
   0x77b664fc +45:push   %ecx
   0x77b664fd +46:mov$0x77b919b0,%ebx
= 0x77b66502 +51:mov0x8(%ebp),%ecx
   0x77b66505 +54:mov%ecx,0x8(%ebx)
   0x77b66508 +57:mov%eax,0x4(%ebx)
   0x77b6650b +60:mov%ebp,0xc(%ebx)
   0x77b6650e +63:push   %ebp
---Type return to continue, or q return to quit---q
Quit


[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread ktietz at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

Kai Tietz ktietz at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID

--- Comment #3 from Kai Tietz ktietz at gcc dot gnu.org 2011-06-29 17:30:41 
UTC ---
Well, this test-file helps pretty much to see your problem.
As you didn't mentioned, which options you are specifying to gcc on
complilation, I assumed that you were using -fomit-frame-pointer and -O1. But
well, as described later, it doesn't really matters much here.

As register ebp is used by gcc as internal frame-register. Even if you are
specifying -fomit-frame-pointer as option, the main function will still have a
frame-pointer setup. Also ebp-register is a callee-saved register, which means
its use as local-register variable is in general nothing wise to do.

I compiled program with 4.6.0 gcc using mingw-w64 as runtime, and I get a crash
when main-function exits.  This is to be expected, as epilogue for main is

 movl %ebp, %esp
 pop  %ebp
 ret

but output looks as expected:

$ ./tst.exe
start
foobar 10
foobar 9
foobar 8
foobar 7
foobar 6
foobar 5
foobar 4
foobar 3
foobar 2
foobar 1
foobar 0
bar

So I mark this bug as invalid. If for you the code crashes by using mingw.org,
well then file a report to them.  This is for sure no gcc issue.

Regards,
Kai


[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread jojelino at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

--- Comment #4 from gee jojelino at gmail dot com 2011-06-29 18:03:24 UTC ---
Created attachment 24637
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24637
generated asm with i686-pc-mingw32-gcc testsetjmp.c -S -s

 I compiled program with 4.6.0 gcc using mingw-w64 as runtime, and I get a 
 crash
yes this testcase crashes at epilogue of main if gcc doesn't do anything
but in latest gcc trunk, it doesn't work as expected. 
sorry. i forgot to say gcc version
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-pc-cygwin/4.7.0/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: ./configure --config-cache --prefix=/usr
--disable-win32-registry --enable-threads=win32 --enable-languages=c,c++,lto
--with-win32-nlsapi=unicode --enable-tls --disable-bootstrap --enable-shared
--disable-sjlj-exceptions --enable-gomp
Thread model: win32
gcc version 4.7.0 20110622 (experimental) (GCC)
and i attached asm code latest gcc trunk generated
i used i686-pc-mingw32-gcc testsetjmp.c -S -s to generate .s file.
 . please ld using attached asm file.
and i expect you and i get same result.
D:\cygwin\tmpi686-pc-mingw32-gcc testsetjmp.s

D:\cygwin\tmpa
start
foobar 10
foobar 9
foobar 8
foobar 7
foobar 6
foobar 5
foobar 4
foobar 3
foobar 2
foobar 1
foobar 0
(jit debugger message dialog shows)


[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread jojelino at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

gee jojelino at gmail dot com changed:

   What|Removed |Added

  Known to work||4.6.0
  Known to fail||4.7.0

--- Comment #5 from gee jojelino at gmail dot com 2011-06-29 18:07:14 UTC ---
and expected bar didn't show up
as it sigsegvs in msvcrt!nlg_notify


[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread jojelino at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

--- Comment #6 from gee jojelino at gmail dot com 2011-06-29 18:08:34 UTC ---
 $ gcc -v
i'm sorry to attach invalid gcc -v. this is proper one.
$ i686-pc-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=i686-pc-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-pc-mingw32/4.7.0/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with: ./configure --config-cache --prefix=/usr
--enable-win32-registry --enable-threads=win32 --enable-languages=c,c++,lto
--with-win32-nlsapi=unicode --enable-tls --disable-bootstrap
--target=i686-pc-mingw32 --enable-shared --enable-interpreter
--disable-sjlj-exceptions --enable-gomp
Thread model: win32
gcc version 4.7.0 20110622 (experimental) (GCC)


[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread jojelino at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

gee jojelino at gmail dot com changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |

--- Comment #7 from gee jojelino at gmail dot com 2011-06-29 19:35:20 UTC ---
(In reply to comment #3)
 As register ebp is used by gcc as internal frame-register. Even if you are
 specifying -fomit-frame-pointer as option, the main function will still have a
 frame-pointer setup. Also ebp-register is a callee-saved register, which means
 its use as local-register variable is in general nothing wise to do.

maybe the following could be counterexample.
this code is from gcc 200622.
ebp may be not internal frame pointer.
so in this case setjmp can store invalid ebp.
nlg_notify dereferences ebp,causing sigsegv
not only it don't use framepointer, but also it doesn't restore framepointer

LFE104:
.p2align 4,,15
.globl_rb_ensure
.def_rb_ensure;.scl2;.type32;.endef
_rb_ensure:
LFB105:
.loc 2 727 0 is_stmt 1
.cfi_startproc
LVL835:
pushl%ebx
LCFI228:
.cfi_def_cfa_offset 8
.cfi_offset 3, -8
subl$120, %esp
LCFI229:
.cfi_def_cfa_offset 128
LBB566:
.loc 2 731 0
movl_ruby_current_thread, %eax
LBE566:
.loc 2 729 0
movl$4, 32(%esp)
LVL836:
LBB567:
.loc 2 731 0
movl$0, 100(%esp)
movl%eax, %edx
movl%eax, 28(%esp)
LVL837:
movl152(%eax), %eax
movl%eax, 108(%esp)
leal36(%esp), %eax
movl%eax, 152(%edx)
.loc 2 732 0
movl%eax, (%esp)
call__setjmp
LVL838:
testl%eax, %eax
movl%eax, %ebx
LVL839:
jeL733
.loc 2 735 0
movl108(%esp), %eax
LVL840:
movl28(%esp), %edx
movl%eax, 152(%edx)
LBE567:
.loc 2 738 0
movl140(%esp), %eax
movl%eax, (%esp)
call*136(%esp)
LVL841:
.loc 2 740 0
movl_ruby_current_thread, %eax
movl%ebx, 4(%esp)
movl152(%eax), %eax
movl%eax, (%esp)
call_longjmp
LVL842:
.p2align 4,,10
L733:
LBB568:
.loc 2 733 0
movl132(%esp), %eax
movl%eax, (%esp)
call*128(%esp)
LVL843:
.loc 2 735 0
movl28(%esp), %edx
.loc 2 733 0
movl%eax, 32(%esp)
.loc 2 735 0
movl108(%esp), %eax
movl%eax, 152(%edx)
LBE568:
.loc 2 738 0
movl140(%esp), %eax
movl%eax, (%esp)
call*136(%esp)
LVL844:
.loc 2 741 0
movl32(%esp), %eax
.loc 2 742 0
addl$120, %esp
LCFI230:
.cfi_def_cfa_offset 8
popl%ebx
LCFI231:
.cfi_def_cfa_offset 4
.cfi_restore 3
LVL845:
ret
.cfi_endproc
LFE105:
.p2align 4,,15
.globl_rb_frame_this_func
.def_rb_frame_this_func;.scl2;.type32;.endef
_rb_frame_this_func:
LFB108:
.loc 2 791 0
.cfi_startproc
.loc 2 792 0
movl_ruby_current_thread, %eax
movl16(%eax), %eax
jmp_frame_func_id
LVL846:
.cfi_endproc
LFE108:


[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread jojelino at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

--- Comment #8 from gee jojelino at gmail dot com 2011-06-29 19:37:35 UTC ---
Created attachment 24640
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24640
preprocessed source and generated code

verbose log

i686-pc-mingw32-gcc -O4 -mfpmath=sse -march=native -mtune=native -mthreads
-mstackrealign -g3 -Wextra -Wno-unused-parameter -Wno-parentheses
-Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith
-Werror=write-strings -Werror=declaration-after-statement
-Werror=implicit-function-declaration -include ruby/config.h -include
ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT   -I.
-I.ext/include/i386-mingw32 -I./include -I. -I/usr/include/w32api -o eval.o -c
eval.c -save-temps -v
Using built-in specs.
COLLECT_GCC=i686-pc-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-pc-mingw32/4.7.0/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with: ./configure --config-cache --prefix=/usr
--enable-win32-registry --enable-threads=win32 --enable-languages=c,c++,lto
--with-win32-nlsapi=unicode --enable-tls --disable-bootstrap
--target=i686-pc-mingw32 --enable-shared --enable-interpreter
--disable-sjlj-exceptions --enable-gomp
Thread model: win32
gcc version 4.7.0 20110622 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-O4' '-mfpmath=sse' '-march=native' '-mtune=native'
'-mthreads' '-mstackrealign' '-g3' '-Wextra' '-Wno-unused-parameter'
'-Wno-parentheses' '-Wno-long-long' '-Wno-missing-field-initializers'
'-Werror=pointer-arith' '-Werror=write-strings'
'-Werror=declaration-after-statement' '-Werror=implicit-function-declaration'
'-include' 'ruby/config.h' '-include' 'ruby/missing.h' '-fvisibility=hidden'
'-D' 'RUBY_EXPORT' '-I' '.' '-I' '.ext/include/i386-mingw32' '-I' './include'
'-I' '.' '-I' '/usr/include/w32api' '-o' 'eval.o' '-c' '-save-temps' '-v'
 /usr/libexec/gcc/i686-pc-mingw32/4.7.0/cc1.exe -E -quiet -v -I . -I
.ext/include/i386-mingw32 -I ./include -I . -I /usr/include/w32api -dD -D_MT -D
RUBY_EXPORT -include ruby/config.h -include ruby/missing.h eval.c -march=core2
-mcx16 -msahf -mno-movbe -mno-aes -mno-pclmul -mno-popcnt -mno-abm -mno-lwp
-mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-tbm -mno-avx -mno-sse4.2 -msse4.1
--param l1-cache-size=32 --param l1-cache-line-size=64 --param
l2-cache-size=2048 -mtune=core2 -mfpmath=sse -mthreads -mstackrealign -Wextra
-Wno-unused-parameter -Wno-parentheses -Wno-long-long
-Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings
-Werror=declaration-after-statement -Werror=implicit-function-declaration
-fvisibility=hidden -g3 -fworking-directory -O4 -fpch-preprocess -o eval.i
ignoring nonexistent directory
/usr/lib/gcc/i686-pc-mingw32/4.7.0/../../../../i686-pc-mingw32/sys-include
ignoring duplicate directory .
#include ... search starts here:
#include ... search starts here:
 .
 .ext/include/i386-mingw32
 ./include
 /usr/include/w32api
 /usr/lib/gcc/i686-pc-mingw32/4.7.0/include
 /usr/lib/gcc/i686-pc-mingw32/4.7.0/include-fixed
 /usr/lib/gcc/i686-pc-mingw32/4.7.0/../../../../i686-pc-mingw32/include
End of search list.
COLLECT_GCC_OPTIONS='-O4' '-mfpmath=sse' '-march=native' '-mtune=native'
'-mthreads' '-mstackrealign' '-g3' '-Wextra' '-Wno-unused-parameter'
'-Wno-parentheses' '-Wno-long-long' '-Wno-missing-field-initializers'
'-Werror=pointer-arith' '-Werror=write-strings'
'-Werror=declaration-after-statement' '-Werror=implicit-function-declaration'
'-include' 'ruby/config.h' '-include' 'ruby/missing.h' '-fvisibility=hidden'
'-D' 'RUBY_EXPORT' '-I' '.' '-I' '.ext/include/i386-mingw32' '-I' './include'
'-I' '.' '-I' '/usr/include/w32api' '-o' 'eval.o' '-c' '-save-temps' '-v'
 /usr/libexec/gcc/i686-pc-mingw32/4.7.0/cc1.exe -fpreprocessed eval.i
-march=core2 -mcx16 -msahf -mno-movbe -mno-aes -mno-pclmul -mno-popcnt -mno-abm
-mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-tbm -mno-avx -mno-sse4.2
-msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param
l2-cache-size=2048 -mtune=core2 -quiet -dumpbase eval.c -mfpmath=sse -mthreads
-mstackrealign -auxbase-strip eval.o -g3 -O4 -Wextra -Wno-unused-parameter
-Wno-parentheses -Wno-long-long -Wno-missing-field-initializers
-Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement
-Werror=implicit-function-declaration -version -fvisibility=hidden -o eval.s
GNU C (GCC) version 4.7.0 20110622 (experimental) (i686-pc-mingw32)
compiled by GNU C version 4.7.0 20110622 (experimental), GMP version
5.0.0, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (GCC) version 4.7.0 20110622 (experimental) (i686-pc-mingw32)
compiled by GNU C version 4.7.0 20110622 (experimental), GMP version
5.0.0, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: b98a9904da950a3b4c2a13878d133f7f
COLLECT_GCC_OPTIONS='-O4' '-mfpmath=sse' '-march=native' '-mtune=native'

[Bug rtl-optimization/49230] please provide workaround for setjmp/longjmp in mingw32

2011-06-29 Thread ktietz at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49230

Kai Tietz ktietz at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID

--- Comment #10 from Kai Tietz ktietz at gcc dot gnu.org 2011-06-29 20:20:21 
UTC ---
Please stop to reopen this bug. It isn't related to gcc at all. I just rebuild
a gcc 4.7 (trunk) version for i686-w64-mingw32 and test passes as expected
(with crash after trying to leave main function).
This issue is related to mingw.org's header-set and handling of setjmp.  As I
mentioned before, this is caused by a missing (undocumented) argument for
setjmp. You disassembly of this function shows that msvcrt's setjmp function
tries to read this hidden argument and just by accident it is here the place of
ebp.
See on msdn the user-comment about setjmp.