summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2016-10-07 17:00:44 +0200
committerPanu Matilainen <pmatilai@redhat.com>2016-10-20 15:32:36 +0300
commite756795087208f6c9df51608457dfd4db258c472 (patch)
tree237eec6dd1fe16fe06885b5ffda3143196907762
parent881b71b550bf15c1ed09491b06b3df95c26c30ed (diff)
downloadrpm-e756795087208f6c9df51608457dfd4db258c472.tar.gz
find-debuginfo.sh: Don't copy extra sections into .gnu_debugdata.
When creating the compressed mini-symtab section in find-debuginfo add_minidebug we explicitly remove .gdb_index and .comment. But there can be other non-empty sections in the debuginfo that shouldn't be copied. For example rust binaries might have a .rustc section. Explicitly remove any non-allocated PROGBITS or NOTE sections. https://bugzilla.redhat.com/show_bug.cgi?id=1382394 Signed-off-by: Mark Wielaard <mjw@redhat.com> (cherry picked from commit bd7611151b59dfe2f0feb41e478799b5bc26a391)
-rw-r--r--scripts/find-debuginfo.sh10
1 files changed, 9 insertions, 1 deletions
diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh
index 2dc1b2594..6aaf21692 100644
--- a/scripts/find-debuginfo.sh
+++ b/scripts/find-debuginfo.sh
@@ -146,6 +146,14 @@ add_minidebug()
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 any other non-allocated PROGBITS or NOTE 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 agressive. 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") && 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"
@@ -157,7 +165,7 @@ add_minidebug()
# 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-section .gdb_index --remove-section .comment --keep-symbols="$keep_symbols" "$debuginfo" "$mini_debuginfo" &> /dev/null
+ 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"