Add ELF compressed section support
by Mark Wielaard
Hi,
This is hopefully the final patch set to add SHF_COMPRESSED section
support to libelf, libdw and some of the elfutils utilities.
All XXXs in the code have been resolved. There has been a small
interface change (as discussed on the Generic System V Application Binary
Interface mailinglist) to add a ELF_CHF_FORCE flag to elf_compress
and elf_compress_gnu and a slight change in return value (zero now means
that the section wasn't compressed because it wasn't beneficial).
This version also makes it so that libdw and libdwfl functions will
automatically handle compressed ELF sections, extends the eu-readelf
support a little, makes elflint recognize and check compressed sections
and adds a new eu-elfcompress utility that can be used to compress or
uncompress ELF sections.
The code can also be found on the mjw/compress4 branch in git.
Comments welcome.
Kurt, this should solve the issue on Debian powerpc that you were
seeing. If you could test the code on the mjw/compress4 branch that
would be great.
Thanks,
Mark
8 years, 3 months
[PATCH] config: Add libelf and libdw pkg-config files.
by Mark Wielaard
There were some requests for pkg-config files, so this adds them for
libelf and libdw. Since I don't have much experience with pkg-config
files I would like it if someone could double check this produces
the correct .pc files.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
ChangeLog | 5 +++++
config/ChangeLog | 10 ++++++++++
config/Makefile.am | 6 +++++-
config/elfutils.spec.in | 2 ++
config/libdw.pc.in | 22 ++++++++++++++++++++++
config/libelf.pc.in | 14 ++++++++++++++
configure.ac | 12 ++++++++++--
7 files changed, 68 insertions(+), 3 deletions(-)
create mode 100644 config/libdw.pc.in
create mode 100644 config/libelf.pc.in
diff --git a/ChangeLog b/ChangeLog
index bbe0b8c..49b1527 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-01-04 Mark Wielaard <mjw(a)redhat.com>
+
+ * configure.ac: Add BZ2_LIBS and LIBLZMA substitutions.
+ Add config/libelf.pc and config/libdw.pc config files.
+
2015-10-16 Mark Wielaard <mjw(a)redhat.com>
* configure.ac: Make zlib mandatory.
diff --git a/config/ChangeLog b/config/ChangeLog
index 428162f..baa4303 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,13 @@
+2016-01-04 Mark Wielaard <mjw(a)redhat.com>
+
+ * libelf.pc.in: New file.
+ * libdw.pc.in: Likewise.
+ * Makefile.am (EXTRA_DIST): Add libelf.pc.in and libdw.pc.in.
+ (pkgconfigdir): New variable.
+ (pkgconfigdir_DATA): Likewise.
+ * elfutils.spec.in (files devel): Add libdw.pc.
+ (files libelf-devel): Add libelf.pc.
+
2015-10-15 Mark Wielaard <mjw(a)redhat.com>
* elfutils.spec.in: Update for 0.164.
diff --git a/config/Makefile.am b/config/Makefile.am
index 23f7b65..66012d0 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-
## Configure input file for elfutils.
##
-## Copyright (C) 2004, 2005, 2008, 2009, 2011, 2015 Red Hat, Inc.
+## Copyright (C) 2004, 2005, 2008, 2009, 2011, 2015, 2016 Red Hat, Inc.
## This file is part of elfutils.
##
## This file is free software; you can redistribute it and/or modify
@@ -29,6 +29,10 @@
## not, see <http://www.gnu.org/licenses/>.
##
EXTRA_DIST = elfutils.spec.in known-dwarf.awk 10-default-yama-scope.conf
+ libelf.pc.in libdw.pc.in
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libelf.pc libdw.pc
if MAINTAINER_MODE
$(srcdir)/elfutils.spec.in: $(top_srcdir)/NEWS
diff --git a/config/elfutils.spec.in b/config/elfutils.spec.in
index b718f06..40b08bf 100644
--- a/config/elfutils.spec.in
+++ b/config/elfutils.spec.in
@@ -197,6 +197,7 @@ rm -rf ${RPM_BUILD_ROOT}
%{_libdir}/libebl.a
#%{_libdir}/libasm.so
%{_libdir}/libdw.so
+%{_libdir}/pkgconfig/libdw.pc
%files devel-static
%{_libdir}/libdw.a
@@ -215,6 +216,7 @@ rm -rf ${RPM_BUILD_ROOT}
%{_includedir}/nlist.h
%{_includedir}/elfutils/version.h
%{_libdir}/libelf.so
+%{_libdir}/pkgconfig/libelf.pc
%files libelf-devel-static
%{_libdir}/libelf.a
diff --git a/config/libdw.pc.in b/config/libdw.pc.in
new file mode 100644
index 0000000..b7dc002
--- /dev/null
+++ b/config/libdw.pc.in
@@ -0,0 +1,22 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libdw
+Description: elfutils library for DWARF data and ELF file or process inspection
+Version: @VERSION@
+URL: https://fedorahosted.org/elfutils/
+
+Libs: -L${libdir} -ldw
+Cflags: -I${includedir}
+
+# We need the exact matching elfutils libelf version since internal data
+# structures are used.
+Requires: libelf = @VERSION@
+
+# We support various compressed ELF images, but don't export any of the
+# data structures or functions. zlib (gz) is always required, bzip2 (bz2)
+# and lzma (xz) are optional. But bzip2 doesn't have a pkg-config file.
+Requires.private: zlib @LIBLZMA@
+Libs.private: @BZ2_LIB@
diff --git a/config/libelf.pc.in b/config/libelf.pc.in
new file mode 100644
index 0000000..1fc7e4c
--- /dev/null
+++ b/config/libelf.pc.in
@@ -0,0 +1,14 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libelf
+Description: elfutils libelf library to read and write ELF files
+Version: @VERSION@
+URL: https://fedorahosted.org/elfutils/
+
+Libs: -L${libdir} -lelf
+Cflags: -I${includedir}
+
+Requires.private: zlib
diff --git a/configure.ac b/configure.ac
index e010754..bc50e31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
dnl Process this file with autoconf to produce a configure script.
dnl Configure input file for elfutils. -*-autoconf-*-
dnl
-dnl Copyright (C) 1996-2015 Red Hat, Inc.
+dnl Copyright (C) 1996-2016 Red Hat, Inc.
dnl
dnl This file is part of elfutils.
dnl
@@ -22,7 +22,7 @@ AC_INIT([elfutils],[0.164],[https://bugzilla.redhat.com/],[elfutils])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_FILES([config/Makefile])
-AC_COPYRIGHT([Copyright (C) 1996-2015 Red Hat, Inc.])
+AC_COPYRIGHT([Copyright (C) 1996-2016 Red Hat, Inc.])
AC_PREREQ(2.63) dnl Minimum Autoconf version required.
dnl We use GNU make extensions; automake 1.10 defaults to -Wportability.
@@ -252,7 +252,12 @@ dnl conditional and config.h USE_BZLIB/USE_LZMALIB #define.
save_LIBS="$LIBS"
LIBS=
eu_ZIPLIB(bzlib,BZLIB,bz2,BZ2_bzdopen,bzip2)
+# We need this since bzip2 doesn't have a pkgconfig file.
+BZ2_LIB="$LIBS"
+AC_SUBST([BZ2_LIB])
eu_ZIPLIB(lzma,LZMA,lzma,lzma_auto_decoder,[LZMA (xz)])
+AS_IF([test "x$with_lzma" = xyes], [LIBLZMA="liblzma"], [LIBLZMA=""])
+AC_SUBST([LIBLZMA])
zip_LIBS="$LIBS"
LIBS="$save_LIBS"
AC_SUBST([zip_LIBS])
@@ -352,6 +357,9 @@ dnl Test suite.
AM_CONDITIONAL(STANDALONE, false)dnl Used in tests/Makefile.am, which see.
AC_CONFIG_FILES([tests/Makefile])
+dnl pkgconfig files
+AC_CONFIG_FILES([config/libelf.pc config/libdw.pc])
+
# Get the definitions necessary to create the Makefiles in the po
# subdirectories. This is a small subset of the gettext rules.
AC_SUBST(USE_NLS, yes)
--
1.8.3.1
8 years, 3 months
[PATCH] elflint: Add _edata and _end to the list of possibly dangling gnuld symbols.
by Mark Wielaard
gnuld might keep dangling/unused symbols around (see sourceware PR13621).
Add _edata (end of initialized data address) and _end (end of uninitialized
data address) to that list. They might have been added by gnuld even if
there is no such [un]initialized data. Also add the double underscore
variants which are used on some architectures.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
src/ChangeLog | 5 +++++
src/elflint.c | 6 +++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 3f970a2..9ed151c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-31 Mark Wielaard <mjw(a)redhat.com>
+
+ * elflint.c (check_symtab): Add _edata and _end (plus extra underscore
+ variants) to to the list of possibly dangling symbols.
+
2015-12-16 Mark Wielaard <mjw(a)redhat.com>
* elfcompress.c: New file.
diff --git a/src/elflint.c b/src/elflint.c
index 86cf331..7a7b9ce 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -801,7 +801,11 @@ section [%2d] '%s': symbol %zu: function in COMMON section is nonsense\n"),
&& strcmp (name, "__bss_start") != 0
&& strcmp (name, "__bss_start__") != 0
&& strcmp (name, "__TMC_END__") != 0
- && strcmp (name, ".TOC.") != 0))
+ && strcmp (name, ".TOC.") != 0
+ && strcmp (name, "_edata") != 0
+ && strcmp (name, "__edata") != 0
+ && strcmp (name, "_end") != 0
+ && strcmp (name, "__end") != 0))
ERROR (gettext ("\
section [%2d] '%s': symbol %zu: st_value out of bounds\n"),
idx, section_name (ebl, idx), cnt);
--
2.5.0
8 years, 3 months
[PATCH] tests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.
by Mark Wielaard
Old linkers might have created an STT_SECTION symbol for the section
header string table section, which isn't actually used. For now just
warn about such symbols. If such a symbol would actually really be used
(but why?) then we would have to handle it by removing it and rewriting
the symbol table.
This is a testsuite only change, but includes an extra test with files
that have such STT_SECTION symbols to make sure it will be handled in
case we "upgrade" the elfstrmerge test to a real utility.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
tests/ChangeLog | 7 +++++++
tests/Makefile.am | 4 ++--
tests/elfstrmerge.c | 9 +++++++--
tests/run-elfstrmerge-test.sh | 40 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 56 insertions(+), 4 deletions(-)
create mode 100755 tests/run-elfstrmerge-test.sh
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b6cf28d..087e22f 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2015-12-31 Mark Wielaard <mjw(a)redhat.com>
+
+ * elfstrmerge.c (main): Warn about STT_SECTION symbol for shstrhndx.
+ * run-elfstrmerge-test.sh: New test.
+ * Makefile.am (TESTS): Add run-elfstrmerge-test.sh
+ (EXTRA_DIST): Likewise.
+
2015-12-16 Mark Wielaard <mjw(a)redhat.com>
* run-compress-test.sh: New test.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8d48393..d67fc7f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -81,7 +81,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-strip-test9.sh run-strip-test10.sh \
run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \
run-unstrip-test.sh run-unstrip-test2.sh \
- run-unstrip-test3.sh run-unstrip-M.sh \
+ run-unstrip-test3.sh run-unstrip-M.sh run-elfstrmerge-test.sh \
run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \
run-elflint-test.sh run-elflint-self.sh run-ranlib-test.sh \
run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \
@@ -171,7 +171,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-unstrip-test.sh run-unstrip-test2.sh \
testfile-info-link.bz2 testfile-info-link.debuginfo.bz2 \
testfile-info-link.stripped.bz2 run-unstrip-test3.sh \
- run-unstrip-M.sh \
+ run-unstrip-M.sh run-elfstrmerge-test.sh \
run-elflint-self.sh run-ranlib-test.sh run-ranlib-test2.sh \
run-ranlib-test3.sh run-ranlib-test4.sh \
run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \
diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index 6b927c8..4149ca6 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -518,8 +518,13 @@ main (int argc, char **argv)
if (gelf_getsym (data, i, &sym) == NULL)
fail_elf_idx ("Couldn't get symbol", fname, i);
- if (sym.st_shndx != SHN_UNDEF
- && sym.st_shndx < SHN_LORESERVE)
+ if (GELF_ST_TYPE (sym.st_info) == STT_SECTION
+ && sym.st_shndx == shdrstrndx)
+ fprintf (stderr, "WARNING:"
+ " symbol table [%zd] contains section symbol %zd"
+ " for old shdrstrndx %zd\n", ndx, i, shdrstrndx);
+ else if (sym.st_shndx != SHN_UNDEF
+ && sym.st_shndx < SHN_LORESERVE)
sym.st_shndx = newsecndx (sym.st_shndx, "section", ndx,
"symbol", i);
if (update_name && sym.st_name != 0)
diff --git a/tests/run-elfstrmerge-test.sh b/tests/run-elfstrmerge-test.sh
new file mode 100755
index 0000000..d08b6fc
--- /dev/null
+++ b/tests/run-elfstrmerge-test.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2015 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
+
+# Merge string tables of file and check result with elflint.
+testrun_elfcompress()
+{
+ testfile="$1"
+ testfiles ${testfile}
+
+ mergedfile="${testfile}.merged"
+ tempfiles ${mergedfile}
+
+ echo "merging string tables ${testfile} -> ${mergedfile}"
+ testrun ${abs_top_builddir}/tests/elfstrmerge -o ${mergedfile} ${testfile}
+ testrun ${abs_top_builddir}/src/elflint --gnu-ld ${mergedfile}
+}
+
+# Random ELF32 testfile with extra STT_SECTION symbols
+testrun_elfcompress testfile4
+
+# Random ELF64 testfile with extra STT_SECTION symbols
+testrun_elfcompress testfile12
+
+exit 0
--
2.5.0
8 years, 3 months
[PATCH] Make make more silent.
by Mark Wielaard
Silent rules already are the default, but automake and make both still
tell which directory is being entered/build. Disable printing from make.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
ChangeLog | 4 ++++
Makefile.am | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index bbe0b8c..7b67c2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-12-31 Mark Wielaard <mjw(a)redhat.com>
+
+ * Makefile.am (AM_MAKEFLAGS): Set --no-print-directory.
+
2015-10-16 Mark Wielaard <mjw(a)redhat.com>
* configure.ac: Make zlib mandatory.
diff --git a/Makefile.am b/Makefile.am
index 1454d04..2ff444e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to create Makefile.in
## Configure input file for elfutils.
##
-## Copyright (C) 1996-2002, 2003, 2004, 2005, 2006, 2008, 2009 Red Hat, Inc.
+## Copyright (C) 1996-2006, 2008, 2009, 2015 Red Hat, Inc.
##
## This file is part of elfutils.
##
@@ -20,6 +20,10 @@
##
ACLOCAL_AMFLAGS = -I m4
+# automake already tells which subdir is being entered.
+# Don't make make repeat.
+AM_MAKEFLAGS = --no-print-directory
+
pkginclude_HEADERS = version.h
# Add doc back when we have some real content.
--
2.5.0
8 years, 3 months
[PATCH] Move nested functions in linux-proc-maps.c to file scope.
by Chih-Hung Hsieh
* Move nested function 'report' to file scope to compile with clang.
Signed-off-by: Chih-Hung Hsieh <chh(a)google.com>
---
libdwfl/ChangeLog | 5 +++++
libdwfl/linux-proc-maps.c | 31 +++++++++++++++++--------------
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 163a6f1..8d5553c 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2015-11-18 Chih-Hung Hsieh <chh(a)google.com>
+
+ * linux-proc-maps.c (proc_maps_report): Move nested function
+ 'report' to file scope.
+
2015-11-13 Chih-Hung Hsieh <chh(a)google.com>
* gzip.c (unzip): Move nested functions to file scope.
diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c
index 2e2c8f9..9e7b2a2 100644
--- a/libdwfl/linux-proc-maps.c
+++ b/libdwfl/linux-proc-maps.c
@@ -175,6 +175,23 @@ grovel_auxv (pid_t pid, Dwfl *dwfl, GElf_Addr *sysinfo_ehdr)
return ENOEXEC;
}
+static inline bool
+do_report (Dwfl *dwfl, char **plast_file, Dwarf_Addr low, Dwarf_Addr high)
+{
+ if (*plast_file != NULL)
+ {
+ Dwfl_Module *mod = INTUSE(dwfl_report_module) (dwfl, *plast_file,
+ low, high);
+ free (*plast_file);
+ *plast_file = NULL;
+ if (unlikely (mod == NULL))
+ return true;
+ }
+ return false;
+}
+
+#define report() do_report(dwfl, &last_file, low, high)
+
static int
proc_maps_report (Dwfl *dwfl, FILE *f, GElf_Addr sysinfo_ehdr, pid_t pid)
{
@@ -183,20 +200,6 @@ proc_maps_report (Dwfl *dwfl, FILE *f, GElf_Addr sysinfo_ehdr, pid_t pid)
char *last_file = NULL;
Dwarf_Addr low = 0, high = 0;
- inline bool report (void)
- {
- if (last_file != NULL)
- {
- Dwfl_Module *mod = INTUSE(dwfl_report_module) (dwfl, last_file,
- low, high);
- free (last_file);
- last_file = NULL;
- if (unlikely (mod == NULL))
- return true;
- }
- return false;
- }
-
char *line = NULL;
size_t linesz;
ssize_t len;
--
2.6.0.rc2.230.g3dd15c0
8 years, 3 months
[PATCH] Move nested functions in core-file.c to file scope.
by Chih-Hung Hsieh
* Move nested functions 'fail', 'update_end', and 'more' to file scope.
Signed-off-by: Chih-Hung Hsieh <chh(a)google.com>
---
libdwfl/ChangeLog | 6 ++++
libdwfl/core-file.c | 94 +++++++++++++++++++++++++++++------------------------
2 files changed, 58 insertions(+), 42 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 163a6f1..0cc1ad3 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2015-11-18 Chih-Hung Hsieh <chh(a)google.com>
+
+ * core-file.c (elf_begin_rand): Move nested function 'fail' to file scope.
+ * core-file.c (dwfl_elf_phdr_memory_callback): Move nested functions
+ 'update_end' and 'more' to file scope.
+
2015-11-13 Chih-Hung Hsieh <chh(a)google.com>
* gzip.c (unzip): Move nested functions to file scope.
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
index b317eca..d54240e 100644
--- a/libdwfl/core-file.c
+++ b/libdwfl/core-file.c
@@ -39,6 +39,19 @@
#include "system.h"
+/* On failure return, we update *NEXT to point back at OFFSET. */
+static inline Elf *
+do_fail (int error, off_t *next, off_t offset)
+{
+ if (next != NULL)
+ *next = offset;
+ //__libelf_seterrno (error);
+ __libdwfl_seterrno (DWFL_E (LIBELF, error));
+ return NULL;
+}
+
+#define fail(error) do_fail (error, next, offset)
+
/* This is a prototype of what a new libelf interface might be.
This implementation is pessimal for non-mmap cases and should
be replaced by more diddling inside libelf internals. */
@@ -48,16 +61,6 @@ elf_begin_rand (Elf *parent, off_t offset, off_t size, off_t *next)
if (parent == NULL)
return NULL;
- /* On failure return, we update *NEXT to point back at OFFSET. */
- inline Elf *fail (int error)
- {
- if (next != NULL)
- *next = offset;
- //__libelf_seterrno (error);
- __libdwfl_seterrno (DWFL_E (LIBELF, error));
- return NULL;
- }
-
off_t min = (parent->kind == ELF_K_ELF ?
(parent->class == ELFCLASS32
? sizeof (Elf32_Ehdr) : sizeof (Elf64_Ehdr))
@@ -238,6 +241,44 @@ core_file_read_eagerly (Dwfl_Module *mod,
return cost <= MAX_EAGER_COST;
}
+static inline void
+update_end (GElf_Phdr *pphdr, const GElf_Off align,
+ GElf_Off *pend, GElf_Addr *pend_vaddr)
+{
+ *pend = (pphdr->p_offset + pphdr->p_filesz + align - 1) & -align;
+ *pend_vaddr = (pphdr->p_vaddr + pphdr->p_memsz + align - 1) & -align;
+}
+
+/* Use following contiguous segments to get towards SIZE. */
+static inline bool
+do_more (size_t size, GElf_Phdr *pphdr, const GElf_Off align,
+ Elf *elf, GElf_Off start, int *pndx,
+ GElf_Off *pend, GElf_Addr *pend_vaddr)
+{
+ while (*pend <= start || *pend - start < size)
+ {
+ if (pphdr->p_filesz < pphdr->p_memsz)
+ /* This segment is truncated, so no following one helps us. */
+ return false;
+
+ if (unlikely (gelf_getphdr (elf, (*pndx)++, pphdr) == NULL))
+ return false;
+
+ if (pphdr->p_type == PT_LOAD)
+ {
+ if (pphdr->p_offset > *pend
+ || pphdr->p_vaddr > *pend_vaddr)
+ /* It's discontiguous! */
+ return false;
+
+ update_end (pphdr, align, pend, pend_vaddr);
+ }
+ }
+ return true;
+}
+
+#define more(size) do_more (size, &phdr, align, elf, start, &ndx, &end, &end_vaddr)
+
bool
dwfl_elf_phdr_memory_callback (Dwfl *dwfl, int ndx,
void **buffer, size_t *buffer_available,
@@ -270,38 +311,7 @@ dwfl_elf_phdr_memory_callback (Dwfl *dwfl, int ndx,
GElf_Off end;
GElf_Addr end_vaddr;
- inline void update_end (void)
-{
- end = (phdr.p_offset + phdr.p_filesz + align - 1) & -align;
- end_vaddr = (phdr.p_vaddr + phdr.p_memsz + align - 1) & -align;
- }
-
- update_end ();
-
- /* Use following contiguous segments to get towards SIZE. */
- inline bool more (size_t size)
- {
- while (end <= start || end - start < size)
- {
- if (phdr.p_filesz < phdr.p_memsz)
- /* This segment is truncated, so no following one helps us. */
- return false;
-
- if (unlikely (gelf_getphdr (elf, ndx++, &phdr) == NULL))
- return false;
-
- if (phdr.p_type == PT_LOAD)
- {
- if (phdr.p_offset > end
- || phdr.p_vaddr > end_vaddr)
- /* It's discontiguous! */
- return false;
-
- update_end ();
- }
- }
- return true;
- }
+ update_end (&phdr, align, &end, &end_vaddr);
/* We need at least this much. */
if (! more (minread))
--
2.6.0.rc2.230.g3dd15c0
8 years, 3 months
Re: [PATCH 4/4] backends: sparc: support for live backtraces
by Jose E. Marchesi
> This patch implements the set_initial_registers_tid hook for sparc.
> It works in both sparcv9-*-* and sparc64-*-* targets.
Looks good. Pushed to master.
Not having access to a sparc setup I couldn't test this, but I assume
that with this run-backtrace-native.sh and run-backtrace-native-biarch.sh
now PASS on sparc64?
Yes. Both native and -m32 PASS on sparc64-*-*.
8 years, 3 months
[PATCH 0/4] Unwinder support for SPARC targets
by Jose E. Marchesi
This little patch series adds unwinder support (eu-stack) for SPARC,
both 32-bit (v9) and 64-bit targets.
Salud!
Jose E. Marchesi (4):
libebl: new backend attribute ra_offset.
libdwfl: make the unwinder aware of the backend defined ra_offset.
backends: sparc: support for core backtraces
backends: sparc: support for live backtraces
backends/ChangeLog | 16 +++++
backends/Makefile.am | 3 +-
backends/sparc_cfi.c | 83 ++++++++++++++++++++++++
backends/sparc_corenote.c | 10 ++-
backends/sparc_init.c | 8 +++
backends/sparc_initreg.c | 129 ++++++++++++++++++++++++++++++++++++++
libdwfl/ChangeLog | 7 +++
libdwfl/dwfl_frame.c | 2 +-
libdwfl/frame_unwind.c | 9 ++-
libebl/ChangeLog | 6 ++
libebl/eblabicfi.c | 6 ++
libebl/libebl.h | 6 ++
libebl/libeblP.h | 6 ++
tests/ChangeLog | 5 ++
tests/Makefile.am | 2 +-
tests/backtrace.sparc.core.bz2 | Bin 0 -> 9628 bytes
tests/backtrace.sparc.exec.bz2 | Bin 0 -> 348964 bytes
tests/run-backtrace-core-sparc.sh | 20 ++++++
18 files changed, 313 insertions(+), 5 deletions(-)
create mode 100644 backends/sparc_cfi.c
create mode 100644 backends/sparc_initreg.c
create mode 100644 tests/backtrace.sparc.core.bz2
create mode 100755 tests/backtrace.sparc.exec.bz2
create mode 100755 tests/run-backtrace-core-sparc.sh
--
2.3.4
8 years, 3 months
[PATCH] tests: Use valgrind --leak-check=full.
by Mark Wielaard
When --enable-valgrind is given run the testsuite with --leak-check=full
treating any memory leak as a failure. Also disable valgrind for those
tests that trigger a valgrind bug.
https://bugs.kde.org/show_bug.cgi?id=327427
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
tests/ChangeLog | 8 ++++++++
tests/Makefile.am | 2 +-
tests/run-backtrace-demangle.sh | 11 +++++++++++
tests/run-stack-d-test.sh | 10 ++++++++++
tests/run-stack-demangled-test.sh | 10 ++++++++++
tests/run-stack-i-test.sh | 10 ++++++++++
6 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 4c56400..2940e38 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,11 @@
+2015-12-02 Mark Wielaard <mjw(a)redhat.com>
+
+ * Makefile.am (valgrind_cmd): Use --leak-check=full.
+ * run-backtrace-demangle.sh: Disable valgrind.
+ * run-stack-demangled-test.sh: Likewise.
+ * run-stack-d-test.sh: Likewise.
+ * run-stack-i-test.sh: Likewise.
+
2015-12-01 Mark Wielaard <mjw(a)redhat.com>
* test-flag-nobits.c (main): Call elf_end.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 30cf137..0077c0f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -307,7 +307,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-lfs-symbols.sh lfs-symbols testfile-nolfs.bz2
if USE_VALGRIND
-valgrind_cmd='valgrind -q --error-exitcode=1 --run-libc-freeres=no'
+valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
endif
diff --git a/tests/run-backtrace-demangle.sh b/tests/run-backtrace-demangle.sh
index 71a7351..2d25324 100755
--- a/tests/run-backtrace-demangle.sh
+++ b/tests/run-backtrace-demangle.sh
@@ -26,6 +26,11 @@ child=testfile-backtrace-demangle
testfiles $child{,.core}
tempfiles $child.{bt,err}
+# Disable valgrind while dumping because of a bug unmapping libc.so.
+# https://bugs.kde.org/show_bug.cgi?id=327427
+SAVED_VALGRIND_CMD="$VALGRIND_CMD"
+unset VALGRIND_CMD
+
# There can be more than 3 frames, but depending on the system/installed
# glibc we might not be able to unwind fully till the end.
# cxxfunc -> f -> main
@@ -33,6 +38,12 @@ tempfiles $child.{bt,err}
# (exit code 1)
testrun ${abs_top_builddir}/src/stack -n 2 -e $child --core $child.core >$child.bt 2>$child.err || exitcode=$?
cat $child.{bt,err}
+
+if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
+ VALGRIND_CMD="$SAVED_VALGRIND_CMD"
+ export VALGRIND_CMD
+fi
+
if test $exitcode != 1 || ! grep "shown max number of frames" $child.err; then
echo >&2 $2: expected more than 2 frames
false
diff --git a/tests/run-stack-d-test.sh b/tests/run-stack-d-test.sh
index 4198201..a9f0380 100755
--- a/tests/run-stack-d-test.sh
+++ b/tests/run-stack-d-test.sh
@@ -68,6 +68,11 @@ else
STACKCMD=${abs_top_builddir}/src/stack
fi
+# Disable valgrind while dumping because of a bug unmapping libc.so.
+# https://bugs.kde.org/show_bug.cgi?id=327427
+SAVED_VALGRIND_CMD="$VALGRIND_CMD"
+unset VALGRIND_CMD
+
# Without -d the top function comes out as fu. Use --raw to not demangle.
testrun_compare ${abs_top_builddir}/src/stack -r -n 2 -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
PID 13654 - core
@@ -109,4 +114,9 @@ TID 13654:
$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
EOF
+if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
+ VALGRIND_CMD="$SAVED_VALGRIND_CMD"
+ export VALGRIND_CMD
+fi
+
exit 0
diff --git a/tests/run-stack-demangled-test.sh b/tests/run-stack-demangled-test.sh
index 98f8ff8..c26918f 100755
--- a/tests/run-stack-demangled-test.sh
+++ b/tests/run-stack-demangled-test.sh
@@ -37,6 +37,11 @@ else
STACKCMD=${abs_top_builddir}/src/stack
fi
+# Disable valgrind while dumping because of a bug unmapping libc.so.
+# https://bugs.kde.org/show_bug.cgi?id=327427
+SAVED_VALGRIND_CMD="$VALGRIND_CMD"
+unset VALGRIND_CMD
+
# Without -d the top function comes out as fu.
testrun_compare ${abs_top_builddir}/src/stack -n 2 -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
PID 13654 - core
@@ -92,4 +97,9 @@ TID 13654:
$STACKCMD: tid 13654: shown max number of frames (6, use -n 0 for unlimited)
EOF
+if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
+ VALGRIND_CMD="$SAVED_VALGRIND_CMD"
+ export VALGRIND_CMD
+fi
+
exit 0
diff --git a/tests/run-stack-i-test.sh b/tests/run-stack-i-test.sh
index ffab85f..3722ab0 100755
--- a/tests/run-stack-i-test.sh
+++ b/tests/run-stack-i-test.sh
@@ -29,6 +29,11 @@ else
STACKCMD=${abs_top_builddir}/src/stack
fi
+# Disable valgrind while dumping because of a bug unmapping libc.so.
+# https://bugs.kde.org/show_bug.cgi?id=327427
+SAVED_VALGRIND_CMD="$VALGRIND_CMD"
+unset VALGRIND_CMD
+
# Compare with run-stack-d-test.sh to see the output without --inlines.
# Only two call frames are visible (there is a jump from main to fu or
# fubar). Explicitly use --raw so demangler support being configured in
@@ -68,4 +73,9 @@ TID 13654:
$STACKCMD: tid 13654: shown max number of frames (6, use -n 0 for unlimited)
EOF
+if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
+ VALGRIND_CMD="$SAVED_VALGRIND_CMD"
+ export VALGRIND_CMD
+fi
+
exit 0
--
2.5.0
8 years, 3 months