calling-convention

Difference in data alignment in struct vs parameter?

余生颓废 提交于 2020-01-06 13:09:12
问题 Given the following code: typedef struct tagRECT { int left; int top; int right; int bottom; } RECT; extern int Func(RECT *a, int b, char *c, int d, char e, long f, int g, int h, int i, int j); int main() { } void gui() { RECT x = {4, 5, 6, 7}; Func(&x, 1, 0, 3, 4, 5, 6, 7, 8, 9); } This is the assembly generated gcc x86_64 presumably on linux (I used compiler explorer). main: mov eax, 0 ret gui: push rbp mov rbp, rsp sub rsp, 16 ; RECT x assignment mov DWORD PTR [rbp-16], 4 mov DWORD PTR

Conflicting type attributes specified for virtual destructor

懵懂的女人 提交于 2020-01-05 01:52:34
问题 The following extract was previously compiling under Borland C++, MSVC and OpenWatcom: class aaa { virtual _fastcall ~aaa(); }; class bbb:public aaa { }; It doesn't compile under gcc/g++ (MinGW 4.8.0). Error: probz.cpp:7:7: error: conflicting type attributes specified for 'virtual bbb::~bbb()' class bbb:public aaa { ^ probz.cpp:3:20: error: overriding 'virtual aaa::~aaa()' virtual _fastcall ~aaa()=0;///can't be abstract ^ Obviously, there is no bbb::~bbb()! EDIT The actual class hierarchy is

Why does Rust have both call by value and call by reference?

ぐ巨炮叔叔 提交于 2020-01-04 01:49:13
问题 Some languages, like Haskell, make no distinction between pass-by-value and pass-by-reference. The compiler can then approximately choose the most efficient calling convention with a heuristic. One example heuristic would be for the Linux x64 ABI: if the size of parameter is greater than 16 bytes, pass a pointer to the stack otherwise pass the value in registers. What is the advantage of keeping both notions of pass-by-value and pass-by-reference (non-mutable of course) in Rust and forcing

Calling C function which takes no parameters with parameters

时间秒杀一切 提交于 2020-01-02 06:54:10
问题 I have some weird question about probably undefined behavior between C calling convention and 64/32 bits compilation. First here is my code: int f() { return 0; } int main() { int x = 42; return f(x); } As you can see I am calling f with an argument while f takes no parameters. My first question was does this argument is really given to f while calling it. The mysterious lines After a little objdump I obtained curious results. While passing x as argument of f: 00000000004004b6 <f>: 4004b6: 55

X86-64 NASM calling extern c functions

…衆ロ難τιáo~ 提交于 2019-12-31 07:54:26
问题 Im very new to assembly but know a bit of c. Im playing around with extern function calls like extern _printf str db "Hello", 0 push str call _printf but cant find any tutorials using extern functions except scanf and printf. For example strcmp? How can i call strcmp in my case? 回答1: Here is my answer. It is specific to x86-64 though. Please know that when pushing arguments to a function, you usually place the first 6 in registers rdi , rsi , rdx , rcx , r8 , and r9 . The rest get pushed to

X86-64 NASM calling extern c functions

混江龙づ霸主 提交于 2019-12-31 07:54:04
问题 Im very new to assembly but know a bit of c. Im playing around with extern function calls like extern _printf str db "Hello", 0 push str call _printf but cant find any tutorials using extern functions except scanf and printf. For example strcmp? How can i call strcmp in my case? 回答1: Here is my answer. It is specific to x86-64 though. Please know that when pushing arguments to a function, you usually place the first 6 in registers rdi , rsi , rdx , rcx , r8 , and r9 . The rest get pushed to

What registers must be preserved by an x86 function?

心不动则不痛 提交于 2019-12-30 08:02:52
问题 I'm writing a function in x86 assembly that should be callable from c code, and I'm wondering which registers i have to restore before i return to the caller. Currently I'm only restoring esp and ebp , while the return value is in eax . Are there any other registers I should be concerned about, or could I leave whatever pleases me in them? 回答1: Using Microsoft's 32 bit ABI ( cdecl or stdcall or other calling conventions), EAX , EDX and ECX are scratch registers (call clobbered). The other

What registers must be preserved by an x86 function?

别等时光非礼了梦想. 提交于 2019-12-30 08:01:26
问题 I'm writing a function in x86 assembly that should be callable from c code, and I'm wondering which registers i have to restore before i return to the caller. Currently I'm only restoring esp and ebp , while the return value is in eax . Are there any other registers I should be concerned about, or could I leave whatever pleases me in them? 回答1: Using Microsoft's 32 bit ABI ( cdecl or stdcall or other calling conventions), EAX , EDX and ECX are scratch registers (call clobbered). The other

Could someone explain __declspec(naked) please?

巧了我就是萌 提交于 2019-12-30 06:15:13
问题 I'm looking into porting a script engine written for Windows to Linux; it's for Winamp's visualization platform AVS. I'm not sure if it's even possible at the moment. From what I can tell the code is taking the addresses of the C functions nseel_asm_atan and nseel_asm_atan_end and storing them inside a table that it can reference during code execution. I've looked at MS's documentation, but I'm unsure what __declspec(naked) really does. What is prolog and epilog code mentioned in the

Calling convention for function returning struct

老子叫甜甜 提交于 2019-12-29 06:02:46
问题 For the following C code: struct _AStruct { int a; int b; float c; float d; int e; }; typedef struct _AStruct AStruct; AStruct test_callee5(); void test_caller5(); void test_caller5() { AStruct g = test_callee5(); AStruct h = test_callee5(); } I get the following disassembly for Win32: _test_caller5: 00000000: lea eax,[esp-14h] 00000004: sub esp,14h 00000007: push eax 00000008: call _test_callee5 0000000D: lea ecx,[esp+4] 00000011: push ecx 00000012: call _test_callee5 00000017: add esp,1Ch