README revision 1.4
11.2SjoergIntroduction 21.2Sjoerg 31.2SjoergThis document covers the native NetBSD compiler runtime. The full support 41.2Sjoergfor the native runtime is enabled by setting USE_COMPILERCRTSTUFF to no 51.2Sjoergin bsd.own.mk. 61.2Sjoerg 71.2SjoergMachine independent sources can be found in common. The crtbegin.c in 81.2Sjoergthat directory is a useful template for deriving compact assembler 91.2Sjoergversions. That is preferable to decouple the result from changes in the 101.2Sjoergcompiler logic. 111.2Sjoerg 121.2SjoergA new platform should provide the following content in 131.2Sjoergarch/${MACHINE_ARCH} or arch/${MACHINE_CPU}: 141.4Smartin- Makefile.inc: provides ELFSIZE corresponding to 32/64bit file format. 151.4Smartin If using the common C code instead of crtbegin.S also provide a -I option 161.4Smartin to find crtbegin.h in your arch subdir. 171.2Sjoerg- crt0.S: provides setup code and the call to __start. 181.4Smartin- crtbegin.S or crtbegin.h: see below 191.2Sjoerg- crtend.S: see below, most likely just a copy of an existing architecture 201.2Sjoerg- crti.S: prefix part of .init/.fini sections, i.e. to ensure stack alignment 211.3Smartin- crtn.S: suffix part of the .init/.fini sections, i.e. return to caller. 221.2Sjoerg 231.2Sjoerg 241.1SjoergOverview of the common runtime support 251.1Sjoerg 261.1SjoergThe common runtime support contains two modules, crtbegin and crtend. 271.1Sjoergcrtbegin is linked before all other object files of the program or 281.1Sjoergdynamic library, crtend after all other object files. They frame the 291.1Sjoerglists of constructors, destructors, Java types and exception handling frames. 301.1Sjoerg 311.1SjoergIf done correctly, crtend contains no code and is therefore position 321.1Sjoergindependent. crtendS.o is therefore just a link to crtend.o. 331.1Sjoerg 341.1Sjoergcrtbegin should be position-independent code. crtbeginT.o doesn't have 351.1Sjoergto be PIC as it is statically linked. The overhead is generally not 361.1Sjoergworth the trouble though. 371.1Sjoerg 381.1Sjoerg 391.1SjoergSection types: 401.1Sjoerg.ctor: writeable 411.1Sjoerg.dtor: writeable 421.1Sjoerg.eh_frame: read-only if platform allows mixing read-only and read-write 431.1Sjoergsections. This is supported by GNU ld. 441.1Sjoerg.jcr: writeable 451.1Sjoerg.init: executable 461.1Sjoerg.fini: executable 471.1Sjoerg 481.1Sjoerg 491.1SjoergNon-local symbols: 501.1Sjoerg 511.1SjoergWeak references: 521.1Sjoerg- _Jv_RegisterClasses, 531.1Sjoerg- __cxa_finalize (crtbeginS.o) 541.1Sjoerg- __deregister_frame_info 551.1Sjoerg- __register_frame_info 561.1Sjoerg 571.1SjoergHidden: 581.1Sjoerg- __dso_handle: pointer to self for crtbeginS.o, NULL otherwise. 591.1Sjoerg- __CTOR_LIST_END__ 601.1Sjoerg 611.1Sjoerg 621.1SjoergInitialisation (called from .init): 631.1Sjoerg 641.1Sjoerg1. Check that the init code hasn't started already, otherwise bail out. 651.1Sjoerg2. If __register_frame_info is NULL, skip to 4 661.1Sjoerg3. Call __register_frame_info with start of .eh_frame as first argument 671.1Sjoerg and a data object of at least 8 pointers as second argument. 681.1Sjoerg4: If _Jv_RegisterClasses is NULL, skip to 6 691.1Sjoerg5: Call _Jv_RegisterClasses with the first pointer of the .jcr section 701.1Sjoerg as argument. 711.1Sjoerg6: Iterate from the end of the .ctor section to the start. Skip the 721.1Sjoerg terminating NULL and stop when reaching the starting (void *)-1 element. 731.1Sjoerg Call the pointers as void (*)(void) functions. 741.1Sjoerg 751.1Sjoerg 761.1SjoergDeinitialisation (called from .fini): 771.1Sjoerg 781.1Sjoerg1. Check if the init code has already started, otherwise bail out. 791.1Sjoerg2. If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4. 801.1Sjoerg3. Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO) 811.1Sjoerg as first argument. 821.1Sjoerg4. Iterate from the start of the .dtor section to the send. Skip the 831.1Sjoerg initial (void *)-1 and stop when reaching the terminating NULL element. 841.1Sjoerg Call the pointers as void (*)(void) functions. 851.1Sjoerg5. If __deregister_frame_info is NULL, return. 861.1Sjoerg6. Call __deregister_frame_info with the start of .eh_frame as the argument. 871.4Smartin 881.4Smartin 891.4SmartinSince most of this can easily be done in C code, instead of providing a 901.4Smartincrtbegin.S you can also chose to use the generic C implementation. Provide 911.4Smartina crtbegin.h file instead of crtbegin.S. In there put inline assembler 921.4Smartinstubs (mostly copied from some other arch) and implement calls to the 931.4Smartinhelper functions __do_global_ctors_aux/__do_global_dtors_aux. 94