Changeset 1029 for rpm/trunk/scripts/find-debuginfo.sh
- Timestamp:
- Feb 24, 2017, 12:29:59 AM (8 years ago)
- Location:
- rpm/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
rpm/trunk
- Property svn:mergeinfo changed
/rpm/vendor/current merged: 590,997
- Property svn:mergeinfo changed
-
rpm/trunk/scripts/find-debuginfo.sh
r594 r1029 3 3 #for inclusion in an rpm spec file. 4 4 # 5 # Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] 5 # Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m] 6 6 # [-o debugfiles.list] 7 # [--run-dwz] [--dwz-low-mem-die-limit N] 8 # [--dwz-max-die-limit N] 7 9 # [[-l filelist]... [-p 'pattern'] -o debuginfo.list] 8 10 # [builddir] … … 21 23 # and must not use anchors (^ or $). 22 24 # 25 # The --run-dwz flag instructs find-debuginfo.sh to run the dwz utility 26 # if available, and --dwz-low-mem-die-limit and --dwz-max-die-limit 27 # provide detailed limits. See dwz(1) -l and -L option for details. 28 # 23 29 # All file names in switches are relative to builddir (. if not given). 24 30 # 31 32 # Figure out where we are installed so we can call other helper scripts. 33 lib_rpm_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 25 34 26 35 # With -g arg, pass it to strip on libraries or executables. … … 30 39 strip_r=false 31 40 41 # with -m arg, add minimal debuginfo to binary. 42 include_minidebug=false 43 32 44 # Barf on missing build IDs. 33 45 strict=false 46 47 # DWZ parameters. 48 run_dwz=false 49 dwz_low_mem_die_limit= 50 dwz_max_die_limit= 34 51 35 52 BUILDDIR=. … … 41 58 strict=true 42 59 ;; 60 --run-dwz) 61 run_dwz=true 62 ;; 63 --dwz-low-mem-die-limit) 64 dwz_low_mem_die_limit=$2 65 shift 66 ;; 67 --dwz-max-die-limit) 68 dwz_max_die_limit=$2 69 shift 70 ;; 43 71 -g) 44 72 strip_g=true 73 ;; 74 -m) 75 include_minidebug=true 45 76 ;; 46 77 -o) … … 87 118 SOURCEFILE="$BUILDDIR/debugsources.list" 88 119 LINKSFILE="$BUILDDIR/debuglinks.list" 120 ELFBINSFILE="$BUILDDIR/elfbins.list" 89 121 90 122 > "$SOURCEFILE" 91 123 > "$LISTFILE" 92 124 > "$LINKSFILE" 125 > "$ELFBINSFILE" 93 126 94 127 debugdir="${RPM_BUILD_ROOT}/usr/lib/debug" … … 105 138 eu-strip --remove-comment $r $g -f "$1" "$2" || exit 106 139 chmod 444 "$1" || exit 140 } 141 142 add_minidebug() 143 { 144 local debuginfo="$1" 145 local binary="$2" 146 147 local dynsyms=`mktemp` 148 local funcsyms=`mktemp` 149 local keep_symbols=`mktemp` 150 local mini_debuginfo=`mktemp` 151 152 # In the minisymtab we don't need the .debug_ sections (already removed 153 # by -S) but also not any other non-allocated PROGBITS or NOTE sections. 154 # List and remove them explicitly. We do want to keep the allocated, 155 # symbol and NOBITS sections so cannot use --keep-only because that is 156 # too agressive. Field $2 is the section name, $3 is the section type 157 # and $8 are the section flags. 158 local remove_sections=`readelf -W -S "$debuginfo" | awk '{ if (index($2,".debug_") != 1 && ($3 == "PROGBITS" || $3 == "NOTE") && index($8,"A") == 0) printf "--remove-section "$2" " }'` 159 160 # Extract the dynamic symbols from the main binary, there is no need to also have these 161 # in the normal symbol table 162 nm -D "$binary" --format=posix --defined-only | awk '{ print $1 }' | sort > "$dynsyms" 163 # Extract all the text (i.e. function) symbols from the debuginfo 164 # Use format sysv to make sure we can match against the actual ELF FUNC 165 # symbol type. The binutils nm posix format symbol type chars are 166 # ambigous for architectures that might use function descriptors. 167 nm "$debuginfo" --format=sysv --defined-only | awk -F \| '{ if ($4 ~ "FUNC") print $1 }' | sort > "$funcsyms" 168 # Keep all the function symbols not already in the dynamic symbol table 169 comm -13 "$dynsyms" "$funcsyms" > "$keep_symbols" 170 # Copy the full debuginfo, keeping only a minumal set of symbols and removing some unnecessary sections 171 objcopy -S $remove_sections --keep-symbols="$keep_symbols" "$debuginfo" "$mini_debuginfo" &> /dev/null 172 #Inject the compressed data into the .gnu_debugdata section of the original binary 173 xz "$mini_debuginfo" 174 mini_debuginfo="${mini_debuginfo}.xz" 175 objcopy --add-section .gnu_debugdata="$mini_debuginfo" "$binary" 176 rm -f "$dynsyms" "$funcsyms" "$keep_symbols" "$mini_debuginfo" 107 177 } 108 178 … … 233 303 234 304 echo "extracting debug info from $f" 235 id=$( /usr/lib/rpm/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \305 id=$(${lib_rpm_dir}/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \ 236 306 -i -l "$SOURCEFILE" "$f") || exit 237 307 if [ $nlinks -gt 1 ]; then … … 243 313 fi 244 314 245 [ -x /usr/bin/gdb-add-index ] && /usr/bin/gdb-add-index "$f" > /dev/null 2>&1315 [ type gdb-add-index >/dev/null 2>&1 && gdb-add-index "$f" > /dev/null 2>&1 246 316 247 317 # A binary already copied into /usr/lib/debug doesn't get stripped, … … 262 332 fi 263 333 334 # strip -g implies we have full symtab, don't add mini symtab in that case. 335 $strip_g || ($include_minidebug && add_minidebug "${debugfn}" "$f") 336 337 echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE" 338 264 339 if [ -n "$id" ]; then 265 340 make_id_link "$id" "$dn/$(basename $f)" … … 267 342 fi 268 343 done || exit 344 345 # Invoke the DWARF Compressor utility. 346 if $run_dwz && type dwz >/dev/null 2>&1 \ 347 && [ -d "${RPM_BUILD_ROOT}/usr/lib/debug" ]; then 348 dwz_files="`cd "${RPM_BUILD_ROOT}/usr/lib/debug"; find -type f -name \*.debug`" 349 if [ -n "${dwz_files}" ]; then 350 dwz_multifile_name="${RPM_PACKAGE_NAME}-${RPM_PACKAGE_VERSION}-${RPM_PACKAGE_RELEASE}.${RPM_ARCH}" 351 dwz_multifile_suffix= 352 dwz_multifile_idx=0 353 while [ -f "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}${dwz_multifile_suffix}" ]; do 354 let ++dwz_multifile_idx 355 dwz_multifile_suffix=".${dwz_multifile_idx}" 356 done 357 dwz_multfile_name="${dwz_multifile_name}${dwz_multifile_suffix}" 358 dwz_opts="-h -q -r -m .dwz/${dwz_multifile_name}" 359 mkdir -p "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" 360 [ -n "${dwz_low_mem_die_limit}" ] \ 361 && dwz_opts="${dwz_opts} -l ${dwz_low_mem_die_limit}" 362 [ -n "${dwz_max_die_limit}" ] \ 363 && dwz_opts="${dwz_opts} -L ${dwz_max_die_limit}" 364 ( cd "${RPM_BUILD_ROOT}/usr/lib/debug" && dwz $dwz_opts $dwz_files ) 365 # Remove .dwz directory if empty 366 rmdir "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" 2>/dev/null 367 if [ -f "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}" ]; then 368 id="`readelf -Wn "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}" \ 369 2>/dev/null | sed -n 's/^ Build ID: \([0-9a-f]\+\)/\1/p'`" 370 [ -n "$id" ] \ 371 && make_id_link "$id" "/usr/lib/debug/.dwz/${dwz_multifile_name}" .debug 372 fi 373 374 # dwz invalidates .gnu_debuglink CRC32 in the main files. 375 cat "$ELFBINSFILE" | 376 (cd "$RPM_BUILD_ROOT"; \ 377 xargs -d '\n' ${lib_rpm_dir}/sepdebugcrcfix usr/lib/debug) 378 fi 379 fi 269 380 270 381 # For each symlink whose target has a .debug file,
Note:
See TracChangeset
for help on using the changeset viewer.