Crazy debug code
Original Reporter info from Mantis: Adriaan van Os
-
Reporter name: Adriaan van Os
Original Reporter info from Mantis: Adriaan van Os
- Reporter name: Adriaan van Os
Description:
Adding -dDebug triggers a stack overflow for fpc-3.2.0 compiled code statically linked into a gcc program. This doesn't happen when compiling the same code (with -dDebug) with fpc-3.0.4 or when replacing -dDebug by something else, e.g.-dNobug. So, I suspect that somebody left-in some code in the compiler that looks, at runtime to "Debug" being defined or not.
Tested on OS X 10.8.5 i386.
Steps to reproduce:
Unzip attached DebugBug.zip and cd to the DebugBug folder on the command-line
adriaan% libtool -static /usr/local/lib/fpc/3.2.0/units/i386-darwin/rtl/*.o -o rtl-3.2.0.a
adriaan% /usr/local/lib/fpc/3.2.0/ppc386 -Cn mylib.p
adriaan% gcc -arch i386 myUnit.o myLib.o rtl-3.2.0.a testlib.c
adriaan% ./a.out
myUnit init
myLib init
Before calling PascalProc
msg called: PascalProc( "main" ) called
After calling PascalProc
So, this is OK. Now we will add -dDebug, after cleaning-up
adriaan% rm *.o *.ppu a.out link.res linkfiles.res linksyms.fpc ppas.sh
adriaan% /usr/local/lib/fpc/3.2.0/ppc386 -dDebug -Cn mylib.p
gcc -arch i386 myUnit.o myLib.o rtl-3.2.0.a testlib.c
adriaan% ./a.out
Runtime error 202 at $000E3F1D
$000E3F1D
But this is a stack-overflow !
Additional information:
library myLib;
uses
myUnit;
exports
PascalProc;
begin
writeln( 'myLib init')
end.
---------------
unit myUnit;
interface
procedure PascalProc( cstr: PChar); cdecl;
implementation
procedure msg(s: PChar); cdecl; external;
procedure PascalProc( cstr: PChar); cdecl;
var
pstr : AnsiString;
begin
pstr := 'PascalProc( "' + cstr + '" ) called';
msg( PChar( pstr))
end;
begin
writeln( 'myUnit init')
end.
---------------
/*
* Pascal static lib test program, adriaan@microbizz.nl
*
*/
#include &LtPos;stdio.h>
extern void PascalProc(char* str);
extern void msg(char* str)
{
fprintf(stdout, "msg called: %s\n", str);
}
int main(void)
{
fprintf(stdout, "Before calling PascalProc\n");
PascalProc("main");
fprintf(stdout, "After calling PascalProc\n");
return 0;
}
Mantis conversion info:
- Mantis ID: 38440
- Build: 2020/05/31
- Version: 3.2.0