public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Make smaller-than.sh match dwz heuristic
Date: Mon, 22 Mar 2021 05:51:04 +0100	[thread overview]
Message-ID: <20210322045103.GA13271@delia> (raw)

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

                 reply	other threads:[~2021-03-22  4:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210322045103.GA13271@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).