]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Use correct CU to resolve file names in dwarf_decl_file.
authorMark Wielaard <mark@klomp.org>
Fri, 8 May 2020 10:33:11 +0000 (12:33 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 8 May 2020 15:47:12 +0000 (17:47 +0200)
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 <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_decl_file.c
libdw/dwarf_ranges.c
libdw/libdw.h
tests/ChangeLog
tests/Makefile.am
tests/run-allfcts.sh
tests/testfile-lto-gcc10.bz2 [new file with mode: 0755]

index 75fc8f0624538bc95187279505ee190735dcf049..34def10d56b45805f101a70d5c2f66815ecd29cb 100644 (file)
@@ -1,3 +1,10 @@
+2020-05-08  Mark Wielaard  <mark@klomp.org>
+
+       * 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  <mark@klomp.org>
 
        * libdw_alloc.c (__libdw_alloc_tail): Call Dwarf oom_handler()
index 5657132f4eed42420db4c16aac8755ffa96a8ad5..d4aa0a18e9866a24227e02e5b90fc260cdbdeb89 100644 (file)
@@ -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;
index f67d8a5a8cbe86c355b027fe484e9344d0996e6a..520f9ffe6f200614bb41f84393d2bebe9a55c6ed 100644 (file)
@@ -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)
index e20961be2cbc71b4bd4a234b7fa7dfb06a745367..1a4e15a169dea532c76446c0effd2da522614600 100644 (file)
@@ -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)
index 301b0fb6e698db0e1af723c57632e78edace717d..b59ebc9fefd08cee206bd1c660be6dfb75acfb63 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-05  Mark Wielaard  <mark@klomp.org>
+
+       * 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  <mark@klomp.org>
 
        * test-subr.sh (testrun_on_self_obj): New function.
index d173d547e777a33911ea7cd67d263fc96e355c21..2fed12e12d832928832d32095a8b3b1af75ca2a9 100644 (file)
@@ -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 \
index 6eaf13c8b11167899db04d5bcf7409207c601be1..f8c1ce78a1e9e9e4eb40f19cec46c84aa0afc50e 100755 (executable)
@@ -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 (executable)
index 0000000..e8ef621
Binary files /dev/null and b/tests/testfile-lto-gcc10.bz2 differ