Mercurial > pub > dyncall > dyncall
diff doc/disas_examples/x86.stdcall.disas @ 497:cb19b2fe2422
- more disas examples to check behaviour of passing C++ non-trivial aggregates by value; they all behave the same, calling the copy ctor first, passing a pointer then
author | Tassilo Philipp |
---|---|
date | Wed, 23 Mar 2022 15:24:31 +0100 |
parents | 4e84d6faed54 |
children | fc614cb865c6 |
line wrap: on
line diff
--- a/doc/disas_examples/x86.stdcall.disas Mon Mar 21 18:11:38 2022 +0100 +++ b/doc/disas_examples/x86.stdcall.disas Wed Mar 23 15:24:31 2022 +0100 @@ -166,5 +166,100 @@ +; ---------- C++ trivial and non-trivial aggrs passed to C funcs ----------> +; +; struct Trivial { int a; }; +; struct NonTrivial { +; int a; +; __attribute__((stdcall)) NonTrivial() : a(0) {} +; __attribute__((stdcall)) NonTrivial(const NonTrivial& rhs) : a(rhs.a) { } +; }; +; +; extern "C" { +; +; void __attribute__((stdcall)) f1(struct Trivial s) { } +; void __attribute__((stdcall)) f2(struct NonTrivial s) { } +; +; void __attribute__((stdcall)) f() +; { +; struct Trivial t; +; struct NonTrivial n; +; int a=1; +; a += 123; +; f1(t); +; a -= 123; +; f2(n); +; a -= 12; +; } +; } + + + +; output from alpine_linux-3.11.3-x86 w/ gcc 9.2.0 + +00001215 <f1>: + 1215: 55 push %ebp + 1216: 89 e5 mov %esp,%ebp + 1218: e8 f0 ff ff ff call 120d <__x86.get_pc_thunk.ax> + 121d: 05 af 2d 00 00 add $0x2daf,%eax + 1222: 90 nop + 1223: 5d pop %ebp + 1224: c2 04 00 ret $0x4 + +00001227 <f2>: + 1227: 55 push %ebp + 1228: 89 e5 mov %esp,%ebp + 122a: e8 de ff ff ff call 120d <__x86.get_pc_thunk.ax> + 122f: 05 9d 2d 00 00 add $0x2d9d,%eax + 1234: 90 nop + 1235: 5d pop %ebp + 1236: c2 04 00 ret $0x4 + +00001239 <f>: + 1239: 55 push %ebp ; + 123a: 89 e5 mov %esp,%ebp ; + 123c: 83 ec 28 sub $0x28,%esp ; + 123f: e8 c9 ff ff ff call 120d <__x86.get_pc_thunk.ax> ; + 1244: 05 88 2d 00 00 add $0x2d88,%eax ; + 1249: 65 a1 14 00 00 00 mov %gs:0x14,%eax ; + 124f: 89 45 f4 mov %eax,-0xc(%ebp) ; + 1252: 31 c0 xor %eax,%eax ; + 1254: 83 ec 0c sub $0xc,%esp ; + 1257: 8d 45 e8 lea -0x18(%ebp),%eax ; + 125a: 50 push %eax ; + 125b: e8 6e 00 00 00 call 12ce <_ZN10NonTrivialC1Ev> ; NonTrivial::NonTrivial() / ctor + 1260: 83 c4 0c add $0xc,%esp ; + 1263: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) ; + 126a: 83 45 f0 7b addl $0x7b,-0x10(%ebp) ; + 126e: 83 ec 0c sub $0xc,%esp ; + 1271: ff 75 e4 pushl -0x1c(%ebp) ; + 1274: e8 9c ff ff ff call 1215 <f1> ; call f1(struct Trivial) + 1279: 83 c4 0c add $0xc,%esp ; + 127c: 83 6d f0 7b subl $0x7b,-0x10(%ebp) ; + 1280: 83 ec 08 sub $0x8,%esp ; + 1283: 8d 45 e8 lea -0x18(%ebp),%eax ; | | ptr to n + 1286: 50 push %eax ; | / + 1287: 8d 45 ec lea -0x14(%ebp),%eax ; | \ + 128a: 50 push %eax ; | copy n | ptr to dest of copy of n + 128b: e8 5a 00 00 00 call 12ea <_ZN10NonTrivialC1ERKS_> ; | NonTrivial::NonTrivial(const NonTrivial&) / copy ctor + 1290: 83 c4 08 add $0x8,%esp ; + 1293: 83 ec 0c sub $0xc,%esp ; + 1296: 8d 45 ec lea -0x14(%ebp),%eax ; | + 1299: 50 push %eax ; | f2 arg 0 (ptr to copy of struct NonTrivial), via ptr as non-trivial + 129a: e8 88 ff ff ff call 1227 <f2> ; call f2(struct NonTrivial) + 129f: 83 c4 0c add $0xc,%esp ; + 12a2: 83 6d f0 0c subl $0xc,-0x10(%ebp) ; + 12a6: 90 nop ; + 12a7: 8b 45 f4 mov -0xc(%ebp),%eax ; + 12aa: 65 33 05 14 00 00 00 xor %gs:0x14,%eax ; + 12b1: 74 05 je 12b8 <f+0x7f> ; + 12b3: e8 4e 00 00 00 call 1306 <__stack_chk_fail_local> ; + 12b8: c9 leave ; + 12b9: c3 ret ; + + ; ... snip, removed code of ctor and copy ctor ... + + + ; vim: ft=asm