Conversation

Jarkko Sakkinen

Edited 2 days ago
Can you specify calling convention for assembly (with asm, global_asm etc.)? I mean things like stdcall and cdecl in C and GCC...

I could not find anything and it'd be a huge limitation...

#rust #assembly
2
2
1

@jarkko Not sure what you mean...

There are no functions in asm, so no calling conventions for them.

Maybe look at naked function which have recently been stabilized.

1
0
0
@diondokter

[I edited the message had to think a bit what I meant.]

OK so, this would stdcall in C:

int __attribute__((__stdcall__)) foo() { asm(" ...

This would be naked stdcall

__attribute__((__naked__)) int __attribute__((__stdcall__)) foo() { asm(" ...

So you're correct saying that in naked version you do what you want but the difference is that you're telling GCC that "I will use stdcall". This makes the function compile equally well in Linux and Windows.

GCC won't create epilogue and prologue for you but it will make the assumptions based on stdcall how you've organized the function from callers perspective. I don't know how to do this in Rust.
1
0
0

@jarkko So you want a normal function with the stdcall abi?

Can't you just do:

```rust
extern "stdcall" fn foo() {
// Whatever... (including inline assembly)
}
```

1
0
0
@liiwi OK so there is clobber_api(), which is new to me but I have no idea if that can be used with naked...
0
0
0
@diondokter I can try this and share the results :-) I have to say that I don't know but I'll test this thanks.
1
0
0