minix/lib/csu
Lionel Sambuc 4684ddb6aa LLVM Minix changes
- import libcxx
 - reduce targets to the one when compiled as a tools

Change-Id: Iabb8427f80ff8e89463559a28bcb8b4f2bdbc496
2014-07-28 17:05:59 +02:00
..
alpha Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
arch Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
common Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
common_elf Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00
ia64 Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
m68k_elf Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
mips Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
powerpc Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
powerpc64 Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
sh3_elf Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
sparc64 Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
sparc_elf Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
vax_elf Libraries updates and cleanup 2013-01-14 11:36:26 +01:00
Makefile LLVM Minix changes 2014-07-28 17:05:59 +02:00
README Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC) 2014-07-28 17:05:06 +02:00

Introduction

This document covers the native NetBSD compiler runtime. The full support
for the native runtime is enabled by setting USE_COMPILERCRTSTUFF to no
in bsd.own.mk.

Machine independent sources can be found in common. The crtbegin.c in
that directory is a useful template for deriving compact assembler
versions. That is preferable to decouple the result from changes in the
compiler logic.

A new platform should provide the following content in
arch/${MACHINE_ARCH} or arch/${MACHINE_CPU}:
- Makefile.inc: provides ELFSIZE corresponding to 32/64bit file format.
  If using the common C code instead of crtbegin.S also provide a -I option
  to find crtbegin.h in your arch subdir.
- crt0.S: provides setup code and the call to ___start.
- crtbegin.S or crtbegin.h: see below
- crtend.S: see below, most likely just a copy of an existing architecture
- crti.S: prefix part of .init/.fini sections, i.e. to ensure stack alignment
- crtn.S: suffix part of the .init/.fini sections, i.e. return to caller.


Overview of the common runtime support

The common runtime support contains two modules, crtbegin and crtend.
crtbegin is linked before all other object files of the program or
dynamic library, crtend after all other object files.  They frame the
lists of constructors, destructors, Java types and exception handling frames.

If done correctly, crtend contains no code and is therefore position
independent.  crtendS.o is therefore just a link to crtend.o.

crtbegin should be position-independent code.  crtbeginT.o doesn't have
to be PIC as it is statically linked.  The overhead is generally not
worth the trouble though.


Section types:
.ctor: writeable
.dtor: writeable
.eh_frame: read-only if platform allows mixing read-only and read-write
sections.  This is supported by GNU ld.
.jcr: writeable
.init: executable
.fini: executable


Non-local symbols:

Weak references:
- _Jv_RegisterClasses,
- __cxa_finalize (crtbeginS.o)
- __deregister_frame_info
- __register_frame_info

Hidden:
- __dso_handle: pointer to self for crtbeginS.o, NULL otherwise.
- __CTOR_LIST_END__


Initialisation (called from .init):

1.  Check that the init code hasn't started already, otherwise bail out.
2.  If __register_frame_info is NULL, skip to 4
3.  Call __register_frame_info with start of .eh_frame as first argument
    and a data object of at least 8 pointers as second argument.
4:  If _Jv_RegisterClasses is NULL, skip to 6
5:  Call _Jv_RegisterClasses with the first pointer of the .jcr section
    as argument.
6:  Iterate from the end of the .ctor section to the start.  Skip the
    terminating NULL and stop when reaching the starting (void *)-1 element.
    Call the pointers as void (*)(void) functions.


Deinitialisation (called from .fini):

1.  Check if the init code has already started, otherwise bail out.
2.  If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4.
3.  Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO)
    as first argument.
4.  Iterate from the start of the .dtor section to the send.  Skip the
    initial (void *)-1 and stop when reaching the terminating NULL element.
    Call the pointers as void (*)(void) functions.
5.  If __deregister_frame_info is NULL, return.
6.  Call __deregister_frame_info with the start of .eh_frame as the argument.


Since most of this can easily be done in C code, instead of providing a
crtbegin.S you can also chose to use the generic C implementation. Provide
a crtbegin.h file instead of crtbegin.S. In there put inline assembler
stubs (mostly copied from some other arch) and implement calls to the
helper functions __do_global_ctors_aux/__do_global_dtors_aux.