README revision 1.2 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.2 joerg - Makefile.inc: provides ELFSIZE corresponding to 32/64bit file format
15 1.2 joerg - crt0.S: provides setup code and the call to __start.
16 1.2 joerg - crtbegin.S: see below
17 1.2 joerg - crtend.S: see below, most likely just a copy of an existing architecture
18 1.2 joerg - crti.S: prefix part of .init/.fini sections, i.e. to ensure stack alignment
19 1.2 joerg - crte.S: suffix part of the .init/.fini sections, i.e. return to caller.
20 1.2 joerg
21 1.2 joerg
22 1.1 joerg Overview of the common runtime support
23 1.1 joerg
24 1.1 joerg The common runtime support contains two modules, crtbegin and crtend.
25 1.1 joerg crtbegin is linked before all other object files of the program or
26 1.1 joerg dynamic library, crtend after all other object files. They frame the
27 1.1 joerg lists of constructors, destructors, Java types and exception handling frames.
28 1.1 joerg
29 1.1 joerg If done correctly, crtend contains no code and is therefore position
30 1.1 joerg independent. crtendS.o is therefore just a link to crtend.o.
31 1.1 joerg
32 1.1 joerg crtbegin should be position-independent code. crtbeginT.o doesn't have
33 1.1 joerg to be PIC as it is statically linked. The overhead is generally not
34 1.1 joerg worth the trouble though.
35 1.1 joerg
36 1.1 joerg
37 1.1 joerg Section types:
38 1.1 joerg .ctor: writeable
39 1.1 joerg .dtor: writeable
40 1.1 joerg .eh_frame: read-only if platform allows mixing read-only and read-write
41 1.1 joerg sections. This is supported by GNU ld.
42 1.1 joerg .jcr: writeable
43 1.1 joerg .init: executable
44 1.1 joerg .fini: executable
45 1.1 joerg
46 1.1 joerg
47 1.1 joerg Non-local symbols:
48 1.1 joerg
49 1.1 joerg Weak references:
50 1.1 joerg - _Jv_RegisterClasses,
51 1.1 joerg - __cxa_finalize (crtbeginS.o)
52 1.1 joerg - __deregister_frame_info
53 1.1 joerg - __register_frame_info
54 1.1 joerg
55 1.1 joerg Hidden:
56 1.1 joerg - __dso_handle: pointer to self for crtbeginS.o, NULL otherwise.
57 1.1 joerg - __CTOR_LIST_END__
58 1.1 joerg
59 1.1 joerg
60 1.1 joerg Initialisation (called from .init):
61 1.1 joerg
62 1.1 joerg 1. Check that the init code hasn't started already, otherwise bail out.
63 1.1 joerg 2. If __register_frame_info is NULL, skip to 4
64 1.1 joerg 3. Call __register_frame_info with start of .eh_frame as first argument
65 1.1 joerg and a data object of at least 8 pointers as second argument.
66 1.1 joerg 4: If _Jv_RegisterClasses is NULL, skip to 6
67 1.1 joerg 5: Call _Jv_RegisterClasses with the first pointer of the .jcr section
68 1.1 joerg as argument.
69 1.1 joerg 6: Iterate from the end of the .ctor section to the start. Skip the
70 1.1 joerg terminating NULL and stop when reaching the starting (void *)-1 element.
71 1.1 joerg Call the pointers as void (*)(void) functions.
72 1.1 joerg
73 1.1 joerg
74 1.1 joerg Deinitialisation (called from .fini):
75 1.1 joerg
76 1.1 joerg 1. Check if the init code has already started, otherwise bail out.
77 1.1 joerg 2. If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4.
78 1.1 joerg 3. Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO)
79 1.1 joerg as first argument.
80 1.1 joerg 4. Iterate from the start of the .dtor section to the send. Skip the
81 1.1 joerg initial (void *)-1 and stop when reaching the terminating NULL element.
82 1.1 joerg Call the pointers as void (*)(void) functions.
83 1.1 joerg 5. If __deregister_frame_info is NULL, return.
84 1.1 joerg 6. Call __deregister_frame_info with the start of .eh_frame as the argument.
85