From: Mark Wielaard Date: Fri, 8 May 2020 10:33:11 +0000 (+0200) Subject: libdw: Use correct CU to resolve file names in dwarf_decl_file. X-Git-Tag: elfutils-0.180~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e1db5cdc9f230f8de4df1a0f38dca69b283ee57a;p=thirdparty%2Felfutils.git libdw: Use correct CU to resolve file names in dwarf_decl_file. 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 --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 75fc8f062..34def10d5 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 5657132f4..d4aa0a18e 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 f67d8a5a8..520f9ffe6 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 e20961be2..1a4e15a16 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 301b0fb6e..b59ebc9fe 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 d173d547e..2fed12e12 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 6eaf13c8b..f8c1ce78a 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 000000000..e8ef621f2 Binary files /dev/null and b/tests/testfile-lto-gcc10.bz2 differ