Skip to content

Commit

Permalink
fix Issue 7387 - call instruction does not understand $
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 26, 2020
1 parent 065da71 commit 605c054
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/dmd/iasmdmd.d
Expand Up @@ -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++)
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions test/runnable/iasm.d
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions test/runnable/iasm64.d
Expand Up @@ -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");
Expand Down Expand Up @@ -6940,6 +6968,7 @@ int main()
test17027();
test18553();
test20126();
test63();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 605c054

Please sign in to comment.