From 605c05413b1917596522804ff63a4de41a77aa3d Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Tue, 25 Aug 2020 03:25:26 -0700 Subject: [PATCH] fix Issue 7387 - call instruction does not understand $ --- src/dmd/iasmdmd.d | 14 +++++++++++--- test/runnable/iasm.d | 8 ++++++++ test/runnable/iasm64.d | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/dmd/iasmdmd.d b/src/dmd/iasmdmd.d index c8861bfa5e3e..2431d385ede9 100644 --- a/src/dmd/iasmdmd.d +++ b/src/dmd/iasmdmd.d @@ -777,6 +777,14 @@ RETRY: enum log = false; if (log) { printf("`%s`\n", asm_opstr(pop)); } if (log) { printf("opflags1 = "); asm_output_flags(opflags[0]); printf("\n"); } + + if (pop.ptb.pptb1.opcode == 0xE8 && + opnds[0].s == asmstate.psDollar && + (opnds[0].disp >= byte.min && opnds[0].disp <= byte.max) + ) + // Rewrite CALL $+disp from rel8 to rel32 + opflags[0] = CONSTRUCT_FLAGS(OpndSize._32, _rel, _flbl, 0); + PTRNTAB1 *table1; for (table1 = pop.ptb.pptb1; table1.opcode != ASM_END; table1++) @@ -1232,9 +1240,9 @@ opflag_t asm_determine_operand_flags(ref OPND popnd) if (popnd.disp >= byte.min && popnd.disp <= byte.max) us = CONSTRUCT_FLAGS(OpndSize._8, _rel, _flbl,0); - else if (popnd.disp >= short.min && - popnd.disp <= short.max && !global.params.is64bit) - us = CONSTRUCT_FLAGS(OpndSize._16, _rel, _flbl,0); + //else if (popnd.disp >= short.min && + //popnd.disp <= short.max && global.params.is16bit) + //us = CONSTRUCT_FLAGS(OpndSize._16, _rel, _flbl,0); else us = CONSTRUCT_FLAGS(OpndSize._32, _rel, _flbl,0); } diff --git a/test/runnable/iasm.d b/test/runnable/iasm.d index affede104642..0375b2848ede 100644 --- a/test/runnable/iasm.d +++ b/test/runnable/iasm.d @@ -4748,6 +4748,10 @@ void test9866() 0x66, 0x0f, 0xb7, 0x00, // movzx AX, word ptr [EAX]; 0x0f, 0xb7, 0xc0, // movzx EAX, AX; 0x0f, 0xb7, 0x00, // movzx EAX, word ptr [EAX]; + + 0xEB, 0x00, //jmp $; + 0xE9, 0xCD, 0xAB, 0x00, 0x00, // jmp $+0xABCD; + 0xE8, 0x05, 0x00, 0x00, 0x00, // call $+5; ]; asm @@ -4772,6 +4776,10 @@ void test9866() movzx EAX, AX; movzx EAX, word ptr [EAX]; + jmp $; + jmp $+0xABCD; + call $+5; + L1: pop EAX; mov p[EBP],EAX; } diff --git a/test/runnable/iasm64.d b/test/runnable/iasm64.d index b6f595154cf9..a33af5ab980a 100644 --- a/test/runnable/iasm64.d +++ b/test/runnable/iasm64.d @@ -6864,6 +6864,34 @@ void test20126() /****************************************************/ +void test63() +{ + asm + { + L1: + mov EAX,0; + jmp L2; + + db 0,0,0,0,0,0,0,0 ; + db 0,0,0,0,0,0,0,0 ; + db 0,0,0,0,0,0,0,0 ; + db 0,0,0,0,0,0,0,0 ; + db 0,0,0,0,0,0,0,0 ; + db 0,0,0,0,0,0,0,0 ; + db 0,0,0,0,0,0,0,0 ; + db 0,0,0,0,0,0,0,0 ; + } + asm + { + jmp L1; // more than 128 bytes away + } + L2: + { + } +} + +/****************************************************/ + int main() { printf("Testing iasm64.d\n"); @@ -6940,6 +6968,7 @@ int main() test17027(); test18553(); test20126(); + test63(); printf("Success\n"); return 0;