Bug 24378 - DW_TAG_subroutine_type as a DIE scope causes infinite loop
authorDodji Seketeli <dodji@redhat.com>
Mon, 25 Mar 2019 13:46:31 +0000 (14:46 +0100)
committerDodji Seketeli <dodji@redhat.com>
Mon, 25 Mar 2019 13:46:31 +0000 (14:46 +0100)
GCC 4.3.2 wrongly emits some type definition DIEs in the scope of a
DW_TAG_subroutine_type.  Whenever the DWARF reader tries to get the
scope of a DIE during the computation of the pretty name of a type DIE
which scope is (wrongly) emitted as being a DW_TAG_subroutine_type
things end-up in an infinite loop.

This patch makes get_scope_die to look through the
DW_TAG_subroutine_type to return the proper scope instead, just like
what we already do for DW_TAG_subprogram and DW_TAG_array_type.

* src/abg-dwarf-reader.cc (get_scope_die): Look through
DW_TAG_subroutine_type to get the scope of a given DIE.
* tests/data/Makefile.am: Add the two new files below to source
distribution.
* tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi: New
reference test output.
* tests/data/test-read-dwarf/PR24378-fn-is-not-scope.o: New binary
test input.
* tests/test-read-dwarf.cc (in_out_specs): Add the new test input
to the test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-dwarf-reader.cc
tests/data/Makefile.am
tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi [new file with mode: 0644]
tests/data/test-read-dwarf/PR24378-fn-is-not-scope.o [new file with mode: 0644]
tests/test-read-dwarf.cc

index a4a2e30..8f3052f 100644 (file)
@@ -12363,6 +12363,7 @@ get_scope_die(const read_context&       ctxt,
     return false;
 
   if (dwarf_tag(&scope_die) == DW_TAG_subprogram
+      || dwarf_tag(&scope_die) == DW_TAG_subroutine_type
       || dwarf_tag(&scope_die) == DW_TAG_array_type)
     return get_scope_die(ctxt, &scope_die, where_offset, scope_die);
   return true;
index 2705856..0debab9 100644 (file)
@@ -397,6 +397,8 @@ test-read-dwarf/PR22015-libboost_iostreams.so \
 test-read-dwarf/PR22015-libboost_iostreams.so.abi \
 test-read-dwarf/PR22122-libftdc.so \
 test-read-dwarf/PR22122-libftdc.so.abi \
+test-read-dwarf/PR24378-fn-is-not-scope.abi \
+test-read-dwarf/PR24378-fn-is-not-scope.o \
 \
 test-annotate/test0.abi                        \
 test-annotate/test1.abi                        \
diff --git a/tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi b/tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi
new file mode 100644 (file)
index 0000000..5ac179d
--- /dev/null
@@ -0,0 +1,18 @@
+<abi-corpus path='data/test-read-dwarf/PR24378-fn-is-not-scope.o'>
+  <elf-function-symbols>
+    <elf-symbol name='_ZN4stac14buggy_functionEPFvPFfiiEE' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+  </elf-function-symbols>
+  <abi-instr version='1.0' address-size='64' path='dwarf_bug.cpp' comp-dir-path='/remote/users/lstacul' language='LANG_C_plus_plus'>
+    <namespace-decl name='stac'>
+      <function-decl name='buggy_function' mangled-name='_ZN4stac14buggy_functionEPFvPFfiiEE' filepath='/remote/users/lstacul/dwarf_bug.cpp' line='10' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_ZN4stac14buggy_functionEPFvPFfiiEE'>
+        <parameter type-id='type-id-1'/>
+        <return type-id='type-id-2'/>
+      </function-decl>
+    </namespace-decl>
+    <type-decl name='void' id='type-id-2'/>
+    <pointer-type-def type-id='type-id-3' size-in-bits='64' id='type-id-1'/>
+    <function-type size-in-bits='64' id='type-id-3'>
+      <return type-id='type-id-2'/>
+    </function-type>
+  </abi-instr>
+</abi-corpus>
diff --git a/tests/data/test-read-dwarf/PR24378-fn-is-not-scope.o b/tests/data/test-read-dwarf/PR24378-fn-is-not-scope.o
new file mode 100644 (file)
index 0000000..02e8bb0
Binary files /dev/null and b/tests/data/test-read-dwarf/PR24378-fn-is-not-scope.o differ
index cd22bcc..e743e5b 100644 (file)
@@ -228,6 +228,12 @@ InOutSpec in_out_specs[] =
     "data/test-read-dwarf/PR22122-libftdc.so.abi",
     "output/test-read-dwarf/PR22122-libftdc.so.abi",
   },
+  {
+    "data/test-read-dwarf/PR24378-fn-is-not-scope.o",
+    "",
+    "data/test-read-dwarf/PR24378-fn-is-not-scope.abi",
+    "output/test-read-dwarf/PR24378-fn-is-not-scope.abi",
+  },
   // This should be the last entry.
   {NULL, NULL, NULL, NULL}
 };