PureBasic Forum
https://www.purebasic.fr/english/

x64 call convention parsing bug
https://www.purebasic.fr/english/viewtopic.php?f=23&t=76748
Page 1 of 1

Author:  idle [ Mon Feb 15, 2021 1:36 am ]
Post subject:  x64 call convention parsing bug

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


Quote:
g 7
h 10
bug below
g 8873415
h



Code:
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()

Author:  NicTheQuick [ Mon Feb 15, 2021 10:40 am ]
Post subject:  Re: x64 call convention parsing bug

Confirmed on Ubuntu 20.10 x64 with Purebasic 5.73.

Author:  Shardik [ Mon Feb 15, 2021 2:19 pm ]
Post subject:  Re: x64 call convention parsing bug

@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.

Author:  skywalk [ Mon Feb 15, 2021 4:19 pm ]
Post subject:  Re: x64 call convention parsing bug

True Detectives 8)

Author:  NicTheQuick [ Mon Feb 15, 2021 4:59 pm ]
Post subject:  Re: x64 call convention parsing bug

Looks like there is one PUSH to much if I am reading that right:
Code:
; 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

Author:  idle [ Mon Feb 15, 2021 9:40 pm ]
Post subject:  Re: x64 call convention parsing bug

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.

Author:  Saki [ Mon Feb 15, 2021 9:44 pm ]
Post subject:  Re: x64 call convention parsing bug

Good Morning Idle.
Yep, confirmed on MacOS BigSur / PB573

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/