From: Mark Wielaard Date: Fri, 8 May 2020 10:18:41 +0000 (+0200) Subject: libdw: Skip imported compiler_units in libdw_visit_scopes walking DIE tree X-Git-Tag: elfutils-0.180~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8493c12a707390fb8307fe60fe83e1aed960f89;p=thirdparty%2Felfutils.git libdw: Skip imported compiler_units in libdw_visit_scopes walking DIE tree 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 --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 34def10d5..c75b09587 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2020-05-08 Mark Wielaard + + * libdw_visit_scopes.c (walk_children): Don't recurse into imported + DW_TAG_compile_units. + 2020-05-08 Mark Wielaard * dwarf_decl_file.c (dwarf_decl_file): Use attr CU instead of DIE diff --git a/libdw/libdw_visit_scopes.c b/libdw/libdw_visit_scopes.c index eb892e10a..7dfa5f6b8 100644 --- a/libdw/libdw_visit_scopes.c +++ b/libdw/libdw_visit_scopes.c @@ -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. */ diff --git a/tests/ChangeLog b/tests/ChangeLog index b59ebc9fe..4e9ae020b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2020-05-05 Mark Wielaard + + * 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 * testfile-lto-gcc10.bz2: New test file. diff --git a/tests/Makefile.am b/tests/Makefile.am index 2fed12e12..a7ad07d0d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/run-allfcts.sh b/tests/run-allfcts.sh index f8c1ce78a..9c0a55d86 100755 --- a/tests/run-allfcts.sh +++ b/tests/run-allfcts.sh @@ -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 index 000000000..cf744d9ec 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 index 000000000..df5036188 Binary files /dev/null and b/tests/testfile-lto-gcc9.bz2 differ