From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id E42553858D34 for ; Fri, 8 May 2020 16:50:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E42553858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 1FE7830275C9; Fri, 8 May 2020 18:50:46 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id C1C0641D367E; Fri, 8 May 2020 18:50:46 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH 1/2] libdw: Use correct CU to resolve file names in dwarf_decl_file. Date: Fri, 8 May 2020 18:50:33 +0200 Message-Id: <20200508165034.12405-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, LIKELY_SPAM_BODY, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 May 2020 16:51:00 -0000 dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file attribute. This means the attribute might come from a different DIE in a different CU. If so, we need to use the CU associated with the attribute, not the original DIE, to resolve the file name. Also add a bit more documentation to dwarf_attr_integrate explaining that the attribute returned might come from a different CU (and even different Dwarf). Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 7 +++++ libdw/dwarf_decl_file.c | 2 +- libdw/dwarf_ranges.c | 5 ++++ libdw/libdw.h | 9 +++++- tests/ChangeLog | 6 ++++ tests/Makefile.am | 1 + tests/run-allfcts.sh | 52 +++++++++++++++++++++++++++++++++++ tests/testfile-lto-gcc10.bz2 | Bin 0 -> 4319 bytes 8 files changed, 80 insertions(+), 2 deletions(-) create mode 100755 tests/testfile-lto-gcc10.bz2 diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 75fc8f06..34def10d 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,10 @@ +2020-05-08 Mark Wielaard + + * dwarf_decl_file.c (dwarf_decl_file): Use attr CU instead of DIE + CU to resolve file name. + * dwarf_ranges.c(dwarf_ranges): Document which CU we use when. + * libdw.h (dwarf_attr_integrate): Extend documentation. + 2020-04-25 Mark Wielaard * libdw_alloc.c (__libdw_alloc_tail): Call Dwarf oom_handler() diff --git a/libdw/dwarf_decl_file.c b/libdw/dwarf_decl_file.c index 5657132f..d4aa0a18 100644 --- a/libdw/dwarf_decl_file.c +++ b/libdw/dwarf_decl_file.c @@ -55,7 +55,7 @@ dwarf_decl_file (Dwarf_Die *die) } /* Get the array of source files for the CU. */ - struct Dwarf_CU *cu = die->cu; + struct Dwarf_CU *cu = attr_mem.cu; if (cu->lines == NULL) { Dwarf_Lines *lines; diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c index f67d8a5a..520f9ffe 100644 --- a/libdw/dwarf_ranges.c +++ b/libdw/dwarf_ranges.c @@ -506,6 +506,11 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep, Dwarf_Attribute attr_mem; Dwarf_Attribute *attr = INTUSE(dwarf_attr) (die, DW_AT_ranges, &attr_mem); + /* Note that above we use dwarf_attr, not dwarf_attr_integrate. + The only case where the ranges can come from another DIE + attribute are the split CU case. In that case we also have a + different CU to check against. But that is already set up + above using __libdw_find_split_unit. */ if (attr == NULL && is_cudie (die) && die->cu->unit_type == DW_UT_split_compile) diff --git a/libdw/libdw.h b/libdw/libdw.h index e20961be..1a4e15a1 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -474,7 +474,14 @@ extern Dwarf_Attribute *dwarf_attr (Dwarf_Die *die, unsigned int search_name, extern int dwarf_hasattr (Dwarf_Die *die, unsigned int search_name); /* These are the same as dwarf_attr and dwarf_hasattr, respectively, - but they resolve an indirect attribute through DW_AT_abstract_origin. */ + but they resolve an indirect attribute through + DW_AT_abstract_origin, DW_AT_specification or, if the DIE is a + top-level split CU, the skeleton DIE. Note that the attribute + might come from a DIE in a different CU (possibly from a different + Dwarf file). In that case all attribute information needs to be + resolved through the CU associated with the returned + Dwarf_Attribute. The dwarf_form functions already do this + automatically. */ extern Dwarf_Attribute *dwarf_attr_integrate (Dwarf_Die *die, unsigned int search_name, Dwarf_Attribute *result) diff --git a/tests/ChangeLog b/tests/ChangeLog index 301b0fb6..b59ebc9f 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2020-05-05 Mark Wielaard + + * testfile-lto-gcc10.bz2: New test file. + * Makefile.am (EXTRA_DIST): Add testfile-lto-gcc10.bz2. + * run-allfcts.sh: Add testfile-lto-gcc10 test. + 2020-04-17 Mark Wielaard * test-subr.sh (testrun_on_self_obj): New function. diff --git a/tests/Makefile.am b/tests/Makefile.am index d173d547..2fed12e1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -218,6 +218,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile9.bz2 testfile10.bz2 testfile11.bz2 testfile12.bz2 \ testfile13.bz2 run-strip-test3.sh run-allfcts.sh \ testfile_class_func.bz2 testfile_nested_funcs.bz2 \ + testfile-lto-gcc10.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 6eaf13c8..f8c1ce78 100755 --- a/tests/run-allfcts.sh +++ b/tests/run-allfcts.sh @@ -91,4 +91,56 @@ testrun_compare ${abs_builddir}/allfcts testfile_nested_funcs testfile_class_fun /home/mark/src/tests/nested/class_func.cxx:13:main EOF +# = testfile-lto.h = +# struct t +# { +# int *p; +# int c; +# }; +# +# extern int foo (int i, struct t *t); + +# = testfile-lto-func.c = +# #include "testfile-lto.h" +# +# int +# foo (int i, struct t *t) +# { +# int j, res = 0; +# for (j = 0; j < i && j < t->c; j++) +# res += t->p[j]; +# +# return res; +# } + +# = testfile-lto-main.c = +# #include "testfile-lto.h" +# +# static struct t g; +# +# int +# main (int argc, char **argv) +# { +# int i; +# int j[argc]; +# g.c = argc; +# g.p = j; +# for (i = 0; i < argc; i++) +# j[i] = (int) argv[i][0]; +# return foo (3, &g); +# } + +# Using gcc (GCC) 10.0.1 20200430 (Red Hat 10.0.1-0.13) +# 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-gcc10 testfile-lto-func.o testfile-lto-main.o + +testfiles testfile-lto-gcc10 + +testrun_compare ${abs_builddir}/allfcts testfile-lto-gcc10 <<\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-gcc10.bz2 b/tests/testfile-lto-gcc10.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..e8ef621f2ef7da5c6d65caa4b66e625ec324454c GIT binary patch literal 4319 zcma)8S5OlSw+tmnNt7xfl%GIAT4)APYG|Q+AiV?#LTCwHKu`!6I)b!-G(i)op()Z4 z_^3f5U_x&yHk6_wf(oKu|ND5K?!N4qvomM+Wo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