Closed sergey-sj closed 7 years ago
I’ve tested this in ML and it’s fine, as a quick test (and this seems to work for me with hjwasm) can you change the label name from @@ret: to something else? I used @@xet: and make sure the ret instruction is on it’s own line.
Let me know if that solves the issue for you.
From: sergey-sj [mailto:notifications@github.com] Sent: 24 January 2017 12:29 PM To: Terraspace/HJWasm HJWasm@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [Terraspace/HJWasm] JMP over a RET with a custom epilogue is incorrect (#47)
;Strangely, forward JMP is correct but backward is not.
.386 .MODEL FLAT .CODE
Proc1 PROC NEAR test eax,eax; 85 C0 JNZ @@over https://github.com/over ; 75 06 -ok test eax,eax; 85 C0 JNZ @@ret https://github.com/ret ; 75 00 -ok @@ret https://github.com/ret : CLC ; F8 RET ; C3
@@over https://github.com/over : test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 FA -ok test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 F6 -ok Proc1 ENDP
TestEpilogue MACRO procname, flag, parmbytes, localbytes, reglist, userparms CLC RET ENDM
OPTION EPILOGUE:TestEpilogue
Proc2 PROC NEAR test eax,eax ; 85 C0 JZ @@over https://github.com/over ; 74 06 - ok test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 00 - ok
@@ret https://github.com/ret : RET; F8 C3; epilogue ok
@@over https://github.com/over : test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 FE - wrong - makes infinite loop test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 FE - wrong Proc2 ENDP END
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Terraspace/HJWasm/issues/47 , or mute the thread https://github.com/notifications/unsubscribe-auth/AQGQVHZp_cKrB_kSRmtYTzXRU3NOMGXxks5rVe5zgaJpZM4LsNCw .
It seems like the issue is the epilogue macro being run on a line that has a label.
Just moving the ret to it’s own line seems to solve the issue.
Please confirm.
From: sergey-sj [mailto:notifications@github.com] Sent: 24 January 2017 12:29 PM To: Terraspace/HJWasm HJWasm@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [Terraspace/HJWasm] JMP over a RET with a custom epilogue is incorrect (#47)
;Strangely, forward JMP is correct but backward is not.
.386 .MODEL FLAT .CODE
Proc1 PROC NEAR test eax,eax; 85 C0 JNZ @@over https://github.com/over ; 75 06 -ok test eax,eax; 85 C0 JNZ @@ret https://github.com/ret ; 75 00 -ok @@ret https://github.com/ret : CLC ; F8 RET ; C3
@@over https://github.com/over : test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 FA -ok test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 F6 -ok Proc1 ENDP
TestEpilogue MACRO procname, flag, parmbytes, localbytes, reglist, userparms CLC RET ENDM
OPTION EPILOGUE:TestEpilogue
Proc2 PROC NEAR test eax,eax ; 85 C0 JZ @@over https://github.com/over ; 74 06 - ok test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 00 - ok
@@ret https://github.com/ret : RET; F8 C3; epilogue ok
@@over https://github.com/over : test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 FE - wrong - makes infinite loop test eax,eax ; 85 C0 JNZ @@ret https://github.com/ret ; 75 FE - wrong Proc2 ENDP END
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Terraspace/HJWasm/issues/47 , or mute the thread https://github.com/notifications/unsubscribe-auth/AQGQVHZp_cKrB_kSRmtYTzXRU3NOMGXxks5rVe5zgaJpZM4LsNCw .
Confirmed that this behaviour isn't present for normal macros, ONLY the epilogue when on a line with a label.
; Disassembly of file: epi.obj ; Thu Jan 26 20:03:24 2017 ; Mode: 32 bits ; Syntax: MASM/ML ; Instruction set: 80386
.386 .model flat
public Proc1 public Proc3 public Proc2
_text SEGMENT DWORD PUBLIC 'CODE' ; section number 1
Proc1 PROC NEAR test eax, eax ; 0000 _ 85. C0 jnz ?002 ; 0002 75, 06 test eax, eax ; 0004 _ 85. C0 jnz ?001 ; 0006 75, 00 ?001: clc ; 0008 F8 ret ; 0009 _ C3 Proc1 ENDP
?002 LABEL NEAR test eax, eax ; 000A 85. C0 jnz ?001 ; 000C 75, FA test eax, eax ; 000E _ 85. C0 jnz ?001 ; 0010 75, F6
Proc3 LABEL NEAR test eax, eax ; 0012 _ 85. C0 jz ?004 ; 0014 74, 06 test eax, eax ; 0016 _ 85. C0 jnz ?003 ; 0018 75, 00 ?003: clc ; 001A F8 ret ; 001B _ C3
?004 LABEL NEAR test eax, eax ; 001C 85. C0 jnz ?003 ; 001E 75, FA test eax, eax ; 0020 _ 85. C0 jnz ?003 ; 0022 75, F6 ret ; 0024 _ C3
Proc2 PROC NEAR test eax, eax ; 0025 _ 85. C0 jz ?006 ; 0027 74, 06 test eax, eax ; 0029 _ 85. C0 jnz ?005 ; 002B 75, 00 ?005: clc ; 002D F8 ret ; 002E _ C3 Proc2 ENDP
?006 LABEL NEAR test eax, eax ; 002F 85. C0 jnz ?005 ; 0031 75, FA test eax, eax ; 0033 _ 85. C0 ; Note: Function does not end with ret or jmp jnz ?005 ; 0035 75, F6
_text ENDS
_data SEGMENT DWORD PUBLIC 'DATA' ; section number 2
_data ENDS
END
Ok thanks, so there is a workaround - to place labels on separate lines.
Still there's something wrong with labels declared with a colon - two labels on the same line also don't work .CODE l1: l2: ;Error A2209: Syntax error l1:: l2: ;Error A2209: Syntax error
;labels in data segment don't work .DATA l1: DB ?; Error A2183: Use of register assumed to ERROR
Labels declared with LABEL are all ok, but they aren't scoped.
I don’t think two labels on a line has ever worked in jwasm, but worth adding to the list to check.
Will check labels in data, that should work.
From: sergey-sj [mailto:notifications@github.com] Sent: 30 January 2017 10:09 AM To: Terraspace/HJWasm HJWasm@noreply.github.com Cc: John Hankinson john@terraspace.co.uk; Comment comment@noreply.github.com Subject: Re: [Terraspace/HJWasm] JMP over a RET with a custom epilogue is incorrect (#47)
Ok thanks, so there is a workaround - to place labels on separate lines.
Still there's something wrong with labels declared with a colon - two labels on the same line also don't work .CODE l1: l2: ;Error A2209: Syntax error l1:: l2: ;Error A2209: Syntax error
;labels in data segment don't work .DATA l1: DB ?; Error A2183: Use of register assumed to ERROR
Labels declared with LABEL are all ok, but they aren't scoped.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Terraspace/HJWasm/issues/47#issuecomment-276023535 , or mute the thread https://github.com/notifications/unsubscribe-auth/AQGQVMfrMMVfR6j7y48InM2yD468WliMks5rXbazgaJpZM4LsNCw .
So the fix is more of a workaround, when using a custom epilogue macro, ensure that the ret is on it's own line without a label preceeding it.
;Strangely, forward JMP is correct but backward is not.
.386 .MODEL FLAT .CODE
Proc1 PROC NEAR test eax,eax; 85 C0 JNZ @@over ; 75 06 -ok test eax,eax; 85 C0 JNZ @@ret ; 75 00 -ok @@ret: CLC ; F8 RET ; C3
@@over: test eax,eax ; 85 C0 JNZ @@ret; 75 FA -ok test eax,eax ; 85 C0 JNZ @@ret; 75 F6 -ok Proc1 ENDP
TestEpilogue MACRO procname, flag, parmbytes, localbytes, reglist, userparms CLC RET ENDM
OPTION EPILOGUE:TestEpilogue
Proc2 PROC NEAR test eax,eax ; 85 C0 JZ @@over; 74 06 - ok test eax,eax ; 85 C0 JNZ @@ret; 75 00 - ok
@@ret: RET; F8 C3; epilogue ok
@@over: test eax,eax ; 85 C0 JNZ @@ret ; 75 FE - wrong - makes infinite loop test eax,eax ; 85 C0 JNZ @@ret; 75 FE - wrong Proc2 ENDP END