If there is a symbol with the same name as a label in an asm statement, any jump instruction to that label will go to the symbol instead, even it's in another module.
import core.cpuid;
void foo()
{
asm
{
jmp sse; //this will jump to core.cpuid.sse;
sse:
ret;
}
}
Comment #1 by bugzilla — 2020-08-18T07:54:31Z
The assembler actually looks for labels first, as this code from iasm.asm_primary_exp() shows:
Dsymbol s;
if (asmstate.sc.func.labtab)
s = asmstate.sc.func.labtab.lookup(asmstate.tok.ident);
if (!s)
s = asmstate.sc.search(Loc.initial, asmstate.tok.ident, null);
if (!s)
{
// Assume it is a label, and define that label
s = asmstate.sc.func.searchLabel(asmstate.tok.ident);
}
The trouble here is that the label sse is forward referenced, and undefined at the time the asm statement is semantically checked.
Comment #2 by dlang-bot — 2020-08-18T08:37:58Z
@WalterBright created dlang/dmd pull request #11590 "fix Issue 16963 - Forward reference label name resolution in asm stat…" fixing this issue:
- fix Issue 16963 - Forward reference label name resolution in asm statement
https://github.com/dlang/dmd/pull/11590
Comment #3 by dlang-bot — 2020-08-18T19:54:08Z
dlang/dmd pull request #11590 "fix Issue 16963 - Forward reference label name resolution in asm stat…" was merged into master:
- da2fcbffc9993a55f5ef4b82cf9ac5ebe40198c6 by Walter Bright:
fix Issue 16963 - Forward reference label name resolution in asm statement
https://github.com/dlang/dmd/pull/11590