[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[committed] Fix multifile opt if single file opt fails



Hi,

When optimizing hello in multi-file mode we have:
...
$ cp hello 1
$ cp 1 2
$ dwz -m 3 1 2
$ ls 3
3
$
...

In multifile mode, dwz first optimizes all inputs in single file mode, and then
in multifile mode.

But if we try to factor out the single file optimization using a seperate dwz
invocation we get:
...
$ cp hello 1
$ dwz 1
$ cp 1 2
$ ./dwz -m 3 1 2
./dwz: 1: DWARF compression not beneficial - old size 436 new size 436
./dwz: 2: DWARF compression not beneficial - old size 436 new size 436
ls: cannot access '3': No such file or directory
$
...

Multifile optimization fails here, because optimize_multifile early-returns
-1 because multi_ehdr.e_ident[0] == '\0'.  The multi_ehdr variable is
initialized in write_dso in single file mode, which is not triggered because
compression is not beneficial.

Fix this by moving the multi_ehdr initialization from write_dso to
write_multifile.

Committed to trunk.

Thanks,
- Tom

Fix multifile opt if single file opt fails

2019-04-23  Tom de Vries  <tdevries@suse.de>

	PR dwz/24354
	PR dwz/24477
	* dwz.c (write_dso): Move multi_ehdr init ...
	(write_multifile): ... here.
	* testsuite/dwz.tests/twice-multifile.sh: Expect multifile optimization
	to work.

---
 dwz.c                                  |  5 +++--
 testsuite/dwz.tests/twice-multifile.sh | 10 +++-------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/dwz.c b/dwz.c
index 8ea7c4d..c67fa9d 100644
--- a/dwz.c
+++ b/dwz.c
@@ -10043,8 +10043,6 @@ write_dso (DSO *dso, const char *file, struct stat *st)
 
   memset (remove_sections, '\0', sizeof (remove_sections));
   ehdr = dso->ehdr;
-  if (multi_ehdr.e_ident[0] == '\0')
-    multi_ehdr = ehdr;
 
   for (i = 0; debug_sections[i].name; i++)
     if (debug_sections[i].new_size != debug_sections[i].size)
@@ -10768,6 +10766,9 @@ write_multifile (DSO *dso)
   unsigned int i;
   int ret = 0;
 
+  if (multi_ehdr.e_ident[0] == '\0')
+    multi_ehdr = dso->ehdr;
+
   if ((multi_ptr_size && ptr_size != multi_ptr_size)
       || (multi_endian
 	  && multi_endian != (do_read_32 == buf_read_ule32
diff --git a/testsuite/dwz.tests/twice-multifile.sh b/testsuite/dwz.tests/twice-multifile.sh
index 6d612f0..8a66e25 100644
--- a/testsuite/dwz.tests/twice-multifile.sh
+++ b/testsuite/dwz.tests/twice-multifile.sh
@@ -24,12 +24,8 @@ if [ $(grep -qv "DWARF compression not beneficial" dwz.err \
     exit 1
 fi
 
-if [ $status -eq 1 ]; then
-    echo "PR24354 workaround used" > dwz.info
-else
-    [ $status -eq 0 ]
-fi
+[ $status -eq 0 ]
 
-cmp 1 1.saved
+smaller-than.sh 1 1.saved
 
-rm -f 1 1.saved 2 2.saved dwz.err
+rm -f 1 1.saved 2 2.saved dwz.err 3