README revision 1.3
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.2Sjoerg- Makefile.inc: provides ELFSIZE corresponding to 32/64bit file format
151.2Sjoerg- crt0.S: provides setup code and the call to __start.
161.2Sjoerg- crtbegin.S: see below
171.2Sjoerg- crtend.S: see below, most likely just a copy of an existing architecture
181.2Sjoerg- crti.S: prefix part of .init/.fini sections, i.e. to ensure stack alignment
191.3Smartin- crtn.S: suffix part of the .init/.fini sections, i.e. return to caller.
201.2Sjoerg
211.2Sjoerg
221.1SjoergOverview of the common runtime support
231.1Sjoerg
241.1SjoergThe common runtime support contains two modules, crtbegin and crtend.
251.1Sjoergcrtbegin is linked before all other object files of the program or
261.1Sjoergdynamic library, crtend after all other object files.  They frame the
271.1Sjoerglists of constructors, destructors, Java types and exception handling frames.
281.1Sjoerg
291.1SjoergIf done correctly, crtend contains no code and is therefore position
301.1Sjoergindependent.  crtendS.o is therefore just a link to crtend.o.
311.1Sjoerg
321.1Sjoergcrtbegin should be position-independent code.  crtbeginT.o doesn't have
331.1Sjoergto be PIC as it is statically linked.  The overhead is generally not
341.1Sjoergworth the trouble though.
351.1Sjoerg
361.1Sjoerg
371.1SjoergSection types:
381.1Sjoerg.ctor: writeable
391.1Sjoerg.dtor: writeable
401.1Sjoerg.eh_frame: read-only if platform allows mixing read-only and read-write
411.1Sjoergsections.  This is supported by GNU ld.
421.1Sjoerg.jcr: writeable
431.1Sjoerg.init: executable
441.1Sjoerg.fini: executable
451.1Sjoerg
461.1Sjoerg
471.1SjoergNon-local symbols:
481.1Sjoerg
491.1SjoergWeak references:
501.1Sjoerg- _Jv_RegisterClasses,
511.1Sjoerg- __cxa_finalize (crtbeginS.o)
521.1Sjoerg- __deregister_frame_info
531.1Sjoerg- __register_frame_info
541.1Sjoerg
551.1SjoergHidden:
561.1Sjoerg- __dso_handle: pointer to self for crtbeginS.o, NULL otherwise.
571.1Sjoerg- __CTOR_LIST_END__
581.1Sjoerg
591.1Sjoerg
601.1SjoergInitialisation (called from .init):
611.1Sjoerg
621.1Sjoerg1.  Check that the init code hasn't started already, otherwise bail out.
631.1Sjoerg2.  If __register_frame_info is NULL, skip to 4
641.1Sjoerg3.  Call __register_frame_info with start of .eh_frame as first argument
651.1Sjoerg    and a data object of at least 8 pointers as second argument.
661.1Sjoerg4:  If _Jv_RegisterClasses is NULL, skip to 6
671.1Sjoerg5:  Call _Jv_RegisterClasses with the first pointer of the .jcr section
681.1Sjoerg    as argument.
691.1Sjoerg6:  Iterate from the end of the .ctor section to the start.  Skip the
701.1Sjoerg    terminating NULL and stop when reaching the starting (void *)-1 element.
711.1Sjoerg    Call the pointers as void (*)(void) functions.
721.1Sjoerg
731.1Sjoerg
741.1SjoergDeinitialisation (called from .fini):
751.1Sjoerg
761.1Sjoerg1.  Check if the init code has already started, otherwise bail out.
771.1Sjoerg2.  If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4.
781.1Sjoerg3.  Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO)
791.1Sjoerg    as first argument.
801.1Sjoerg4.  Iterate from the start of the .dtor section to the send.  Skip the
811.1Sjoerg    initial (void *)-1 and stop when reaching the terminating NULL element.
821.1Sjoerg    Call the pointers as void (*)(void) functions.
831.1Sjoerg5.  If __deregister_frame_info is NULL, return.
841.1Sjoerg6.  Call __deregister_frame_info with the start of .eh_frame as the argument.
85