Page 1 of 1

[Done] x64 call convention parsing bug

Posted: Mon Feb 15, 2021 1:36 am
by idle
bug is in x64 call parsing, it is set off by a float or double parameter, if the last parameter is changed to an integer the code works
result on linux x64 PB 5.72

bug reported from saki
viewtopic.php?f=7&t=76745

g 7
h 10
bug below
g 8873415
h

Code: Select all

Procedure bar(a,b,c,d,e,f,g,h.s=" ",i=9,j.d=10.0)
 
  Debug g
  Debug h
   
EndProcedure   

Procedure foo()
  Protected a,text.s   
 
  For a = 1 To 10
    text=Str(a)
    bar(1,2,3,4,5,6,7,text,9,#PI)
  Next
 
  Debug " bug below "
 
  For a = 1 To 10
     bar(1,2,3,4,5,6,7,Str(a),9,#PI)
  Next
   
EndProcedure

foo()

Re: x64 call convention parsing bug

Posted: Mon Feb 15, 2021 10:40 am
by NicTheQuick
Confirmed on Ubuntu 20.10 x64 with Purebasic 5.73.

Re: x64 call convention parsing bug

Posted: Mon Feb 15, 2021 2:19 pm
by Shardik
@idle,

good catch! Congratulations!

I can confirm your described bug in x64 call parsing (and the disappearance of the bug when changing j.d=10.0 or j.f=10.0 to j.i=10) in PB 5.73 x64 for these two operating systems:
  • Linux Mint 19.3 'Tricia' x64 with Cinnamon and GTK3
  • MacOS 11.2.1 'Big Sur'
On MacOS 10.9.5 'Mavericks' with PB 5.73 x86 idle's example code runs like a charm, so the x86 call parsing is working correctly and the call parsing bug is limited to the Linux and MacOS x64 versions.

Re: x64 call convention parsing bug

Posted: Mon Feb 15, 2021 4:19 pm
by skywalk
True Detectives 8)

Re: x64 call convention parsing bug

Posted: Mon Feb 15, 2021 4:59 pm
by NicTheQuick
Looks like there is one PUSH to much if I am reading that right:

Code: Select all

; bar(1,2,3,4,5,6,7,text,9,#PI)         | ; bar(1,2,3,4,5,6,7,Str(a),9,#PI)
  SUB    rsp,8                          |   PUSH   qword [PB_StringBasePosition]
  PUSH   qword 9                        |   PUSH   qword 9
                                        |   PUSH   qword [PB_StringBasePosition]
                                        |   SUB    rsp,8
                                        |   PUSH   qword [PB_StringBasePosition]
                                        |   PUSH   qword [v_a]
                                        |   POP    rdi
                                        |   POP    rsi
                                        |   CALL   PB_Str
                                        |   ADD    rsp,8
  PUSH   qword [v_text]                 |   ADD    qword [PB_StringBasePosition],2
  PUSH   qword 7                        |   PUSH   qword 7
  FLD    qword [D1]                     |   FLD    qword [D1]
  SUB    rsp,8                          |   SUB    rsp,8
  FSTP   qword [rsp]                    |   FSTP   qword [rsp]
  PUSH   qword 6                        |   PUSH   qword 6
  PUSH   qword 5                        |   PUSH   qword 5
  PUSH   qword 4                        |   PUSH   qword 4
  PUSH   qword 3                        |   PUSH   qword 3
  PUSH   qword 2                        |   PUSH   qword 2
  PUSH   qword 1                        |   PUSH   qword 1
                                        |   MOV    rsi,[PB_StringBase]
                                        |   ADD    [rsp+56],rsi
  POP    rdi                            |   POP    rdi
  POP    rsi                            |   POP    rsi
  POP    rdx                            |   POP    rdx
  POP    rcx                            |   POP    rcx
  POP    r8                             |   POP    r8
  POP    r9                             |   POP    r9
  MOVSD  xmm0,qword [rsp]               |   MOVSD  xmm0,qword [rsp]
  ADD    rsp,8                          |   ADD    rsp,8
  CALL  _Procedure0                     |   CALL  _Procedure0
  ADD    rsp,32                         |   ADD    rsp,24
                                        |   SUB    rsp,8

Re: x64 call convention parsing bug

Posted: Mon Feb 15, 2021 9:40 pm
by idle
Shardik wrote:@idle,

good catch! Congratulations!

I can confirm your described bug in x64 call parsing (and the disappearance of the bug when changing j.d=10.0 or j.f=10.0 to j.i=10) in PB 5.73 x64 for these two operating systems:
  • Linux Mint 19.3 'Tricia' x64 with Cinnamon and GTK3
  • MacOS 11.2.1 'Big Sur'
On MacOS 10.9.5 'Mavericks' with PB 5.73 x86 idle's example code runs like a charm, so the x86 call parsing is working correctly and the call parsing bug is limited to the Linux and MacOS x64 versions.
Thanks for confirming the bug on MacOS, hopefully this will get treated with urgency.

Re: x64 call convention parsing bug

Posted: Mon Feb 15, 2021 9:44 pm
by Saki
Good Morning Idle.
Yep, confirmed on MacOS BigSur / PB573

Re: x64 call convention parsing bug

Posted: Wed Jan 03, 2024 4:05 pm
by Fred
Fixed.