15b92de54SjoergIntroduction 25b92de54Sjoerg 3*61731496SjoergThis document covers the native NetBSD compiler runtime. 45b92de54Sjoerg 55b92de54SjoergMachine independent sources can be found in common. The crtbegin.c in 65b92de54Sjoergthat directory is a useful template for deriving compact assembler 75b92de54Sjoergversions. That is preferable to decouple the result from changes in the 85b92de54Sjoergcompiler logic. 95b92de54Sjoerg 105b92de54SjoergA new platform should provide the following content in 115b92de54Sjoergarch/${MACHINE_ARCH} or arch/${MACHINE_CPU}: 1214d55ae5Smartin- Makefile.inc: provides ELFSIZE corresponding to 32/64bit file format. 1314d55ae5Smartin If using the common C code instead of crtbegin.S also provide a -I option 1414d55ae5Smartin to find crtbegin.h in your arch subdir. 159a641fd1Sskrll- crt0.S: provides setup code and the call to ___start. 1614d55ae5Smartin- crtbegin.S or crtbegin.h: see below 175b92de54Sjoerg- crtend.S: see below, most likely just a copy of an existing architecture 185b92de54Sjoerg- crti.S: prefix part of .init/.fini sections, i.e. to ensure stack alignment 1936d44ff5Smartin- crtn.S: suffix part of the .init/.fini sections, i.e. return to caller. 205b92de54Sjoerg 215b92de54Sjoerg 2201bc9d50SjoergOverview of the common runtime support 2301bc9d50Sjoerg 2401bc9d50SjoergThe common runtime support contains two modules, crtbegin and crtend. 2501bc9d50Sjoergcrtbegin is linked before all other object files of the program or 2601bc9d50Sjoergdynamic library, crtend after all other object files. They frame the 2701bc9d50Sjoerglists of constructors, destructors, Java types and exception handling frames. 2801bc9d50Sjoerg 2901bc9d50SjoergIf done correctly, crtend contains no code and is therefore position 3001bc9d50Sjoergindependent. crtendS.o is therefore just a link to crtend.o. 3101bc9d50Sjoerg 3201bc9d50Sjoergcrtbegin should be position-independent code. crtbeginT.o doesn't have 3301bc9d50Sjoergto be PIC as it is statically linked. The overhead is generally not 3401bc9d50Sjoergworth the trouble though. 3501bc9d50Sjoerg 3601bc9d50Sjoerg 3701bc9d50SjoergSection types: 3801bc9d50Sjoerg.ctor: writeable 3901bc9d50Sjoerg.dtor: writeable 4001bc9d50Sjoerg.eh_frame: read-only if platform allows mixing read-only and read-write 4101bc9d50Sjoergsections. This is supported by GNU ld. 4201bc9d50Sjoerg.jcr: writeable 4301bc9d50Sjoerg.init: executable 4401bc9d50Sjoerg.fini: executable 4501bc9d50Sjoerg 4601bc9d50Sjoerg 4701bc9d50SjoergNon-local symbols: 4801bc9d50Sjoerg 4901bc9d50SjoergWeak references: 5001bc9d50Sjoerg- _Jv_RegisterClasses, 5101bc9d50Sjoerg- __cxa_finalize (crtbeginS.o) 5201bc9d50Sjoerg- __deregister_frame_info 5301bc9d50Sjoerg- __register_frame_info 5401bc9d50Sjoerg 5501bc9d50SjoergHidden: 5601bc9d50Sjoerg- __dso_handle: pointer to self for crtbeginS.o, NULL otherwise. 5701bc9d50Sjoerg- __CTOR_LIST_END__ 5801bc9d50Sjoerg 5901bc9d50Sjoerg 6001bc9d50SjoergInitialisation (called from .init): 6101bc9d50Sjoerg 6201bc9d50Sjoerg1. Check that the init code hasn't started already, otherwise bail out. 6301bc9d50Sjoerg2. If __register_frame_info is NULL, skip to 4 6401bc9d50Sjoerg3. Call __register_frame_info with start of .eh_frame as first argument 6501bc9d50Sjoerg and a data object of at least 8 pointers as second argument. 6601bc9d50Sjoerg4: If _Jv_RegisterClasses is NULL, skip to 6 6701bc9d50Sjoerg5: Call _Jv_RegisterClasses with the first pointer of the .jcr section 6801bc9d50Sjoerg as argument. 6901bc9d50Sjoerg6: Iterate from the end of the .ctor section to the start. Skip the 7001bc9d50Sjoerg terminating NULL and stop when reaching the starting (void *)-1 element. 7101bc9d50Sjoerg Call the pointers as void (*)(void) functions. 7201bc9d50Sjoerg 7301bc9d50Sjoerg 7401bc9d50SjoergDeinitialisation (called from .fini): 7501bc9d50Sjoerg 7601bc9d50Sjoerg1. Check if the init code has already started, otherwise bail out. 7701bc9d50Sjoerg2. If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4. 7801bc9d50Sjoerg3. Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO) 7901bc9d50Sjoerg as first argument. 8001bc9d50Sjoerg4. Iterate from the start of the .dtor section to the send. Skip the 8101bc9d50Sjoerg initial (void *)-1 and stop when reaching the terminating NULL element. 8201bc9d50Sjoerg Call the pointers as void (*)(void) functions. 8301bc9d50Sjoerg5. If __deregister_frame_info is NULL, return. 8401bc9d50Sjoerg6. Call __deregister_frame_info with the start of .eh_frame as the argument. 8514d55ae5Smartin 8614d55ae5Smartin 8714d55ae5SmartinSince most of this can easily be done in C code, instead of providing a 8814d55ae5Smartincrtbegin.S you can also chose to use the generic C implementation. Provide 8914d55ae5Smartina crtbegin.h file instead of crtbegin.S. In there put inline assembler 9014d55ae5Smartinstubs (mostly copied from some other arch) and implement calls to the 9114d55ae5Smartinhelper functions __do_global_ctors_aux/__do_global_dtors_aux. 92