Pascal Viandier wrote:
I gathered all the details I could. The versions of the components:
gpc -v Reading specs from /usr/local/lib/gcc/sparc-sun-solaris2.6/3.4.3/specs Configured with: ../gcc-3.4.3/configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls --disable-libgcj --enable-languages=pascal,c,c++ Thread model: posix gpc version 20050331, based on gcc-3.4.3
as -V as: WorkShop Compilers 4.X dev 18 Sep 1996
ld -V ld: Software Generation Utilities - Solaris-ELF (4.0)
That may be the difference. IIRC I used Gnu assembler and linker (and I have different versions of Sun tools).
The test program:
It is a variation on the adam3k program from the gpc test suite:
program adam3k2; const sconst = [3,5]; var s : set of 1..10; s2 : set of 1..10 = [3,5]; begin s := [3,5]; if s = s2 then WriteLn ('OK') else WriteLn ('failed'); if s = sconst then WriteLn ('OK') else WriteLn ('failed'); end.
I compile it with: gpc -g -O0 --automake -o adam3k2 adam3k2.pas
Results:
There are four interesting points here: 1- If I execute it as it is, there is no core dump but both tests display "failed" instead of "OK" 2- If I swap the two tests (put "if s = s2..." after "if s = sconst...") the test crashes on the first comparison in _p_Set_Equal. 3- The optimization level at the gpc command-line (-O0) has no impact on the result 4- (Perhaps useless) Swapping the operands of the tests has no impact on the result.
What gdb says: Starting program: /data1/Pascal/p/test/adam3k2
Program received signal SIGSEGV, Segmentation fault. $00029134 in _p_Set_Equal (Seta=$55d84, Lowa=0, Higha=1312, Setb=$41c62, Lowb=3, Highb=0)
That shows paramteters at the point of crash (where they changed by the execution). Can you put a breakpoint at _p_Set_Equal and check if parameters are correct: both Seta nad Setb should point to number 40. BTW: to get correct values on my machine I had to setep trough few instructions (so that parameters are copied to their registers) and then do:
set language c print *(long *)SetA
(I am not sure if Pascal mode in gdb allows one to cast values to unnamed type).
If the paramters are incorrect then one should egzamine assembly file obtained via `gpc -g -S adam3k2.pas'. However, the file I got from the cross compiler looks OK, so the most likely reason is assembler or linker.
(gdb) disassemble
The code looks OK (my first guess was that SetEqual got miscompiled). And after reassembling it runs correctly in an emulator. Also, I get the same code from the cross compiler.