1Introduction 2 3This document covers the native NetBSD compiler runtime. The full support 4for the native runtime is enabled by setting USE_COMPILERCRTSTUFF to no 5in bsd.own.mk. 6 7Machine independent sources can be found in common. The crtbegin.c in 8that directory is a useful template for deriving compact assembler 9versions. That is preferable to decouple the result from changes in the 10compiler logic. 11 12A new platform should provide the following content in 13arch/${MACHINE_ARCH} or arch/${MACHINE_CPU}: 14- Makefile.inc: provides ELFSIZE corresponding to 32/64bit file format. 15 If using the common C code instead of crtbegin.S also provide a -I option 16 to find crtbegin.h in your arch subdir. 17- crt0.S: provides setup code and the call to ___start. 18- crtbegin.S or crtbegin.h: see below 19- crtend.S: see below, most likely just a copy of an existing architecture 20- crti.S: prefix part of .init/.fini sections, i.e. to ensure stack alignment 21- crtn.S: suffix part of the .init/.fini sections, i.e. return to caller. 22 23 24Overview of the common runtime support 25 26The common runtime support contains two modules, crtbegin and crtend. 27crtbegin is linked before all other object files of the program or 28dynamic library, crtend after all other object files. They frame the 29lists of constructors, destructors, Java types and exception handling frames. 30 31If done correctly, crtend contains no code and is therefore position 32independent. crtendS.o is therefore just a link to crtend.o. 33 34crtbegin should be position-independent code. crtbeginT.o doesn't have 35to be PIC as it is statically linked. The overhead is generally not 36worth the trouble though. 37 38 39Section types: 40.ctor: writeable 41.dtor: writeable 42.eh_frame: read-only if platform allows mixing read-only and read-write 43sections. This is supported by GNU ld. 44.jcr: writeable 45.init: executable 46.fini: executable 47 48 49Non-local symbols: 50 51Weak references: 52- _Jv_RegisterClasses, 53- __cxa_finalize (crtbeginS.o) 54- __deregister_frame_info 55- __register_frame_info 56 57Hidden: 58- __dso_handle: pointer to self for crtbeginS.o, NULL otherwise. 59- __CTOR_LIST_END__ 60 61 62Initialisation (called from .init): 63 641. Check that the init code hasn't started already, otherwise bail out. 652. If __register_frame_info is NULL, skip to 4 663. Call __register_frame_info with start of .eh_frame as first argument 67 and a data object of at least 8 pointers as second argument. 684: If _Jv_RegisterClasses is NULL, skip to 6 695: Call _Jv_RegisterClasses with the first pointer of the .jcr section 70 as argument. 716: Iterate from the end of the .ctor section to the start. Skip the 72 terminating NULL and stop when reaching the starting (void *)-1 element. 73 Call the pointers as void (*)(void) functions. 74 75 76Deinitialisation (called from .fini): 77 781. Check if the init code has already started, otherwise bail out. 792. If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4. 803. Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO) 81 as first argument. 824. Iterate from the start of the .dtor section to the send. Skip the 83 initial (void *)-1 and stop when reaching the terminating NULL element. 84 Call the pointers as void (*)(void) functions. 855. If __deregister_frame_info is NULL, return. 866. Call __deregister_frame_info with the start of .eh_frame as the argument. 87 88 89Since most of this can easily be done in C code, instead of providing a 90crtbegin.S you can also chose to use the generic C implementation. Provide 91a crtbegin.h file instead of crtbegin.S. In there put inline assembler 92stubs (mostly copied from some other arch) and implement calls to the 93helper functions __do_global_ctors_aux/__do_global_dtors_aux. 94