blob: 5785b3072b67c17cc214a5cafc54d62441169a75 [file] [log] [blame]
Elliott Hughes560cee62014-02-18 22:08:56 -08001Working on bionic
2=================
3
4What are the big pieces of bionic?
5----------------------------------
6
7libc/ --- libc.so, libc.a
8 The C library. Stuff like fopen(3) and kill(2).
9libm/ --- libm.so, libm.a
10 The math library. Traditionally Unix systems kept stuff like sin(3) and
11 cos(3) in a separate library to save space in the days before shared
12 libraries.
13libdl/ --- libdl.so
14 The dynamic linker interface library. This is actually just a bunch of
15 stubs that the dynamic linker replaces with pointers to its own
16 implementation at runtime. This is where stuff like dlopen(3) lives.
17libstdc++/ --- libstdc++.so
18 The C++ ABI support functions. The C++ compiler doesn't know how to
19 implement thread-safe static initialization and the like, so it just calls
20 functions that are supplied by the system. Stuff like __cxa_guard_acquire
21 and __cxa_pure_virtual live here.
22
23linker/ --- /system/bin/linker and /system/bin/linker64
24 The dynamic linker. When you run a dynamically-linked executable, its ELF
25 file has a DT_INTERP entry that says "use the following program to start me".
26 On Android, that's either linker or linker64 (depending on whether it's a
27 32-bit or 64-bit executable). It's responsible for loading the ELF executable
28 into memory and resolving references to symbols (so that when your code tries
29 to jump to fopen(3), say, it lands in the right place).
30
31tests/ --- unit tests
32 The tests/ directory contains unit tests. Roughly arranged as one file per
33 publicly-exported header file.
34benchmarks/ --- benchmarks
35 The benchmarks/ directory contains benchmarks.
36
37
38What's in libc/?
39----------------
40
41libc/
42 arch-arm/
43 arch-arm64/
44 arch-common/
45 arch-mips/
46 arch-mips64/
47 arch-x86/
48 arch-x86_64/
49 # Each architecture has its own subdirectory for stuff that isn't shared
50 # because it's architecture-specific. There will be a .mk file in here that
51 # drags in all the architecture-specific files.
52 bionic/
53 # Every architecture needs a handful of machine-specific assembler files.
54 # They live here.
55 include/
56 machine/
57 # The majority of header files are actually in libc/include/, but many
58 # of them pull in a <machine/something.h> for things like limits,
59 # endianness, and how floating point numbers are represented. Those
60 # headers live here.
61 string/
62 # Most architectures have a handful of optional assembler files
63 # implementing optimized versions of various routines. The <string.h>
64 # functions are particular favorites.
65 syscalls/
66 # The syscalls directories contain script-generated assembler files.
67 # See 'Adding system calls' later.
68
69 include/
70 # The public header files on everyone's include path. These are a mixture of
71 # files written by us and files taken from BSD.
72
73 kernel/
74 # The kernel uapi header files. These are scrubbed copies of the originals
75 # in external/kernel-headers/. These files must not be edited directly. The
76 # generate_uapi_headers.sh script should be used to go from a kernel tree to
77 # external/kernel-headers/ --- this takes care of the architecture-specific
78 # details. The update_all.py script should be used to regenerate bionic's
79 # scrubbed headers from external/kernel-headers/.
80
81 private/
82 # These are private header files meant for use within bionic itself.
83
84 netbsd/
85 stdio/
86 stdlib/
87 string/
88 unistd/
89 wchar/
90 # These are legacy files of unknown provenance. In the past, bionic was a
91 # mess of random versions of random files from all three of FreeBSD, NetBSD,
92 # and OpenBSD! We've been working to clean that up, but these directories
93 # are basically where all the stuff we haven't got to yet lives.
94 # The 'netbsd' directory misleadingly contains the DNS resolver (which will
95 # probably be forked sometime soon, and that directory simply renamed).
96 # The other directories contain stuff that still needs to be sorted.
97
98 upstream-dlmalloc/
99 upstream-freebsd/
100 upstream-netbsd/
101 upstream-openbsd/
102 # These directories contain unmolested upstream source. Any time we can
103 # just use a BSD implementation of something unmodified, we should.
104 # See files like netbsd-compat.h for various ways in which we manage to
105 # build BSD source in bionic.
106
107 bionic/
108 # This is the biggest mess. The C++ files are files we own, typically
109 # because the Linux kernel interface is sufficiently different that we
110 # can't use any of the BSD implementations. The C files are usually
111 # legacy mess that needs to be sorted out, either by replacing it with
112 # current upstream source in one of the upstream directories or by
113 # switching the file to C++ and cleaning it up.
114
115 tools/
116 # Various tools used to maintain bionic.
117
118 tzcode/
119 # A modified superset of the IANA tzcode. Most of the modifications relate
120 # to Android's use of a single file (with corresponding index) to contain
121 # time zone data.
122 zoneinfo/
123 # Android-format time zone data.
124 # See 'Updating tzdata' later.
125
126
127Adding system calls
128-------------------
129
130Adding a system call usually involves:
131
132 1. Add entries to SYSCALLS.TXT.
133 See SYSCALLS.TXT itself for documentation on the format.
134 2. Run the gensyscalls.py script.
135 3. Add constants (and perhaps types) to the appropriate header file.
136 Note that you should check to see whether the constants are already in
137 kernel uapi header files, in which case you just need to make sure that
138 that appropriate POSIX header file in libc/include/ includes the
139 relevant file or files.
140 4. Add function declarations to the appropriate header file.
141 5. Add at least basic tests. Even a test that deliberately supplies
142 an invalid argument helps check that we're generating the right symbol
143 and have the right declaration in the header file. (And strace(1) can
144 confirm that the correct system call is being made.)
145
146
147Updating kernel header files
148----------------------------
149
150As mentioned above, this is currently a two-step process:
151
152 1. Use generate_uapi_headers.sh to go from a Linux source tree to appropriate
153 contents for external/kernel-headers/.
154 2. Run update_all.py to scrub those headers and import them into bionic.
155
156
157Updating tzdata
158---------------
159
160This is fully automated:
161
162 1. Run update-tzdata.py.
163