x86-64 Pascal problem

User avatar

Topic author
arne_v
Master
Posts: 409
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

x86-64 Pascal problem

Post by arne_v » Wed Feb 07, 2024 11:56 am

I did not expect this:

Code: Select all

$ type z5.pas
program z5(input, output);

type
   pstr = varying [1812] of char;

procedure test1(xmlstr : pstr);

begin
    writeln(xmlstr);
end;

begin
    writeln('start');
    test1('<methodResponse>' +
          '<params>' +
          '<param>' +
          '<value><i4>123</i4></value>' +
          '</param>' +
          '</params>' +
          '</methodResponse>');
end.
$ pas z5
$ link z5
$ r z5
start
<methodResponse><params><param><value><i4>123</i4></value></param></params></methodResponse>
$ type z6.pas
program z6(input, output);

type
   pstr = varying [1813] of char;

procedure test1(xmlstr : pstr);

begin
    writeln(xmlstr);
end;

begin
    writeln('start');
    test1('<methodResponse>' +
          '<params>' +
          '<param>' +
          '<value><i4>123</i4></value>' +
          '</param>' +
          '</params>' +
          '</methodResponse>');
end.
$ pas z6
$ link z6
$ r z6
start
%SYSTEM-F-ACCVIO, access violation, reason mask=05, virtual address=000000007ACDA000, PC=FFFF830009A4B279, PS=0000001B
%TRACE-F-TRACEBACK, symbolic stack dump follows
image     module    routine               line      rel PC           abs PC
LIBOTS                                       0 0000000080002279 FFFF830009A4B279
z6  Z6  TEST1                                6 000000000000008F 000000008000008F
z6  Z6  Z6                                  14 000000000000005B 000000008000005B
                                             0 FFFF8300081FC0A6 FFFF8300081FC0A6
DCL                                          0 00000000800677FB 000000007ADFF7FB
%TRACE-I-END, end of TRACE stack dump
What happen when the varying goes from 1812 to 1813??

Added in 46 minutes 9 seconds:
And:

$ pas/ver
VSI Pascal x86-64 V6.3-143 (GEM 50XC4) on OpenVMS x86_64 V9.2-2

Added in 22 minutes 6 seconds:
In the real program I got other errors with 1800. But it worked with 800. So the 1812-1813 difference seems to depend on the specific context.

Not sure how useful this note is, but ...

Added in 17 minutes 41 seconds:
And the real program works fine on Alpha with 32000.
Arne
arne@vajhoej.dk
VMS user since 1986


jreagan
VSI Expert
Master
Posts: 154
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: x86-64 Pascal problem

Post by jreagan » Wed Feb 07, 2024 2:10 pm

Interesting. Note that the failing PC of 07ACD8000 is on a page boundary.

For Z6/test, I see the compiler saving the old sp and allocating 1816 bytes on the stack

Code: Select all

00000071:  movq    %rsp,%rbp
00000075:  subq    $00000718,%rsp
and then we pass the address 8 bytes beyond the "top" of the stack to OTS$MOVE and ask it to copy 1815 bytes

Code: Select all

0000007F:  leaq    -00000720(%rbp),%rdi
00000086:  movl    $00000717,%esi
0000008B:  callq   OTS$MOVE@PLT
if that stack page doesn't exist (and beyond the top of the stack) and we get an ACCVIO, it seems that the system doesn't do "stack extension" and gives the ACCVIO back.

I'll enter a bug report.

User avatar

Topic author
arne_v
Master
Posts: 409
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: x86-64 Pascal problem

Post by arne_v » Wed Feb 07, 2024 7:01 pm

So it is a VMS problem not a Pascal problem - if I tried playing with large stack variables in C then I would eventually hit the same problem?
Arne
arne@vajhoej.dk
VMS user since 1986


jreagan
VSI Expert
Master
Posts: 154
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: x86-64 Pascal problem

Post by jreagan » Thu Feb 08, 2024 9:31 am

No, since we touched an address past the end of the stack pointer, I don't expect the OS to extend the stack. I might have implied that I was expecting it to do so.

It might turn into an OS question at some point with regards to "red zones" on x86 but we turn those off and always move the stack pointer and always set the frame pointer.

User avatar

Topic author
arne_v
Master
Posts: 409
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: x86-64 Pascal problem

Post by arne_v » Thu Feb 08, 2024 4:38 pm

OK. So I am waiting for a new Pascal compiler.
Arne
arne@vajhoej.dk
VMS user since 1986


jreagan
VSI Expert
Master
Posts: 154
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: x86-64 Pascal problem

Post by jreagan » Wed Feb 28, 2024 10:42 am

Finally tracked this down. The code in the routine didn't use the current length of the VARYING string to make the local copy, it used the max length by mistake. We've fixed it. Not sure when we'll make the next Pascal kit (which would technically be the 1st FT for a future V6.4 kit). I'm just back from holiday and will start to plan it out.


niklas
Contributor
Posts: 13
Joined: Fri Oct 22, 2021 7:31 am
Reputation: 0
Status: Offline

Re: x86-64 Pascal problem

Post by niklas » Mon May 13, 2024 7:15 am

jreagan wrote:
Wed Feb 28, 2024 10:42 am
Finally tracked this down. The code in the routine didn't use the current length of the VARYING string to make the local copy, it used the max length by mistake. We've fixed it. Not sure when we'll make the next Pascal kit (which would technically be the 1st FT for a future V6.4 kit). I'm just back from holiday and will start to plan it out.
Any updates on when a new version of the compiler will be out?

//Niklas


jreagan
VSI Expert
Master
Posts: 154
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: x86-64 Pascal problem

Post by jreagan » Thu May 16, 2024 10:40 am

We hope to get a new Pascal kit (a X6.4 field test release) out in the next week or so.


soutbarr
Active Contributor
Posts: 40
Joined: Wed Mar 13, 2024 4:45 pm
Reputation: 1
Status: Offline

Re: x86-64 Pascal problem

Post by soutbarr » Thu May 16, 2024 8:22 pm

Will we have access to that on vmdk?


niklas
Contributor
Posts: 13
Joined: Fri Oct 22, 2021 7:31 am
Reputation: 0
Status: Offline

Re: x86-64 Pascal problem

Post by niklas » Thu May 30, 2024 5:43 am

New compiler installed now, and the crashes are gone!

We do get the warnings below now, our developers haven´t seen this error befor, so if anyone has any pointers on what to look for it would be much appreciated.

Code: Select all

invalid tag
!104 = !DICompositeType(tag: DW_TAG_set_type, baseType: !19, size: 8, align: 8)
invalid tag
!106 = !DICompositeType(tag: DW_TAG_set_type, baseType: !31, size: 8, align: 8)
invalid tag
!108 = !DICompositeType(tag: DW_TAG_set_type, baseType: !35, size: 8, align: 8)

Post Reply