Calling Global Constructors: Difference between revisions

m
This wiki has no AT&T assembly syntax high-lighting
[unchecked revision][unchecked revision]
m (It's not possible to split .size into multiple files)
m (This wiki has no AT&T assembly syntax high-lighting)
Line 79:
It is very simple to implement this under x86. You simply have to define the header of two functions in <tt>crti.o</tt> and the footer in <tt>crtn.o</tt> and use these objects in your C library or kernel. You can then simply call <tt>_init</tt> to perform the initialization tasks and call <tt>_fini</tt> to perform the termination tasks (normally done from a <tt>crt0.o</tt> or <tt>my-kernel-boot-object.o</tt>).
 
<pre>
<source lang="asm">
/* x86 crti.s */
.section .init
Line 96:
movl %esp, %ebp
/* gcc will nicely put the contents of crtbegin.o's .fini section here. */
</sourcepre>
 
<pre>
<source lang="asm">
/* x86 crtn.s */
.section .init
Line 109:
popl %ebp
ret
</sourcepre>
 
== x86_64 (64-bit) ==
Line 115:
The system ABI on x86_64 is similar to its 32-bit counterpart and we also just need to provide function headers and function footers and the compiler will insert the rest of the <tt>_init</tt> and <tt>_fini</tt> functions through <tt>crtbegin.o</tt> and <tt>crtend.o</tt>.
 
<pre>
<source lang="asm">
/* x86_64 crti.s */
.section .init
Line 132:
movq %rsp, %rbp
/* gcc will nicely put the contents of crtbegin.o's .fini section here. */
</sourcepre>
 
<pre>
<source lang="asm">
/* x86_64 crtn.s */
.section .init
Line 145:
popq %rbp
ret
</sourcepre>
 
== ARM (BPABI) ==
Anonymous user