Ignore:
Timestamp:
Feb 24, 2017, 12:29:59 AM (8 years ago)
Author:
dmik
Message:

rpm: Merge version 4.13.0 from vendor to trunk.

Location:
rpm/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rpm/trunk

  • rpm/trunk/scripts/find-debuginfo.sh

    r594 r1029  
    33#for inclusion in an rpm spec file.
    44#
    5 # Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r]
     5# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m]
    66#                          [-o debugfiles.list]
     7#                          [--run-dwz] [--dwz-low-mem-die-limit N]
     8#                          [--dwz-max-die-limit N]
    79#                          [[-l filelist]... [-p 'pattern'] -o debuginfo.list]
    810#                          [builddir]
     
    2123# and must not use anchors (^ or $).
    2224#
     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#
    2329# All file names in switches are relative to builddir (. if not given).
    2430#
     31
     32# Figure out where we are installed so we can call other helper scripts.
     33lib_rpm_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    2534
    2635# With -g arg, pass it to strip on libraries or executables.
     
    3039strip_r=false
    3140
     41# with -m arg, add minimal debuginfo to binary.
     42include_minidebug=false
     43
    3244# Barf on missing build IDs.
    3345strict=false
     46
     47# DWZ parameters.
     48run_dwz=false
     49dwz_low_mem_die_limit=
     50dwz_max_die_limit=
    3451
    3552BUILDDIR=.
     
    4158    strict=true
    4259    ;;
     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    ;;
    4371  -g)
    4472    strip_g=true
     73    ;;
     74  -m)
     75    include_minidebug=true
    4576    ;;
    4677  -o)
     
    87118SOURCEFILE="$BUILDDIR/debugsources.list"
    88119LINKSFILE="$BUILDDIR/debuglinks.list"
     120ELFBINSFILE="$BUILDDIR/elfbins.list"
    89121
    90122> "$SOURCEFILE"
    91123> "$LISTFILE"
    92124> "$LINKSFILE"
     125> "$ELFBINSFILE"
    93126
    94127debugdir="${RPM_BUILD_ROOT}/usr/lib/debug"
     
    105138  eu-strip --remove-comment $r $g -f "$1" "$2" || exit
    106139  chmod 444 "$1" || exit
     140}
     141
     142add_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"
    107177}
    108178
     
    233303
    234304  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 \
    236306                              -i -l "$SOURCEFILE" "$f") || exit
    237307  if [ $nlinks -gt 1 ]; then
     
    243313  fi
    244314
    245   [ -x /usr/bin/gdb-add-index ] && /usr/bin/gdb-add-index "$f" > /dev/null 2>&1
     315  [ type gdb-add-index >/dev/null 2>&1 && gdb-add-index "$f" > /dev/null 2>&1
    246316
    247317  # A binary already copied into /usr/lib/debug doesn't get stripped,
     
    262332  fi
    263333
     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
    264339  if [ -n "$id" ]; then
    265340    make_id_link "$id" "$dn/$(basename $f)"
     
    267342  fi
    268343done || exit
     344
     345# Invoke the DWARF Compressor utility.
     346if $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
     379fi
    269380
    270381# For each symlink whose target has a .debug file,
Note: See TracChangeset for help on using the changeset viewer.