blob: 6c142e13f0d548e081ce61de71e617311f5d46f4 [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/
Elliott Hughes560cee62014-02-18 22:08:56 -080087 unistd/
Elliott Hughes560cee62014-02-18 22:08:56 -080088 # These are legacy files of unknown provenance. In the past, bionic was a
89 # mess of random versions of random files from all three of FreeBSD, NetBSD,
90 # and OpenBSD! We've been working to clean that up, but these directories
91 # are basically where all the stuff we haven't got to yet lives.
92 # The 'netbsd' directory misleadingly contains the DNS resolver (which will
93 # probably be forked sometime soon, and that directory simply renamed).
94 # The other directories contain stuff that still needs to be sorted.
95
96 upstream-dlmalloc/
97 upstream-freebsd/
98 upstream-netbsd/
99 upstream-openbsd/
100 # These directories contain unmolested upstream source. Any time we can
101 # just use a BSD implementation of something unmodified, we should.
102 # See files like netbsd-compat.h for various ways in which we manage to
103 # build BSD source in bionic.
104
105 bionic/
106 # This is the biggest mess. The C++ files are files we own, typically
107 # because the Linux kernel interface is sufficiently different that we
108 # can't use any of the BSD implementations. The C files are usually
109 # legacy mess that needs to be sorted out, either by replacing it with
110 # current upstream source in one of the upstream directories or by
111 # switching the file to C++ and cleaning it up.
112
113 tools/
114 # Various tools used to maintain bionic.
115
116 tzcode/
117 # A modified superset of the IANA tzcode. Most of the modifications relate
118 # to Android's use of a single file (with corresponding index) to contain
119 # time zone data.
120 zoneinfo/
121 # Android-format time zone data.
122 # See 'Updating tzdata' later.
123
124
125Adding system calls
126-------------------
127
128Adding a system call usually involves:
129
130 1. Add entries to SYSCALLS.TXT.
131 See SYSCALLS.TXT itself for documentation on the format.
132 2. Run the gensyscalls.py script.
133 3. Add constants (and perhaps types) to the appropriate header file.
134 Note that you should check to see whether the constants are already in
135 kernel uapi header files, in which case you just need to make sure that
Elliott Hughes247904a2014-02-21 16:09:27 -0800136 the appropriate POSIX header file in libc/include/ includes the
Elliott Hughes560cee62014-02-18 22:08:56 -0800137 relevant file or files.
138 4. Add function declarations to the appropriate header file.
139 5. Add at least basic tests. Even a test that deliberately supplies
140 an invalid argument helps check that we're generating the right symbol
141 and have the right declaration in the header file. (And strace(1) can
142 confirm that the correct system call is being made.)
143
144
145Updating kernel header files
146----------------------------
147
148As mentioned above, this is currently a two-step process:
149
150 1. Use generate_uapi_headers.sh to go from a Linux source tree to appropriate
151 contents for external/kernel-headers/.
152 2. Run update_all.py to scrub those headers and import them into bionic.
153
154
155Updating tzdata
156---------------
157
158This is fully automated:
159
160 1. Run update-tzdata.py.
161