teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0057-find-debuginfo.sh-Remove-non-allocated-NOBITS-sectio.patch

Mark Wielaard b7548d
From 1fb19a11f6d6a4c221f2e1c08fe246761a4d1e82 Mon Sep 17 00:00:00 2001
Mark Wielaard b7548d
From: Mark Wielaard <mark@klomp.org>
Mark Wielaard b7548d
Date: Wed, 19 Jul 2017 14:53:53 +0200
Mark Wielaard b7548d
Subject: [PATCH] find-debuginfo.sh: Remove non-allocated NOBITS sections from
Mark Wielaard b7548d
 minisymtab.
Mark Wielaard b7548d
Mark Wielaard b7548d
In the minisymtab section (the .gnu_debugdata embedded ELF image) we
Mark Wielaard b7548d
do not need unallocated sections (except for the SYMTAB and STRTAB
Mark Wielaard b7548d
sections we are creating). We already remove PROGBITS and NOTES. Also
Mark Wielaard b7548d
remove NOBITS sections. They should not really take up much (any) space
Mark Wielaard b7548d
but they still add to the section tables. These sections might be created
Mark Wielaard b7548d
with the new --keep-section support (which puts the actual section in
Mark Wielaard b7548d
the main ELF binary, and a NOBITS variant in the .debug file).
Mark Wielaard b7548d
Mark Wielaard b7548d
Also binutils objcopy seems to sometimes add them anyway filled with
Mark Wielaard b7548d
zeros instead of marking them NOBITS.
Mark Wielaard b7548d
Mark Wielaard b7548d
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard b7548d
(cherry picked from commit 860c04e0c3603f4697b7be5fe15ad325369f082c)
Mark Wielaard b7548d
---
Mark Wielaard b7548d
 scripts/find-debuginfo.sh | 8 ++++++--
Mark Wielaard b7548d
 1 file changed, 6 insertions(+), 2 deletions(-)
Mark Wielaard b7548d
Mark Wielaard b7548d
diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh
Mark Wielaard b7548d
index 5ec52d3..b83e4c6 100644
Mark Wielaard b7548d
--- a/scripts/find-debuginfo.sh
Mark Wielaard b7548d
+++ b/scripts/find-debuginfo.sh
Mark Wielaard b7548d
@@ -247,12 +247,16 @@ add_minidebug()
Mark Wielaard b7548d
   local mini_debuginfo=`mktemp`
Mark Wielaard b7548d
 
Mark Wielaard b7548d
   # In the minisymtab we don't need the .debug_ sections (already removed
Mark Wielaard b7548d
-  # by -S) but also not any other non-allocated PROGBITS or NOTE sections.
Mark Wielaard b7548d
+  # by -S) but also not other non-allocated PROGBITS, NOTE or NOBITS sections.
Mark Wielaard b7548d
   # List and remove them explicitly. We do want to keep the allocated,
Mark Wielaard b7548d
   # symbol and NOBITS sections so cannot use --keep-only because that is
Mark Wielaard b7548d
   # too agressive. Field $2 is the section name, $3 is the section type
Mark Wielaard b7548d
   # and $8 are the section flags.
Mark Wielaard b7548d
-  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" " }'`
Mark Wielaard b7548d
+  local remove_sections=`readelf -W -S "$debuginfo" \
Mark Wielaard b7548d
+	| awk '{ if (index($2,".debug_") != 1 \
Mark Wielaard b7548d
+		     && ($3 == "PROGBITS" || $3 == "NOTE" || $3 == "NOBITS") \
Mark Wielaard b7548d
+		     && index($8,"A") == 0) \
Mark Wielaard b7548d
+		   printf "--remove-section "$2" " }'`
Mark Wielaard b7548d
 
Mark Wielaard b7548d
   # Extract the dynamic symbols from the main binary, there is no need to also have these
Mark Wielaard b7548d
   # in the normal symbol table