@@ -8,7 +8,7 @@ Full Host Build
8
8
:depth: 1
9
9
:local:
10
10
11
- .. note ::
11
+ .. note ::
12
12
Fullbuild requires running headergen, which is a python program that depends on
13
13
pyyaml. The minimum versions are listed on the :ref: `header_generation `
14
14
page, as well as additional information.
@@ -99,11 +99,16 @@ a C++ standard library (like libc++). Hence, we do not include
99
99
`libc++ <https://libcxx.llvm.org/ >`_, libcxx-abi and libunwind in the
100
100
LLVM only toolchain and use them to build and link C++ applications.
101
101
102
- Below is the list of commands for a simple recipe to build and install the
103
- libc components along with other components of an LLVM only toolchain. In this
104
- we've set the Ninja generator, enabled a full compiler suite, set the build
105
- type to "Debug", and enabled the Scudo allocator. The build also tells clang
106
- to use the freshly built lld and compiler-rt.
102
+ Below is the cmake command for a bootstrapping build of LLVM. This will build
103
+ clang and lld with the current system's toolchain, then build compiler-rt and
104
+ LLVM-libc with that freshly built clang. This ensures that LLVM-libc can take
105
+ advantage of the latest clang features and optimizations.
106
+
107
+ This build also uses Ninja as cmake's generator, and sets lld and compiler-rt as
108
+ the default for the fresh clang. Those settings are recommended, but the build
109
+ should still work without them. The compiler-rt options are required for
110
+ building `Scudo <https://llvm.org/docs/ScudoHardenedAllocator.html >`_ as the
111
+ allocator for LLVM-libc.
107
112
108
113
.. note ::
109
114
if your build fails with an error saying the compiler can't find
@@ -113,7 +118,6 @@ to use the freshly built lld and compiler-rt.
113
118
this command:
114
119
``sudo ln -s /usr/include/<TARGET TRIPLE>/asm /usr/include/asm ``
115
120
116
- .. TODO: Move from projects to runtimes for libc, compiler-rt
117
121
.. code-block :: sh
118
122
119
123
$> cd llvm-project # The llvm-project checkout
@@ -122,8 +126,9 @@ to use the freshly built lld and compiler-rt.
122
126
$> SYSROOT=/path/to/sysroot # Remember to set this!
123
127
$> cmake ../llvm \
124
128
-G Ninja \
125
- -DLLVM_ENABLE_PROJECTS=" clang;lld;libc;compiler-rt" \
126
- -DCMAKE_BUILD_TYPE=Debug \
129
+ -DLLVM_ENABLE_PROJECTS=" clang;lld" \
130
+ -DLLVM_ENABLE_RUNTIMES=" libc;compiler-rt" \
131
+ -DCMAKE_BUILD_TYPE=Release \
127
132
-DCMAKE_C_COMPILER=clang \
128
133
-DCMAKE_CXX_COMPILER=clang++ \
129
134
-DLLVM_LIBC_FULL_BUILD=ON \
@@ -133,25 +138,8 @@ to use the freshly built lld and compiler-rt.
133
138
-DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF \
134
139
-DCLANG_DEFAULT_LINKER=lld \
135
140
-DCLANG_DEFAULT_RTLIB=compiler-rt \
136
- -DDEFAULT_SYSROOT=$SYSROOT \
137
141
-DCMAKE_INSTALL_PREFIX=$SYSROOT
138
142
139
- We will go over some of the special options passed to the ``cmake `` command
140
- above.
141
-
142
- * **Enabled Projects ** - Since we want to build and install clang, lld
143
- and compiler-rt along with the libc, we specify
144
- ``clang;libc;lld;compiler-rt `` as the list of enabled projects.
145
- * **The full build option ** - Since we want to do build the full libc, we pass
146
- ``-DLLVM_LIBC_FULL_BUILD=ON ``.
147
- * **Scudo related options ** - LLVM's libc uses
148
- `Scudo <https://llvm.org/docs/ScudoHardenedAllocator.html >`_ as its allocator.
149
- So, when building the full libc, we should specify that we want to include
150
- Scudo in the libc. Since the libc currently only supports static linking, we
151
- also specify that we do not want to build the Scudo shared library.
152
- * **Default sysroot and install prefix ** - This is the path to the tool chain
153
- install directory. This is the directory where you intend to set up the sysroot.
154
-
155
143
Build and install
156
144
=================
157
145
@@ -164,14 +152,19 @@ Build and install
164
152
you may need to delete them from ``/usr/local/include ``.
165
153
166
154
After configuring the build with the above ``cmake `` command, one can build and
167
- install the libc, clang (and its support libraries and builtins), lld and
168
- compiler-rt, with the following command:
155
+ install the toolchain with
169
156
170
157
.. code-block :: sh
171
158
172
159
$> ninja install-clang install-builtins install-compiler-rt \
173
160
install-core-resource-headers install-libc install-lld
174
161
162
+ or
163
+
164
+ .. code-block :: sh
165
+
166
+ $> ninja install
167
+
175
168
Once the above command completes successfully, the ``$SYSROOT `` directory you
176
169
have specified with the CMake configure step above will contain a full LLVM-only
177
170
toolchain with which you can build practical/real-world C applications. See
@@ -190,9 +183,9 @@ These instructions should work on a Debian-based x86_64 system:
190
183
191
184
$> apt download linux-libc-dev
192
185
$> dpkg -x linux-libc-dev* deb .
193
- $> mv usr/include/ * /path/to/sysroot/include
194
- $> rm -rf usr linux-libc-dev* deb
195
- $> ln -s x86_64-linux-gnu/asm ~ /Programming /sysroot/include/asm
186
+ $> cp -r usr/* /path/to/sysroot/
187
+ $> rm -r usr linux-libc-dev* deb
188
+ $> ln -s /path/to/sysroot/include/ x86_64-linux-gnu/asm /path/to /sysroot/include/asm
196
189
197
190
Using your newly built libc
198
191
===========================
@@ -208,3 +201,20 @@ invocation:
208
201
Because the libc does not yet support dynamic linking, the -static parameter
209
202
must be added to all clang invocations.
210
203
204
+
205
+ You can make sure you're using the newly built toolchain by trying out features
206
+ that aren't yet supported by the system toolchain, such as fixed point. The
207
+ following is an example program that demonstrates the difference:
208
+
209
+ .. code-block :: C
210
+
211
+ // $ $SYSROOT/bin/clang example.c -static -ffixed-point --sysroot=$SYSROOT
212
+
213
+ #include <stdio.h>
214
+ int main() {
215
+ printf("Hello, World!\n%.9f\n%.9lK\n",
216
+ 4294967295.000000001,
217
+ 4294967295.000000001ulK);
218
+ return 0;
219
+ }
220
+
0 commit comments