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
Subject: [committed] Add --devel-ignore-locus
Date: Tue, 01 Jan 2019 00:00:00 -0000	[thread overview]
Message-ID: <20190406170141.GA17098@delia> (raw)

Hi,

Add a developer-only option --devel-ignore-locus, that allows two DIEs to be
considered duplicate, even if the location information doesn't match.

This makes the dwz compression lossy, in the sense that if f.i. a type is
defined in two files with equivalent definition, the type will only show up in
one file after compression.  To illustrate the information loss using gdb
command info types, before compression we have:
...
$ gdb -batch -ex "info types" --args two-typedef \
    | egrep '^File|size_t' | grep -B1 size_t
File $pwd/testsuite/dwz.tests/two-typedef-2.c:
2:      typedef unsigned long size_t;
File $pwd/testsuite/dwz.tests/two-typedef.c:
1:      typedef unsigned long size_t;
...
and after compression we have:
...
$ gdb -batch -ex "info types" --args two-typedef.dwz.ignore-locus \
    | egrep '^File|size_t' | grep -B1 size_t
File $pwd/testsuite/dwz.tests/two-typedef.c:
1:      typedef unsigned long size_t;
...

Committed to trunk.

Thanks,
- Tom

Add --devel-ignore-locus

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

	* dwz.c (IGNORE_LOCUS): Replace with ignore_locus.
	(checksum_die, die_eq_1): Replace IGNORE_LOCUS with ignore_locus.
	(dwz_options): Add --devel-ignore-locus.
	* Makefile (TEST_EXECS): Add two-typedef.
	(two-typedef): New target.
	* testsuite/dwz.tests/devel-ignore-locus.sh: New test.
	* testsuite/dwz.tests/two-typedef-2.c: New test source.
	* testsuite/dwz.tests/two-typedef.c: New test source.
	* testsuite/dwz.tests/two-typedef.h: New test source.

---
 Makefile                                  |  6 +++++-
 dwz.c                                     | 16 +++++++---------
 testsuite/dwz.tests/devel-ignore-locus.sh | 27 +++++++++++++++++++++++++++
 testsuite/dwz.tests/two-typedef-2.c       |  6 ++++++
 testsuite/dwz.tests/two-typedef.c         | 11 +++++++++++
 testsuite/dwz.tests/two-typedef.h         |  3 +++
 6 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index d07a66d..9b4fb7f 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 min
+TEST_EXECS = hello dw2-restrict py-section-script dwz-for-test min two-typedef
 
 hello:
 	$(CC) $(TEST_SRC)/hello.c -o $@ -g
@@ -41,6 +41,10 @@ dwz-for-test: $(DWZ_TEST_SOURCES)
 min:
 	$(CC) $(TEST_SRC)/min.c $(TEST_SRC)/min-2.c -o $@ -g
 
+two-typedef:
+	$(CC) $(TEST_SRC)/two-typedef.c $(TEST_SRC)/two-typedef-2.c \
+	  -I $(TEST_SRC) -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 ab565d7..9dba649 100644
--- a/dwz.c
+++ b/dwz.c
@@ -99,10 +99,6 @@
 # define NT_GNU_BUILD_ID 3
 #endif
 
-#ifndef IGNORE_LOCUS
-# define IGNORE_LOCUS 0
-#endif
-
 #if defined __GNUC__ && __GNUC__ >= 3
 # define likely(x) __builtin_expect (!!(x), 1)
 # define unlikely(x) __builtin_expect (!!(x), 0)
@@ -138,6 +134,7 @@ static struct obstack alt_ob, alt_ob2;
 
 static int tracing;
 static int ignore_size;
+static int ignore_locus;
 
 typedef struct
 {
@@ -1903,7 +1900,7 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die)
 		}
 	      if (value == 0)
 		handled = false;
-	      else if (!IGNORE_LOCUS && die->die_ck_state != CK_BAD)
+	      else if (!ignore_locus && die->die_ck_state != CK_BAD)
 		{
 		  struct dw_file *cu_file = &cu->cu_files[value - 1];
 		  size_t file_len = strlen (cu_file->file);
@@ -1950,7 +1947,7 @@ checksum_die (DSO *dso, dw_cu_ref cu, dw_die_ref top_die, dw_die_ref die)
 	case DW_AT_decl_column:
 	case DW_AT_call_line:
 	case DW_AT_call_column:
-	  if (IGNORE_LOCUS)
+	  if (ignore_locus)
 	    handled = true;
 	  break;
 	default:
@@ -3104,7 +3101,7 @@ die_eq_1 (dw_cu_ref cu1, dw_cu_ref cu2,
 	    case DW_FORM_udata: value2 = read_uleb128 (ptr2); break;
 	    default: abort ();
 	    }
-	  if (IGNORE_LOCUS)
+	  if (ignore_locus)
 	    {
 	      i++;
 	      j++;
@@ -3175,7 +3172,7 @@ die_eq_1 (dw_cu_ref cu1, dw_cu_ref cu2,
 	case DW_AT_decl_column:
 	case DW_AT_call_line:
 	case DW_AT_call_column:
-	  if (IGNORE_LOCUS)
+	  if (ignore_locus)
 	    old_ptr1 = NULL;
 	  break;
 	default:
@@ -3462,7 +3459,7 @@ die_eq_1 (dw_cu_ref cu1, dw_cu_ref cu2,
 	  abort ();
 	}
 
-      if ((!IGNORE_LOCUS || old_ptr1)
+      if ((!ignore_locus || old_ptr1)
 	  && (ptr1 - old_ptr1 != ptr2 - old_ptr2
 	      || memcmp (old_ptr1, old_ptr2, ptr1 - old_ptr1)))
 	FAIL;
@@ -11826,6 +11823,7 @@ static struct option dwz_options[] =
   { "version",		 no_argument,	    0, 'v' },
   { "devel-trace",	 no_argument,	    &tracing, 1 },
   { "devel-ignore-size", no_argument,	    &ignore_size, 1 },
+  { "devel-ignore-locus",no_argument,	    &ignore_locus, 1 },
   { NULL,		 no_argument,	    0, 0 }
 };
 
diff --git a/testsuite/dwz.tests/devel-ignore-locus.sh b/testsuite/dwz.tests/devel-ignore-locus.sh
new file mode 100644
index 0000000..e856cc6
--- /dev/null
+++ b/testsuite/dwz.tests/devel-ignore-locus.sh
@@ -0,0 +1,27 @@
+cp ../two-typedef 1
+
+cnt=$(readelf -wi 1 \
+	    | grep 'DW_AT_name.*: aaa' \
+	    | wc -l)
+
+[ $cnt -eq 2 ]
+
+dwz 1 2>/dev/null
+
+cnt=$(readelf -wi 1 \
+	    | grep 'DW_AT_name.*: aaa' \
+	    | wc -l)
+
+[ $cnt -eq 2 ]
+
+cp ../two-typedef 1
+
+dwz --devel-ignore-locus --devel-ignore-size 1
+
+cnt=$(readelf -wi 1 \
+	    | grep 'DW_AT_name.*: aaa' \
+	    | wc -l)
+
+[ $cnt -eq 1 ]
+
+rm -f 1
diff --git a/testsuite/dwz.tests/two-typedef-2.c b/testsuite/dwz.tests/two-typedef-2.c
new file mode 100644
index 0000000..8af8df6
--- /dev/null
+++ b/testsuite/dwz.tests/two-typedef-2.c
@@ -0,0 +1,6 @@
+
+typedef long unsigned int size_t;
+
+#include "two-typedef.h"
+
+struct aaa var2;
diff --git a/testsuite/dwz.tests/two-typedef.c b/testsuite/dwz.tests/two-typedef.c
new file mode 100644
index 0000000..fb1e044
--- /dev/null
+++ b/testsuite/dwz.tests/two-typedef.c
@@ -0,0 +1,11 @@
+typedef long unsigned int size_t;
+
+#include "two-typedef.h"
+
+struct aaa var;
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/testsuite/dwz.tests/two-typedef.h b/testsuite/dwz.tests/two-typedef.h
new file mode 100644
index 0000000..1675f39
--- /dev/null
+++ b/testsuite/dwz.tests/two-typedef.h
@@ -0,0 +1,3 @@
+struct aaa {
+  size_t size;
+};

                 reply	other threads:[~2019-04-06 17:01 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=20190406170141.GA17098@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    /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).