public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Make smaller-than.sh match dwz heuristic
@ 2021-03-22  4:51 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-03-22  4:51 UTC (permalink / raw)
  To: dwz, jakub, mark

Hi,

As reported in PR27603, when using clang-11 we run into:
...
Running testsuite/dwz.tests/dwz-tests.exp ...
+ exec=start-gold
+ cp start-gold 1
+ dwz 1
+ smaller-than.sh 1 start-gold
FAIL: testsuite/dwz.tests/pr24747.sh
...

The files are the same size:
...
$ ls -l start-gold tmp.pr24747.sh/1
-rwxr-xr-x 1 vries users 2024 Mar 18 11:58 start-gold
-rwxr-xr-x 1 vries users 2024 Mar 18 11:58 tmp.pr24747.sh/1
...
but not the same:
...
$ diff -q start-gold tmp.pr24747.sh/1
Files start-gold and tmp.pr24747.sh/1 differ
...

The .debug_info size is smaller, by 6 bytes:
...
 [Nr] Name         Type      Address  Off    Size   ES Flg Lk Inf Al
-[ 6] .debug_info  PROGBITS  00000000 0001cd 000040 00      0   0  1
+[ 6] .debug_info  PROGBITS  00000000 0001cd 00003a 00      0   0  1
...

The size reduction in the .debug_info section happens not to result in a
smaller file because subsequent sections .note.gnu.gold-version and .symtab
have a bigger-than-one align.

We could try to fix this by adapting the heuristic to not compress if the
eventual file size is equal.

Instead, fix this by making the smaller-than.sh test match the heuristic,
which only looks at the size of some .debug sections.

Committed to trunk.

Thanks,
- Tom

Make smaller-than.sh match dwz heuristic

2021-03-22  Tom de Vries  <tdevries@suse.de>

	* testsuite/scripts/smaller-than.sh: Calculate size as sum of
	.debug sections.

---
 testsuite/scripts/smaller-than.sh | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/testsuite/scripts/smaller-than.sh b/testsuite/scripts/smaller-than.sh
index b3672a5..ab06e3a 100755
--- a/testsuite/scripts/smaller-than.sh
+++ b/testsuite/scripts/smaller-than.sh
@@ -1,10 +1,40 @@
-#!/bin/sh
+#!/bin/bash
 
 f1=$1
 f2=$2
 
-s1=$(ls -l $f1 | awk '{print $5}')
-s2=$(ls -l $f2 | awk '{print $5}')
+section_size ()
+{
+    local f="$1"
+    local section="$2"
+
+    local s
+    s=$(readelf -S -W $f \
+	    | grep "\.debug_$section" \
+	    | sed 's/.*\.debug_//' \
+	    | awk '{print $5}')
+
+    # Convert hex to decimal.
+    s=$(printf "%d" $((16#$s)))
+
+    echo $s
+}
+
+size ()
+{
+    local f="$1"
+
+    local total=0
+    local section
+    for section in info abbrev str macro types; do
+	total=$(($total + $(section_size $f $section)))
+    done
+
+    echo $total
+}
+
+s1=$(size $f1)
+s2=$(size $f2)
 
 if [ $s1 -ge $s2 ]; then
     exit 1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-22  4:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22  4:51 [committed] Make smaller-than.sh match dwz heuristic Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).