diff options
Diffstat (limited to 'tests')
34 files changed, 2751 insertions, 16 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index b8d1d954..37f98112 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,113 @@ +2016-01-13 Mark Wielaard <mjw@redhat.com> + + * dwfl-bug-fd-leak.c: Skip test unless on __linux__. + +2016-01-13 Mark Wielaard <mjw@redhat.com> + + * dwfl-proc-attach.c: Guard linux specific header. + +2016-01-13 Mark Wielaard <mjw@redhat.com> + + * system-elf-libelf-test.c: New test. + * Makefile.am (TESTS): Add system-elf-libelf-test, if !STANDALONE. + (check_PROGRAMS): Likewise. + (system_elf_libelf_test_CPPFLAGS): New variable. + (system_elf_libelf_test_LDADD): Likewise. + +2016-01-08 Mark Wielaard <mjw@redhat.com> + + * elfputzdata.c (main): Fix parentheses in strncmp test. + +2016-01-08 Mark Wielaard <mjw@redhat.com> + + * elfputzdata.c (main): Use PRId64 to print 64 bit value. + +2016-01-08 Mark Wielaard <mjw@redhat.com> + + * Makefile.am (TESTS): Always unconditionally add + run-readelf-zdebug.sh and run-readelf-zdebug-rel.sh. + +2015-12-16 Mark Wielaard <mjw@redhat.com> + + * run-compress-test.sh: New test. + * Makefile.am (TESTS): Add run-compress-test.sh. + (EXTRA_DISTS): Likewise. + +2015-11-26 Mark Wielaard <mjw@redhat.com> + + * zstrptr.c: New file. + * run-zstrptr.sh: New test. + * elfputzdata.c (main): (re)compress .shstrtab. + * run-elfputzdata.sh: Expect .shstrtab compression. + * Makefile.am (check_PROGRAMS): Add zstrptr. + (TESTS): Add run-zstrptr.sh. + (EXTRA_DIST): Likewise. + (zstrptr_LDADD): New variable. + +2015-10-20 Mark Wielaard <mjw@redhat.com> + + * run-readelf-zx.sh: New test. + * run-readelf-zp.sh: Likewise. + * Makefile.am (TESTS): Add run-readelf-zx.sh and run-readelf-zp.sh. + (EXTRA_DIST): Likewise. + +2015-10-21 Mark Wielaard <mjw@redhat.com> + + * Makefile.am (check_PROGRAMS): Add elfgetzdata and elfputzdata. + (TESTS): Add run-elfgetzdata.sh and run-elfputzdata.sh. + (EXTRA_DIST: Likewise. + (elfgetzdata_LDADD): New variable. + (elfputzdata_LDADD): Likewise. + * elfgetzdata.c: New file. + * elfputzdata.c: Likewise. + * msg_tst.c: Handle ELF_E_ALREADY_COMPRESSED, + ELF_E_UNKNOWN_COMPRESSION_TYPE, ELF_E_COMPRESS_ERROR and + ELF_E_DECOMPRESS_ERROR. + * run-elfgetzdata.sh: New test. + * run-elfputzdata.sh: Likewise. + +2015-10-28 Mark Wielaard <mjw@redhat.com> + + * run-readelf-z.sh: New test. + * Makefile.am (TESTS): Add run-readelf-z.sh. + (EXTRA_DIST): Likewise. + +2015-10-28 Mark Wielaard <mjw@redhat.com> + + * elfgetchdr.c: New file. + * run-elfgetchdr.sh: New test. + * testfile-zgabi32.bz2: New testfile. + * testfile-zgabi32be.bz2: Likewise. + * testfile-zgabi64.bz2: Likewise. + * testfile-zgabi64be.bz2: Likewise. + * Makefile.am (check_PROGRAMS): Add elfgetchdr. + (TESTS): Add run-elfgetchdr.sh. + (EXTRA_DIST): Add run-elfgetchdr.sh, testfile-zgabi32.bz2, + testfile-zgabi32be.bz2, testfile-zgabi64.bz2, testfile-zgabi64be.bz2. + (welfgetchdr_LDADD): New variable. + * msg_tst.c: Add ELF_E_NOT_COMPRESSED, ELF_E_INVALID_SECTION_TYPE + and ELF_E_INVALID_SECTION_FLAGS, + + +2015-10-28 Mark Wielaard <mjw@redhat.com> + + * dwelfgnucompressed.c: New file. + * run-dwelfgnucompressed.sh: New test. + * testfile-zgnu32.bz2: New testfile. + * testfile-zgnu64.bz2: Likewise. + * Makefile.am (check_PROGRAMS): Add dwelfgnucompressed. + (TESTS): Add run-dwelfgnucompressed.sh. + (EXTRA_DIST): Add run-dwelfgnucompressed.sh, testfile-zgnu32.bz2, + testfile-zgnu64.bz2, testfile-zgnu32be.bz2, testfile-zgnu64be.bz2. + (dwelfgnucompressed_LDADD): New variable. + +2015-12-31 Mark Wielaard <mjw@redhat.com> + + * elfstrmerge.c (main): Warn about STT_SECTION symbol for shstrhndx. + * run-elfstrmerge-test.sh: New test. + * Makefile.am (TESTS): Add run-elfstrmerge-test.sh + (EXTRA_DIST): Likewise. + 2015-12-08 Jose E. Marchesi <jose.marchesi@oracle.com> * run-backtrace-core-sparc.sh: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index 8fca8014..7b9e1083 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -52,7 +52,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ backtrace-data backtrace-dwarf debuglink debugaltlink \ buildid deleted deleted-lib.so aggregate_size vdsosyms \ getsrc_die strptr newdata elfstrtab dwfl-proc-attach \ - elfshphehdr elfstrmerge + elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \ + elfgetzdata elfputzdata zstrptr asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -80,7 +81,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-strip-test9.sh run-strip-test10.sh \ run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \ run-unstrip-test.sh run-unstrip-test2.sh \ - run-unstrip-test3.sh run-unstrip-M.sh \ + run-unstrip-test3.sh run-unstrip-M.sh run-elfstrmerge-test.sh \ run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \ run-elflint-test.sh run-elflint-self.sh run-ranlib-test.sh \ run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \ @@ -90,7 +91,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \ run-readelf-test4.sh run-readelf-twofiles.sh \ run-readelf-macro.sh run-readelf-loc.sh \ - run-readelf-aranges.sh run-readelf-line.sh \ + run-readelf-aranges.sh run-readelf-line.sh run-readelf-z.sh \ run-native-test.sh run-bug1-test.sh \ run-debuglink.sh run-debugaltlink.sh run-buildid.sh \ dwfl-bug-addr-overflow run-addrname-test.sh \ @@ -116,11 +117,15 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-backtrace-core-s390x.sh run-backtrace-core-s390.sh \ run-backtrace-core-aarch64.sh run-backtrace-core-sparc.sh \ run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \ - run-stack-demangled-test.sh \ + run-stack-demangled-test.sh run-readelf-zx.sh run-readelf-zp.sh \ run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \ run-linkmap-cut.sh run-aggregate-size.sh vdsosyms run-readelf-A.sh \ run-getsrc-die.sh run-strptr.sh newdata elfstrtab dwfl-proc-attach \ - elfshphehdr run-lfs-symbols.sh + elfshphehdr run-lfs-symbols.sh run-dwelfgnucompressed.sh \ + run-elfgetchdr.sh \ + run-elfgetzdata.sh run-elfputzdata.sh run-zstrptr.sh \ + run-compress-test.sh \ + run-readelf-zdebug.sh run-readelf-zdebug-rel.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -131,18 +136,14 @@ export ELFUTILS_DISABLE_DEMANGLE = 1 endif if !STANDALONE -check_PROGRAMS += msg_tst md5-sha1-test -TESTS += msg_tst md5-sha1-test +check_PROGRAMS += msg_tst md5-sha1-test system-elf-libelf-test +TESTS += msg_tst md5-sha1-test system-elf-libelf-test endif if LZMA TESTS += run-readelf-s.sh run-dwflsyms.sh endif -if ZLIB -TESTS += run-readelf-zdebug.sh -endif - if HAVE_LIBASM check_PROGRAMS += $(asm_TESTS) TESTS += $(asm_TESTS) @@ -167,7 +168,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-unstrip-test.sh run-unstrip-test2.sh \ testfile-info-link.bz2 testfile-info-link.debuginfo.bz2 \ testfile-info-link.stripped.bz2 run-unstrip-test3.sh \ - run-unstrip-M.sh \ + run-unstrip-M.sh run-elfstrmerge-test.sh \ run-elflint-self.sh run-ranlib-test.sh run-ranlib-test2.sh \ run-ranlib-test3.sh run-ranlib-test4.sh \ run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \ @@ -208,6 +209,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-readelf-macro.sh testfilemacro.bz2 \ run-readelf-loc.sh testfileloc.bz2 \ run-readelf-aranges.sh run-readelf-line.sh testfilefoobarbaz.bz2 \ + run-readelf-z.sh \ run-readelf-dwz-multi.sh libtestfile_multi_shared.so.bz2 \ testfile_multi.dwz.bz2 testfile_multi_main.bz2 \ testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \ @@ -296,6 +298,9 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-stack-demangled-test.sh \ testfiledwarfinlines.bz2 testfiledwarfinlines.core.bz2 \ run-readelf-zdebug.sh testfile-debug.bz2 testfile-zdebug.bz2 \ + run-readelf-zdebug-rel.sh testfile-debug-rel.o.bz2 \ + testfile-debug-rel-g.o.bz2 testfile-debug-rel-z.o.bz2 \ + run-readelf-zx.sh run-readelf-zp.sh \ run-deleted.sh run-linkmap-cut.sh linkmap-cut-lib.so.bz2 \ linkmap-cut.bz2 linkmap-cut.core.bz2 \ run-aggregate-size.sh testfile-sizes1.o.bz2 testfile-sizes2.o.bz2 \ @@ -306,7 +311,14 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile-x32-core.bz2 testfile-x32.bz2 \ backtrace.x32.core.bz2 backtrace.x32.exec.bz2 \ testfile-x32-s.bz2 testfile-x32-d.bz2 testfile-x32-debug.bz2 \ - run-lfs-symbols.sh lfs-symbols testfile-nolfs.bz2 + run-lfs-symbols.sh lfs-symbols testfile-nolfs.bz2 \ + testfile-zgnu32.bz2 testfile-zgnu64.bz2 \ + testfile-zgnu32be.bz2 testfile-zgnu64be.bz2 \ + run-dwelfgnucompressed.sh \ + testfile-zgabi32.bz2 testfile-zgabi64.bz2 \ + testfile-zgabi32be.bz2 testfile-zgabi64be.bz2 \ + run-elfgetchdr.sh run-elfgetzdata.sh run-elfputzdata.sh \ + run-zstrptr.sh run-compress-test.sh if USE_VALGRIND valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1' @@ -455,6 +467,16 @@ dwfl_proc_attach_LDADD = $(libdw) dwfl_proc_attach_LDFLAGS = -pthread $(AM_LDFLAGS) elfshphehdr_LDADD =$(libelf) elfstrmerge_LDADD = $(libebl) $(libelf) +dwelfgnucompressed_LDADD = $(libelf) $(libdw) +elfgetchdr_LDADD = $(libelf) $(libdw) +elfgetzdata_LDADD = $(libelf) +elfputzdata_LDADD = $(libelf) +zstrptr_LDADD = $(libelf) + +# We want to test the libelf header against the system elf.h header. +# Don't include any -I CPPFLAGS. +system_elf_libelf_test_CPPFLAGS = +system_elf_libelf_test_LDADD = $(libelf) if GCOV check: check-am coverage diff --git a/tests/dwelfgnucompressed.c b/tests/dwelfgnucompressed.c new file mode 100644 index 00000000..0132271c --- /dev/null +++ b/tests/dwelfgnucompressed.c @@ -0,0 +1,104 @@ +/* Copyright (C) 2015 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <assert.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <inttypes.h> + +#include ELFUTILS_HEADER(elf) +#include ELFUTILS_HEADER(dwelf) +#include <gelf.h> + +#include <stdio.h> +#include <unistd.h> +#include <string.h> + +int +main (int argc, char *argv[]) +{ + int result = 0; + int cnt; + + elf_version (EV_CURRENT); + + for (cnt = 1; cnt < argc; ++cnt) + { + int fd = open (argv[cnt], O_RDONLY); + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + { + printf ("%s not usable %s\n", argv[cnt], elf_errmsg (-1)); + result = 1; + close (fd); + continue; + } + + size_t shdrstrndx; + if (elf_getshdrstrndx (elf, &shdrstrndx) == -1) + { + printf ("elf_getshdrstrnd failed %s\n", elf_errmsg (-1)); + result = 1; + close (fd); + continue; + } + + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (elf, scn)) != NULL) + { + int idx = elf_ndxscn (scn); + GElf_Shdr shdr; + if (gelf_getshdr (scn, &shdr) == NULL) + { + printf ("gelf_getshdr failed: %s\n", elf_errmsg (-1)); + result = 1; + break; + } + + const char *sname = elf_strptr (elf, shdrstrndx, shdr.sh_name); + if (sname == NULL) + { + printf ("couldn't get section name: %s\n", elf_errmsg (-1)); + result = 1; + break; + } + + if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0) + { + ssize_t size; + if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1) + { + printf ("dwelf_scn_gnu_compressed_size failed: %s\n", + elf_errmsg (-1)); + result = 1; + break; + } + printf ("section %d: GNU Compressed size: %zx\n", idx, size); + } + } + + elf_end (elf); + close (fd); + } + + return result; +} diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c index bcbfb290..689cdd79 100644 --- a/tests/dwfl-bug-fd-leak.c +++ b/tests/dwfl-bug-fd-leak.c @@ -27,6 +27,15 @@ #include <error.h> #include <unistd.h> #include <dwarf.h> + +#ifndef __linux__ +int +main (void) +{ + return 77; /* dwfl_linux_proc_report is linux specific. */ +} +#else + #include <sys/resource.h> #include ELFUTILS_HEADER(dwfl) @@ -104,3 +113,4 @@ main (void) return 0; } +#endif diff --git a/tests/dwfl-proc-attach.c b/tests/dwfl-proc-attach.c index 0ba0be24..e7bb2010 100644 --- a/tests/dwfl-proc-attach.c +++ b/tests/dwfl-proc-attach.c @@ -22,6 +22,7 @@ #include <errno.h> #include <error.h> #include <unistd.h> +#ifdef __linux__ #include <sys/types.h> #include <sys/stat.h> #include <sys/user.h> @@ -29,6 +30,7 @@ #include <string.h> #include ELFUTILS_HEADER(dwfl) #include <pthread.h> +#endif #ifndef __linux__ int diff --git a/tests/elfgetchdr.c b/tests/elfgetchdr.c new file mode 100644 index 00000000..44ba1789 --- /dev/null +++ b/tests/elfgetchdr.c @@ -0,0 +1,124 @@ +/* Copyright (C) 2015 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <assert.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <inttypes.h> + +#include ELFUTILS_HEADER(elf) +#include ELFUTILS_HEADER(dwelf) +#include <gelf.h> + +#include <stdio.h> +#include <unistd.h> +#include <string.h> + +int +main (int argc, char *argv[]) +{ + int result = 0; + int cnt; + + elf_version (EV_CURRENT); + + for (cnt = 1; cnt < argc; ++cnt) + { + int fd = open (argv[cnt], O_RDONLY); + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + { + printf ("%s not usable %s\n", argv[cnt], elf_errmsg (-1)); + result = 1; + close (fd); + continue; + } + + size_t shdrstrndx; + if (elf_getshdrstrndx (elf, &shdrstrndx) == -1) + { + printf ("elf_getshdrstrnd failed %s\n", elf_errmsg (-1)); + result = 1; + close (fd); + continue; + } + + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (elf, scn)) != NULL) + { + int idx = elf_ndxscn (scn); + GElf_Shdr shdr; + if (gelf_getshdr (scn, &shdr) == NULL) + { + printf ("gelf_getshdr failed: %s\n", elf_errmsg (-1)); + result = 1; + break; + } + + if ((shdr.sh_flags & SHF_COMPRESSED) != 0) + { + GElf_Chdr chdr; + if (gelf_getchdr (scn, &chdr) == NULL) + { + printf ("gelf_getchdr failed: %s\n", elf_errmsg (-1)); + result = 1; + break; + } + + printf ("section %d: ELF Compressed ch_type: %" PRId32 + ", ch_size: %" PRIx64 ", ch_addralign: %" PRIx64 "\n", + idx, chdr.ch_type, chdr.ch_size, chdr.ch_addralign); + } + else + { + const char *sname = elf_strptr (elf, shdrstrndx, shdr.sh_name); + if (sname == NULL) + { + printf ("couldn't get section name: %s\n", elf_errmsg (-1)); + result = 1; + break; + } + + /* This duplicates what the dwelfgnucompressed testcase does. */ + if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0) + { + ssize_t size; + if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1) + { + printf ("dwelf_scn_gnu_compressed_size failed: %s\n", + elf_errmsg (-1)); + result = 1; + break; + } + printf ("section %d: GNU Compressed size: %zx\n", idx, size); + } + else + printf ("section %d: NOT Compressed\n", idx); + } + } + + elf_end (elf); + close (fd); + } + + return result; +} diff --git a/tests/elfgetzdata.c b/tests/elfgetzdata.c new file mode 100644 index 00000000..82afbe52 --- /dev/null +++ b/tests/elfgetzdata.c @@ -0,0 +1,113 @@ +/* Copyright (C) 2015 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <inttypes.h> +#include <libelf.h> +#include <gelf.h> +#include <stdbool.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + + +int +main (int argc, char *argv[]) +{ + int result = 0; + int cnt; + + if (argc < 3 + || (strcmp (argv[1], "read") != 0 + && strcmp (argv[1], "mmap") != 0)) + { + printf ("Usage: (read|mmap) files...\n"); + return -1; + } + + bool mmap = strcmp (argv[1], "mmap") == 0; + + elf_version (EV_CURRENT); + + for (cnt = 2; cnt < argc; ++cnt) + { + int fd = open (argv[cnt], O_RDONLY); + + Elf *elf = elf_begin (fd, mmap ? ELF_C_READ_MMAP : ELF_C_READ, NULL); + if (elf == NULL) + { + printf ("%s not usable %s\n", argv[cnt], elf_errmsg (-1)); + result = 1; + close (fd); + continue; + } + + /* To get the section names. */ + size_t strndx; + elf_getshdrstrndx (elf, &strndx); + + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (elf, scn)) != NULL) + { + size_t idx = elf_ndxscn (scn); + GElf_Shdr mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &mem); + const char *name = elf_strptr (elf, strndx, shdr->sh_name); + if ((shdr->sh_flags & SHF_COMPRESSED) != 0) + { + /* Real compressed section. */ + if (elf_compress (scn, 0, 0) < 0) + { + printf ("elf_compress failed for section %zd: %s\n", + idx, elf_errmsg (-1)); + return -1; + } + Elf_Data *d = elf_getdata (scn, NULL); + printf ("%zd: %s, ELF compressed, size: %zx\n", + idx, name, d->d_size); + } + else + { + /* Maybe an old GNU compressed .z section? */ + if (name[0] == '.' && name[1] == 'z') + { + if (elf_compress_gnu (scn, 0, 0) < 0) + { + printf ("elf_compress_gnu failed for section %zd: %s\n", + idx, elf_errmsg (-1)); + return -1; + } + Elf_Data *d = elf_getdata (scn, NULL); + printf ("%zd: %s, GNU compressed, size: %zx\n", + idx, name, d->d_size); + } + else + printf ("%zd: %s, NOT compressed\n", idx, name); + } + } + + elf_end (elf); + close (fd); + } + + return result; +} diff --git a/tests/elfputzdata.c b/tests/elfputzdata.c new file mode 100644 index 00000000..66ab77ba --- /dev/null +++ b/tests/elfputzdata.c @@ -0,0 +1,237 @@ +/* Copyright (C) 2015 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <inttypes.h> +#include <libelf.h> +#include <gelf.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + + +int +main (int argc, char *argv[]) +{ + int result = 0; + int cnt; + + if (argc < 3 + || (strcmp (argv[1], "elf") != 0 + && strcmp (argv[1], "gnu") != 0)) + { + printf ("Usage: (elf|gnu) files...\n"); + return -1; + } + + int gnu; + if (strcmp (argv[1], "gnu") == 0) + gnu = 1; + else + gnu = 0; + + elf_version (EV_CURRENT); + + for (cnt = 2; cnt < argc; ++cnt) + { + int fd = open (argv[cnt], O_RDONLY); + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + { + printf ("%s not usable %s\n", argv[cnt], elf_errmsg (-1)); + result = 1; + close (fd); + continue; + } + + /* To get the section names. */ + size_t strndx; + elf_getshdrstrndx (elf, &strndx); + + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (elf, scn)) != NULL) + { + size_t idx = elf_ndxscn (scn); + GElf_Shdr mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &mem); + const char *name = elf_strptr (elf, strndx, shdr->sh_name); + if (shdr->sh_type == SHT_NOBITS + || (shdr->sh_flags & SHF_ALLOC) != 0) + { + printf ("Cannot compress %zd %s\n", idx, name); + } + else if ((shdr->sh_flags & SHF_COMPRESSED) != 0 + || strncmp (name, ".zdebug", strlen (".zdebug")) == 0) + { + printf ("Already compressed %zd %s\n", idx, name); + } + else + { + size_t orig_size = shdr->sh_size; + printf ("Lets compress %zd %s, size: %" PRId64 "\n", + idx, name, shdr->sh_size); + Elf_Data *d = elf_getdata (scn, NULL); + if (d == NULL) + { + printf ("Couldn't get orig data for section %zd\n", idx); + return -1; + } + /* Make a copy so we can compare after + compression/decompression. */ + if (d->d_size != orig_size) + { + printf ("Unexpected data size for orig section %zd\n", idx); + return -1; + } + char *orig_buf = malloc (d->d_size); + if (orig_size > 0 && orig_buf == NULL) + { + printf ("No memory to copy section %zd data\n", idx); + return -1; + } + if (orig_size > 0) + memcpy (orig_buf, d->d_buf, orig_size); + + bool forced = false; + if (gnu) + { + int res = elf_compress_gnu (scn, 1, 0); + if (res == 0) + { + forced = true; + res = elf_compress_gnu (scn, 1, ELF_CHF_FORCE); + } + if (res < 0) + { + printf ("elf_compress_gnu%sfailed for section %zd: %s\n", + forced ? " (forced) " : " ", + idx, elf_errmsg (-1)); + return -1; + } + } + else + { + int res = elf_compress (scn, ELFCOMPRESS_ZLIB, 0); + if (res == 0) + { + forced = true; + res = elf_compress (scn, ELFCOMPRESS_ZLIB, ELF_CHF_FORCE); + } + if (res < 0) + { + printf ("elf_compress%sfailed for section %zd: %s\n", + forced ? " (forced) " : " ", + idx, elf_errmsg (-1)); + return -1; + } + } + GElf_Shdr newmem; + GElf_Shdr *newshdr = gelf_getshdr (scn, &newmem); + size_t new_size = newshdr->sh_size; + d = elf_getdata (scn, NULL); + // Don't check this, might depend on zlib implementation. + // fprintf (stderr, " new_size: %zd\n", new_size); + if (d->d_size != new_size) + { + printf ("Unexpected data size for compressed section %zd\n", + idx); + return -1; + } + + if (forced && new_size < orig_size) + { + printf ("section %zd forced to compress, but size smaller\n", + idx); + return -1; + } + + if (! forced && new_size >= orig_size) + { + printf ("section %zd compressed to bigger size\n", + idx); + return -1; + } + + if (new_size == orig_size + && memcmp (orig_buf, d->d_buf, orig_size) == 0) + { + printf ("section %zd didn't compress\n", idx); + return -1; + } + + if (gnu) + { + if (elf_compress_gnu (scn, 0, 0) < 0) + { + printf ("elf_[un]compress_gnu failed for section %zd: %s\n", + idx, elf_errmsg (-1)); + return -1; + } + } + else + { + if (elf_compress (scn, 0, 0) < 0) + { + printf ("elf_[un]compress failed for section %zd: %s\n", + idx, elf_errmsg (-1)); + return -1; + } + } + GElf_Shdr newermem; + GElf_Shdr *newershdr = gelf_getshdr (scn, &newermem); + size_t newer_size = newershdr->sh_size; + d = elf_getdata (scn, NULL); + // fprintf (stderr, " newer_size: %zd\n", newer_size); + if (d->d_size != newer_size) + { + printf ("Unexpected data size for compressed section %zd\n", + idx); + return -1; + } + if (newer_size != orig_size + && memcmp (orig_buf, d->d_buf, orig_size) != 0) + { + printf ("section %zd didn't correctly uncompress\n", idx); + return -1; + } + free (orig_buf); + // Recompress the string table, just to make sure + // everything keeps working. See elf_strptr above. + if (! gnu && idx == strndx + && elf_compress (scn, ELFCOMPRESS_ZLIB, 0) < 0) + { + printf ("couldn't recompress section header strings: %s\n", + elf_errmsg (-1)); + return -1; + } + } + } + + elf_end (elf); + close (fd); + } + + return result; +} diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c index 6b927c83..4149ca6e 100644 --- a/tests/elfstrmerge.c +++ b/tests/elfstrmerge.c @@ -518,8 +518,13 @@ main (int argc, char **argv) if (gelf_getsym (data, i, &sym) == NULL) fail_elf_idx ("Couldn't get symbol", fname, i); - if (sym.st_shndx != SHN_UNDEF - && sym.st_shndx < SHN_LORESERVE) + if (GELF_ST_TYPE (sym.st_info) == STT_SECTION + && sym.st_shndx == shdrstrndx) + fprintf (stderr, "WARNING:" + " symbol table [%zd] contains section symbol %zd" + " for old shdrstrndx %zd\n", ndx, i, shdrstrndx); + else if (sym.st_shndx != SHN_UNDEF + && sym.st_shndx < SHN_LORESERVE) sym.st_shndx = newsecndx (sym.st_shndx, "section", ndx, "symbol", i); if (update_name && sym.st_name != 0) diff --git a/tests/msg_tst.c b/tests/msg_tst.c index 10ff0f73..7baea0a2 100644 --- a/tests/msg_tst.c +++ b/tests/msg_tst.c @@ -74,7 +74,14 @@ static struct "program header only allowed in executables, shared objects, \ and core files" }, { ELF_E_NO_PHDR, "file has no program header" }, - { ELF_E_INVALID_OFFSET, "invalid offset" } + { ELF_E_INVALID_OFFSET, "invalid offset" }, + { ELF_E_INVALID_SECTION_TYPE , "invalid section type" }, + { ELF_E_INVALID_SECTION_FLAGS , "invalid section flags" }, + { ELF_E_NOT_COMPRESSED, "section does not contain compressed data" }, + { ELF_E_ALREADY_COMPRESSED, "section contains compressed data" }, + { ELF_E_UNKNOWN_COMPRESSION_TYPE, "unknown compression type" }, + { ELF_E_COMPRESS_ERROR, "cannot compress data" }, + { ELF_E_DECOMPRESS_ERROR, "cannot decompress data" } }; diff --git a/tests/run-compress-test.sh b/tests/run-compress-test.sh new file mode 100755 index 00000000..a6a298f5 --- /dev/null +++ b/tests/run-compress-test.sh @@ -0,0 +1,102 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# uncompress -> gnucompress -> uncompress -> elfcompress -> uncompress +testrun_elfcompress_file() +{ + infile="$1" + uncompressedfile="${infile}.uncompressed" + tempfiles "$uncompressedfile" + + echo "uncompress $infile -> $uncompressedfile" + testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${uncompressedfile} ${infile} + testrun ${abs_top_builddir}/src/elflint --gnu-ld ${uncompressedfile} + + SIZE_uncompressed=$(stat -c%s $uncompressedfile) + + gnucompressedfile="${infile}.gnu" + tempfiles "$gnucompressedfile" + echo "compress gnu $uncompressedfile -> $gnucompressedfile" + testrun ${abs_top_builddir}/src/elfcompress -v -t gnu -o ${gnucompressedfile} ${uncompressedfile} + testrun ${abs_top_builddir}/src/elflint --gnu-ld ${gnucompressedfile} + + SIZE_gnucompressed=$(stat -c%s $gnucompressedfile) + test $SIZE_gnucompressed -lt $SIZE_uncompressed || + { echo "*** failure $gnucompressedfile not smaller"; exit -1; } + + gnuuncompressedfile="${infile}.gnu.uncompressed" + tempfiles "$gnuuncompressedfile" + echo "uncompress $gnucompressedfile -> $gnuuncompressedfile" + testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${gnuuncompressedfile} ${gnucompressedfile} + testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${gnuuncompressedfile} + + elfcompressedfile="${infile}.gabi" + tempfiles "$elfcompressedfile" + echo "compress gabi $uncompressedfile -> $elfcompressedfile" + testrun ${abs_top_builddir}/src/elfcompress -v -t zlib -o ${elfcompressedfile} ${uncompressedfile} + testrun ${abs_top_builddir}/src/elflint --gnu-ld ${elfcompressedfile} + + SIZE_elfcompressed=$(stat -c%s $elfcompressedfile) + test $SIZE_elfcompressed -lt $SIZE_uncompressed || + { echo "*** failure $elfcompressedfile not smaller"; exit -1; } + + elfuncompressedfile="${infile}.gabi.uncompressed" + tempfiles "$elfuncompressedfile" + echo "uncompress $elfcompressedfile -> $elfuncompressedfile" + testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${elfuncompressedfile} ${elfcompressedfile} + testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${elfuncompressedfile} +} + +testrun_elfcompress() +{ + testfile="$1" + testfiles ${testfile} + testrun_elfcompress_file ${testfile} + + # Merge the string tables to make things a little more interesting. + mergedfile="${testfile}.merged" + tempfiles ${mergedfile} + echo "merging string tables ${testfile} -> ${mergedfile}" + testrun ${abs_top_builddir}/tests/elfstrmerge -o ${mergedfile} ${testfile} + testrun_elfcompress_file ${mergedfile} +} + +# Random ELF32 testfile +testrun_elfcompress testfile4 + +# Random ELF64 testfile +testrun_elfcompress testfile12 + +# Random ELF64BE testfile +testrun_elfcompress testfileppc64 + +# Random ELF32BE testfile +testrun_elfcompress testfileppc32 + +# Already compressed files +testrun_elfcompress testfile-zgnu64 +testrun_elfcompress testfile-zgnu64be +testrun_elfcompress testfile-zgabi64 +testrun_elfcompress testfile-zgabi64be +testrun_elfcompress testfile-zgnu32 +testrun_elfcompress testfile-zgnu32be +testrun_elfcompress testfile-zgabi32 +testrun_elfcompress testfile-zgabi32be + +exit 0 diff --git a/tests/run-dwelfgnucompressed.sh b/tests/run-dwelfgnucompressed.sh new file mode 100755 index 00000000..b93a56f2 --- /dev/null +++ b/tests/run-dwelfgnucompressed.sh @@ -0,0 +1,108 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# = funcs.s = +# .globl testfunc +# testfunc: +# nop +# ret +# .type testfunc, @function +# .size testfunc, .-testfunc +# +# .globl testfunc2 +# testfunc2: +# call testfunc +# nop +# nop +# ret +# .type testfunc2, @function +# .size testfunc2, .-testfunc2 +# +# .globl functest3 +# functest3: +# jmp local +# nop +# nop +# local: +# call testfunc2 +# ret +# .type functest3, @function +# .size functest3, .-functest3 + +# = start.s = +# .global _start +# _start: +# call functest3 +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# ret +# .type _start, @function +# .size _start, .-_start + +# gas --compress-debug-sections=zlib-gnu -32 -g -o start.o start.s +# gas --compress-debug-sections=zlib-gnu -32 -g -o funcs.o funcs.s +# ld --compress-debug-sections=zlib-gnu -melf_i386 -g -o zgnu32 funcs.o start.o + +# gas --compress-debug-sections=zlib-gnu -64 -g -o start.o start.s +# gas --compress-debug-sections=zlib-gnu -64 -g -o funcs.o funcs.s +# ld --compress-debug-sections=zlib-gnu -g -o zgnu32 funcs.o start.o + +testfiles testfile-zgnu64 +testrun_compare ${abs_top_builddir}/tests/dwelfgnucompressed testfile-zgnu64 <<\EOF +section 2: GNU Compressed size: 60 +section 3: GNU Compressed size: aa +section 5: GNU Compressed size: 8d +EOF + +testfiles testfile-zgnu64be +testrun_compare ${abs_top_builddir}/tests/dwelfgnucompressed testfile-zgnu64be <<\EOF +section 3: GNU Compressed size: 60 +section 4: GNU Compressed size: 7e +section 6: GNU Compressed size: 8d +EOF + +testfiles testfile-zgnu32 +testrun_compare ${abs_top_builddir}/tests/dwelfgnucompressed testfile-zgnu32 <<\EOF +section 2: GNU Compressed size: 40 +section 3: GNU Compressed size: 9a +section 5: GNU Compressed size: 85 +EOF + +testfiles testfile-zgnu32be +testrun_compare ${abs_top_builddir}/tests/dwelfgnucompressed testfile-zgnu32be <<\EOF +section 3: GNU Compressed size: 40 +section 4: GNU Compressed size: 6e +section 6: GNU Compressed size: 85 +EOF + +exit 0 diff --git a/tests/run-elfgetchdr.sh b/tests/run-elfgetchdr.sh new file mode 100755 index 00000000..7a422f39 --- /dev/null +++ b/tests/run-elfgetchdr.sh @@ -0,0 +1,188 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# = funcs.s = +# .globl testfunc +# testfunc: +# nop +# ret +# .type testfunc, @function +# .size testfunc, .-testfunc +# +# .globl testfunc2 +# testfunc2: +# call testfunc +# nop +# nop +# ret +# .type testfunc2, @function +# .size testfunc2, .-testfunc2 +# +# .globl functest3 +# functest3: +# jmp local +# nop +# nop +# local: +# call testfunc2 +# ret +# .type functest3, @function +# .size functest3, .-functest3 + +# = start.s = +# .global _start +# _start: +# call functest3 +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# nop +# ret +# .type _start, @function +# .size _start, .-_start + +# gas --compress-debug-sections=zlib-gnu -32 -g -o start.o start.s +# gas --compress-debug-sections=zlib-gnu -32 -g -o funcs.o funcs.s +# ld --compress-debug-sections=zlib-gnu -melf_i386 -g -o zgnu32 funcs.o start.o + +# gas --compress-debug-sections=zlib-gnu -64 -g -o start.o start.s +# gas --compress-debug-sections=zlib-gnu -64 -g -o funcs.o funcs.s +# ld --compress-debug-sections=zlib-gnu -g -o zgnu64 funcs.o start.o + +# gas --compress-debug-sections=zlib-gabi -32 -g -o start.o start.s +# gas --compress-debug-sections=zlib-gabi -32 -g -o funcs.o funcs.s +# ld --compress-debug-sections=zlib-gabi -melf_i386 -g -o zgabi32 funcs.o start.o + +# gas --compress-debug-sections=zlib-gabi -64 -g -o start.o start.s +# gas --compress-debug-sections=zlib-gabi -64 -g -o funcs.o funcs.s +# ld --compress-debug-sections=zlib-gabi -g -o zgabi64 funcs.o start.o + +testfiles testfile-zgnu64 +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgnu64 <<\EOF +section 1: NOT Compressed +section 2: GNU Compressed size: 60 +section 3: GNU Compressed size: aa +section 4: NOT Compressed +section 5: GNU Compressed size: 8d +section 6: NOT Compressed +section 7: NOT Compressed +section 8: NOT Compressed +EOF + +testfiles testfile-zgabi64 +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgabi64 <<\EOF +section 1: NOT Compressed +section 2: ELF Compressed ch_type: 1, ch_size: 60, ch_addralign: 10 +section 3: ELF Compressed ch_type: 1, ch_size: aa, ch_addralign: 1 +section 4: NOT Compressed +section 5: ELF Compressed ch_type: 1, ch_size: 8d, ch_addralign: 1 +section 6: NOT Compressed +section 7: NOT Compressed +section 8: NOT Compressed +EOF + +testfiles testfile-zgnu32 +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgnu32 <<\EOF +section 1: NOT Compressed +section 2: GNU Compressed size: 40 +section 3: GNU Compressed size: 9a +section 4: NOT Compressed +section 5: GNU Compressed size: 85 +section 6: NOT Compressed +section 7: NOT Compressed +section 8: NOT Compressed +EOF + +testfiles testfile-zgabi32 +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgabi32 <<\EOF +section 1: NOT Compressed +section 2: ELF Compressed ch_type: 1, ch_size: 40, ch_addralign: 8 +section 3: ELF Compressed ch_type: 1, ch_size: 9a, ch_addralign: 1 +section 4: NOT Compressed +section 5: ELF Compressed ch_type: 1, ch_size: 85, ch_addralign: 1 +section 6: NOT Compressed +section 7: NOT Compressed +section 8: NOT Compressed +EOF + +testfiles testfile-zgnu64be +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgnu64be <<\EOF +section 1: NOT Compressed +section 2: NOT Compressed +section 3: GNU Compressed size: 60 +section 4: GNU Compressed size: 7e +section 5: NOT Compressed +section 6: GNU Compressed size: 8d +section 7: NOT Compressed +section 8: NOT Compressed +section 9: NOT Compressed +EOF + +testfiles testfile-zgabi64be +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgabi64be <<\EOF +section 1: NOT Compressed +section 2: NOT Compressed +section 3: ELF Compressed ch_type: 1, ch_size: 60, ch_addralign: 10 +section 4: ELF Compressed ch_type: 1, ch_size: 7e, ch_addralign: 1 +section 5: NOT Compressed +section 6: ELF Compressed ch_type: 1, ch_size: 8d, ch_addralign: 1 +section 7: NOT Compressed +section 8: NOT Compressed +section 9: NOT Compressed +EOF + +testfiles testfile-zgnu32be +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgnu32be <<\EOF +section 1: NOT Compressed +section 2: NOT Compressed +section 3: GNU Compressed size: 40 +section 4: GNU Compressed size: 6e +section 5: NOT Compressed +section 6: GNU Compressed size: 85 +section 7: NOT Compressed +section 8: NOT Compressed +section 9: NOT Compressed +EOF + +testfiles testfile-zgabi32be +testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgabi32be <<\EOF +section 1: NOT Compressed +section 2: NOT Compressed +section 3: ELF Compressed ch_type: 1, ch_size: 40, ch_addralign: 8 +section 4: ELF Compressed ch_type: 1, ch_size: 6e, ch_addralign: 1 +section 5: NOT Compressed +section 6: ELF Compressed ch_type: 1, ch_size: 85, ch_addralign: 1 +section 7: NOT Compressed +section 8: NOT Compressed +section 9: NOT Compressed +EOF + +exit 0 diff --git a/tests/run-elfgetzdata.sh b/tests/run-elfgetzdata.sh new file mode 100755 index 00000000..e2df3081 --- /dev/null +++ b/tests/run-elfgetzdata.sh @@ -0,0 +1,214 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# See run-elfgetchdr.sh for testfiles. + +testfiles testfile-zgnu64 +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgnu64 <<\EOF +1: .text, NOT compressed +2: .zdebug_aranges, GNU compressed, size: 60 +3: .zdebug_info, GNU compressed, size: aa +4: .debug_abbrev, NOT compressed +5: .zdebug_line, GNU compressed, size: 8d +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgnu64 <<\EOF +1: .text, NOT compressed +2: .zdebug_aranges, GNU compressed, size: 60 +3: .zdebug_info, GNU compressed, size: aa +4: .debug_abbrev, NOT compressed +5: .zdebug_line, GNU compressed, size: 8d +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testfiles testfile-zgnu64be +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgnu64be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .zdebug_aranges, GNU compressed, size: 60 +4: .zdebug_info, GNU compressed, size: 7e +5: .debug_abbrev, NOT compressed +6: .zdebug_line, GNU compressed, size: 8d +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgnu64be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .zdebug_aranges, GNU compressed, size: 60 +4: .zdebug_info, GNU compressed, size: 7e +5: .debug_abbrev, NOT compressed +6: .zdebug_line, GNU compressed, size: 8d +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +testfiles testfile-zgabi64 +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgabi64 <<\EOF +1: .text, NOT compressed +2: .debug_aranges, ELF compressed, size: 60 +3: .debug_info, ELF compressed, size: aa +4: .debug_abbrev, NOT compressed +5: .debug_line, ELF compressed, size: 8d +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgabi64 <<\EOF +1: .text, NOT compressed +2: .debug_aranges, ELF compressed, size: 60 +3: .debug_info, ELF compressed, size: aa +4: .debug_abbrev, NOT compressed +5: .debug_line, ELF compressed, size: 8d +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testfiles testfile-zgabi64be +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgabi64be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .debug_aranges, ELF compressed, size: 60 +4: .debug_info, ELF compressed, size: 7e +5: .debug_abbrev, NOT compressed +6: .debug_line, ELF compressed, size: 8d +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgabi64be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .debug_aranges, ELF compressed, size: 60 +4: .debug_info, ELF compressed, size: 7e +5: .debug_abbrev, NOT compressed +6: .debug_line, ELF compressed, size: 8d +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +testfiles testfile-zgnu32 +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgnu32 <<\EOF +1: .text, NOT compressed +2: .zdebug_aranges, GNU compressed, size: 40 +3: .zdebug_info, GNU compressed, size: 9a +4: .debug_abbrev, NOT compressed +5: .zdebug_line, GNU compressed, size: 85 +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgnu32 <<\EOF +1: .text, NOT compressed +2: .zdebug_aranges, GNU compressed, size: 40 +3: .zdebug_info, GNU compressed, size: 9a +4: .debug_abbrev, NOT compressed +5: .zdebug_line, GNU compressed, size: 85 +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testfiles testfile-zgnu32be +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgnu32be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .zdebug_aranges, GNU compressed, size: 40 +4: .zdebug_info, GNU compressed, size: 6e +5: .debug_abbrev, NOT compressed +6: .zdebug_line, GNU compressed, size: 85 +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgnu32be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .zdebug_aranges, GNU compressed, size: 40 +4: .zdebug_info, GNU compressed, size: 6e +5: .debug_abbrev, NOT compressed +6: .zdebug_line, GNU compressed, size: 85 +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +testfiles testfile-zgabi32 +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgabi32 <<\EOF +1: .text, NOT compressed +2: .debug_aranges, ELF compressed, size: 40 +3: .debug_info, ELF compressed, size: 9a +4: .debug_abbrev, NOT compressed +5: .debug_line, ELF compressed, size: 85 +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgabi32 <<\EOF +1: .text, NOT compressed +2: .debug_aranges, ELF compressed, size: 40 +3: .debug_info, ELF compressed, size: 9a +4: .debug_abbrev, NOT compressed +5: .debug_line, ELF compressed, size: 85 +6: .shstrtab, NOT compressed +7: .symtab, NOT compressed +8: .strtab, NOT compressed +EOF + +testfiles testfile-zgabi32be +testrun_compare ${abs_top_builddir}/tests/elfgetzdata read testfile-zgabi32be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .debug_aranges, ELF compressed, size: 40 +4: .debug_info, ELF compressed, size: 6e +5: .debug_abbrev, NOT compressed +6: .debug_line, ELF compressed, size: 85 +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +testrun_compare ${abs_top_builddir}/tests/elfgetzdata mmap testfile-zgabi32be <<\EOF +1: .text, NOT compressed +2: .eh_frame, NOT compressed +3: .debug_aranges, ELF compressed, size: 40 +4: .debug_info, ELF compressed, size: 6e +5: .debug_abbrev, NOT compressed +6: .debug_line, ELF compressed, size: 85 +7: .shstrtab, NOT compressed +8: .symtab, NOT compressed +9: .strtab, NOT compressed +EOF + +exit 0 diff --git a/tests/run-elfputzdata.sh b/tests/run-elfputzdata.sh new file mode 100755 index 00000000..b882b3f0 --- /dev/null +++ b/tests/run-elfputzdata.sh @@ -0,0 +1,340 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# Random ELF32 testfile +testfiles testfile4 + +testrun_compare ${abs_top_builddir}/tests/elfputzdata gnu testfile4 <<\EOF +Cannot compress 1 .interp +Cannot compress 2 .note.ABI-tag +Cannot compress 3 .hash +Cannot compress 4 .dynsym +Cannot compress 5 .dynstr +Cannot compress 6 .gnu.version +Cannot compress 7 .gnu.version_r +Cannot compress 8 .rel.got +Cannot compress 9 .rel.plt +Cannot compress 10 .init +Cannot compress 11 .plt +Cannot compress 12 .text +Cannot compress 13 .fini +Cannot compress 14 .rodata +Cannot compress 15 .data +Cannot compress 16 .eh_frame +Cannot compress 17 .gcc_except_table +Cannot compress 18 .ctors +Cannot compress 19 .dtors +Cannot compress 20 .got +Cannot compress 21 .dynamic +Lets compress 22 .sbss, size: 0 +Cannot compress 23 .bss +Lets compress 24 .stab, size: 21540 +Lets compress 25 .stabstr, size: 57297 +Lets compress 26 .comment, size: 648 +Lets compress 27 .debug_aranges, size: 56 +Lets compress 28 .debug_pubnames, size: 93 +Lets compress 29 .debug_info, size: 960 +Lets compress 30 .debug_abbrev, size: 405 +Lets compress 31 .debug_line, size: 189 +Lets compress 32 .note, size: 240 +Lets compress 33 .shstrtab, size: 320 +Lets compress 34 .symtab, size: 5488 +Lets compress 35 .strtab, size: 5727 +EOF + +testrun_compare ${abs_top_builddir}/tests/elfputzdata elf testfile4 <<\EOF +Cannot compress 1 .interp +Cannot compress 2 .note.ABI-tag +Cannot compress 3 .hash +Cannot compress 4 .dynsym +Cannot compress 5 .dynstr +Cannot compress 6 .gnu.version +Cannot compress 7 .gnu.version_r +Cannot compress 8 .rel.got +Cannot compress 9 .rel.plt +Cannot compress 10 .init +Cannot compress 11 .plt +Cannot compress 12 .text +Cannot compress 13 .fini +Cannot compress 14 .rodata +Cannot compress 15 .data +Cannot compress 16 .eh_frame +Cannot compress 17 .gcc_except_table +Cannot compress 18 .ctors +Cannot compress 19 .dtors +Cannot compress 20 .got +Cannot compress 21 .dynamic +Lets compress 22 .sbss, size: 0 +Cannot compress 23 .bss +Lets compress 24 .stab, size: 21540 +Lets compress 25 .stabstr, size: 57297 +Lets compress 26 .comment, size: 648 +Lets compress 27 .debug_aranges, size: 56 +Lets compress 28 .debug_pubnames, size: 93 +Lets compress 29 .debug_info, size: 960 +Lets compress 30 .debug_abbrev, size: 405 +Lets compress 31 .debug_line, size: 189 +Lets compress 32 .note, size: 240 +Lets compress 33 .shstrtab, size: 320 +Lets compress 34 .symtab, size: 5488 +Lets compress 35 .strtab, size: 5727 +EOF + +# Random ELF64 testfile +testfiles testfile12 + +testrun_compare ${abs_top_builddir}/tests/elfputzdata gnu testfile12 <<\EOF +Cannot compress 1 .hash +Cannot compress 2 .dynsym +Cannot compress 3 .dynstr +Cannot compress 4 .gnu.version +Cannot compress 5 .gnu.version_r +Cannot compress 6 .rela.dyn +Cannot compress 7 .rela.plt +Cannot compress 8 .init +Cannot compress 9 .plt +Cannot compress 10 .text +Cannot compress 11 .fini +Cannot compress 12 .rodata +Cannot compress 13 .eh_frame_hdr +Cannot compress 14 .eh_frame +Cannot compress 15 .data +Cannot compress 16 .dynamic +Cannot compress 17 .ctors +Cannot compress 18 .dtors +Cannot compress 19 .jcr +Cannot compress 20 .got +Cannot compress 21 .bss +Lets compress 22 .comment, size: 246 +Lets compress 23 .debug_aranges, size: 192 +Lets compress 24 .debug_pubnames, size: 26 +Lets compress 25 .debug_info, size: 3468 +Lets compress 26 .debug_abbrev, size: 341 +Lets compress 27 .debug_line, size: 709 +Lets compress 28 .debug_frame, size: 56 +Lets compress 29 .debug_str, size: 2235 +Lets compress 30 .debug_macinfo, size: 10518 +Lets compress 31 .shstrtab, size: 308 +Lets compress 32 .symtab, size: 1944 +Lets compress 33 .strtab, size: 757 +EOF + +testrun_compare ${abs_top_builddir}/tests/elfputzdata elf testfile12 <<\EOF +Cannot compress 1 .hash +Cannot compress 2 .dynsym +Cannot compress 3 .dynstr +Cannot compress 4 .gnu.version +Cannot compress 5 .gnu.version_r +Cannot compress 6 .rela.dyn +Cannot compress 7 .rela.plt +Cannot compress 8 .init +Cannot compress 9 .plt +Cannot compress 10 .text +Cannot compress 11 .fini +Cannot compress 12 .rodata +Cannot compress 13 .eh_frame_hdr +Cannot compress 14 .eh_frame +Cannot compress 15 .data +Cannot compress 16 .dynamic +Cannot compress 17 .ctors +Cannot compress 18 .dtors +Cannot compress 19 .jcr +Cannot compress 20 .got +Cannot compress 21 .bss +Lets compress 22 .comment, size: 246 +Lets compress 23 .debug_aranges, size: 192 +Lets compress 24 .debug_pubnames, size: 26 +Lets compress 25 .debug_info, size: 3468 +Lets compress 26 .debug_abbrev, size: 341 +Lets compress 27 .debug_line, size: 709 +Lets compress 28 .debug_frame, size: 56 +Lets compress 29 .debug_str, size: 2235 +Lets compress 30 .debug_macinfo, size: 10518 +Lets compress 31 .shstrtab, size: 308 +Lets compress 32 .symtab, size: 1944 +Lets compress 33 .strtab, size: 757 +EOF + +# Random ELF64BE testfile +testfiles testfileppc64 + +testrun_compare ${abs_top_builddir}/tests/elfputzdata gnu testfileppc64 <<\EOF +Cannot compress 1 .interp +Cannot compress 2 .note.ABI-tag +Cannot compress 3 .note.gnu.build-id +Cannot compress 4 .gnu.hash +Cannot compress 5 .dynsym +Cannot compress 6 .dynstr +Cannot compress 7 .gnu.version +Cannot compress 8 .gnu.version_r +Cannot compress 9 .rela.plt +Cannot compress 10 .init +Cannot compress 11 .text +Cannot compress 12 .fini +Cannot compress 13 .rodata +Cannot compress 14 .eh_frame_hdr +Cannot compress 15 .eh_frame +Cannot compress 16 .init_array +Cannot compress 17 .fini_array +Cannot compress 18 .jcr +Cannot compress 19 .dynamic +Cannot compress 20 .data +Cannot compress 21 .opd +Cannot compress 22 .got +Cannot compress 23 .plt +Cannot compress 24 .bss +Lets compress 25 .comment, size: 88 +Lets compress 26 .debug_aranges, size: 96 +Lets compress 27 .debug_info, size: 363 +Lets compress 28 .debug_abbrev, size: 315 +Lets compress 29 .debug_line, size: 119 +Lets compress 30 .debug_frame, size: 96 +Lets compress 31 .debug_str, size: 174 +Lets compress 32 .debug_loc, size: 171 +Lets compress 33 .debug_ranges, size: 32 +Lets compress 34 .shstrtab, size: 352 +Lets compress 35 .symtab, size: 1800 +Lets compress 36 .strtab, size: 602 +EOF + +testrun_compare ${abs_top_builddir}/tests/elfputzdata elf testfileppc64 <<\EOF +Cannot compress 1 .interp +Cannot compress 2 .note.ABI-tag +Cannot compress 3 .note.gnu.build-id +Cannot compress 4 .gnu.hash +Cannot compress 5 .dynsym +Cannot compress 6 .dynstr +Cannot compress 7 .gnu.version +Cannot compress 8 .gnu.version_r +Cannot compress 9 .rela.plt +Cannot compress 10 .init +Cannot compress 11 .text +Cannot compress 12 .fini +Cannot compress 13 .rodata +Cannot compress 14 .eh_frame_hdr +Cannot compress 15 .eh_frame +Cannot compress 16 .init_array +Cannot compress 17 .fini_array +Cannot compress 18 .jcr +Cannot compress 19 .dynamic +Cannot compress 20 .data +Cannot compress 21 .opd +Cannot compress 22 .got +Cannot compress 23 .plt +Cannot compress 24 .bss +Lets compress 25 .comment, size: 88 +Lets compress 26 .debug_aranges, size: 96 +Lets compress 27 .debug_info, size: 363 +Lets compress 28 .debug_abbrev, size: 315 +Lets compress 29 .debug_line, size: 119 +Lets compress 30 .debug_frame, size: 96 +Lets compress 31 .debug_str, size: 174 +Lets compress 32 .debug_loc, size: 171 +Lets compress 33 .debug_ranges, size: 32 +Lets compress 34 .shstrtab, size: 352 +Lets compress 35 .symtab, size: 1800 +Lets compress 36 .strtab, size: 602 +EOF + +# Random ELF32BE testfile +testfiles testfileppc32 + +testrun_compare ${abs_top_builddir}/tests/elfputzdata gnu testfileppc32 <<\EOF +Cannot compress 1 .interp +Cannot compress 2 .note.ABI-tag +Cannot compress 3 .note.gnu.build-id +Cannot compress 4 .gnu.hash +Cannot compress 5 .dynsym +Cannot compress 6 .dynstr +Cannot compress 7 .gnu.version +Cannot compress 8 .gnu.version_r +Cannot compress 9 .rela.dyn +Cannot compress 10 .rela.plt +Cannot compress 11 .init +Cannot compress 12 .text +Cannot compress 13 .fini +Cannot compress 14 .rodata +Cannot compress 15 .eh_frame_hdr +Cannot compress 16 .eh_frame +Cannot compress 17 .init_array +Cannot compress 18 .fini_array +Cannot compress 19 .jcr +Cannot compress 20 .got2 +Cannot compress 21 .dynamic +Cannot compress 22 .got +Cannot compress 23 .plt +Cannot compress 24 .data +Cannot compress 25 .sdata +Cannot compress 26 .bss +Lets compress 27 .comment, size: 88 +Lets compress 28 .debug_aranges, size: 64 +Lets compress 29 .debug_info, size: 319 +Lets compress 30 .debug_abbrev, size: 318 +Lets compress 31 .debug_line, size: 109 +Lets compress 32 .debug_frame, size: 64 +Lets compress 33 .debug_str, size: 179 +Lets compress 34 .debug_loc, size: 99 +Lets compress 35 .debug_ranges, size: 16 +Lets compress 36 .shstrtab, size: 370 +Lets compress 37 .symtab, size: 1232 +Lets compress 38 .strtab, size: 569 +EOF + +testrun_compare ${abs_top_builddir}/tests/elfputzdata elf testfileppc32 <<\EOF +Cannot compress 1 .interp +Cannot compress 2 .note.ABI-tag +Cannot compress 3 .note.gnu.build-id +Cannot compress 4 .gnu.hash +Cannot compress 5 .dynsym +Cannot compress 6 .dynstr +Cannot compress 7 .gnu.version +Cannot compress 8 .gnu.version_r +Cannot compress 9 .rela.dyn +Cannot compress 10 .rela.plt +Cannot compress 11 .init +Cannot compress 12 .text +Cannot compress 13 .fini +Cannot compress 14 .rodata +Cannot compress 15 .eh_frame_hdr +Cannot compress 16 .eh_frame +Cannot compress 17 .init_array +Cannot compress 18 .fini_array +Cannot compress 19 .jcr +Cannot compress 20 .got2 +Cannot compress 21 .dynamic +Cannot compress 22 .got +Cannot compress 23 .plt +Cannot compress 24 .data +Cannot compress 25 .sdata +Cannot compress 26 .bss +Lets compress 27 .comment, size: 88 +Lets compress 28 .debug_aranges, size: 64 +Lets compress 29 .debug_info, size: 319 +Lets compress 30 .debug_abbrev, size: 318 +Lets compress 31 .debug_line, size: 109 +Lets compress 32 .debug_frame, size: 64 +Lets compress 33 .debug_str, size: 179 +Lets compress 34 .debug_loc, size: 99 +Lets compress 35 .debug_ranges, size: 16 +Lets compress 36 .shstrtab, size: 370 +Lets compress 37 .symtab, size: 1232 +Lets compress 38 .strtab, size: 569 +EOF + +exit 0 diff --git a/tests/run-elfstrmerge-test.sh b/tests/run-elfstrmerge-test.sh new file mode 100755 index 00000000..d08b6fca --- /dev/null +++ b/tests/run-elfstrmerge-test.sh @@ -0,0 +1,40 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# Merge string tables of file and check result with elflint. +testrun_elfcompress() +{ + testfile="$1" + testfiles ${testfile} + + mergedfile="${testfile}.merged" + tempfiles ${mergedfile} + + echo "merging string tables ${testfile} -> ${mergedfile}" + testrun ${abs_top_builddir}/tests/elfstrmerge -o ${mergedfile} ${testfile} + testrun ${abs_top_builddir}/src/elflint --gnu-ld ${mergedfile} +} + +# Random ELF32 testfile with extra STT_SECTION symbols +testrun_elfcompress testfile4 + +# Random ELF64 testfile with extra STT_SECTION symbols +testrun_elfcompress testfile12 + +exit 0 diff --git a/tests/run-readelf-z.sh b/tests/run-readelf-z.sh new file mode 100755 index 00000000..6dbd2f14 --- /dev/null +++ b/tests/run-readelf-z.sh @@ -0,0 +1,202 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# See run-elfgetchdr.sh for testfiles. + +testfiles testfile-zgnu64 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgnu64 <<\EOF +There are 9 section headers, starting at offset 0x3e0: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 0000000000000000 00000000 00000000 0 0 0 0 +[ 1] .text PROGBITS 0000000000400078 00000078 0000002a 0 AX 0 0 1 +[ 2] .zdebug_aranges PROGBITS 0000000000000000 00000260 00000032 0 0 0 16 + [GNU ZLIB 00000060 ] +[ 3] .zdebug_info PROGBITS 0000000000000000 00000292 0000006f 0 0 0 1 + [GNU ZLIB 000000aa ] +[ 4] .debug_abbrev PROGBITS 0000000000000000 00000301 00000028 0 0 0 1 +[ 5] .zdebug_line PROGBITS 0000000000000000 00000329 0000005b 0 0 0 1 + [GNU ZLIB 0000008d ] +[ 6] .shstrtab STRTAB 0000000000000000 00000384 00000059 0 0 0 1 +[ 7] .symtab SYMTAB 0000000000000000 000000a8 00000168 24 8 8 8 +[ 8] .strtab STRTAB 0000000000000000 00000210 0000004b 0 0 0 1 + +EOF + +testfiles testfile-zgnu64be +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgnu64be <<\EOF +There are 10 section headers, starting at offset 0x438: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 0000000000000000 00000000 00000000 0 0 0 0 +[ 1] .text PROGBITS 0000000010000078 00000078 00000074 0 AX 0 0 8 +[ 2] .eh_frame PROGBITS 00000000100000ec 000000ec 00000000 0 A 0 0 4 +[ 3] .zdebug_aranges PROGBITS 0000000000000000 000002c0 00000034 0 0 0 16 + [GNU ZLIB 00000060 ] +[ 4] .zdebug_info PROGBITS 0000000000000000 000002f4 00000059 0 0 0 1 + [GNU ZLIB 0000007e ] +[ 5] .debug_abbrev PROGBITS 0000000000000000 0000034d 00000028 0 0 0 1 +[ 6] .zdebug_line PROGBITS 0000000000000000 00000375 0000005b 0 0 0 1 + [GNU ZLIB 0000008d ] +[ 7] .shstrtab STRTAB 0000000000000000 000003d0 00000063 0 0 0 1 +[ 8] .symtab SYMTAB 0000000000000000 000000f0 00000180 24 9 9 8 +[ 9] .strtab STRTAB 0000000000000000 00000270 00000044 0 0 0 1 + +EOF + +testfiles testfile-zgabi64 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgabi64 <<\EOF +There are 9 section headers, starting at offset 0x400: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 0000000000000000 00000000 00000000 0 0 0 0 +[ 1] .text PROGBITS 0000000000400078 00000078 0000002a 0 AX 0 0 1 +[ 2] .debug_aranges PROGBITS 0000000000000000 00000260 0000003e 0 C 0 0 16 + [ELF ZLIB (1) 00000060 16] +[ 3] .debug_info PROGBITS 0000000000000000 0000029e 0000007b 0 C 0 0 1 + [ELF ZLIB (1) 000000aa 1] +[ 4] .debug_abbrev PROGBITS 0000000000000000 00000319 00000028 0 0 0 1 +[ 5] .debug_line PROGBITS 0000000000000000 00000341 00000067 0 C 0 0 1 + [ELF ZLIB (1) 0000008d 1] +[ 6] .shstrtab STRTAB 0000000000000000 000003a8 00000056 0 0 0 1 +[ 7] .symtab SYMTAB 0000000000000000 000000a8 00000168 24 8 8 8 +[ 8] .strtab STRTAB 0000000000000000 00000210 0000004b 0 0 0 1 + +EOF + +testfiles testfile-zgabi64be +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgabi64be <<\EOF +There are 10 section headers, starting at offset 0x458: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 0000000000000000 00000000 00000000 0 0 0 0 +[ 1] .text PROGBITS 0000000010000078 00000078 00000074 0 AX 0 0 8 +[ 2] .eh_frame PROGBITS 00000000100000ec 000000ec 00000000 0 A 0 0 4 +[ 3] .debug_aranges PROGBITS 0000000000000000 000002c0 00000040 0 C 0 0 16 + [ELF ZLIB (1) 00000060 16] +[ 4] .debug_info PROGBITS 0000000000000000 00000300 00000065 0 C 0 0 1 + [ELF ZLIB (1) 0000007e 1] +[ 5] .debug_abbrev PROGBITS 0000000000000000 00000365 00000028 0 0 0 1 +[ 6] .debug_line PROGBITS 0000000000000000 0000038d 00000067 0 C 0 0 1 + [ELF ZLIB (1) 0000008d 1] +[ 7] .shstrtab STRTAB 0000000000000000 000003f4 00000060 0 0 0 1 +[ 8] .symtab SYMTAB 0000000000000000 000000f0 00000180 24 9 9 8 +[ 9] .strtab STRTAB 0000000000000000 00000270 00000044 0 0 0 1 + +EOF + +testfiles testfile-zgnu32 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgnu32 <<\EOF +There are 9 section headers, starting at offset 0x33c: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 00000000 000000 000000 0 0 0 0 +[ 1] .text PROGBITS 08048054 000054 00002a 0 AX 0 0 1 +[ 2] .zdebug_aranges PROGBITS 00000000 0001c0 000031 0 0 0 8 + [GNU ZLIB 000040 ] +[ 3] .zdebug_info PROGBITS 00000000 0001f1 00006f 0 0 0 1 + [GNU ZLIB 00009a ] +[ 4] .debug_abbrev PROGBITS 00000000 000260 000028 0 0 0 1 +[ 5] .zdebug_line PROGBITS 00000000 000288 00005a 0 0 0 1 + [GNU ZLIB 000085 ] +[ 6] .shstrtab STRTAB 00000000 0002e2 000059 0 0 0 1 +[ 7] .symtab SYMTAB 00000000 000080 0000f0 16 8 8 4 +[ 8] .strtab STRTAB 00000000 000170 00004b 0 0 0 1 + +EOF + +testfiles testfile-zgnu32be +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgnu32be <<\EOF +There are 10 section headers, starting at offset 0x390: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 00000000 000000 000000 0 0 0 0 +[ 1] .text PROGBITS 01800054 000054 000074 0 AX 0 0 1 +[ 2] .eh_frame PROGBITS 018000c8 0000c8 000000 0 A 0 0 4 +[ 3] .zdebug_aranges PROGBITS 00000000 000220 000033 0 0 0 8 + [GNU ZLIB 000040 ] +[ 4] .zdebug_info PROGBITS 00000000 000253 000058 0 0 0 1 + [GNU ZLIB 00006e ] +[ 5] .debug_abbrev PROGBITS 00000000 0002ab 000028 0 0 0 1 +[ 6] .zdebug_line PROGBITS 00000000 0002d3 000059 0 0 0 1 + [GNU ZLIB 000085 ] +[ 7] .shstrtab STRTAB 00000000 00032c 000063 0 0 0 1 +[ 8] .symtab SYMTAB 00000000 0000c8 000110 16 9 9 4 +[ 9] .strtab STRTAB 00000000 0001d8 000045 0 0 0 1 + +EOF + +testfiles testfile-zgabi32 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgabi32 <<\EOF +There are 9 section headers, starting at offset 0x338: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 00000000 000000 000000 0 0 0 0 +[ 1] .text PROGBITS 08048054 000054 00002a 0 AX 0 0 1 +[ 2] .debug_aranges PROGBITS 00000000 0001c0 000031 0 C 0 0 8 + [ELF ZLIB (1) 000040 8] +[ 3] .debug_info PROGBITS 00000000 0001f1 00006f 0 C 0 0 1 + [ELF ZLIB (1) 00009a 1] +[ 4] .debug_abbrev PROGBITS 00000000 000260 000028 0 0 0 1 +[ 5] .debug_line PROGBITS 00000000 000288 00005a 0 C 0 0 1 + [ELF ZLIB (1) 000085 1] +[ 6] .shstrtab STRTAB 00000000 0002e2 000056 0 0 0 1 +[ 7] .symtab SYMTAB 00000000 000080 0000f0 16 8 8 4 +[ 8] .strtab STRTAB 00000000 000170 00004b 0 0 0 1 + +EOF + +testfiles testfile-zgabi32be +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgabi32be <<\EOF +There are 10 section headers, starting at offset 0x38c: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 00000000 000000 000000 0 0 0 0 +[ 1] .text PROGBITS 01800054 000054 000074 0 AX 0 0 1 +[ 2] .eh_frame PROGBITS 018000c8 0000c8 000000 0 A 0 0 4 +[ 3] .debug_aranges PROGBITS 00000000 000220 000033 0 C 0 0 8 + [ELF ZLIB (1) 000040 8] +[ 4] .debug_info PROGBITS 00000000 000253 000058 0 C 0 0 1 + [ELF ZLIB (1) 00006e 1] +[ 5] .debug_abbrev PROGBITS 00000000 0002ab 000028 0 0 0 1 +[ 6] .debug_line PROGBITS 00000000 0002d3 000059 0 C 0 0 1 + [ELF ZLIB (1) 000085 1] +[ 7] .shstrtab STRTAB 00000000 00032c 000060 0 0 0 1 +[ 8] .symtab SYMTAB 00000000 0000c8 000110 16 9 9 4 +[ 9] .strtab STRTAB 00000000 0001d8 000045 0 0 0 1 + +EOF + +exit 0 diff --git a/tests/run-readelf-zdebug-rel.sh b/tests/run-readelf-zdebug-rel.sh new file mode 100755 index 00000000..88ea5bf2 --- /dev/null +++ b/tests/run-readelf-zdebug-rel.sh @@ -0,0 +1,144 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# - testfile-zdebug-rel.c +# #define UINT64_MAX 18446744073709551615UL +# +# int +# main (int argc, char **argv) +# { +# unsigned long a = UINT64_MAX - 8; +# unsigned long b = 42 + argc; +# +# if ( a + b < b ) +# argc = a + argc; +# else +# b--; +# +# return a - b; +# } +# +# gcc -Og -g -Xassembler --compress-debug-sections=none \ +# -c -o testfile-debug-rel.o testfile-zdebug-rel.c +# gcc -Og -g -Xassembler --compress-debug-sections=zlib-gnu \ +# -c -o testfile-debug-rel-g.o testfile-zdebug-rel.c +# gcc -Og -g -Xassembler --compress-debug-sections=zlib-gabi \ +# -c -o testfile-debug-rel-z.o testfile-zdebug-rel.c + +testfiles testfile-debug-rel.o testfile-debug-rel-g.o testfile-debug-rel-z.o +tempfiles readelf.out +tempfiles info.out loc.out + +cat > info.out << \EOF + +DWARF section [ 4] '.debug_info' at offset 0x58: + [Offset] + Compilation unit at offset 0: + Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + [ b] compile_unit + producer (strp) "GNU C11 5.3.1 20151207 (Red Hat 5.3.1-2) -mtune=generic -march=x86-64 -g -Og" + language (data1) C99 (12) + name (strp) "testfile-zdebug-rel.c" + comp_dir (strp) "/tmp" + low_pc (addr) 000000000000000000 + high_pc (data8) 24 (0x0000000000000018) + stmt_list (sec_offset) 0 + [ 2d] subprogram + external (flag_present) + name (strp) "main" + decl_file (data1) 1 + decl_line (data1) 4 + prototyped (flag_present) + type (ref4) [ 80] + low_pc (addr) 000000000000000000 + high_pc (data8) 24 (0x0000000000000018) + frame_base (exprloc) + [ 0] call_frame_cfa + GNU_all_call_sites (flag_present) + sibling (ref4) [ 80] + [ 4e] formal_parameter + name (strp) "argc" + decl_file (data1) 1 + decl_line (data1) 4 + type (ref4) [ 80] + location (sec_offset) location list [ 0] + [ 5d] formal_parameter + name (strp) "argv" + decl_file (data1) 1 + decl_line (data1) 4 + type (ref4) [ 87] + location (exprloc) + [ 0] reg4 + [ 6a] variable + name (string) "a" + decl_file (data1) 1 + decl_line (data1) 6 + type (ref4) [ 9a] + const_value (sdata) -9 + [ 74] variable + name (string) "b" + decl_file (data1) 1 + decl_line (data1) 7 + type (ref4) [ 9a] + location (exprloc) + [ 0] reg5 + [ 80] base_type + byte_size (data1) 4 + encoding (data1) signed (5) + name (string) "int" + [ 87] pointer_type + byte_size (data1) 8 + type (ref4) [ 8d] + [ 8d] pointer_type + byte_size (data1) 8 + type (ref4) [ 93] + [ 93] base_type + byte_size (data1) 1 + encoding (data1) signed_char (6) + name (strp) "char" + [ 9a] base_type + byte_size (data1) 8 + encoding (data1) unsigned (7) + name (strp) "long unsigned int" +EOF + +cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel.o + +cat info.out | sed -e "s/'.debug_info'/'.zdebug_info'/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-g.o + +cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-z.o + +cat > loc.out << \EOF + +DWARF section [ 7] '.debug_loc' at offset 0x185: + [ 0] 000000000000000000..0x0000000000000003 [ 0] reg5 + 0x0000000000000003..0x0000000000000010 [ 0] breg5 -42 + [ 2] stack_value + 0x0000000000000010..0x0000000000000018 [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value +EOF + +cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o + +cat loc.out | sed -e "s/'.debug_loc' at offset 0x185/'.zdebug_loc' at offset 0x138/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-g.o + +cat loc.out | sed -e "s/at offset 0x185/at offset 0x150/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-z.o + +exit 0 diff --git a/tests/run-readelf-zp.sh b/tests/run-readelf-zp.sh new file mode 100755 index 00000000..872126c5 --- /dev/null +++ b/tests/run-readelf-zp.sh @@ -0,0 +1,271 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# See run-readelf-zdebug.sh for testfile. + +testfiles testfile-zdebug +testrun_compare ${abs_top_builddir}/src/readelf -z -p.zdebug_str testfile-zdebug <<\EOF + +String section [35] '.zdebug_str' contains 2431 bytes (6433 uncompressed) at offset 0x1da3: + [ 0] UINT64_MAX 18446744073709551615UL + [ 22] __DBL_DENORM_MIN__ ((double)4.94065645841246544177e-324L) + [ 5c] __linux 1 + [ 66] __SIZEOF_SIZE_T__ 8 + [ 7a] __UINTPTR_TYPE__ long unsigned int + [ 9d] __SIZEOF_POINTER__ 8 + [ b2] __UINT8_MAX__ 255 + [ c4] __PTRDIFF_MAX__ 9223372036854775807L + [ e9] __DEC64_MANT_DIG__ 16 + [ ff] __FLT_RADIX__ 2 + [ 10f] __DEC32_MIN__ 1E-95DF + [ 125] __unix__ 1 + [ 130] testfile-zdebug.c + [ 142] __UINT_LEAST64_MAX__ 18446744073709551615UL + [ 16e] __SIZEOF_WINT_T__ 4 + [ 182] __LONG_MAX__ 9223372036854775807L + [ 1a4] __LDBL_MIN__ 3.36210314311209350626e-4932L + [ 1cf] __GCC_ATOMIC_SHORT_LOCK_FREE 2 + [ 1ee] __LP64__ 1 + [ 1f9] __UINT64_C(c) c ## UL + [ 20f] __DBL_HAS_INFINITY__ 1 + [ 226] __SSE2_MATH__ 1 + [ 236] __linux__ 1 + [ 242] __STDC_HOSTED__ 1 + [ 254] __WINT_MIN__ 0U + [ 264] __x86_64__ 1 + [ 271] __UINT32_TYPE__ unsigned int + [ 28e] __UINT_LEAST8_MAX__ 255 + [ 2a6] __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD + [ 2d7] __FLT_MAX__ 3.40282346638528859812e+38F + [ 2ff] long unsigned int + [ 311] __DBL_MANT_DIG__ 53 + [ 325] linux 1 + [ 32d] __DBL_HAS_QUIET_NAN__ 1 + [ 345] __UINT8_TYPE__ unsigned char + [ 362] __DEC32_MAX_EXP__ 97 + [ 377] __INT32_TYPE__ int + [ 38a] __SIG_ATOMIC_TYPE__ int + [ 3a2] __DEC64_MAX_EXP__ 385 + [ 3b8] __DBL_MIN_EXP__ (-1021) + [ 3d0] _LP64 1 + [ 3d8] __LDBL_HAS_INFINITY__ 1 + [ 3f0] __INT_FAST64_TYPE__ long int + [ 40d] __gnu_linux__ 1 + [ 41d] __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 + [ 43e] __UINT_FAST64_TYPE__ long unsigned int + [ 465] __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ + [ 48c] __UINT16_MAX__ 65535 + [ 4a1] __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__ + [ 4ce] __PRAGMA_REDEFINE_EXTNAME 1 + [ 4ea] __INT_LEAST16_TYPE__ short int + [ 509] __k8__ 1 + [ 512] __DECIMAL_DIG__ 21 + [ 525] main + [ 52a] __DBL_MAX__ ((double)1.79769313486231570815e+308L) + [ 55d] __INT16_TYPE__ short int + [ 576] __LDBL_HAS_QUIET_NAN__ 1 + [ 58f] __SIZEOF_DOUBLE__ 8 + [ 5a3] __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF + [ 5ca] __ATOMIC_SEQ_CST 5 + [ 5dd] __UINT64_TYPE__ long unsigned int + [ 5ff] __INT_LEAST32_TYPE__ int + [ 618] __INT_LEAST64_MAX__ 9223372036854775807L + [ 641] __OPTIMIZE__ 1 + [ 650] __INTMAX_C(c) c ## L + [ 665] __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 + [ 687] __INT_FAST8_MAX__ 127 + [ 69d] __PTRDIFF_TYPE__ long int + [ 6b7] __LDBL_MIN_EXP__ (-16381) + [ 6d1] __SIZEOF_LONG_LONG__ 8 + [ 6e8] __FLT_DIG__ 6 + [ 6f6] __UINTMAX_MAX__ 18446744073709551615UL + [ 71d] __SIZEOF_WCHAR_T__ 4 + [ 732] __INT64_C(c) c ## L + [ 746] __UINTPTR_MAX__ 18446744073709551615UL + [ 76d] __FLT_MAX_10_EXP__ 38 + [ 783] __FLT_MIN__ 1.17549435082228750797e-38F + [ 7ab] __UINT_LEAST64_TYPE__ long unsigned int + [ 7d3] __SIZEOF_LONG_DOUBLE__ 16 + [ 7ed] __SIZE_MAX__ 18446744073709551615UL + [ 811] __INT8_C(c) c + [ 81f] __amd64__ 1 + [ 82b] __INT_LEAST64_TYPE__ long int + [ 849] __INT_FAST64_MAX__ 9223372036854775807L + [ 871] __DEC_EVAL_METHOD__ 2 + [ 887] __DEC32_MAX__ 9.999999E96DF + [ 8a3] __GNUC_MINOR__ 8 + [ 8b4] __WCHAR_MAX__ 2147483647 + [ 8cd] __SIZE_TYPE__ long unsigned int + [ 8ed] __INT8_MAX__ 127 + [ 8fe] __INTMAX_MAX__ 9223372036854775807L + [ 922] __ATOMIC_HLE_RELEASE 131072 + [ 93e] __FLT_HAS_QUIET_NAN__ 1 + [ 956] __DBL_EPSILON__ ((double)2.22044604925031308085e-16L) + [ 98c] __FLT_MIN_EXP__ (-125) + [ 9a3] __INT_LEAST8_MAX__ 127 + [ 9ba] __SIZEOF_INT128__ 16 + [ 9cf] __INTPTR_MAX__ 9223372036854775807L + [ 9f3] __INTPTR_TYPE__ long int + [ a0c] __LDBL_MIN_10_EXP__ (-4931) + [ a28] __GCC_ATOMIC_POINTER_LOCK_FREE 2 + [ a49] __UINT_LEAST32_MAX__ 4294967295U + [ a6a] __SIZEOF_SHORT__ 2 + [ a7d] __LDBL_MAX_10_EXP__ 4932 + [ a96] __INT16_C(c) c + [ aa5] __MMX__ 1 + [ aaf] unix 1 + [ ab6] __FLT_MAX_EXP__ 128 + [ aca] __DEC64_MAX__ 9.999999999999999E384DD + [ af0] __FLT_EPSILON__ 1.19209289550781250000e-7F + [ b1b] __INT_FAST16_TYPE__ long int + [ b38] __VERSION__ "4.8.2 20140120 (Red Hat 4.8.2-15)" + [ b68] __GCC_ATOMIC_LLONG_LOCK_FREE 2 + [ b87] __DEC128_MIN_EXP__ (-6142) + [ ba2] __ATOMIC_RELEASE 3 + [ bb5] __GNUC_PATCHLEVEL__ 2 + [ bcb] __UINT_FAST64_MAX__ 18446744073709551615UL + [ bf6] __DBL_DECIMAL_DIG__ 17 + [ c0d] __DBL_DIG__ 15 + [ c1c] __FLT_MANT_DIG__ 24 + [ c30] __FLT_DECIMAL_DIG__ 9 + [ c46] __INT16_MAX__ 32767 + [ c5a] __DEC128_MIN__ 1E-6143DL + [ c73] __BIGGEST_ALIGNMENT__ 16 + [ c8c] __INT64_MAX__ 9223372036854775807L + [ caf] __INT_FAST32_TYPE__ long int + [ ccc] __GCC_ATOMIC_INT_LOCK_FREE 2 + [ ce9] __DEC128_MAX_EXP__ 6145 + [ d01] __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 + [ d26] __FXSR__ 1 + [ d31] __INT8_TYPE__ signed char + [ d4b] __ATOMIC_ACQ_REL 4 + [ d5e] __UINT_LEAST16_MAX__ 65535 + [ d79] __UINTMAX_TYPE__ long unsigned int + [ d9c] __UINT_FAST8_MAX__ 255 + [ db3] __ORDER_BIG_ENDIAN__ 4321 + [ dcd] __INT_LEAST32_MAX__ 2147483647 + [ dec] __UINT_LEAST16_TYPE__ short unsigned int + [ e15] __INT_FAST8_TYPE__ signed char + [ e34] __DBL_MAX_EXP__ 1024 + [ e49] __STDC__ 1 + [ e54] __ELF__ 1 + [ e5e] __FLT_EVAL_METHOD__ 0 + [ e74] __ATOMIC_ACQUIRE 2 + [ e87] __DEC64_EPSILON__ 1E-15DD + [ ea1] __INT32_MAX__ 2147483647 + [ eba] __GCC_ATOMIC_CHAR_LOCK_FREE 2 + [ ed8] __DEC128_EPSILON__ 1E-33DL + [ ef3] __UINT_FAST8_TYPE__ unsigned char + [ f15] __amd64 1 + [ f1f] __DEC32_MIN_EXP__ (-94) + [ f37] __GCC_HAVE_DWARF2_CFI_ASM 1 + [ f53] __LDBL_DIG__ 18 + [ f63] __UINT32_MAX__ 4294967295U + [ f7e] __GNUC_GNU_INLINE__ 1 + [ f94] __SSE2__ 1 + [ f9f] __ATOMIC_HLE_ACQUIRE 65536 + [ fba] __SSE_MATH__ 1 + [ fc9] __INT_FAST16_MAX__ 9223372036854775807L + [ ff1] __LDBL_MAX__ 1.18973149535723176502e+4932L + [ 101c] __DBL_MIN__ ((double)2.22507385850720138309e-308L) + [ 104f] __DEC128_MANT_DIG__ 34 + [ 1066] __INT32_C(c) c + [ 1075] __DEC64_MIN_EXP__ (-382) + [ 108e] __WCHAR_MIN__ (-__WCHAR_MAX__ - 1) + [ 10b1] __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 + [ 10d3] __LDBL_MAX_EXP__ 16384 + [ 10ea] __DEC32_MANT_DIG__ 7 + [ 10ff] __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL + [ 1139] __CHAR32_TYPE__ unsigned int + [ 1156] __INT_LEAST8_TYPE__ signed char + [ 1176] __UINT16_C(c) c + [ 1186] __GCC_ATOMIC_BOOL_LOCK_FREE 2 + [ 11a4] __SIZEOF_FLOAT__ 4 + [ 11b7] __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 + [ 11dc] __DBL_MAX_10_EXP__ 308 + [ 11f3] __LDBL_EPSILON__ 1.08420217248550443401e-19L + [ 1220] __ORDER_PDP_ENDIAN__ 3412 + [ 123a] __ORDER_LITTLE_ENDIAN__ 1234 + [ 1257] __WINT_TYPE__ unsigned int + [ 1272] __unix 1 + [ 127b] __ATOMIC_RELAXED 0 + [ 128e] __UINT_FAST32_MAX__ 18446744073709551615UL + [ 12b9] __INT_FAST32_MAX__ 9223372036854775807L + [ 12e1] __SIG_ATOMIC_MAX__ 2147483647 + [ 12ff] __UINT_FAST32_TYPE__ long unsigned int + [ 1326] __INT_MAX__ 2147483647 + [ 133d] __GXX_ABI_VERSION 1002 + [ 1354] __SIZEOF_INT__ 4 + [ 1365] char + [ 136a] __UINT_FAST16_TYPE__ long unsigned int + [ 1391] __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L + [ 13c3] __WINT_MAX__ 4294967295U + [ 13dc] __FLT_HAS_INFINITY__ 1 + [ 13f3] __SHRT_MAX__ 32767 + [ 1406] __INT_LEAST16_MAX__ 32767 + [ 1420] __LONG_LONG_MAX__ 9223372036854775807LL + [ 1448] __SIZEOF_LONG__ 8 + [ 145a] __INTMAX_TYPE__ long int + [ 1473] __LDBL_HAS_DENORM__ 1 + [ 1489] __code_model_small__ 1 + [ 14a0] __REGISTER_PREFIX__ + [ 14b5] __ATOMIC_CONSUME 1 + [ 14c8] __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL + [ 150d] __GNUC__ 4 + [ 1518] __UINT16_TYPE__ short unsigned int + [ 153b] __SSE__ 1 + [ 1545] __UINT32_C(c) c ## U + [ 155a] __k8 1 + [ 1561] __UINTMAX_C(c) c ## UL + [ 1578] __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 + [ 159d] __SIZEOF_PTRDIFF_T__ 8 + [ 15b4] __CHAR_BIT__ 8 + [ 15c3] __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1) + [ 15f0] __DEC32_EPSILON__ 1E-6DF + [ 1609] __UINT_LEAST32_TYPE__ unsigned int + [ 162c] __DBL_HAS_DENORM__ 1 + [ 1641] /tmp + [ 1646] __LDBL_MANT_DIG__ 64 + [ 165b] __GCC_ATOMIC_LONG_LOCK_FREE 2 + [ 1679] __DECIMAL_BID_FORMAT__ 1 + [ 1692] __FLT_MIN_10_EXP__ (-37) + [ 16ab] __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 + [ 16cf] __WCHAR_TYPE__ int + [ 16e2] __FINITE_MATH_ONLY__ 0 + [ 16f9] argc + [ 16fe] __USER_LABEL_PREFIX__ + [ 1715] __CHAR16_TYPE__ short unsigned int + [ 1738] __UINT64_MAX__ 18446744073709551615UL + [ 175e] __UINT8_C(c) c + [ 176d] __x86_64 1 + [ 1778] __UINT_LEAST8_TYPE__ unsigned char + [ 179b] __INT64_TYPE__ long int + [ 17b3] __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 + [ 17d8] argv + [ 17dd] __GNUC_RH_RELEASE__ 15 + [ 17f4] __UINT_FAST16_MAX__ 18446744073709551615UL + [ 181f] __FLT_HAS_DENORM__ 1 + [ 1834] __DEC64_MIN__ 1E-383DD + [ 184b] __DBL_MIN_10_EXP__ (-307) + [ 1865] __FLT_DENORM_MIN__ 1.40129846432481707092e-45F + [ 1894] GNU C 4.8.2 20140120 (Red Hat 4.8.2-15) -mtune=generic -march=x86-64 -g3 -O3 -fuse-ld=gold -fno-asynchronous-unwind-tables + [ 190f] __SCHAR_MAX__ 127 +EOF + +exit 0 diff --git a/tests/run-readelf-zx.sh b/tests/run-readelf-zx.sh new file mode 100755 index 00000000..994528c0 --- /dev/null +++ b/tests/run-readelf-zx.sh @@ -0,0 +1,66 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# See run-elfgetchdr.sh for testfiles. + +testfiles testfile-zgnu64 +testrun_compare ${abs_top_builddir}/src/readelf -z -x.zdebug_aranges testfile-zgnu64 <<\EOF + +Hex dump of section [2] '.zdebug_aranges', 50 bytes (96 uncompressed) at offset 0x260: + 0x00000000 2c000000 02000000 00000800 00000000 ,............... + 0x00000010 78004000 00000000 14000000 00000000 x.@............. + 0x00000020 00000000 00000000 00000000 00000000 ................ + 0x00000030 2c000000 02005500 00000800 00000000 ,.....U......... + 0x00000040 8c004000 00000000 16000000 00000000 ..@............. + 0x00000050 00000000 00000000 00000000 00000000 ................ +EOF + +testfiles testfile-zgabi64 +testrun_compare ${abs_top_builddir}/src/readelf -z -x.debug_aranges testfile-zgabi64 <<\EOF + +Hex dump of section [2] '.debug_aranges', 62 bytes (96 uncompressed) at offset 0x260: + 0x00000000 2c000000 02000000 00000800 00000000 ,............... + 0x00000010 78004000 00000000 14000000 00000000 x.@............. + 0x00000020 00000000 00000000 00000000 00000000 ................ + 0x00000030 2c000000 02005500 00000800 00000000 ,.....U......... + 0x00000040 8c004000 00000000 16000000 00000000 ..@............. + 0x00000050 00000000 00000000 00000000 00000000 ................ +EOF + +testfiles testfile-zgnu32 +testrun_compare ${abs_top_builddir}/src/readelf -z -x.zdebug_aranges testfile-zgnu32 <<\EOF + +Hex dump of section [2] '.zdebug_aranges', 49 bytes (64 uncompressed) at offset 0x1c0: + 0x00000000 1c000000 02000000 00000400 00000000 ................ + 0x00000010 54800408 14000000 00000000 00000000 T............... + 0x00000020 1c000000 02004d00 00000400 00000000 ......M......... + 0x00000030 68800408 16000000 00000000 00000000 h............... +EOF + +testfiles testfile-zgabi32 +testrun_compare ${abs_top_builddir}/src/readelf -z -x.debug_aranges testfile-zgabi32 <<\EOF + +Hex dump of section [2] '.debug_aranges', 49 bytes (64 uncompressed) at offset 0x1c0: + 0x00000000 1c000000 02000000 00000400 00000000 ................ + 0x00000010 54800408 14000000 00000000 00000000 T............... + 0x00000020 1c000000 02004d00 00000400 00000000 ......M......... + 0x00000030 68800408 16000000 00000000 00000000 h............... +EOF + +exit 0 diff --git a/tests/run-zstrptr.sh b/tests/run-zstrptr.sh new file mode 100755 index 00000000..254dcd85 --- /dev/null +++ b/tests/run-zstrptr.sh @@ -0,0 +1,167 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# A random 32bit and 64bit testfile +testfiles testfile testfile10 + +testrun_compare ${abs_top_builddir}/tests/zstrptr testfile <<\EOF +Strings in section 32 (compressed): +[0] '' +[1] '.symtab' +[9] '.strtab' +[11] '.shstrtab' +[1b] '.interp' +[23] '.note.ABI-tag' +[31] '.hash' +[37] '.dynsym' +[3f] '.dynstr' +[47] '.gnu.version' +[54] '.gnu.version_r' +[63] '.rel.got' +[6c] '.rel.plt' +[75] '.init' +[7b] '.plt' +[80] '.text' +[86] '.fini' +[8c] '.rodata' +[94] '.data' +[9a] '.eh_frame' +[a4] '.ctors' +[ab] '.dtors' +[b2] '.got' +[b7] '.dynamic' +[c0] '.sbss' +[c6] '.bss' +[cb] '.stab' +[d1] '.stabstr' +[da] '.comment' +[e3] '.debug_aranges' +[f2] '.debug_pubnames' +[102] '.debug_info' +[10e] '.debug_abbrev' +[11c] '.debug_line' +[128] '.note' +Strings in section 32 (uncompressed): +[0] '' +[1] '.symtab' +[9] '.strtab' +[11] '.shstrtab' +[1b] '.interp' +[23] '.note.ABI-tag' +[31] '.hash' +[37] '.dynsym' +[3f] '.dynstr' +[47] '.gnu.version' +[54] '.gnu.version_r' +[63] '.rel.got' +[6c] '.rel.plt' +[75] '.init' +[7b] '.plt' +[80] '.text' +[86] '.fini' +[8c] '.rodata' +[94] '.data' +[9a] '.eh_frame' +[a4] '.ctors' +[ab] '.dtors' +[b2] '.got' +[b7] '.dynamic' +[c0] '.sbss' +[c6] '.bss' +[cb] '.stab' +[d1] '.stabstr' +[da] '.comment' +[e3] '.debug_aranges' +[f2] '.debug_pubnames' +[102] '.debug_info' +[10e] '.debug_abbrev' +[11c] '.debug_line' +[128] '.note' +EOF + +testrun_compare ${abs_top_builddir}/tests/zstrptr testfile10 <<\EOF +Strings in section 30 (compressed): +[0] '' +[1] '.symtab' +[9] '.strtab' +[11] '.shstrtab' +[1b] '.hash' +[21] '.dynsym' +[29] '.dynstr' +[31] '.gnu.version' +[3e] '.gnu.version_r' +[4d] '.rela.dyn' +[57] '.init' +[5d] '.text' +[63] '.fini' +[69] '.eh_frame' +[73] '.data' +[79] '.dynamic' +[82] '.ctors' +[89] '.dtors' +[90] '.jcr' +[95] '.plt' +[9a] '.got' +[9f] '.sdata' +[a6] '.sbss' +[ac] '.bss' +[b1] '.comment' +[ba] '.debug_aranges' +[c9] '.debug_pubnames' +[d9] '.debug_abbrev' +[e7] '.debug_line' +[f3] '.debug_frame' +[100] '.debug_str' +[10b] '.rela.debug_info' +Strings in section 30 (uncompressed): +[0] '' +[1] '.symtab' +[9] '.strtab' +[11] '.shstrtab' +[1b] '.hash' +[21] '.dynsym' +[29] '.dynstr' +[31] '.gnu.version' +[3e] '.gnu.version_r' +[4d] '.rela.dyn' +[57] '.init' +[5d] '.text' +[63] '.fini' +[69] '.eh_frame' +[73] '.data' +[79] '.dynamic' +[82] '.ctors' +[89] '.dtors' +[90] '.jcr' +[95] '.plt' +[9a] '.got' +[9f] '.sdata' +[a6] '.sbss' +[ac] '.bss' +[b1] '.comment' +[ba] '.debug_aranges' +[c9] '.debug_pubnames' +[d9] '.debug_abbrev' +[e7] '.debug_line' +[f3] '.debug_frame' +[100] '.debug_str' +[10b] '.rela.debug_info' +EOF + +exit 0 diff --git a/tests/system-elf-libelf-test.c b/tests/system-elf-libelf-test.c new file mode 100644 index 00000000..7dfe4989 --- /dev/null +++ b/tests/system-elf-libelf-test.c @@ -0,0 +1,35 @@ +/* Explicit test compiling with system elf.h header plus libelf header. + + Copyright (C) 2016 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 <elf.h> +#include <stddef.h> +#include "../libelf/libelf.h" + +int +main (void) +{ + /* Trivial test, this is really a compile test anyway. */ + if (elf_version (EV_CURRENT) == EV_NONE) + return -1; + + /* This will obviously fail. It is just to check that Elf32_Chdr and + elf32_getchdr are available (both at compile time and runtime). */ + Elf32_Chdr *chdr = elf32_getchdr (NULL); + + return chdr == NULL ? 0 : -1; +} diff --git a/tests/testfile-debug-rel-g.o.bz2 b/tests/testfile-debug-rel-g.o.bz2 Binary files differnew file mode 100644 index 00000000..b8c94e7e --- /dev/null +++ b/tests/testfile-debug-rel-g.o.bz2 diff --git a/tests/testfile-debug-rel-z.o.bz2 b/tests/testfile-debug-rel-z.o.bz2 Binary files differnew file mode 100644 index 00000000..1cdac790 --- /dev/null +++ b/tests/testfile-debug-rel-z.o.bz2 diff --git a/tests/testfile-debug-rel.o.bz2 b/tests/testfile-debug-rel.o.bz2 Binary files differnew file mode 100644 index 00000000..a3f8dffa --- /dev/null +++ b/tests/testfile-debug-rel.o.bz2 diff --git a/tests/testfile-zgabi32.bz2 b/tests/testfile-zgabi32.bz2 Binary files differnew file mode 100755 index 00000000..6159dbce --- /dev/null +++ b/tests/testfile-zgabi32.bz2 diff --git a/tests/testfile-zgabi32be.bz2 b/tests/testfile-zgabi32be.bz2 Binary files differnew file mode 100755 index 00000000..f1f5eb5c --- /dev/null +++ b/tests/testfile-zgabi32be.bz2 diff --git a/tests/testfile-zgabi64.bz2 b/tests/testfile-zgabi64.bz2 Binary files differnew file mode 100755 index 00000000..3b44f089 --- /dev/null +++ b/tests/testfile-zgabi64.bz2 diff --git a/tests/testfile-zgabi64be.bz2 b/tests/testfile-zgabi64be.bz2 Binary files differnew file mode 100755 index 00000000..d819ae3d --- /dev/null +++ b/tests/testfile-zgabi64be.bz2 diff --git a/tests/testfile-zgnu32.bz2 b/tests/testfile-zgnu32.bz2 Binary files differnew file mode 100755 index 00000000..9d622cad --- /dev/null +++ b/tests/testfile-zgnu32.bz2 diff --git a/tests/testfile-zgnu32be.bz2 b/tests/testfile-zgnu32be.bz2 Binary files differnew file mode 100755 index 00000000..c1dd589e --- /dev/null +++ b/tests/testfile-zgnu32be.bz2 diff --git a/tests/testfile-zgnu64.bz2 b/tests/testfile-zgnu64.bz2 Binary files differnew file mode 100755 index 00000000..1bc2c090 --- /dev/null +++ b/tests/testfile-zgnu64.bz2 diff --git a/tests/testfile-zgnu64be.bz2 b/tests/testfile-zgnu64be.bz2 Binary files differnew file mode 100755 index 00000000..390c9c90 --- /dev/null +++ b/tests/testfile-zgnu64be.bz2 diff --git a/tests/zstrptr.c b/tests/zstrptr.c new file mode 100644 index 00000000..6d8e19f7 --- /dev/null +++ b/tests/zstrptr.c @@ -0,0 +1,124 @@ +/* Test program for elf_strptr function. + Copyright (C) 2015 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include ELFUTILS_HEADER(elf) +#include <gelf.h> + +int +main (int argc, char *argv[]) +{ + if (argc != 2) + { + printf ("No ELF file given as argument"); + exit (1); + } + + const char *fname = argv[1]; + + // Initialize libelf. + elf_version (EV_CURRENT); + + /* Read the ELF from disk now. */ + int fd = open (fname, O_RDONLY); + if (fd == -1) + { + printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno)); + exit (1); + } + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + { + printf ("cannot create ELF descriptor read-only: %s\n", elf_errmsg (-1)); + exit (1); + } + + size_t ndx; + if (elf_getshdrstrndx (elf, &ndx) != 0) + { + printf ("cannot get section header table index: %s\n", elf_errmsg (-1)); + exit (1); + } + + if (ndx == SHN_UNDEF) + { + printf ("ELF file `%s' doesn't have a section header table index", fname); + exit (1); + } + + Elf_Scn *scn = elf_getscn (elf, ndx); + if (scn == NULL) + { + printf ("Couldn't get section %zd: %s\n", ndx, elf_errmsg (-1)); + exit (1); + } + + void print_strings (void) + { + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); + + printf ("Strings in section %zd (%s):\n", ndx, + ((shdr->sh_flags & SHF_COMPRESSED) != 0 + ? "compressed" : "uncompressed")); + + size_t off = 0; + const char *str = elf_strptr (elf, ndx, off); + while (str != NULL) + { + printf ("[%zx] '%s'\n", off, str); + off += strlen (str) + 1; + str = elf_strptr (elf, ndx, off); + } + } + + if (elf_compress (scn, ELFCOMPRESS_ZLIB, 0) < 0) + { + printf ("Couldn't compress section %zd: %s\n", ndx, elf_errmsg (-1)); + exit (1); + } + print_strings (); + + if (elf_compress (scn, 0, 0) < 0) + { + printf ("Couldn't decompress section %zd: %s\n", ndx, elf_errmsg (-1)); + exit (1); + } + print_strings (); + + if (elf_end (elf) != 0) + { + printf ("failure in elf_end: %s\n", elf_errmsg (-1)); + exit (1); + } + + close (fd); + + return 0; +} |