I am trying to get the address of a label using inline asm in Zig.
const main_ccb_p1 = core.mainCCCBPtr();
comptime var to_return_label = ".to_return" ++ mangle(function);
asm volatile (
\\ # save main context
\\ movq %rbx, 0(%[ctx]) # save rbx
\\ movq %r12, 8(%[ctx]) # save r12
\\ movq %r13, 16(%[ctx]) # save r13
\\ movq %r15, 24(%[ctx]) # save r15
\\ movq %rsp, 32(%[ctx]) # save rsp
\\ movq %rbp, 40(%[ctx]) # save rbp
\\
++ "movq $" ++ to_return_label ++ ", 48(%[ctx])"
:
: [ctx] "{rax}" (&main_ccb_p1.context),
);
// some code
// ...
asm volatile (to_return_label ++ ":" ::: "memory");
It works fine on Linux. But I got some weird result on Windows. The address I expected is 0000 7FFF F661 2D60
, but I got FFFF FFFF F661 2D60
. Then I try to use lea label, %rcx
. And I still got a wrong result 0000 0000 F661 2D60
.
Why this happened? How to get the address of a label using inline assembly on Windows? Thanks for your help.