[committed] Make smaller-than.sh match dwz heuristic

Tom de Vries tdevries@suse.de
Mon Mar 22 04:51:04 GMT 2021


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


More information about the Dwz mailing list