]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-new-debuginfo.patch
- compress debuginfo sections with zlib (reduce /usr/lib/debug size).
[packages/rpm.git] / rpm-new-debuginfo.patch
1 --- rpm-4.5/macros.in.org       2009-03-23 09:25:24.383581794 +0100
2 +++ rpm-4.5/macros.in   2009-03-23 09:25:19.403234944 +0100
3 @@ -183,7 +183,7 @@
4  #      Path to script that creates debug symbols in a /usr/lib/debug
5  #      shadow tree.
6  %__debug_install_post   \
7 -   %{_rpmhome}/find-debuginfo.sh %{_builddir}/%{?buildsubdir}\
8 +   %{_rpmhome}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
9  %{nil}
10  
11  #      Template for debug information sub-package.
12 --- rpm-4.5/scripts/find-debuginfo.sh.orig      2007-08-31 03:07:02.000000000 +0200
13 +++ rpm-4.5/scripts/find-debuginfo.sh   2009-09-17 15:22:30.299290490 +0200
14 @@ -1,57 +1,328 @@
15 -#!/bin/sh
16 +#!/bin/bash
17  #find-debuginfo.sh - automagically generate debug info and file list
18  #for inclusion in an rpm spec file.
19 +#
20 +# Usage: find-debuginfo.sh [--strict-build-id]
21 +#                         [-o debugfiles.list]
22 +#                         [[-l filelist]... [-p 'pattern'] -o debuginfo.list]
23 +#                         [builddir]
24 +#
25 +# The --strict-build-id flag says to exit with failure status if
26 +# any ELF binary processed fails to contain a build-id note.
27 +#
28 +# A single -o switch before any -l or -p switches simply renames
29 +# the primary output file from debugfiles.list to something else.
30 +# A -o switch that follows a -p switch or some -l switches produces
31 +# an additional output file with the debuginfo for the files in
32 +# the -l filelist file, or whose names match the -p pattern.
33 +# The -p argument is an egrep-style regexp matching the a file name,
34 +# and must not use anchors (^ or $).
35 +#
36 +# All file names in switches are relative to builddir (. if not given).
37 +#
38 +
39 +# Barf on missing build IDs.
40 +strict=false
41 +
42 +BUILDDIR=.
43 +out=debugfiles.list
44 +nout=0
45 +while [ $# -gt 0 ]; do
46 +  case "$1" in
47 +  --strict-build-id)
48 +    strict=true
49 +    ;;
50 +  -o)
51 +    if [ -z "${lists[$nout]}" -a -z "${ptns[$nout]}" ]; then
52 +      out=$2
53 +    else
54 +      outs[$nout]=$2
55 +      ((nout++))
56 +    fi
57 +    shift
58 +    ;;
59 +  -l)
60 +    lists[$nout]="${lists[$nout]} $2"
61 +    shift
62 +    ;;
63 +  -p)
64 +    ptns[$nout]=$2
65 +    shift
66 +    ;;
67 +  *)
68 +    BUILDDIR=$1
69 +    shift
70 +    break
71 +    ;;
72 +  esac
73 +  shift
74 +done
75  
76 -if [ -z "$1" ] ; then BUILDDIR="."
77 -else BUILDDIR=$1
78 -fi
79 +i=0
80 +while ((i < nout)); do
81 +  outs[$i]="$BUILDDIR/${outs[$i]}"
82 +  l=''
83 +  for f in ${lists[$i]}; do
84 +    l="$l $BUILDDIR/$f"
85 +  done
86 +  lists[$i]=$l
87 +  ((++i))
88 +done
89  
90 -LISTFILE=$BUILDDIR/debugfiles.list
91 -SOURCEFILE=$BUILDDIR/debugsources.list
92 +LISTFILE="$BUILDDIR/$out"
93 +SOURCEFILE="$BUILDDIR/debugsources.list"
94 +LINKSFILE="$BUILDDIR/debuglinks.list"
95 +
96 +> "$SOURCEFILE"
97 +> "$LISTFILE"
98 +> "$LINKSFILE"
99  
100  debugdir="${RPM_BUILD_ROOT}/usr/lib/debug"
101  
102 -echo -n > $SOURCEFILE
103 -
104  strip_to_debug()
105  {
106 -  eu-strip --remove-comment -f "$1" "$2" || :
107 +  local t=$(mktemp "/tmp/rpm.stripped.XXXXXX")
108 +  objcopy --compress-debug-sections "$2" || exit
109 +  eu-strip --remove-comment -f "$1" "$2" -o "$t" || exit
110 +  rm -f "$t"
111 +}
112 +
113 +# Make a relative symlink to $1 called $3$2
114 +shopt -s extglob
115 +link_relative()
116 +{
117 +  local t="$1" f="$2" pfx="$3"
118 +  local fn="${f#/}" tn="${t#/}"
119 +  local fd td d
120 +
121 +  while fd="${fn%%/*}"; td="${tn%%/*}"; [ "$fd" = "$td" ]; do
122 +    fn="${fn#*/}"
123 +    tn="${tn#*/}"
124 +  done
125 +
126 +  d="${fn%/*}"
127 +  if [ "$d" != "$fn" ]; then
128 +    d="${d//+([!\/])/..}"
129 +    tn="${d}/${tn}"
130 +  fi
131 +
132 +  mkdir -p "$(dirname "$pfx$f")" && ln -snf "$tn" "$pfx$f"
133  }
134  
135 +# Make a symlink in /usr/lib/debug/$2 to $1
136 +debug_link()
137 +{
138 +  local l="/usr/lib/debug$2"
139 +  local t="$1"
140 +  echo >> "$LINKSFILE" "$l $t"
141 +  link_relative "$t" "$l" "$RPM_BUILD_ROOT"
142 +}
143 +
144 +# Make a build-id symlink for id $1 with suffix $3 to file $2.
145 +make_id_link()
146 +{
147 +  local id="$1" file="$2"
148 +  local idfile=".build-id/${id:0:2}/${id:2}"
149 +  [ $# -eq 3 ] && idfile="${idfile}$3"
150 +  local root_idfile="$RPM_BUILD_ROOT/usr/lib/debug/$idfile"
151 +
152 +  if [ ! -L "$root_idfile" ]; then
153 +    debug_link "$file" "/$idfile"
154 +    return
155 +  fi
156 +
157 +  [ $# -eq 3 ] && return 0
158 +
159 +  local other=$(readlink -m "$root_idfile")
160 +  other=${other#$RPM_BUILD_ROOT}
161 +  if cmp -s "$root_idfile" "$RPM_BUILD_ROOT$file" ||
162 +     eu-elfcmp -q "$root_idfile" "$RPM_BUILD_ROOT$file" 2> /dev/null; then
163 +    # Two copies.  Maybe one has to be setuid or something.
164 +    echo >&2 "*** WARNING: identical binaries are copied, not linked:"
165 +    echo >&2 "        $file"
166 +    echo >&2 "   and  $other"
167 +  else
168 +    # This is pathological, break the build.
169 +    echo >&2 "*** ERROR: same build ID in nonidentical files!"
170 +    echo >&2 "        $file"
171 +    echo >&2 "   and  $other"
172 +    exit 2
173 +  fi
174 +}
175 +
176 +get_debugfn()
177 +{
178 +  dn=$(dirname "${1#$RPM_BUILD_ROOT}")
179 +  bn=$(basename "$1" .debug).debug
180 +
181 +  debugdn=${debugdir}${dn}
182 +  debugfn=${debugdn}/${bn}
183 +}
184 +
185 +set -o pipefail
186 +
187 +strict_error=ERROR
188 +$strict || strict_error=WARNING
189 +
190  # Strip ELF binaries
191 -for f in `find $RPM_BUILD_ROOT ! -path "${debugdir}/*.debug" -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) -exec file {} \; | \
192 -       sed -n -e 's/^\(.*\):[  ]*.*ELF.*, not stripped/\1/p'`
193 +find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \
194 +                    \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
195 +                    -print |
196 +file -N -f - | sed -n -e 's/^\(.*\):[  ]*.*ELF.*, not stripped/\1/p' |
197 +xargs --no-run-if-empty stat -c '%h %D_%i %n' |
198 +while read nlinks inum f; do
199 +  get_debugfn "$f"
200 +  [ -f "${debugfn}" ] && continue
201 +
202 +  # If this file has multiple links, keep track and make
203 +  # the corresponding .debug files all links to one file too.
204 +  if [ $nlinks -gt 1 ]; then
205 +    eval linked=\$linked_$inum
206 +    if [ -n "$linked" ]; then
207 +      link=$debugfn
208 +      get_debugfn "$linked"
209 +      echo "hard linked $link to $debugfn"
210 +      ln -nf "$debugfn" "$link"
211 +      continue
212 +    else
213 +      eval linked_$inum=\$f
214 +      echo "file $f has $[$nlinks - 1] other hard links"
215 +    fi
216 +  fi
217 +
218 +  echo "extracting debug info from $f"
219 +  id=$(/usr/lib/rpm/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \
220 +                             -i -l "$SOURCEFILE" "$f") || exit
221 +  if [ -z "$id" ]; then
222 +    echo >&2 "*** ${strict_error}: No build ID note found in $f"
223 +    $strict && exit 2
224 +  fi
225 +
226 +  # A binary already copied into /usr/lib/debug doesn't get stripped,
227 +  # just has its file names collected and adjusted.
228 +  case "$dn" in
229 +  /usr/lib/debug/*)
230 +    [ -z "$id" ] || make_id_link "$id" "$dn/$(basename $f)"
231 +    continue ;;
232 +  esac
233 +
234 +  mkdir -p "${debugdn}"
235 +  if test -w "$f"; then
236 +    strip_to_debug "${debugfn}" "$f"
237 +  else
238 +    chmod u+w "$f"
239 +    strip_to_debug "${debugfn}" "$f"
240 +    chmod u-w "$f"
241 +  fi
242 +
243 +  if [ -n "$id" ]; then
244 +    make_id_link "$id" "$dn/$(basename $f)"
245 +    make_id_link "$id" "/usr/lib/debug$dn/$bn" .debug
246 +  fi
247 +done || exit
248 +
249 +# For each symlink whose target has a .debug file,
250 +# make a .debug symlink to that file.
251 +find $RPM_BUILD_ROOT ! -path "${debugdir}/*" -type l -print |
252 +while read f
253  do
254 -       dn=$(dirname $f | sed -n -e "s#^$RPM_BUILD_ROOT##p")
255 -       bn=$(basename $f .debug).debug
256 -
257 -       debugdn="${debugdir}${dn}"
258 -       debugfn="${debugdn}/${bn}"
259 -       [ -f "${debugfn}" ] && continue
260 -
261 -       echo extracting debug info from $f
262 -       /usr/lib/rpm/4.5/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug -l "$SOURCEFILE" "$f"
263 -
264 -       # A binary already copied into /usr/lib/debug doesn't get stripped,
265 -       # just has its file names collected and adjusted.
266 -       case "$dn" in
267 -       /usr/lib/debug/*) continue ;;
268 -       esac
269 -
270 -       mkdir -p "${debugdn}"
271 -       if test -w "$f"; then
272 -               strip_to_debug "${debugfn}" "$f"
273 -       else
274 -               chmod u+w "$f"
275 -               strip_to_debug "${debugfn}" "$f"
276 -               chmod u-w "$f"
277 -       fi
278 +  t=$(readlink -m "$f").debug
279 +  f=${f#$RPM_BUILD_ROOT}
280 +  t=${t#$RPM_BUILD_ROOT}
281 +  if [ -f "$debugdir$t" ]; then
282 +    echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug"
283 +    debug_link "/usr/lib/debug$t" "${f}.debug"
284 +  fi
285  done
286  
287 -mkdir -p ${RPM_BUILD_ROOT}/usr/src/debug
288 -cat $SOURCEFILE | (cd $RPM_BUILD_DIR; LANG=C sort -z -u | cpio -pd0mL ${RPM_BUILD_ROOT}/usr/src/debug)
289 -# stupid cpio creates new directories in mode 0700, fixup
290 -find ${RPM_BUILD_ROOT}/usr/src/debug -type d -print0 | xargs -0 chmod a+rx
291 +if [ -s "$SOURCEFILE" ]; then
292 +  mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug"
293 +  LC_ALL=C sort -z -u "$SOURCEFILE" | egrep -v -z '(<internal>|<built-in>)$' |
294 +  (cd "$RPM_BUILD_DIR"; cpio -pd0mL "${RPM_BUILD_ROOT}/usr/src/debug")
295 +  # stupid cpio creates new directories in mode 0700, fixup
296 +  find "${RPM_BUILD_ROOT}/usr/src/debug" -type d -print0 |
297 +  xargs --no-run-if-empty -0 chmod a+rx
298 +fi
299 +
300 +if [ -d "${RPM_BUILD_ROOT}/usr/lib" -o -d "${RPM_BUILD_ROOT}/usr/src" ]; then
301 +  ((nout > 0)) ||
302 +  test ! -d "${RPM_BUILD_ROOT}/usr/lib" ||
303 +  (cd "${RPM_BUILD_ROOT}/usr/lib"; find debug -type d) |
304 +  sed 's,^,%dir /usr/lib/,' >> "$LISTFILE"
305 +
306 +  (cd "${RPM_BUILD_ROOT}/usr"
307 +   test ! -d lib/debug || find lib/debug ! -type d
308 +   test ! -d src/debug || find src/debug -mindepth 1 -maxdepth 1
309 +  ) | sed 's,^,/usr/,' >> "$LISTFILE"
310 +fi
311 +
312 +# Append to $1 only the lines from stdin not already in the file.
313 +append_uniq()
314 +{
315 +  fgrep -f "$1" -x -v >> "$1"
316 +}
317  
318 -find ${RPM_BUILD_ROOT}/usr/lib/debug -type f | sed -n -e "s#^$RPM_BUILD_ROOT##p" > $LISTFILE
319 -find ${RPM_BUILD_ROOT}/usr/src/debug -mindepth 1 -maxdepth 1 | sed -n -e "s#^$RPM_BUILD_ROOT##p" >> $LISTFILE
320 +# Helper to generate list of corresponding .debug files from a file list.
321 +filelist_debugfiles()
322 +{
323 +  local extra="$1"
324 +  shift
325 +  sed 's/^%[a-z0-9_][a-z0-9_]*([^)]*) *//
326 +s/^%[a-z0-9_][a-z0-9_]* *//
327 +/^$/d
328 +'"$extra" "$@"
329 +}
330 +
331 +# Write an output debuginfo file list based on given input file lists.
332 +filtered_list()
333 +{
334 +  local out="$1"
335 +  shift
336 +  test $# -gt 0 || return
337 +  fgrep -f <(filelist_debugfiles 's,^.*$,/usr/lib/debug&.debug,' "$@") \
338 +       -x $LISTFILE >> $out
339 +  sed -n -f <(filelist_debugfiles 's/[\\.*+#]/\\&/g
340 +h
341 +s,^.*$,s# &$##p,p
342 +g
343 +s,^.*$,s# /usr/lib/debug&.debug$##p,p
344 +' "$@") "$LINKSFILE" | append_uniq "$out"
345 +}
346 +
347 +# Write an output debuginfo file list based on an egrep-style regexp.
348 +pattern_list()
349 +{
350 +  local out="$1" ptn="$2"
351 +  test -n "$ptn" || return
352 +  egrep -x -e "$ptn" "$LISTFILE" >> "$out"
353 +  sed -n -r "\#^$ptn #s/ .*\$//p" "$LINKSFILE" | append_uniq "$out"
354 +}
355 +
356 +#
357 +# When given multiple -o switches, split up the output as directed.
358 +#
359 +i=0
360 +while ((i < nout)); do
361 +  > ${outs[$i]}
362 +  filtered_list ${outs[$i]} ${lists[$i]}
363 +  pattern_list ${outs[$i]} "${ptns[$i]}"
364 +  fgrep -vx -f ${outs[$i]} "$LISTFILE" > "${LISTFILE}.new"
365 +  mv "${LISTFILE}.new" "$LISTFILE"
366 +  ((++i))
367 +done
368 +if ((nout > 0)); then
369 +  # Now add the right %dir lines to each output list.
370 +  (cd "${RPM_BUILD_ROOT}"; find usr/lib/debug -type d) |
371 +  sed 's#^.*$#\\@^/&/@{h;s@^.*$@%dir /&@p;g;}#' |
372 +  LC_ALL=C sort -ur > "${LISTFILE}.dirs.sed"
373 +  i=0
374 +  while ((i < nout)); do
375 +    sed -n -f "${LISTFILE}.dirs.sed" "${outs[$i]}" | sort -u > "${outs[$i]}.new"
376 +    cat "${outs[$i]}" >> "${outs[$i]}.new"
377 +    mv -f "${outs[$i]}.new" "${outs[$i]}"
378 +    ((++i))
379 +  done
380 +  sed -n -f "${LISTFILE}.dirs.sed" "${LISTFILE}" | sort -u > "${LISTFILE}.new"
381 +  cat "$LISTFILE" >> "${LISTFILE}.new"
382 +  mv "${LISTFILE}.new" "$LISTFILE"
383 +fi
This page took 0.081194 seconds and 3 git commands to generate.