Mercurial > pub > dyncall > dyncall
diff doc/disas_examples/x86.stdcall.disas @ 499:fc614cb865c6
- doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
author | Tassilo Philipp |
---|---|
date | Mon, 04 Apr 2022 15:50:52 +0200 |
parents | cb19b2fe2422 |
children |
line wrap: on
line diff
--- a/doc/disas_examples/x86.stdcall.disas Wed Mar 23 15:33:09 2022 +0100 +++ b/doc/disas_examples/x86.stdcall.disas Mon Apr 04 15:50:52 2022 +0200 @@ -261,5 +261,85 @@ +; ---------- C++ trivial and non-trivial aggrs as return values ----------> +; +; struct Trivial { int a; }; +; struct NonTrivial { +; int a; +; __attribute__((stdcall)) NonTrivial() : a(0) {} +; __attribute__((stdcall)) NonTrivial(const NonTrivial& rhs) : a(rhs.a) { } +; }; +; +; extern "C" { +; struct Trivial __attribute__((stdcall)) f1() { return Trivial(); } +; } +; +; struct NonTrivial __attribute__((stdcall)) f2() { return NonTrivial(); } +; +; extern "C" { +; void __attribute__((stdcall)) f() +; { +; int a=1; +; a += 123; +; struct Trivial t = f1(); +; a -= 123; +; struct NonTrivial n = f2(); +; a -= 12; +; } +; } + + + +; output from alpine_linux-3.11.3-x86 w/ gcc 9.2.0 (w/ -O0 --no-stack-protector for simplicity) + +00001205 <f1>: + 1205: 55 push %ebp ; | prolog + 1206: 89 e5 mov %esp,%ebp ; | + 1208: e8 f0 ff ff ff call 11fd <__x86.get_pc_thunk.ax> ; + 120d: 05 c3 2d 00 00 add $0x2dc3,%eax ; + 1212: 8b 45 08 mov 0x8(%ebp),%eax ; fetch ptr to retval space -> eax + 1215: c7 00 00 00 00 00 movl $0x0,(%eax) ; write retval + 121b: 8b 45 08 mov 0x8(%ebp),%eax ; re-fetch ptr to retval space -> eax, to return it in eax (a bit pointless) + 121e: 5d pop %ebp ; | + 121f: c2 04 00 ret $0x4 ; | epilog + +00001222 <_Z2f2v>: + 1222: 55 push %ebp + 1223: 89 e5 mov %esp,%ebp + 1225: 83 ec 08 sub $0x8,%esp + 1228: e8 d0 ff ff ff call 11fd <__x86.get_pc_thunk.ax> + 122d: 05 a3 2d 00 00 add $0x2da3,%eax + 1232: 83 ec 0c sub $0xc,%esp + 1235: ff 75 08 pushl 0x8(%ebp) + 1238: e8 65 00 00 00 call 12a2 <_ZN10NonTrivialC1Ev> + 123d: 83 c4 0c add $0xc,%esp + 1240: 8b 45 08 mov 0x8(%ebp),%eax + 1243: c9 leave + 1244: c2 04 00 ret $0x4 + +00001247 <f>: + 1247: 55 push %ebp ; + 1248: 89 e5 mov %esp,%ebp ; + 124a: 83 ec 18 sub $0x18,%esp ; + 124d: e8 ab ff ff ff call 11fd <__x86.get_pc_thunk.ax> ; + 1252: 05 7e 2d 00 00 add $0x2d7e,%eax ; + 1257: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%ebp) ; a = 1 + 125e: 83 45 f4 7b addl $0x7b,-0xc(%ebp) ; a += 123 + 1262: 8d 45 f0 lea -0x10(%ebp),%eax ; ptr to space (top of stack) to hold aggr retval -> eax ... + 1265: 50 push %eax ; ... as hidden first arg + 1266: e8 9a ff ff ff call 1205 <f1> ; call f1() + 126b: 83 6d f4 7b subl $0x7b,-0xc(%ebp) ; a -= 123 + 126f: 8d 45 ec lea -0x14(%ebp),%eax ; ptr to space to hold aggr retval -> eax ... + 1272: 83 ec 0c sub $0xc,%esp ; grow stack by 12 + 1275: 50 push %eax ; ... as hidden first arg + 1276: e8 a7 ff ff ff call 1222 <_Z2f2v> ; call f2() + 127b: 83 c4 0c add $0xc,%esp ; shrink stack back by 12 + 127e: 83 6d f4 0c subl $0xc,-0xc(%ebp) ; a -= 12 + 1282: 90 nop ; + 1283: c9 leave ; + 1284: c3 ret ; + + + ; vim: ft=asm