1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
5 | %general-entities;
|
---|
6 | ]>
|
---|
7 |
|
---|
8 | <sect1 id="unpacking">
|
---|
9 | <?dbhtml filename="notes-on-building.html"?>
|
---|
10 |
|
---|
11 |
|
---|
12 | <title>Notes on Building Software</title>
|
---|
13 |
|
---|
14 | <para>Those people who have built an LFS system may be aware
|
---|
15 | of the general principles of downloading and unpacking software. Some
|
---|
16 | of that information is repeated here for those new to building
|
---|
17 | their own software.</para>
|
---|
18 |
|
---|
19 | <para>Each set of installation instructions contains a URL from which you
|
---|
20 | can download the package. The patches; however, are stored on the LFS
|
---|
21 | servers and are available via HTTP. These are referenced as needed in the
|
---|
22 | installation instructions.</para>
|
---|
23 |
|
---|
24 | <para>While you can keep the source files anywhere you like, we assume that
|
---|
25 | you have unpacked the package and changed into the directory created by the
|
---|
26 | unpacking process (the 'build' directory). We also assume you have
|
---|
27 | uncompressed any required patches and they are in the directory immediately
|
---|
28 | above the 'build' directory.</para>
|
---|
29 |
|
---|
30 | <para>We can not emphasize strongly enough that you should start from a
|
---|
31 | <emphasis>clean source tree</emphasis> each time. This means that if
|
---|
32 | you have had an error during configuration or compilation, it's usually
|
---|
33 | best to delete the source tree and
|
---|
34 | re-unpack it <emphasis>before</emphasis> trying again. This obviously
|
---|
35 | doesn't apply if you're an advanced user used to hacking
|
---|
36 | <filename>Makefile</filename>s and C code, but if in doubt, start from a
|
---|
37 | clean tree.</para>
|
---|
38 |
|
---|
39 | <sect2>
|
---|
40 | <title>Building Software as an Unprivileged (non-root) User</title>
|
---|
41 |
|
---|
42 | <para>The golden rule of Unix System Administration is to use your
|
---|
43 | superpowers only when necessary. Hence, BLFS recommends that you
|
---|
44 | build software as an unprivileged user and only become the
|
---|
45 | <systemitem class='username'>root</systemitem> user when installing the
|
---|
46 | software. This philosophy is followed in all the packages in this book.
|
---|
47 | Unless otherwise specified, all instructions should be executed as an
|
---|
48 | unprivileged user. The book will advise you on instructions that need
|
---|
49 | <systemitem class='username'>root</systemitem> privileges.</para>
|
---|
50 |
|
---|
51 | </sect2>
|
---|
52 |
|
---|
53 | <sect2>
|
---|
54 | <title>Unpacking the Software</title>
|
---|
55 |
|
---|
56 | <para>If a file is in <filename class='extension'>.tar</filename> format
|
---|
57 | and compressed, it is unpacked by running one of the following
|
---|
58 | commands:</para>
|
---|
59 |
|
---|
60 | <screen><userinput>tar -xvf filename.tar.gz
|
---|
61 | tar -xvf filename.tgz
|
---|
62 | tar -xvf filename.tar.Z
|
---|
63 | tar -xvf filename.tar.bz2</userinput></screen>
|
---|
64 |
|
---|
65 | <note>
|
---|
66 | <para>You may omit using the <option>v</option> parameter in the commands
|
---|
67 | shown above and below if you wish to suppress the verbose listing of all
|
---|
68 | the files in the archive as they are extracted. This can help speed up the
|
---|
69 | extraction as well as make any errors produced during the extraction
|
---|
70 | more obvious to you.</para>
|
---|
71 | </note>
|
---|
72 |
|
---|
73 | <para>You can also use a slightly different method:</para>
|
---|
74 |
|
---|
75 | <screen><userinput>bzcat filename.tar.bz2 | tar -xv</userinput></screen>
|
---|
76 |
|
---|
77 | <para>Finally, you sometimes need to be able to unpack patches which are
|
---|
78 | generally not in <filename class='extension'>.tar</filename> format. The
|
---|
79 | best way to do this is to copy the patch file to the parent of the 'build'
|
---|
80 | directory and then run one of the following commands depending on whether
|
---|
81 | the file is a <filename class='extension'>.gz</filename> or <filename
|
---|
82 | class='extension'>.bz2</filename> file:</para>
|
---|
83 |
|
---|
84 | <screen><userinput>gunzip -v patchname.gz
|
---|
85 | bunzip2 -v patchname.bz2</userinput></screen>
|
---|
86 |
|
---|
87 | </sect2>
|
---|
88 |
|
---|
89 | <sect2>
|
---|
90 | <title>Verifying File Integrity</title>
|
---|
91 |
|
---|
92 | <para>Generally, to verify that the downloaded file is complete,
|
---|
93 | many package maintainers also distribute md5sums of the files. To verify the
|
---|
94 | md5sum of the downloaded files, download both the file and the
|
---|
95 | corresponding md5sum file to the same directory (preferably from different
|
---|
96 | on-line locations), and (assuming <filename>file.md5sum</filename> is the
|
---|
97 | md5sum file downloaded) run the following command:</para>
|
---|
98 |
|
---|
99 | <screen><userinput>md5sum -c file.md5sum</userinput></screen>
|
---|
100 |
|
---|
101 | <para>If there are any errors, they will be reported. Note that the BLFS
|
---|
102 | book includes md5sums for all the source files also. To use the BLFS
|
---|
103 | supplied md5sums, you can create a <filename>file.md5sum</filename> (place
|
---|
104 | the md5sum data and the exact name of the downloaded file on the same
|
---|
105 | line of a file, separated by white space) and run the command shown above.
|
---|
106 | Alternately, simply run the command shown below and compare the output
|
---|
107 | to the md5sum data shown in the BLFS book.</para>
|
---|
108 |
|
---|
109 | <screen><userinput>md5sum <replaceable><name_of_downloaded_file></replaceable></userinput></screen>
|
---|
110 |
|
---|
111 | <para>MD5 is not cryptographically secure, so the md5sums are only
|
---|
112 | provided for detecting unmalicious changes to the file content. For
|
---|
113 | example, an error or truncation introduced during network transfer, or
|
---|
114 | a <quote>stealth</quote> update to the package from the upstream
|
---|
115 | (updating the content of a released tarball instead of making a new
|
---|
116 | release properly).</para>
|
---|
117 |
|
---|
118 | <para>There is no <quote>100%</quote> secure way to make
|
---|
119 | sure the genuity of the source files. Assuming the upstream is managing
|
---|
120 | their website correctly (the private key is not leaked and the domain is
|
---|
121 | not hijacked), and the trust anchors have been set up correctly using
|
---|
122 | <xref linkend="make-ca"/> on the BLFS system, we can reasonably trust
|
---|
123 | download URLs to the upstream official website
|
---|
124 | <emphasis role="bold">with https protocol</emphasis>. Note that
|
---|
125 | BLFS book itself is published on a website with https, so you should
|
---|
126 | already have some confidence in https protocol or you wouldn't trust the
|
---|
127 | book content.</para>
|
---|
128 |
|
---|
129 | <para>If the package is downloaded from an unofficial location (for
|
---|
130 | example a local mirror), checksums generated by cryptographically secure
|
---|
131 | digest algorithms (for example SHA256) can be used to verify the
|
---|
132 | genuity of the package. Download the checksum file from the upstream
|
---|
133 | <emphasis role="bold">official</emphasis> website (or somewhere
|
---|
134 | <emphasis role="bold">you can trust</emphasis>) and compare the
|
---|
135 | checksum of the package from unofficial location with it. For example,
|
---|
136 | SHA256 checksum can be checked with the command:</para>
|
---|
137 |
|
---|
138 | <note>
|
---|
139 | <para>If the checksum and the package are downloaded from the same
|
---|
140 | untrusted location, you won't gain security enhancement by verifying
|
---|
141 | the package with the checksum. The attacker can fake the checksum as
|
---|
142 | well as compromising the package itself.</para>
|
---|
143 | </note>
|
---|
144 |
|
---|
145 | <screen><userinput>sha256sum -c <replaceable>file</replaceable>.sha256sum</userinput></screen>
|
---|
146 |
|
---|
147 | <para>If <xref linkend="gnupg2"/> is installed, you can also verify the
|
---|
148 | genuity of the package with a GPG signature. Import the upstream GPG
|
---|
149 | public key with:</para>
|
---|
150 |
|
---|
151 | <screen><userinput>gpg --recv-key <replaceable>keyID</replaceable></userinput></screen>
|
---|
152 |
|
---|
153 | <para><replaceable>keyID</replaceable> should be replaced with the key ID
|
---|
154 | from somewhere <emphasis role="bold">you can trust</emphasis> (for
|
---|
155 | example, copy it from the upstream official website using https). Now
|
---|
156 | you can verify the signature with:</para>
|
---|
157 |
|
---|
158 | <screen><userinput>gpg --recv-key <replaceable>file</replaceable>.sig <replaceable>file</replaceable></userinput></screen>
|
---|
159 |
|
---|
160 | <para>The advantage of <application>GnuPG</application> signature is,
|
---|
161 | once you imported a public key which can be trusted, you can download
|
---|
162 | both the package and its signature from the same unofficial location and
|
---|
163 | verify them with the public key. So you won't need to connect to the
|
---|
164 | official upstream website to retrieve a checksum for each new release.
|
---|
165 | You only need to update the public key if it's expired or revoked.
|
---|
166 | </para>
|
---|
167 |
|
---|
168 | </sect2>
|
---|
169 |
|
---|
170 | <sect2>
|
---|
171 | <title>Creating Log Files During Installation</title>
|
---|
172 |
|
---|
173 | <para>For larger packages, it is convenient to create log files instead of
|
---|
174 | staring at the screen hoping to catch a particular error or warning. Log
|
---|
175 | files are also useful for debugging and keeping records. The following
|
---|
176 | command allows you to create an installation log. Replace
|
---|
177 | <replaceable><command></replaceable> with the command you intend to execute.</para>
|
---|
178 |
|
---|
179 | <screen><userinput>( <replaceable><command></replaceable> 2>&1 | tee compile.log && exit $PIPESTATUS )</userinput></screen>
|
---|
180 |
|
---|
181 | <para><option>2>&1</option> redirects error messages to the same
|
---|
182 | location as standard output. The <command>tee</command> command allows
|
---|
183 | viewing of the output while logging the results to a file. The parentheses
|
---|
184 | around the command run the entire command in a subshell and finally the
|
---|
185 | <command>exit $PIPESTATUS</command> command ensures the result of the
|
---|
186 | <replaceable><command></replaceable> is returned as the result and not the
|
---|
187 | result of the <command>tee</command> command.</para>
|
---|
188 |
|
---|
189 | </sect2>
|
---|
190 |
|
---|
191 | <sect2 id="parallel-builds" xreflabel="Using Multiple Processors">
|
---|
192 | <title>Using Multiple Processors</title>
|
---|
193 |
|
---|
194 | <para>For many modern systems with multiple processors (or cores) the
|
---|
195 | compilation time for a package can be reduced by performing a "parallel
|
---|
196 | make" by either setting an environment variable or telling the make program
|
---|
197 | how many processors are available. For instance, a Core2Duo can support two
|
---|
198 | simultaneous processes with: </para>
|
---|
199 |
|
---|
200 | <screen><userinput>export MAKEFLAGS='-j2'</userinput></screen>
|
---|
201 |
|
---|
202 | <para>or just building with:</para>
|
---|
203 |
|
---|
204 | <screen><userinput>make -j2</userinput></screen>
|
---|
205 |
|
---|
206 | <para>
|
---|
207 | If you have applied the optional <command>sed</command> when building
|
---|
208 | <application>ninja</application> in LFS, you can use:
|
---|
209 | </para>
|
---|
210 |
|
---|
211 | <screen><userinput>export NINJAJOBS=2</userinput></screen>
|
---|
212 |
|
---|
213 | <para>
|
---|
214 | when a package uses <command>ninja</command>, or just:
|
---|
215 | </para>
|
---|
216 |
|
---|
217 | <screen><userinput>ninja -j2</userinput></screen>
|
---|
218 |
|
---|
219 | <para>
|
---|
220 | but for ninja, the default number of jobs is <N>+2, where <N>
|
---|
221 | is the number of processors available, so that using the above commands
|
---|
222 | is rather for limiting the number of jobs (see below for why this could
|
---|
223 | be necessary).
|
---|
224 | </para>
|
---|
225 |
|
---|
226 | <para>Generally the number of processes should not exceed the number of
|
---|
227 | cores supported by the CPU. To list the processors on your
|
---|
228 | system, issue: <userinput>grep processor /proc/cpuinfo</userinput>.
|
---|
229 | </para>
|
---|
230 |
|
---|
231 | <para>In some cases, using multiple processes may result in a 'race'
|
---|
232 | condition where the success of the build depends on the order of the
|
---|
233 | commands run by the <command>make</command> program. For instance, if an
|
---|
234 | executable needs File A and File B, attempting to link the program before
|
---|
235 | one of the dependent components is available will result in a failure.
|
---|
236 | This condition usually arises because the upstream developer has not
|
---|
237 | properly designated all the prerequisites needed to accomplish a step in the
|
---|
238 | Makefile.</para>
|
---|
239 |
|
---|
240 | <para>If this occurs, the best way to proceed is to drop back to a
|
---|
241 | single processor build. Adding '-j1' to a make command will override
|
---|
242 | the similar setting in the <envar>MAKEFLAGS</envar> environment
|
---|
243 | variable.</para>
|
---|
244 |
|
---|
245 | <note><para>When running the package tests or the install portion of the
|
---|
246 | package build process, we do not recommend using an option greater than
|
---|
247 | '-j1' unless specified otherwise. The installation procedures or checks
|
---|
248 | have not been validated using parallel procedures and may fail with issues
|
---|
249 | that are difficult to debug.</para></note>
|
---|
250 |
|
---|
251 | <important>
|
---|
252 | <para>
|
---|
253 | Another problem may occur with modern CPU's, which have a lot of cores.
|
---|
254 | Each job started consumes memory, and if the sum of the needed
|
---|
255 | memory for each job exceeds the available memory, you may encounter
|
---|
256 | either an OOM (Out of Memory) kernel interrupt or intense swapping
|
---|
257 | that will slow the build beyond reasonable limits.
|
---|
258 | </para>
|
---|
259 |
|
---|
260 | <para>
|
---|
261 | Some compilations with <command>g++</command> may consume up to 2.5 GB
|
---|
262 | of memory, so to be safe, you should restrict the number of jobs
|
---|
263 | to (Total Memory in GB)/2.5, at least for big packages such as LLVM,
|
---|
264 | WebKitGtk, QtWebEngine, or libreoffice.
|
---|
265 | </para>
|
---|
266 | </important>
|
---|
267 | </sect2>
|
---|
268 |
|
---|
269 | <sect2 id="automating-builds" xreflabel="Automated Building Procedures">
|
---|
270 | <title>Automated Building Procedures</title>
|
---|
271 |
|
---|
272 | <para>There are times when automating the building of a package can come in
|
---|
273 | handy. Everyone has their own reasons for wanting to automate building,
|
---|
274 | and everyone goes about it in their own way. Creating
|
---|
275 | <filename>Makefile</filename>s, <application>Bash</application> scripts,
|
---|
276 | <application>Perl</application> scripts or simply a list of commands used
|
---|
277 | to cut and paste are just some of the methods you can use to automate
|
---|
278 | building BLFS packages. Detailing how and providing examples of the many
|
---|
279 | ways you can automate the building of packages is beyond the scope of this
|
---|
280 | section. This section will expose you to using file redirection and the
|
---|
281 | <command>yes</command> command to help provide ideas on how to automate
|
---|
282 | your builds.</para>
|
---|
283 |
|
---|
284 | <bridgehead renderas="sect3">File Redirection to Automate Input</bridgehead>
|
---|
285 |
|
---|
286 | <para>You will find times throughout your BLFS journey when you will come
|
---|
287 | across a package that has a command prompting you for information. This
|
---|
288 | information might be configuration details, a directory path, or a response
|
---|
289 | to a license agreement. This can present a challenge to automate the
|
---|
290 | building of that package. Occasionally, you will be prompted for different
|
---|
291 | information in a series of questions. One method to automate this type of
|
---|
292 | scenario requires putting the desired responses in a file and using
|
---|
293 | redirection so that the program uses the data in the file as the answers to
|
---|
294 | the questions.</para>
|
---|
295 |
|
---|
296 | <para>Building the <application>CUPS</application> package is a good
|
---|
297 | example of how redirecting a file as input to prompts can help you automate
|
---|
298 | the build. If you run the test suite, you are asked to respond to a series
|
---|
299 | of questions regarding the type of test to run and if you have any
|
---|
300 | auxiliary programs the test can use. You can create a file with your
|
---|
301 | responses, one response per line, and use a command similar to the
|
---|
302 | one shown below to automate running the test suite:</para>
|
---|
303 |
|
---|
304 | <screen><userinput>make check < ../cups-1.1.23-testsuite_parms</userinput></screen>
|
---|
305 |
|
---|
306 | <para>This effectively makes the test suite use the responses in the file
|
---|
307 | as the input to the questions. Occasionally you may end up doing a bit of
|
---|
308 | trial and error determining the exact format of your input file for some
|
---|
309 | things, but once figured out and documented you can use this to automate
|
---|
310 | building the package.</para>
|
---|
311 |
|
---|
312 | <bridgehead renderas="sect3">Using <command>yes</command> to Automate
|
---|
313 | Input</bridgehead>
|
---|
314 |
|
---|
315 | <para>Sometimes you will only need to provide one response, or provide the
|
---|
316 | same response to many prompts. For these instances, the
|
---|
317 | <command>yes</command> command works really well. The
|
---|
318 | <command>yes</command> command can be used to provide a response (the same
|
---|
319 | one) to one or more instances of questions. It can be used to simulate
|
---|
320 | pressing just the <keycap>Enter</keycap> key, entering the
|
---|
321 | <keycap>Y</keycap> key or entering a string of text. Perhaps the easiest
|
---|
322 | way to show its use is in an example.</para>
|
---|
323 |
|
---|
324 | <para>First, create a short <application>Bash</application> script by
|
---|
325 | entering the following commands:</para>
|
---|
326 |
|
---|
327 | <screen><userinput>cat > blfs-yes-test1 << "EOF"
|
---|
328 | <literal>#!/bin/bash
|
---|
329 |
|
---|
330 | echo -n -e "\n\nPlease type something (or nothing) and press Enter ---> "
|
---|
331 |
|
---|
332 | read A_STRING
|
---|
333 |
|
---|
334 | if test "$A_STRING" = ""; then A_STRING="Just the Enter key was pressed"
|
---|
335 | else A_STRING="You entered '$A_STRING'"
|
---|
336 | fi
|
---|
337 |
|
---|
338 | echo -e "\n\n$A_STRING\n\n"</literal>
|
---|
339 | EOF
|
---|
340 | chmod 755 blfs-yes-test1</userinput></screen>
|
---|
341 |
|
---|
342 | <para>Now run the script by issuing <command>./blfs-yes-test1</command> from
|
---|
343 | the command line. It will wait for a response, which can be anything (or
|
---|
344 | nothing) followed by the <keycap>Enter</keycap> key. After entering
|
---|
345 | something, the result will be echoed to the screen. Now use the
|
---|
346 | <command>yes</command> command to automate the entering of a
|
---|
347 | response:</para>
|
---|
348 |
|
---|
349 | <screen><userinput>yes | ./blfs-yes-test1</userinput></screen>
|
---|
350 |
|
---|
351 | <para>Notice that piping <command>yes</command> by itself to the script
|
---|
352 | results in <keycap>y</keycap> being passed to the script. Now try it with a
|
---|
353 | string of text:</para>
|
---|
354 |
|
---|
355 | <screen><userinput>yes 'This is some text' | ./blfs-yes-test1</userinput></screen>
|
---|
356 |
|
---|
357 | <para>The exact string was used as the response to the script. Finally,
|
---|
358 | try it using an empty (null) string:</para>
|
---|
359 |
|
---|
360 | <screen><userinput>yes '' | ./blfs-yes-test1</userinput></screen>
|
---|
361 |
|
---|
362 | <para>Notice this results in passing just the press of the
|
---|
363 | <keycap>Enter</keycap> key to the script. This is useful for times when the
|
---|
364 | default answer to the prompt is sufficient. This syntax is used in the
|
---|
365 | <xref linkend="net-tools-automate-example"/> instructions to accept all the
|
---|
366 | defaults to the many prompts during the configuration step. You may now
|
---|
367 | remove the test script, if desired.</para>
|
---|
368 |
|
---|
369 | <bridgehead renderas="sect3">File Redirection to Automate Output</bridgehead>
|
---|
370 |
|
---|
371 | <para>In order to automate the building of some packages, especially those
|
---|
372 | that require you to read a license agreement one page at a time, requires
|
---|
373 | using a method that avoids having to press a key to display each page.
|
---|
374 | Redirecting the output to a file can be used in these instances to assist
|
---|
375 | with the automation. The previous section on this page touched on creating
|
---|
376 | log files of the build output. The redirection method shown there used the
|
---|
377 | <command>tee</command> command to redirect output to a file while also
|
---|
378 | displaying the output to the screen. Here, the output will only be sent to
|
---|
379 | a file.</para>
|
---|
380 |
|
---|
381 | <para>Again, the easiest way to demonstrate the technique is to show an
|
---|
382 | example. First, issue the command:</para>
|
---|
383 |
|
---|
384 | <screen><userinput>ls -l /usr/bin | more</userinput></screen>
|
---|
385 |
|
---|
386 | <para>Of course, you'll be required to view the output one page at a time
|
---|
387 | because the <command>more</command> filter was used. Now try the same
|
---|
388 | command, but this time redirect the output to a file. The special file
|
---|
389 | <filename>/dev/null</filename> can be used instead of the filename shown,
|
---|
390 | but you will have no log file to examine:</para>
|
---|
391 |
|
---|
392 | <screen><userinput>ls -l /usr/bin | more > redirect_test.log 2>&1</userinput></screen>
|
---|
393 |
|
---|
394 | <para>Notice that this time the command immediately returned to the shell
|
---|
395 | prompt without having to page through the output. You may now remove the
|
---|
396 | log file.</para>
|
---|
397 |
|
---|
398 | <para>The last example will use the <command>yes</command> command in
|
---|
399 | combination with output redirection to bypass having to page through the
|
---|
400 | output and then provide a <keycap>y</keycap> to a prompt. This technique
|
---|
401 | could be used in instances when otherwise you would have to page through
|
---|
402 | the output of a file (such as a license agreement) and then answer the
|
---|
403 | question of <quote>do you accept the above?</quote>. For this example,
|
---|
404 | another short <application>Bash</application> script is required:</para>
|
---|
405 |
|
---|
406 | <screen><userinput>cat > blfs-yes-test2 << "EOF"
|
---|
407 | <literal>#!/bin/bash
|
---|
408 |
|
---|
409 | ls -l /usr/bin | more
|
---|
410 |
|
---|
411 | echo -n -e "\n\nDid you enjoy reading this? (y,n) "
|
---|
412 |
|
---|
413 | read A_STRING
|
---|
414 |
|
---|
415 | if test "$A_STRING" = "y"; then A_STRING="You entered the 'y' key"
|
---|
416 | else A_STRING="You did NOT enter the 'y' key"
|
---|
417 | fi
|
---|
418 |
|
---|
419 | echo -e "\n\n$A_STRING\n\n"</literal>
|
---|
420 | EOF
|
---|
421 | chmod 755 blfs-yes-test2</userinput></screen>
|
---|
422 |
|
---|
423 | <para>This script can be used to simulate a program that requires you to
|
---|
424 | read a license agreement, then respond appropriately to accept the
|
---|
425 | agreement before the program will install anything. First, run the script
|
---|
426 | without any automation techniques by issuing
|
---|
427 | <command>./blfs-yes-test2</command>.</para>
|
---|
428 |
|
---|
429 | <para>Now issue the following command which uses two automation techniques,
|
---|
430 | making it suitable for use in an automated build script:</para>
|
---|
431 |
|
---|
432 | <screen><userinput>yes | ./blfs-yes-test2 > blfs-yes-test2.log 2>&1</userinput></screen>
|
---|
433 |
|
---|
434 | <para>If desired, issue <command>tail blfs-yes-test2.log</command> to see
|
---|
435 | the end of the paged output, and confirmation that <keycap>y</keycap> was
|
---|
436 | passed through to the script. Once satisfied that it works as it should,
|
---|
437 | you may remove the script and log file.</para>
|
---|
438 |
|
---|
439 | <para>Finally, keep in mind that there are many ways to automate and/or
|
---|
440 | script the build commands. There is not a single <quote>correct</quote> way
|
---|
441 | to do it. Your imagination is the only limit.</para>
|
---|
442 |
|
---|
443 | </sect2>
|
---|
444 |
|
---|
445 | <sect2>
|
---|
446 | <title>Dependencies</title>
|
---|
447 |
|
---|
448 | <para>For each package described, BLFS lists the known dependencies.
|
---|
449 | These are listed under several headings, whose meaning is as follows:</para>
|
---|
450 |
|
---|
451 | <itemizedlist>
|
---|
452 | <listitem>
|
---|
453 | <para><emphasis>Required</emphasis> means that the target package
|
---|
454 | cannot be correctly built without the dependency having first been
|
---|
455 | installed.</para>
|
---|
456 | </listitem>
|
---|
457 | <listitem>
|
---|
458 | <para><emphasis>Recommended</emphasis> means that BLFS strongly
|
---|
459 | suggests this package is installed first for a clean and trouble-free
|
---|
460 | build, that won't have issues either during the build process, or at
|
---|
461 | run-time. The instructions in the book assume these packages are
|
---|
462 | installed. Some changes or workarounds may be required if these
|
---|
463 | packages are not installed.</para>
|
---|
464 | </listitem>
|
---|
465 | <listitem>
|
---|
466 | <para><emphasis>Optional</emphasis> means that this package might be
|
---|
467 | installed for added functionality. Often BLFS will describe the
|
---|
468 | dependency to explain the added functionality that will result.</para>
|
---|
469 | </listitem>
|
---|
470 | </itemizedlist>
|
---|
471 |
|
---|
472 | </sect2>
|
---|
473 |
|
---|
474 | <sect2 id="package_updates">
|
---|
475 | <title>Using the Most Current Package Sources</title>
|
---|
476 |
|
---|
477 | <para>On occasion you may run into a situation in the book when a package
|
---|
478 | will not build or work properly. Though the Editors attempt to ensure
|
---|
479 | that every package in the book builds and works properly, sometimes a
|
---|
480 | package has been overlooked or was not tested with this particular version
|
---|
481 | of BLFS.</para>
|
---|
482 |
|
---|
483 | <para>If you discover that a package will not build or work properly, you
|
---|
484 | should see if there is a more current version of the package. Typically
|
---|
485 | this means you go to the maintainer's web site and download the most current
|
---|
486 | tarball and attempt to build the package. If you cannot determine the
|
---|
487 | maintainer's web site by looking at the download URLs, use Google and query
|
---|
488 | the package's name. For example, in the Google search bar type:
|
---|
489 | 'package_name download' (omit the quotes) or something similar. Sometimes
|
---|
490 | typing: 'package_name home page' will result in you finding the
|
---|
491 | maintainer's web site.</para>
|
---|
492 |
|
---|
493 | </sect2>
|
---|
494 |
|
---|
495 | <sect2 id="stripping">
|
---|
496 | <title>Stripping One More Time</title>
|
---|
497 |
|
---|
498 | <para>
|
---|
499 | In LFS, stripping of debugging symbols and unneeded symbol table
|
---|
500 | entries was discussed a couple of times. When building BLFS packages,
|
---|
501 | there are generally no special instructions that discuss stripping
|
---|
502 | again. Stripping can be done while installing a package, or
|
---|
503 | afterwards.
|
---|
504 | </para>
|
---|
505 |
|
---|
506 | <bridgehead renderas="sect3" id="stripping-install">Stripping while Installing a Package</bridgehead>
|
---|
507 |
|
---|
508 | <para>
|
---|
509 | There are several ways to strip executables installed by a
|
---|
510 | package. They depend on the build system used (see below <link
|
---|
511 | linkend="buildsystems">the section about build systems</link>),
|
---|
512 | so only some
|
---|
513 | generalities can be listed here:
|
---|
514 | </para>
|
---|
515 |
|
---|
516 | <note>
|
---|
517 | <para>
|
---|
518 | The following methods using the feature of a building system
|
---|
519 | (autotools, meson, or cmake) will not strip static libraries if any
|
---|
520 | is installed. Fortunately there are not too many static libraries
|
---|
521 | in BLFS, and a static library can always be stripped safely by
|
---|
522 | running <command>strip --strip-unneeded</command> on it manually.
|
---|
523 | </para>
|
---|
524 | </note>
|
---|
525 |
|
---|
526 | <itemizedlist>
|
---|
527 | <listitem>
|
---|
528 | <para>
|
---|
529 | The packages using autotools usually have an
|
---|
530 | <parameter>install-strip</parameter> target in their generated
|
---|
531 | <filename>Makefile</filename> files. So installing stripped
|
---|
532 | executables is just a matter of using
|
---|
533 | <command>make install-strip</command> instead of
|
---|
534 | <command>make install</command>.
|
---|
535 | </para>
|
---|
536 | </listitem>
|
---|
537 | <listitem>
|
---|
538 | <para>
|
---|
539 | The packages using the meson build system can accept
|
---|
540 | <parameter>-Dstrip=true</parameter> when running
|
---|
541 | <command>meson</command>. If you've forgot to add this option
|
---|
542 | running the <command>meson</command>, you can also run
|
---|
543 | <command>meson install --strip</command> instead of
|
---|
544 | <command>ninja install</command>.
|
---|
545 | </para>
|
---|
546 | </listitem>
|
---|
547 | <listitem>
|
---|
548 | <para>
|
---|
549 | <command>cmake</command> generates
|
---|
550 | <parameter>install/strip</parameter> targets for both the
|
---|
551 | <parameter>Unix Makefiles</parameter> and
|
---|
552 | <parameter>Ninja</parameter> generators (the default is
|
---|
553 | <parameter>Unix Makefiles</parameter> on linux). So just run
|
---|
554 | <command>make install/strip</command> or
|
---|
555 | <command>ninja install/strip</command> instead of the
|
---|
556 | <command>install</command> counterparts.
|
---|
557 | </para>
|
---|
558 | </listitem>
|
---|
559 | <listitem>
|
---|
560 | <para>
|
---|
561 | Removing (or not generating) debug symbols can also be
|
---|
562 | achieved by removing the
|
---|
563 | <parameter>-g<something></parameter> options
|
---|
564 | in C/C++ calls. How to do that is very specific for each
|
---|
565 | package. And, it does not remove unneeded symbol table entries.
|
---|
566 | So it will not be explained in detail here. See also below
|
---|
567 | the paragraphs about optimization.
|
---|
568 | </para>
|
---|
569 | </listitem>
|
---|
570 | </itemizedlist>
|
---|
571 |
|
---|
572 | <bridgehead renderas="sect3" id="stripping-installed">Stripping Installed Executables</bridgehead>
|
---|
573 |
|
---|
574 | <para>
|
---|
575 | The <command>strip</command> utility changes files in place, which may
|
---|
576 | break anything using it if it is loaded in memory. Note that if a file is
|
---|
577 | in use but just removed from the disk (i.e. not overwritten nor
|
---|
578 | modified), this is not a problem since the kernel can use
|
---|
579 | <quote>deleted</quote> files. Look at <filename>/proc/*/maps</filename>
|
---|
580 | and it is likely that you'll see some <emphasis>(deleted)</emphasis>
|
---|
581 | entries. The <command>mv</command> just removes the destination file from
|
---|
582 | the directory but does not touch its content, so that it satisfies the
|
---|
583 | condition for the kernel to use the old (deleted) file. The script below
|
---|
584 | is just an example.
|
---|
585 | It should be run as the &root; user:
|
---|
586 | </para>
|
---|
587 |
|
---|
588 | <screen><userinput>cat > strip-all.sh << "EOF"
|
---|
589 | <literal>#!/bin/bash
|
---|
590 |
|
---|
591 | if [ $EUID -ne 0 ]; then
|
---|
592 | echo "Need to be root"
|
---|
593 | exit 1
|
---|
594 | fi
|
---|
595 |
|
---|
596 | { find /usr/lib -type f -name '*.so*' ! -name '*dbg'
|
---|
597 | find /usr/lib -type f -name '*.a'
|
---|
598 | find /usr/{bin,sbin,libexec} -type f
|
---|
599 | } | while read file; do
|
---|
600 | if ! readelf -h $file >/dev/null 2>&1; then continue; fi
|
---|
601 | if $( file $file | grep --quiet --invert-match 'not stripped' ); then
|
---|
602 | continue;
|
---|
603 | fi
|
---|
604 |
|
---|
605 | cp --preserve $file ${file}.tmp
|
---|
606 | strip --strip-unneeded ${file}.tmp
|
---|
607 | mv ${file}.tmp $file
|
---|
608 | done</literal>
|
---|
609 | EOF
|
---|
610 | chmod 755 strip-all.sh</userinput></screen>
|
---|
611 |
|
---|
612 | <para>
|
---|
613 | If you install programs in other directories such as <filename
|
---|
614 | class="directory">/opt</filename> or <filename
|
---|
615 | class="directory">/usr/local</filename>, you may want to strip the files
|
---|
616 | there too. Just add other directories to scan in the compound list of
|
---|
617 | <command>find</command> commands between the braces.
|
---|
618 | </para>
|
---|
619 |
|
---|
620 | <para>
|
---|
621 | For more information on stripping, see <ulink
|
---|
622 | url="https://www.technovelty.org/linux/stripping-shared-libraries.html"/>.
|
---|
623 | </para>
|
---|
624 |
|
---|
625 | </sect2>
|
---|
626 |
|
---|
627 | <!--
|
---|
628 | <sect2 id="libtool">
|
---|
629 | <title>Libtool files</title>
|
---|
630 |
|
---|
631 | <para>
|
---|
632 | One of the side effects of packages that use Autotools, including
|
---|
633 | libtool, is that they create many files with an .la extension. These
|
---|
634 | files are not needed in an LFS environment. If there are conflicts with
|
---|
635 | pkgconfig entries, they can actually prevent successful builds. You
|
---|
636 | may want to consider removing these files periodically:
|
---|
637 | </para>
|
---|
638 |
|
---|
639 | <screen><userinput>find /lib /usr/lib -not -path "*Image*" -a -name \*.la -delete</userinput></screen>
|
---|
640 |
|
---|
641 | <para>
|
---|
642 | The above command removes all .la files with the exception of those that
|
---|
643 | have <quote>Image</quote> or <quote>openldap</quote> as a part of the
|
---|
644 | path. These .la files are used by the ImageMagick and openldap programs,
|
---|
645 | respectively. There may be other exceptions by packages not in BLFS.
|
---|
646 | </para>
|
---|
647 |
|
---|
648 | </sect2>
|
---|
649 | -->
|
---|
650 | <sect2 id="buildsystems">
|
---|
651 | <title>Working with different build systems</title>
|
---|
652 |
|
---|
653 | <para>
|
---|
654 | There are now three different build systems in common use for
|
---|
655 | converting C or C++ source code into compiled programs or
|
---|
656 | libraries and their details (particularly, finding out about available
|
---|
657 | options and their default values) differ. It may be easiest to understand
|
---|
658 | the issues caused by some choices (typically slow execution or
|
---|
659 | unexpected use of, or omission of, optimizatons) by starting with
|
---|
660 | the CFLAGS and CXXFLAGS environment variables. There are also some
|
---|
661 | programs which use rust.
|
---|
662 | </para>
|
---|
663 |
|
---|
664 | <para>
|
---|
665 | Most LFS and BLFS builders are probably aware of the basics of CFLAGS
|
---|
666 | and CXXFLAGS for altering how a program is compiled. Typically, some
|
---|
667 | form of optimization is used by upstream developers (-O2 or -O3),
|
---|
668 | sometimes with the creation of debug symbols (-g), as defaults.
|
---|
669 | </para>
|
---|
670 |
|
---|
671 | <para>
|
---|
672 | If there are contradictory flags (e.g. multiple different -O values),
|
---|
673 | the <emphasis>last</emphasis> value will be used. Sometimes this means
|
---|
674 | that flags specified in environment variables will be picked up before
|
---|
675 | values hardcoded in the Makefile, and therefore ignored. For example,
|
---|
676 | where a user specifies '-O2' and that is followed by '-O3' the build will
|
---|
677 | use '-O3'.
|
---|
678 | </para>
|
---|
679 |
|
---|
680 | <para>
|
---|
681 | There are various other things which can be passed in CFLAGS or
|
---|
682 | CXXFLAGS, such as forcing compilation for a specific microarchitecture
|
---|
683 | (e.g. -march=amdfam10, -march=native) or specifying a specific standard
|
---|
684 | for C or C++ (-std=c++17 for example). But one thing which has now come
|
---|
685 | to light is that programmers might include debug assertions in their
|
---|
686 | code, expecting them to be disabled in releases by using -DNDEBUG.
|
---|
687 | Specifically, if <xref linkend="mesa"/> is built with these assertions
|
---|
688 | enabled, some activities such as loading levels of games can take
|
---|
689 | extremely long times, even on high-class video cards.
|
---|
690 | </para>
|
---|
691 |
|
---|
692 | <bridgehead renderas="sect3" id="autotools-info">Autotools with Make</bridgehead>
|
---|
693 |
|
---|
694 | <para>
|
---|
695 | This combination is often described as 'CMMI' (configure, make, make
|
---|
696 | install) and is used here to also cover the few packages which have a
|
---|
697 | configure script that is not generated by autotools.
|
---|
698 | </para>
|
---|
699 |
|
---|
700 | <para>
|
---|
701 | Sometimes running <command>./configure --help</command> will produce
|
---|
702 | useful options about switches which might be used. At other times,
|
---|
703 | after looking at the output from configure you may need to look
|
---|
704 | at the details of the script to find out what it was actually searching
|
---|
705 | for.
|
---|
706 | </para>
|
---|
707 |
|
---|
708 | <para>
|
---|
709 | Many configure scripts will pick up any CFLAGS or CXXFLAGS from the
|
---|
710 | environment, but CMMI packages vary about how these will be mixed with
|
---|
711 | any flags which would otherwise be used (<emphasis>variously</emphasis>:
|
---|
712 | ignored, used to replace the programmer's suggestion, used before the
|
---|
713 | programmer's suggestion, or used after the programmer's suggestion).
|
---|
714 | </para>
|
---|
715 |
|
---|
716 | <para>
|
---|
717 | In most CMMI packages, running 'make' will list each command and run
|
---|
718 | it, interspersed with any warnings. But some packages try to be 'silent'
|
---|
719 | and only show which file they are compiling or linking instead of showing
|
---|
720 | the command line. If you need to inspect the command, either because of
|
---|
721 | an error, or just to see what options and flags are being used, adding
|
---|
722 | 'V=1' to the make invocation may help.
|
---|
723 | </para>
|
---|
724 |
|
---|
725 | <bridgehead renderas="sect3" id="cmake-info">CMake</bridgehead>
|
---|
726 |
|
---|
727 | <para>
|
---|
728 | CMake works in a very different way, and it has two backends which can
|
---|
729 | be used on BLFS: 'make' and 'ninja'. The default backend is make, but
|
---|
730 | ninja can be faster on large packages with multiple processors. To
|
---|
731 | use ninja, specify '-G Ninja' in the cmake command. However, there are
|
---|
732 | some packages which create fatal errors in their ninja files but build
|
---|
733 | successfully using the default of Unix Makefiles.
|
---|
734 | </para>
|
---|
735 |
|
---|
736 | <para>
|
---|
737 | The hardest part of using CMake is knowing what options you might wish
|
---|
738 | to specify. The only way to get a list of what the package knows about
|
---|
739 | is to run <command>cmake -LAH</command> and look at the output for that
|
---|
740 | default configuration.
|
---|
741 | </para>
|
---|
742 |
|
---|
743 | <para>
|
---|
744 | Perhaps the most-important thing about CMake is that it has a variety
|
---|
745 | of CMAKE_BUILD_TYPE values, and these affect the flags. The default
|
---|
746 | is that this is not set and no flags are generated. Any CFLAGS or
|
---|
747 | CXXFLAGS in the environment will be used. If the programmer has coded
|
---|
748 | any debug assertions, those will be enabled unless -DNDEBUG is used.
|
---|
749 | The following CMAKE_BUILD_TYPE values will generate the flags shown,
|
---|
750 | and these will come <emphasis>after</emphasis> any flags in the
|
---|
751 | environment and therefore take precedence.
|
---|
752 | </para>
|
---|
753 |
|
---|
754 | <informaltable align="center">
|
---|
755 | <tgroup cols="2">
|
---|
756 | <colspec colnum="1" align="center"/>
|
---|
757 | <colspec colnum="2" align="center"/>
|
---|
758 | <thead>
|
---|
759 | <row><entry>Value</entry><entry>Flags</entry></row>
|
---|
760 | </thead>
|
---|
761 | <tbody>
|
---|
762 | <row>
|
---|
763 | <entry>Debug</entry><entry><option>-g</option></entry>
|
---|
764 | </row>
|
---|
765 | <row>
|
---|
766 | <entry>Release</entry><entry><option>-O3 -DNDEBUG</option></entry>
|
---|
767 | </row>
|
---|
768 | <row>
|
---|
769 | <entry>RelWithDebInfo</entry><entry><option>-O2 -g -DNDEBUG</option></entry>
|
---|
770 | </row>
|
---|
771 | <row>
|
---|
772 | <entry>MinSizeRel</entry><entry><option>-Os -DNDEBUG</option></entry>
|
---|
773 | </row>
|
---|
774 | </tbody>
|
---|
775 | </tgroup>
|
---|
776 | </informaltable>
|
---|
777 |
|
---|
778 | <para>
|
---|
779 | CMake tries to produce quiet builds. To see the details of the commands
|
---|
780 | which are being run, use <command>make VERBOSE=1</command> or
|
---|
781 | <command>ninja -v</command>.
|
---|
782 | </para>
|
---|
783 |
|
---|
784 | <para>
|
---|
785 | By default, CMake treats file installation differently from the other
|
---|
786 | build systems: if a file already exists and is not newer than a file
|
---|
787 | that would overwrite it, then the file is not installed. This may be
|
---|
788 | a problem if a user wants to record which file belongs to a package,
|
---|
789 | either using <envar>LD_PRELOAD</envar>, or by listing files newer
|
---|
790 | than a timestamp. The default can be changed by setting the variable
|
---|
791 | <envar>CMAKE_INSTALL_ALWAYS</envar> to 1 in the
|
---|
792 | <emphasis>environment</emphasis>, for example by
|
---|
793 | <command>export</command>'ing it.
|
---|
794 | </para>
|
---|
795 |
|
---|
796 | <bridgehead renderas="sect3" id="meson-info">Meson</bridgehead>
|
---|
797 |
|
---|
798 | <para>
|
---|
799 | Meson has some similarities to CMake, but many differences. To get
|
---|
800 | details of the defines that you may wish to change you can look at
|
---|
801 | <filename>meson_options.txt</filename> which is usually in the
|
---|
802 | top-level directory.
|
---|
803 | </para>
|
---|
804 |
|
---|
805 | <para>
|
---|
806 | If you have already configured the package by running
|
---|
807 | <command>meson</command> and now wish to change one or more settings,
|
---|
808 | you can either remove the build directory, recreate it, and use the
|
---|
809 | altered options, or within the build directory run <command>meson
|
---|
810 | configure</command>, e.g. to set an option:
|
---|
811 | </para>
|
---|
812 |
|
---|
813 | <screen><userinput>meson configure -D<some_option>=true</userinput></screen>
|
---|
814 |
|
---|
815 | <para>
|
---|
816 | If you do that, the file <filename>meson-private/cmd_line.txt</filename>
|
---|
817 | will show the <emphasis>last</emphasis> commands which were used.
|
---|
818 | </para>
|
---|
819 |
|
---|
820 | <para>
|
---|
821 | Meson provides the following buildtype values, and the flags they enable
|
---|
822 | come <emphasis>after</emphasis> any flags supplied in the environment and
|
---|
823 | therefore take precedence.
|
---|
824 | </para>
|
---|
825 |
|
---|
826 | <itemizedlist>
|
---|
827 | <listitem>
|
---|
828 | <para>plain : no added flags. This is for distributors to supply their
|
---|
829 | own CLFAGS, CXXFLAGS and LDFLAGS. There is no obvious reason to use
|
---|
830 | this in BLFS.</para>
|
---|
831 | </listitem>
|
---|
832 | <listitem>
|
---|
833 | <para>debug : '-g' - this is the default if nothing is specified
|
---|
834 | in either <filename>meson.build</filename> or the command line.
|
---|
835 | However it results large and slow binaries, so we should override
|
---|
836 | it in BLFS.</para>
|
---|
837 | </listitem>
|
---|
838 | <listitem>
|
---|
839 | <para>debugoptimized : '-O2 -g' : this is the default specified in
|
---|
840 | <filename>meson.build</filename> of some packages.</para>
|
---|
841 | </listitem>
|
---|
842 | <listitem>
|
---|
843 | <para>release : '-O3 -DNDEBUG' (but occasionally a package will force
|
---|
844 | -O2 here)</para>
|
---|
845 | </listitem>
|
---|
846 | </itemizedlist>
|
---|
847 |
|
---|
848 | <para>
|
---|
849 | Although the 'release' buildtype is described as enabling -DNDEBUG, and all
|
---|
850 | CMake Release builds pass that, it has so far only been observed (in
|
---|
851 | verbose builds) for <xref linkend="mesa"/>. That suggests that it might
|
---|
852 | only be used when there are debug assertions present.
|
---|
853 | </para>
|
---|
854 |
|
---|
855 | <para>
|
---|
856 | The -DNDEBUG flag can also be provided by passing
|
---|
857 | <command>-Db_ndebug=true</command>.
|
---|
858 | </para>
|
---|
859 |
|
---|
860 | <para>
|
---|
861 | To see the details of the commands which are being run in a package using
|
---|
862 | meson, use 'ninja -v'.
|
---|
863 | </para>
|
---|
864 |
|
---|
865 | <bridgehead renderas="sect3" id="rust-info">Rustc and Cargo</bridgehead>
|
---|
866 |
|
---|
867 | <para>
|
---|
868 | Most released rustc programs are provided as crates (source tarballs)
|
---|
869 | which will query a server to check current versions of dependencies
|
---|
870 | and then download them as necessary. These packages are built using
|
---|
871 | <command>cargo --release</command>. In theory, you can manipulate the
|
---|
872 | RUSTFLAGS to change the optimize-level (default is 3, like -O3, e.g.
|
---|
873 | <literal>-Copt-level=3</literal>) or to force it to build for the
|
---|
874 | machine it is being compiled on, using
|
---|
875 | <literal>-Ctarget-cpu=native</literal> but in practice this seems to
|
---|
876 | make no significant difference.
|
---|
877 | </para>
|
---|
878 |
|
---|
879 | <para>
|
---|
880 | If you find an interesting rustc program which is only provided as
|
---|
881 | unpackaged source, you should at least specify
|
---|
882 | <literal>RUSTFLAGS=-Copt-level=2</literal> otherwise it will do an
|
---|
883 | unoptimized compile with debug info and run <emphasis>much</emphasis>
|
---|
884 | slower.
|
---|
885 | </para>
|
---|
886 |
|
---|
887 | <para>
|
---|
888 | The rust developers seem to assume that everyone will compile on a
|
---|
889 | machine dedicated to producing builds, so by default all CPUs are used.
|
---|
890 | This can often be worked around, either by exporting
|
---|
891 | CARGO_BUILD_JOBS=<N> or passing --jobs <N> to cargo. For
|
---|
892 | compiling rustc itself, specifying --jobs <N> on invocations of
|
---|
893 | x.py (together with the <envar>CARGO_BUILD_JOBS</envar> environment
|
---|
894 | variable, which looks like a "belt and braces" approach but seems to be
|
---|
895 | necessary) mostly works. The exception is running the tests when building
|
---|
896 | rustc, some of them will nevertheless use all online CPUs, at least as of
|
---|
897 | rustc-1.42.0.
|
---|
898 | </para>
|
---|
899 |
|
---|
900 | </sect2>
|
---|
901 |
|
---|
902 | <sect2 id="optimizations">
|
---|
903 | <title>Optimizing the build</title>
|
---|
904 |
|
---|
905 | <para>
|
---|
906 | Many people will prefer to optimize compiles as they see fit, by providing
|
---|
907 | CFLAGS or CXXFLAGS. For an introduction to the options available with gcc
|
---|
908 | and g++ see <ulink
|
---|
909 | url="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html"/> and <ulink
|
---|
910 | url="https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html"/>
|
---|
911 | and <command>info gcc</command>.
|
---|
912 |
|
---|
913 | </para>
|
---|
914 |
|
---|
915 | <para>
|
---|
916 | Some packages default to '-O2 -g', others to '-O3 -g', and if CFLAGS or
|
---|
917 | CXXFLAGS are supplied they might be added to the package's defaults,
|
---|
918 | replace the package's defaults, or even be ignored. There are details
|
---|
919 | on some desktop packages which were mostly current in April 2019 at
|
---|
920 | <ulink url="https://www.linuxfromscratch.org/~ken/tuning/"/> - in
|
---|
921 | particular, README.txt, tuning-1-packages-and-notes.txt, and
|
---|
922 | tuning-notes-2B.txt. The particular thing to remember is that if you
|
---|
923 | want to try some of the more interesting flags you may need to force
|
---|
924 | verbose builds to confirm what is being used.
|
---|
925 | </para>
|
---|
926 |
|
---|
927 | <para>
|
---|
928 | Clearly, if you are optimizing your own program you can spend time to
|
---|
929 | profile it and perhaps recode some of it if it is too slow. But for
|
---|
930 | building a whole system that approach is impractical. In general,
|
---|
931 | -O3 usually produces faster programs than -O2. Specifying
|
---|
932 | -march=native is also beneficial, but means that you cannot move the
|
---|
933 | binaries to an incompatible machine - this can also apply to newer
|
---|
934 | machines, not just to older machines. For example programs compiled for
|
---|
935 | 'amdfam10' run on old Phenoms, Kaveris, and Ryzens : but programs
|
---|
936 | compiled for a Kaveri will not run on a Ryzen because certain op-codes
|
---|
937 | are not present. Similarly, if you build for a Haswell not everything
|
---|
938 | will run on a SandyBridge.
|
---|
939 | </para>
|
---|
940 |
|
---|
941 | <para>
|
---|
942 | There are also various other options which some people claim are
|
---|
943 | beneficial. At worst, you get to recompile and test, and then
|
---|
944 | discover that in your usage the options do not provide a benefit.
|
---|
945 | </para>
|
---|
946 |
|
---|
947 | <para>
|
---|
948 | If building Perl or Python modules, or Qt packages which use qmake,
|
---|
949 | in general the CFLAGS and CXXFLAGS used are those which were used by
|
---|
950 | those 'parent' packages.
|
---|
951 | </para>
|
---|
952 |
|
---|
953 | </sect2>
|
---|
954 |
|
---|
955 | <sect2 id="hardening">
|
---|
956 | <title>Options for hardening the build</title>
|
---|
957 |
|
---|
958 | <para>
|
---|
959 | Even on desktop systems, there are still a lot of exploitable
|
---|
960 | vulnerabilities. For many of these, the attack comes via javascript
|
---|
961 | in a browser. Often, a series of vulnerabilities are used to gain
|
---|
962 | access to data (or sometimes to pwn, i.e. own, the machine and
|
---|
963 | install rootkits). Most commercial distros will apply various
|
---|
964 | hardening measures.
|
---|
965 | </para>
|
---|
966 |
|
---|
967 | <para>
|
---|
968 | For hardening options which are reasonably cheap, there is some
|
---|
969 | discussion in the 'tuning' link above (occasionally, one or more
|
---|
970 | of these options might be inappropriate for a package). These
|
---|
971 | options are -D_FORTIFY_SOURCE=2, -fstack-protector=strong, and
|
---|
972 | (for C++) -D_GLIBCXX_ASSERTIONS. On modern machines these should
|
---|
973 | only have a little impact on how fast things run, and often they
|
---|
974 | will not be noticeable.
|
---|
975 | </para>
|
---|
976 |
|
---|
977 | <para>
|
---|
978 | In the past, there was Hardened LFS where gcc (a much older version)
|
---|
979 | was forced to use hardening (with options to turn some of it off on a
|
---|
980 | per-package basis. What is being covered here is different - first you
|
---|
981 | have to make sure that the package is indeed using your added flags and
|
---|
982 | not over-riding them.
|
---|
983 | </para>
|
---|
984 |
|
---|
985 | <para>
|
---|
986 | The main distros use much more, such as RELRO (Relocation Read Only)
|
---|
987 | and perhaps -fstack-clash-protection. You may also encounter the
|
---|
988 | so-called 'userspace retpoline' (-mindirect-branch=thunk etc.) which
|
---|
989 | is the equivalent of the spectre mitigations applied to the linux
|
---|
990 | kernel in late 2018). The kernel mitigations caused a lot of complaints
|
---|
991 | about lost performance, if you have a production server you might wish
|
---|
992 | to consider testing that, along with the other available options, to
|
---|
993 | see if performance is still sufficient.
|
---|
994 | </para>
|
---|
995 |
|
---|
996 | <para>
|
---|
997 | Whilst gcc has many hardening options, clang/LLVM's strengths lie
|
---|
998 | elsewhere. Some options which gcc provides are said to be less effective
|
---|
999 | in clang/LLVM.
|
---|
1000 | </para>
|
---|
1001 |
|
---|
1002 | </sect2>
|
---|
1003 |
|
---|
1004 | </sect1>
|
---|