diff options
| author | Ulf Hermann <[email protected]> | 2018-10-11 17:20:12 +0200 |
|---|---|---|
| committer | Ulf Hermann <[email protected]> | 2018-10-11 17:54:03 +0200 |
| commit | 5da108a40dd24c7d3e4183ec9ae1904bb3f01575 (patch) | |
| tree | b3aacdcce39ec53a581137229e4a30ccb235f09d /tests | |
| parent | c8dd3e3985dce3ae94bb09d6df82a516852e78c4 (diff) | |
| parent | 52b6b2f1f49e7385527e9f311f248092be0c0b61 (diff) | |
Merge tag 'elfutils-0.174'
elfutils 0.174 release
Change-Id: Ibcbdfca61cf0b65391ab6d0ad00f18ba61027e07
Diffstat (limited to 'tests')
51 files changed, 1302 insertions, 42 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index a38e3756..2e14d364 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -30,6 +30,70 @@ * update3.c: Likewise. * update4.c: Likewise. +2018-09-13 Mark Wielaard <[email protected]> + + * run-strip-test-many.sh: New test. + * Makefile.am (TESTS): Add run-strip-test-many.sh. + (EXTRA_DIST): Likewise. + +2018-09-13 Mark Wielaard <[email protected]> + + * run-typeiter-many.sh: New test. + * Makefile.am (TESTS): Add run-typeiter-many.sh. + (EXTRA_DIST): Likewise. + +2018-09-13 Mark Wielaard <[email protected]> + + * run-copymany-sections.sh: New test. + * Makefile.am (TESTS): Add run-copymany-sections.sh. + (EXTRA_DIST): Likewise. + +2018-09-12 Mark Wielaard <[email protected]> + + * Makefile.am (check_PROGRAMS): Add elfcopy and addsections. + (TESTS): Add run-copyadd-sections.sh. + (EXTRA_DIST): Likewise. + (elfcopy_LDADD): New variable. + (addsections_LDADD): Likewise. + * addsections.c: New file. + * elfcopy.c: Likewise. + * run-copyadd-sections.sh: New test. + +2018-09-11 Mark Wielaard <[email protected]> + + * backtrace-dwarf.c (main): Add section attribute. + +2018-07-24 Mark Wielaard <[email protected]> + + * run-annobingroup.sh: Add testfile-annobingroup-i386.o tests. + * testfile-annobingroup-i386.o.bz2: New test file. + * Makefile.am (EXTRA_DIST): Add testfile-annobingroup-i386.o.bz2. + +2018-07-21 Mark Wielaard <[email protected]> + + * run-annobingroup.sh: New test. + * testfile-annobingroup.o.bz2: New test file. + * Makefile.am (TESTS): Add run-annobingroup.sh. + (EXTRA_DIST): Add run-annobingroup.sh and + testfile-annobingroup.o.bz2. + +2018-07-19 Andreas Schwab <[email protected]> + + * Makefile.am (TESTS): Add run-strip-test12.sh. + (EXTRA_DIST): Add run-strip-test12.sh, testfile-riscv64.bz2, + testfile-riscv64-s.bz2, testfile-riscv64-core.bz2. + (run-strip-test11.sh): New file. + (testfile-riscv64.bz2): New file. + (testfile-riscv64-s.bz2): New file. + (testfile-riscv64-core.bz2): New file. + * run-allregs.sh: Add test for testfile-riscv64-core. + * run-readelf-mixed-corenote.sh: Likewise. + +2018-07-16 Ulf Hermann <[email protected]> + + * run-strip-reloc.sh: Remove previous testfiles before running the + next test. + 2018-07-17 Mark Wielaard <[email protected]> * hello_riscv64.ko.bz2: Updated with debuginfo. @@ -157,6 +221,50 @@ * Makefile.am: Link test programs agaist libgnu.a if requested. +2018-07-05 Mark Wielaard <[email protected]> + + * next_cfi.c (handle_section): Take a new argument name. Check + whether the section is compressed and uncompress if so. + (main): Check also for .zdebug_frame and pass the name of the + section to handle_section. + +2018-07-04 Ross Burton <[email protected]> + + * addrscopes.c: Remove error.h include, add system.h include. + * allregs.c: Likewise. + * backtrace-data.c: Likewise. + * backtrace-dwarf.c: Likewise. + * backtrace.c: Likewise. + * buildid.c: Likewise. + * debugaltlink.c: Likewise. + * debuglink.c: Likewise. + * deleted.c : Likewise. + * dwarfcfi.c: Likewise. + * dwfl-addr-sect.c: Likewise. + * dwfl-bug-addr-overflow.c: Likewise. + * dwfl-bug-fd-leak.c: Likewise. + * dwfl-bug-getmodules.c: Likewise. + * dwfl-proc-attach.c: Likewise. + * dwfl-report-elf-align.c: Likewise. + * dwfllines.c: Likewise. + * dwflmodtest.c: Likewise. + * dwflsyms.c: Likewise. + * early-offscn.c: Likewise + * ecp.c: Likewise. + * elfstrmerge.c: Likewise. + * find-prologues.c: Likewise. + * funcretval.c: Likewise. + * funcscopes.c: Likewise. + * getsrc_die.c: Likewise. + * line2addr.c: Likewise. + * low_high_pc.c: Likewise. + * next_cfi.c: Likewise. + * rdwrmmap.c: Likewise. + * saridx.c: Likewise. + * sectiondump.c: Likewise. + * varlocs.c: Likewise. + * vdsosyms.c: Likewise. + 2018-06-28 Mark Wielaard <[email protected]> * next_cfi.c: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index 296d1b36..81c53c31 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -58,7 +58,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ elfgetzdata elfputzdata zstrptr emptyfile vendorelf \ fillfile dwarf_default_lower_bound dwarf-die-addr-die \ get-units-invalid get-units-split attr-integrate-skel \ - all-dwarf-ranges unit-info next_cfi + all-dwarf-ranges unit-info next_cfi \ + elfcopy addsections check_DATA = deleted-lib$(LIBEXT) CLEANFILES += deleted-lib$(LIBEXT) @@ -88,7 +89,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-strip-test3.sh run-strip-test4.sh run-strip-test5.sh \ run-strip-test6.sh run-strip-test7.sh run-strip-test8.sh \ run-strip-test9.sh run-strip-test10.sh run-strip-test11.sh \ - run-strip-nothing.sh run-strip-g.sh \ + run-strip-test12.sh \ + run-strip-nothing.sh run-strip-g.sh run-annobingroup.sh \ run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \ run-strip-nobitsalign.sh run-strip-remove-keep.sh \ run-unstrip-test.sh run-unstrip-test2.sh run-unstrip-test3.sh \ @@ -154,7 +156,9 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-attr-integrate-skel.sh \ run-all-dwarf-ranges.sh run-unit-info.sh \ run-reloc-bpf.sh \ - run-next-cfi.sh run-next-cfi-self.sh + run-next-cfi.sh run-next-cfi-self.sh \ + run-copyadd-sections.sh run-copymany-sections.sh \ + run-typeiter-many.sh run-strip-test-many.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -193,7 +197,10 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \ run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \ run-strip-test9.sh run-strip-test10.sh run-strip-test11.sh \ + run-strip-test12.sh \ run-strip-nothing.sh run-strip-remove-keep.sh run-strip-g.sh \ + run-annobingroup.sh testfile-annobingroup.o.bz2 \ + testfile-annobingroup-i386.o.bz2 \ run-strip-strmerge.sh run-strip-nobitsalign.sh \ testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \ run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \ @@ -399,7 +406,11 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-attr-integrate-skel.sh \ run-all-dwarf-ranges.sh testfilesplitranges4.debug.bz2 \ testfile-ranges-hello.dwo.bz2 testfile-ranges-world.dwo.bz2 \ - run-unit-info.sh run-next-cfi.sh run-next-cfi-self.sh + run-unit-info.sh run-next-cfi.sh run-next-cfi-self.sh \ + testfile-riscv64.bz2 testfile-riscv64-s.bz2 \ + testfile-riscv64-core.bz2 \ + run-copyadd-sections.sh run-copymany-sections.sh \ + run-typeiter-many.sh run-strip-test-many.sh EXTRA_DIST += deleted-lib.c @@ -585,6 +596,8 @@ attr_integrate_skel_LDADD = $(libdw) $(libgnu) all_dwarf_ranges_LDADD = $(libdw) $(libgnu) unit_info_LDADD = $(libdw) $(libgnu) next_cfi_LDADD = $(libelf) $(libdw) $(libgnu) +elfcopy_LDADD = $(libelf) $(libgnu) +addsections_LDADD = $(libelf) $(libgnu) if SELFCONTAINED # In self contained mode we cannot expect a system elf header. diff --git a/tests/addrscopes.c b/tests/addrscopes.c index 791569f5..b231b6a9 100644 --- a/tests/addrscopes.c +++ b/tests/addrscopes.c @@ -25,8 +25,8 @@ #include <stdio_ext.h> #include <locale.h> #include <stdlib.h> -#include <error.h> #include <string.h> +#include "system.h" static void diff --git a/tests/addsections.c b/tests/addsections.c new file mode 100644 index 00000000..66266624 --- /dev/null +++ b/tests/addsections.c @@ -0,0 +1,286 @@ +/* Test program for adding (more than SHN_LORESERVE) sections. + 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 <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include ELFUTILS_HEADER(elf) +#include <gelf.h> + + +/* shstrndx is special, might overflow into section zero header sh_link. */ +static int +setshstrndx (Elf *elf, size_t ndx) +{ + printf ("setshstrndx: %zd\n", ndx); + + GElf_Ehdr ehdr_mem; + GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem); + if (ehdr == NULL) + return -1; + + if (ndx < SHN_LORESERVE) + ehdr->e_shstrndx = ndx; + else + { + ehdr->e_shstrndx = SHN_XINDEX; + Elf_Scn *zscn = elf_getscn (elf, 0); + GElf_Shdr zshdr_mem; + GElf_Shdr *zshdr = gelf_getshdr (zscn, &zshdr_mem); + if (zshdr == NULL) + return -1; + zshdr->sh_link = ndx; + if (gelf_update_shdr (zscn, zshdr) == 0) + return -1; + } + + if (gelf_update_ehdr (elf, ehdr) == 0) + return -1; + + return 0; +} + +/* Will add nr new '.extra' sections and a new '.new_shstrtab' section + at the end. */ +static void +add_sections (const char *name, size_t nr, int use_mmap) +{ + printf ("add_sections '%s': %zd\n", name, nr); + + int fd = open (name, O_RDWR | O_BINARY); + if (fd < 0) + { + fprintf (stderr, "Couldn't open file '%s': %s\n", + name, strerror (errno)); + exit (1); + } + + Elf *elf = elf_begin (fd, use_mmap ? ELF_C_RDWR_MMAP : ELF_C_RDWR, NULL); + if (elf == NULL) + { + fprintf (stderr, "Couldn't open ELF file '%s': %s\n", + name, elf_errmsg (-1)); + exit (1); + } + + /* We will add a new shstrtab section with two new names at the end. + Just get the current shstrtab table and add two entries '.extra' + and '.new_shstrtab' at the end of the table, so all existing indexes + are still valid. */ + size_t shstrndx; + if (elf_getshdrstrndx (elf, &shstrndx) < 0) + { + printf ("cannot get shstrndx: %s\n", elf_errmsg (-1)); + exit (1); + } + + Elf_Scn *shstrtab_scn = elf_getscn (elf, shstrndx); + if (shstrtab_scn == NULL) + { + printf ("couldn't get shstrtab scn: %s\n", elf_errmsg (-1)); + exit (1); + } + Elf_Data *shstrtab_data = elf_getdata (shstrtab_scn, NULL); + if (shstrtab_data == NULL) + { + printf ("couldn't get shstrtab data: %s\n", elf_errmsg (-1)); + exit (1); + } + size_t new_shstrtab_size = (shstrtab_data->d_size + + strlen (".extra") + 1 + + strlen (".new_shstrtab") + 1); + void *new_shstrtab_buf = malloc (new_shstrtab_size); + if (new_shstrtab_buf == NULL) + { + printf ("couldn't allocate new shstrtab data d_buf\n"); + exit (1); + } + memcpy (new_shstrtab_buf, shstrtab_data->d_buf, shstrtab_data->d_size); + size_t extra_idx = shstrtab_data->d_size; + size_t new_shstrtab_idx = extra_idx + strlen (".extra") + 1; + strcpy (new_shstrtab_buf + extra_idx, ".extra"); + strcpy (new_shstrtab_buf + new_shstrtab_idx, ".new_shstrtab"); + + // Add lots of .extra sections... + size_t cnt = 0; + while (cnt++ < nr) + { + Elf_Scn *scn = elf_newscn (elf); + if (scn == NULL) + { + printf ("cannot create .extra section (%zd): %s\n", cnt, + elf_errmsg (-1)); + exit (1); + } + + Elf_Data *data = elf_newdata (scn); + if (data == NULL) + { + printf ("couldn't create new section data (%zd): %s\n", cnt, + elf_errmsg (-1)); + exit (1); + } + + data->d_size = strlen ("extra") + 1; + data->d_buf = "extra"; + data->d_type = ELF_T_BYTE; + data->d_align = 1; + + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); + if (shdr == NULL) + { + printf ("cannot get header for new section (%zd): %s\n", cnt, + elf_errmsg (-1)); + exit (1); + } + + shdr->sh_type = SHT_PROGBITS; + shdr->sh_flags = 0; + shdr->sh_addr = 0; + shdr->sh_link = SHN_UNDEF; + shdr->sh_info = SHN_UNDEF; + shdr->sh_addralign = 1; + shdr->sh_entsize = 0; + shdr->sh_size = data->d_size; + shdr->sh_name = extra_idx; + + if (gelf_update_shdr (scn, shdr) == 0) + { + printf ("cannot update new section header (%zd): %s\n", cnt, + elf_errmsg (-1)); + exit (1); + } + } + + // Create new shstrtab section. + Elf_Scn *new_shstrtab_scn = elf_newscn (elf); + if (new_shstrtab_scn == NULL) + { + printf ("cannot create new shstrtab section: %s\n", elf_errmsg (-1)); + exit (1); + } + + Elf_Data *new_shstrtab_data = elf_newdata (new_shstrtab_scn); + if (new_shstrtab_data == NULL) + { + printf ("couldn't create new shstrtab section data: %s\n", + elf_errmsg (-1)); + exit (1); + } + + new_shstrtab_data->d_size = new_shstrtab_size; + new_shstrtab_data->d_buf = new_shstrtab_buf; + new_shstrtab_data->d_type = ELF_T_BYTE; + new_shstrtab_data->d_align = 1; + + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (new_shstrtab_scn, &shdr_mem); + if (shdr == NULL) + { + printf ("cannot get header for new shstrtab section: %s\n", + elf_errmsg (-1)); + exit (1); + } + + shdr->sh_type = SHT_STRTAB; + shdr->sh_flags = 0; + shdr->sh_addr = 0; + shdr->sh_link = SHN_UNDEF; + shdr->sh_info = SHN_UNDEF; + shdr->sh_addralign = 1; + shdr->sh_entsize = 0; + shdr->sh_size = new_shstrtab_size; + shdr->sh_name = new_shstrtab_idx; + + // Finished new shstrtab section, update the header. + if (gelf_update_shdr (new_shstrtab_scn, shdr) == 0) + { + printf ("cannot update new shstrtab section header: %s\n", + elf_errmsg (-1)); + exit (1); + } + + // Set it as the new shstrtab section to get the names correct. + size_t new_shstrndx = elf_ndxscn (new_shstrtab_scn); + if (setshstrndx (elf, new_shstrndx) < 0) + { + printf ("cannot set shstrndx: %s\n", elf_errmsg (-1)); + exit (1); + } + + // Write everything to disk. + if (elf_update (elf, ELF_C_WRITE) < 0) + { + printf ("failure in elf_update: %s\n", elf_errmsg (-1)); + exit (1); + } + + if (elf_end (elf) != 0) + { + printf ("couldn't cleanup elf '%s': %s\n", name, elf_errmsg (-1)); + exit (1); + } + + if (close (fd) != 0) + { + printf ("couldn't close '%s': %s\n", name, strerror (errno)); + exit (1); + } + + free (new_shstrtab_buf); +} + +int +main (int argc, char *argv[]) +{ + elf_version (EV_CURRENT); + + /* Takes the given file, and adds the given number of sections. */ + if (argc < 3 || argc > 4) + { + fprintf (stderr, "addsections [--mmap] nr elf.file\n"); + exit (1); + } + + int argn = 1; + bool use_mmap = false; + if (strcmp (argv[argn], "--mmap") == 0) + { + use_mmap = true; + argn++; + } + + size_t nr = atoi (argv[argn++]); + const char *file = argv[argn]; + add_sections (file, nr, use_mmap); + + return 0; +} diff --git a/tests/allregs.c b/tests/allregs.c index 286f7e3c..f18f0b28 100644 --- a/tests/allregs.c +++ b/tests/allregs.c @@ -21,13 +21,13 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <error.h> #include <locale.h> #include <argp.h> #include <assert.h> #include ELFUTILS_HEADER(dwfl) #include <dwarf.h> +#include "system.h" #include "../libdw/known-dwarf.h" static const char * diff --git a/tests/backtrace-data.c b/tests/backtrace-data.c index 6db98789..60d556e0 100644 --- a/tests/backtrace-data.c +++ b/tests/backtrace-data.c @@ -27,7 +27,6 @@ #include <dirent.h> #include <stdlib.h> #include <errno.h> -#include <error.h> #include <unistd.h> #include <dwarf.h> #if defined(__x86_64__) && defined(__linux__) @@ -41,6 +40,7 @@ #include <string.h> #include ELFUTILS_HEADER(dwfl) #endif +#include "system.h" #if !defined(__x86_64__) || !defined(__linux__) diff --git a/tests/backtrace-dwarf.c b/tests/backtrace-dwarf.c index 7ff826cd..35f25ed6 100644 --- a/tests/backtrace-dwarf.c +++ b/tests/backtrace-dwarf.c @@ -21,10 +21,10 @@ #include <stdio_ext.h> #include <locale.h> #include <errno.h> -#include <error.h> #include <unistd.h> #include <sys/types.h> #include ELFUTILS_HEADER(dwfl) +#include "system.h" #ifndef __linux__ @@ -124,6 +124,7 @@ thread_callback (Dwfl_Thread *thread, void *thread_arg) } int +__attribute__((section(".main"))) /* Defeat -freorder-blocks-and-partition */ main (int argc __attribute__ ((unused)), char **argv) { /* We use no threads here which can interfere with handling a stream. */ diff --git a/tests/backtrace.c b/tests/backtrace.c index f5dd761f..24ab68dd 100644 --- a/tests/backtrace.c +++ b/tests/backtrace.c @@ -24,7 +24,6 @@ #include <dirent.h> #include <stdlib.h> #include <errno.h> -#include <error.h> #include <unistd.h> #include <dwarf.h> #ifdef __linux__ @@ -39,6 +38,7 @@ #include <argp.h> #include ELFUTILS_HEADER(dwfl) #endif +#include "system.h" #ifndef __linux__ diff --git a/tests/buildid.c b/tests/buildid.c index 1049860c..95a994f6 100644 --- a/tests/buildid.c +++ b/tests/buildid.c @@ -22,13 +22,13 @@ #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> +#include "system.h" int main (int argc, char *argv[]) diff --git a/tests/debugaltlink.c b/tests/debugaltlink.c index 4618b615..df3ae307 100644 --- a/tests/debugaltlink.c +++ b/tests/debugaltlink.c @@ -22,13 +22,13 @@ #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> +#include "system.h" int main (int argc, char *argv[]) diff --git a/tests/debuglink.c b/tests/debuglink.c index ea5bd238..e71d9152 100644 --- a/tests/debuglink.c +++ b/tests/debuglink.c @@ -21,13 +21,13 @@ #include <errno.h> #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> +#include "system.h" int main (int argc, char *argv[]) diff --git a/tests/deleted.c b/tests/deleted.c index f11cb1b6..ec301fcd 100644 --- a/tests/deleted.c +++ b/tests/deleted.c @@ -21,7 +21,6 @@ #include <unistd.h> #include <assert.h> #include <stdio.h> -#include <error.h> #include <errno.h> #ifdef __linux__ #include <sys/prctl.h> diff --git a/tests/dwarfcfi.c b/tests/dwarfcfi.c index 283a9184..beadd930 100644 --- a/tests/dwarfcfi.c +++ b/tests/dwarfcfi.c @@ -18,7 +18,6 @@ #include <config.h> #include <assert.h> #include <inttypes.h> -#include <error.h> #include ELFUTILS_HEADER(dw) #include <dwarf.h> #include <argp.h> @@ -30,6 +29,7 @@ #include <stdlib.h> #include <string.h> +#include "system.h" #include "../libdw/known-dwarf.h" static const char * diff --git a/tests/dwfl-addr-sect.c b/tests/dwfl-addr-sect.c index 21e470a3..4d85c007 100644 --- a/tests/dwfl-addr-sect.c +++ b/tests/dwfl-addr-sect.c @@ -23,11 +23,11 @@ #include <stdio_ext.h> #include <stdlib.h> #include <string.h> -#include <error.h> #include <locale.h> #include <argp.h> #include ELFUTILS_HEADER(dwfl) #include <dwarf.h> +#include "system.h" static int handle_address (Dwfl *dwfl, Dwarf_Addr address) diff --git a/tests/dwfl-bug-addr-overflow.c b/tests/dwfl-bug-addr-overflow.c index aa8030e1..9a3373a6 100644 --- a/tests/dwfl-bug-addr-overflow.c +++ b/tests/dwfl-bug-addr-overflow.c @@ -20,7 +20,6 @@ #include <inttypes.h> #include <stdio.h> #include <stdio_ext.h> -#include <error.h> #include <locale.h> #include ELFUTILS_HEADER(dwfl) diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c index 689cdd79..ee3a916b 100644 --- a/tests/dwfl-bug-fd-leak.c +++ b/tests/dwfl-bug-fd-leak.c @@ -24,9 +24,9 @@ #include <dirent.h> #include <stdlib.h> #include <errno.h> -#include <error.h> #include <unistd.h> #include <dwarf.h> +#include "system.h" #ifndef __linux__ int diff --git a/tests/dwfl-bug-getmodules.c b/tests/dwfl-bug-getmodules.c index 1ee989f8..2783f65c 100644 --- a/tests/dwfl-bug-getmodules.c +++ b/tests/dwfl-bug-getmodules.c @@ -17,8 +17,8 @@ #include <config.h> #include ELFUTILS_HEADER(dwfl) +#include "system.h" -#include <error.h> static const Dwfl_Callbacks callbacks = { diff --git a/tests/dwfl-proc-attach.c b/tests/dwfl-proc-attach.c index e7bb2010..102ba181 100644 --- a/tests/dwfl-proc-attach.c +++ b/tests/dwfl-proc-attach.c @@ -20,7 +20,6 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> -#include <error.h> #include <unistd.h> #ifdef __linux__ #include <sys/types.h> @@ -31,6 +30,7 @@ #include ELFUTILS_HEADER(dwfl) #include <pthread.h> #endif +#include "system.h" #ifndef __linux__ int diff --git a/tests/dwfl-report-elf-align.c b/tests/dwfl-report-elf-align.c index a4e97d3c..6558ab81 100644 --- a/tests/dwfl-report-elf-align.c +++ b/tests/dwfl-report-elf-align.c @@ -20,11 +20,11 @@ #include <inttypes.h> #include <stdio.h> #include <stdio_ext.h> -#include <error.h> #include <locale.h> #include <string.h> #include <stdlib.h> #include ELFUTILS_HEADER(dwfl) +#include "system.h" static const Dwfl_Callbacks offline_callbacks = diff --git a/tests/dwfllines.c b/tests/dwfllines.c index 90379dd2..d732e401 100644 --- a/tests/dwfllines.c +++ b/tests/dwfllines.c @@ -27,7 +27,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <error.h> +#include "system.h" int main (int argc, char *argv[]) diff --git a/tests/dwflmodtest.c b/tests/dwflmodtest.c index 0027f96b..9251d158 100644 --- a/tests/dwflmodtest.c +++ b/tests/dwflmodtest.c @@ -23,11 +23,11 @@ #include <stdio_ext.h> #include <stdlib.h> #include <string.h> -#include <error.h> #include <locale.h> #include <argp.h> #include ELFUTILS_HEADER(dwfl) #include <dwarf.h> +#include "system.h" static bool show_inlines; diff --git a/tests/dwflsyms.c b/tests/dwflsyms.c index 49ac3346..bc23cb63 100644 --- a/tests/dwflsyms.c +++ b/tests/dwflsyms.c @@ -25,7 +25,6 @@ #include <stdio.h> #include <stdio_ext.h> #include <stdlib.h> -#include <error.h> #include <string.h> static const char * diff --git a/tests/early-offscn.c b/tests/early-offscn.c index d47abc88..12c1fb66 100644 --- a/tests/early-offscn.c +++ b/tests/early-offscn.c @@ -19,11 +19,11 @@ #endif #include <errno.h> -#include <error.h> #include <fcntl.h> #include <gelf.h> #include <stdio.h> #include <stdlib.h> +#include "system.h" int main (int argc, char *argv[]) diff --git a/tests/ecp.c b/tests/ecp.c index 0882c54e..6449bf03 100644 --- a/tests/ecp.c +++ b/tests/ecp.c @@ -20,11 +20,11 @@ #endif #include <errno.h> -#include <error.h> #include <fcntl.h> #include <gelf.h> #include <stdlib.h> #include <unistd.h> +#include "system.h" int main (int argc, char *argv[]) diff --git a/tests/elfcopy.c b/tests/elfcopy.c new file mode 100644 index 00000000..82b3763e --- /dev/null +++ b/tests/elfcopy.c @@ -0,0 +1,286 @@ +/* Test program for copying a whole ELF file using libelf. + 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 <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include ELFUTILS_HEADER(elf) +#include <gelf.h> + + +/* shstrndx is special, might overflow into section zero header sh_link. */ +static int +setshstrndx (Elf *elf, size_t ndx) +{ + printf ("setshstrndx: %zd\n", ndx); + + GElf_Ehdr ehdr_mem; + GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem); + if (ehdr == NULL) + return -1; + + if (ndx < SHN_LORESERVE) + ehdr->e_shstrndx = ndx; + else + { + ehdr->e_shstrndx = SHN_XINDEX; + Elf_Scn *zscn = elf_getscn (elf, 0); + GElf_Shdr zshdr_mem; + GElf_Shdr *zshdr = gelf_getshdr (zscn, &zshdr_mem); + if (zshdr == NULL) + return -1; + zshdr->sh_link = ndx; + if (gelf_update_shdr (zscn, zshdr) == 0) + return -1; + } + + if (gelf_update_ehdr (elf, ehdr) == 0) + return -1; + + return 0; +} + +/* Copies all elements of an ELF file either using mmap or read. */ +static void +copy_elf (const char *in, const char *out, bool use_mmap) +{ + printf ("\ncopy_elf: %s -> %s (%s)\n", in, out, use_mmap ? "mmap" : "read"); + + /* Existing ELF file. */ + int fda = open (in, O_RDONLY | O_BINARY); + if (fda < 0) + { + fprintf (stderr, "Couldn't open file '%s': %s\n", + in, strerror (errno)); + exit (1); + } + + Elf *elfa = elf_begin (fda, use_mmap ? ELF_C_READ_MMAP : ELF_C_READ, NULL); + if (elfa == NULL) + { + fprintf (stderr, "Couldn't open ELF file '%s': %s\n", + in, elf_errmsg (-1)); + exit (1); + } + + /* Open new file. */ + int fdb = open (out, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0644); + if (fdb < 0) + { + fprintf (stderr, "Couldn't create file '%s': %s\n", + out, strerror (errno)); + exit (1); + } + + Elf *elfb = elf_begin (fdb, use_mmap ? ELF_C_WRITE_MMAP : ELF_C_WRITE, NULL); + if (elfb == NULL) + { + fprintf (stderr, "Couldn't create ELF file '%s': %s\n", + out, elf_errmsg (-1)); + exit (1); + } + + // Copy ELF header. + GElf_Ehdr ehdr_mema; + GElf_Ehdr *ehdra = gelf_getehdr (elfa, &ehdr_mema); + if (ehdra == NULL) + { + printf ("cannot get ELF header: %s\n", elf_errmsg (-1)); + exit (1); + } + + int class = gelf_getclass (elfa); + // Create an ELF header. + if (gelf_newehdr (elfb, class) == 0) + { + printf ("cannot create ELF header: %s\n", elf_errmsg (-1)); + exit (1); + } + + /* New elf header is an exact copy. */ + GElf_Ehdr ehdr_memb; + GElf_Ehdr *ehdrb = &ehdr_memb; + *ehdrb = *ehdra; + if (gelf_update_ehdr (elfb, ehdrb) == 0) + { + printf ("cannot update ELF header: %s\n", elf_errmsg (-1)); + exit (1); + } + + /* shstrndx is special. (Technically phdrnum and shdrnum are also + special, but they are handled by libelf.) */ + size_t shstrndx; + if (elf_getshdrstrndx (elfa, &shstrndx) < 0) + { + printf ("cannot get shstrndx: %s\n", elf_errmsg (-1)); + exit (1); + } + if (setshstrndx (elfb, shstrndx) < 0) + { + printf ("cannot set shstrndx: %s\n", elf_errmsg (-1)); + exit (1); + } + + /* If there are phdrs, copy them over. */ + size_t phnum; + if (elf_getphdrnum (elfa, &phnum) != 0) + { + printf ("cannot get phdrs: %s\n", elf_errmsg (-1)); + exit (1); + } + + if (phnum > 0) + { + if (gelf_newphdr (elfb, phnum) == 0) + { + printf ("cannot create phdrs: %s\n", elf_errmsg (-1)); + exit (1); + } + + for (size_t cnt = 0; cnt < phnum; ++cnt) + { + GElf_Phdr phdr_mem; + GElf_Phdr *phdr = gelf_getphdr (elfa, cnt, &phdr_mem); + if (phdr == NULL) + { + printf ("couldn't get phdr %zd: %s\n", cnt, elf_errmsg (-1)); + exit (1); + } + + if (gelf_update_phdr (elfb, cnt, phdr) == 0) + { + printf ("couldn't update phdr %zd: %s\n", cnt, elf_errmsg (-1)); + exit (1); + } + } + } + + /* Copy all sections, headers and data. */ + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (elfa, scn)) != NULL) + { + /* Get the header. */ + GElf_Shdr shdr; + if (gelf_getshdr (scn, &shdr) == NULL) + { + printf ("couldn't get shdr: %s\n", elf_errmsg (-1)); + exit (1); + } + + /* Create new section. */ + Elf_Scn *new_scn = elf_newscn (elfb); + if (new_scn == NULL) + { + printf ("couldn't create new section: %s\n", elf_errmsg (-1)); + exit (1); + } + + if (gelf_update_shdr (new_scn, &shdr) == 0) + { + printf ("couldn't update shdr: %s\n", elf_errmsg (-1)); + exit (1); + } + + /* Copy over section data. */ + Elf_Data *data = NULL; + while ((data = elf_getdata (scn, data)) != NULL) + { + Elf_Data *new_data = elf_newdata (new_scn); + if (new_data == NULL) + { + printf ("couldn't create new section data: %s\n", + elf_errmsg (-1)); + exit (1); + } + *new_data = *data; + } + } + + /* Write everything to disk. If there are any phdrs then we want + the exact same layout. Do we want ELF_F_PERMISSIVE? */ + if (phnum > 0) + elf_flagelf (elfb, ELF_C_SET, ELF_F_LAYOUT); + if (elf_update (elfb, ELF_C_WRITE) < 0) + { + printf ("failure in elf_update: %s\n", elf_errmsg (-1)); + exit (1); + } + + if (elf_end (elfa) != 0) + { + printf ("couldn't cleanup elf '%s': %s\n", in, elf_errmsg (-1)); + exit (1); + } + + if (close (fda) != 0) + { + printf ("couldn't close '%s': %s\n", in, strerror (errno)); + exit (1); + } + + if (elf_end (elfb) != 0) + { + printf ("couldn't cleanup elf '%s': %s\n", out, elf_errmsg (-1)); + exit (1); + } + + if (close (fdb) != 0) + { + printf ("couldn't close '%s': %s\n", out, strerror (errno)); + exit (1); + } +} + +int +main (int argc, const char *argv[]) +{ + elf_version (EV_CURRENT); + + /* Takes the given file, and create a new identical one. */ + if (argc < 3 || argc > 4) + { + fprintf (stderr, "elfcopy [--mmap] in.elf out.elf\n"); + exit (1); + } + + int argn = 1; + bool use_mmap = false; + if (strcmp (argv[argn], "--mmap") == 0) + { + use_mmap = true; + argn++; + } + + const char *in = argv[argn++]; + const char *out = argv[argn]; + copy_elf (in, out, use_mmap); + + return 0; +} diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c index 8801cb7c..ec0dc9f7 100644 --- a/tests/elfstrmerge.c +++ b/tests/elfstrmerge.c @@ -24,11 +24,11 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <error.h> #include <stdio.h> #include <inttypes.h> #include <unistd.h> +#include <system.h> #include <gelf.h> #include ELFUTILS_HEADER(dwelf) #include "elf-knowledge.h" diff --git a/tests/find-prologues.c b/tests/find-prologues.c index ba8ae371..b0bf9362 100644 --- a/tests/find-prologues.c +++ b/tests/find-prologues.c @@ -25,9 +25,9 @@ #include <stdio_ext.h> #include <locale.h> #include <stdlib.h> -#include <error.h> #include <string.h> #include <fnmatch.h> +#include "system.h" struct args diff --git a/tests/funcretval.c b/tests/funcretval.c index 8d19d117..16cd1a44 100644 --- a/tests/funcretval.c +++ b/tests/funcretval.c @@ -25,9 +25,9 @@ #include <stdio_ext.h> #include <locale.h> #include <stdlib.h> -#include <error.h> #include <string.h> #include <fnmatch.h> +#include "system.h" struct args diff --git a/tests/funcscopes.c b/tests/funcscopes.c index 9c901858..689d376a 100644 --- a/tests/funcscopes.c +++ b/tests/funcscopes.c @@ -25,9 +25,9 @@ #include <stdio_ext.h> #include <locale.h> #include <stdlib.h> -#include <error.h> #include <string.h> #include <fnmatch.h> +#include "system.h" static void diff --git a/tests/getsrc_die.c b/tests/getsrc_die.c index 3c5060bf..9942bbd0 100644 --- a/tests/getsrc_die.c +++ b/tests/getsrc_die.c @@ -19,7 +19,6 @@ #endif #include <errno.h> -#include <error.h> #include <fcntl.h> #include <inttypes.h> #include <libelf.h> @@ -27,6 +26,7 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include "system.h" int diff --git a/tests/line2addr.c b/tests/line2addr.c index e0d65d3d..663746fd 100644 --- a/tests/line2addr.c +++ b/tests/line2addr.c @@ -26,7 +26,7 @@ #include <locale.h> #include <stdlib.h> #include <string.h> -#include <error.h> +#include "system.h" static void diff --git a/tests/low_high_pc.c b/tests/low_high_pc.c index 5c6b343c..78b6ad08 100644 --- a/tests/low_high_pc.c +++ b/tests/low_high_pc.c @@ -25,7 +25,6 @@ #include <stdio_ext.h> #include <locale.h> #include <stdlib.h> -#include <error.h> #include <string.h> #include <fnmatch.h> diff --git a/tests/next_cfi.c b/tests/next_cfi.c index 2b633577..0b171ecc 100644 --- a/tests/next_cfi.c +++ b/tests/next_cfi.c @@ -18,7 +18,6 @@ #include <config.h> #include <assert.h> #include <inttypes.h> -#include <error.h> #include ELFUTILS_HEADER(dw) #include <dwarf.h> #include <argp.h> @@ -31,9 +30,10 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include "system.h" void -handle_section (const unsigned char e_ident[], +handle_section (char *name, const unsigned char e_ident[], Elf_Scn *scn, const bool is_eh) { if (is_eh) @@ -41,6 +41,24 @@ handle_section (const unsigned char e_ident[], else printf (".debug_frame\n"); + GElf_Shdr mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &mem); + if (shdr == NULL) + error (EXIT_FAILURE, 0, "Couldn't get section header: %s", + elf_errmsg (-1)); + if ((shdr->sh_flags & SHF_COMPRESSED) != 0) + { + if (elf_compress (scn, 0, 0) < 0) + error (EXIT_FAILURE, 0, "Couldn't decompress section: %s", + elf_errmsg (-1)); + } + else if (name[0] == '.' && name[1] == 'z') + { + if (elf_compress_gnu (scn, 0, 0) < 0) + error (EXIT_FAILURE, 0, "Couldn't decompress section: %s", + elf_errmsg (-1)); + } + Elf_Data *data = elf_getdata (scn, NULL); if (data == NULL || data->d_buf == NULL) error (EXIT_FAILURE, 0, "no section data"); @@ -117,9 +135,10 @@ main (int argc, char *argv[]) if (name != NULL && shdr.sh_type == SHT_PROGBITS) { if (strcmp (name, ".eh_frame") == 0) - handle_section (ident, scn, true); - if (strcmp (name, ".debug_frame") == 0) - handle_section (ident, scn, false); + handle_section (name, ident, scn, true); + if (strcmp (name, ".debug_frame") == 0 + || strcmp (name, ".zdebug_frame") == 0) + handle_section (name, ident, scn, false); } } } diff --git a/tests/rdwrmmap.c b/tests/rdwrmmap.c index 1a968ebf..16148f1a 100644 --- a/tests/rdwrmmap.c +++ b/tests/rdwrmmap.c @@ -19,11 +19,11 @@ #endif #include <errno.h> -#include <error.h> #include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <libelf.h> +#include "system.h" int main (int argc __attribute__ ((unused)), char *argv[]) diff --git a/tests/run-allregs.sh b/tests/run-allregs.sh index 7ddd4520..1422bd67 100755 --- a/tests/run-allregs.sh +++ b/tests/run-allregs.sh @@ -2902,4 +2902,75 @@ FPU registers: 22: %fp6 (fp6), float 96 bits 23: %fp7 (fp7), float 96 bits EOF + +# See run-readelf-mixed-corenote.sh for instructions to regenerate +# this core file. +regs_test testfile-riscv64-core <<\EOF +integer registers: + 0: zero (zero), signed 64 bits + 1: ra (ra), address 64 bits + 2: sp (sp), address 64 bits + 3: gp (gp), address 64 bits + 4: tp (tp), address 64 bits + 5: t0 (t0), signed 64 bits + 6: t1 (t1), signed 64 bits + 7: t2 (t2), signed 64 bits + 8: s0 (s0), signed 64 bits + 9: s1 (s1), signed 64 bits + 10: a0 (a0), signed 64 bits + 11: a1 (a1), signed 64 bits + 12: a2 (a2), signed 64 bits + 13: a3 (a3), signed 64 bits + 14: a4 (a4), signed 64 bits + 15: a5 (a5), signed 64 bits + 16: a6 (a6), signed 64 bits + 17: a7 (a7), signed 64 bits + 18: s2 (s2), signed 64 bits + 19: s3 (s3), signed 64 bits + 20: s4 (s4), signed 64 bits + 21: s5 (s5), signed 64 bits + 22: s6 (s6), signed 64 bits + 23: s7 (s7), signed 64 bits + 24: s8 (s8), signed 64 bits + 25: s9 (s9), signed 64 bits + 26: s10 (s10), signed 64 bits + 27: s11 (s11), signed 64 bits + 28: t3 (t3), signed 64 bits + 29: t4 (t4), signed 64 bits + 30: t5 (t5), signed 64 bits + 31: t6 (t6), signed 64 bits +FPU registers: + 32: ft0 (ft0), float 64 bits + 33: ft1 (ft1), float 64 bits + 34: ft2 (ft2), float 64 bits + 35: ft3 (ft3), float 64 bits + 36: ft4 (ft4), float 64 bits + 37: ft5 (ft5), float 64 bits + 38: ft6 (ft6), float 64 bits + 39: ft7 (ft7), float 64 bits + 40: fs0 (fs0), float 64 bits + 41: fs1 (fs1), float 64 bits + 42: fa0 (fa0), float 64 bits + 43: fa1 (fa1), float 64 bits + 44: fa2 (fa2), float 64 bits + 45: fa3 (fa3), float 64 bits + 46: fa4 (fa4), float 64 bits + 47: fa5 (fa5), float 64 bits + 48: fa6 (fa6), float 64 bits + 49: fa7 (fa7), float 64 bits + 50: fs2 (fs2), float 64 bits + 51: fs3 (fs3), float 64 bits + 52: fs4 (fs4), float 64 bits + 53: fs5 (fs5), float 64 bits + 54: fs6 (fs6), float 64 bits + 55: fs7 (fs7), float 64 bits + 56: fs8 (fs8), float 64 bits + 57: fs9 (fs9), float 64 bits + 58: fs10 (fs10), float 64 bits + 59: fs11 (fs11), float 64 bits + 60: ft8 (ft8), float 64 bits + 61: ft9 (ft9), float 64 bits + 62: ft10 (ft10), float 64 bits + 63: ft11 (ft11), float 64 bits +EOF exit 0 diff --git a/tests/run-annobingroup.sh b/tests/run-annobingroup.sh new file mode 100755 index 00000000..700df321 --- /dev/null +++ b/tests/run-annobingroup.sh @@ -0,0 +1,123 @@ +#! /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 + +# Testfile generated by annobin, creates group. +# strip and unstrip it. Check group symbol/name is correct. + +# echo "int __attribute__((cold)) foo (void) { return 42; }" \ +# > testfile-annobingroup.c +# gcc -g -O2 -fplugin=annobin -c testfile-annobingroup.c +testfiles testfile-annobingroup.o + +tempfiles merged.elf stripped.elf debugfile.elf remerged.elf + +testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup.o << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +EOF + +testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup.o + +testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +EOF + +testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +EOF + +testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile.elf + +testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +EOF + +testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup.o remerged.elf + +# echo "void * __attribute__((cold)) foo (void) { return foo; }" +# > testfile-annobingroup-i386.c +# gcc -fpic -g -O2 -fplugin=annobin -c testfile-annobingroup-i386.c +testfiles testfile-annobingroup-i386.o + +testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-i386.o << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup-i386.o + +testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile.elf + +testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-i386.o remerged.elf + +exit 0 diff --git a/tests/run-copyadd-sections.sh b/tests/run-copyadd-sections.sh new file mode 100755 index 00000000..bc20f6ee --- /dev/null +++ b/tests/run-copyadd-sections.sh @@ -0,0 +1,87 @@ +#! /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 + +test_copy_and_add () +{ + in_file="$1" + out_file="${in_file}.copy" + out_file_mmap="${out_file}.mmap" + + testfiles ${in_file} + tempfiles ${out_file} ${out_file_mmap} readelf.out + + # Can we copy the file? + testrun ${abs_builddir}/elfcopy ${in_file} ${out_file} + testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file} + + # Can we add a section (in-place)? + testrun ${abs_builddir}/addsections 3 ${out_file} + testrun ${abs_top_builddir}/src/readelf -S ${out_file} > readelf.out + nr=$(grep '.extra' readelf.out | wc -l) + if test ${nr} != 3; then + # Show what went wrong + testrun ${abs_top_builddir}/src/readelf -S ${out_file} + exit 1 + fi + + # Can we add a section (in-place) using ELF_C_WRITE_MMAP? + testrun ${abs_builddir}/elfcopy --mmap ${in_file} ${out_file_mmap} + testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file_mmap} + + # Can we add a section (in-place) using ELF_C_RDWR_MMAP? + # Note we are only adding one sections, adding more might fail + # because mremap cannot extend too much. + testrun ${abs_builddir}/addsections --mmap 1 ${out_file_mmap} + testrun ${abs_top_builddir}/src/readelf -S ${out_file_mmap} > readelf.out + nr=$(grep '.extra' readelf.out | wc -l) + if test ${nr} != 1; then + # Show what went wrong + testrun ${abs_top_builddir}/src/readelf -S ${out_file_mmap} + exit 1 + fi +} + +# A collection of random testfiles to test 32/64bit, little/big endian +# and non-ET_REL (with phdrs)/ET_REL (without phdrs). + +# 32bit, big endian, rel +test_copy_and_add testfile29 + +# 64bit, big endian, rel +test_copy_and_add testfile23 + +# 32bit, little endian, rel +test_copy_and_add testfile9 + +# 64bit, little endian, rel +test_copy_and_add testfile38 + +# 32bit, big endian, non-rel +test_copy_and_add testfile26 + +# 64bit, big endian, non-rel +test_copy_and_add testfile27 + +# 32bit, little endian, non-rel +test_copy_and_add testfile + +# 64bit, little endian, non-rel +test_copy_and_add testfile10 + +exit 0 diff --git a/tests/run-copymany-sections.sh b/tests/run-copymany-sections.sh new file mode 100755 index 00000000..84c052c9 --- /dev/null +++ b/tests/run-copymany-sections.sh @@ -0,0 +1,99 @@ +#! /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/>. + +# Same as run-copyadd-sections.sh, but for many > 0xffff sections. +# Doesn't use mmap for addsections since that doesn't work. +# ELF_C_RDWR_MMAP needs mremap which will fail since it needs too +# much space and the original mmap cannot move. + +. $srcdir/test-subr.sh + +test_copy_and_add () +{ + in_file="$1" + out_file="${in_file}.copy" + out_file_mmap="${out_file}.mmap" + + tempfiles ${out_file} ${out_file_mmap} readelf.out + + # Can we copy the file? + testrun ${abs_builddir}/elfcopy ${in_file} ${out_file} + testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file} + + # Can we add a section (in-place)? + testrun ${abs_builddir}/addsections 65535 ${out_file} + testrun ${abs_top_builddir}/src/readelf -S ${out_file} > readelf.out + nr=$(grep '.extra' readelf.out | wc -l) + # We try twice... + if test ${nr} != 65535 -a ${nr} != 131070; then + # Show what went wrong + testrun ${abs_top_builddir}/src/readelf -S ${out_file} + exit 1 + fi + + # Can we copy the file using ELF_C_WRITE_MMAP? + testrun ${abs_builddir}/elfcopy --mmap ${in_file} ${out_file_mmap} + testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file_mmap} + + # Don't try to add using mmap (see above) +} + +# A collection of random testfiles to test 32/64bit, little/big endian +# and non-ET_REL (with phdrs)/ET_REL (without phdrs). +# Try to add 0xffff sections twice. + +# 32bit, big endian, rel +testfiles testfile29 +test_copy_and_add testfile29 +test_copy_and_add testfile29.copy + +# 64bit, big endian, rel +testfiles testfile23 +test_copy_and_add testfile23 +test_copy_and_add testfile23.copy + +# 32bit, little endian, rel +testfiles testfile9 +test_copy_and_add testfile9 +test_copy_and_add testfile9.copy + +# 64bit, little endian, rel +testfiles testfile38 +test_copy_and_add testfile38 +test_copy_and_add testfile38.copy + +# 32bit, big endian, non-rel +testfiles testfile26 +test_copy_and_add testfile26 +test_copy_and_add testfile26.copy + +# 64bit, big endian, non-rel +testfiles testfile27 +test_copy_and_add testfile27 +test_copy_and_add testfile27.copy + +# 32bit, little endian, non-rel +testfiles testfile +test_copy_and_add testfile +test_copy_and_add testfile.copy + +# 64bit, little endian, non-rel +testfiles testfile10 +test_copy_and_add testfile10 +test_copy_and_add testfile10.copy + +exit 0 diff --git a/tests/run-readelf-mixed-corenote.sh b/tests/run-readelf-mixed-corenote.sh index 86171c41..07cfc39c 100755 --- a/tests/run-readelf-mixed-corenote.sh +++ b/tests/run-readelf-mixed-corenote.sh @@ -646,4 +646,74 @@ Note segment of 1056 bytes at offset 0x1f4: fp6: 0x7fff0000ffffffffffffffff fp7: 0x7fff0000ffffffffffffffff EOF +# To reproduce this core dump, do this on a riscv64 machine: +# $ gcc -x c <(echo 'int main () { return *(int *)0x12345678; }') +# $ ./a.out +testfiles testfile-riscv64-core +testrun_compare ${abs_top_builddir}/src/readelf -n testfile-riscv64-core <<\EOF + +Note segment of 1408 bytes at offset 0x388: + Owner Data size Type + CORE 376 PRSTATUS + info.si_signo: 11, info.si_code: 0, info.si_errno: 0, cursig: 11 + sigpend: <> + sighold: <> + pid: 6801, ppid: 1155, pgrp: 6801, sid: 1155 + utime: 0.000000, stime: 0.110000, cutime: 0.000000, cstime: 0.000000 + fpvalid: 0 + ra: 0x9a00000000000104 sp: 0x400000002000051c + gp: 0x280000003fff9812 tp: 0xd000000000000128 + t0: 5764607523571106577 t1: -432345563690696255 + t2: -5764607522497362661 s0: 5764607523034235171 + s1: -6629298650415654894 a0: 72057594037928196 + a1: -6341068275337658368 a2: -5188146769657096173 + a3: 1073715219 a4: 8646911284551352320 + a5: 8646911285625067538 a6: 1729382256911463510 + a7: 536876397 s2: -1152921504606846976 + s3: 1152921505322686797 s4: 536871337 + s5: -3458764513820540928 s6: -9223372036138925403 + s7: 715843991 s8: -2594073385365405696 + s9: 4611686019143218592 s10: 715850259 + s11: 715850393 t3: -432345564227567616 + t4: 144115188075856379 t5: 216172782113783808 + t6: 1152921504606846976 + CORE 136 PRPSINFO + state: 0, sname: R, zomb: 0, nice: 0, flag: 0x0000000000400600 + uid: 0, gid: 0, pid: 6801, ppid: 1155, pgrp: 6801, sid: 1155 + fname: a.out, psargs: /tmp/a.out + CORE 128 SIGINFO + si_signo: 11, si_errno: 0, si_code: 1 + fault address: 0x12345678 + CORE 288 AUXV + SYSINFO_EHDR: 0x200001d000 + HWCAP: 0x1105 + PAGESZ: 4096 + CLKTCK: 100 + PHDR: 0x10040 + PHENT: 56 + PHNUM: 9 + BASE: 0x2000000000 + FLAGS: 0 + ENTRY: 0x103e0 + UID: 0 + EUID: 0 + GID: 0 + EGID: 0 + SECURE: 0 + RANDOM: 0x3fff9816d6 + EXECFN: 0x3fff981fed + NULL + CORE 379 FILE + 9 files: + 00010000-00011000 00000000 4096 /tmp/a.out + 00011000-00012000 00000000 4096 /tmp/a.out + 00012000-00013000 00001000 4096 /tmp/a.out + 2000000000-200001a000 00000000 106496 /lib64/ld-2.27.so + 200001a000-200001b000 00019000 4096 /lib64/ld-2.27.so + 200001b000-200001c000 0001a000 4096 /lib64/ld-2.27.so + 2000032000-2000151000 00000000 1175552 /lib64/libc-2.27.so + 2000151000-2000155000 0011e000 16384 /lib64/libc-2.27.so + 2000155000-2000157000 00122000 8192 /lib64/libc-2.27.so +EOF + exit 0 diff --git a/tests/run-strip-test-many.sh b/tests/run-strip-test-many.sh new file mode 100755 index 00000000..9a9657cd --- /dev/null +++ b/tests/run-strip-test-many.sh @@ -0,0 +1,66 @@ +#! /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 + +# Use the original file from run-strip-test.sh but with many sections +testfiles testfile +tempfiles testfile.strip testfile.debug testfile.unstrip + +echo "Adding sections to testfile" +testrun ${abs_builddir}/addsections 65535 testfile + +echo "Testing strip -o" +testrun ${abs_top_builddir}/src/strip -o testfile.strip -f testfile.debug testfile + +# Do the parts check out? +echo "elflint testfile.strip" +testrun ${abs_top_builddir}/src/elflint --gnu -q testfile.strip +echo "elflint testfile.debug" +testrun ${abs_top_builddir}/src/elflint --gnu -q -d testfile.debug + +# Now test unstrip recombining those files. +echo "unstrip" +testrun ${abs_top_builddir}/src/unstrip -o testfile.unstrip testfile.strip testfile.debug +echo "elfcmp" +testrun ${abs_top_builddir}/src/elfcmp testfile testfile.unstrip + +# test strip -g +echo "Testing strip -g" +testrun ${abs_top_builddir}/src/strip -g -o testfile.strip -f testfile.debug testfile + +# Do the parts check out? +echo "elflint testfile.strip" +testrun ${abs_top_builddir}/src/elflint --gnu -q testfile.strip +echo "elflint testfile.debug" +testrun ${abs_top_builddir}/src/elflint --gnu -q -d testfile.debug + +# Now strip "in-place" and make sure it is smaller. +echo "TEsting strip in-place" +SIZE_original=$(stat -c%s testfile) +echo "original size $SIZE_original" + +testrun ${abs_top_builddir}/src/strip testfile +SIZE_stripped=$(stat -c%s testfile) +echo "stripped size $SIZE_stripped" +test $SIZE_stripped -lt $SIZE_original || + { echo "*** failure in-place strip file not smaller $original"; exit 1; } + +echo "elflint in-place" +testrun ${abs_top_builddir}/src/elflint --gnu -q testfile + +exit 0 diff --git a/tests/run-strip-test12.sh b/tests/run-strip-test12.sh new file mode 100755 index 00000000..cb120985 --- /dev/null +++ b/tests/run-strip-test12.sh @@ -0,0 +1,4 @@ +original=testfile-riscv64 +stripped=testfile-riscv64-s + +. $srcdir/run-strip-test.sh diff --git a/tests/run-typeiter-many.sh b/tests/run-typeiter-many.sh new file mode 100755 index 00000000..39168f2e --- /dev/null +++ b/tests/run-typeiter-many.sh @@ -0,0 +1,31 @@ +#! /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 + + +# Like run-typeiter.sh but we first add many sections to make sure +# dwarf_begin actually recognizes the debug section names. +testfiles testfile-debug-types + +testrun ${abs_builddir}/addsections 65535 testfile-debug-types +testrun_compare ${abs_builddir}/typeiter2 testfile-debug-types <<\EOF +ok A [68] +ok B [38] +EOF + +exit 0 diff --git a/tests/saridx.c b/tests/saridx.c index 37c0bbf2..27f6bc73 100644 --- a/tests/saridx.c +++ b/tests/saridx.c @@ -17,7 +17,6 @@ #include <config.h> -#include <error.h> #include <fcntl.h> #include <gelf.h> #include <stdio.h> @@ -25,6 +24,7 @@ #include <string.h> #include <time.h> #include <unistd.h> +#include "system.h" static const char *machines[] = diff --git a/tests/sectiondump.c b/tests/sectiondump.c index edec1a7a..e8562427 100644 --- a/tests/sectiondump.c +++ b/tests/sectiondump.c @@ -18,13 +18,13 @@ #include <config.h> #include <errno.h> -#include <error.h> #include <fcntl.h> #include <gelf.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include "system.h" /* Prototypes for local functions. */ diff --git a/tests/testfile-annobingroup-i386.o.bz2 b/tests/testfile-annobingroup-i386.o.bz2 Binary files differnew file mode 100644 index 00000000..798eefda --- /dev/null +++ b/tests/testfile-annobingroup-i386.o.bz2 diff --git a/tests/testfile-annobingroup.o.bz2 b/tests/testfile-annobingroup.o.bz2 Binary files differnew file mode 100644 index 00000000..b1ca7ea1 --- /dev/null +++ b/tests/testfile-annobingroup.o.bz2 diff --git a/tests/testfile-riscv64-core.bz2 b/tests/testfile-riscv64-core.bz2 Binary files differnew file mode 100644 index 00000000..f5b472bb --- /dev/null +++ b/tests/testfile-riscv64-core.bz2 diff --git a/tests/testfile-riscv64-s.bz2 b/tests/testfile-riscv64-s.bz2 Binary files differnew file mode 100755 index 00000000..149ae416 --- /dev/null +++ b/tests/testfile-riscv64-s.bz2 diff --git a/tests/testfile-riscv64.bz2 b/tests/testfile-riscv64.bz2 Binary files differnew file mode 100755 index 00000000..cae4919d --- /dev/null +++ b/tests/testfile-riscv64.bz2 diff --git a/tests/varlocs.c b/tests/varlocs.c index 25124399..40505196 100644 --- a/tests/varlocs.c +++ b/tests/varlocs.c @@ -25,13 +25,13 @@ #include <dwarf.h> #include <stdio.h> #include <stdlib.h> -#include <error.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> +#include "system.h" #include "../libdw/known-dwarf.h" // The Dwarf, Dwarf_CFIs and address bias of diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c index b876c10b..7bfa7381 100644 --- a/tests/vdsosyms.c +++ b/tests/vdsosyms.c @@ -18,13 +18,13 @@ #include <config.h> #include <assert.h> #include <errno.h> -#include <error.h> #include <inttypes.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include ELFUTILS_HEADER(dwfl) +#include "system.h" #ifndef __linux__ int |
