]>
Commit | Line | Data |
---|---|---|
0af33fd8 AM |
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. | |
66c468a1 PS |
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,327 @@ | |
0af33fd8 AM |
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 | +# | |
66c468a1 | 20 | +# Usage: find-debuginfo.sh [--strict-build-id] |
0af33fd8 AM |
21 | +# [-o debugfiles.list] |
22 | +# [[-l filelist]... [-p 'pattern'] -o debuginfo.list] | |
23 | +# [builddir] | |
24 | +# | |
0af33fd8 AM |
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 | + | |
0af33fd8 AM |
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 | + ;; | |
0af33fd8 AM |
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" || : | |
66c468a1 PS |
107 | + local t=$(mktemp "/tmp/rpm.stripped.XXXXXX") |
108 | + eu-strip --strip-debug -f "$1" "$2" -o "$t" || exit | |
109 | + rm -f "$t" | |
0af33fd8 AM |
110 | +} |
111 | + | |
112 | +# Make a relative symlink to $1 called $3$2 | |
113 | +shopt -s extglob | |
114 | +link_relative() | |
115 | +{ | |
116 | + local t="$1" f="$2" pfx="$3" | |
117 | + local fn="${f#/}" tn="${t#/}" | |
118 | + local fd td d | |
119 | + | |
120 | + while fd="${fn%%/*}"; td="${tn%%/*}"; [ "$fd" = "$td" ]; do | |
121 | + fn="${fn#*/}" | |
122 | + tn="${tn#*/}" | |
123 | + done | |
124 | + | |
125 | + d="${fn%/*}" | |
126 | + if [ "$d" != "$fn" ]; then | |
127 | + d="${d//+([!\/])/..}" | |
128 | + tn="${d}/${tn}" | |
129 | + fi | |
130 | + | |
131 | + mkdir -p "$(dirname "$pfx$f")" && ln -snf "$tn" "$pfx$f" | |
132 | } | |
133 | ||
134 | +# Make a symlink in /usr/lib/debug/$2 to $1 | |
135 | +debug_link() | |
136 | +{ | |
137 | + local l="/usr/lib/debug$2" | |
138 | + local t="$1" | |
139 | + echo >> "$LINKSFILE" "$l $t" | |
140 | + link_relative "$t" "$l" "$RPM_BUILD_ROOT" | |
141 | +} | |
142 | + | |
143 | +# Make a build-id symlink for id $1 with suffix $3 to file $2. | |
144 | +make_id_link() | |
145 | +{ | |
146 | + local id="$1" file="$2" | |
147 | + local idfile=".build-id/${id:0:2}/${id:2}" | |
148 | + [ $# -eq 3 ] && idfile="${idfile}$3" | |
149 | + local root_idfile="$RPM_BUILD_ROOT/usr/lib/debug/$idfile" | |
150 | + | |
151 | + if [ ! -L "$root_idfile" ]; then | |
152 | + debug_link "$file" "/$idfile" | |
153 | + return | |
154 | + fi | |
155 | + | |
156 | + [ $# -eq 3 ] && return 0 | |
157 | + | |
158 | + local other=$(readlink -m "$root_idfile") | |
159 | + other=${other#$RPM_BUILD_ROOT} | |
160 | + if cmp -s "$root_idfile" "$RPM_BUILD_ROOT$file" || | |
161 | + eu-elfcmp -q "$root_idfile" "$RPM_BUILD_ROOT$file" 2> /dev/null; then | |
162 | + # Two copies. Maybe one has to be setuid or something. | |
163 | + echo >&2 "*** WARNING: identical binaries are copied, not linked:" | |
164 | + echo >&2 " $file" | |
165 | + echo >&2 " and $other" | |
166 | + else | |
167 | + # This is pathological, break the build. | |
168 | + echo >&2 "*** ERROR: same build ID in nonidentical files!" | |
169 | + echo >&2 " $file" | |
170 | + echo >&2 " and $other" | |
171 | + exit 2 | |
172 | + fi | |
173 | +} | |
174 | + | |
175 | +get_debugfn() | |
176 | +{ | |
177 | + dn=$(dirname "${1#$RPM_BUILD_ROOT}") | |
178 | + bn=$(basename "$1" .debug).debug | |
179 | + | |
180 | + debugdn=${debugdir}${dn} | |
181 | + debugfn=${debugdn}/${bn} | |
182 | +} | |
183 | + | |
184 | +set -o pipefail | |
185 | + | |
186 | +strict_error=ERROR | |
187 | +$strict || strict_error=WARNING | |
188 | + | |
189 | # Strip ELF binaries | |
190 | -for f in `find $RPM_BUILD_ROOT ! -path "${debugdir}/*.debug" -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) -exec file {} \; | \ | |
191 | - sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p'` | |
192 | +find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \ | |
193 | + \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \ | |
194 | + -print | | |
195 | +file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p' | | |
196 | +xargs --no-run-if-empty stat -c '%h %D_%i %n' | | |
197 | +while read nlinks inum f; do | |
198 | + get_debugfn "$f" | |
199 | + [ -f "${debugfn}" ] && continue | |
200 | + | |
201 | + # If this file has multiple links, keep track and make | |
202 | + # the corresponding .debug files all links to one file too. | |
203 | + if [ $nlinks -gt 1 ]; then | |
204 | + eval linked=\$linked_$inum | |
205 | + if [ -n "$linked" ]; then | |
206 | + link=$debugfn | |
207 | + get_debugfn "$linked" | |
208 | + echo "hard linked $link to $debugfn" | |
209 | + ln -nf "$debugfn" "$link" | |
210 | + continue | |
211 | + else | |
212 | + eval linked_$inum=\$f | |
213 | + echo "file $f has $[$nlinks - 1] other hard links" | |
214 | + fi | |
215 | + fi | |
216 | + | |
217 | + echo "extracting debug info from $f" | |
218 | + id=$(/usr/lib/rpm/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \ | |
219 | + -i -l "$SOURCEFILE" "$f") || exit | |
220 | + if [ -z "$id" ]; then | |
221 | + echo >&2 "*** ${strict_error}: No build ID note found in $f" | |
222 | + $strict && exit 2 | |
223 | + fi | |
224 | + | |
225 | + # A binary already copied into /usr/lib/debug doesn't get stripped, | |
226 | + # just has its file names collected and adjusted. | |
227 | + case "$dn" in | |
228 | + /usr/lib/debug/*) | |
229 | + [ -z "$id" ] || make_id_link "$id" "$dn/$(basename $f)" | |
230 | + continue ;; | |
231 | + esac | |
232 | + | |
233 | + mkdir -p "${debugdn}" | |
234 | + if test -w "$f"; then | |
235 | + strip_to_debug "${debugfn}" "$f" | |
236 | + else | |
237 | + chmod u+w "$f" | |
238 | + strip_to_debug "${debugfn}" "$f" | |
239 | + chmod u-w "$f" | |
240 | + fi | |
241 | + | |
242 | + if [ -n "$id" ]; then | |
243 | + make_id_link "$id" "$dn/$(basename $f)" | |
244 | + make_id_link "$id" "/usr/lib/debug$dn/$bn" .debug | |
245 | + fi | |
246 | +done || exit | |
247 | + | |
248 | +# For each symlink whose target has a .debug file, | |
249 | +# make a .debug symlink to that file. | |
250 | +find $RPM_BUILD_ROOT ! -path "${debugdir}/*" -type l -print | | |
251 | +while read f | |
252 | do | |
253 | - dn=$(dirname $f | sed -n -e "s#^$RPM_BUILD_ROOT##p") | |
254 | - bn=$(basename $f .debug).debug | |
255 | - | |
256 | - debugdn="${debugdir}${dn}" | |
257 | - debugfn="${debugdn}/${bn}" | |
258 | - [ -f "${debugfn}" ] && continue | |
259 | - | |
260 | - echo extracting debug info from $f | |
261 | - /usr/lib/rpm/4.5/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug -l "$SOURCEFILE" "$f" | |
262 | - | |
263 | - # A binary already copied into /usr/lib/debug doesn't get stripped, | |
264 | - # just has its file names collected and adjusted. | |
265 | - case "$dn" in | |
266 | - /usr/lib/debug/*) continue ;; | |
267 | - esac | |
268 | - | |
269 | - mkdir -p "${debugdn}" | |
270 | - if test -w "$f"; then | |
271 | - strip_to_debug "${debugfn}" "$f" | |
272 | - else | |
273 | - chmod u+w "$f" | |
274 | - strip_to_debug "${debugfn}" "$f" | |
275 | - chmod u-w "$f" | |
276 | - fi | |
277 | + t=$(readlink -m "$f").debug | |
278 | + f=${f#$RPM_BUILD_ROOT} | |
279 | + t=${t#$RPM_BUILD_ROOT} | |
280 | + if [ -f "$debugdir$t" ]; then | |
281 | + echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug" | |
282 | + debug_link "/usr/lib/debug$t" "${f}.debug" | |
283 | + fi | |
284 | done | |
285 | ||
286 | -mkdir -p ${RPM_BUILD_ROOT}/usr/src/debug | |
287 | -cat $SOURCEFILE | (cd $RPM_BUILD_DIR; LANG=C sort -z -u | cpio -pd0mL ${RPM_BUILD_ROOT}/usr/src/debug) | |
288 | -# stupid cpio creates new directories in mode 0700, fixup | |
289 | -find ${RPM_BUILD_ROOT}/usr/src/debug -type d -print0 | xargs -0 chmod a+rx | |
290 | +if [ -s "$SOURCEFILE" ]; then | |
291 | + mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug" | |
292 | + LC_ALL=C sort -z -u "$SOURCEFILE" | egrep -v -z '(<internal>|<built-in>)$' | | |
293 | + (cd "$RPM_BUILD_DIR"; cpio -pd0mL "${RPM_BUILD_ROOT}/usr/src/debug") | |
294 | + # stupid cpio creates new directories in mode 0700, fixup | |
295 | + find "${RPM_BUILD_ROOT}/usr/src/debug" -type d -print0 | | |
296 | + xargs --no-run-if-empty -0 chmod a+rx | |
297 | +fi | |
298 | + | |
299 | +if [ -d "${RPM_BUILD_ROOT}/usr/lib" -o -d "${RPM_BUILD_ROOT}/usr/src" ]; then | |
300 | + ((nout > 0)) || | |
301 | + test ! -d "${RPM_BUILD_ROOT}/usr/lib" || | |
302 | + (cd "${RPM_BUILD_ROOT}/usr/lib"; find debug -type d) | | |
303 | + sed 's,^,%dir /usr/lib/,' >> "$LISTFILE" | |
304 | + | |
305 | + (cd "${RPM_BUILD_ROOT}/usr" | |
306 | + test ! -d lib/debug || find lib/debug ! -type d | |
307 | + test ! -d src/debug || find src/debug -mindepth 1 -maxdepth 1 | |
308 | + ) | sed 's,^,/usr/,' >> "$LISTFILE" | |
309 | +fi | |
310 | + | |
311 | +# Append to $1 only the lines from stdin not already in the file. | |
312 | +append_uniq() | |
313 | +{ | |
314 | + fgrep -f "$1" -x -v >> "$1" | |
315 | +} | |
316 | ||
317 | -find ${RPM_BUILD_ROOT}/usr/lib/debug -type f | sed -n -e "s#^$RPM_BUILD_ROOT##p" > $LISTFILE | |
318 | -find ${RPM_BUILD_ROOT}/usr/src/debug -mindepth 1 -maxdepth 1 | sed -n -e "s#^$RPM_BUILD_ROOT##p" >> $LISTFILE | |
319 | +# Helper to generate list of corresponding .debug files from a file list. | |
320 | +filelist_debugfiles() | |
321 | +{ | |
322 | + local extra="$1" | |
323 | + shift | |
324 | + sed 's/^%[a-z0-9_][a-z0-9_]*([^)]*) *// | |
325 | +s/^%[a-z0-9_][a-z0-9_]* *// | |
326 | +/^$/d | |
327 | +'"$extra" "$@" | |
328 | +} | |
329 | + | |
330 | +# Write an output debuginfo file list based on given input file lists. | |
331 | +filtered_list() | |
332 | +{ | |
333 | + local out="$1" | |
334 | + shift | |
335 | + test $# -gt 0 || return | |
336 | + fgrep -f <(filelist_debugfiles 's,^.*$,/usr/lib/debug&.debug,' "$@") \ | |
337 | + -x $LISTFILE >> $out | |
338 | + sed -n -f <(filelist_debugfiles 's/[\\.*+#]/\\&/g | |
339 | +h | |
340 | +s,^.*$,s# &$##p,p | |
341 | +g | |
342 | +s,^.*$,s# /usr/lib/debug&.debug$##p,p | |
343 | +' "$@") "$LINKSFILE" | append_uniq "$out" | |
344 | +} | |
345 | + | |
346 | +# Write an output debuginfo file list based on an egrep-style regexp. | |
347 | +pattern_list() | |
348 | +{ | |
349 | + local out="$1" ptn="$2" | |
350 | + test -n "$ptn" || return | |
351 | + egrep -x -e "$ptn" "$LISTFILE" >> "$out" | |
352 | + sed -n -r "\#^$ptn #s/ .*\$//p" "$LINKSFILE" | append_uniq "$out" | |
353 | +} | |
354 | + | |
355 | +# | |
356 | +# When given multiple -o switches, split up the output as directed. | |
357 | +# | |
358 | +i=0 | |
359 | +while ((i < nout)); do | |
360 | + > ${outs[$i]} | |
361 | + filtered_list ${outs[$i]} ${lists[$i]} | |
362 | + pattern_list ${outs[$i]} "${ptns[$i]}" | |
363 | + fgrep -vx -f ${outs[$i]} "$LISTFILE" > "${LISTFILE}.new" | |
364 | + mv "${LISTFILE}.new" "$LISTFILE" | |
365 | + ((++i)) | |
366 | +done | |
367 | +if ((nout > 0)); then | |
368 | + # Now add the right %dir lines to each output list. | |
369 | + (cd "${RPM_BUILD_ROOT}"; find usr/lib/debug -type d) | | |
370 | + sed 's#^.*$#\\@^/&/@{h;s@^.*$@%dir /&@p;g;}#' | | |
371 | + LC_ALL=C sort -ur > "${LISTFILE}.dirs.sed" | |
372 | + i=0 | |
373 | + while ((i < nout)); do | |
374 | + sed -n -f "${LISTFILE}.dirs.sed" "${outs[$i]}" | sort -u > "${outs[$i]}.new" | |
375 | + cat "${outs[$i]}" >> "${outs[$i]}.new" | |
376 | + mv -f "${outs[$i]}.new" "${outs[$i]}" | |
377 | + ((++i)) | |
378 | + done | |
379 | + sed -n -f "${LISTFILE}.dirs.sed" "${LISTFILE}" | sort -u > "${LISTFILE}.new" | |
380 | + cat "$LISTFILE" >> "${LISTFILE}.new" | |
381 | + mv "${LISTFILE}.new" "$LISTFILE" | |
382 | +fi |