From e1db5cdc9f230f8de4df1a0f38dca69b283ee57a Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 8 May 2020 12:33:11 +0200 Subject: [PATCH] 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 --- 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 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 0000000000000000000000000000000000000000..e8ef621f2ef7da5c6d65caa4b66e625ec324454c GIT binary patch literal 4319 zc-oDYS6C8`-^FoY4k%|Lj=w0H3s+X}E;?t;1jcFw^hv}%*3DgCZ++9=m2>(wlewm2 zy%slWB5mRes!%+(xPQ02j<#8F2ko%!CzD_z9~^J0WzZ;9_@N@q&I#6e#-Yg0NofB1 zxf(DR+Rm6(f1j;-9^4S0Z*PDm#iyckky7@^Tmgy=nk4V=I@eCVo>p4iw<8#E<~+e;ojkH8uTT0${8D zuY=jBDQ1@P71c~zq|+C9g58MX+kE>2^sIrMt)0{Sp%mP}f<~<`HV|SEsM~DY@#Uv# z00at$Eda?y0+H}iMbdv$@c+M_A~>{+H@7XA5e+xcVT3<=osm15GhFK1l*KEzq&fYxIgT9Z=ha|S(91C}WZel9i9WKSr zq3<3YKQ>*j8;Vyb`J^<2f8nJX;pL*3J67;zvIE!t0dmoQ9Mp-9Fy?^22oj5R`*+lp zLw3NQ5UHXac=hNE@S*8MM1l|;w}ustEomnOWn6zO)*Ntg&i~>Zw6$OKb7b3iG*f^w zR-9ey4D86hr$%EgeZXQbT=(!8$j_M8T6wnnGUexL>9GtVKt_H7G4&?Al+H-rJH!iP zoFNhQiSg^p;aCDiseL^3;IO>H%fJ$Na?Yji@2!Yin&j=}OZLUw;A$P>v}=oGWB(NZQ6HoVWXO7EoT%R2eRgS+{ntoI9_o94=&6=MLC`ELw`bvUJ-_iFP?=x+0$ zq@bG<52BY>3}1i!fos@pnzwCbz)#_iTI5#xGbBpV=Q`M4PCOy#GYcN0^GAjw9Q8?A z1MTcwi(k`FeBms#YWmT1WHln6&CMdf^xp~V2WVlJj=N-o&ET~@e{j;b8>>Ise}rG( zo#qzS+#exSd6XWSMn>++UD}sekl^4%`RwsO5wg-wj?UDjTNkzg$`<`htgQ_WvMTT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