diff options
-rw-r--r-- | libdw/ChangeLog | 4 | ||||
-rw-r--r-- | libdw/libdw.map | 1 | ||||
-rw-r--r-- | libdwelf/ChangeLog | 8 | ||||
-rw-r--r-- | libdwelf/Makefile.am | 2 | ||||
-rw-r--r-- | libdwelf/dwelf_dwarf_gnu_debugaltlink.c | 62 | ||||
-rw-r--r-- | libdwelf/libdwelf.h | 10 | ||||
-rw-r--r-- | libdwelf/libdwelfP.h | 1 | ||||
-rw-r--r-- | tests/ChangeLog | 7 | ||||
-rw-r--r-- | tests/Makefile.am | 7 | ||||
-rw-r--r-- | tests/debugaltlink.c | 83 | ||||
-rwxr-xr-x | tests/run-debugaltlink.sh | 34 |
11 files changed, 215 insertions, 4 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 0b9b649c..49004325 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2014-04-24 Florian Weimer <fweimer@redhat.com> + + * libdw.map (ELFUTILS_0.159): Export dwelf_dwarf_gnu_debugaltlink. + 2014-04-22 Florian Weimer <fweimer@redhat.com> * dwarf_getalt.c, dwarf_setalt.c: New files. diff --git a/libdw/libdw.map b/libdw/libdw.map index 71247e37..35299808 100644 --- a/libdw/libdw.map +++ b/libdw/libdw.map @@ -297,5 +297,6 @@ ELFUTILS_0.159 { global: dwarf_getalt; dwarf_setalt; + dwelf_dwarf_gnu_debugaltlink; dwelf_elf_gnu_debuglink; } ELFUTILS_0.158; diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog index caf1c5dd..aa291320 100644 --- a/libdwelf/ChangeLog +++ b/libdwelf/ChangeLog @@ -1,3 +1,11 @@ +2014-04-24 Florian Weimer <fweimer@redhat.com> + + * dwelf_dwarf_gnu_debugaltlink.c: New file. + * Makefile.am (libdwelf_a_SOURCES): Add it. + * libdwelf.h (dwelf_dwarf_gnu_debugaltlink): Declare new function. + * libdwelfP.h (dwelf_dwarf_gnu_debugaltlink): Add internal + declaration. + 2014-04-11 Mark Wielaard <mjw@redhat.com> * Makefile.am: New file. diff --git a/libdwelf/Makefile.am b/libdwelf/Makefile.am index 0f684d4a..1ca3a5cd 100644 --- a/libdwelf/Makefile.am +++ b/libdwelf/Makefile.am @@ -38,7 +38,7 @@ noinst_LIBRARIES = libdwelf.a libdwelf_pic.a pkginclude_HEADERS = libdwelf.h noinst_HEADERS = libdwelfP.h -libdwelf_a_SOURCES = dwelf_elf_gnu_debuglink.c +libdwelf_a_SOURCES = dwelf_elf_gnu_debuglink.c dwelf_dwarf_gnu_debugaltlink.c libdwelf = $(libdw) diff --git a/libdwelf/dwelf_dwarf_gnu_debugaltlink.c b/libdwelf/dwelf_dwarf_gnu_debugaltlink.c new file mode 100644 index 00000000..b8285d09 --- /dev/null +++ b/libdwelf/dwelf_dwarf_gnu_debugaltlink.c @@ -0,0 +1,62 @@ +/* Returns the file name and build ID stored in the .gnu_altdebuglink if found. + Copyright (C) 2014 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 either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "libdwelfP.h" + +ssize_t +dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf, + const char **name_p, + const void **build_idp) +{ + Elf_Data *data = dwarf->sectiondata[IDX_gnu_debugaltlink]; + if (data == NULL) + { + return 0; + } + + const void *ptr = memchr (data->d_buf, '\0', data->d_size); + if (ptr == NULL) + { + __libdw_seterrno (DWARF_E_INVALID_ELF); + return -1; + } + size_t build_id_len = data->d_size - (ptr - data->d_buf + 1); + if (build_id_len == 0 || (size_t) (ssize_t) build_id_len != build_id_len) + { + __libdw_seterrno (DWARF_E_INVALID_ELF); + return -1; + } + *name_p = data->d_buf; + *build_idp = ptr + 1; + return build_id_len; +} +INTDEF(dwelf_dwarf_gnu_debugaltlink) diff --git a/libdwelf/libdwelf.h b/libdwelf/libdwelf.h index 5d636d16..6f1dbd3a 100644 --- a/libdwelf/libdwelf.h +++ b/libdwelf/libdwelf.h @@ -47,6 +47,16 @@ extern "C" { section or some other error occured. */ extern const char *dwelf_elf_gnu_debuglink (Elf *elf, GElf_Word *crc); +/* Returns the name and build ID from the .gnu_debugaltlink section if + found in the ELF. On success, pointers to the name and build ID + are written to *NAMEP and *BUILDID_P, and the positive length of + the build ID is returned. Returns 0 if the ELF lacks a + .gnu_debugaltlink section. Returns -1 in case of malformed data or + other errors. */ +extern ssize_t dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf, + const char **namep, + const void **build_idp); + #ifdef __cplusplus } #endif diff --git a/libdwelf/libdwelfP.h b/libdwelf/libdwelfP.h index bdadc8b7..c00a834c 100644 --- a/libdwelf/libdwelfP.h +++ b/libdwelf/libdwelfP.h @@ -36,5 +36,6 @@ /* Avoid PLT entries. */ INTDECL (dwelf_elf_gnu_debuglink) +INTDECL (dwelf_dwarf_gnu_debugaltlink) #endif /* libdwelfP.h */ diff --git a/tests/ChangeLog b/tests/ChangeLog index 990d5d53..3e702055 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +2014-04-24 Florian Weimer <fweimer@redhat.com> + + * debugaltlink.c, run-debugaltlink.sh: New files. + * Makefile.am (check_PROGRAMS): Add debugaltlink. + (TESTS): Add run-debugaltlink.sh. + (debugaltlink_LDADD): New variable. + 2014-04-11 Mark Wielaard <mjw@redhat.com> * Makefile.am (AM_CPPFLAGS): Add -I libdwelf. diff --git a/tests/Makefile.am b/tests/Makefile.am index 67c7fbcb..33803fca 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -49,7 +49,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ alldts md5-sha1-test typeiter typeiter2 low_high_pc \ test-elf_cntl_gelf_getshdr dwflsyms dwfllines \ dwfl-report-elf-align varlocs backtrace backtrace-child \ - backtrace-data backtrace-dwarf debuglink + backtrace-data backtrace-dwarf debuglink debugaltlink asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -86,7 +86,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-readelf-macro.sh run-readelf-loc.sh \ run-readelf-aranges.sh run-readelf-line.sh \ run-native-test.sh run-bug1-test.sh \ - run-debuglink.sh \ + run-debuglink.sh run-debugaltlink.sh \ dwfl-bug-addr-overflow run-addrname-test.sh \ dwfl-bug-fd-leak dwfl-bug-report \ run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \ @@ -176,7 +176,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \ run-readelf-test4.sh run-readelf-twofiles.sh \ run-bug1-test.sh testfile28.bz2 testfile28.rdwr.bz2 \ - run-debuglink.sh \ + run-debuglink.sh run-debugaltlink.sh \ testfile29.bz2 testfile29.rdwr.bz2 \ testfile30.bz2 testfile31.bz2 testfile32.bz2 testfile33.bz2 \ testfile34.bz2 testfile35.bz2 testfile35.debug.bz2 \ @@ -405,6 +405,7 @@ backtrace_data_LDADD = $(libdw) $(libelf) backtrace_dwarf_CFLAGS = -Wno-unused-parameter backtrace_dwarf_LDADD = $(libdw) $(libelf) debuglink_LDADD = $(libdw) $(libelf) +debugaltlink_LDADD = $(libdw) $(libelf) if GCOV check: check-am coverage diff --git a/tests/debugaltlink.c b/tests/debugaltlink.c new file mode 100644 index 00000000..6d97d500 --- /dev/null +++ b/tests/debugaltlink.c @@ -0,0 +1,83 @@ +/* Test program for dwelf_dwarf_gnu_debugaltlink, print name and build ID. + Copyright (C) 2014 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/>. */ + +#include <config.h> +#include <assert.h> +#include <inttypes.h> +#include <err.h> +#include <errno.h> +#include ELFUTILS_HEADER(dw) +#include ELFUTILS_HEADER(dwelf) +#include <stdio.h> +#include <error.h> +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +int +main (int argc, char *argv[]) +{ + if (argc < 2) + error (EXIT_FAILURE, 0, "No input file given"); + + elf_version (EV_CURRENT); + + for (int i = 1; i < argc; i++) + { + const char *file = argv[i]; + int fd = open (file, O_RDONLY); + if (fd < 0) + error (EXIT_FAILURE, errno, "couldn't open file '%s'", file); + + Dwarf *dwarf = dwarf_begin (fd, DWARF_C_READ); + if (dwarf == NULL) + { + printf("%s: dwarf_begin failed: %s\n", file, dwarf_errmsg (-1)); + close (fd); + continue; + } + + const char *name; + const void *build_id; + ssize_t ret = dwelf_dwarf_gnu_debugaltlink + (dwarf, &name, &build_id); + switch (ret) + { + case 0: + printf ("%s: <no .gnu_debugaltlink section>\n", file); + break; + case -1: + errx (1, "dwelf_dwarf_gnu_debugaltlink (%s): %s", + file, dwarf_errmsg (-1)); + default: + printf ("%s: %s, build ID: ", file, name); + const unsigned char *p = build_id; + const unsigned char *end = p + ret; + while (p < end) + printf("%02x", (unsigned)*p++); + putchar('\n'); + } + + dwarf_end (dwarf); + close (fd); + } + + return 0; +} diff --git a/tests/run-debugaltlink.sh b/tests/run-debugaltlink.sh new file mode 100755 index 00000000..fa7dd268 --- /dev/null +++ b/tests/run-debugaltlink.sh @@ -0,0 +1,34 @@ +#! /bin/sh +# Copyright (C) 2014 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 + +# Just some random testfiles, four with, one without .gnu_debugaltlink +testfiles testfile42 testfile_multi_main testfile-dwzstr \ + test-offset-loop libtestfile_multi_shared.so + +testrun_compare ${abs_builddir}/debugaltlink testfile42 \ + testfile_multi_main testfile-dwzstr \ + test-offset-loop libtestfile_multi_shared.so <<\EOF +testfile42: <no .gnu_debugaltlink section> +testfile_multi_main: testfile_multi.dwz, build ID: a0d6c06e0d912d74033b6fe2808753cae8f6f594 +testfile-dwzstr: testfile-dwzstr.multi, build ID: 6da22627dae55c1d62cf9122827c665e240a056b +test-offset-loop: test-offset-loop.alt, build ID: 066bbf1a7bc5676f5015ee1966a088f23bdb83ae +libtestfile_multi_shared.so: testfile_multi.dwz, build ID: a0d6c06e0d912d74033b6fe2808753cae8f6f594 +EOF + +exit 0 |