]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Skip imported compiler_units in libdw_visit_scopes walking DIE tree
authorMark Wielaard <mark@klomp.org>
Fri, 8 May 2020 10:18:41 +0000 (12:18 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 8 May 2020 16:50:16 +0000 (18:50 +0200)
Some gcc -flto versions imported other top-level compile units,
skip those. Otherwise we'll visit various DIE trees multiple times.

Note in the testcase that with newer GCC versions function foo is
fully inlined and does appear only once (as declared, but not as
separate subprogram).

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/libdw_visit_scopes.c
tests/ChangeLog
tests/Makefile.am
tests/run-allfcts.sh
tests/testfile-lto-gcc8.bz2 [new file with mode: 0755]
tests/testfile-lto-gcc9.bz2 [new file with mode: 0755]

index 34def10d56b45805f101a70d5c2f66815ecd29cb..c75b09587b1b15d791091f859f0bd1598f3e9dcf 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-08  Mark Wielaard  <mark@klomp.org>
+
+       * libdw_visit_scopes.c (walk_children): Don't recurse into imported
+       DW_TAG_compile_units.
+
 2020-05-08  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_decl_file.c (dwarf_decl_file): Use attr CU instead of DIE
index eb892e10a44ec043570446a2f9f834a72eb846f1..7dfa5f6b8be035ec50928f472e0cc5f8bdb4429c 100644 (file)
@@ -125,8 +125,12 @@ walk_children (struct walk_children_state *state)
          Dwarf_Attribute *attr = INTUSE(dwarf_attr) (&state->child.die,
                                                      DW_AT_import,
                                                      &attr_mem);
+         /* Some gcc -flto versions imported other top-level compile units,
+            skip those.  */
          if (INTUSE(dwarf_formref_die) (attr, &state->child.die) != NULL
-             && INTUSE(dwarf_child) (&state->child.die, &state->child.die) == 0)
+             && INTUSE(dwarf_tag) (&state->child.die) != DW_TAG_compile_unit
+             && (INTUSE(dwarf_child) (&state->child.die, &state->child.die)
+                 == 0))
            {
              /* Checks the given DIE hasn't been imported yet
                 to prevent cycles.  */
index b59ebc9fefd08cee206bd1c660be6dfb75acfb63..4e9ae020bef3d4e9b8f53384996c79d055caba0d 100644 (file)
@@ -1,3 +1,12 @@
+2020-05-05  Mark Wielaard  <mark@klomp.org>
+
+       * testfile-lto-gcc8.bz2: New test file.
+       * testfile-lto-gcc9.bz2: Likewise.
+       * Makefile.am (EXTRA_DIST): Add testfile-lto-gcc8.bz2 and
+       testfile-lto-gcc9.bz2.
+       * run-allfcts.sh: Add testfile-lto-gcc9 and testfile-lto-gcc8
+       tests.
+
 2020-05-05  Mark Wielaard  <mark@klomp.org>
 
        * testfile-lto-gcc10.bz2: New test file.
index 2fed12e12d832928832d32095a8b3b1af75ca2a9..a7ad07d0d77fc55c7c1b4c612637262773d4b40e 100644 (file)
@@ -219,6 +219,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
             testfile13.bz2 run-strip-test3.sh run-allfcts.sh \
             testfile_class_func.bz2 testfile_nested_funcs.bz2 \
             testfile-lto-gcc10.bz2 \
+            testfile-lto-gcc9.bz2 testfile-lto-gcc8.bz2 \
             run-line2addr.sh run-elflint-test.sh testfile14.bz2 \
             run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \
             run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \
index f8c1ce78a1e9e9e4eb40f19cec46c84aa0afc50e..9c0a55d86a1fd5d4dc6043d9b07131f2cbba3437 100755 (executable)
@@ -143,4 +143,31 @@ testrun_compare ${abs_builddir}/allfcts testfile-lto-gcc10 <<\EOF
 /home/mark/src/tests/testfile-lto-main.c:6:main
 EOF
 
+# Using gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
+# gcc -g -O2 -flto -c testfile-lto-func.c
+# gcc -g -O2 -flto -c testfile-lto-main.c
+# gcc -g -O2 -flto -o testfile-lto-gcc8 testfile-lto-func.o testfile-lto-main.o
+
+testfiles testfile-lto-gcc8
+
+testrun_compare ${abs_builddir}/allfcts testfile-lto-gcc8 <<\EOF
+/home/mark/src/tests/testfile-lto-func.c:4:foo
+/home/mark/src/tests/testfile-lto-main.c:6:main
+/home/mark/src/tests/testfile-lto-main.c:6:main
+/home/mark/src/tests/testfile-lto-func.c:4:foo
+EOF
+
+# gcc (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2)
+# gcc -g -O2 -flto -c testfile-lto-func.c
+# gcc -g -O2 -flto -c testfile-lto-main.c
+# gcc -g -O2 -flto -o testfile-lto-gcc9 testfile-lto-func.o testfile-lto-main.o
+
+testfiles testfile-lto-gcc9
+
+testrun_compare ${abs_builddir}/allfcts testfile-lto-gcc9 <<\EOF
+/home/mark/src/tests/testfile-lto-main.c:6:main
+/home/mark/src/tests/testfile-lto-func.c:4:foo
+/home/mark/src/tests/testfile-lto-main.c:6:main
+EOF
+
 exit 0
diff --git a/tests/testfile-lto-gcc8.bz2 b/tests/testfile-lto-gcc8.bz2
new file mode 100755 (executable)
index 0000000..cf744d9
Binary files /dev/null and b/tests/testfile-lto-gcc8.bz2 differ
diff --git a/tests/testfile-lto-gcc9.bz2 b/tests/testfile-lto-gcc9.bz2
new file mode 100755 (executable)
index 0000000..df50361
Binary files /dev/null and b/tests/testfile-lto-gcc9.bz2 differ