Home | History | Annotate | Line # | Download | only in csu
README revision 1.4
      1 Introduction
      2 
      3 This document covers the native NetBSD compiler runtime. The full support
      4 for the native runtime is enabled by setting USE_COMPILERCRTSTUFF to no
      5 in bsd.own.mk.
      6 
      7 Machine independent sources can be found in common. The crtbegin.c in
      8 that directory is a useful template for deriving compact assembler
      9 versions. That is preferable to decouple the result from changes in the
     10 compiler logic.
     11 
     12 A new platform should provide the following content in
     13 arch/${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 
     24 Overview of the common runtime support
     25 
     26 The common runtime support contains two modules, crtbegin and crtend.
     27 crtbegin is linked before all other object files of the program or
     28 dynamic library, crtend after all other object files.  They frame the
     29 lists of constructors, destructors, Java types and exception handling frames.
     30 
     31 If done correctly, crtend contains no code and is therefore position
     32 independent.  crtendS.o is therefore just a link to crtend.o.
     33 
     34 crtbegin should be position-independent code.  crtbeginT.o doesn't have
     35 to be PIC as it is statically linked.  The overhead is generally not
     36 worth the trouble though.
     37 
     38 
     39 Section types:
     40 .ctor: writeable
     41 .dtor: writeable
     42 .eh_frame: read-only if platform allows mixing read-only and read-write
     43 sections.  This is supported by GNU ld.
     44 .jcr: writeable
     45 .init: executable
     46 .fini: executable
     47 
     48 
     49 Non-local symbols:
     50 
     51 Weak references:
     52 - _Jv_RegisterClasses,
     53 - __cxa_finalize (crtbeginS.o)
     54 - __deregister_frame_info
     55 - __register_frame_info
     56 
     57 Hidden:
     58 - __dso_handle: pointer to self for crtbeginS.o, NULL otherwise.
     59 - __CTOR_LIST_END__
     60 
     61 
     62 Initialisation (called from .init):
     63 
     64 1.  Check that the init code hasn't started already, otherwise bail out.
     65 2.  If __register_frame_info is NULL, skip to 4
     66 3.  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.
     68 4:  If _Jv_RegisterClasses is NULL, skip to 6
     69 5:  Call _Jv_RegisterClasses with the first pointer of the .jcr section
     70     as argument.
     71 6:  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 
     76 Deinitialisation (called from .fini):
     77 
     78 1.  Check if the init code has already started, otherwise bail out.
     79 2.  If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4.
     80 3.  Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO)
     81     as first argument.
     82 4.  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.
     85 5.  If __deregister_frame_info is NULL, return.
     86 6.  Call __deregister_frame_info with the start of .eh_frame as the argument.
     87 
     88 
     89 Since most of this can easily be done in C code, instead of providing a
     90 crtbegin.S you can also chose to use the generic C implementation. Provide
     91 a crtbegin.h file instead of crtbegin.S. In there put inline assembler
     92 stubs (mostly copied from some other arch) and implement calls to the
     93 helper functions __do_global_ctors_aux/__do_global_dtors_aux.
     94