Home | History | Annotate | only in /src/lib/csu
Up to higher level directory
NameDateSize
arch/09-Nov-2022
common/03-May-2025
Makefile20-Apr-2021675
README22-Apr-20143.5K

README

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