summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog17
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/elfgetchdr.c124
-rw-r--r--tests/msg_tst.c5
-rwxr-xr-xtests/run-elfgetchdr.sh188
-rwxr-xr-xtests/testfile-zgabi32.bz2bin0 -> 767 bytes
-rwxr-xr-xtests/testfile-zgabi32be.bz2bin0 -> 769 bytes
-rwxr-xr-xtests/testfile-zgabi64.bz2bin0 -> 795 bytes
-rwxr-xr-xtests/testfile-zgabi64be.bz2bin0 -> 780 bytes
9 files changed, 341 insertions, 4 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 5afe4bd2..7096f9f9 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,22 @@
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.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8e2f2833..2528e1c0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,7 +52,7 @@ 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 dwelfgnucompressed
+ elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -120,7 +120,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
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 run-dwelfgnucompressed.sh
+ elfshphehdr run-lfs-symbols.sh run-dwelfgnucompressed.sh \
+ run-elfgetchdr.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
@@ -309,7 +310,10 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-lfs-symbols.sh lfs-symbols testfile-nolfs.bz2 \
testfile-zgnu32.bz2 testfile-zgnu64.bz2 \
testfile-zgnu32be.bz2 testfile-zgnu64be.bz2 \
- run-dwelfgnucompressed.sh
+ run-dwelfgnucompressed.sh \
+ testfile-zgabi32.bz2 testfile-zgabi64.bz2 \
+ testfile-zgabi32be.bz2 testfile-zgabi64be.bz2 \
+ run-elfgetchdr.sh
if USE_VALGRIND
valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
@@ -459,6 +463,7 @@ dwfl_proc_attach_LDFLAGS = -pthread $(AM_LDFLAGS)
elfshphehdr_LDADD =$(libelf)
elfstrmerge_LDADD = $(libebl) $(libelf)
dwelfgnucompressed_LDADD = $(libelf) $(libdw)
+elfgetchdr_LDADD = $(libelf) $(libdw)
if GCOV
check: check-am coverage
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/msg_tst.c b/tests/msg_tst.c
index 10ff0f73..539c5ddb 100644
--- a/tests/msg_tst.c
+++ b/tests/msg_tst.c
@@ -74,7 +74,10 @@ 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" }
};
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/testfile-zgabi32.bz2 b/tests/testfile-zgabi32.bz2
new file mode 100755
index 00000000..6159dbce
--- /dev/null
+++ b/tests/testfile-zgabi32.bz2
Binary files differ
diff --git a/tests/testfile-zgabi32be.bz2 b/tests/testfile-zgabi32be.bz2
new file mode 100755
index 00000000..f1f5eb5c
--- /dev/null
+++ b/tests/testfile-zgabi32be.bz2
Binary files differ
diff --git a/tests/testfile-zgabi64.bz2 b/tests/testfile-zgabi64.bz2
new file mode 100755
index 00000000..3b44f089
--- /dev/null
+++ b/tests/testfile-zgabi64.bz2
Binary files differ
diff --git a/tests/testfile-zgabi64be.bz2 b/tests/testfile-zgabi64be.bz2
new file mode 100755
index 00000000..d819ae3d
--- /dev/null
+++ b/tests/testfile-zgabi64be.bz2
Binary files differ