Thank you, I succeeded in installing the latest cygwin build: gpc-20070904.i686-pc-cygwin.tar.gz
This is the compiler version: $ gpc -v Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs Configured with: ../configure --enable-languages=pascal --enable-threads=posix - -with-system-zlib --enable-nls --without-included-gettext --enable-interpreter - -disable-sjlj-exceptions --enable-shared --build=i686-pc-cygwin --host=i686-pc-c ygwin --target=i686-pc-cygwin --enable-haifa --prefix=/usr : (reconfigured) ../c onfigure --enable-languages=pascal --enable-threads=posix --with-system-zlib --e nable-nls --without-included-gettext --enable-interpreter --disable-sjlj-excepti ons --enable-shared --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-p c-cygwin --enable-haifa --prefix=/usr Thread model: posix gpc version 20070904, based on gcc-3.4.4
This is the compilation and execution: $ gpc crashes.p -Wall -g -o crashes.exe
$ gdb crashes.exe GNU gdb 6.5.50.20060706-cvs (cygwin-special) Copyright (C) 2006 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-cygwin"... (gdb) run Starting program: /cygdrive/c/Documents and Settings/regis.cridlig/My Documents/Info/Pascal/crashes.exe Loaded symbols for /cygdrive/c/WINDOWS/system32/ntdll.dll Loaded symbols for /cygdrive/c/WINDOWS/system32/kernel32.dll Loaded symbols for /usr/bin/cygwin1.dll Loaded symbols for /cygdrive/c/WINDOWS/system32/advapi32.dll Loaded symbols for /cygdrive/c/WINDOWS/system32/rpcrt4.dll Loaded symbols for /cygdrive/c/WINDOWS/system32/secur32.dll
Program received signal SIGSEGV, Segmentation fault. 0x0022cc20 in ?? () (gdb) bt #0 0x0022cc20 in ?? () #1 0x004010a9 in _p__M0_S1_Q (J=200, A=@0x22cc20) at crashes.p:16 #2 0x004010c6 in _p__M0_S1_Q (J=100, A=@0x401050) at crashes.p:16 #3 0x004010e2 in _p__M0_main_program () at crashes.p:20 #4 0x0040115b in main (argc=1, argv=0x6927a0, envp=0x690090) at <implicit code>:22 (gdb)
The program source: $ cat crashes.p program Crashes(input,output);
function B(l:integer):boolean; begin B:=true; end;
procedure Q(j:integer;function A(l:integer):boolean);
function E(l:integer):boolean; begin E := false end;
begin if A(j) then Q(200,E); end;
begin Q(100,B); end.
What is going wrong?
-- Regis
2008/4/4, Prof A Olowofoyeku (The African Chief) chiefsoft@bigfoot.com:
On 3 Apr 2008 at 14:25, Régis Cridlig wrote:
What is the latest stable release of gpc?
http://www.math.uni.wroc.pl/~hebisch/gpc/gpc-20070904.tar.bz2
You can get Cygwin binaries here: http://gnu-pascal.de/contrib/chief/win32/cygwin/
Best regards, The Chief
Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
On 4 Apr 2008 at 14:10, Régis Cridlig wrote:
Thank you, I succeeded in installing the latest cygwin build: gpc-20070904.i686-pc-cygwin.tar.gz
[...]
What is going wrong?
I don't know. It works perfectly fine here:
bash-3.00 /f/gpc> cat crash.pas program Crashes(input,output);
function B(l:integer):boolean; begin B:=true; end;
procedure Q(j:integer;function A(l:integer):boolean);
function E(l:integer):boolean; begin E := false end;
begin if A(j) then Q(200,E); end;
begin Q(100,B); end. bash-3.00 /f/gpc> gpc crash.pas -Wall -g -o crash.exe bash-3.00 /f/gpc> gdb crash.exe GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-cygwin"... (gdb) run Starting program: /f/gpc/crash.exe
Program exited normally. (gdb)
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Have you tried with Cygwin?
2008/4/4, Prof A Olowofoyeku (The African Chief) chiefsoft@bigfoot.com:
On 4 Apr 2008 at 14:10, Régis Cridlig wrote:
Thank you, I succeeded in installing the latest cygwin build: gpc-20070904.i686-pc-cygwin.tar.gz
[...]
What is going wrong?
I don't know. It works perfectly fine here:
bash-3.00 /f/gpc> cat crash.pas
program Crashes(input,output);
function B(l:integer):boolean; begin B:=true; end;
procedure Q(j:integer;function A(l:integer):boolean);
function E(l:integer):boolean; begin E := false end;
begin if A(j) then Q(200,E); end;
begin Q(100,B); end.
bash-3.00 /f/gpc> gpc crash.pas -Wall -g -o crash.exe bash-3.00 /f/gpc> gdb crash.exe GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special) Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-cygwin"... (gdb) run
Starting program: /f/gpc/crash.exe
Program exited normally. (gdb)
Best regards, The Chief
Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
I have attached the assembly code generated by the command: gpc crashes.p -S It is only two pages :-)
2008/4/4, Régis Cridlig cridlig@gmail.com:
Have you tried with Cygwin?
2008/4/4, Prof A Olowofoyeku (The African Chief) chiefsoft@bigfoot.com:
On 4 Apr 2008 at 14:10, Régis Cridlig wrote:
Thank you, I succeeded in installing the latest cygwin build: gpc-20070904.i686-pc-cygwin.tar.gz
[...]
What is going wrong?
I don't know. It works perfectly fine here:
bash-3.00 /f/gpc> cat crash.pas
program Crashes(input,output);
function B(l:integer):boolean; begin B:=true; end;
procedure Q(j:integer;function A(l:integer):boolean);
function E(l:integer):boolean; begin E := false end;
begin if A(j) then Q(200,E); end;
begin Q(100,B); end.
bash-3.00 /f/gpc> gpc crash.pas -Wall -g -o crash.exe bash-3.00 /f/gpc> gdb crash.exe GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special) Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-cygwin"... (gdb) run
Starting program: /f/gpc/crash.exe
Program exited normally. (gdb)
Best regards, The Chief
Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Regis Cridlig wrote:
I have attached the assembly code generated by the command: gpc crashes.p -S It is only two pages :-)
Thanks, the code looks OK. But the program uses a special feature called "trampolines": it writes instructions (a small routine) on the stack and executes that code on the stack.
Trampolines are used to support nested functions as procedure parameters. However, various security measures sometimes disallow executing code on the stack. In particular on reasonably new processors Windows can make stack non-executable. So, I suspect that your Windows detected that program tries to execute code on the stack and signaled error. In such case you need to enable executiong code on the stack.
BTW: What is your Windows version? You seem to be the first to have problem with non-executable stack on Windows.
I run the code on windows xp. By default code on stack cannot be executed. Is there a compiler option to disable this trampoline trick?
-- Regis Cridlig cridlig@gmail.com
Le 4 avr. 08 à 17:29, Waldek Hebisch hebisch@math.uni.wroc.pl a écrit :
Regis Cridlig wrote:
I have attached the assembly code generated by the command: gpc crashes.p -S It is only two pages :-)
Thanks, the code looks OK. But the program uses a special feature called "trampolines": it writes instructions (a small routine) on the stack and executes that code on the stack.
Trampolines are used to support nested functions as procedure parameters. However, various security measures sometimes disallow executing code on the stack. In particular on reasonably new processors Windows can make stack non-executable. So, I suspect that your Windows detected that program tries to execute code on the stack and signaled error. In such case you need to enable executiong code on the stack.
BTW: What is your Windows version? You seem to be the first to have problem with non-executable stack on Windows.
-- Waldek Hebisch hebisch@math.uni.wroc.pl
Waldek Hebisch wrote:
disallow executing code on the stack. In particular on reasonably new processors Windows can make stack non-executable. So, I suspect that
It was always possible, hardware wise, to make the stack non-executable, from the 80286 on up. On the 80286, it would be done by removing the execute bit from the stack segment. On 80386 or later, by removing execute permissions from the stack pages.
I'd be shocked if he had a windows that disallowed this. It would break hundreds of programs in existence, including several of mine. I use it all the time, you pretty much have to in order to get reasonable thunks.
Scott
If you take a closer look at the Pascal source code below there is no need for a trampoline or stub code since the inner function E does not use any variable or parameter in the lexical scope of the containing function Q.
Hence, why does gpc generate a trampoline in this case? how to prevent it?
$ cat crashes.p program Crashes(input,output);
function B(l:integer):boolean; begin B:=true; end;
procedure Q(j:integer;function A(l:integer):boolean);
function E(l:integer):boolean; begin E := false end;
begin if A(j) then Q(200,E); end;
begin Q(100,B); end.
-- Regis
2008/4/4, scott moore samiam@moorecad.com:
Waldek Hebisch wrote:
disallow executing code on the stack. In particular on reasonably new processors Windows can make stack non-executable. So, I suspect that
It was always possible, hardware wise, to make the stack non-executable, from the 80286 on up. On the 80286, it would be done by removing the execute bit from the stack segment. On 80386 or later, by removing execute permissions from the stack pages.
I'd be shocked if he had a windows that disallowed this. It would break hundreds of programs in existence, including several of mine. I use it all the time, you pretty much have to in order to get reasonable thunks.
Scott
Regis Cridlig wrote:
If you take a closer look at the Pascal source code below there is no need for a trampoline or stub code since the inner function E does not use any variable or parameter in the lexical scope of the containing function Q.
Hence, why does gpc generate a trampoline in this case? how to prevent it?
Well, do not used nested function as a procedural parameter -- if you do not need access to variables or parameters in Q you can move E outside. The assumption when allowing nested functions as functional parameter was that they are used to access lexicals in the containing function.
Well, this code is a small fragment of a bigger program. When the program crashed I had to isolate the root cause of the wrong behavior. I cannot move all nested functions because first it can cause name clashes and second the nested functions indeed use lexicals of the containing functions in most cases.
-- Regis Cridlig cridlig@gmail.com
Le 5 avr. 08 à 06:08, Waldek Hebisch hebisch@math.uni.wroc.pl a écrit :
Regis Cridlig wrote:
If you take a closer look at the Pascal source code below there is no need for a trampoline or stub code since the inner function E does not use any variable or parameter in the lexical scope of the containing function Q.
Hence, why does gpc generate a trampoline in this case? how to prevent it?
Well, do not used nested function as a procedural parameter -- if you do not need access to variables or parameters in Q you can move E outside. The assumption when allowing nested functions as functional parameter was that they are used to access lexicals in the containing function.
-- Waldek Hebisch hebisch@math.uni.wroc.pl
On 4 Apr 2008 at 15:19, Régis Cridlig wrote:
Have you tried with Cygwin?
Isn't it clear that I was running under Cygwin? See below ...
[...]
bash-3.00 /f/gpc> gdb crash.exe GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-cygwin"...
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Regis Cridlig wrote:
Thank you, I succeeded in installing the latest cygwin build: gpc-20070904.i686-pc-cygwin.tar.gz
<snip>
$ gpc crashes.p -Wall -g -o crashes.exe
Could you post assembly output from your program? You can get it typing:
gpc -Wall -g -S crashes.p
(the output will be in the crashes.s file).
Attached is the assembly code with the command: gpc -Wall -g -S crashes.p
-- Regis
2008/4/4, Waldek Hebisch hebisch@math.uni.wroc.pl:
Regis Cridlig wrote:
Thank you, I succeeded in installing the latest cygwin build: gpc-20070904.i686-pc-cygwin.tar.gz
<snip>
$ gpc crashes.p -Wall -g -o crashes.exe
Could you post assembly output from your program? You can get it typing:
gpc -Wall -g -S crashes.p
(the output will be in the crashes.s file).
-- Waldek Hebisch hebisch@math.uni.wroc.pl