Mercurial > pub > dyncall > dyncall
diff doc/disas_examples/x86.fastcall_gnu.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 | 79e76734bb5c |
children | fc614cb865c6 |
line wrap: on
line diff
--- a/doc/disas_examples/x86.fastcall_gnu.disas Mon Mar 21 18:11:38 2022 +0100 +++ b/doc/disas_examples/x86.fastcall_gnu.disas Wed Mar 23 15:24:31 2022 +0100 @@ -279,5 +279,95 @@ +; ---------- C++ trivial and non-trivial aggrs passed to C funcs ----------> +; +; struct Trivial { int a; }; +; struct NonTrivial { +; int a; +; __attribute__((fastcall)) NonTrivial() : a(0) {} +; __attribute__((fastcall)) NonTrivial(const NonTrivial& rhs) : a(rhs.a) { } +; }; +; +; extern "C" { +; +; void __attribute__((fastcall)) f1(struct Trivial s) { } +; void __attribute__((fastcall)) f2(struct NonTrivial s) { } +; +; void __attribute__((fastcall)) 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: 83 ec 04 sub $0x4,%esp + 122d: e8 db ff ff ff call 120d <__x86.get_pc_thunk.ax> + 1232: 05 9a 2d 00 00 add $0x2d9a,%eax + 1237: 89 4d fc mov %ecx,-0x4(%ebp) + 123a: 90 nop + 123b: c9 leave + 123c: c3 ret + +0000123d <f>: + 123d: 55 push %ebp ; + 123e: 89 e5 mov %esp,%ebp ; + 1240: 83 ec 28 sub $0x28,%esp ; + 1243: e8 c5 ff ff ff call 120d <__x86.get_pc_thunk.ax> ; + 1248: 05 84 2d 00 00 add $0x2d84,%eax ; + 124d: 65 a1 14 00 00 00 mov %gs:0x14,%eax ; + 1253: 89 45 f4 mov %eax,-0xc(%ebp) ; + 1256: 31 c0 xor %eax,%eax ; + 1258: 8d 45 e8 lea -0x18(%ebp),%eax ; + 125b: 89 c1 mov %eax,%ecx ; + 125d: e8 60 00 00 00 call 12c2 <_ZN10NonTrivialC1Ev> ; NonTrivial::NonTrivial() / ctor + 1262: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) ; + 1269: 83 45 f0 7b addl $0x7b,-0x10(%ebp) ; + 126d: 83 ec 0c sub $0xc,%esp ; + 1270: ff 75 e4 pushl -0x1c(%ebp) ; + 1273: e8 9d ff ff ff call 1215 <f1> ; call f1(struct Trivial) + 1278: 83 c4 0c add $0xc,%esp ; + 127b: 83 6d f0 7b subl $0x7b,-0x10(%ebp) ; + 127f: 8d 55 e8 lea -0x18(%ebp),%edx ; | ptr to n + 1282: 8d 45 ec lea -0x14(%ebp),%eax ; | | + 1285: 89 c1 mov %eax,%ecx ; | copy n | ptr to dest of copy of n + 1287: e8 56 00 00 00 call 12e2 <_ZN10NonTrivialC1ERKS_> ; / NonTrivial::NonTrivial(const NonTrivial&) / copy ctor + 128c: 8d 45 ec lea -0x14(%ebp),%eax ; \ + 128f: 89 c1 mov %eax,%ecx ; | f2 arg 0 (ptr to copy of struct NonTrivial), via ptr as non-trivial + 1291: e8 91 ff ff ff call 1227 <f2> ; call f2(struct NonTrivial) + 1296: 83 6d f0 0c subl $0xc,-0x10(%ebp) ; + 129a: 90 nop ; + 129b: 8b 45 f4 mov -0xc(%ebp),%eax ; + 129e: 65 33 05 14 00 00 00 xor %gs:0x14,%eax ; + 12a5: 74 05 je 12ac <f+0x6f> ; + 12a7: e8 59 00 00 00 call 1305 <__stack_chk_fail_local> ; + 12ac: c9 leave ; + 12ad: c3 ret ; + + ; ... snip, removed code of ctor and copy ctor ... + + + ; vim: ft=asm