Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • introduction/important/building-notes.xml

    r97ba425 r3f2db3a6  
    99  <?dbhtml filename="notes-on-building.html"?>
    1010
    11   <sect1info>
    12     <date>$Date$</date>
    13   </sect1info>
    1411
    1512  <title>Notes on Building Software</title>
     
    136133    <emphasis role="bold">official</emphasis> website (or somewhere
    137134    <emphasis role="bold">you can trust</emphasis>) and compare the
    138     checksum of the package from unoffical location with it.  For example,
     135    checksum of the package from unofficial location with it.  For example,
    139136    SHA256 checksum can be checked with the command:</para>
    140137
     
    207204    <screen><userinput>make -j2</userinput></screen>
    208205
     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 &lt;N&gt;+2, where &lt;N&gt;
     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
    209226    <para>Generally the number of processes should not exceed the number of
    210227    cores supported by the CPU.  To list the processors on your
     
    212229    </para>
    213230
    214     <para>In some cases, using multiple processors may result in a 'race'
     231    <para>In some cases, using multiple processes may result in a 'race'
    215232    condition where the success of the build depends on the order of the
    216233    commands run by the <command>make</command> program.  For instance, if an
     
    223240    <para>If this occurs, the best way to proceed is to drop back to a
    224241    single processor build.  Adding '-j1' to a make command will override
    225     the similar setting in the MAKEFLAGS environment variable.</para>
     242    the similar setting in the <envar>MAKEFLAGS</envar> environment
     243    variable.</para>
    226244
    227245    <note><para>When running the package tests or the install portion of the
     
    231249    that are difficult to debug.</para></note>
    232250
     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>
    233267  </sect2>
    234268
     
    462496    <title>Stripping One More Time</title>
    463497
    464     <warning>
    465       <para>If you did not strip programs and libraries in LFS,
    466       the following will probably make your system unusable. To avoid that,
    467       run the instructions at <ulink url="&lfs-root;/chapter08/strippingagain.html"/>
    468       instead.  After the critical files are  stripped using those instructions,
    469       the instructions below can be run any time new packages are installed.
    470       </para>
    471     </warning>
    472 
    473     <para>
    474       In LFS, stripping of debugging symbols was discussed a couple of
    475       times.  When building BLFS packages, there are generally no special
    476       instructions that discuss stripping again.  It is probably not a good
    477       idea to strip an executable or a library while it is in use, so exiting
    478       any windowing environment is a good idea.  Then you can do:
    479     </para>
    480 
    481 <screen><userinput>find /usr/{bin,lib,sbin} \
    482     -type f \( -name \*.so* -a ! -name \*dbg \) \
    483     -exec strip --strip-unneeded {} \;</userinput></screen>
     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&lt;something&gt;</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
     576      may break anything using it if it is loaded in memory. Note that
     577      if a file is in use but just removed from the disk (i.e. not overwritten
     578      nor modified), this is not a problem since the kernel can use
     579      <quote>deleted</quote> files.
     580      Look at <filename>/proc/*/maps</filename>, and it is likely that
     581      you'll see some <emphasis>(deleted)</emphasis> entries. The
     582      <command>mv</command> just removes the destination file from the
     583      directory but does not touch its content, so that it satisfies the
     584      condition for the kernel to use the old (deleted) file. The script
     585      below is just an example. Feel free to add stronger error detection,
     586      other directories to scan, etcetera. It should be run as the &root; user:
     587    </para>
     588
     589<screen role="root"><userinput>{ find /usr/lib -type f \( -name \*.a -o \
     590    \( -name \*.so* ! -name \*dbg \) \)
     591 find /usr/{bin,sbin,libexec} -type f; } | while read file; do
     592      if readelf -h $file >/dev/null 2>&amp;1; then
     593        cp -a $file ${file}.tmp            &amp;&amp;
     594        strip --strip-unneeded ${file}.tmp &amp;&amp;
     595        mv ${file}.tmp $file
     596      fi
     597    done</userinput></screen>
    484598
    485599    <para>
     
    492606    <para>
    493607      For more information on stripping, see <ulink
    494       url="http://www.technovelty.org/linux/stripping-shared-libraries.html"/>.
    495     </para>
    496 
    497   </sect2>
     608      url="https://www.technovelty.org/linux/stripping-shared-libraries.html"/>.
     609    </para>
     610
     611  </sect2>
     612
    498613<!--
    499614  <sect2 id="libtool">
     
    623738      </para>
    624739
    625       <itemizedlist>
    626         <listitem>
    627           <para>Debug : '-g'</para>
    628         </listitem>
    629         <listitem>
    630           <para>Release : '-O3 -DNDEBUG'</para>
    631         </listitem>
    632         <listitem>
    633            <para>RelWithDebInfo : '-O2 -g -DNDEBUG'</para>
    634         </listitem>
    635         <listitem>
    636            <para>MinSizeRel : '-Os -DNDEBUG'</para>
    637         </listitem>
    638       </itemizedlist>
     740      <informaltable align="center">
     741        <tgroup cols="2">
     742          <colspec colnum="1" align="center"/>
     743          <colspec colnum="2" align="center"/>
     744          <thead>
     745            <row><entry>Value</entry><entry>Flags</entry></row>
     746          </thead>
     747          <tbody>
     748            <row>
     749              <entry>Debug</entry><entry><option>-g</option></entry>
     750            </row>
     751            <row>
     752              <entry>Release</entry><entry><option>-O3 -DNDEBUG</option></entry>
     753            </row>
     754            <row>
     755              <entry>RelWithDebInfo</entry><entry><option>-O2 -g -DNDEBUG</option></entry>
     756            </row>
     757            <row>
     758              <entry>MinSizeRel</entry><entry><option>-Os -DNDEBUG</option></entry>
     759            </row>
     760          </tbody>
     761        </tgroup>
     762      </informaltable>
    639763
    640764      <para>
    641765        CMake tries to produce quiet builds. To see the details of the commands
    642         which are being run, use 'make VERBOSE=1' or 'ninja -v'.
     766        which are being run, use <command>make VERBOSE=1</command> or
     767        <command>ninja -v</command>.
     768      </para>
     769
     770      <para>
     771        By default, CMake treats file installation differently from the other
     772        build systems: if a file already exists and is not newer than a file
     773        that would overwrite it, then the file is not installed. This may be
     774        a problem if a user wants to record which file belongs to a package,
     775        either using <envar>LD_PRELOAD</envar>, or by listing files newer
     776        than a timestamp. The default can be changed by setting the variable
     777        <envar>CMAKE_INSTALL_ALWAYS</envar> to 1 in the
     778        <emphasis>environment</emphasis>, for example by
     779        <command>export</command>'ing it.
    643780      </para>
    644781
Note: See TracChangeset for help on using the changeset viewer.