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