Changeset 17fe56e1


Ignore:
Timestamp:
01/06/2023 09:13:50 PM (16 months ago)
Author:
Bruce Dubbs <bdubbs@…>
Branches:
11.3, 12.0, 12.1, kea, ken/TL2024, ken/inkscape-core-mods, ken/tuningfonts, lazarus, lxqt, plabs/newcss, plabs/python-mods, python3.11, qt5new, rahul/power-profiles-daemon, renodr/vulkan-addition, trunk, xry111/llvm18, xry111/xf86-video-removal
Children:
0ebd12a3
Parents:
9de2208
Message:

Update discussion of stripping installed files

Reformat the script and in the stripping section to make
it more clear and make it executable.

File:
1 edited

Legend:

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

    r9de2208 r17fe56e1  
    573573
    574574    <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>
     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 &gt; strip-all.sh &lt;&lt; "EOF"
     589<literal>#!/bin/bash
     590
     591if [ $EUID -ne 0 ]; then
     592  echo "Need to be root"
     593  exit 1
     594fi
     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>&amp;1; then continue; fi
     601       if $( file $file | grep --quiet --invert-match 'not stripped' ); then
     602         continue;
     603       fi
     604
     605       base=$(basename $file)
     606       cp --preserve $file    ${base}.tmp
     607       strip --strip-unneeded ${base}.tmp
     608       mv ${base}.tmp $file
     609     done</literal>
     610EOF
     611chmod 755 strip-all.sh</userinput></screen>
    598612
    599613    <para>
     
    601615      class="directory">/opt</filename> or <filename
    602616      class="directory">/usr/local</filename>, you may want to strip the files
    603       there too.
     617      there too. Just add other directories to scan in the compound list of
     618      <command>find</command> commands between the braces.
    604619    </para>
    605620
Note: See TracChangeset for help on using the changeset viewer.