This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] libdw: Search skeleton DIE for split compile unit DIE attributes.
- From: Mark Wielaard <mark at klomp dot org>
- To: elfutils-devel at sourceware dot org
- Cc: Mark Wielaard <mark at klomp dot org>
- Date: Thu, 17 May 2018 13:28:25 +0200
- Subject: [PATCH] libdw: Search skeleton DIE for split compile unit DIE attributes.
dwarf_attr_integrate and dwarf_hasattr_integrate should also search
for attributes from the skeleton DIE in case the given DIE is a split
compile unit DIE. Split compile unit DIEs inherit various attributes
from their skeleton unit DIE in DWARF5.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libdw/ChangeLog | 7 ++
libdw/dwarf_attr_integrate.c | 15 ++++-
libdw/dwarf_hasattr_integrate.c | 16 ++++-
libdw/libdwP.h | 2 +-
tests/ChangeLog | 9 +++
tests/Makefile.am | 11 ++--
tests/attr-integrate-skel.c | 109 +++++++++++++++++++++++++++++++
tests/run-attr-integrate-skel.sh | 52 +++++++++++++++
8 files changed, 214 insertions(+), 7 deletions(-)
create mode 100644 tests/attr-integrate-skel.c
create mode 100755 tests/run-attr-integrate-skel.sh
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index a87a7092..c22811ec 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-17 Mark Wielaard <mark@klomp.org>
+
+ * dwarf_attr_integrate.c (dwarf_attr_integrate): Handle split_compile
+ unit DIE, search skeleton_compile unit DIE.
+ * dwarf_hasattr_integrate.c (dwarf_hasattr_integrate): Likewise.
+ * libdwP.h (is_cudie): Check cu is not NULL.
+
2018-05-15 Mark Wielaard <mark@klomp.org>
* Makefile.am (libdw_a_SOURCES): Add libdw_find_split_unit.c.
diff --git a/libdw/dwarf_attr_integrate.c b/libdw/dwarf_attr_integrate.c
index 812d74b9..748d988d 100644
--- a/libdw/dwarf_attr_integrate.c
+++ b/libdw/dwarf_attr_integrate.c
@@ -1,5 +1,5 @@
/* Return specific DWARF attribute of a DIE, integrating indirections.
- Copyright (C) 2005 Red Hat, Inc.
+ Copyright (C) 2005, 2018 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -55,6 +55,19 @@ dwarf_attr_integrate (Dwarf_Die *die, unsigned int search_name,
}
while (die != NULL);
+ /* Not NULL if it didn't have abstract_origin and specification
+ attributes. If it is a split CU then see if the skeleton
+ has it. */
+ if (die != NULL && is_cudie (die)
+ && die->cu->unit_type == DW_UT_split_compile)
+ {
+ Dwarf_CU *skel_cu = __libdw_find_split_unit (die->cu);
+ if (skel_cu != NULL)
+ {
+ Dwarf_Die skel_die = CUDIE (skel_cu);
+ return INTUSE(dwarf_attr) (&skel_die, search_name, result);
+ }
+ }
return NULL;
}
INTDEF (dwarf_attr_integrate)
diff --git a/libdw/dwarf_hasattr_integrate.c b/libdw/dwarf_hasattr_integrate.c
index 2d5348cf..4d4b4c54 100644
--- a/libdw/dwarf_hasattr_integrate.c
+++ b/libdw/dwarf_hasattr_integrate.c
@@ -1,5 +1,5 @@
/* Check whether DIE has specific attribute, integrating DW_AT_abstract_origin.
- Copyright (C) 2005 Red Hat, Inc.
+ Copyright (C) 2005, 2018 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -55,5 +55,19 @@ dwarf_hasattr_integrate (Dwarf_Die *die, unsigned int search_name)
}
while (die != NULL);
+ /* Not NULL if it didn't have abstract_origin and specification
+ attributes. If it is a split CU then see if the skeleton
+ has it. */
+ if (die != NULL && is_cudie (die)
+ && die->cu->unit_type == DW_UT_split_compile)
+ {
+ Dwarf_CU *skel_cu = __libdw_find_split_unit (die->cu);
+ if (skel_cu != NULL)
+ {
+ Dwarf_Die skel_die = CUDIE (skel_cu);
+ return INTUSE(dwarf_hasattr) (&skel_die, search_name);
+ }
+ }
+
return 0;
}
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index 60572276..08d144ba 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -892,7 +892,7 @@ cu_sec_idx (struct Dwarf_CU *cu)
static inline bool
is_cudie (Dwarf_Die *cudie)
{
- return CUDIE (cudie->cu).addr == cudie->addr;
+ return cudie->cu != NULL && CUDIE (cudie->cu).addr == cudie->addr;
}
/* Read up begin/end pair and increment read pointer.
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b865ad54..05e8f26c 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,12 @@
+2018-05-17 Mark Wielaard <mark@klomp.org>
+
+ * Makefile.am (check_PROGRAMS): Add attr-integrate-skel.
+ (TESTS): Add run-attr-integrate-skel.
+ (EXTRA_DIST): Likewise.
+ (attr_integrate_skel_LDADD): New variable.
+ * attr-integrate-skel.c: New test.
+ * run-attr-integrate-skel.sh: New test runner.
+
2018-05-16 Mark Wielaard <mark@klomp.org>
* Makefile.am (check_PROGRAMS): Add get-units-split.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 07165d84..05a5441b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to create Makefile.in
##
-## Copyright (C) 1996-2017 Red Hat, Inc.
+## Copyright (C) 1996-2018 Red Hat, Inc.
## This file is part of elfutils.
##
## This file is free software; you can redistribute it and/or modify
@@ -56,7 +56,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \
elfgetzdata elfputzdata zstrptr emptyfile vendorelf \
fillfile dwarf_default_lower_bound dwarf-die-addr-die \
- get-units-invalid get-units-split
+ get-units-invalid get-units-split attr-integrate-skel
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -140,7 +140,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
run-readelf-zdebug.sh run-readelf-zdebug-rel.sh \
emptyfile vendorelf fillfile dwarf_default_lower_bound \
run-dwarf-die-addr-die.sh \
- run-get-units-invalid.sh run-get-units-split.sh
+ run-get-units-invalid.sh run-get-units-split.sh \
+ run-attr-integrate-skel.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
@@ -364,7 +365,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
run-get-units-invalid.sh run-get-units-split.sh \
testfile-hello4.dwo.bz2 testfile-hello5.dwo.bz2 \
testfile-splitdwarf-4.bz2 testfile-splitdwarf-5.bz2 \
- testfile-world5.dwo.bz2 testfile-world4.dwo.bz2
+ testfile-world5.dwo.bz2 testfile-world4.dwo.bz2 \
+ run-attr-integrate-skel.sh
if USE_VALGRIND
valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
@@ -525,6 +527,7 @@ dwarf_default_lower_bound_LDADD = $(libdw)
dwarf_die_addr_die_LDADD = $(libdw)
get_units_invalid_LDADD = $(libdw)
get_units_split_LDADD = $(libdw)
+attr_integrate_skel_LDADD = $(libdw)
# We want to test the libelf header against the system elf.h header.
# Don't include any -I CPPFLAGS.
diff --git a/tests/attr-integrate-skel.c b/tests/attr-integrate-skel.c
new file mode 100644
index 00000000..644cd272
--- /dev/null
+++ b/tests/attr-integrate-skel.c
@@ -0,0 +1,109 @@
+/* Test dwarf_get_units finds split DWO CUs.
+ Copyright (C) 2018 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <dwarf.h>
+#include ELFUTILS_HEADER(dw)
+#include <stdio.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ for (int i = 1; i < argc; i++)
+ {
+ printf ("file: %s\n", argv[i]);
+ int fd = open (argv[i], O_RDONLY);
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable: %s\n", argv[i], dwarf_errmsg (-1));
+ return -1;
+ }
+
+ Dwarf_CU *cu = NULL;
+ Dwarf_Die cudie, subdie;
+ uint8_t unit_type;
+ Dwarf_Half version;
+ int count = 0;
+ while (dwarf_get_units (dbg, cu, &cu, &version,
+ &unit_type, &cudie, &subdie) == 0)
+ {
+ count++;
+ if (unit_type == DW_UT_skeleton)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Word word;
+ Dwarf_Addr addr;
+
+ printf ("Split DIE: %s\n", dwarf_diename (&subdie));
+
+ if (dwarf_attr_integrate (&subdie,
+ DW_AT_GNU_addr_base, &attr) == NULL
+ && dwarf_attr_integrate (&subdie,
+ DW_AT_addr_base, &attr) == NULL)
+ printf ("No addr_base");
+ else if (dwarf_formudata (&attr, &word) != 0)
+ printf ("Bad addr_base: %s\n", dwarf_errmsg (-1));
+ else
+ printf ("addr_base secoff: 0x%" PRIx64 "\n", word);
+
+ if (dwarf_attr (&subdie, DW_AT_low_pc, &attr) != NULL)
+ printf ("Unexpected low_pc on split DIE.\n");
+
+ if (dwarf_attr_integrate (&subdie,
+ DW_AT_low_pc, &attr) == NULL)
+ printf ("No low_pc");
+ else if (dwarf_formaddr (&attr, &addr) != 0)
+ printf ("Bad low_pc: %s\n", dwarf_errmsg (-1));
+ else
+ printf ("low_pc addr: 0x%" PRIx64 "\n", addr);
+
+ if (dwarf_hasattr (&subdie, DW_AT_high_pc))
+ printf ("Unexpected highpc on split DIE\n");
+ if (dwarf_hasattr (&subdie, DW_AT_ranges))
+ printf ("Unexpected ranges on split DIE\n");
+
+ if (dwarf_hasattr_integrate (&subdie, DW_AT_high_pc))
+ printf ("Skel has high_pc.\n");
+ if (dwarf_hasattr_integrate (&subdie, DW_AT_ranges))
+ printf ("Skel has ranges.\n");
+
+ printf ("\n");
+ }
+ }
+
+ if (count == 0)
+ {
+ printf ("No units found\n");
+ return -1;
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+ }
+
+ return 0;
+}
diff --git a/tests/run-attr-integrate-skel.sh b/tests/run-attr-integrate-skel.sh
new file mode 100755
index 00000000..a9a9409a
--- /dev/null
+++ b/tests/run-attr-integrate-skel.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2018 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# see tests/testfile-dwarf-45.source
+testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo
+testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo
+
+testrun_compare ${abs_builddir}/attr-integrate-skel testfile-splitdwarf-4 << EOF
+file: testfile-splitdwarf-4
+Split DIE: hello.c
+addr_base secoff: 0x0
+low_pc addr: 0x401160
+Skel has high_pc.
+
+Split DIE: world.c
+addr_base secoff: 0x98
+low_pc addr: 0x0
+Skel has ranges.
+
+EOF
+
+testrun_compare ${abs_builddir}/attr-integrate-skel testfile-splitdwarf-5 << EOF
+file: testfile-splitdwarf-5
+Split DIE: hello.c
+addr_base secoff: 0x8
+low_pc addr: 0x401160
+Skel has high_pc.
+
+Split DIE: world.c
+addr_base secoff: 0xa8
+low_pc addr: 0x0
+Skel has ranges.
+
+EOF
+
+exit 0
--
2.17.0