summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog113
-rw-r--r--tests/Makefile.am18
-rw-r--r--tests/addrscopes.c2
-rw-r--r--tests/addsections.c286
-rw-r--r--tests/allregs.c2
-rw-r--r--tests/backtrace-data.c2
-rw-r--r--tests/backtrace-dwarf.c3
-rw-r--r--tests/backtrace.c2
-rw-r--r--tests/buildid.c2
-rw-r--r--tests/debugaltlink.c2
-rw-r--r--tests/debuglink.c2
-rw-r--r--tests/deleted.c1
-rw-r--r--tests/dwarfcfi.c2
-rw-r--r--tests/dwfl-addr-sect.c2
-rw-r--r--tests/dwfl-bug-addr-overflow.c1
-rw-r--r--tests/dwfl-bug-fd-leak.c2
-rw-r--r--tests/dwfl-bug-getmodules.c2
-rw-r--r--tests/dwfl-proc-attach.c2
-rw-r--r--tests/dwfl-report-elf-align.c2
-rw-r--r--tests/dwfllines.c2
-rw-r--r--tests/dwflmodtest.c2
-rw-r--r--tests/dwflsyms.c1
-rw-r--r--tests/early-offscn.c2
-rw-r--r--tests/ecp.c2
-rw-r--r--tests/elfcopy.c286
-rw-r--r--tests/elfstrmerge.c1
-rw-r--r--tests/find-prologues.c2
-rw-r--r--tests/funcretval.c2
-rw-r--r--tests/funcscopes.c2
-rw-r--r--tests/getsrc_die.c2
-rw-r--r--tests/hello_riscv64.ko.bz2bin1166 -> 39548 bytes
-rw-r--r--tests/line2addr.c2
-rw-r--r--tests/low_high_pc.c1
-rw-r--r--tests/next_cfi.c29
-rw-r--r--tests/rdwrmmap.c2
-rwxr-xr-xtests/run-annobingroup.sh123
-rwxr-xr-xtests/run-copyadd-sections.sh87
-rwxr-xr-xtests/run-copymany-sections.sh99
-rwxr-xr-xtests/run-strip-reloc.sh6
-rwxr-xr-xtests/run-strip-test-many.sh66
-rwxr-xr-xtests/run-strip-test12.sh4
-rwxr-xr-xtests/run-typeiter-many.sh31
-rw-r--r--tests/saridx.c2
-rw-r--r--tests/sectiondump.c2
-rw-r--r--tests/testfile-annobingroup-i386.o.bz2bin0 -> 1387 bytes
-rw-r--r--tests/testfile-annobingroup.o.bz2bin0 -> 1266 bytes
-rw-r--r--tests/testfile-riscv64-core.bz2bin0 -> 16229 bytes
-rwxr-xr-xtests/testfile-riscv64-s.bz2bin0 -> 1657 bytes
-rwxr-xr-xtests/testfile-riscv64.bz2bin0 -> 6006 bytes
-rw-r--r--tests/varlocs.c2
-rw-r--r--tests/vdsosyms.c2
51 files changed, 1168 insertions, 42 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 765a874b..4e8b8144 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,116 @@
+2018-09-13 Mark Wielaard <[email protected]>
+
+ * run-strip-test-many.sh: New test.
+ * Makefile.am (TESTS): Add run-strip-test-many.sh.
+ (EXTRA_DIST): Likewise.
+
+2018-09-13 Mark Wielaard <[email protected]>
+
+ * run-typeiter-many.sh: New test.
+ * Makefile.am (TESTS): Add run-typeiter-many.sh.
+ (EXTRA_DIST): Likewise.
+
+2018-09-13 Mark Wielaard <[email protected]>
+
+ * run-copymany-sections.sh: New test.
+ * Makefile.am (TESTS): Add run-copymany-sections.sh.
+ (EXTRA_DIST): Likewise.
+
+2018-09-12 Mark Wielaard <[email protected]>
+
+ * Makefile.am (check_PROGRAMS): Add elfcopy and addsections.
+ (TESTS): Add run-copyadd-sections.sh.
+ (EXTRA_DIST): Likewise.
+ (elfcopy_LDADD): New variable.
+ (addsections_LDADD): Likewise.
+ * addsections.c: New file.
+ * elfcopy.c: Likewise.
+ * run-copyadd-sections.sh: New test.
+
+2018-09-11 Mark Wielaard <[email protected]>
+
+ * backtrace-dwarf.c (main): Add section attribute.
+
+2018-07-24 Mark Wielaard <[email protected]>
+
+ * run-annobingroup.sh: Add testfile-annobingroup-i386.o tests.
+ * testfile-annobingroup-i386.o.bz2: New test file.
+ * Makefile.am (EXTRA_DIST): Add testfile-annobingroup-i386.o.bz2.
+
+2018-07-21 Mark Wielaard <[email protected]>
+
+ * run-annobingroup.sh: New test.
+ * testfile-annobingroup.o.bz2: New test file.
+ * Makefile.am (TESTS): Add run-annobingroup.sh.
+ (EXTRA_DIST): Add run-annobingroup.sh and
+ testfile-annobingroup.o.bz2.
+
+2018-07-19 Andreas Schwab <[email protected]>
+
+ * Makefile.am (TESTS): Add run-strip-test12.sh.
+ (EXTRA_DIST): Add run-strip-test12.sh, testfile-riscv64.bz2,
+ testfile-riscv64-s.bz2, testfile-riscv64-core.bz2.
+ (run-strip-test11.sh): New file.
+ (testfile-riscv64.bz2): New file.
+ (testfile-riscv64-s.bz2): New file.
+ (testfile-riscv64-core.bz2): New file.
+ * run-allregs.sh: Add test for testfile-riscv64-core.
+ * run-readelf-mixed-corenote.sh: Likewise.
+
+2018-07-16 Ulf Hermann <[email protected]>
+
+ * run-strip-reloc.sh: Remove previous testfiles before running the
+ next test.
+
+2018-07-17 Mark Wielaard <[email protected]>
+
+ * hello_riscv64.ko.bz2: Updated with debuginfo.
+ * run-strip-reloc.sh: Add documentation on CONFIG_DEBUG_INFO=y.
+
+2018-07-05 Mark Wielaard <[email protected]>
+
+ * next_cfi.c (handle_section): Take a new argument name. Check
+ whether the section is compressed and uncompress if so.
+ (main): Check also for .zdebug_frame and pass the name of the
+ section to handle_section.
+
+2018-07-04 Ross Burton <[email protected]>
+
+ * addrscopes.c: Remove error.h include, add system.h include.
+ * allregs.c: Likewise.
+ * backtrace-data.c: Likewise.
+ * backtrace-dwarf.c: Likewise.
+ * backtrace.c: Likewise.
+ * buildid.c: Likewise.
+ * debugaltlink.c: Likewise.
+ * debuglink.c: Likewise.
+ * deleted.c : Likewise.
+ * dwarfcfi.c: Likewise.
+ * dwfl-addr-sect.c: Likewise.
+ * dwfl-bug-addr-overflow.c: Likewise.
+ * dwfl-bug-fd-leak.c: Likewise.
+ * dwfl-bug-getmodules.c: Likewise.
+ * dwfl-proc-attach.c: Likewise.
+ * dwfl-report-elf-align.c: Likewise.
+ * dwfllines.c: Likewise.
+ * dwflmodtest.c: Likewise.
+ * dwflsyms.c: Likewise.
+ * early-offscn.c: Likewise
+ * ecp.c: Likewise.
+ * elfstrmerge.c: Likewise.
+ * find-prologues.c: Likewise.
+ * funcretval.c: Likewise.
+ * funcscopes.c: Likewise.
+ * getsrc_die.c: Likewise.
+ * line2addr.c: Likewise.
+ * low_high_pc.c: Likewise.
+ * next_cfi.c: Likewise.
+ * rdwrmmap.c: Likewise.
+ * saridx.c: Likewise.
+ * sectiondump.c: Likewise.
+ * varlocs.c: Likewise.
+ * vdsosyms.c: Likewise.
+
2018-06-28 Mark Wielaard <[email protected]>
* next_cfi.c: New file.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e89163d5..b060587b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -59,7 +59,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
elfgetzdata elfputzdata zstrptr emptyfile vendorelf \
fillfile dwarf_default_lower_bound dwarf-die-addr-die \
get-units-invalid get-units-split attr-integrate-skel \
- all-dwarf-ranges unit-info next_cfi
+ all-dwarf-ranges unit-info next_cfi \
+ elfcopy addsections
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -152,7 +153,9 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
run-attr-integrate-skel.sh \
run-all-dwarf-ranges.sh run-unit-info.sh \
run-reloc-bpf.sh \
- run-next-cfi.sh run-next-cfi-self.sh
+ run-next-cfi.sh run-next-cfi-self.sh \
+ run-copyadd-sections.sh run-copymany-sections.sh \
+ run-typeiter-many.sh run-strip-test-many.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
@@ -191,7 +194,10 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \
run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \
run-strip-test9.sh run-strip-test10.sh run-strip-test11.sh \
+ run-strip-test12.sh \
run-strip-nothing.sh run-strip-remove-keep.sh run-strip-g.sh \
+ run-annobingroup.sh testfile-annobingroup.o.bz2 \
+ testfile-annobingroup-i386.o.bz2 \
run-strip-strmerge.sh run-strip-nobitsalign.sh \
testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \
run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \
@@ -397,7 +403,11 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
run-attr-integrate-skel.sh \
run-all-dwarf-ranges.sh testfilesplitranges4.debug.bz2 \
testfile-ranges-hello.dwo.bz2 testfile-ranges-world.dwo.bz2 \
- run-unit-info.sh run-next-cfi.sh run-next-cfi-self.sh
+ run-unit-info.sh run-next-cfi.sh run-next-cfi-self.sh \
+ testfile-riscv64.bz2 testfile-riscv64-s.bz2 \
+ testfile-riscv64-core.bz2 \
+ run-copyadd-sections.sh run-copymany-sections.sh \
+ run-typeiter-many.sh run-strip-test-many.sh
if USE_VALGRIND
valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
@@ -567,6 +577,8 @@ attr_integrate_skel_LDADD = $(libdw)
all_dwarf_ranges_LDADD = $(libdw)
unit_info_LDADD = $(libdw)
next_cfi_LDADD = $(libelf) $(libdw)
+elfcopy_LDADD = $(libelf)
+addsections_LDADD = $(libelf)
# We want to test the libelf header against the system elf.h header.
# Don't include any -I CPPFLAGS.
diff --git a/tests/addrscopes.c b/tests/addrscopes.c
index 791569f5..b231b6a9 100644
--- a/tests/addrscopes.c
+++ b/tests/addrscopes.c
@@ -25,8 +25,8 @@
#include <stdio_ext.h>
#include <locale.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
+#include "system.h"
static void
diff --git a/tests/addsections.c b/tests/addsections.c
new file mode 100644
index 00000000..391c5b47
--- /dev/null
+++ b/tests/addsections.c
@@ -0,0 +1,286 @@
+/* Test program for adding (more than SHN_LORESERVE) sections.
+ Copyright (C) 2018 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include ELFUTILS_HEADER(elf)
+#include <gelf.h>
+
+
+/* shstrndx is special, might overflow into section zero header sh_link. */
+static int
+setshstrndx (Elf *elf, size_t ndx)
+{
+ printf ("setshstrndx: %zd\n", ndx);
+
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ return -1;
+
+ if (ndx < SHN_LORESERVE)
+ ehdr->e_shstrndx = ndx;
+ else
+ {
+ ehdr->e_shstrndx = SHN_XINDEX;
+ Elf_Scn *zscn = elf_getscn (elf, 0);
+ GElf_Shdr zshdr_mem;
+ GElf_Shdr *zshdr = gelf_getshdr (zscn, &zshdr_mem);
+ if (zshdr == NULL)
+ return -1;
+ zshdr->sh_link = ndx;
+ if (gelf_update_shdr (zscn, zshdr) == 0)
+ return -1;
+ }
+
+ if (gelf_update_ehdr (elf, ehdr) == 0)
+ return -1;
+
+ return 0;
+}
+
+/* Will add nr new '.extra' sections and a new '.new_shstrtab' section
+ at the end. */
+static void
+add_sections (const char *name, size_t nr, int use_mmap)
+{
+ printf ("add_sections '%s': %zd\n", name, nr);
+
+ int fd = open (name, O_RDWR);
+ if (fd < 0)
+ {
+ fprintf (stderr, "Couldn't open file '%s': %s\n",
+ name, strerror (errno));
+ exit (1);
+ }
+
+ Elf *elf = elf_begin (fd, use_mmap ? ELF_C_RDWR_MMAP : ELF_C_RDWR, NULL);
+ if (elf == NULL)
+ {
+ fprintf (stderr, "Couldn't open ELF file '%s': %s\n",
+ name, elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* We will add a new shstrtab section with two new names at the end.
+ Just get the current shstrtab table and add two entries '.extra'
+ and '.new_shstrtab' at the end of the table, so all existing indexes
+ are still valid. */
+ size_t shstrndx;
+ if (elf_getshdrstrndx (elf, &shstrndx) < 0)
+ {
+ printf ("cannot get shstrndx: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ Elf_Scn *shstrtab_scn = elf_getscn (elf, shstrndx);
+ if (shstrtab_scn == NULL)
+ {
+ printf ("couldn't get shstrtab scn: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ Elf_Data *shstrtab_data = elf_getdata (shstrtab_scn, NULL);
+ if (shstrtab_data == NULL)
+ {
+ printf ("couldn't get shstrtab data: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ size_t new_shstrtab_size = (shstrtab_data->d_size
+ + strlen (".extra") + 1
+ + strlen (".new_shstrtab") + 1);
+ void *new_shstrtab_buf = malloc (new_shstrtab_size);
+ if (new_shstrtab_buf == NULL)
+ {
+ printf ("couldn't allocate new shstrtab data d_buf\n");
+ exit (1);
+ }
+ memcpy (new_shstrtab_buf, shstrtab_data->d_buf, shstrtab_data->d_size);
+ size_t extra_idx = shstrtab_data->d_size;
+ size_t new_shstrtab_idx = extra_idx + strlen (".extra") + 1;
+ strcpy (new_shstrtab_buf + extra_idx, ".extra");
+ strcpy (new_shstrtab_buf + new_shstrtab_idx, ".new_shstrtab");
+
+ // Add lots of .extra sections...
+ size_t cnt = 0;
+ while (cnt++ < nr)
+ {
+ Elf_Scn *scn = elf_newscn (elf);
+ if (scn == NULL)
+ {
+ printf ("cannot create .extra section (%zd): %s\n", cnt,
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ Elf_Data *data = elf_newdata (scn);
+ if (data == NULL)
+ {
+ printf ("couldn't create new section data (%zd): %s\n", cnt,
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ data->d_size = strlen ("extra") + 1;
+ data->d_buf = "extra";
+ data->d_type = ELF_T_BYTE;
+ data->d_align = 1;
+
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for new section (%zd): %s\n", cnt,
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ shdr->sh_type = SHT_PROGBITS;
+ shdr->sh_flags = 0;
+ shdr->sh_addr = 0;
+ shdr->sh_link = SHN_UNDEF;
+ shdr->sh_info = SHN_UNDEF;
+ shdr->sh_addralign = 1;
+ shdr->sh_entsize = 0;
+ shdr->sh_size = data->d_size;
+ shdr->sh_name = extra_idx;
+
+ if (gelf_update_shdr (scn, shdr) == 0)
+ {
+ printf ("cannot update new section header (%zd): %s\n", cnt,
+ elf_errmsg (-1));
+ exit (1);
+ }
+ }
+
+ // Create new shstrtab section.
+ Elf_Scn *new_shstrtab_scn = elf_newscn (elf);
+ if (new_shstrtab_scn == NULL)
+ {
+ printf ("cannot create new shstrtab section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ Elf_Data *new_shstrtab_data = elf_newdata (new_shstrtab_scn);
+ if (new_shstrtab_data == NULL)
+ {
+ printf ("couldn't create new shstrtab section data: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ new_shstrtab_data->d_size = new_shstrtab_size;
+ new_shstrtab_data->d_buf = new_shstrtab_buf;
+ new_shstrtab_data->d_type = ELF_T_BYTE;
+ new_shstrtab_data->d_align = 1;
+
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (new_shstrtab_scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for new shstrtab section: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ shdr->sh_type = SHT_STRTAB;
+ shdr->sh_flags = 0;
+ shdr->sh_addr = 0;
+ shdr->sh_link = SHN_UNDEF;
+ shdr->sh_info = SHN_UNDEF;
+ shdr->sh_addralign = 1;
+ shdr->sh_entsize = 0;
+ shdr->sh_size = new_shstrtab_size;
+ shdr->sh_name = new_shstrtab_idx;
+
+ // Finished new shstrtab section, update the header.
+ if (gelf_update_shdr (new_shstrtab_scn, shdr) == 0)
+ {
+ printf ("cannot update new shstrtab section header: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ // Set it as the new shstrtab section to get the names correct.
+ size_t new_shstrndx = elf_ndxscn (new_shstrtab_scn);
+ if (setshstrndx (elf, new_shstrndx) < 0)
+ {
+ printf ("cannot set shstrndx: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ // Write everything to disk.
+ if (elf_update (elf, ELF_C_WRITE) < 0)
+ {
+ printf ("failure in elf_update: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (elf_end (elf) != 0)
+ {
+ printf ("couldn't cleanup elf '%s': %s\n", name, elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (close (fd) != 0)
+ {
+ printf ("couldn't close '%s': %s\n", name, strerror (errno));
+ exit (1);
+ }
+
+ free (new_shstrtab_buf);
+}
+
+int
+main (int argc, char *argv[])
+{
+ elf_version (EV_CURRENT);
+
+ /* Takes the given file, and adds the given number of sections. */
+ if (argc < 3 || argc > 4)
+ {
+ fprintf (stderr, "addsections [--mmap] nr elf.file\n");
+ exit (1);
+ }
+
+ int argn = 1;
+ bool use_mmap = false;
+ if (strcmp (argv[argn], "--mmap") == 0)
+ {
+ use_mmap = true;
+ argn++;
+ }
+
+ size_t nr = atoi (argv[argn++]);
+ const char *file = argv[argn];
+ add_sections (file, nr, use_mmap);
+
+ return 0;
+}
diff --git a/tests/allregs.c b/tests/allregs.c
index 286f7e3c..f18f0b28 100644
--- a/tests/allregs.c
+++ b/tests/allregs.c
@@ -21,13 +21,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <error.h>
#include <locale.h>
#include <argp.h>
#include <assert.h>
#include ELFUTILS_HEADER(dwfl)
#include <dwarf.h>
+#include "system.h"
#include "../libdw/known-dwarf.h"
static const char *
diff --git a/tests/backtrace-data.c b/tests/backtrace-data.c
index a387d8ff..67ecd475 100644
--- a/tests/backtrace-data.c
+++ b/tests/backtrace-data.c
@@ -27,7 +27,6 @@
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>
-#include <error.h>
#include <unistd.h>
#include <dwarf.h>
#if defined(__x86_64__) && defined(__linux__)
@@ -41,6 +40,7 @@
#include <string.h>
#include ELFUTILS_HEADER(dwfl)
#endif
+#include "system.h"
#if !defined(__x86_64__) || !defined(__linux__)
diff --git a/tests/backtrace-dwarf.c b/tests/backtrace-dwarf.c
index 7ff826cd..35f25ed6 100644
--- a/tests/backtrace-dwarf.c
+++ b/tests/backtrace-dwarf.c
@@ -21,10 +21,10 @@
#include <stdio_ext.h>
#include <locale.h>
#include <errno.h>
-#include <error.h>
#include <unistd.h>
#include <sys/types.h>
#include ELFUTILS_HEADER(dwfl)
+#include "system.h"
#ifndef __linux__
@@ -124,6 +124,7 @@ thread_callback (Dwfl_Thread *thread, void *thread_arg)
}
int
+__attribute__((section(".main"))) /* Defeat -freorder-blocks-and-partition */
main (int argc __attribute__ ((unused)), char **argv)
{
/* We use no threads here which can interfere with handling a stream. */
diff --git a/tests/backtrace.c b/tests/backtrace.c
index f5dd761f..24ab68dd 100644
--- a/tests/backtrace.c
+++ b/tests/backtrace.c
@@ -24,7 +24,6 @@
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>
-#include <error.h>
#include <unistd.h>
#include <dwarf.h>
#ifdef __linux__
@@ -39,6 +38,7 @@
#include <argp.h>
#include ELFUTILS_HEADER(dwfl)
#endif
+#include "system.h"
#ifndef __linux__
diff --git a/tests/buildid.c b/tests/buildid.c
index 87c18773..2390eff7 100644
--- a/tests/buildid.c
+++ b/tests/buildid.c
@@ -23,13 +23,13 @@
#include ELFUTILS_HEADER(elf)
#include ELFUTILS_HEADER(dwelf)
#include <stdio.h>
-#include <error.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include "system.h"
int
main (int argc, char *argv[])
diff --git a/tests/debugaltlink.c b/tests/debugaltlink.c
index 6d97d500..e7dc8623 100644
--- a/tests/debugaltlink.c
+++ b/tests/debugaltlink.c
@@ -23,13 +23,13 @@
#include ELFUTILS_HEADER(dw)
#include ELFUTILS_HEADER(dwelf)
#include <stdio.h>
-#include <error.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include "system.h"
int
main (int argc, char *argv[])
diff --git a/tests/debuglink.c b/tests/debuglink.c
index 935d1029..f92b9b59 100644
--- a/tests/debuglink.c
+++ b/tests/debuglink.c
@@ -21,13 +21,13 @@
#include <errno.h>
#include ELFUTILS_HEADER(dwelf)
#include <stdio.h>
-#include <error.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include "system.h"
int
main (int argc, char *argv[])
diff --git a/tests/deleted.c b/tests/deleted.c
index 6be35bc2..f4e8f768 100644
--- a/tests/deleted.c
+++ b/tests/deleted.c
@@ -21,7 +21,6 @@
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
-#include <error.h>
#include <errno.h>
#ifdef __linux__
#include <sys/prctl.h>
diff --git a/tests/dwarfcfi.c b/tests/dwarfcfi.c
index db4a36ff..29849e71 100644
--- a/tests/dwarfcfi.c
+++ b/tests/dwarfcfi.c
@@ -18,7 +18,6 @@
#include <config.h>
#include <assert.h>
#include <inttypes.h>
-#include <error.h>
#include ELFUTILS_HEADER(dw)
#include <dwarf.h>
#include <argp.h>
@@ -30,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
+#include "system.h"
#include "../libdw/known-dwarf.h"
static const char *
diff --git a/tests/dwfl-addr-sect.c b/tests/dwfl-addr-sect.c
index 21e470a3..4d85c007 100644
--- a/tests/dwfl-addr-sect.c
+++ b/tests/dwfl-addr-sect.c
@@ -23,11 +23,11 @@
#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
-#include <error.h>
#include <locale.h>
#include <argp.h>
#include ELFUTILS_HEADER(dwfl)
#include <dwarf.h>
+#include "system.h"
static int
handle_address (Dwfl *dwfl, Dwarf_Addr address)
diff --git a/tests/dwfl-bug-addr-overflow.c b/tests/dwfl-bug-addr-overflow.c
index aa8030e1..9a3373a6 100644
--- a/tests/dwfl-bug-addr-overflow.c
+++ b/tests/dwfl-bug-addr-overflow.c
@@ -20,7 +20,6 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdio_ext.h>
-#include <error.h>
#include <locale.h>
#include ELFUTILS_HEADER(dwfl)
diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c
index 689cdd79..ee3a916b 100644
--- a/tests/dwfl-bug-fd-leak.c
+++ b/tests/dwfl-bug-fd-leak.c
@@ -24,9 +24,9 @@
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>
-#include <error.h>
#include <unistd.h>
#include <dwarf.h>
+#include "system.h"
#ifndef __linux__
int
diff --git a/tests/dwfl-bug-getmodules.c b/tests/dwfl-bug-getmodules.c
index 1ee989f8..2783f65c 100644
--- a/tests/dwfl-bug-getmodules.c
+++ b/tests/dwfl-bug-getmodules.c
@@ -17,8 +17,8 @@
#include <config.h>
#include ELFUTILS_HEADER(dwfl)
+#include "system.h"
-#include <error.h>
static const Dwfl_Callbacks callbacks =
{
diff --git a/tests/dwfl-proc-attach.c b/tests/dwfl-proc-attach.c
index e7bb2010..102ba181 100644
--- a/tests/dwfl-proc-attach.c
+++ b/tests/dwfl-proc-attach.c
@@ -20,7 +20,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
-#include <error.h>
#include <unistd.h>
#ifdef __linux__
#include <sys/types.h>
@@ -31,6 +30,7 @@
#include ELFUTILS_HEADER(dwfl)
#include <pthread.h>
#endif
+#include "system.h"
#ifndef __linux__
int
diff --git a/tests/dwfl-report-elf-align.c b/tests/dwfl-report-elf-align.c
index a4e97d3c..6558ab81 100644
--- a/tests/dwfl-report-elf-align.c
+++ b/tests/dwfl-report-elf-align.c
@@ -20,11 +20,11 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdio_ext.h>
-#include <error.h>
#include <locale.h>
#include <string.h>
#include <stdlib.h>
#include ELFUTILS_HEADER(dwfl)
+#include "system.h"
static const Dwfl_Callbacks offline_callbacks =
diff --git a/tests/dwfllines.c b/tests/dwfllines.c
index 90379dd2..d732e401 100644
--- a/tests/dwfllines.c
+++ b/tests/dwfllines.c
@@ -27,7 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <error.h>
+#include "system.h"
int
main (int argc, char *argv[])
diff --git a/tests/dwflmodtest.c b/tests/dwflmodtest.c
index 0027f96b..9251d158 100644
--- a/tests/dwflmodtest.c
+++ b/tests/dwflmodtest.c
@@ -23,11 +23,11 @@
#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
-#include <error.h>
#include <locale.h>
#include <argp.h>
#include ELFUTILS_HEADER(dwfl)
#include <dwarf.h>
+#include "system.h"
static bool show_inlines;
diff --git a/tests/dwflsyms.c b/tests/dwflsyms.c
index 49ac3346..bc23cb63 100644
--- a/tests/dwflsyms.c
+++ b/tests/dwflsyms.c
@@ -25,7 +25,6 @@
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
static const char *
diff --git a/tests/early-offscn.c b/tests/early-offscn.c
index 924cb9ef..af29da5a 100644
--- a/tests/early-offscn.c
+++ b/tests/early-offscn.c
@@ -19,11 +19,11 @@
#endif
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
#include <gelf.h>
#include <stdio.h>
#include <stdlib.h>
+#include "system.h"
int
main (int argc, char *argv[])
diff --git a/tests/ecp.c b/tests/ecp.c
index 38a6859e..1df40a32 100644
--- a/tests/ecp.c
+++ b/tests/ecp.c
@@ -20,11 +20,11 @@
#endif
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
#include <gelf.h>
#include <stdlib.h>
#include <unistd.h>
+#include "system.h"
int
main (int argc, char *argv[])
diff --git a/tests/elfcopy.c b/tests/elfcopy.c
new file mode 100644
index 00000000..9000cc96
--- /dev/null
+++ b/tests/elfcopy.c
@@ -0,0 +1,286 @@
+/* Test program for copying a whole ELF file using libelf.
+ Copyright (C) 2018 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include ELFUTILS_HEADER(elf)
+#include <gelf.h>
+
+
+/* shstrndx is special, might overflow into section zero header sh_link. */
+static int
+setshstrndx (Elf *elf, size_t ndx)
+{
+ printf ("setshstrndx: %zd\n", ndx);
+
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ return -1;
+
+ if (ndx < SHN_LORESERVE)
+ ehdr->e_shstrndx = ndx;
+ else
+ {
+ ehdr->e_shstrndx = SHN_XINDEX;
+ Elf_Scn *zscn = elf_getscn (elf, 0);
+ GElf_Shdr zshdr_mem;
+ GElf_Shdr *zshdr = gelf_getshdr (zscn, &zshdr_mem);
+ if (zshdr == NULL)
+ return -1;
+ zshdr->sh_link = ndx;
+ if (gelf_update_shdr (zscn, zshdr) == 0)
+ return -1;
+ }
+
+ if (gelf_update_ehdr (elf, ehdr) == 0)
+ return -1;
+
+ return 0;
+}
+
+/* Copies all elements of an ELF file either using mmap or read. */
+static void
+copy_elf (const char *in, const char *out, bool use_mmap)
+{
+ printf ("\ncopy_elf: %s -> %s (%s)\n", in, out, use_mmap ? "mmap" : "read");
+
+ /* Existing ELF file. */
+ int fda = open (in, O_RDONLY);
+ if (fda < 0)
+ {
+ fprintf (stderr, "Couldn't open file '%s': %s\n",
+ in, strerror (errno));
+ exit (1);
+ }
+
+ Elf *elfa = elf_begin (fda, use_mmap ? ELF_C_READ_MMAP : ELF_C_READ, NULL);
+ if (elfa == NULL)
+ {
+ fprintf (stderr, "Couldn't open ELF file '%s': %s\n",
+ in, elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Open new file. */
+ int fdb = open (out, O_RDWR | O_CREAT | O_TRUNC, 0644);
+ if (fdb < 0)
+ {
+ fprintf (stderr, "Couldn't create file '%s': %s\n",
+ out, strerror (errno));
+ exit (1);
+ }
+
+ Elf *elfb = elf_begin (fdb, use_mmap ? ELF_C_WRITE_MMAP : ELF_C_WRITE, NULL);
+ if (elfb == NULL)
+ {
+ fprintf (stderr, "Couldn't create ELF file '%s': %s\n",
+ out, elf_errmsg (-1));
+ exit (1);
+ }
+
+ // Copy ELF header.
+ GElf_Ehdr ehdr_mema;
+ GElf_Ehdr *ehdra = gelf_getehdr (elfa, &ehdr_mema);
+ if (ehdra == NULL)
+ {
+ printf ("cannot get ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ int class = gelf_getclass (elfa);
+ // Create an ELF header.
+ if (gelf_newehdr (elfb, class) == 0)
+ {
+ printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* New elf header is an exact copy. */
+ GElf_Ehdr ehdr_memb;
+ GElf_Ehdr *ehdrb = &ehdr_memb;
+ *ehdrb = *ehdra;
+ if (gelf_update_ehdr (elfb, ehdrb) == 0)
+ {
+ printf ("cannot update ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* shstrndx is special. (Technically phdrnum and shdrnum are also
+ special, but they are handled by libelf.) */
+ size_t shstrndx;
+ if (elf_getshdrstrndx (elfa, &shstrndx) < 0)
+ {
+ printf ("cannot get shstrndx: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ if (setshstrndx (elfb, shstrndx) < 0)
+ {
+ printf ("cannot set shstrndx: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* If there are phdrs, copy them over. */
+ size_t phnum;
+ if (elf_getphdrnum (elfa, &phnum) != 0)
+ {
+ printf ("cannot get phdrs: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (phnum > 0)
+ {
+ if (gelf_newphdr (elfb, phnum) == 0)
+ {
+ printf ("cannot create phdrs: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ for (size_t cnt = 0; cnt < phnum; ++cnt)
+ {
+ GElf_Phdr phdr_mem;
+ GElf_Phdr *phdr = gelf_getphdr (elfa, cnt, &phdr_mem);
+ if (phdr == NULL)
+ {
+ printf ("couldn't get phdr %zd: %s\n", cnt, elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (gelf_update_phdr (elfb, cnt, phdr) == 0)
+ {
+ printf ("couldn't update phdr %zd: %s\n", cnt, elf_errmsg (-1));
+ exit (1);
+ }
+ }
+ }
+
+ /* Copy all sections, headers and data. */
+ Elf_Scn *scn = NULL;
+ while ((scn = elf_nextscn (elfa, scn)) != NULL)
+ {
+ /* Get the header. */
+ GElf_Shdr shdr;
+ if (gelf_getshdr (scn, &shdr) == NULL)
+ {
+ printf ("couldn't get shdr: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Create new section. */
+ Elf_Scn *new_scn = elf_newscn (elfb);
+ if (new_scn == NULL)
+ {
+ printf ("couldn't create new section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (gelf_update_shdr (new_scn, &shdr) == 0)
+ {
+ printf ("couldn't update shdr: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Copy over section data. */
+ Elf_Data *data = NULL;
+ while ((data = elf_getdata (scn, data)) != NULL)
+ {
+ Elf_Data *new_data = elf_newdata (new_scn);
+ if (new_data == NULL)
+ {
+ printf ("couldn't create new section data: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+ *new_data = *data;
+ }
+ }
+
+ /* Write everything to disk. If there are any phdrs then we want
+ the exact same layout. Do we want ELF_F_PERMISSIVE? */
+ if (phnum > 0)
+ elf_flagelf (elfb, ELF_C_SET, ELF_F_LAYOUT);
+ if (elf_update (elfb, ELF_C_WRITE) < 0)
+ {
+ printf ("failure in elf_update: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (elf_end (elfa) != 0)
+ {
+ printf ("couldn't cleanup elf '%s': %s\n", in, elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (close (fda) != 0)
+ {
+ printf ("couldn't close '%s': %s\n", in, strerror (errno));
+ exit (1);
+ }
+
+ if (elf_end (elfb) != 0)
+ {
+ printf ("couldn't cleanup elf '%s': %s\n", out, elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (close (fdb) != 0)
+ {
+ printf ("couldn't close '%s': %s\n", out, strerror (errno));
+ exit (1);
+ }
+}
+
+int
+main (int argc, const char *argv[])
+{
+ elf_version (EV_CURRENT);
+
+ /* Takes the given file, and create a new identical one. */
+ if (argc < 3 || argc > 4)
+ {
+ fprintf (stderr, "elfcopy [--mmap] in.elf out.elf\n");
+ exit (1);
+ }
+
+ int argn = 1;
+ bool use_mmap = false;
+ if (strcmp (argv[argn], "--mmap") == 0)
+ {
+ use_mmap = true;
+ argn++;
+ }
+
+ const char *in = argv[argn++];
+ const char *out = argv[argn];
+ copy_elf (in, out, use_mmap);
+
+ return 0;
+}
diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index 3bb90c42..ba0d68df 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -24,7 +24,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <error.h>
#include <stdio.h>
#include <inttypes.h>
#include <unistd.h>
diff --git a/tests/find-prologues.c b/tests/find-prologues.c
index ba8ae371..b0bf9362 100644
--- a/tests/find-prologues.c
+++ b/tests/find-prologues.c
@@ -25,9 +25,9 @@
#include <stdio_ext.h>
#include <locale.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
#include <fnmatch.h>
+#include "system.h"
struct args
diff --git a/tests/funcretval.c b/tests/funcretval.c
index 8d19d117..16cd1a44 100644
--- a/tests/funcretval.c
+++ b/tests/funcretval.c
@@ -25,9 +25,9 @@
#include <stdio_ext.h>
#include <locale.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
#include <fnmatch.h>
+#include "system.h"
struct args
diff --git a/tests/funcscopes.c b/tests/funcscopes.c
index 9c901858..689d376a 100644
--- a/tests/funcscopes.c
+++ b/tests/funcscopes.c
@@ -25,9 +25,9 @@
#include <stdio_ext.h>
#include <locale.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
#include <fnmatch.h>
+#include "system.h"
static void
diff --git a/tests/getsrc_die.c b/tests/getsrc_die.c
index 055aede0..f878fa62 100644
--- a/tests/getsrc_die.c
+++ b/tests/getsrc_die.c
@@ -19,7 +19,6 @@
#endif
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
#include <inttypes.h>
#include <libelf.h>
@@ -27,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include "system.h"
int
diff --git a/tests/hello_riscv64.ko.bz2 b/tests/hello_riscv64.ko.bz2
index 355a5122..a086c380 100644
--- a/tests/hello_riscv64.ko.bz2
+++ b/tests/hello_riscv64.ko.bz2
Binary files differ
diff --git a/tests/line2addr.c b/tests/line2addr.c
index e0d65d3d..663746fd 100644
--- a/tests/line2addr.c
+++ b/tests/line2addr.c
@@ -26,7 +26,7 @@
#include <locale.h>
#include <stdlib.h>
#include <string.h>
-#include <error.h>
+#include "system.h"
static void
diff --git a/tests/low_high_pc.c b/tests/low_high_pc.c
index 5c6b343c..78b6ad08 100644
--- a/tests/low_high_pc.c
+++ b/tests/low_high_pc.c
@@ -25,7 +25,6 @@
#include <stdio_ext.h>
#include <locale.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
#include <fnmatch.h>
diff --git a/tests/next_cfi.c b/tests/next_cfi.c
index b923744f..6a847b4d 100644
--- a/tests/next_cfi.c
+++ b/tests/next_cfi.c
@@ -18,7 +18,6 @@
#include <config.h>
#include <assert.h>
#include <inttypes.h>
-#include <error.h>
#include ELFUTILS_HEADER(dw)
#include <dwarf.h>
#include <argp.h>
@@ -31,9 +30,10 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include "system.h"
void
-handle_section (const unsigned char e_ident[],
+handle_section (char *name, const unsigned char e_ident[],
Elf_Scn *scn, const bool is_eh)
{
if (is_eh)
@@ -41,6 +41,24 @@ handle_section (const unsigned char e_ident[],
else
printf (".debug_frame\n");
+ GElf_Shdr mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &mem);
+ if (shdr == NULL)
+ error (EXIT_FAILURE, 0, "Couldn't get section header: %s",
+ elf_errmsg (-1));
+ if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
+ {
+ if (elf_compress (scn, 0, 0) < 0)
+ error (EXIT_FAILURE, 0, "Couldn't decompress section: %s",
+ elf_errmsg (-1));
+ }
+ else if (name[0] == '.' && name[1] == 'z')
+ {
+ if (elf_compress_gnu (scn, 0, 0) < 0)
+ error (EXIT_FAILURE, 0, "Couldn't decompress section: %s",
+ elf_errmsg (-1));
+ }
+
Elf_Data *data = elf_getdata (scn, NULL);
if (data == NULL || data->d_buf == NULL)
error (EXIT_FAILURE, 0, "no section data");
@@ -117,9 +135,10 @@ main (int argc, char *argv[])
if (name != NULL && shdr.sh_type == SHT_PROGBITS)
{
if (strcmp (name, ".eh_frame") == 0)
- handle_section (ident, scn, true);
- if (strcmp (name, ".debug_frame") == 0)
- handle_section (ident, scn, false);
+ handle_section (name, ident, scn, true);
+ if (strcmp (name, ".debug_frame") == 0
+ || strcmp (name, ".zdebug_frame") == 0)
+ handle_section (name, ident, scn, false);
}
}
}
diff --git a/tests/rdwrmmap.c b/tests/rdwrmmap.c
index 6f027dfe..490a4eea 100644
--- a/tests/rdwrmmap.c
+++ b/tests/rdwrmmap.c
@@ -19,11 +19,11 @@
#endif
#include <errno.h>
-#include <error.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <libelf.h>
+#include "system.h"
int
main (int argc __attribute__ ((unused)), char *argv[])
diff --git a/tests/run-annobingroup.sh b/tests/run-annobingroup.sh
new file mode 100755
index 00000000..700df321
--- /dev/null
+++ b/tests/run-annobingroup.sh
@@ -0,0 +1,123 @@
+#! /bin/sh
+# Copyright (C) 2018 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Testfile generated by annobin, creates group.
+# strip and unstrip it. Check group symbol/name is correct.
+
+# echo "int __attribute__((cold)) foo (void) { return 42; }" \
+# > testfile-annobingroup.c
+# gcc -g -O2 -fplugin=annobin -c testfile-annobingroup.c
+testfiles testfile-annobingroup.o
+
+tempfiles merged.elf stripped.elf debugfile.elf remerged.elf
+
+testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup.o << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 7] .gnu.build.attributes..text.unlikely
+ [ 8] .rela.gnu.build.attributes..text.unlikely
+ [ 9] .text.unlikely
+EOF
+
+testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup.o
+
+testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 7] .gnu.build.attributes..text.unlikely
+ [ 8] .rela.gnu.build.attributes..text.unlikely
+ [ 9] .text.unlikely
+EOF
+
+testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 7] .gnu.build.attributes..text.unlikely
+ [ 8] .rela.gnu.build.attributes..text.unlikely
+ [ 9] .text.unlikely
+EOF
+
+testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile.elf
+
+testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 7] .gnu.build.attributes..text.unlikely
+ [ 8] .rela.gnu.build.attributes..text.unlikely
+ [ 9] .text.unlikely
+EOF
+
+testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup.o remerged.elf
+
+# echo "void * __attribute__((cold)) foo (void) { return foo; }"
+# > testfile-annobingroup-i386.c
+# gcc -fpic -g -O2 -fplugin=annobin -c testfile-annobingroup-i386.c
+testfiles testfile-annobingroup-i386.o
+
+testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-i386.o << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 8] .gnu.build.attributes..text.unlikely
+ [ 9] .rel.gnu.build.attributes..text.unlikely
+ [10] .text.unlikely
+
+COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
+ [13] .text.__x86.get_pc_thunk.ax
+EOF
+
+testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup-i386.o
+
+testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 8] .gnu.build.attributes..text.unlikely
+ [ 9] .rel.gnu.build.attributes..text.unlikely
+ [10] .text.unlikely
+
+COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
+ [13] .text.__x86.get_pc_thunk.ax
+EOF
+
+testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 8] .gnu.build.attributes..text.unlikely
+ [ 9] .rel.gnu.build.attributes..text.unlikely
+ [10] .text.unlikely
+
+COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
+ [13] .text.__x86.get_pc_thunk.ax
+EOF
+
+testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile.elf
+
+testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
+
+Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
+ [ 8] .gnu.build.attributes..text.unlikely
+ [ 9] .rel.gnu.build.attributes..text.unlikely
+ [10] .text.unlikely
+
+COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
+ [13] .text.__x86.get_pc_thunk.ax
+EOF
+
+testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-i386.o remerged.elf
+
+exit 0
diff --git a/tests/run-copyadd-sections.sh b/tests/run-copyadd-sections.sh
new file mode 100755
index 00000000..bc20f6ee
--- /dev/null
+++ b/tests/run-copyadd-sections.sh
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2018 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+test_copy_and_add ()
+{
+ in_file="$1"
+ out_file="${in_file}.copy"
+ out_file_mmap="${out_file}.mmap"
+
+ testfiles ${in_file}
+ tempfiles ${out_file} ${out_file_mmap} readelf.out
+
+ # Can we copy the file?
+ testrun ${abs_builddir}/elfcopy ${in_file} ${out_file}
+ testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file}
+
+ # Can we add a section (in-place)?
+ testrun ${abs_builddir}/addsections 3 ${out_file}
+ testrun ${abs_top_builddir}/src/readelf -S ${out_file} > readelf.out
+ nr=$(grep '.extra' readelf.out | wc -l)
+ if test ${nr} != 3; then
+ # Show what went wrong
+ testrun ${abs_top_builddir}/src/readelf -S ${out_file}
+ exit 1
+ fi
+
+ # Can we add a section (in-place) using ELF_C_WRITE_MMAP?
+ testrun ${abs_builddir}/elfcopy --mmap ${in_file} ${out_file_mmap}
+ testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file_mmap}
+
+ # Can we add a section (in-place) using ELF_C_RDWR_MMAP?
+ # Note we are only adding one sections, adding more might fail
+ # because mremap cannot extend too much.
+ testrun ${abs_builddir}/addsections --mmap 1 ${out_file_mmap}
+ testrun ${abs_top_builddir}/src/readelf -S ${out_file_mmap} > readelf.out
+ nr=$(grep '.extra' readelf.out | wc -l)
+ if test ${nr} != 1; then
+ # Show what went wrong
+ testrun ${abs_top_builddir}/src/readelf -S ${out_file_mmap}
+ exit 1
+ fi
+}
+
+# A collection of random testfiles to test 32/64bit, little/big endian
+# and non-ET_REL (with phdrs)/ET_REL (without phdrs).
+
+# 32bit, big endian, rel
+test_copy_and_add testfile29
+
+# 64bit, big endian, rel
+test_copy_and_add testfile23
+
+# 32bit, little endian, rel
+test_copy_and_add testfile9
+
+# 64bit, little endian, rel
+test_copy_and_add testfile38
+
+# 32bit, big endian, non-rel
+test_copy_and_add testfile26
+
+# 64bit, big endian, non-rel
+test_copy_and_add testfile27
+
+# 32bit, little endian, non-rel
+test_copy_and_add testfile
+
+# 64bit, little endian, non-rel
+test_copy_and_add testfile10
+
+exit 0
diff --git a/tests/run-copymany-sections.sh b/tests/run-copymany-sections.sh
new file mode 100755
index 00000000..84c052c9
--- /dev/null
+++ b/tests/run-copymany-sections.sh
@@ -0,0 +1,99 @@
+#! /bin/sh
+# Copyright (C) 2018 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Same as run-copyadd-sections.sh, but for many > 0xffff sections.
+# Doesn't use mmap for addsections since that doesn't work.
+# ELF_C_RDWR_MMAP needs mremap which will fail since it needs too
+# much space and the original mmap cannot move.
+
+. $srcdir/test-subr.sh
+
+test_copy_and_add ()
+{
+ in_file="$1"
+ out_file="${in_file}.copy"
+ out_file_mmap="${out_file}.mmap"
+
+ tempfiles ${out_file} ${out_file_mmap} readelf.out
+
+ # Can we copy the file?
+ testrun ${abs_builddir}/elfcopy ${in_file} ${out_file}
+ testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file}
+
+ # Can we add a section (in-place)?
+ testrun ${abs_builddir}/addsections 65535 ${out_file}
+ testrun ${abs_top_builddir}/src/readelf -S ${out_file} > readelf.out
+ nr=$(grep '.extra' readelf.out | wc -l)
+ # We try twice...
+ if test ${nr} != 65535 -a ${nr} != 131070; then
+ # Show what went wrong
+ testrun ${abs_top_builddir}/src/readelf -S ${out_file}
+ exit 1
+ fi
+
+ # Can we copy the file using ELF_C_WRITE_MMAP?
+ testrun ${abs_builddir}/elfcopy --mmap ${in_file} ${out_file_mmap}
+ testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file_mmap}
+
+ # Don't try to add using mmap (see above)
+}
+
+# A collection of random testfiles to test 32/64bit, little/big endian
+# and non-ET_REL (with phdrs)/ET_REL (without phdrs).
+# Try to add 0xffff sections twice.
+
+# 32bit, big endian, rel
+testfiles testfile29
+test_copy_and_add testfile29
+test_copy_and_add testfile29.copy
+
+# 64bit, big endian, rel
+testfiles testfile23
+test_copy_and_add testfile23
+test_copy_and_add testfile23.copy
+
+# 32bit, little endian, rel
+testfiles testfile9
+test_copy_and_add testfile9
+test_copy_and_add testfile9.copy
+
+# 64bit, little endian, rel
+testfiles testfile38
+test_copy_and_add testfile38
+test_copy_and_add testfile38.copy
+
+# 32bit, big endian, non-rel
+testfiles testfile26
+test_copy_and_add testfile26
+test_copy_and_add testfile26.copy
+
+# 64bit, big endian, non-rel
+testfiles testfile27
+test_copy_and_add testfile27
+test_copy_and_add testfile27.copy
+
+# 32bit, little endian, non-rel
+testfiles testfile
+test_copy_and_add testfile
+test_copy_and_add testfile.copy
+
+# 64bit, little endian, non-rel
+testfiles testfile10
+test_copy_and_add testfile10
+test_copy_and_add testfile10.copy
+
+exit 0
diff --git a/tests/run-strip-reloc.sh b/tests/run-strip-reloc.sh
index 5c847a4d..caa7eb52 100755
--- a/tests/run-strip-reloc.sh
+++ b/tests/run-strip-reloc.sh
@@ -32,6 +32,8 @@ runtest() {
outfile2=out.stripped2
debugfile2=out.debug2
+ rm -f $outfile1 $debugfile1 $outfile2 $debugfile2
+
testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile ||
{ echo "*** failure strip $infile"; status=1; }
@@ -68,6 +70,7 @@ runtest() {
}
# Most simple hello world kernel module for various architectures.
+# Make sure that it contains debuginfo with CONFIG_DEBUG_INFO=y.
# ::::::::::::::
# Makefile
# ::::::::::::::
@@ -75,7 +78,8 @@ runtest() {
# hello-y := init.o exit.o
#
# all:
-# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
+# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) \
+# CONFIG_DEBUG_INFO=y modules
# ::::::::::::::
# init.c
# ::::::::::::::
diff --git a/tests/run-strip-test-many.sh b/tests/run-strip-test-many.sh
new file mode 100755
index 00000000..9a9657cd
--- /dev/null
+++ b/tests/run-strip-test-many.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2018 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Use the original file from run-strip-test.sh but with many sections
+testfiles testfile
+tempfiles testfile.strip testfile.debug testfile.unstrip
+
+echo "Adding sections to testfile"
+testrun ${abs_builddir}/addsections 65535 testfile
+
+echo "Testing strip -o"
+testrun ${abs_top_builddir}/src/strip -o testfile.strip -f testfile.debug testfile
+
+# Do the parts check out?
+echo "elflint testfile.strip"
+testrun ${abs_top_builddir}/src/elflint --gnu -q testfile.strip
+echo "elflint testfile.debug"
+testrun ${abs_top_builddir}/src/elflint --gnu -q -d testfile.debug
+
+# Now test unstrip recombining those files.
+echo "unstrip"
+testrun ${abs_top_builddir}/src/unstrip -o testfile.unstrip testfile.strip testfile.debug
+echo "elfcmp"
+testrun ${abs_top_builddir}/src/elfcmp testfile testfile.unstrip
+
+# test strip -g
+echo "Testing strip -g"
+testrun ${abs_top_builddir}/src/strip -g -o testfile.strip -f testfile.debug testfile
+
+# Do the parts check out?
+echo "elflint testfile.strip"
+testrun ${abs_top_builddir}/src/elflint --gnu -q testfile.strip
+echo "elflint testfile.debug"
+testrun ${abs_top_builddir}/src/elflint --gnu -q -d testfile.debug
+
+# Now strip "in-place" and make sure it is smaller.
+echo "TEsting strip in-place"
+SIZE_original=$(stat -c%s testfile)
+echo "original size $SIZE_original"
+
+testrun ${abs_top_builddir}/src/strip testfile
+SIZE_stripped=$(stat -c%s testfile)
+echo "stripped size $SIZE_stripped"
+test $SIZE_stripped -lt $SIZE_original ||
+ { echo "*** failure in-place strip file not smaller $original"; exit 1; }
+
+echo "elflint in-place"
+testrun ${abs_top_builddir}/src/elflint --gnu -q testfile
+
+exit 0
diff --git a/tests/run-strip-test12.sh b/tests/run-strip-test12.sh
new file mode 100755
index 00000000..cb120985
--- /dev/null
+++ b/tests/run-strip-test12.sh
@@ -0,0 +1,4 @@
+original=testfile-riscv64
+stripped=testfile-riscv64-s
+
+. $srcdir/run-strip-test.sh
diff --git a/tests/run-typeiter-many.sh b/tests/run-typeiter-many.sh
new file mode 100755
index 00000000..39168f2e
--- /dev/null
+++ b/tests/run-typeiter-many.sh
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Copyright (C) 2018 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+
+# Like run-typeiter.sh but we first add many sections to make sure
+# dwarf_begin actually recognizes the debug section names.
+testfiles testfile-debug-types
+
+testrun ${abs_builddir}/addsections 65535 testfile-debug-types
+testrun_compare ${abs_builddir}/typeiter2 testfile-debug-types <<\EOF
+ok A [68]
+ok B [38]
+EOF
+
+exit 0
diff --git a/tests/saridx.c b/tests/saridx.c
index 8a450d82..e7f0c566 100644
--- a/tests/saridx.c
+++ b/tests/saridx.c
@@ -17,7 +17,6 @@
#include <config.h>
-#include <error.h>
#include <fcntl.h>
#include <gelf.h>
#include <stdio.h>
@@ -25,6 +24,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include "system.h"
static const char *machines[] =
diff --git a/tests/sectiondump.c b/tests/sectiondump.c
index 3033fedc..f33484f9 100644
--- a/tests/sectiondump.c
+++ b/tests/sectiondump.c
@@ -18,13 +18,13 @@
#include <config.h>
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
#include <gelf.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include "system.h"
/* Prototypes for local functions. */
diff --git a/tests/testfile-annobingroup-i386.o.bz2 b/tests/testfile-annobingroup-i386.o.bz2
new file mode 100644
index 00000000..798eefda
--- /dev/null
+++ b/tests/testfile-annobingroup-i386.o.bz2
Binary files differ
diff --git a/tests/testfile-annobingroup.o.bz2 b/tests/testfile-annobingroup.o.bz2
new file mode 100644
index 00000000..b1ca7ea1
--- /dev/null
+++ b/tests/testfile-annobingroup.o.bz2
Binary files differ
diff --git a/tests/testfile-riscv64-core.bz2 b/tests/testfile-riscv64-core.bz2
new file mode 100644
index 00000000..f5b472bb
--- /dev/null
+++ b/tests/testfile-riscv64-core.bz2
Binary files differ
diff --git a/tests/testfile-riscv64-s.bz2 b/tests/testfile-riscv64-s.bz2
new file mode 100755
index 00000000..149ae416
--- /dev/null
+++ b/tests/testfile-riscv64-s.bz2
Binary files differ
diff --git a/tests/testfile-riscv64.bz2 b/tests/testfile-riscv64.bz2
new file mode 100755
index 00000000..cae4919d
--- /dev/null
+++ b/tests/testfile-riscv64.bz2
Binary files differ
diff --git a/tests/varlocs.c b/tests/varlocs.c
index 25124399..40505196 100644
--- a/tests/varlocs.c
+++ b/tests/varlocs.c
@@ -25,13 +25,13 @@
#include <dwarf.h>
#include <stdio.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include "system.h"
#include "../libdw/known-dwarf.h"
// The Dwarf, Dwarf_CFIs and address bias of
diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c
index b876c10b..7bfa7381 100644
--- a/tests/vdsosyms.c
+++ b/tests/vdsosyms.c
@@ -18,13 +18,13 @@
#include <config.h>
#include <assert.h>
#include <errno.h>
-#include <error.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include ELFUTILS_HEADER(dwfl)
+#include "system.h"
#ifndef __linux__
int