Skip to content

MS Inline Assembly $ syntax not supported #20235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tritao mannequin opened this issue May 27, 2014 · 5 comments
Open

MS Inline Assembly $ syntax not supported #20235

tritao mannequin opened this issue May 27, 2014 · 5 comments
Labels

Comments

@tritao
Copy link
Mannequin

tritao mannequin commented May 27, 2014

Bugzilla Link 19861
Version trunk
OS Windows NT
Blocks #13712
CC @DougGregor,@rnk

Extended Description

While compiling the Mono runtime via clang-cl I've found an issue while handling MSVC inline assembly. This works correctly with cl but fails with clang.

Failure:

clang-cl asm.c
asm.c(1,25) : error: unexpected token in argument list
int main() { __asm call $+5; }
^
asm.c(1,30) : error: expected '}'
int main() { __asm call $+5; }
^
asm.c(1,11) : note: to match this '{'
int main() { __asm call $+5; }
^
2 errors generated.

Minimal repro:

int main() { __asm call $+5; }

Repro with some context:

typedef int mgreg_t;

typedef struct {
mgreg_t eax;
mgreg_t ebx;
mgreg_t ecx;
mgreg_t edx;
mgreg_t ebp;
mgreg_t esp;
mgreg_t esi;
mgreg_t edi;
mgreg_t eip;
} MonoContext;

#define MONO_CONTEXT_GET_CURRENT(ctx) do {
void *_ptr = &(ctx);
__asm {
__asm mov eax, _ptr
__asm mov [eax+0x00], eax
__asm mov [eax+0x04], ebx
__asm mov [eax+0x08], ecx
__asm mov [eax+0x0c], edx
__asm mov [eax+0x10], ebp
__asm mov [eax+0x14], esp
__asm mov [eax+0x18], esi
__asm mov [eax+0x1c], edi
__asm call $+5
__asm pop dword ptr [eax+0x20]
}
} while (0)

int main()
{
MonoContext ctx;
MONO_CONTEXT_GET_CURRENT(ctx);
return 0;
}

@tritao
Copy link
Mannequin Author

tritao mannequin commented May 27, 2014

By the way, this syntax is documented in MSDN: http://msdn.microsoft.com/en-us/library/78cxesy1.aspx

"As in MASM programs, the dollar symbol ($) serves as the current location counter. It is a label for the instruction currently being assembled. In __asm blocks, its main use is to make long conditional jumps"

@rnk
Copy link
Collaborator

rnk commented May 27, 2014

blink OK, sounds good, let's do it. :)

@tritao
Copy link
Mannequin Author

tritao mannequin commented May 27, 2014

@tritao
Copy link
Mannequin Author

tritao mannequin commented May 27, 2014

I've spent a couple hours trying learning this part of the codebase and trying to add this to Clang but I've not been able to get it working. I've attached a work in progress patch, it goes a bit further and emits the inline assembly but there's some asm rewriting going on for translating immediates and it's output as "call $$$" which the assembler fails to deal with.

I'm not that familiar with either AT&T or Intel assembly and neither am I sure that the approach I am taking is the correct one so I'll leave more knowledge souls to deal with this.

FWIW I just rewrote this part of code in Mono to use labels and that works as an alternative in this specific case.

This was also the only issue I've found so far while compiling Mono with clang-cl, awesome job Reid & co. on improving the MS ABI these last couple of months.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@rnk
Copy link
Collaborator

rnk commented Sep 29, 2023

Related test case, support for $ in Intel style assembly: https://gcc.godbolt.org/z/8Mz97hYre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants