From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============7735118067614830081==" MIME-Version: 1.0 From: Mark Wielaard To: elfutils-devel@lists.fedorahosted.org Subject: [PATCH 7/9] libdwelf: Add dwelf_elf_gnu_build_id. Date: Sat, 03 May 2014 00:40:09 +0200 Message-ID: <1399070411-5284-8-git-send-email-mjw@redhat.com> In-Reply-To: 1399070411-5284-1-git-send-email-mjw@redhat.com --===============7735118067614830081== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 --- libdw/ChangeLog | 4 + libdw/libdw.map | 1 + libdwelf/ChangeLog | 9 ++ libdwelf/Makefile.am | 6 +- .../dwelf_elf_gnu_build_id.c | 126 ++++++-----------= ---- libdwelf/libdwelf.h | 8 ++ libdwelf/libdwelfP.h | 1 + libdwfl/ChangeLog | 10 ++ libdwfl/dwfl_module_build_id.c | 92 +-------------- libdwfl/dwfl_module_getdwarf.c | 31 +---- libdwfl/dwfl_segment_report_module.c | 11 +- tests/ChangeLog | 8 ++ tests/Makefile.am | 12 +- tests/buildid.c | 81 +++++++++++++ tests/run-buildid.sh | 38 +++++++ tests/testfile42_noshdrs.bz2 | Bin 0 -> 6746 bytes 16 files changed, 222 insertions(+), 216 deletions(-) copy libdwfl/dwfl_module_build_id.c =3D> libdwelf/dwelf_elf_gnu_build_id.c= (60%) create mode 100644 tests/buildid.c create mode 100755 tests/run-buildid.sh create mode 100644 tests/testfile42_noshdrs.bz2 diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 3152239..94ef03c 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2014-04-30 Mark Wielaard + + * libdw.map (ELFUTILS_0.159): Add dwelf_elf_gnu_build_id. + 2014-04-15 Florian Weimer = * dwarf_begin_elf.c (__check_build_id, try_debugaltlink) diff --git a/libdw/libdw.map b/libdw/libdw.map index 3529980..899e13e 100644 --- a/libdw/libdw.map +++ b/libdw/libdw.map @@ -299,4 +299,5 @@ ELFUTILS_0.159 { dwarf_setalt; dwelf_dwarf_gnu_debugaltlink; dwelf_elf_gnu_debuglink; + dwelf_elf_gnu_build_id; } ELFUTILS_0.158; diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog index aa29132..9f95ea8 100644 --- a/libdwelf/ChangeLog +++ b/libdwelf/ChangeLog @@ -1,3 +1,12 @@ +2014-04-30 Mark Wielaard + + * Makefile.am (AM_CPPFLAGS): Add libdwfl and libebl include dirs. + (libdwelf_a_SOURCES): Add dwelf_elf_gnu_build_id.c + * dwelf_elf_gnu_build_id.c: New file. Moved libdwfl function + __libdwfl_find_elf_build_id here. + * libdwelf.h (dwelf_elf_gnu_build_id): Declare new function. + * libdwelfP.h (dwelf_elf_gnu_build_id): Add internal declaration. + 2014-04-24 Florian Weimer = * dwelf_dwarf_gnu_debugaltlink.c: New file. diff --git a/libdwelf/Makefile.am b/libdwelf/Makefile.am index 1ca3a5c..cd4b7dd 100644 --- a/libdwelf/Makefile.am +++ b/libdwelf/Makefile.am @@ -30,7 +30,8 @@ ## not, see . ## include $(top_srcdir)/config/eu.am -AM_CPPFLAGS +=3D -I$(srcdir)/../libelf -I$(srcdir)/../libdw +AM_CPPFLAGS +=3D -I$(srcdir)/../libelf -I$(srcdir)/../libdw \ + -I$(srcdir)/../libdwfl -I$(srcdir)/../libebl VERSION =3D 1 = noinst_LIBRARIES =3D libdwelf.a libdwelf_pic.a @@ -38,7 +39,8 @@ noinst_LIBRARIES =3D libdwelf.a libdwelf_pic.a pkginclude_HEADERS =3D libdwelf.h noinst_HEADERS =3D libdwelfP.h = -libdwelf_a_SOURCES =3D dwelf_elf_gnu_debuglink.c dwelf_dwarf_gnu_debugaltl= ink.c +libdwelf_a_SOURCES =3D dwelf_elf_gnu_debuglink.c dwelf_dwarf_gnu_debugaltl= ink.c \ + dwelf_elf_gnu_build_id.c = libdwelf =3D $(libdw) = diff --git a/libdwfl/dwfl_module_build_id.c b/libdwelf/dwelf_elf_gnu_build_= id.c similarity index 60% copy from libdwfl/dwfl_module_build_id.c copy to libdwelf/dwelf_elf_gnu_build_id.c index cae007b..1ed501d 100644 --- a/libdwfl/dwfl_module_build_id.c +++ b/libdwelf/dwelf_elf_gnu_build_id.c @@ -1,5 +1,5 @@ -/* Return build ID information for a module. - Copyright (C) 2007-2010 Red Hat, Inc. +/* Returns the build id if found in a NT_GNU_BUILD_ID note. + Copyright (C) 2014 Red Hat, Inc. This file is part of elfutils. = This file is free software; you can redistribute it and/or modify @@ -26,49 +26,22 @@ the GNU Lesser General Public License along with this program. If not, see . */ = -#include "libdwflP.h" - -static int -found_build_id (Dwfl_Module *mod, bool set, - const void *bits, int len, GElf_Addr vaddr) -{ - if (!set) - /* When checking bits, we do not compare VADDR because the - address found in a debuginfo file may not match the main - file as modified by prelink. */ - return 1 + (mod->build_id_len =3D=3D len - && !memcmp (bits, mod->build_id_bits, len)); - - void *copy =3D malloc (len); - if (unlikely (copy =3D=3D NULL)) - { - __libdwfl_seterrno (DWFL_E_NOMEM); - return -1; - } +#ifdef HAVE_CONFIG_H +# include +#endif = - mod->build_id_bits =3D memcpy (copy, bits, len); - mod->build_id_vaddr =3D vaddr; - mod->build_id_len =3D len; - return len; -} +#include "libdwelfP.h" +#include "libdwflP.h" = #define NO_VADDR ((GElf_Addr) -1l) = -int -internal_function -__libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf, - const void **build_id_bits, - GElf_Addr *build_id_elfaddr, int *build_id_len) +/* Defined here for reuse. The dwelf interface doesn't care about the + address of the note, but libdwfl does. */ +static int +find_elf_build_id (Dwfl_Module *mod, int e_type, Elf *elf, + const void **build_id_bits, GElf_Addr *build_id_elfaddr, + int *build_id_len) { - GElf_Ehdr ehdr_mem, *ehdr =3D gelf_getehdr (elf, &ehdr_mem); - if (unlikely (ehdr =3D=3D NULL)) - { - __libdwfl_seterrno (DWFL_E_LIBELF); - return -1; - } - // MOD->E_TYPE is zero here. - assert (ehdr->e_type !=3D ET_REL || mod !=3D NULL); - int check_notes (Elf_Data *data, GElf_Addr data_elfaddr) { size_t pos =3D 0; @@ -100,7 +73,8 @@ __libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf, size_t phnum; if (unlikely (elf_getphdrnum (elf, &phnum) !=3D 0)) { - __libdwfl_seterrno (DWFL_E_LIBELF); + if (mod !=3D NULL) + __libdwfl_seterrno (DWFL_E_LIBELF); return -1; } for (size_t i =3D 0; result =3D=3D 0 && i < phnum; ++i) @@ -126,7 +100,7 @@ __libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf, GElf_Addr vaddr =3D 0; if (!(shdr->sh_flags & SHF_ALLOC)) vaddr =3D NO_VADDR; - else if (mod =3D=3D NULL || ehdr->e_type !=3D ET_REL) + else if (mod =3D=3D NULL || e_type !=3D ET_REL) vaddr =3D shdr->sh_addr; else if (__libdwfl_relocate_value (mod, elf, &shstrndx, elf_ndxscn (scn), &vaddr)) @@ -141,61 +115,33 @@ __libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *e= lf, = int internal_function -__libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf) -{ - const void *build_id_bits; - GElf_Addr build_id_elfaddr; - int build_id_len; - - int result =3D __libdwfl_find_elf_build_id (mod, elf, &build_id_bits, - &build_id_elfaddr, &build_id_len); - if (result <=3D 0) - return result; - - GElf_Addr build_id_vaddr =3D build_id_elfaddr + (build_id_elfaddr !=3D 0 - ? mod->main_bias : 0); - return found_build_id (mod, set, build_id_bits, build_id_len, build_id_v= addr); -} - -int -dwfl_module_build_id (Dwfl_Module *mod, - const unsigned char **bits, GElf_Addr *vaddr) +__libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf, + const void **build_id_bits, + GElf_Addr *build_id_elfaddr, int *build_id_len) { - if (mod =3D=3D NULL) - return -1; - - if (mod->build_id_len =3D=3D 0 && mod->main.elf !=3D NULL) + GElf_Ehdr ehdr_mem, *ehdr =3D gelf_getehdr (elf, &ehdr_mem); + if (unlikely (ehdr =3D=3D NULL)) { - /* We have the file, but have not examined it yet. */ - int result =3D __libdwfl_find_build_id (mod, true, mod->main.elf); - if (result <=3D 0) - { - mod->build_id_len =3D -1; /* Cache negative result. */ - return result; - } + __libdwfl_seterrno (DWFL_E_LIBELF); + return -1; } + // MOD->E_TYPE is zero here. + assert (ehdr->e_type !=3D ET_REL || mod !=3D NULL); = - if (mod->build_id_len <=3D 0) - return 0; - - *bits =3D mod->build_id_bits; - *vaddr =3D mod->build_id_vaddr; - return mod->build_id_len; + return find_elf_build_id (mod, ehdr->e_type, elf, + build_id_bits, build_id_elfaddr, build_id_len); } -INTDEF (dwfl_module_build_id) -NEW_VERSION (dwfl_module_build_id, ELFUTILS_0.138) = -#ifdef SHARED -COMPAT_VERSION (dwfl_module_build_id, ELFUTILS_0.130, vaddr_at_end) - -int -_compat_vaddr_at_end_dwfl_module_build_id (Dwfl_Module *mod, - const unsigned char **bits, - GElf_Addr *vaddr) +ssize_t +dwelf_elf_gnu_build_id (Elf *elf, const void **build_idp) { - int result =3D INTUSE(dwfl_module_build_id) (mod, bits, vaddr); + GElf_Addr build_id_elfaddr; + int build_id_len; + int result =3D find_elf_build_id (NULL, ET_NONE, elf, build_idp, + &build_id_elfaddr, &build_id_len); if (result > 0) - *vaddr +=3D (result + 3) & -4; + return build_id_len; + return result; } -#endif +INTDEF(dwelf_elf_gnu_build_id) diff --git a/libdwelf/libdwelf.h b/libdwelf/libdwelf.h index 6f1dbd3..e16dc0f 100644 --- a/libdwelf/libdwelf.h +++ b/libdwelf/libdwelf.h @@ -57,6 +57,14 @@ extern ssize_t dwelf_dwarf_gnu_debugaltlink (Dwarf *dwar= f, const char **namep, const void **build_idp); = +/* Returns the build ID as found in a NT_GNU_BUILD_ID note from either + a SHT_NOTE section or from a PT_NOTE segment if the ELF file + doesn't contain any section headers. On success a pointer to the + build ID is written to *BUILDID_P, and the positive length of the + build ID is returned. Returns 0 if the ELF lacks a NT_GNU_BUILD_ID + note. Returns -1 in case of malformed data or other errors. */ +extern ssize_t dwelf_elf_gnu_build_id (Elf *elf, const void **build_idp); + #ifdef __cplusplus } #endif diff --git a/libdwelf/libdwelfP.h b/libdwelf/libdwelfP.h index c00a834..d83c759 100644 --- a/libdwelf/libdwelfP.h +++ b/libdwelf/libdwelfP.h @@ -37,5 +37,6 @@ /* Avoid PLT entries. */ INTDECL (dwelf_elf_gnu_debuglink) INTDECL (dwelf_dwarf_gnu_debugaltlink) +INTDECL (dwelf_elf_gnu_build_id) = #endif /* libdwelfP.h */ diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 62ea412..7e4234d 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,13 @@ +2014-04-30 Mark Wielaard + + * dwfl_module_build_id.c (__libdwfl_find_elf_build_id): Moved to + dwelf_elf_gnu_build_id.c. + (__libdwfl_find_build_id): Add assert to make sure mod is never NULL. + * dwfl_segment_report_module.c (dwfl_segment_report_module): Call + dwelf_elf_gnu_build_id directly instead of __libdwfl_find_build_id. + * dwfl_module_getdwarf.c (__check_build_id): Implement using + dwelf_elf_gnu_build_id. + 2014-04-15 Florian Weimer = * dwfl_module_getdwarf.c (__check_build_id): Moved from libdw. diff --git a/libdwfl/dwfl_module_build_id.c b/libdwfl/dwfl_module_build_id.c index cae007b..350bbf8 100644 --- a/libdwfl/dwfl_module_build_id.c +++ b/libdwfl/dwfl_module_build_id.c @@ -1,5 +1,5 @@ /* Return build ID information for a module. - Copyright (C) 2007-2010 Red Hat, Inc. + Copyright (C) 2007-2010, 2014 Red Hat, Inc. This file is part of elfutils. = This file is free software; you can redistribute it and/or modify @@ -52,93 +52,6 @@ found_build_id (Dwfl_Module *mod, bool set, return len; } = -#define NO_VADDR ((GElf_Addr) -1l) - -int -internal_function -__libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf, - const void **build_id_bits, - GElf_Addr *build_id_elfaddr, int *build_id_len) -{ - GElf_Ehdr ehdr_mem, *ehdr =3D gelf_getehdr (elf, &ehdr_mem); - if (unlikely (ehdr =3D=3D NULL)) - { - __libdwfl_seterrno (DWFL_E_LIBELF); - return -1; - } - // MOD->E_TYPE is zero here. - assert (ehdr->e_type !=3D ET_REL || mod !=3D NULL); - - int check_notes (Elf_Data *data, GElf_Addr data_elfaddr) - { - size_t pos =3D 0; - GElf_Nhdr nhdr; - size_t name_pos; - size_t desc_pos; - while ((pos =3D gelf_getnote (data, pos, &nhdr, &name_pos, &desc_pos))= > 0) - if (nhdr.n_type =3D=3D NT_GNU_BUILD_ID - && nhdr.n_namesz =3D=3D sizeof "GNU" && !memcmp (data->d_buf + name_pos, - "GNU", sizeof "GNU")) - { - *build_id_bits =3D data->d_buf + desc_pos; - *build_id_elfaddr =3D (data_elfaddr =3D=3D NO_VADDR - ? 0 : data_elfaddr + desc_pos); - *build_id_len =3D nhdr.n_descsz; - return 1; - } - return 0; - } - - size_t shstrndx =3D SHN_UNDEF; - int result =3D 0; - - Elf_Scn *scn =3D elf_nextscn (elf, NULL); - - if (scn =3D=3D NULL) - { - /* No sections, have to look for phdrs. */ - size_t phnum; - if (unlikely (elf_getphdrnum (elf, &phnum) !=3D 0)) - { - __libdwfl_seterrno (DWFL_E_LIBELF); - return -1; - } - for (size_t i =3D 0; result =3D=3D 0 && i < phnum; ++i) - { - GElf_Phdr phdr_mem; - GElf_Phdr *phdr =3D gelf_getphdr (elf, i, &phdr_mem); - if (likely (phdr !=3D NULL) && phdr->p_type =3D=3D PT_NOTE) - result =3D check_notes (elf_getdata_rawchunk (elf, - phdr->p_offset, - phdr->p_filesz, - ELF_T_NHDR), - phdr->p_vaddr); - } - } - else - do - { - GElf_Shdr shdr_mem; - GElf_Shdr *shdr =3D gelf_getshdr (scn, &shdr_mem); - if (likely (shdr !=3D NULL) && shdr->sh_type =3D=3D SHT_NOTE) - { - /* Determine the right sh_addr in this module. */ - GElf_Addr vaddr =3D 0; - if (!(shdr->sh_flags & SHF_ALLOC)) - vaddr =3D NO_VADDR; - else if (mod =3D=3D NULL || ehdr->e_type !=3D ET_REL) - vaddr =3D shdr->sh_addr; - else if (__libdwfl_relocate_value (mod, elf, &shstrndx, - elf_ndxscn (scn), &vaddr)) - vaddr =3D NO_VADDR; - result =3D check_notes (elf_getdata (scn, NULL), vaddr); - } - } - while (result =3D=3D 0 && (scn =3D elf_nextscn (elf, scn)) !=3D NULL); - - return result; -} - int internal_function __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf) @@ -147,6 +60,9 @@ __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf= *elf) GElf_Addr build_id_elfaddr; int build_id_len; = + /* For mod =3D=3D NULL use dwelf_elf_gnu_build_id directly. */ + assert (mod !=3D NULL); + int result =3D __libdwfl_find_elf_build_id (mod, elf, &build_id_bits, &build_id_elfaddr, &build_id_len); if (result <=3D 0) diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index 6163ddb..e8087bf 100644 --- a/libdwfl/dwfl_module_getdwarf.c +++ b/libdwfl/dwfl_module_getdwarf.c @@ -42,34 +42,13 @@ __check_build_id (Dwarf *dw, const uint8_t *build_id, c= onst size_t id_len) return -1; = Elf *elf =3D dw->elf; - Elf_Scn *scn =3D elf_nextscn (elf, NULL); - if (scn =3D=3D NULL) + const void *elf_build_id; + ssize_t elf_id_len =3D INTUSE(dwelf_elf_gnu_build_id) (elf, &elf_build_i= d); + if (elf_id_len < 0) return -1; = - do - { - GElf_Shdr shdr_mem; - GElf_Shdr *shdr =3D gelf_getshdr (scn, &shdr_mem); - if (likely (shdr !=3D NULL) && shdr->sh_type =3D=3D SHT_NOTE) - { - size_t pos =3D 0; - GElf_Nhdr nhdr; - size_t name_pos; - size_t desc_pos; - Elf_Data *data =3D elf_getdata (scn, NULL); - while ((pos =3D gelf_getnote (data, pos, &nhdr, &name_pos, - &desc_pos)) > 0) - if (nhdr.n_type =3D=3D NT_GNU_BUILD_ID - && nhdr.n_namesz =3D=3D sizeof "GNU" - && ! memcmp (data->d_buf + name_pos, "GNU", sizeof "GNU")) - return (nhdr.n_descsz =3D=3D id_len - && ! memcmp (data->d_buf + desc_pos, - build_id, id_len)) ? 0 : 1; - } - } - while ((scn =3D elf_nextscn (elf, scn)) !=3D NULL); - - return -1; + return (id_len =3D=3D (size_t) elf_id_len + && memcmp (build_id, elf_build_id, id_len) =3D=3D 0) ? 0 : 1; } = /* Try to open an debug alt link by name, checking build_id. diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_re= port_module.c index fd967e9..dfecb51 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -494,13 +494,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, cons= t char *name, && module->disk_file_has_build_id && build_id_len > 0) { const void *elf_build_id; - GElf_Addr elf_build_id_elfaddr; - int elf_build_id_len; + ssize_t elf_build_id_len; = - if (__libdwfl_find_elf_build_id (NULL, module->elf, - &elf_build_id, - &elf_build_id_elfaddr, - &elf_build_id_len) > 0) + /* If there is a build id in the elf file, check it. */ + elf_build_id_len =3D INTUSE(dwelf_elf_gnu_build_id) (module->elf, + &elf_build_id); + if (elf_build_id_len > 0) { if (build_id_len !=3D (size_t) elf_build_id_len || memcmp (build_id, elf_build_id, build_id_len) !=3D 0) diff --git a/tests/ChangeLog b/tests/ChangeLog index 1c30778..ff396d5 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +2014-04-30 Mark Wielaard + + * 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 = * allfcts.c (setup_alt): New function. diff --git a/tests/Makefile.am b/tests/Makefile.am index 33803fc..dd110a5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -49,7 +49,9 @@ check_PROGRAMS =3D arextract arsymtest newfile saridx scn= names 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 =3D asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 = @@ -86,7 +88,7 @@ TESTS =3D 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 =3D 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 =3D -Wno-unused-parameter backtrace_dwarf_LDADD =3D $(libdw) $(libelf) debuglink_LDADD =3D $(libdw) $(libelf) debugaltlink_LDADD =3D $(libdw) $(libelf) +buildid_LDADD =3D $(libdw) $(libelf) = if GCOV check: check-am coverage diff --git a/tests/buildid.c b/tests/buildid.c new file mode 100644 index 0000000..87c1877 --- /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 . = */ + +#include +#include +#include +#include +#include +#include ELFUTILS_HEADER(elf) +#include ELFUTILS_HEADER(dwelf) +#include +#include +#include +#include +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + if (argc < 2) + error (EXIT_FAILURE, 0, "No input file given"); + + elf_version (EV_CURRENT); + + for (int i =3D 1; i < argc; i++) + { + const char *file =3D argv[i]; + int fd =3D open (file, O_RDONLY); + if (fd < 0) + error (EXIT_FAILURE, errno, "couldn't open file '%s'", file); + + Elf *elf =3D elf_begin (fd, ELF_C_READ, NULL); + if (elf =3D=3D NULL) + { + printf("%s: elf_begin failed: %s\n", file, elf_errmsg (-1)); + close (fd); + continue; + } + + const void *build_id; + ssize_t len =3D dwelf_elf_gnu_build_id (elf, &build_id); + switch (len) + { + case 0: + printf ("%s: \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 =3D build_id; + const unsigned char *end =3D 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 0000000..31cec24 --- /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 . + +. $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=3Dtestfile42_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: +EOF + +exit 0 diff --git a/tests/testfile42_noshdrs.bz2 b/tests/testfile42_noshdrs.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..e50f750057435211f4aa4baa517= 2b1e3c4fcc4ea GIT binary patch literal 6746 zcmV-g8l~kzT4*^jL0KkKS(a)wkud;k+#|NsC0|NsC0|NsC0|NsC0|NZ~}|NsAg_y7O> z|NsC0|Nr0(a)D*1=3DInXNT!0N%sy$0OUDleN2av*`Q2>pnj7yU%aC-#q(x?Q(a)7?r>^EY z$nNg|`Wx)MXwKya4sg*EK{O(a)_rip+Ff?{F(a)o|8r<0aMy#PtX|@^G#1pG-XfFXes7~ zr1Zr$)jcv{H8!WF(nB#L(lMr*hMuOLMDPlEPbBn%)E<$e)bvKuHcbYIAORXoXwW81 zjT6+sAy3m1c_ey`=3D}oD2#LnA;mW}pBYQ$`w$0&PG6ra&-2X^;UXq)Dg~6G-$V$npt|Pti?@riApGW`b$y zG}9)H8Udpq0ibBm115o{Oo66=3D05kvq00w{n000006-`25OcN1+&=3DUbP%@a(}Xaw{V z45lZfU zV_L}8P~XmoY)0waxq2HJMZoF&DAC~7qyQN*{bbW%s4|KU` z;I9%q)Qc-XeqXwJm44|XHk~Y zK?(V?A;$W~02fS%vh;TxrS&+z>%6?xW(a)+(v)#Id1noy_;K}Z7UGur~D`Dk(|6^FSuv9VaaMKzk6t!S1pk$EJVqbyyEuPK&lW&{HTZ4BFx!SXcP9FX`(`4=3D)o3(a{dr`isqex(=3D>5(3~ zg>?<>)#Ni%Of-^Fhze(O z%x6Cz-T5x~FH_K#<8x%5(a)4PRqdmU`nSFPUt&tLZ8_#AipgKvF=3Dmdnt0o6ezjZrHd; zG2yq&41_p{95NTG!u?jj#V=3Dx|mYhV9NW_NOggE-xZW%>1T!hADwRT5v;ke~883Ih| z5{$NN@=3D**J8Ch-YWoKk8Ofabn5iZQT4Piu-HD-ZjBx$QclylM)V?j*4R9O}klBkhk zdZOu;%x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