diff options
| author | Mark Wielaard <[email protected]> | 2014-04-30 23:00:40 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2014-05-01 13:51:31 +0200 |
| commit | d81d32d2a4f92355e4c677b578147dfe819251b9 (patch) | |
| tree | 79c9bf17a4334d86c220676fc8c6b54b1dacee34 /tests | |
| parent | 920f03dcd3a6dd46b3d88c45be8dbfa0adc780dd (diff) | |
libdwelf: Add dwelf_elf_gnu_build_id.
Move internal function __libdwfl_find_build_id to libdwelf and use it to
add a public dwelf_elf_gnu_build_id function to extract the NT_GNU_BUILD_ID
from an ELF file using either the shdrs or phdrs. Adjust internal callers
and add a testcase.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 8 | ||||
| -rw-r--r-- | tests/Makefile.am | 12 | ||||
| -rw-r--r-- | tests/buildid.c | 81 | ||||
| -rwxr-xr-x | tests/run-buildid.sh | 38 | ||||
| -rw-r--r-- | tests/testfile42_noshdrs.bz2 | bin | 0 -> 6746 bytes |
5 files changed, 135 insertions, 4 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 1c30778d..ff396d50 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +2014-04-30 Mark Wielaard <[email protected]> + + * buildid.c, buildid.sh, testfile42_noshdrs.bz2: New files. + * Makefile.am (check_PROGRAMS): Add buildid. + (TESTS): Add run-buildid.sh. + (EXTRA_DISTS): Add run-buildid.sh and testfile42_noshdrs.bz2. + (buildid_LDADD): New variable. + 2014-04-24 Florian Weimer <[email protected]> * allfcts.c (setup_alt): New function. diff --git a/tests/Makefile.am b/tests/Makefile.am index 33803fca..dd110a52 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -49,7 +49,9 @@ 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 debugaltlink + backtrace-data backtrace-dwarf debuglink debugaltlink \ + buildid + asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -86,7 +88,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-debugaltlink.sh \ + run-debuglink.sh run-debugaltlink.sh run-buildid.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,14 +178,15 @@ 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-debugaltlink.sh \ + run-debuglink.sh run-debugaltlink.sh run-buildid.sh \ testfile29.bz2 testfile29.rdwr.bz2 \ testfile30.bz2 testfile31.bz2 testfile32.bz2 testfile33.bz2 \ testfile34.bz2 testfile35.bz2 testfile35.debug.bz2 \ testfile36.bz2 testfile36.debug.bz2 \ testfile37.bz2 testfile37.debug.bz2 \ testfile38.bz2 testfile39.bz2 testfile40.bz2 testfile40.debug.bz2 \ - testfile41.bz2 testfile42.bz2 testfile43.bz2 \ + testfile41.bz2 testfile42.bz2 testfile42_noshdrs.bz2 \ + testfile43.bz2 \ testfile44.S.bz2 testfile44.expect.bz2 run-disasm-x86.sh \ testfile45.S.bz2 testfile45.expect.bz2 run-disasm-x86-64.sh \ testfile46.bz2 testfile47.bz2 testfile48.bz2 testfile48.debug.bz2 \ @@ -406,6 +409,7 @@ backtrace_dwarf_CFLAGS = -Wno-unused-parameter backtrace_dwarf_LDADD = $(libdw) $(libelf) debuglink_LDADD = $(libdw) $(libelf) debugaltlink_LDADD = $(libdw) $(libelf) +buildid_LDADD = $(libdw) $(libelf) if GCOV check: check-am coverage diff --git a/tests/buildid.c b/tests/buildid.c new file mode 100644 index 00000000..87c18773 --- /dev/null +++ b/tests/buildid.c @@ -0,0 +1,81 @@ +/* Test program for dwelf_elf_gnu_build_id, print 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(elf) +#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); + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + { + printf("%s: elf_begin failed: %s\n", file, elf_errmsg (-1)); + close (fd); + continue; + } + + const void *build_id; + ssize_t len = dwelf_elf_gnu_build_id (elf, &build_id); + switch (len) + { + case 0: + printf ("%s: <no NT_GNU_BUILD_ID note>\n", file); + break; + case -1: + errx (1, "dwelf_elf_gnu_build_id (%s): %s", + file, elf_errmsg (-1)); + default: + printf ("%s: build ID: ", file); + const unsigned char *p = build_id; + const unsigned char *end = p + len; + while (p < end) + printf("%02x", (unsigned)*p++); + putchar('\n'); + } + + elf_end (elf); + close (fd); + } + + return 0; +} diff --git a/tests/run-buildid.sh b/tests/run-buildid.sh new file mode 100755 index 00000000..31cec24d --- /dev/null +++ b/tests/run-buildid.sh @@ -0,0 +1,38 @@ +#! /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 build-id, +# and one without shdrs forcing reading the notes through phdrs. +# eu-strip --strip-sections -g --output=testfile42_noshdrs testfile42 +# See also run-debugaltlink.sh. +testfiles testfile42 testfile_multi.dwz testfile-dwzstr.multi \ + test-offset-loop.alt testfile14 testfile42_noshdrs + +testrun_compare ${abs_builddir}/buildid testfile42 testfile42_noshdrs \ + testfile_multi.dwz testfile-dwzstr.multi \ + test-offset-loop.alt testfile14 <<\EOF +testfile42: build ID: d826d96c4d097bdc5c254b1f7344a907e36b0439 +testfile42_noshdrs: build ID: d826d96c4d097bdc5c254b1f7344a907e36b0439 +testfile_multi.dwz: build ID: a0d6c06e0d912d74033b6fe2808753cae8f6f594 +testfile-dwzstr.multi: build ID: 6da22627dae55c1d62cf9122827c665e240a056b +test-offset-loop.alt: build ID: 066bbf1a7bc5676f5015ee1966a088f23bdb83ae +testfile14: <no NT_GNU_BUILD_ID note> +EOF + +exit 0 diff --git a/tests/testfile42_noshdrs.bz2 b/tests/testfile42_noshdrs.bz2 Binary files differnew file mode 100644 index 00000000..e50f7500 --- /dev/null +++ b/tests/testfile42_noshdrs.bz2 |
