• Home
  • History
  • Annotate
  • only in this directory
NameDateSize

..25-Jul-201981

arch/H25-Jul-20197

crtbegin.cH A D25-Jul-20192.3 KiB

crtend.cH A D25-Jul-2019691

HakefileH A D25-Jul-20191.2 KiB

READMEH A D25-Jul-20192.3 KiB

README

1libcrt - Barrelfish C and C++ run-time support code
2
3INTRODUCTION
4
5This code supports the C and C++ run-times. It is responsible for
6calling the main() function and (if available) all static, global
7constructors, before doing so. On program exit, it is responsible for
8calling the corresponding global destructors.
9
10GLOBAL (DE-)CONSTRUCTION
11
12This is supported for both C and C++. C global constructors are a GCC
13extension. In libcrt, crtbegin.c and crtend.c are responsible for
14global (de-)construction.
15
16For global construction, the GCC C++ ABI mandates that a .ctors
17section be contained in the ELF binary, which contains an array of
18function pointers to global constructor functions, prefixed by a
19processor word specifying its length. The length is equal to the
20number of elements in the array, or -1, which specifies no length
21information. For a length of -1, the array shall be NULL terminated
22instead. libcrt uses a NULL terminated array and a length of -1, but
23supports loading the other format.
24
25In order for this to work, crtbegin.o has to be linked before any
26other object file, except crt0.o, and crtend.o after any other object
27file, respectively. crtbegin.o starts the .ctors section by giving the
28length word of -1. crtend.o gives the NULL terminator. GCC inserts its
29function pointers into the other object files, where appropriate.
30
31Global deconstruction is unimplemented.
32
33UPDATE: In recent versions of binutils (e.g. 2.21.51.20110523), the
34linker converts .ctors into .init_array and creates two new symbols
35__init_array_start, and __init_array_end, which point to the start and
36after the end of the .init_array section, respectively. .init_array
37seems to be a forward-walked array of function pointers, without a
38length header.
39
40
41RUN-TIME INITIALIZATION
42
43crt0.S defines _start, the entry point for all Barrelfish ELF
44binaries. It is responsible for setting up an initial stack and will
45call barrelfish_init_disabled() for libbarrelfish initialization.
46
47A special entry point is _start_init, which passes a third parameter
48to barrelfish_init_disabled() to mark an "init domain". Refer to
49libbarrelfish documentation for more information.
50
51
52CALLING MAIN
53
54crtbegin.c contains _main(), which is expected to be called by
55libbarrelfish after initialization. This will call all global
56constructors and then call main().
57