Mercurial > pub > dyncall > dyncall
comparison 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 |
comparison
equal
deleted
inserted
replaced
498:fd9ba3a6d348 | 499:fc614cb865c6 |
---|---|
259 | 259 |
260 ; ... snip, removed code of ctor and copy ctor ... | 260 ; ... snip, removed code of ctor and copy ctor ... |
261 | 261 |
262 | 262 |
263 | 263 |
264 ; ---------- C++ trivial and non-trivial aggrs as return values ----------> | |
265 ; | |
266 ; struct Trivial { int a; }; | |
267 ; struct NonTrivial { | |
268 ; int a; | |
269 ; __attribute__((stdcall)) NonTrivial() : a(0) {} | |
270 ; __attribute__((stdcall)) NonTrivial(const NonTrivial& rhs) : a(rhs.a) { } | |
271 ; }; | |
272 ; | |
273 ; extern "C" { | |
274 ; struct Trivial __attribute__((stdcall)) f1() { return Trivial(); } | |
275 ; } | |
276 ; | |
277 ; struct NonTrivial __attribute__((stdcall)) f2() { return NonTrivial(); } | |
278 ; | |
279 ; extern "C" { | |
280 ; void __attribute__((stdcall)) f() | |
281 ; { | |
282 ; int a=1; | |
283 ; a += 123; | |
284 ; struct Trivial t = f1(); | |
285 ; a -= 123; | |
286 ; struct NonTrivial n = f2(); | |
287 ; a -= 12; | |
288 ; } | |
289 ; } | |
290 | |
291 | |
292 | |
293 ; output from alpine_linux-3.11.3-x86 w/ gcc 9.2.0 (w/ -O0 --no-stack-protector for simplicity) | |
294 | |
295 00001205 <f1>: | |
296 1205: 55 push %ebp ; | prolog | |
297 1206: 89 e5 mov %esp,%ebp ; | | |
298 1208: e8 f0 ff ff ff call 11fd <__x86.get_pc_thunk.ax> ; | |
299 120d: 05 c3 2d 00 00 add $0x2dc3,%eax ; | |
300 1212: 8b 45 08 mov 0x8(%ebp),%eax ; fetch ptr to retval space -> eax | |
301 1215: c7 00 00 00 00 00 movl $0x0,(%eax) ; write retval | |
302 121b: 8b 45 08 mov 0x8(%ebp),%eax ; re-fetch ptr to retval space -> eax, to return it in eax (a bit pointless) | |
303 121e: 5d pop %ebp ; | | |
304 121f: c2 04 00 ret $0x4 ; | epilog | |
305 | |
306 00001222 <_Z2f2v>: | |
307 1222: 55 push %ebp | |
308 1223: 89 e5 mov %esp,%ebp | |
309 1225: 83 ec 08 sub $0x8,%esp | |
310 1228: e8 d0 ff ff ff call 11fd <__x86.get_pc_thunk.ax> | |
311 122d: 05 a3 2d 00 00 add $0x2da3,%eax | |
312 1232: 83 ec 0c sub $0xc,%esp | |
313 1235: ff 75 08 pushl 0x8(%ebp) | |
314 1238: e8 65 00 00 00 call 12a2 <_ZN10NonTrivialC1Ev> | |
315 123d: 83 c4 0c add $0xc,%esp | |
316 1240: 8b 45 08 mov 0x8(%ebp),%eax | |
317 1243: c9 leave | |
318 1244: c2 04 00 ret $0x4 | |
319 | |
320 00001247 <f>: | |
321 1247: 55 push %ebp ; | |
322 1248: 89 e5 mov %esp,%ebp ; | |
323 124a: 83 ec 18 sub $0x18,%esp ; | |
324 124d: e8 ab ff ff ff call 11fd <__x86.get_pc_thunk.ax> ; | |
325 1252: 05 7e 2d 00 00 add $0x2d7e,%eax ; | |
326 1257: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%ebp) ; a = 1 | |
327 125e: 83 45 f4 7b addl $0x7b,-0xc(%ebp) ; a += 123 | |
328 1262: 8d 45 f0 lea -0x10(%ebp),%eax ; ptr to space (top of stack) to hold aggr retval -> eax ... | |
329 1265: 50 push %eax ; ... as hidden first arg | |
330 1266: e8 9a ff ff ff call 1205 <f1> ; call f1() | |
331 126b: 83 6d f4 7b subl $0x7b,-0xc(%ebp) ; a -= 123 | |
332 126f: 8d 45 ec lea -0x14(%ebp),%eax ; ptr to space to hold aggr retval -> eax ... | |
333 1272: 83 ec 0c sub $0xc,%esp ; grow stack by 12 | |
334 1275: 50 push %eax ; ... as hidden first arg | |
335 1276: e8 a7 ff ff ff call 1222 <_Z2f2v> ; call f2() | |
336 127b: 83 c4 0c add $0xc,%esp ; shrink stack back by 12 | |
337 127e: 83 6d f4 0c subl $0xc,-0xc(%ebp) ; a -= 12 | |
338 1282: 90 nop ; | |
339 1283: c9 leave ; | |
340 1284: c3 ret ; | |
341 | |
342 | |
343 | |
264 ; vim: ft=asm | 344 ; vim: ft=asm |
265 | 345 |