diff mbox series

[v2,19/21] dwarf-reader/writer: consider aliases when dealing with suppressions

Message ID 20200703164651.1510825-20-maennich@google.com
State New
Headers show
Series Refactor (k)symtab reader | expand

Commit Message

Matthias Maennich July 3, 2020, 4:46 p.m. UTC
When a symbol is suppressed and it happens to be the main symbol of a
group of aliased symbols where another symbol is not suppressed, the
dwarf reader discards the DWARF information upon reading and the writer
will not be able to connect dwarf information to the aliased elf symbol.

In order to address this, ensure we are not suppressing symbols
(actually functions and variables) for which an alias is not suppressed.
We therefore keep the DWARF information even if only a non-main symbol
is asked for.

Likewise, when the abg-writer is having to attach an elf-symbol-id to
the DWARF collected information (for functions and variables), instead
of omitting the symbol altogether, rather make use of the property of
aliases and connect the dwarf information to an alias instead. This way
the function dwarf information stays connected to the elf symbol that we
want to track.

	* src/abg-dwarf-reader.cc(function_is_suppressed): Do not suppress
	  a function for which there is an alias that is not suppressed.
	(variable_is_suppressed): Likewise for variables.
	* src/abg-writer.cc(write_elf_symbol_reference): Fall back to
	  any aliased symbol if the main symbol is suppressed.
	* tests/data/Makefile.am: Add new test files.
	* tests/data/test-read-dwarf/test3-alias-1.so.hash.abi: New test file.
	* tests/data/test-read-dwarf/test3-alias-1.suppr: Likewise.
	* tests/data/test-read-dwarf/test3-alias-2.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-2.suppr: Likewise.
	* tests/data/test-read-dwarf/test3-alias-3.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-3.suppr: Likewise.
	* tests/data/test-read-dwarf/test3-alias-4.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-4.suppr: Likewise.
	* tests/test-read-dwarf.cc: Add new test cases.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-dwarf-reader.cc                       | 20 ++++++++++--
 src/abg-writer.cc                             |  5 ++-
 tests/data/Makefile.am                        |  8 +++++
 .../test-read-dwarf/test3-alias-1.so.hash.abi | 14 ++++++++
 .../data/test-read-dwarf/test3-alias-1.suppr  |  3 ++
 .../test-read-dwarf/test3-alias-2.so.hash.abi | 18 +++++++++++
 .../data/test-read-dwarf/test3-alias-2.suppr  |  3 ++
 .../test-read-dwarf/test3-alias-3.so.hash.abi | 14 ++++++++
 .../data/test-read-dwarf/test3-alias-3.suppr  |  3 ++
 .../test-read-dwarf/test3-alias-4.so.hash.abi |  8 +++++
 .../data/test-read-dwarf/test3-alias-4.suppr  |  3 ++
 tests/test-read-dwarf.cc                      | 32 +++++++++++++++++++
 12 files changed, 128 insertions(+), 3 deletions(-)
 create mode 100644 tests/data/test-read-dwarf/test3-alias-1.so.hash.abi
 create mode 100644 tests/data/test-read-dwarf/test3-alias-1.suppr
 create mode 100644 tests/data/test-read-dwarf/test3-alias-2.so.hash.abi
 create mode 100644 tests/data/test-read-dwarf/test3-alias-2.suppr
 create mode 100644 tests/data/test-read-dwarf/test3-alias-3.so.hash.abi
 create mode 100644 tests/data/test-read-dwarf/test3-alias-3.suppr
 create mode 100644 tests/data/test-read-dwarf/test3-alias-4.so.hash.abi
 create mode 100644 tests/data/test-read-dwarf/test3-alias-4.suppr
diff mbox series

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 4120b03b8ac5..d125cc980166 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -13002,8 +13002,16 @@  function_is_suppressed(const read_context& ctxt,
       if (!ctxt.get_function_address(function_die, fn_addr))
 	return true;
 
-      if (!ctxt.function_symbol_is_exported(fn_addr))
+      elf_symbol_sptr symbol = ctxt.function_symbol_is_exported(fn_addr);
+      if (!symbol)
 	return true;
+      if (!symbol->is_suppressed())
+	return false;
+      if (symbol->has_aliases() && symbol->is_main_symbol())
+	for (elf_symbol_sptr a = symbol->get_next_alias();
+	     !a->is_main_symbol(); a = a->get_next_alias())
+	  if (!a->is_suppressed())
+	    return false;
     }
 
   return suppr::function_is_suppressed(ctxt, qualified_name,
@@ -13107,8 +13115,16 @@  variable_is_suppressed(const read_context& ctxt,
       if (!ctxt.get_variable_address(variable_die, var_addr))
 	return true;
 
-      if (!ctxt.variable_symbol_is_exported(var_addr))
+      elf_symbol_sptr symbol = ctxt.variable_symbol_is_exported(var_addr);
+      if (!symbol)
 	return true;
+      if (!symbol->is_suppressed())
+	return false;
+      if (symbol->has_aliases() && symbol->is_main_symbol())
+	for (elf_symbol_sptr a = symbol->get_next_alias();
+	     !a->is_main_symbol(); a = a->get_next_alias())
+	  if (!a->is_suppressed())
+	    return false;
     }
 
   return suppr::variable_is_suppressed(ctxt, qualified_name,
diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index c5be11b26072..723db1a51256 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -1742,7 +1742,10 @@  write_elf_symbol_aliases(const elf_symbol& sym, ostream& out)
 static bool
 write_elf_symbol_reference(const elf_symbol& sym, ostream& o)
 {
-  o << " elf-symbol-id='" << sym.get_id_string() << "'";
+  auto actual_sym = &sym;
+  while (actual_sym->is_suppressed() && actual_sym->has_aliases())
+    actual_sym = actual_sym->get_next_alias().get();
+  o << " elf-symbol-id='" << actual_sym->get_id_string() << "'";
   return true;
 }
 
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 054acb8c5376..54ccb103c8ab 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -411,6 +411,14 @@  test-read-dwarf/test3.c		\
 test-read-dwarf/test3.so		\
 test-read-dwarf/test3.so.abi		\
 test-read-dwarf/test3.so.hash.abi	\
+test-read-dwarf/test3-alias-1.so.hash.abi \
+test-read-dwarf/test3-alias-1.suppr \
+test-read-dwarf/test3-alias-2.so.hash.abi \
+test-read-dwarf/test3-alias-2.suppr \
+test-read-dwarf/test3-alias-3.so.hash.abi \
+test-read-dwarf/test3-alias-3.suppr \
+test-read-dwarf/test3-alias-4.so.hash.abi \
+test-read-dwarf/test3-alias-4.suppr \
 test-read-dwarf/test4.c		\
 test-read-dwarf/test4.so		\
 test-read-dwarf/test4.so.abi		\
diff --git a/tests/data/test-read-dwarf/test3-alias-1.so.hash.abi b/tests/data/test-read-dwarf/test3-alias-1.so.hash.abi
new file mode 100644
index 000000000000..1ed4b0612886
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-1.so.hash.abi
@@ -0,0 +1,14 @@ 
+<abi-corpus path='data/test-read-dwarf/test3.so' soname='test3.so.1'>
+  <elf-needed>
+    <dependency name='libc.so.6'/>
+  </elf-needed>
+  <elf-function-symbols>
+    <elf-symbol name='__foo' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+  </elf-function-symbols>
+  <abi-instr version='1.0' address-size='64' path='test3.c' comp-dir-path='/home/skumari/Tasks/source_repo/dodji/libabigail/tests/data/test-read-dwarf' language='LANG_C89'>
+    <type-decl name='void' id='48b5725f'/>
+    <function-decl name='__foo' mangled-name='__foo' filepath='/home/skumari/Tasks/source_repo/dodji/libabigail/tests/data/test-read-dwarf/test3.c' line='8' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='__foo'>
+      <return type-id='48b5725f'/>
+    </function-decl>
+  </abi-instr>
+</abi-corpus>
diff --git a/tests/data/test-read-dwarf/test3-alias-1.suppr b/tests/data/test-read-dwarf/test3-alias-1.suppr
new file mode 100644
index 000000000000..b347500d4c4e
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-1.suppr
@@ -0,0 +1,3 @@ 
+[suppress_function]
+  symbol_name_not_regexp = ^__foo$
+  drop = true
diff --git a/tests/data/test-read-dwarf/test3-alias-2.so.hash.abi b/tests/data/test-read-dwarf/test3-alias-2.so.hash.abi
new file mode 100644
index 000000000000..50a53f97bf84
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-2.so.hash.abi
@@ -0,0 +1,18 @@ 
+<abi-corpus path='data/test-read-dwarf/test3.so' soname='test3.so.1'>
+  <elf-needed>
+    <dependency name='libc.so.6'/>
+  </elf-needed>
+  <elf-function-symbols>
+    <elf-symbol name='__foo__' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+    <elf-symbol name='_fini' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+    <elf-symbol name='_init' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+    <elf-symbol name='foo' type='func-type' binding='weak-binding' visibility='default-visibility' is-defined='yes'/>
+    <elf-symbol name='foo__' type='func-type' binding='weak-binding' visibility='default-visibility' is-defined='yes'/>
+  </elf-function-symbols>
+  <abi-instr version='1.0' address-size='64' path='test3.c' comp-dir-path='/home/skumari/Tasks/source_repo/dodji/libabigail/tests/data/test-read-dwarf' language='LANG_C89'>
+    <type-decl name='void' id='48b5725f'/>
+    <function-decl name='__foo' mangled-name='__foo' filepath='/home/skumari/Tasks/source_repo/dodji/libabigail/tests/data/test-read-dwarf/test3.c' line='8' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='foo'>
+      <return type-id='48b5725f'/>
+    </function-decl>
+  </abi-instr>
+</abi-corpus>
diff --git a/tests/data/test-read-dwarf/test3-alias-2.suppr b/tests/data/test-read-dwarf/test3-alias-2.suppr
new file mode 100644
index 000000000000..b6d203d53c2b
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-2.suppr
@@ -0,0 +1,3 @@ 
+[suppress_function]
+  symbol_name_regexp = ^__foo$
+  drop = true
diff --git a/tests/data/test-read-dwarf/test3-alias-3.so.hash.abi b/tests/data/test-read-dwarf/test3-alias-3.so.hash.abi
new file mode 100644
index 000000000000..6de4d59b13d5
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-3.so.hash.abi
@@ -0,0 +1,14 @@ 
+<abi-corpus path='data/test-read-dwarf/test3.so' soname='test3.so.1'>
+  <elf-needed>
+    <dependency name='libc.so.6'/>
+  </elf-needed>
+  <elf-function-symbols>
+    <elf-symbol name='foo' type='func-type' binding='weak-binding' visibility='default-visibility' is-defined='yes'/>
+  </elf-function-symbols>
+  <abi-instr version='1.0' address-size='64' path='test3.c' comp-dir-path='/home/skumari/Tasks/source_repo/dodji/libabigail/tests/data/test-read-dwarf' language='LANG_C89'>
+    <type-decl name='void' id='48b5725f'/>
+    <function-decl name='__foo' mangled-name='__foo' filepath='/home/skumari/Tasks/source_repo/dodji/libabigail/tests/data/test-read-dwarf/test3.c' line='8' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='foo'>
+      <return type-id='48b5725f'/>
+    </function-decl>
+  </abi-instr>
+</abi-corpus>
diff --git a/tests/data/test-read-dwarf/test3-alias-3.suppr b/tests/data/test-read-dwarf/test3-alias-3.suppr
new file mode 100644
index 000000000000..66cd33a8d353
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-3.suppr
@@ -0,0 +1,3 @@ 
+[suppress_function]
+  symbol_name_not_regexp = ^foo$
+  drop = true
diff --git a/tests/data/test-read-dwarf/test3-alias-4.so.hash.abi b/tests/data/test-read-dwarf/test3-alias-4.so.hash.abi
new file mode 100644
index 000000000000..b26d12f80e61
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-4.so.hash.abi
@@ -0,0 +1,8 @@ 
+<abi-corpus path='data/test-read-dwarf/test3.so' soname='test3.so.1'>
+  <elf-needed>
+    <dependency name='libc.so.6'/>
+  </elf-needed>
+  <elf-function-symbols>
+    <elf-symbol name='_init' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+  </elf-function-symbols>
+</abi-corpus>
diff --git a/tests/data/test-read-dwarf/test3-alias-4.suppr b/tests/data/test-read-dwarf/test3-alias-4.suppr
new file mode 100644
index 000000000000..25a2c437f51e
--- /dev/null
+++ b/tests/data/test-read-dwarf/test3-alias-4.suppr
@@ -0,0 +1,3 @@ 
+[suppress_function]
+  symbol_name_not_regexp = ^_init$
+  drop = true
diff --git a/tests/test-read-dwarf.cc b/tests/test-read-dwarf.cc
index 8502f8279241..dc11fbca2738 100644
--- a/tests/test-read-dwarf.cc
+++ b/tests/test-read-dwarf.cc
@@ -124,6 +124,38 @@  InOutSpec in_out_specs[] =
     "data/test-read-dwarf/test3.so.hash.abi",
     "output/test-read-dwarf/test3.so.hash.abi"
   },
+  // suppress all except the main symbol of a group of aliases
+  {
+    "data/test-read-dwarf/test3.so",
+    "data/test-read-dwarf/test3-alias-1.suppr",
+    HASH_TYPE_ID_STYLE,
+    "data/test-read-dwarf/test3-alias-1.so.hash.abi",
+    "output/test-read-dwarf/test3-alias-1.so.hash.abi"
+  },
+  // suppress the main symbol of a group of aliases
+  {
+    "data/test-read-dwarf/test3.so",
+    "data/test-read-dwarf/test3-alias-2.suppr",
+    HASH_TYPE_ID_STYLE,
+    "data/test-read-dwarf/test3-alias-2.so.hash.abi",
+    "output/test-read-dwarf/test3-alias-2.so.hash.abi"
+  },
+  // suppress all except one non main symbol of a group of aliases
+  {
+    "data/test-read-dwarf/test3.so",
+    "data/test-read-dwarf/test3-alias-3.suppr",
+    HASH_TYPE_ID_STYLE,
+    "data/test-read-dwarf/test3-alias-3.so.hash.abi",
+    "output/test-read-dwarf/test3-alias-3.so.hash.abi"
+  },
+  // suppress all symbols of a group of aliases
+  {
+    "data/test-read-dwarf/test3.so",
+    "data/test-read-dwarf/test3-alias-4.suppr",
+    HASH_TYPE_ID_STYLE,
+    "data/test-read-dwarf/test3-alias-4.so.hash.abi",
+    "output/test-read-dwarf/test3-alias-4.so.hash.abi"
+  },
   {
     "data/test-read-dwarf/test4.so",
     "",