https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93608

            Bug ID: 93608
           Summary: [libbacktrace] Add support for .gnu_debugdata section
                    (aka MiniDebugInfo)
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libbacktrace
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
                CC: ian at gcc dot gnu.org
  Target Milestone: ---

The find-debuginfo.sh script in the rpm software package has an ability to
generate a .gnu_debugdata section (originally developed at
https://fedoraproject.org/wiki/Features/MiniDebugInfo):
...
add_minidebug()
{
  local debuginfo="$1"
  local binary="$2"

  local dynsyms=`mktemp`
  local funcsyms=`mktemp`
  local keep_symbols=`mktemp`
  local mini_debuginfo=`mktemp`

  # In the minisymtab we don't need the .debug_ sections (already removed
  # by -S) but also not other non-allocated PROGBITS, NOTE or NOBITS sections.
  # List and remove them explicitly. We do want to keep the allocated,
  # symbol and NOBITS sections so cannot use --keep-only because that is
  # too aggressive. Field $2 is the section name, $3 is the section type
  # and $8 are the section flags.
  local remove_sections=`readelf -W -S "$debuginfo" \
        | awk '{ if (index($2,".debug_") != 1 \
                     && ($3 == "PROGBITS" || $3 == "NOTE" || $3 == "NOBITS") \
                     && index($8,"A") == 0) \
                   printf "--remove-section "$2" " }'`

  # Extract the dynamic symbols from the main binary, there is no need to also
have these
  # in the normal symbol table
  nm -D "$binary" --format=posix --defined-only | awk '{ print $1 }' | sort >
"$dynsyms"
  # Extract all the text (i.e. function) symbols from the debuginfo
  # Use format sysv to make sure we can match against the actual ELF FUNC
  # symbol type. The binutils nm posix format symbol type chars are
  # ambigous for architectures that might use function descriptors.
  nm "$debuginfo" --format=sysv --defined-only | awk -F \| '{ if ($4 ~ "FUNC")
print $1 }' | sort > "$funcsyms"
  # Keep all the function symbols not already in the dynamic symbol table
  comm -13 "$dynsyms" "$funcsyms" > "$keep_symbols"
  # Copy the full debuginfo, keeping only a minumal set of symbols and removing
some unnecessary sections
  objcopy -S $remove_sections --keep-symbols="$keep_symbols" "$debuginfo"
"$mini_debuginfo" &> /dev/null
  #Inject the compressed data into the .gnu_debugdata section of the original
binary
  xz "$mini_debuginfo"
  mini_debuginfo="${mini_debuginfo}.xz"
  objcopy --add-section .gnu_debugdata="$mini_debuginfo" "$binary"
  rm -f "$dynsyms" "$funcsyms" "$keep_symbols" "$mini_debuginfo"
}...

It would be nice if libbacktrace could use this information.

Reply via email to