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

[committed] Add --devel-ignore-size



Hi,

Dwz is a dwarf compression tool with the intent to transform dwarf into
equivalent but smaller dwarf.  Consequently:
- during transformation it takes decisions based on size heuristics, and
- at the end of the transformation it discards the result if it's not smaller
  than the original.

Currently, when we run the gdb testsuite in conjunction with dwz using
CC_WITH_TWEAKS_FLAGS, we only test dwz-transformed dwarf if in fact dwz
does not discard the result, and we only test the result of the
transformations enabled by the size heuristics.

Add a developer-only option --devel-ignore-size, that ignores size metrics
and heuristics.  With this option, we force dwz to:
- move all duplicate DIEs to partial units,
- factor out all common partial unit import sets into import-only partial
  units, and
- write out the result.

Also, this may prove useful in dwz test-cases to force a transformation if we
want to test that transformation.

Committed to trunk.

Thanks,
- Tom

Add --devel-ignore-size

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

	* dwz.c (partition_dups_1, create_import_tree): If ignore_size, ignore
	size heuristic.
	(dwz): If ignore_size, skip size test.
	(dwz_options): Add --devel-ignore-size.
	* Makefile (TEST_EXECS): Add min.
	(min): New target.
	* testsuite/dwz.tests/devel-ignore-size.sh: New test.
	* testsuite/dwz.tests/min-2.c: New test source.
	* testsuite/dwz.tests/min.c: New test source.

---
 Makefile                                 |  5 ++++-
 dwz.c                                    | 31 +++++++++++++++++--------------
 testsuite/dwz.tests/devel-ignore-size.sh | 27 +++++++++++++++++++++++++++
 testsuite/dwz.tests/min-2.c              |  5 +++++
 testsuite/dwz.tests/min.c                |  7 +++++++
 5 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index 7150d4a..d07a66d 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ clean:
 PWD:=$(shell pwd -P)
 
 TEST_SRC = $(PWD)/testsuite/dwz.tests
-TEST_EXECS = hello dw2-restrict py-section-script dwz-for-test
+TEST_EXECS = hello dw2-restrict py-section-script dwz-for-test min
 
 hello:
 	$(CC) $(TEST_SRC)/hello.c -o $@ -g
@@ -38,6 +38,9 @@ dwz-for-test: $(DWZ_TEST_SOURCES)
 	$(CC) $(DWZ_TEST_SOURCES) -O2 -g -lelf -o $@ -Wall -W \
 	  -D_FILE_OFFSET_BITS=64 -DDWZ_VERSION='"for-test"'
 
+min:
+	$(CC) $(TEST_SRC)/min.c $(TEST_SRC)/min-2.c -o $@ -g
+
 # On some systems we need to set and export DEJAGNU to suppress
 # WARNING: Couldn't find the global config file.
 DEJAGNU ?= /dev/null
diff --git a/dwz.c b/dwz.c
index f1416fa..ab565d7 100644
--- a/dwz.c
+++ b/dwz.c
@@ -137,6 +137,7 @@ static struct obstack ob2;
 static struct obstack alt_ob, alt_ob2;
 
 static int tracing;
+static int ignore_size;
 
 typedef struct
 {
@@ -5407,7 +5408,7 @@ partition_dups_1 (dw_die_ref *arr, size_t vec_size,
 		 + (die_cu (arr[i])->cu_version == 2
 		    ? 1 + ptr_size : 5) * cnt + 10 * namespaces;
       if (!second_phase)
-	force = orig_size > new_size;
+	force = ignore_size || orig_size > new_size;
       if (force)
 	{
 	  dw_die_ref die, *diep;
@@ -5991,8 +5992,8 @@ create_import_tree (void)
 			cost += pusrc[srccount]->cu->cu_version == 2
 				? 1 + ptr_size : 5;
 		      srccount++;
-		      if ((dstcount - 1) * cost
-			  > 13 + dstcount * new_edge_cost)
+		      if (ignore_size || ((dstcount - 1) * cost
+					  > 13 + dstcount * new_edge_cost))
 			{
 			  unsigned int j;
 
@@ -6170,7 +6171,7 @@ create_import_tree (void)
 				     && e4->icu->cu->cu_version == 2)
 				    ? 1 + ptr_size : 5;
 		    }
-		  if (size_dec > size_inc)
+		  if (!ignore_size || size_dec > size_inc)
 		    {
 		      struct import_cu **ipup;
 		      for (e4 = ipu2->incoming, ep = NULL; e4; e4 = e4->next)
@@ -11120,16 +11121,17 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	  cleanup ();
 	  ret = 1;
 	}
-      else if (debug_sections[DEBUG_INFO].new_size
-	       + debug_sections[DEBUG_ABBREV].new_size
-	       + debug_sections[DEBUG_STR].new_size
-	       + debug_sections[DEBUG_MACRO].new_size
-	       + debug_sections[DEBUG_TYPES].new_size
-	       >= debug_sections[DEBUG_INFO].size
-		  + debug_sections[DEBUG_ABBREV].size
-		  + debug_sections[DEBUG_STR].size
-		  + debug_sections[DEBUG_MACRO].size
-		  + debug_sections[DEBUG_TYPES].size)
+      else if (!ignore_size
+	       && ((debug_sections[DEBUG_INFO].new_size
+		    + debug_sections[DEBUG_ABBREV].new_size
+		    + debug_sections[DEBUG_STR].new_size
+		    + debug_sections[DEBUG_MACRO].new_size
+		    + debug_sections[DEBUG_TYPES].new_size)
+		   >= (debug_sections[DEBUG_INFO].size
+		       + debug_sections[DEBUG_ABBREV].size
+		       + debug_sections[DEBUG_STR].size
+		       + debug_sections[DEBUG_MACRO].size
+		       + debug_sections[DEBUG_TYPES].size)))
 	{
 	  if (!quiet || outfile != NULL)
 	    error (0, 0, "%s: DWARF compression not beneficial "
@@ -11823,6 +11825,7 @@ static struct option dwz_options[] =
   { "relative",		 no_argument,	    0, 'r' },
   { "version",		 no_argument,	    0, 'v' },
   { "devel-trace",	 no_argument,	    &tracing, 1 },
+  { "devel-ignore-size", no_argument,	    &ignore_size, 1 },
   { NULL,		 no_argument,	    0, 0 }
 };
 
diff --git a/testsuite/dwz.tests/devel-ignore-size.sh b/testsuite/dwz.tests/devel-ignore-size.sh
new file mode 100644
index 0000000..31cc923
--- /dev/null
+++ b/testsuite/dwz.tests/devel-ignore-size.sh
@@ -0,0 +1,27 @@
+cp ../min 1
+
+cnt=$(readelf -wi 1 \
+	    | grep '(DW_TAG_partial_unit' \
+	    | wc -l)
+
+[ $cnt -eq 0 ]
+
+dwz 1 2>/dev/null
+
+cnt=$(readelf -wi 1 \
+	    | grep '(DW_TAG_partial_unit' \
+	    | wc -l)
+
+[ $cnt -eq 0 ]
+
+cp ../min 1
+
+dwz --devel-ignore-size 1
+
+cnt=$(readelf -wi 1 \
+	    | grep '(DW_TAG_partial_unit' \
+	    | wc -l)
+
+[ $cnt -gt 0 ]
+
+rm -f 1
diff --git a/testsuite/dwz.tests/min-2.c b/testsuite/dwz.tests/min-2.c
new file mode 100644
index 0000000..a1b61ce
--- /dev/null
+++ b/testsuite/dwz.tests/min-2.c
@@ -0,0 +1,5 @@
+int
+foo (void)
+{
+  return 0;
+}
diff --git a/testsuite/dwz.tests/min.c b/testsuite/dwz.tests/min.c
new file mode 100644
index 0000000..cd4ef42
--- /dev/null
+++ b/testsuite/dwz.tests/min.c
@@ -0,0 +1,7 @@
+extern int foo (void);
+
+int
+main (void)
+{
+  return 0;
+}