Adjust for monotone.
diff --git a/tests/.cvsignore b/tests/.cvsignore
new file mode 100644
index 0000000..70845e0
--- /dev/null
+++ b/tests/.cvsignore
@@ -0,0 +1 @@
+Makefile.in
diff --git a/tests/ChangeLog b/tests/ChangeLog
new file mode 100644
index 0000000..024c7c8
--- /dev/null
+++ b/tests/ChangeLog
@@ -0,0 +1,126 @@
+2005-07-21 Ulrich Drepper <drepper@redhat.com>
+
+ * testfile18.bz2: New file.
+ * run-elflint-test.sh: New file.
+ * Makefile.am (TESTS): Add run-elflint-test.sh.
+ (EXTRA_DIST): Add run-elflint-test.sh and testfile18.bz2.
+
+2005-05-24 Ulrich Drepper <drepper@redhat.com>
+
+ * get-files.c (main): Use correct format specifier.
+
+2005-05-21 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile.am: Add -Wextra to CFLAGS.
+ * get-files.c: Remove warning this produced.
+ * get-pubnames.c: Likewise.
+ * newfile.c: Likewise.
+ * newscn.c: Likewise.
+ * scnnames.c: Likewise.
+ * showptable.c: Likewise.
+ * test-nlist.c: Likewise.
+ * update1.c: Likewise.
+ * update2.c: Likewise.
+ * update3.c: Likewise.
+ * update4.c: Likewise.
+
+2005-05-08 Ulrich Drepper <drepper@redhat.com>
+
+ * run-line2addr.sh: Remove testfile14 at the end.
+
+ * run-strip-test.sh: Remove deubinfo test input file as well.
+
+ * Makefile.am (EXTRA_DIST): Newly added files incorrectly used
+ .bz, not .bz2.
+
+2005-05-03 Roland McGrath <roland@redhat.com>
+
+ * run-strip-test.sh: Use variables for test file names.
+ Optionally produce separate debug file and check it.
+ * run-strip-test2.sh: Use run-strip-test.sh via ., no duplication.
+ * run-strip-test3.sh: Likewise.
+ * run-strip-test4.sh: New file.
+ * run-strip-test5.sh: New file.
+ * run-strip-test6.sh: New file.
+ * testfile15.bz: New file.
+ * testfile15.debug.bz: New file.
+ * testfile16.bz: New file.
+ * testfile16.debug.bz: New file.
+ * testfile17.bz: New file.
+ * testfile17.debug.bz: New file.
+ * Makefile.am (TESTS, EXTRA_DIST): Add them.
+
+2005-04-25 Ulrich Drepper <drepper@redhat.com>
+
+ * run-line2addr.sh: Also use testfile14. Adjust for correct
+ return of multiple matches.
+ * testfile14.bz2: New file.
+ * Makefile.am (EXTRA_DIST): Add testfile14.bz2.
+
+ * show-abbrev.c (main): Adjust for dwarf_getabbrev interface change.
+
+2005-04-04 Roland McGrath <roland@frob.com>
+
+ * line2addr.c (main): Initialize LINES and NLINES before calling
+ dwarf_getsrc_file, and free LINES afterwards.
+
+ * allfcts.c (main): Use size_t for CUHL.
+
+2005-04-04 Ulrich Drepper <drepper@redhat.com>
+
+ * line2addr.c: New file.
+ * run-line2addr.sh: New file.
+ * Makefile.am: Add rules to build, run, and distribute new code.
+
+2005-04-02 Ulrich Drepper <drepper@redhat.com>
+
+ * allfcts.c: New file.
+ * run-allfcts.sh: New file.
+ * Makefile.am: Add rules to build, run, and distribute new code.
+
+2005-02-05 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile.am [MUDFLAP] (AM_CFLAGS): Add -fmudflap. Link all test
+ programs with -lmudflap.
+
+2004-09-25 Ulrich Drepper <drepper@redhat.com>
+
+ * asm-tst4.c (main): Add LD_LIBRARY_PATH to elflint invocation.
+ * asm-tst5.c (main): Likewise.
+ * asm-tst6.c (main): Likewise.
+
+2004-01-17 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile.am: Support building with mudflap.
+
+2004-01-12 Ulrich Drepper <drepper@redhat.com>
+
+ * get-aranges.c: Rewrite to use libdw.
+ * Makefile.am: Reenable get-aranges test.
+
+2004-01-11 Ulrich Drepper <drepper@redhat.com>
+
+ * get-lines.c: New file.
+ * get-files.c: Adjust for libdw.
+ * run-get-files.sh: Adjust expected result.
+ * run-get-lines.sh: Likewise.
+ * Makefile.am: Run get-lines test. Don't run get-aranges and
+ get-ciefde test for now.
+
+ * show-abbrev.c: Adjust call to dwarf_getabbrevattr after interface
+ change. Print attribute offset information.
+ * run-show-abbrev.sh: Adjust expected output.
+
+2004-01-09 Ulrich Drepper <drepper@redhat.com>
+
+ * show-abbrev.c: Adjust call to dwarf_nextcu after interface change.
+ * show-die-info.c: Likewise.
+ * run-show-die-info.sh: Adjust expected output.
+
+2003-08-13 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile.in: Depend on libebl.a, not libebl.so.
+
+2003-08-11 Ulrich Drepper <drepper@redhat.com>
+
+ * Moved to CVS archive.
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..674ed57
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,113 @@
+## Process this file with automake to create Makefile.in
+##
+## Copyright (C) 1996-2002, 2003, 2004, 2005 Red Hat, Inc.
+##
+## This program is Open Source software; you can redistribute it and/or
+## modify it under the terms of the Open Software License version 1.0 as
+## published by the Open Source Initiative.
+##
+## You should have received a copy of the Open Software License along
+## with this program; if not, you may obtain a copy of the Open Software
+## License version 1.0 from http://www.opensource.org/licenses/osl.php or
+## by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+## 3001 King Ranch Road, Ukiah, CA 95482.
+##
+DEFS = -DHAVE_CONFIG_H -D_GNU_SOURCE
+if MUDFLAP
+AM_CFLAGS = -Wall -Werror -Wextra -std=gnu99 -fmudflap\
+ $(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2)
+else
+AM_CFLAGS = -Wall -Werror -Wextra -std=gnu99 \
+ $(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2)
+AM_LDFLAGS = -Wl,-rpath,\$$ORIGIN/../libasm:\$$ORIGIN/../libdw:\$$ORIGIN/../libebl:\$$ORIGIN/../libelf
+endif
+INCLUDES = -I$(top_srcdir)/libasm -I$(top_srcdir)/libdw \
+ -I$(top_srcdir)/libebl -I$(top_srcdir)/libelf \
+ -I$(top_srcdir)/lib -I..
+
+noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
+ showptable update1 update2 update3 update4 test-nlist \
+ show-die-info get-files get-lines get-pubnames \
+ get-aranges allfcts line2addr \
+ show-abbrev hash asm-tst1 asm-tst2 asm-tst3 \
+ asm-tst4 asm-tst5 asm-tst6 asm-tst7 asm-tst8 asm-tst9 \
+ msg_tst newscn ecp
+# get-ciefde
+
+TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
+ update1 update2 update3 update4 \
+ run-show-die-info.sh run-get-files.sh run-get-lines.sh \
+ run-get-pubnames.sh run-get-aranges.sh run-allfcts.sh \
+ run-show-abbrev.sh run-line2addr.sh hash asm-tst1 asm-tst2 \
+ asm-tst3 asm-tst4 asm-tst5 asm-tst6 asm-tst7 asm-tst8 asm-tst9 \
+ msg_tst newscn run-strip-test.sh run-strip-test2.sh \
+ run-strip-test3.sh run-strip-test4.sh run-strip-test5.sh \
+ run-strip-test6.sh run-ecp-test.sh run-ecp-test2.sh \
+ run-elflint-test.sh
+# run-show-ciefde.sh
+
+EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
+ run-show-die-info.sh run-get-files.sh run-get-lines.sh \
+ run-get-pubnames.sh run-get-aranges.sh \
+ run-show-ciefde.sh run-show-abbrev.sh run-strip-test.sh \
+ run-strip-test2.sh run-ecp-test.sh run-ecp-test2.sh \
+ testfile.bz2 testfile2.bz2 testfile3.bz2 testfile4.bz2 \
+ testfile5.bz2 testfile6.bz2 testfile7.bz2 testfile8.bz2 \
+ testfile9.bz2 testfile10.bz2 testfile11.bz2 testfile12.bz2 \
+ testfile13.bz2 run-strip-test3.sh run-allfcts.sh \
+ run-line2addr.sh run-elflint-test.sh testfile14.bz2 \
+ run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \
+ testfile15.bz2 testfile15.debug.bz2 \
+ testfile16.bz2 testfile16.debug.bz2 \
+ testfile17.bz2 testfile17.debug.bz2 \
+ testfile18.bz2
+
+if MUDFLAP
+libdw = ../libdw/libdw.a
+libelf = ../libelf/libelf.a
+libasm = ../libasm/libasm.a
+libmudflap = -lmudflap
+else
+libdw = ../libdw/libdw.so
+libelf = ../libelf/libelf.so
+libasm = ../libasm/libasm.so
+endif
+libebl = ../libebl/libebl.a
+
+arextract_LDADD = $(libelf) $(libmudflap)
+arsymtest_LDADD = $(libelf) $(libmudflap)
+newfile_LDADD = $(libelf) $(libmudflap)
+saridx_LDADD = $(libelf) $(libmudflap)
+scnnames_LDADD = $(libelf) $(libmudflap)
+sectiondump_LDADD = $(libelf) $(libmudflap)
+showptable_LDADD = $(libelf) $(libmudflap)
+hash_LDADD = $(libelf) $(libmudflap)
+test_nlist_LDADD = $(libelf) $(libmudflap)
+msg_tst_LDADD = $(libelf) $(libmudflap)
+newscn_LDADD = $(libelf) $(libmudflap)
+ecp_LDADD = $(libelf) $(libmudflap)
+update1_LDADD = $(libelf) $(libmudflap)
+update2_LDADD = $(libelf) $(libmudflap)
+update3_LDADD = $(libebl) $(libelf) $(libmudflap)
+update4_LDADD = $(libebl) $(libelf) $(libmudflap)
+show_die_info_LDADD = $(libdw) $(libelf) $(libmudflap)
+get_pubnames_LDADD = $(libdw) $(libelf) $(libmudflap)
+show_abbrev_LDADD = $(libdw) $(libelf) $(libmudflap)
+get_lines_LDADD = $(libdw) $(libelf) $(libmudflap)
+get_files_LDADD = $(libdw) $(libelf) $(libmudflap)
+get_aranges_LDADD = $(libdw) $(libelf) $(libmudflap)
+allfcts_LDADD = $(libdw) $(libelf) $(libmudflap)
+line2addr_no_Wformat = yes
+line2addr_LDADD = $(libdw) $(libelf) $(libmudflap)
+#show_ciefde_LDADD = ../libdwarf/libdwarf.so $(libelf) $(libmudflap)
+asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst3_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst4_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst5_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst6_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst7_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst8_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+asm_tst9_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap)
+
+CLEANFILES = xxx
diff --git a/tests/allfcts.c b/tests/allfcts.c
new file mode 100644
index 0000000..147ebc2
--- /dev/null
+++ b/tests/allfcts.c
@@ -0,0 +1,50 @@
+#include <fcntl.h>
+#include <libdw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int
+cb (Dwarf_Func *func, void *arg __attribute__ ((unused)))
+{
+ const char *file = dwarf_func_file (func);
+ int line = -1;
+ dwarf_func_line (func, &line);
+ const char *fct = dwarf_func_name (func);
+
+ printf ("%s:%d:%s\n", file, line, fct);
+
+ return DWARF_CB_OK;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ for (int i = 1; i < argc; ++i)
+ {
+ int fd = open (argv[i], O_RDONLY);
+
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg != NULL)
+ {
+ Dwarf_Off off = 0;
+ size_t cuhl;
+ Dwarf_Off noff;
+
+ while (dwarf_nextcu (dbg, off, &noff, &cuhl, NULL, NULL, NULL) == 0)
+ {
+ Dwarf_Die die_mem;
+ Dwarf_Die *die = dwarf_offdie (dbg, off + cuhl, &die_mem);
+
+ (void) dwarf_getfuncs (die, cb, NULL, 0);
+
+ off = noff;
+ }
+
+ dwarf_end (dbg);
+ }
+
+ close (fd);
+ }
+}
diff --git a/tests/arextract.c b/tests/arextract.c
new file mode 100644
index 0000000..aa86fb4
--- /dev/null
+++ b/tests/arextract.c
@@ -0,0 +1,155 @@
+/* Copyright (C) 1999, 2000, 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ int fd;
+ Elf *elf;
+ Elf *subelf;
+ Elf_Cmd cmd;
+ off_t offset;
+ size_t todo;
+
+ if (argc < 4)
+ exit (1);
+
+ /* Open the archive. */
+ fd = open (argv[1], O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("Cannot open input file: %m");
+ exit (1);
+ }
+
+ /* Set the ELF version. */
+ elf_version (EV_CURRENT);
+
+ /* Create an ELF descriptor. */
+ cmd = ELF_C_READ;
+ elf = elf_begin (fd, cmd, NULL);
+ if (elf == NULL)
+ {
+ printf ("Cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* If it is no archive punt. */
+ if (elf_kind (elf) != ELF_K_AR)
+ {
+ printf ("`%s' is no archive\n", argv[1]);
+ exit (1);
+ }
+
+ /* Get the elements of the archive one after the other. */
+ while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
+ {
+ /* The the header for this element. */
+ Elf_Arhdr *arhdr = elf_getarhdr (subelf);
+
+ if (arhdr == NULL)
+ {
+ printf ("cannot get arhdr: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (strcmp (arhdr->ar_name, argv[2]) == 0)
+ {
+ int outfd;
+
+ /* Get the offset of the file in the archive. */
+ offset = elf_getbase (subelf);
+ if (offset == -1)
+ {
+ printf ("\
+Failed to get base address for the archive element: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Open the output file. */
+ outfd = open (argv[3], O_CREAT | O_TRUNC | O_RDWR, 0666);
+ if (outfd == -1)
+ {
+ printf ("cannot open output file: %m");
+ exit (1);
+ }
+
+ /* Now write out the data. */
+ todo = arhdr->ar_size;
+ while (todo > 0)
+ {
+ char buf[1024];
+ ssize_t n = pread (fd, buf, MIN (sizeof buf, todo), offset);
+ if (n == 0)
+ break;
+
+ if (write (outfd, buf, n) != n)
+ {
+ puts ("Writing output failed");
+ exit (1);
+ }
+
+ offset += n;
+ todo -= n;
+ }
+
+ /* Check whether all the date was read and written out. */
+ if (todo != 0)
+ {
+ puts ("Reading archive member failed.");
+ exit (1);
+ }
+
+ /* Close the descriptors. */
+ if (elf_end (subelf) != 0 || elf_end (elf) != 0)
+ {
+ printf ("Freeing ELF descriptors failed: %s", elf_errmsg (-1));
+ exit (1);
+ }
+
+ close (outfd);
+ close (fd);
+
+ /* All went well. */
+ exit (0);
+ }
+
+ /* Get next archive element. */
+ cmd = elf_next (subelf);
+ if (elf_end (subelf) != 0)
+ {
+ printf ("error while freeing sub-ELF descriptor: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+ }
+
+ /* When we reach this point we haven't found the given file in the
+ archive. */
+ printf ("File `%s' not found in archive\n", argv[2]);
+ exit (1);
+}
diff --git a/tests/arsymtest.c b/tests/arsymtest.c
new file mode 100644
index 0000000..e4c2cf0
--- /dev/null
+++ b/tests/arsymtest.c
@@ -0,0 +1,132 @@
+/* Copyright (C) 1999, 2000, 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <fcntl.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ int fd;
+ FILE *fp;
+ Elf *elf;
+ Elf_Arsym *arsym;
+ size_t narsym;
+
+ if (argc < 3)
+ exit (1);
+
+ /* Open the archive. */
+ fd = open (argv[1], O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("Cannot open input file: %m");
+ exit (1);
+ }
+
+ /* Open the output file. */
+ fp = fopen (argv[2], "w");
+ if (fp == NULL)
+ {
+ printf ("Cannot open output file: %m");
+ exit (1);
+ }
+
+ /* Set the ELF version. */
+ elf_version (EV_CURRENT);
+
+ /* Create an ELF descriptor. */
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("Cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* If it is no archive punt. */
+ if (elf_kind (elf) != ELF_K_AR)
+ {
+ printf ("`%s' is no archive\n", argv[1]);
+ exit (1);
+ }
+
+ /* Now get the index of the archive. */
+ arsym = elf_getarsym (elf, &narsym);
+ if (arsym == NULL)
+ {
+ printf ("Cannot get archive index: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* If there is no element in the index do nothing. There always is
+ an empty entry at the end which is included in the count and
+ which we want to skip. */
+ if (narsym-- > 1)
+ while (narsym-- > 0)
+ {
+ Elf *subelf;
+ Elf_Arhdr *arhdr;
+
+ if (elf_rand (elf, arsym[narsym].as_off) != arsym[narsym].as_off)
+ {
+ printf ("random access for symbol `%s' fails: %s\n",
+ arsym[narsym].as_name, elf_errmsg (-1));
+ exit (1);
+ }
+
+ subelf = elf_begin (fd, ELF_C_READ, elf);
+ if (subelf == NULL)
+ {
+ printf ("Cannot create ELF descriptor for archive member: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+
+ arhdr = elf_getarhdr (subelf);
+ if (arhdr == NULL)
+ {
+ printf ("Cannot get archive header for element `%s': %s\n",
+ arsym[narsym].as_name, elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Now print what we actually want. */
+ fprintf (fp, "%s in %s\n", arsym[narsym].as_name, arhdr->ar_name);
+
+ /* Free the ELF descriptor. */
+ if (elf_end (subelf) != 0)
+ {
+ printf ("Error while freeing subELF descriptor: %s\n",
+ elf_errmsg (-1));
+ exit (1);
+ }
+ }
+
+ /* Free the ELF descriptor. */
+ if (elf_end (elf) != 0)
+ {
+ printf ("Error while freeing ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ close (fd);
+ fclose (fp);
+
+ return 0;
+}
diff --git a/tests/asm-tst1.c b/tests/asm-tst1.c
new file mode 100644
index 0000000..b76930d
--- /dev/null
+++ b/tests/asm-tst1.c
@@ -0,0 +1,239 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static const char fname[] = "asm-tst1-out.o";
+
+
+static const GElf_Ehdr expected_ehdr =
+ {
+ .e_ident = { [EI_MAG0] = ELFMAG0,
+ [EI_MAG1] = ELFMAG1,
+ [EI_MAG2] = ELFMAG2,
+ [EI_MAG3] = ELFMAG3,
+ [EI_CLASS] = ELFCLASS32,
+ [EI_DATA] = ELFDATA2LSB,
+ [EI_VERSION] = EV_CURRENT },
+ .e_type = ET_REL,
+ .e_machine = EM_386,
+ .e_version = EV_CURRENT,
+ .e_shoff = 88,
+ .e_ehsize = sizeof (Elf32_Ehdr),
+ .e_shentsize = sizeof (Elf32_Shdr),
+ .e_shnum = 4,
+ .e_shstrndx = 3
+ };
+
+
+static const char *scnnames[4] =
+ {
+ [0] = "",
+ [1] = ".text",
+ [2] = ".data",
+ [3] = ".shstrtab"
+ };
+
+
+int
+main (void)
+{
+ AsmCtx_t *ctx;
+ AsmScn_t *scn1;
+ AsmScn_t *scn2;
+ int fd;
+ Elf *elf;
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr;
+ int result = 0;
+ size_t cnt;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ /* Create two sections. */
+ scn1 = asm_newscn (ctx, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
+ scn2 = asm_newscn (ctx, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ if (scn1 == NULL || scn2 == NULL)
+ {
+ printf ("cannot create section in output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Special alignment for the .text section. */
+ if (asm_align (scn1, 32) != 0)
+ {
+ printf ("cannot align .text section: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Check the file. */
+ fd = open (fname, O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open generated file: %m\n");
+ result = 1;
+ goto out;
+ }
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close;
+ }
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ puts ("not a valid ELF file");
+ result = 1;
+ goto out_close2;
+ }
+
+ ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ {
+ printf ("cannot get ELF header: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close2;
+ }
+
+ if (memcmp (ehdr, &expected_ehdr, sizeof (GElf_Ehdr)) != 0)
+ {
+ puts ("ELF header does not match");
+ result = 1;
+ goto out_close2;
+ }
+
+ for (cnt = 1; cnt < 4; ++cnt)
+ {
+ Elf_Scn *scn;
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr;
+
+ scn = elf_getscn (elf, cnt);
+ if (scn == NULL)
+ {
+ printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get section header for section %Zd: %s\n",
+ cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ if (strcmp (elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]) != 0)
+ {
+ printf ("section %Zd's name differs: %s vs %s\n", cnt,
+ elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]);
+ result = 1;
+ }
+
+ if (shdr->sh_type != (cnt == 3 ? SHT_STRTAB : SHT_PROGBITS))
+ {
+ printf ("section %Zd's type differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_flags != (SHF_ALLOC | SHF_EXECINSTR))
+ || (cnt == 2 && shdr->sh_flags != (SHF_ALLOC | SHF_WRITE))
+ || (cnt == 3 && shdr->sh_flags != 0))
+ {
+ printf ("section %Zd's flags differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_addr != 0)
+ {
+ printf ("section %Zd's address differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_offset != ((sizeof (Elf32_Ehdr) + 31) & ~31))
+ {
+ printf ("section %Zd's offset differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt != 3 && shdr->sh_size != 0)
+ || (cnt == 3 && shdr->sh_size != 23))
+ {
+ printf ("section %Zd's size differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_link != 0)
+ {
+ printf ("section %Zd's link differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_info != 0)
+ {
+ printf ("section %Zd's info differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_addralign != 32)
+ || (cnt != 1 && shdr->sh_addralign != 1))
+ {
+ printf ("section %Zd's addralign differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_entsize != 0)
+ {
+ printf ("section %Zd's entsize differs\n", cnt);
+ result = 1;
+ }
+ }
+
+ out_close2:
+ elf_end (elf);
+ out_close:
+ close (fd);
+ out:
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst2.c b/tests/asm-tst2.c
new file mode 100644
index 0000000..a309976
--- /dev/null
+++ b/tests/asm-tst2.c
@@ -0,0 +1,261 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static const char fname[] = "asm-tst2-out.o";
+
+
+static const GElf_Ehdr expected_ehdr =
+ {
+ .e_ident = { [EI_MAG0] = ELFMAG0,
+ [EI_MAG1] = ELFMAG1,
+ [EI_MAG2] = ELFMAG2,
+ [EI_MAG3] = ELFMAG3,
+ [EI_CLASS] = ELFCLASS32,
+ [EI_DATA] = ELFDATA2LSB,
+ [EI_VERSION] = EV_CURRENT },
+ .e_type = ET_REL,
+ .e_machine = EM_386,
+ .e_version = EV_CURRENT,
+ .e_shoff = 96,
+ .e_ehsize = sizeof (Elf32_Ehdr),
+ .e_shentsize = sizeof (Elf32_Shdr),
+ .e_shnum = 3,
+ .e_shstrndx = 2
+ };
+
+
+static const char *scnnames[3] =
+ {
+ [0] = "",
+ [1] = ".data",
+ [2] = ".shstrtab"
+ };
+
+
+int
+main (void)
+{
+ AsmCtx_t *ctx;
+ AsmScn_t *scn1;
+ AsmScn_t *scn2;
+ int result = 0;
+ int fd;
+ Elf *elf;
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr;
+ size_t cnt;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ /* Create two sections. */
+ scn1 = asm_newscn (ctx, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ scn2 = asm_newsubscn (scn1, 1);
+ if (scn1 == NULL || scn2 == NULL)
+ {
+ printf ("cannot create section in output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Special alignment for the .text section. */
+ if (asm_align (scn1, 16) != 0)
+ {
+ printf ("cannot align .text section: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+
+ /* Add a few strings. */
+ if (asm_addstrz (scn1, "one", 4) != 0)
+ {
+ printf ("cannot insert first string: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+ if (asm_addstrz (scn2, "three", 0) != 0)
+ {
+ printf ("cannot insert second string: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+ if (asm_addstrz (scn1, "two", 4) != 0)
+ {
+ printf ("cannot insert third string: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Check the file. */
+ fd = open (fname, O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open generated file: %m\n");
+ result = 1;
+ goto out;
+ }
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close;
+ }
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ puts ("not a valid ELF file");
+ result = 1;
+ goto out_close2;
+ }
+
+ ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ {
+ printf ("cannot get ELF header: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close2;
+ }
+
+ if (memcmp (ehdr, &expected_ehdr, sizeof (GElf_Ehdr)) != 0)
+ {
+ puts ("ELF header does not match");
+ result = 1;
+ goto out_close2;
+ }
+
+ for (cnt = 1; cnt < 3; ++cnt)
+ {
+ Elf_Scn *scn;
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr;
+
+ scn = elf_getscn (elf, cnt);
+ if (scn == NULL)
+ {
+ printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get section header for section %Zd: %s\n",
+ cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ if (strcmp (elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]) != 0)
+ {
+ printf ("section %Zd's name differs: %s vs %s\n", cnt,
+ elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]);
+ result = 1;
+ }
+
+ if (shdr->sh_type != (cnt == 2 ? SHT_STRTAB : SHT_PROGBITS))
+ {
+ printf ("section %Zd's type differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_flags != (SHF_ALLOC | SHF_WRITE))
+ || (cnt == 2 && shdr->sh_flags != 0))
+ {
+ printf ("section %Zd's flags differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_addr != 0)
+ {
+ printf ("section %Zd's address differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_offset != ((sizeof (Elf32_Ehdr) + 15) & ~15))
+ || (cnt == 2
+ && shdr->sh_offset != (((sizeof (Elf32_Ehdr) + 15) & ~15)
+ + strlen ("one") + 1
+ + strlen ("two") + 1
+ + strlen ("three") + 1)))
+ {
+ printf ("section %Zd's offset differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_size != (strlen ("one") + 1
+ + strlen ("two") + 1
+ + strlen ("three") + 1))
+ || (cnt == 2 && shdr->sh_size != 17))
+ {
+ printf ("section %Zd's size differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_link != 0)
+ {
+ printf ("section %Zd's link differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_info != 0)
+ {
+ printf ("section %Zd's info differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_addralign != 16)
+ || (cnt != 1 && shdr->sh_addralign != 1))
+ {
+ printf ("section %Zd's addralign differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_entsize != 0)
+ {
+ printf ("section %Zd's entsize differs\n", cnt);
+ result = 1;
+ }
+ }
+
+ out_close2:
+ elf_end (elf);
+ out_close:
+ close (fd);
+ out:
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst3.c b/tests/asm-tst3.c
new file mode 100644
index 0000000..fb79ea7
--- /dev/null
+++ b/tests/asm-tst3.c
@@ -0,0 +1,322 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static const char fname[] = "asm-tst3-out.o";
+
+
+static const char *scnnames[5] =
+ {
+ [0] = "",
+ [1] = ".data",
+ [2] = ".strtab",
+ [3] = ".symtab",
+ [4] = ".shstrtab"
+ };
+
+
+static unsigned int scntypes[5] =
+ {
+ [0] = SHT_NULL,
+ [1] = SHT_PROGBITS,
+ [2] = SHT_STRTAB,
+ [3] = SHT_SYMTAB,
+ [4] = SHT_STRTAB
+ };
+
+
+int
+main (void)
+{
+ AsmCtx_t *ctx;
+ AsmScn_t *scn1;
+ AsmScn_t *scn2;
+ int result = 0;
+ int fd;
+ Elf *elf;
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr;
+ size_t cnt;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ /* Create two sections. */
+ scn1 = asm_newscn (ctx, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ scn2 = asm_newsubscn (scn1, 1);
+ if (scn1 == NULL || scn2 == NULL)
+ {
+ printf ("cannot create section in output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Special alignment for the .text section. */
+ if (asm_align (scn1, 16) != 0)
+ {
+ printf ("cannot align .text section: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+
+ /* Add a few strings with names. */
+ if (asm_newsym (scn1, "one", 4, STT_OBJECT, STB_GLOBAL) == NULL)
+ {
+ printf ("cannot create first name: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+ if (asm_addstrz (scn1, "one", 4) != 0)
+ {
+ printf ("cannot insert first string: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+ if (asm_newsym (scn2, "three", 6, STT_OBJECT, STB_WEAK) == NULL)
+ {
+ printf ("cannot create second name: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+ if (asm_addstrz (scn2, "three", 0) != 0)
+ {
+ printf ("cannot insert second string: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+ if (asm_newsym (scn1, "two", 4, STT_OBJECT, STB_LOCAL) == NULL)
+ {
+ printf ("cannot create third name: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+ if (asm_addstrz (scn1, "two", 4) != 0)
+ {
+ printf ("cannot insert third string: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Check the file. */
+ fd = open (fname, O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open generated file: %m\n");
+ result = 1;
+ goto out;
+ }
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close;
+ }
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ puts ("not a valid ELF file");
+ result = 1;
+ goto out_close2;
+ }
+
+ ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ {
+ printf ("cannot get ELF header: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close2;
+ }
+
+ for (cnt = 1; cnt < 5; ++cnt)
+ {
+ Elf_Scn *scn;
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr;
+
+ scn = elf_getscn (elf, cnt);
+ if (scn == NULL)
+ {
+ printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get section header for section %Zd: %s\n",
+ cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ if (strcmp (elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]) != 0)
+ {
+ printf ("section %Zd's name differs: %s vs %s\n", cnt,
+ elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]);
+ result = 1;
+ }
+
+ if (shdr->sh_type != scntypes[cnt])
+ {
+ printf ("section %Zd's type differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_flags != (SHF_ALLOC | SHF_WRITE))
+ || (cnt != 1 && shdr->sh_flags != 0))
+ {
+ printf ("section %Zd's flags differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_addr != 0)
+ {
+ printf ("section %Zd's address differs\n", cnt);
+ result = 1;
+ }
+
+ if (cnt == 3)
+ {
+ Elf_Data *data;
+
+ if (shdr->sh_link != 2)
+ {
+ puts ("symbol table has incorrect link");
+ result = 1;
+ }
+
+ data = elf_getdata (scn, NULL);
+ if (data == NULL)
+ {
+ puts ("cannot get data of symbol table");
+ result = 1;
+ }
+ else
+ {
+ size_t inner;
+
+ for (inner = 1;
+ inner < (shdr->sh_size
+ / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
+ ++inner)
+ {
+ GElf_Sym sym_mem;
+ GElf_Sym *sym;
+
+ sym = gelf_getsym (data, inner, &sym_mem);
+ if (sym == NULL)
+ {
+ printf ("cannot get symbol %zu: %s\n",
+ inner, elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ /* The order of the third and fourth entry depends
+ on how the hash table is organized. */
+ static const char *names[4] =
+ {
+ [0] = "",
+ [1] = "two",
+ [2] = "one",
+ [3] = "three"
+ };
+ static const int info[4] =
+ {
+ [0] = GELF_ST_INFO (STB_LOCAL, STT_NOTYPE),
+ [1] = GELF_ST_INFO (STB_LOCAL, STT_OBJECT),
+ [2] = GELF_ST_INFO (STB_GLOBAL, STT_OBJECT),
+ [3] = GELF_ST_INFO (STB_WEAK, STT_OBJECT)
+ };
+ static const unsigned value[4] =
+ {
+ [0] = 0,
+ [1] = 4,
+ [2] = 0,
+ [3] = 8
+ };
+
+ if (strcmp (names[inner],
+ elf_strptr (elf, shdr->sh_link,
+ sym->st_name)) != 0)
+ {
+ printf ("symbol %zu has different name\n", inner);
+ result = 1;
+ }
+
+ if (sym->st_value != value[inner])
+ {
+ printf ("symbol %zu has wrong value\n", inner);
+ result = 1;
+ }
+
+ if (sym->st_other != 0)
+ {
+ printf ("symbol %zu has wrong other info\n", inner);
+ result = 1;
+ }
+
+ if (sym->st_shndx != 1)
+ {
+ printf ("symbol %zu has wrong section reference\n",
+ inner);
+ result = 1;
+ }
+
+ if (sym->st_info != info[inner])
+ {
+ printf ("symbol %zu has wrong type or binding\n",
+ inner);
+ result = 1;
+ }
+
+ if ((inner != 3 && sym->st_size != 4)
+ || (inner == 3 && sym->st_size != 6))
+ {
+ printf ("symbol %zu has wrong size\n", inner);
+ result = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ out_close2:
+ elf_end (elf);
+ out_close:
+ close (fd);
+ out:
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst4.c b/tests/asm-tst4.c
new file mode 100644
index 0000000..29d6485
--- /dev/null
+++ b/tests/asm-tst4.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 2002, 2004 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static const char fname[] = "asm-tst4-out.o";
+
+
+int
+main (void)
+{
+ AsmCtx_t *ctx;
+ int result = 0;
+ size_t cnt;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ /* Create 66000 sections. */
+ for (cnt = 0; cnt < 66000; ++cnt)
+ {
+ char buf[20];
+ AsmScn_t *scn;
+
+ /* Create a unique name. */
+ snprintf (buf, sizeof (buf), ".data.%Zu", cnt);
+
+ /* Create the section. */
+ scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ if (scn == NULL)
+ {
+ printf ("cannot create section \"%s\" in output file: %s\n",
+ buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Add some content. */
+ if (asm_adduint32 (scn, cnt) != 0)
+ {
+ printf ("cannot create content of section \"%s\": %s\n",
+ buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ if (result == 0)
+ result = WEXITSTATUS (system ("\
+env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst4-out.o"));
+
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst5.c b/tests/asm-tst5.c
new file mode 100644
index 0000000..4f761ae
--- /dev/null
+++ b/tests/asm-tst5.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2002, 2004 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include "system.h"
+
+
+static const char fname[] = "asm-tst5-out.o";
+
+
+int
+main (void)
+{
+ AsmCtx_t *ctx;
+ int result = 0;
+ size_t cnt;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ /* Create 66000 sections. */
+ for (cnt = 0; cnt < 66000; ++cnt)
+ {
+ char buf[20];
+ AsmScn_t *scn;
+
+ /* Create a unique name. */
+ snprintf (buf, sizeof (buf), ".data.%Zu", cnt);
+
+ /* Create the section. */
+ scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ if (scn == NULL)
+ {
+ printf ("cannot create section \"%s\" in output file: %s\n",
+ buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Add a name. */
+ snprintf (buf, sizeof (buf), "%Zu", cnt);
+ if (asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT,
+ STB_GLOBAL) == NULL)
+ {
+ printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Add some content. */
+ if (asm_adduint32 (scn, cnt) != 0)
+ {
+ printf ("cannot create content of section \"%s\": %s\n",
+ buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ if (result == 0)
+ result = WEXITSTATUS (system ("\
+env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst5-out.o"));
+
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst6.c b/tests/asm-tst6.c
new file mode 100644
index 0000000..ece69bc
--- /dev/null
+++ b/tests/asm-tst6.c
@@ -0,0 +1,134 @@
+/* Copyright (C) 2002, 2004 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include <system.h>
+
+
+static const char fname[] = "asm-tst6-out.o";
+
+
+int
+main (void)
+{
+ AsmCtx_t *ctx;
+ int result = 0;
+ size_t cnt;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ for (cnt = 0; cnt < 22000; ++cnt)
+ {
+ char buf[512];
+ AsmScnGrp_t *grp;
+ AsmScn_t *scn;
+ AsmSym_t *sym;
+
+ snprintf (buf, sizeof (buf), ".grp%Zu", cnt);
+ grp = asm_newscngrp (ctx, buf, NULL, 0);
+ if (grp == NULL)
+ {
+ printf ("cannot section group %Zu: %s\n", cnt, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ scn = asm_newscn_ingrp (ctx, ".data", SHT_PROGBITS,
+ SHF_ALLOC | SHF_WRITE, grp);
+ if (scn == NULL)
+ {
+ printf ("cannot data section for group %Zu: %s\n",
+ cnt, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Add a name. */
+ snprintf (buf, sizeof (buf), "%Zu", cnt);
+ sym = asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT,
+ STB_GLOBAL);
+ if (sym == NULL)
+ {
+ printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Add some content. */
+ if (asm_adduint32 (scn, cnt) != 0)
+ {
+ printf ("cannot create content of section \"%s\": %s\n",
+ buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Now we have a symbol, use it as the signature. */
+ if (asm_scngrp_newsignature (grp, sym) != 0)
+ {
+ printf ("cannot set signature for section group %Zu: %s\n",
+ cnt, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Create a phony debug info section. */
+ scn = asm_newscn_ingrp (ctx, ".stab", SHT_PROGBITS, 0, grp);
+ if (scn == NULL)
+ {
+ printf ("cannot stab section for group %Zu: %s\n",
+ cnt, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Add some content. */
+ if (asm_adduint32 (scn, cnt) != 0)
+ {
+ printf ("cannot create content of section \"%s\": %s\n",
+ buf, asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ if (result == 0)
+ result = WEXITSTATUS (system ("\
+env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst6-out.o"));
+
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst7.c b/tests/asm-tst7.c
new file mode 100644
index 0000000..ebd4559
--- /dev/null
+++ b/tests/asm-tst7.c
@@ -0,0 +1,164 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static const char fname[] = "asm-tst7-out.o";
+
+
+int
+main (void)
+{
+ int result = 0;
+ size_t cnt;
+ AsmCtx_t *ctx;
+ Elf *elf;
+ int fd;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ if (asm_newcomsym (ctx, "commsym", 4, 16) == NULL)
+ {
+ printf ("cannot create common symbol: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Check the file. */
+ fd = open (fname, O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open generated file: %m\n");
+ result = 1;
+ goto out;
+ }
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close;
+ }
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ puts ("not a valid ELF file");
+ result = 1;
+ goto out_close2;
+ }
+
+ for (cnt = 1; 1; ++cnt)
+ {
+ Elf_Scn *scn;
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr;
+
+ scn = elf_getscn (elf, cnt);
+ if (scn == NULL)
+ {
+ printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get section header for section %Zd: %s\n",
+ cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+ /* We are looking for the symbol table. */
+ if (shdr->sh_type != SHT_SYMTAB)
+ continue;
+
+ for (cnt = 1; cnt< (shdr->sh_size
+ / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
+ ++cnt)
+ {
+ GElf_Sym sym_mem;
+ GElf_Sym *sym;
+
+ if (cnt > 1)
+ {
+ puts ("too many symbol");
+ result = 1;
+ break;
+ }
+
+ sym = gelf_getsym (elf_getdata (scn, NULL), cnt, &sym_mem);
+ if (sym == NULL)
+ {
+ printf ("cannot get symbol %zu: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ if (sym->st_shndx != SHN_COMMON)
+ {
+ printf ("expected common symbol, got section %u\n",
+ (unsigned int) sym->st_shndx);
+ result = 1;
+ }
+
+ if (sym->st_value != 16)
+ {
+ printf ("requested alignment 16, is %" PRIuMAX "\n",
+ (uintmax_t) sym->st_value);
+ result = 1;
+ }
+
+ if (sym->st_size != 4)
+ {
+ printf ("requested size 4, is %" PRIuMAX "\n",
+ (uintmax_t) sym->st_value);
+ result = 1;
+ }
+ }
+ }
+
+ break;
+ }
+
+ out_close2:
+ elf_end (elf);
+ out_close:
+ close (fd);
+ out:
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst8.c b/tests/asm-tst8.c
new file mode 100644
index 0000000..6ce7c9c
--- /dev/null
+++ b/tests/asm-tst8.c
@@ -0,0 +1,172 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static const char fname[] = "asm-tst8-out.o";
+
+
+int
+main (void)
+{
+ int result = 0;
+ size_t cnt;
+ AsmCtx_t *ctx;
+ Elf *elf;
+ int fd;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ if (asm_newabssym (ctx, "tst8-out.s", 4, 0xfeedbeef, STT_FILE, STB_LOCAL)
+ == NULL)
+ {
+ printf ("cannot create absolute symbol: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Check the file. */
+ fd = open (fname, O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open generated file: %m\n");
+ result = 1;
+ goto out;
+ }
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close;
+ }
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ puts ("not a valid ELF file");
+ result = 1;
+ goto out_close2;
+ }
+
+ for (cnt = 1; 1; ++cnt)
+ {
+ Elf_Scn *scn;
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr;
+
+ scn = elf_getscn (elf, cnt);
+ if (scn == NULL)
+ {
+ printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get section header for section %Zd: %s\n",
+ cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+ /* We are looking for the symbol table. */
+ if (shdr->sh_type != SHT_SYMTAB)
+ continue;
+
+ for (cnt = 1; cnt< (shdr->sh_size
+ / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
+ ++cnt)
+ {
+ GElf_Sym sym_mem;
+ GElf_Sym *sym;
+
+ if (cnt > 1)
+ {
+ puts ("too many symbol");
+ result = 1;
+ break;
+ }
+
+ sym = gelf_getsym (elf_getdata (scn, NULL), cnt, &sym_mem);
+ if (sym == NULL)
+ {
+ printf ("cannot get symbol %zu: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ if (sym->st_shndx != SHN_ABS)
+ {
+ printf ("expected common symbol, got section %u\n",
+ (unsigned int) sym->st_shndx);
+ result = 1;
+ }
+
+ if (sym->st_value != 0xfeedbeef)
+ {
+ printf ("requested value 0xfeedbeef, is %#" PRIxMAX "\n",
+ (uintmax_t) sym->st_value);
+ result = 1;
+ }
+
+ if (sym->st_size != 4)
+ {
+ printf ("requested size 4, is %" PRIuMAX "\n",
+ (uintmax_t) sym->st_value);
+ result = 1;
+ }
+
+ if (GELF_ST_TYPE (sym->st_info) != STT_FILE)
+ {
+ printf ("requested type FILE, is %u\n",
+ (unsigned int) GELF_ST_TYPE (sym->st_info));
+ result = 1;
+ }
+ }
+ }
+
+ break;
+ }
+
+ out_close2:
+ elf_end (elf);
+ out_close:
+ close (fd);
+ out:
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/asm-tst9.c b/tests/asm-tst9.c
new file mode 100644
index 0000000..28bb478
--- /dev/null
+++ b/tests/asm-tst9.c
@@ -0,0 +1,318 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libasm.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static const char fname[] = "asm-tst9-out.o";
+
+
+static int32_t input[] =
+ {
+ 0, 1, 129, 510, 2000, 33000, 0x7ffffff, 0x7fffffff
+ };
+#define ninput (sizeof (input) / sizeof (input[0]))
+
+
+static const GElf_Ehdr expected_ehdr =
+ {
+ .e_ident = { [EI_MAG0] = ELFMAG0,
+ [EI_MAG1] = ELFMAG1,
+ [EI_MAG2] = ELFMAG2,
+ [EI_MAG3] = ELFMAG3,
+ [EI_CLASS] = ELFCLASS32,
+ [EI_DATA] = ELFDATA2LSB,
+ [EI_VERSION] = EV_CURRENT },
+ .e_type = ET_REL,
+ .e_machine = EM_386,
+ .e_version = EV_CURRENT,
+ .e_shoff = 180,
+ .e_ehsize = sizeof (Elf32_Ehdr),
+ .e_shentsize = sizeof (Elf32_Shdr),
+ .e_shnum = 3,
+ .e_shstrndx = 2
+ };
+
+
+static const char *scnnames[3] =
+ {
+ [0] = "",
+ [1] = ".data",
+ [2] = ".shstrtab"
+ };
+
+
+static const char expecteddata[] =
+ {
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x7f,
+ 0x81, 0x01, 0x81, 0x01, 0xff, 0xfe, 0xff, 0xff, 0x0f, 0xff, 0x7e, 0xfe,
+ 0x03, 0xfe, 0x03, 0x82, 0xfc, 0xff, 0xff, 0x0f, 0x82, 0x7c, 0xd0, 0x0f,
+ 0xd0, 0x0f, 0xb0, 0xf0, 0xff, 0xff, 0x0f, 0xb0, 0x70, 0xe8, 0x81, 0x02,
+ 0xe8, 0x81, 0x02, 0x98, 0xfe, 0xfd, 0xff, 0x0f, 0x98, 0xfe, 0x7d, 0xff,
+ 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0x81, 0x80, 0x80, 0xc0, 0x0f,
+ 0x81, 0x80, 0x80, 0x40, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff,
+ 0xff, 0x07, 0x81, 0x80, 0x80, 0x80, 0x08, 0x81, 0x80, 0x80, 0x80, 0x78
+ };
+
+
+int
+main (void)
+{
+ AsmCtx_t *ctx;
+ AsmScn_t *scn;
+ int result = 0;
+ int fd;
+ Elf *elf;
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr;
+ size_t cnt;
+
+ elf_version (EV_CURRENT);
+
+ ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
+ if (ctx == NULL)
+ {
+ printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
+ return 1;
+ }
+
+ /* Create two sections. */
+ scn = asm_newscn (ctx, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ if (scn == NULL)
+ {
+ printf ("cannot create section in output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Special alignment for the .text section. */
+ if (asm_align (scn, 16) != 0)
+ {
+ printf ("cannot align .text section: %s\n", asm_errmsg (-1));
+ result = 1;
+ }
+
+ /* Add a few ULEB128 and SLEB128 numbers. */
+ for (cnt = 0; cnt < ninput; ++cnt)
+ {
+ if (asm_adduleb128 (scn, input[cnt]) != 0)
+ {
+ printf ("cannot insert uleb %" PRIu32 ": %s\n",
+ (uint32_t) input[cnt], asm_errmsg (-1));
+ result = 1;
+ }
+
+ if (asm_addsleb128 (scn, input[cnt]) != 0)
+ {
+ printf ("cannot insert sleb %" PRId32 ": %s\n",
+ input[cnt], asm_errmsg (-1));
+ result = 1;
+ }
+
+ if (asm_adduleb128 (scn, -input[cnt]) != 0)
+ {
+ printf ("cannot insert uleb %" PRIu32 ": %s\n",
+ (uint32_t) -input[cnt], asm_errmsg (-1));
+ result = 1;
+ }
+
+ if (asm_addsleb128 (scn, -input[cnt]) != 0)
+ {
+ printf ("cannot insert sleb %" PRId32 ": %s\n",
+ -input[cnt], asm_errmsg (-1));
+ result = 1;
+ }
+ }
+
+ /* Create the output file. */
+ if (asm_end (ctx) != 0)
+ {
+ printf ("cannot create output file: %s\n", asm_errmsg (-1));
+ asm_abort (ctx);
+ return 1;
+ }
+
+ /* Check the file. */
+ fd = open (fname, O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open generated file: %m\n");
+ result = 1;
+ goto out;
+ }
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close;
+ }
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ puts ("not a valid ELF file");
+ result = 1;
+ goto out_close2;
+ }
+
+ ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ {
+ printf ("cannot get ELF header: %s\n", elf_errmsg (-1));
+ result = 1;
+ goto out_close2;
+ }
+
+ if (memcmp (ehdr, &expected_ehdr, sizeof (GElf_Ehdr)) != 0)
+ {
+ puts ("ELF header does not match");
+ result = 1;
+ goto out_close2;
+ }
+
+ for (cnt = 1; cnt < 3; ++cnt)
+ {
+ Elf_Scn *scn;
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr;
+
+ scn = elf_getscn (elf, cnt);
+ if (scn == NULL)
+ {
+ printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ {
+ printf ("cannot get section header for section %Zd: %s\n",
+ cnt, elf_errmsg (-1));
+ result = 1;
+ continue;
+ }
+
+ if (strcmp (elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]) != 0)
+ {
+ printf ("section %Zd's name differs: %s vs %s\n", cnt,
+ elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ scnnames[cnt]);
+ result = 1;
+ }
+
+ if (shdr->sh_type != (cnt == 2 ? SHT_STRTAB : SHT_PROGBITS))
+ {
+ printf ("section %Zd's type differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_flags != (SHF_ALLOC | SHF_WRITE))
+ || (cnt == 2 && shdr->sh_flags != 0))
+ {
+ printf ("section %Zd's flags differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_addr != 0)
+ {
+ printf ("section %Zd's address differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_offset != ((sizeof (Elf32_Ehdr) + 15) & ~15))
+ || (cnt == 2
+ && shdr->sh_offset != (((sizeof (Elf32_Ehdr) + 15) & ~15)
+ + sizeof (expecteddata))))
+ {
+ printf ("section %Zd's offset differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_size != sizeof (expecteddata))
+ || (cnt == 2 && shdr->sh_size != 17))
+ {
+ printf ("section %Zd's size differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_link != 0)
+ {
+ printf ("section %Zd's link differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_info != 0)
+ {
+ printf ("section %Zd's info differs\n", cnt);
+ result = 1;
+ }
+
+ if ((cnt == 1 && shdr->sh_addralign != 16)
+ || (cnt != 1 && shdr->sh_addralign != 1))
+ {
+ printf ("section %Zd's addralign differs\n", cnt);
+ result = 1;
+ }
+
+ if (shdr->sh_entsize != 0)
+ {
+ printf ("section %Zd's entsize differs\n", cnt);
+ result = 1;
+ }
+
+ if (cnt == 1)
+ {
+ Elf_Data *data = elf_getdata (scn, NULL);
+
+ if (data == NULL)
+ {
+ printf ("cannot get data of section %Zd\n", cnt);
+ result = 1;
+ }
+ else
+ {
+ if (data->d_size != sizeof (expecteddata))
+ {
+ printf ("data block size of section %Zd wrong: got %Zd, "
+ "expected 96\n", cnt, data->d_size);
+ result = 1;
+ }
+
+ if (memcmp (data->d_buf, expecteddata, sizeof (expecteddata))
+ != 0)
+ {
+ printf ("data block content of section %Zd wrong\n", cnt);
+ result = 1;
+ }
+ }
+ }
+ }
+
+ out_close2:
+ elf_end (elf);
+ out_close:
+ close (fd);
+ out:
+ /* We don't need the file anymore. */
+ unlink (fname);
+
+ return result;
+}
diff --git a/tests/ecp.c b/tests/ecp.c
new file mode 100644
index 0000000..15bc71c
--- /dev/null
+++ b/tests/ecp.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <errno.h>
+#include <error.h>
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main (int argc, char *argv[])
+{
+ if (argc < 3)
+ error (EXIT_FAILURE, 0, "usage: %s FROMNAME TONAME", argv[0]);
+
+ elf_version (EV_CURRENT);
+
+ int infd = open (argv[1], O_RDONLY);
+ if (infd == -1)
+ error (EXIT_FAILURE, errno, "cannot open input file '%s'", argv[1]);
+
+ Elf *inelf = elf_begin (infd, ELF_C_READ, NULL);
+ if (inelf == NULL)
+ error (EXIT_FAILURE, 0, "problems opening '%s' as ELF file: %s",
+ argv[1], elf_errmsg (-1));
+
+ int outfd = creat (argv[2], 0666);
+ if (outfd == -1)
+ error (EXIT_FAILURE, errno, "cannot open output file '%s'", argv[2]);
+
+ Elf *outelf = elf_begin (outfd, ELF_C_WRITE, NULL);
+ if (outelf == NULL)
+ error (EXIT_FAILURE, 0, "problems opening '%s' as ELF file: %s",
+ argv[2], elf_errmsg (-1));
+
+ gelf_newehdr (outelf, gelf_getclass (inelf));
+
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr;
+ gelf_update_ehdr (outelf, (ehdr = gelf_getehdr (inelf, &ehdr_mem)));
+
+ if (ehdr->e_phnum > 0)
+ {
+ int cnt;
+
+ if (gelf_newphdr (outelf, ehdr->e_phnum) == 0)
+ error (EXIT_FAILURE, 0, "cannot create program header: %s",
+ elf_errmsg (-1));
+
+ for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ {
+ GElf_Phdr phdr_mem;
+
+ gelf_update_phdr (outelf, cnt, gelf_getphdr (inelf, cnt, &phdr_mem));
+ }
+ }
+
+ Elf_Scn *scn = NULL;
+ while ((scn = elf_nextscn (inelf, scn)) != NULL)
+ {
+ Elf_Scn *newscn = elf_newscn (outelf);
+
+ GElf_Shdr shdr_mem;
+ gelf_update_shdr (newscn, gelf_getshdr (scn, &shdr_mem));
+
+ *elf_newdata (newscn) = *elf_getdata (scn, NULL);
+ }
+
+ elf_flagelf (outelf, ELF_C_SET, ELF_F_LAYOUT);
+
+ if (elf_update (outelf, ELF_C_WRITE) == -1)
+ error (EXIT_FAILURE, 0, "elf_update failed: %s", elf_errmsg (-1));
+
+ close (outfd);
+
+ return 0;
+}
diff --git a/tests/get-aranges.c b/tests/get-aranges.c
new file mode 100644
index 0000000..1be76b2
--- /dev/null
+++ b/tests/get-aranges.c
@@ -0,0 +1,134 @@
+/* Copyright (C) 2002, 2004 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libelf.h>
+#include <libdw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static const Dwarf_Addr testaddr[] =
+{
+ 0x804842b, 0x804842c, 0x804843c, 0x8048459, 0x804845a,
+ 0x804845b, 0x804845c, 0x8048460, 0x8048465, 0x8048466,
+ 0x8048467, 0x8048468, 0x8048470, 0x8048471, 0x8048472
+};
+#define ntestaddr (sizeof (testaddr) / sizeof (testaddr[0]))
+
+
+int
+main (int argc, char *argv[])
+{
+ int result = 0;
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable\n", argv[cnt]);
+ result = 1;
+ close (fd);
+ continue;
+ }
+
+ Dwarf_Aranges *aranges;
+ size_t naranges;
+ if (dwarf_getaranges (dbg, &aranges, &naranges) != 0)
+ printf ("%s: cannot get aranges\n", argv[cnt]);
+ else
+ {
+ for (size_t i = 0; i < ntestaddr; ++i)
+ {
+ Dwarf_Arange *found;
+
+ found = dwarf_getarange_addr (aranges, testaddr[i]);
+ if (found != NULL)
+ {
+ Dwarf_Off cu_offset;
+
+ if (dwarf_getarangeinfo (found, NULL, NULL, &cu_offset) != 0)
+ {
+ puts ("failed to get CU die offset");
+ result = 1;
+ }
+ else
+ {
+ const char *cuname;
+ Dwarf_Die cu_die;
+
+ if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
+ || (cuname = dwarf_diename (&cu_die)) == NULL)
+ {
+ puts ("failed to get CU die");
+ result = 1;
+ }
+ else
+ printf ("CU name: \"%s\"\n", cuname);
+ }
+ }
+ else
+ printf ("%#llx: not in range\n",
+ (unsigned long long int) testaddr[i]);
+ }
+
+ for (size_t i = 0; i < naranges; ++i)
+ {
+ Dwarf_Arange *arange = dwarf_onearange (aranges, i);
+ if (arange == NULL)
+ {
+ printf ("cannot get arange %zu: %s\n", i, dwarf_errmsg (-1));
+ break;
+ }
+
+ Dwarf_Addr start;
+ Dwarf_Word length;
+ Dwarf_Off cu_offset;
+
+ if (dwarf_getarangeinfo (arange, &start, &length, &cu_offset)
+ != 0)
+ {
+ printf ("cannot get info from aranges[%zu]\n", i);
+ result = 1;
+ }
+ else
+ {
+ printf (" [%2zu] start: %#llx, length: %llu, cu: %llu\n",
+ i, (unsigned long long int) start,
+ (unsigned long long int) length,
+ (unsigned long long int) cu_offset);
+
+ const char *cuname;
+ Dwarf_Die cu_die;
+ if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
+ || (cuname = dwarf_diename (&cu_die)) == NULL)
+ {
+ puts ("failed to get CU die");
+ result = 1;
+ }
+ else
+ printf ("CU name: \"%s\"\n", cuname);
+ }
+ }
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/tests/get-files.c b/tests/get-files.c
new file mode 100644
index 0000000..1294342
--- /dev/null
+++ b/tests/get-files.c
@@ -0,0 +1,83 @@
+/* Copyright (C) 2002, 2004, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libelf.h>
+#include <libdw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ int result = 0;
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable\n", argv[cnt]);
+ result = 1;
+ if (fd != -1)
+ close (fd);
+ continue;
+ }
+
+ Dwarf_Off o = 0;
+ Dwarf_Off ncu;
+ Dwarf_Off ao;
+ size_t cuhl;
+ uint8_t asz;
+ uint8_t osz;
+ while (dwarf_nextcu (dbg, o, &ncu, &cuhl, &ao, &asz, &osz) == 0)
+ {
+ printf ("cuhl = %zu, o = %llu, asz = %hhu, osz = %hhu, ncu = %llu\n",
+ cuhl, (unsigned long long int) ao,
+ asz, osz, (unsigned long long int) ncu);
+
+ Dwarf_Die die_mem;
+ Dwarf_Die *die = dwarf_offdie (dbg, o + cuhl, &die_mem);
+ if (die == NULL)
+ {
+ printf ("%s: cannot get CU die\n", argv[cnt]);
+ result = 1;
+ break;
+ }
+
+ Dwarf_Files *files;
+ size_t nfiles;
+ if (dwarf_getsrcfiles (die, &files, &nfiles) != 0)
+ {
+ printf ("%s: cannot get files\n", argv[cnt]);
+ result = 1;
+ break;
+ }
+
+ for (size_t i = 0; i < nfiles; ++i)
+ printf (" file[%zu] = \"%s\"\n", i,
+ dwarf_filesrc (files, i, NULL, NULL));
+
+ o = ncu;
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/tests/get-lines.c b/tests/get-lines.c
new file mode 100644
index 0000000..6a8c076
--- /dev/null
+++ b/tests/get-lines.c
@@ -0,0 +1,129 @@
+/* Copyright (C) 2002, 2004 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libelf.h>
+#include <libdw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ int result = 0;
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
+ close (fd);
+ continue;
+ }
+
+ Dwarf_Off cuoff = 0;
+ Dwarf_Off old_cuoff = 0;
+ size_t hsize;
+ Dwarf_Off ao;
+ uint8_t asz;
+ uint8_t osz;
+ while (dwarf_nextcu (dbg, cuoff, &cuoff, &hsize, &ao, &asz, &osz) == 0)
+ {
+ printf ("cuhl = %zu, o = %llu, asz = %hhu, osz = %hhu, ncu = %llu\n",
+ hsize, (unsigned long long int) ao,
+ asz, osz, (unsigned long long int) cuoff);
+
+ /* Get the DIE for the CU. */
+ Dwarf_Die die;
+ if (dwarf_offdie (dbg, old_cuoff + hsize, &die) == NULL)
+ {
+ /* Something went wrong. */
+ printf ("%s: cannot get CU die\n", argv[cnt]);
+ result = 1;
+ break;
+ }
+ old_cuoff = cuoff;
+
+ Dwarf_Lines *lb;
+ size_t nlb;
+ if (dwarf_getsrclines (&die, &lb, &nlb) != 0)
+ {
+ printf ("%s: cannot get lines\n", argv[cnt]);
+ result = 1;
+ break;
+ }
+
+ printf (" %zu lines\n", nlb);
+
+ for (size_t i = 0; i < nlb; ++i)
+ {
+ Dwarf_Line *l = dwarf_onesrcline (lb, i);
+ if (l == NULL)
+ {
+ printf ("%s: cannot get individual line\n", argv[cnt]);
+ result = 1;
+ break;
+ }
+
+ Dwarf_Addr addr;
+ if (dwarf_lineaddr (l, &addr) != 0)
+ addr = 0;
+ const char *file = dwarf_linesrc (l, NULL, NULL);
+ int line;
+ if (dwarf_lineno (l, &line) != 0)
+ line = 0;
+
+ printf ("%" PRIx64 ": %s:%d:", (uint64_t) addr,
+ file ?: "???", line);
+
+ int column;
+ if (dwarf_linecol (l, &column) != 0)
+ column = 0;
+ if (column >= 0)
+ printf ("%d:", column);
+
+ bool is_stmt;
+ if (dwarf_linebeginstatement (l, &is_stmt) != 0)
+ is_stmt = false;
+ bool end_sequence;
+ if (dwarf_lineendsequence (l, &end_sequence) != 0)
+ end_sequence = false;
+ bool basic_block;
+ if (dwarf_lineblock (l, &basic_block) != 0)
+ basic_block = false;
+ bool prologue_end;
+ if (dwarf_lineprologueend (l, &prologue_end) != 0)
+ prologue_end = false;
+ bool epilogue_begin;
+ if (dwarf_lineepiloguebegin (l, &epilogue_begin) != 0)
+ epilogue_begin = false;
+
+ printf (" is_stmt:%s, end_seq:%s, bb:%s, prologue:%s, epilogue:%s\n",
+ is_stmt ? "yes" : "no", end_sequence ? "yes" : "no",
+ basic_block ? "yes" : "no", prologue_end ? "yes" : "no",
+ epilogue_begin ? "yes" : "no");
+ }
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/tests/get-pubnames.c b/tests/get-pubnames.c
new file mode 100644
index 0000000..e2791a2
--- /dev/null
+++ b/tests/get-pubnames.c
@@ -0,0 +1,90 @@
+/* Copyright (C) 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <fcntl.h>
+#include <libelf.h>
+#include <libdw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int globcnt;
+
+static int
+callback (Dwarf *dbg, Dwarf_Global *gl, void *arg __attribute__ ((unused)))
+{
+ int result = DWARF_CB_OK;
+
+ printf (" [%2d] \"%s\", die: %llu, cu: %llu\n",
+ globcnt++, gl->name, (unsigned long long int) gl->die_offset,
+ (unsigned long long int) gl->cu_offset);
+
+ Dwarf_Die cu_die;
+ const char *cuname;
+ if (dwarf_offdie (dbg, gl->cu_offset, &cu_die) == NULL
+ || (cuname = dwarf_diename (&cu_die)) == NULL)
+ {
+ puts ("failed to get CU die");
+ result = DWARF_CB_ABORT;
+ }
+ else
+ printf ("CU name: \"%s\"\n", cuname);
+
+ const char *diename;
+ Dwarf_Die die;
+ if (dwarf_offdie (dbg, gl->die_offset, &die) == NULL
+ || (diename = dwarf_diename (&die)) == NULL)
+ {
+ puts ("failed to get object die");
+ result = DWARF_CB_ABORT;
+ }
+ else
+ printf ("object name: \"%s\"\n", diename);
+
+ return result;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int result = 0;
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
+ result = 1;
+ close (fd);
+ continue;
+ }
+
+ globcnt = 0;
+
+ if (dwarf_getpubnames (dbg, callback, NULL, 0) != 0)
+ {
+ printf ("dwarf_get_pubnames didn't return zero: %s\n",
+ dwarf_errmsg (-1));
+ result = 1;
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/tests/hash.c b/tests/hash.c
new file mode 100644
index 0000000..afe853b
--- /dev/null
+++ b/tests/hash.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <libelf.h>
+#include <stdio.h>
+
+
+static int
+check (const char *name, unsigned long int expected)
+{
+ unsigned long int actual = elf_hash (name);
+
+ return actual != expected;
+}
+
+
+int
+main (void)
+{
+ int status;
+
+ /* Check some names. We know what the expected result is. */
+ status = check ("_DYNAMIC", 165832675);
+ status |= check ("_GLOBAL_OFFSET_TABLE_", 102264335);
+
+ return status;
+}
diff --git a/tests/line2addr.c b/tests/line2addr.c
new file mode 100644
index 0000000..d2017fb
--- /dev/null
+++ b/tests/line2addr.c
@@ -0,0 +1,65 @@
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libdw.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ for (int cnt = 1; cnt < argc; ++cnt)
+ {
+ char *fname;
+ char *file;
+ int line;
+
+ switch (sscanf (argv[cnt], "%a[^:]:%a[^:]:%d",
+ &fname, &file, &line))
+ {
+ default:
+ case 0:
+ case 1:
+ printf ("ignored %s\n", argv[cnt]);
+ continue;
+ case 2:
+ line = 0;
+ break;
+ case 3:
+ break;
+ }
+
+ int fd = open (fname, O_RDONLY);
+ if (fd == -1)
+ continue;
+
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg != NULL)
+ {
+ Dwarf_Line **lines = NULL;
+ size_t nlines = 0;
+
+ if (dwarf_getsrc_file (dbg, file, line, 0, &lines, &nlines) == 0)
+ {
+ for (size_t inner = 0; inner < nlines; ++inner)
+ {
+ Dwarf_Addr addr;
+ if (dwarf_lineaddr (lines[inner], &addr) == 0)
+ printf ("%s -> %#" PRIxMAX "\n",
+ argv[cnt], (uintmax_t) addr);
+ }
+
+ free (lines);
+ }
+
+ dwarf_end (dbg);
+ }
+
+ close (fd);
+ free (fname);
+ free (file);
+ }
+
+ return 0;
+}
diff --git a/tests/msg_tst.c b/tests/msg_tst.c
new file mode 100644
index 0000000..67e63c0
--- /dev/null
+++ b/tests/msg_tst.c
@@ -0,0 +1,99 @@
+/* Copyright (C) 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libelfP.h>
+
+static struct
+{
+ int id;
+ const char *expected;
+} libelf_msgs[ELF_E_NUM] =
+ {
+ { ELF_E_NOERROR, "no error" },
+ { ELF_E_UNKNOWN_ERROR, "unknown error" },
+ { ELF_E_UNKNOWN_VERSION, "unknown version" },
+ { ELF_E_UNKNOWN_TYPE, "unknown type" },
+ { ELF_E_INVALID_HANDLE, "invalid `Elf' handle" },
+ { ELF_E_SOURCE_SIZE, "invalid size of source operand" },
+ { ELF_E_DEST_SIZE, "invalid size of destination operand" },
+ { ELF_E_INVALID_ENCODING, "invalid encoding" },
+ { ELF_E_NOMEM, "out of memory" },
+ { ELF_E_INVALID_FILE, "invalid file descriptor" },
+ { ELF_E_INVALID_OP, "invalid operation" },
+ { ELF_E_NO_VERSION, "ELF version not set" },
+ { ELF_E_INVALID_CMD, "invalid command" },
+ { ELF_E_RANGE, "offset out of range" },
+ { ELF_E_ARCHIVE_FMAG, "invalid fmag field in archive header" },
+ { ELF_E_INVALID_ARCHIVE, "invalid archive file" },
+ { ELF_E_NO_ARCHIVE, "descriptor is not for an archive" },
+ { ELF_E_NO_INDEX, "no index available" },
+ { ELF_E_READ_ERROR, "cannot read data from file" },
+ { ELF_E_WRITE_ERROR, "cannot write data to file" },
+ { ELF_E_INVALID_CLASS, "invalid binary class" },
+ { ELF_E_INVALID_INDEX, "invalid section index" },
+ { ELF_E_INVALID_OPERAND, "invalid operand" },
+ { ELF_E_INVALID_SECTION, "invalid section" },
+ { ELF_E_INVALID_COMMAND, "invalid command" },
+ { ELF_E_WRONG_ORDER_EHDR, "executable header not created first" },
+ { ELF_E_FD_DISABLED, "file descriptor disabled" },
+ { ELF_E_FD_MISMATCH, "archive/member fildes mismatch" },
+ { ELF_E_OFFSET_RANGE, "offset out of range" },
+ { ELF_E_NOT_NUL_SECTION, "cannot manipulate null section" },
+ { ELF_E_DATA_MISMATCH, "data/scn mismatch" },
+ { ELF_E_INVALID_SECTION_HEADER, "invalid section header" },
+ { ELF_E_INVALID_DATA, "invalid data" },
+ { ELF_E_DATA_ENCODING, "unknown data encoding" },
+ { ELF_E_SECTION_TOO_SMALL, "section `sh_size' too small for data" },
+ { ELF_E_INVALID_ALIGN, "invalid section alignment" },
+ { ELF_E_INVALID_SHENTSIZE, "invalid section entry size" },
+ { ELF_E_UPDATE_RO, "update() for write on read-only file" },
+ { ELF_E_NOFILE, "no such file" },
+ { ELF_E_GROUP_NOT_REL,
+ "only relocatable files can contain section groups" },
+ { ELF_E_INVALID_PHDR,
+ "program header only allowed in executables and shared objects" },
+ { ELF_E_NO_PHDR,
+ "file has no program header" }
+ };
+
+
+int
+main (void)
+{
+ size_t cnt;
+ int result = EXIT_SUCCESS;
+
+ /* Clear the error state. */
+ (void) elf_errno ();
+
+ /* Check all the messages of libelf. */
+ for (cnt = 1; cnt < ELF_E_NUM; ++cnt)
+ {
+ const char *str = elf_errmsg (libelf_msgs[cnt].id);
+
+ if (strcmp (str, libelf_msgs[cnt].expected) != 0)
+ {
+ printf ("libelf msg %zu: expected \"%s\", got \"%s\"\n",
+ cnt, libelf_msgs[cnt].expected, str);
+ result = EXIT_FAILURE;
+ }
+ }
+
+ return result;
+}
diff --git a/tests/newfile.c b/tests/newfile.c
new file mode 100644
index 0000000..32c4091
--- /dev/null
+++ b/tests/newfile.c
@@ -0,0 +1,166 @@
+/* Copyright (C) 1999, 2000, 2001, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static void
+print_ehdr (Elf32_Ehdr *ehdr)
+{
+ int n;
+
+ for (n = 0; n < EI_NIDENT; ++n)
+ printf (" %02x", ehdr->e_ident[n]);
+
+ printf ("\ntype = %d\nmachine = %d\nversion = %d\nentry = %d\n"
+ "phoff = %d\nshoff = %d\nflags = %d\nehsize = %d\n"
+ "phentsize = %d\nphnum = %d\nshentsize = %d\nshnum = %d\n"
+ "shstrndx = %d\n",
+ ehdr->e_type,
+ ehdr->e_machine,
+ ehdr->e_version,
+ ehdr->e_entry,
+ ehdr->e_phoff,
+ ehdr->e_shoff,
+ ehdr->e_flags,
+ ehdr->e_ehsize,
+ ehdr->e_phentsize,
+ ehdr->e_phnum,
+ ehdr->e_shentsize,
+ ehdr->e_shnum,
+ ehdr->e_shstrndx);
+}
+
+int
+main (int argc, char *argv[] __attribute__ ((unused)))
+{
+ Elf *elf;
+ int result = 0;
+ int fd;
+ char fname[] = "newfile-XXXXXX";
+
+ fd = mkstemp (fname);
+ if (fd == -1)
+ {
+ printf ("cannot create temporary file: %m\n");
+ exit (1);
+ }
+ /* Remove the file when we exit. */
+ unlink (fname);
+
+ elf_version (EV_CURRENT);
+ elf = elf_begin (fd, ELF_C_WRITE, NULL);
+ if (elf == NULL)
+ {
+ printf ("elf_begin: %s\n", elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ if (elf32_newehdr (elf) == NULL)
+ {
+ printf ("elf32_newehdr: %s\n", elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ Elf32_Ehdr *ehdr = elf32_getehdr (elf);
+
+ if (ehdr == NULL)
+ {
+ printf ("elf32_getehdr: %s\n", elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ int i;
+
+ if (argc > 1)
+ /* Use argc as a debugging flag. */
+ print_ehdr (ehdr);
+
+ /* Some tests. */
+ for (i = 0; i < EI_NIDENT; ++i)
+ if (ehdr->e_ident[i] != 0)
+ {
+ printf ("ehdr->e_ident[%d] != 0\n", i);
+ result = 1;
+ break;
+ }
+
+#define VALUE_TEST(name, val) \
+ if (ehdr->name != val) \
+ { \
+ printf ("ehdr->%s != %d\n", #name, val); \
+ result = 1; \
+ }
+#define ZERO_TEST(name) VALUE_TEST (name, 0)
+ ZERO_TEST (e_type);
+ ZERO_TEST (e_machine);
+ ZERO_TEST (e_version);
+ ZERO_TEST (e_entry);
+ ZERO_TEST (e_phoff);
+ ZERO_TEST (e_shoff);
+ ZERO_TEST (e_flags);
+ ZERO_TEST (e_ehsize);
+ ZERO_TEST (e_phentsize);
+ ZERO_TEST (e_phnum);
+ ZERO_TEST (e_shentsize);
+ ZERO_TEST (e_shnum);
+ ZERO_TEST (e_shstrndx);
+
+ if (elf32_newphdr (elf, 10) == NULL)
+ {
+ printf ("elf32_newphdr: %s\n", elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ if (argc > 1)
+ print_ehdr (ehdr);
+
+ ehdr = elf32_getehdr (elf);
+ if (ehdr == NULL)
+ {
+ printf ("elf32_getehdr (#2): %s\n", elf_errmsg (-1));
+ result = 1;
+ }
+ else
+ {
+ ZERO_TEST (e_type);
+ ZERO_TEST (e_machine);
+ ZERO_TEST (e_version);
+ ZERO_TEST (e_entry);
+ ZERO_TEST (e_phoff);
+ ZERO_TEST (e_shoff);
+ ZERO_TEST (e_flags);
+ ZERO_TEST (e_ehsize);
+ VALUE_TEST (e_phentsize, (int) sizeof (Elf32_Phdr));
+ VALUE_TEST (e_phnum, 10);
+ ZERO_TEST (e_shentsize);
+ ZERO_TEST (e_shnum);
+ ZERO_TEST (e_shstrndx);
+ }
+ }
+ }
+ }
+
+ (void) elf_end (elf);
+ }
+
+ return result;
+}
diff --git a/tests/newscn.c b/tests/newscn.c
new file mode 100644
index 0000000..8c8b335
--- /dev/null
+++ b/tests/newscn.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1999, 2000, 2001, 2002, 2005 Red Hat, Inc.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <assert.h>
+#include <fcntl.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int
+main (void)
+{
+ Elf *elf;
+ int fd;
+ Elf_Scn *section;
+
+ if (elf_version (EV_CURRENT) == EV_NONE)
+ {
+ fprintf (stderr, "library fd of date\n");
+ exit (1);
+ }
+
+ char name[] = "test.XXXXXX";
+ fd = mkstemp (name);
+ if (fd < 0)
+ {
+ fprintf (stderr, "Failed to open fdput file: %s\n", name);
+ exit (1);
+ }
+ unlink (name);
+
+ elf = elf_begin (fd, ELF_C_WRITE, NULL);
+ if (elf == NULL)
+ {
+ fprintf (stderr, "Failed to elf_begin fdput file: %s\n", name);
+ exit (1);
+ }
+
+ section = elf_newscn (elf);
+ section = elf_nextscn (elf, section);
+ assert (section == NULL);
+
+ elf_end (elf);
+ close (fd);
+
+ return 0;
+}
diff --git a/tests/run-allfcts.sh b/tests/run-allfcts.sh
new file mode 100644
index 0000000..51fe75c
--- /dev/null
+++ b/tests/run-allfcts.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 2005.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile.bz2 > testfile 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile8.bz2 > testfile8 2>/dev/null || exit 0
+
+./allfcts testfile testfile2 testfile8 > allfcts.out
+
+diff -u allfcts.out - <<"EOF"
+/home/drepper/gnu/new-bu/build/ttt/m.c:5:main
+/home/drepper/gnu/new-bu/build/ttt/b.c:4:bar
+/home/drepper/gnu/new-bu/build/ttt/f.c:3:foo
+/shoggoth/drepper/b.c:4:bar
+/shoggoth/drepper/f.c:3:foo
+/shoggoth/drepper/m.c:5:main
+/home/drepper/gnu/elfutils/build/src/../../src/strip.c:107:main
+/home/drepper/gnu/elfutils/build/src/../../src/strip.c:159:print_version
+/home/drepper/gnu/elfutils/build/src/../../src/strip.c:173:parse_opt
+/home/drepper/gnu/elfutils/build/src/../../src/strip.c:201:more_help
+/home/drepper/gnu/elfutils/build/src/../../src/strip.c:217:process_file
+/usr/include/sys/stat.h:375:stat64
+/home/drepper/gnu/elfutils/build/src/../../src/strip.c:291:crc32_file
+/home/drepper/gnu/elfutils/build/src/../../src/strip.c:313:handle_elf
+EOF
+
+rm -f testfile testfile2 testfile8 allfcts.out
+
+exit 0
diff --git a/tests/run-arextract.sh b/tests/run-arextract.sh
new file mode 100644
index 0000000..69ac0bc
--- /dev/null
+++ b/tests/run-arextract.sh
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+
+archive=../libelf/libelf.a
+if test -f $archive; then
+ # The file is really available (i.e., no shared-only built).
+ echo -n "Extracting symbols... $ac_c"
+
+ # The files we are looking at.
+ for f in ../libelf/*.o; do
+ ./arextract $archive `basename $f` arextract.test || exit 1
+ cmp $f arextract.test || {
+ echo "Extraction of $1 failed"
+ exit 1
+ }
+ rm -f ${objpfx}arextract.test
+ done
+
+ echo "done"
+fi
+
+exit 0
diff --git a/tests/run-arsymtest.sh b/tests/run-arsymtest.sh
new file mode 100644
index 0000000..793cdb8
--- /dev/null
+++ b/tests/run-arsymtest.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+
+lib=../libelf/libelf.a
+okfile=arsymtest.ok
+tmpfile=arsymtest.tmp
+testfile=arsymtest.test
+
+result=0
+if test -f $lib; then
+ # Generate list using `nm' we check against.
+ nm -s $lib |
+ sed -e '1,/^Arch/d' -e '/^$/,$d' |
+ sort > $okfile
+
+ # Now run our program using libelf.
+ ./arsymtest $lib $tmpfile || exit 1
+ sort $tmpfile > $testfile
+ rm $tmpfile
+
+ # Compare the outputs.
+ if cmp $okfile $testfile; then
+ result=0
+ rm $testfile $okfile
+ else
+ result=1
+ fi
+fi
+
+exit $result
diff --git a/tests/run-ecp-test.sh b/tests/run-ecp-test.sh
new file mode 100644
index 0000000..e430496
--- /dev/null
+++ b/tests/run-ecp-test.sh
@@ -0,0 +1,25 @@
+#! /bin/sh
+# Copyright (C) 2002 Red Hat, Inc.
+# Written by Jakub Jelinek <jakub@redhat.com>, 2002.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile10.bz2 > testfile10 2>/dev/null || exit 0
+
+./ecp testfile10 testfile10.tmp
+
+cmp testfile10 testfile10.tmp
+
+rm -f testfile10 testfile10.tmp
+
+exit 0
diff --git a/tests/run-ecp-test2.sh b/tests/run-ecp-test2.sh
new file mode 100644
index 0000000..143c70a
--- /dev/null
+++ b/tests/run-ecp-test2.sh
@@ -0,0 +1,23 @@
+#! /bin/sh
+# Copyright (C) 2002 Red Hat, Inc.
+# Written by Jakub Jelinek <jakub@redhat.com>, 2002.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+./ecp testfile2 testfile2.tmp
+
+rm -f testfile2 testfile2.tmp
+
+exit 0
diff --git a/tests/run-elflint-test.sh b/tests/run-elflint-test.sh
new file mode 100644
index 0000000..f008ccd
--- /dev/null
+++ b/tests/run-elflint-test.sh
@@ -0,0 +1,28 @@
+#! /bin/sh
+# Copyright (C) 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 2005.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile18.bz2 > testfile18 2>/dev/null || exit 0
+
+LD_LIBRARY_PATH=../libebl:../libelf${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH \
+ ../src/elflint --gnu testfile18 >& elflint-test.out || :
+
+diff -u elflint-test.out - <<"EOF"
+section [ 8] '.rela.dyn': relocation 1: copy relocation against symbol of type FUNC
+EOF
+
+rm -f testfile18 elflint-test.out
+
+exit 0
diff --git a/tests/run-get-aranges.sh b/tests/run-get-aranges.sh
new file mode 100644
index 0000000..26b2986
--- /dev/null
+++ b/tests/run-get-aranges.sh
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile.bz2 > testfile 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+./get-aranges testfile testfile2 > get-aranges.out
+
+cmp get-aranges.out - <<"EOF"
+0x804842b: not in range
+CU name: "m.c"
+CU name: "m.c"
+CU name: "m.c"
+0x804845a: not in range
+0x804845b: not in range
+CU name: "b.c"
+CU name: "b.c"
+CU name: "b.c"
+0x8048466: not in range
+0x8048467: not in range
+CU name: "f.c"
+CU name: "f.c"
+CU name: "f.c"
+0x8048472: not in range
+ [ 0] start: 0x804842c, length: 46, cu: 11
+CU name: "m.c"
+ [ 1] start: 0x804845c, length: 10, cu: 202
+CU name: "b.c"
+ [ 2] start: 0x8048468, length: 10, cu: 5628
+CU name: "f.c"
+0x804842b: not in range
+0x804842c: not in range
+0x804843c: not in range
+0x8048459: not in range
+0x804845a: not in range
+0x804845b: not in range
+0x804845c: not in range
+0x8048460: not in range
+0x8048465: not in range
+0x8048466: not in range
+0x8048467: not in range
+0x8048468: not in range
+0x8048470: not in range
+0x8048471: not in range
+0x8048472: not in range
+ [ 0] start: 0x10000470, length: 32, cu: 11
+CU name: "b.c"
+ [ 1] start: 0x10000490, length: 32, cu: 2429
+CU name: "f.c"
+ [ 2] start: 0x100004b0, length: 100, cu: 2532
+CU name: "m.c"
+EOF
+
+rm -f testfile testfile2 get-aranges.out
+
+exit 0
diff --git a/tests/run-get-files.sh b/tests/run-get-files.sh
new file mode 100644
index 0000000..7af5c13
--- /dev/null
+++ b/tests/run-get-files.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2004 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile.bz2 > testfile 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+./get-files testfile testfile2 > get-files.out
+
+diff -u get-files.out - <<"EOF"
+cuhl = 11, o = 0, asz = 4, osz = 4, ncu = 191
+ file[0] = "???"
+ file[1] = "/home/drepper/gnu/new-bu/build/ttt/m.c"
+cuhl = 11, o = 114, asz = 4, osz = 4, ncu = 5617
+ file[0] = "???"
+ file[1] = "/home/drepper/gnu/new-bu/build/ttt/b.c"
+ file[2] = "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h"
+ file[3] = "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stdarg.h"
+ file[4] = "/usr/include/bits/types.h"
+ file[5] = "/usr/include/bits/sched.h"
+ file[6] = "/usr/include/bits/pthreadtypes.h"
+ file[7] = "/usr/include/stdio.h"
+ file[8] = "/usr/include/libio.h"
+ file[9] = "/usr/include/wchar.h"
+ file[10] = "/usr/include/_G_config.h"
+ file[11] = "/usr/include/gconv.h"
+cuhl = 11, o = 412, asz = 4, osz = 4, ncu = 5752
+ file[0] = "???"
+ file[1] = "/home/drepper/gnu/new-bu/build/ttt/f.c"
+cuhl = 11, o = 0, asz = 4, osz = 4, ncu = 2418
+ file[0] = "???"
+ file[1] = "/shoggoth/drepper/b.c"
+ file[2] = "/home/geoffk/objs/laurel-000912-branch/lib/gcc-lib/powerpc-unknown-linux-gnu/2.96-laurel-000912/include/stddef.h"
+ file[3] = "/home/geoffk/objs/laurel-000912-branch/lib/gcc-lib/powerpc-unknown-linux-gnu/2.96-laurel-000912/include/stdarg.h"
+ file[4] = "/shoggoth/drepper/<built-in>"
+ file[5] = "/usr/include/bits/types.h"
+ file[6] = "/usr/include/stdio.h"
+ file[7] = "/usr/include/libio.h"
+ file[8] = "/usr/include/_G_config.h"
+cuhl = 11, o = 213, asz = 4, osz = 4, ncu = 2521
+ file[0] = "???"
+ file[1] = "/shoggoth/drepper/f.c"
+cuhl = 11, o = 267, asz = 4, osz = 4, ncu = 2680
+ file[0] = "???"
+ file[1] = "/shoggoth/drepper/m.c"
+EOF
+
+rm -f testfile testfil2 get-files.out
+
+exit 0
diff --git a/tests/run-get-lines.sh b/tests/run-get-lines.sh
new file mode 100644
index 0000000..70c9cd8
--- /dev/null
+++ b/tests/run-get-lines.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2004 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile.bz2 > testfile 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+./get-lines testfile testfile2 > get-lines.out
+
+diff -u get-lines.out - <<"EOF"
+cuhl = 11, o = 0, asz = 4, osz = 4, ncu = 191
+ 5 lines
+804842c: /home/drepper/gnu/new-bu/build/ttt/m.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+8048432: /home/drepper/gnu/new-bu/build/ttt/m.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+804844d: /home/drepper/gnu/new-bu/build/ttt/m.c:7:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+8048458: /home/drepper/gnu/new-bu/build/ttt/m.c:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+804845a: /home/drepper/gnu/new-bu/build/ttt/m.c:8:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no
+cuhl = 11, o = 114, asz = 4, osz = 4, ncu = 5617
+ 4 lines
+804845c: /home/drepper/gnu/new-bu/build/ttt/b.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+804845f: /home/drepper/gnu/new-bu/build/ttt/b.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+8048464: /home/drepper/gnu/new-bu/build/ttt/b.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+8048466: /home/drepper/gnu/new-bu/build/ttt/b.c:6:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no
+cuhl = 11, o = 412, asz = 4, osz = 4, ncu = 5752
+ 4 lines
+8048468: /home/drepper/gnu/new-bu/build/ttt/f.c:3:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+804846b: /home/drepper/gnu/new-bu/build/ttt/f.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+8048470: /home/drepper/gnu/new-bu/build/ttt/f.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+8048472: /home/drepper/gnu/new-bu/build/ttt/f.c:5:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no
+cuhl = 11, o = 0, asz = 4, osz = 4, ncu = 2418
+ 4 lines
+10000470: /shoggoth/drepper/b.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+1000047c: /shoggoth/drepper/b.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+10000480: /shoggoth/drepper/b.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+10000490: /shoggoth/drepper/b.c:6:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no
+cuhl = 11, o = 213, asz = 4, osz = 4, ncu = 2521
+ 4 lines
+10000490: /shoggoth/drepper/f.c:3:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+1000049c: /shoggoth/drepper/f.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+100004a0: /shoggoth/drepper/f.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+100004b0: /shoggoth/drepper/f.c:5:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no
+cuhl = 11, o = 267, asz = 4, osz = 4, ncu = 2680
+ 5 lines
+100004b0: /shoggoth/drepper/m.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+100004cc: /shoggoth/drepper/m.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+100004e8: /shoggoth/drepper/m.c:7:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+100004f4: /shoggoth/drepper/m.c:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+10000514: /shoggoth/drepper/m.c:8:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no
+EOF
+
+rm -f testfile testfile2 get-lines.out
+
+exit 0
diff --git a/tests/run-get-pubnames.sh b/tests/run-get-pubnames.sh
new file mode 100644
index 0000000..a232bfd
--- /dev/null
+++ b/tests/run-get-pubnames.sh
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2003 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile.bz2 > testfile 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+./get-pubnames testfile testfile2 > get-pubnames.out
+
+diff -u get-pubnames.out - <<"EOF"
+ [ 0] "main", die: 104, cu: 11
+CU name: "m.c"
+object name: "main"
+ [ 1] "a", die: 174, cu: 11
+CU name: "m.c"
+object name: "a"
+ [ 2] "bar", die: 295, cu: 202
+CU name: "b.c"
+object name: "bar"
+ [ 3] "foo", die: 5721, cu: 5628
+CU name: "f.c"
+object name: "foo"
+ [ 0] "bar", die: 72, cu: 11
+CU name: "b.c"
+object name: "bar"
+ [ 1] "foo", die: 2490, cu: 2429
+CU name: "f.c"
+object name: "foo"
+ [ 2] "main", die: 2593, cu: 2532
+CU name: "m.c"
+object name: "main"
+ [ 3] "a", die: 2663, cu: 2532
+CU name: "m.c"
+object name: "a"
+EOF
+
+rm -f testfile testfile2 get-pubnames.out
+
+exit 0
diff --git a/tests/run-line2addr.sh b/tests/run-line2addr.sh
new file mode 100644
index 0000000..c46c8fd
--- /dev/null
+++ b/tests/run-line2addr.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 2005.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile.bz2 > testfile 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile8.bz2 > testfile8 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile14.bz2 > testfile14 2>/dev/null || exit 0
+
+./line2addr testfile:f.c:4 testfile:f.c:8 testfile2:m.c:6 testfile2:b.c:1 testfile8:strip.c:953 testfile8:strip.c:365 testfile14:v.c:6 > line2addr.out
+
+diff -u line2addr.out - <<"EOF"
+testfile:f.c:4 -> 0x804846b
+testfile2:m.c:6 -> 0x100004cc
+testfile2:b.c:1 -> 0x10000470
+testfile8:strip.c:953 -> 0x169f
+testfile8:strip.c:953 -> 0x16aa
+testfile8:strip.c:365 -> 0x278b
+testfile8:strip.c:365 -> 0x2797
+testfile14:v.c:6 -> 0x400468
+testfile14:v.c:6 -> 0x400487
+EOF
+
+rm -f testfile testfile2 testfile8 testfile14 line2addr.out
+
+exit 0
diff --git a/tests/run-show-abbrev.sh b/tests/run-show-abbrev.sh
new file mode 100644
index 0000000..78812a5
--- /dev/null
+++ b/tests/run-show-abbrev.sh
@@ -0,0 +1,355 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2003, 2004 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile.bz2 > testfile 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+./show-abbrev testfile testfile2 > show-abbrev.out
+
+diff -u show-abbrev.out - <<"EOF"
+abbrev[0]: code = 1, tag = 17, children = 1
+abbrev[0]: attr[0]: code = 16, form = 6, offset = 0
+abbrev[0]: attr[1]: code = 18, form = 1, offset = 2
+abbrev[0]: attr[2]: code = 17, form = 1, offset = 4
+abbrev[0]: attr[3]: code = 3, form = 8, offset = 6
+abbrev[0]: attr[4]: code = 27, form = 8, offset = 8
+abbrev[0]: attr[5]: code = 37, form = 8, offset = 10
+abbrev[0]: attr[6]: code = 19, form = 11, offset = 12
+abbrev[19]: code = 2, tag = 46, children = 1
+abbrev[19]: attr[0]: code = 1, form = 19, offset = 19
+abbrev[19]: attr[1]: code = 63, form = 12, offset = 21
+abbrev[19]: attr[2]: code = 3, form = 8, offset = 23
+abbrev[19]: attr[3]: code = 58, form = 11, offset = 25
+abbrev[19]: attr[4]: code = 59, form = 11, offset = 27
+abbrev[19]: attr[5]: code = 39, form = 12, offset = 29
+abbrev[19]: attr[6]: code = 73, form = 19, offset = 31
+abbrev[19]: attr[7]: code = 17, form = 1, offset = 33
+abbrev[19]: attr[8]: code = 18, form = 1, offset = 35
+abbrev[19]: attr[9]: code = 64, form = 10, offset = 37
+abbrev[44]: code = 3, tag = 46, children = 1
+abbrev[44]: attr[0]: code = 1, form = 19, offset = 44
+abbrev[44]: attr[1]: code = 63, form = 12, offset = 46
+abbrev[44]: attr[2]: code = 3, form = 8, offset = 48
+abbrev[44]: attr[3]: code = 58, form = 11, offset = 50
+abbrev[44]: attr[4]: code = 59, form = 11, offset = 52
+abbrev[44]: attr[5]: code = 73, form = 19, offset = 54
+abbrev[44]: attr[6]: code = 60, form = 12, offset = 56
+abbrev[63]: code = 4, tag = 24, children = 0
+abbrev[68]: code = 5, tag = 46, children = 1
+abbrev[68]: attr[0]: code = 63, form = 12, offset = 68
+abbrev[68]: attr[1]: code = 3, form = 8, offset = 70
+abbrev[68]: attr[2]: code = 58, form = 11, offset = 72
+abbrev[68]: attr[3]: code = 59, form = 11, offset = 74
+abbrev[68]: attr[4]: code = 73, form = 19, offset = 76
+abbrev[68]: attr[5]: code = 60, form = 12, offset = 78
+abbrev[85]: code = 6, tag = 36, children = 0
+abbrev[85]: attr[0]: code = 3, form = 8, offset = 85
+abbrev[85]: attr[1]: code = 11, form = 11, offset = 87
+abbrev[85]: attr[2]: code = 62, form = 11, offset = 89
+abbrev[96]: code = 7, tag = 52, children = 0
+abbrev[96]: attr[0]: code = 3, form = 8, offset = 96
+abbrev[96]: attr[1]: code = 58, form = 11, offset = 98
+abbrev[96]: attr[2]: code = 59, form = 11, offset = 100
+abbrev[96]: attr[3]: code = 73, form = 19, offset = 102
+abbrev[96]: attr[4]: code = 63, form = 12, offset = 104
+abbrev[96]: attr[5]: code = 2, form = 10, offset = 106
+abbrev[0]: code = 1, tag = 17, children = 1
+abbrev[0]: attr[0]: code = 16, form = 6, offset = 114
+abbrev[0]: attr[1]: code = 18, form = 1, offset = 116
+abbrev[0]: attr[2]: code = 17, form = 1, offset = 118
+abbrev[0]: attr[3]: code = 3, form = 8, offset = 120
+abbrev[0]: attr[4]: code = 27, form = 8, offset = 122
+abbrev[0]: attr[5]: code = 37, form = 8, offset = 124
+abbrev[0]: attr[6]: code = 19, form = 11, offset = 126
+abbrev[19]: code = 2, tag = 46, children = 0
+abbrev[19]: attr[0]: code = 63, form = 12, offset = 133
+abbrev[19]: attr[1]: code = 3, form = 8, offset = 135
+abbrev[19]: attr[2]: code = 58, form = 11, offset = 137
+abbrev[19]: attr[3]: code = 59, form = 11, offset = 139
+abbrev[19]: attr[4]: code = 39, form = 12, offset = 141
+abbrev[19]: attr[5]: code = 73, form = 19, offset = 143
+abbrev[19]: attr[6]: code = 17, form = 1, offset = 145
+abbrev[19]: attr[7]: code = 18, form = 1, offset = 147
+abbrev[19]: attr[8]: code = 64, form = 10, offset = 149
+abbrev[42]: code = 3, tag = 36, children = 0
+abbrev[42]: attr[0]: code = 3, form = 8, offset = 156
+abbrev[42]: attr[1]: code = 11, form = 11, offset = 158
+abbrev[42]: attr[2]: code = 62, form = 11, offset = 160
+abbrev[53]: code = 4, tag = 22, children = 0
+abbrev[53]: attr[0]: code = 3, form = 8, offset = 167
+abbrev[53]: attr[1]: code = 58, form = 11, offset = 169
+abbrev[53]: attr[2]: code = 59, form = 11, offset = 171
+abbrev[53]: attr[3]: code = 73, form = 19, offset = 173
+abbrev[66]: code = 5, tag = 15, children = 0
+abbrev[66]: attr[0]: code = 11, form = 11, offset = 180
+abbrev[73]: code = 6, tag = 15, children = 0
+abbrev[73]: attr[0]: code = 11, form = 11, offset = 187
+abbrev[73]: attr[1]: code = 73, form = 19, offset = 189
+abbrev[82]: code = 7, tag = 19, children = 1
+abbrev[82]: attr[0]: code = 1, form = 19, offset = 196
+abbrev[82]: attr[1]: code = 11, form = 11, offset = 198
+abbrev[82]: attr[2]: code = 58, form = 11, offset = 200
+abbrev[82]: attr[3]: code = 59, form = 11, offset = 202
+abbrev[95]: code = 8, tag = 13, children = 0
+abbrev[95]: attr[0]: code = 3, form = 8, offset = 209
+abbrev[95]: attr[1]: code = 58, form = 11, offset = 211
+abbrev[95]: attr[2]: code = 59, form = 11, offset = 213
+abbrev[95]: attr[3]: code = 73, form = 19, offset = 215
+abbrev[95]: attr[4]: code = 56, form = 10, offset = 217
+abbrev[110]: code = 9, tag = 1, children = 1
+abbrev[110]: attr[0]: code = 1, form = 19, offset = 224
+abbrev[110]: attr[1]: code = 73, form = 19, offset = 226
+abbrev[119]: code = 10, tag = 33, children = 0
+abbrev[119]: attr[0]: code = 73, form = 19, offset = 233
+abbrev[119]: attr[1]: code = 47, form = 11, offset = 235
+abbrev[128]: code = 11, tag = 19, children = 1
+abbrev[128]: attr[0]: code = 1, form = 19, offset = 242
+abbrev[128]: attr[1]: code = 3, form = 8, offset = 244
+abbrev[128]: attr[2]: code = 11, form = 11, offset = 246
+abbrev[128]: attr[3]: code = 58, form = 11, offset = 248
+abbrev[128]: attr[4]: code = 59, form = 11, offset = 250
+abbrev[143]: code = 12, tag = 19, children = 0
+abbrev[143]: attr[0]: code = 3, form = 8, offset = 257
+abbrev[143]: attr[1]: code = 60, form = 12, offset = 259
+abbrev[152]: code = 13, tag = 13, children = 0
+abbrev[152]: attr[0]: code = 3, form = 8, offset = 266
+abbrev[152]: attr[1]: code = 58, form = 11, offset = 268
+abbrev[152]: attr[2]: code = 59, form = 5, offset = 270
+abbrev[152]: attr[3]: code = 73, form = 19, offset = 272
+abbrev[152]: attr[4]: code = 56, form = 10, offset = 274
+abbrev[167]: code = 14, tag = 22, children = 0
+abbrev[167]: attr[0]: code = 3, form = 8, offset = 281
+abbrev[167]: attr[1]: code = 58, form = 11, offset = 283
+abbrev[167]: attr[2]: code = 59, form = 5, offset = 285
+abbrev[167]: attr[3]: code = 73, form = 19, offset = 287
+abbrev[180]: code = 15, tag = 23, children = 1
+abbrev[180]: attr[0]: code = 1, form = 19, offset = 294
+abbrev[180]: attr[1]: code = 11, form = 11, offset = 296
+abbrev[180]: attr[2]: code = 58, form = 11, offset = 298
+abbrev[180]: attr[3]: code = 59, form = 11, offset = 300
+abbrev[193]: code = 16, tag = 13, children = 0
+abbrev[193]: attr[0]: code = 3, form = 8, offset = 307
+abbrev[193]: attr[1]: code = 58, form = 11, offset = 309
+abbrev[193]: attr[2]: code = 59, form = 11, offset = 311
+abbrev[193]: attr[3]: code = 73, form = 19, offset = 313
+abbrev[206]: code = 17, tag = 4, children = 1
+abbrev[206]: attr[0]: code = 1, form = 19, offset = 320
+abbrev[206]: attr[1]: code = 11, form = 11, offset = 322
+abbrev[206]: attr[2]: code = 58, form = 11, offset = 324
+abbrev[206]: attr[3]: code = 59, form = 11, offset = 326
+abbrev[219]: code = 18, tag = 40, children = 0
+abbrev[219]: attr[0]: code = 3, form = 8, offset = 333
+abbrev[219]: attr[1]: code = 28, form = 11, offset = 335
+abbrev[228]: code = 19, tag = 38, children = 0
+abbrev[228]: attr[0]: code = 73, form = 19, offset = 342
+abbrev[235]: code = 20, tag = 21, children = 1
+abbrev[235]: attr[0]: code = 1, form = 19, offset = 349
+abbrev[235]: attr[1]: code = 39, form = 12, offset = 351
+abbrev[235]: attr[2]: code = 73, form = 19, offset = 353
+abbrev[246]: code = 21, tag = 5, children = 0
+abbrev[246]: attr[0]: code = 73, form = 19, offset = 360
+abbrev[253]: code = 22, tag = 21, children = 1
+abbrev[253]: attr[0]: code = 1, form = 19, offset = 367
+abbrev[253]: attr[1]: code = 39, form = 12, offset = 369
+abbrev[262]: code = 23, tag = 33, children = 0
+abbrev[262]: attr[0]: code = 73, form = 19, offset = 376
+abbrev[262]: attr[1]: code = 47, form = 6, offset = 378
+abbrev[271]: code = 24, tag = 22, children = 0
+abbrev[271]: attr[0]: code = 3, form = 8, offset = 385
+abbrev[271]: attr[1]: code = 58, form = 11, offset = 387
+abbrev[271]: attr[2]: code = 59, form = 11, offset = 389
+abbrev[282]: code = 25, tag = 4, children = 1
+abbrev[282]: attr[0]: code = 1, form = 19, offset = 396
+abbrev[282]: attr[1]: code = 3, form = 8, offset = 398
+abbrev[282]: attr[2]: code = 11, form = 11, offset = 400
+abbrev[282]: attr[3]: code = 58, form = 11, offset = 402
+abbrev[282]: attr[4]: code = 59, form = 11, offset = 404
+abbrev[0]: code = 1, tag = 17, children = 1
+abbrev[0]: attr[0]: code = 16, form = 6, offset = 412
+abbrev[0]: attr[1]: code = 18, form = 1, offset = 414
+abbrev[0]: attr[2]: code = 17, form = 1, offset = 416
+abbrev[0]: attr[3]: code = 3, form = 8, offset = 418
+abbrev[0]: attr[4]: code = 27, form = 8, offset = 420
+abbrev[0]: attr[5]: code = 37, form = 8, offset = 422
+abbrev[0]: attr[6]: code = 19, form = 11, offset = 424
+abbrev[19]: code = 2, tag = 46, children = 0
+abbrev[19]: attr[0]: code = 63, form = 12, offset = 431
+abbrev[19]: attr[1]: code = 3, form = 8, offset = 433
+abbrev[19]: attr[2]: code = 58, form = 11, offset = 435
+abbrev[19]: attr[3]: code = 59, form = 11, offset = 437
+abbrev[19]: attr[4]: code = 39, form = 12, offset = 439
+abbrev[19]: attr[5]: code = 73, form = 19, offset = 441
+abbrev[19]: attr[6]: code = 17, form = 1, offset = 443
+abbrev[19]: attr[7]: code = 18, form = 1, offset = 445
+abbrev[19]: attr[8]: code = 64, form = 10, offset = 447
+abbrev[42]: code = 3, tag = 36, children = 0
+abbrev[42]: attr[0]: code = 3, form = 8, offset = 454
+abbrev[42]: attr[1]: code = 11, form = 11, offset = 456
+abbrev[42]: attr[2]: code = 62, form = 11, offset = 458
+abbrev[0]: code = 1, tag = 17, children = 1
+abbrev[0]: attr[0]: code = 16, form = 6, offset = 0
+abbrev[0]: attr[1]: code = 18, form = 1, offset = 2
+abbrev[0]: attr[2]: code = 17, form = 1, offset = 4
+abbrev[0]: attr[3]: code = 3, form = 8, offset = 6
+abbrev[0]: attr[4]: code = 27, form = 8, offset = 8
+abbrev[0]: attr[5]: code = 37, form = 8, offset = 10
+abbrev[0]: attr[6]: code = 19, form = 11, offset = 12
+abbrev[19]: code = 2, tag = 46, children = 0
+abbrev[19]: attr[0]: code = 63, form = 12, offset = 19
+abbrev[19]: attr[1]: code = 3, form = 8, offset = 21
+abbrev[19]: attr[2]: code = 58, form = 11, offset = 23
+abbrev[19]: attr[3]: code = 59, form = 11, offset = 25
+abbrev[19]: attr[4]: code = 39, form = 12, offset = 27
+abbrev[19]: attr[5]: code = 73, form = 19, offset = 29
+abbrev[19]: attr[6]: code = 17, form = 1, offset = 31
+abbrev[19]: attr[7]: code = 18, form = 1, offset = 33
+abbrev[19]: attr[8]: code = 64, form = 10, offset = 35
+abbrev[42]: code = 3, tag = 36, children = 0
+abbrev[42]: attr[0]: code = 3, form = 8, offset = 42
+abbrev[42]: attr[1]: code = 11, form = 11, offset = 44
+abbrev[42]: attr[2]: code = 62, form = 11, offset = 46
+abbrev[53]: code = 4, tag = 22, children = 0
+abbrev[53]: attr[0]: code = 3, form = 8, offset = 53
+abbrev[53]: attr[1]: code = 58, form = 11, offset = 55
+abbrev[53]: attr[2]: code = 59, form = 11, offset = 57
+abbrev[53]: attr[3]: code = 73, form = 19, offset = 59
+abbrev[66]: code = 5, tag = 1, children = 1
+abbrev[66]: attr[0]: code = 1, form = 19, offset = 66
+abbrev[66]: attr[1]: code = 3, form = 8, offset = 68
+abbrev[66]: attr[2]: code = 73, form = 19, offset = 70
+abbrev[77]: code = 6, tag = 33, children = 0
+abbrev[77]: attr[0]: code = 73, form = 19, offset = 77
+abbrev[77]: attr[1]: code = 47, form = 11, offset = 79
+abbrev[86]: code = 7, tag = 19, children = 1
+abbrev[86]: attr[0]: code = 1, form = 19, offset = 86
+abbrev[86]: attr[1]: code = 3, form = 8, offset = 88
+abbrev[86]: attr[2]: code = 11, form = 11, offset = 90
+abbrev[86]: attr[3]: code = 58, form = 11, offset = 92
+abbrev[86]: attr[4]: code = 59, form = 11, offset = 94
+abbrev[101]: code = 8, tag = 13, children = 0
+abbrev[101]: attr[0]: code = 3, form = 8, offset = 101
+abbrev[101]: attr[1]: code = 58, form = 11, offset = 103
+abbrev[101]: attr[2]: code = 59, form = 11, offset = 105
+abbrev[101]: attr[3]: code = 73, form = 19, offset = 107
+abbrev[101]: attr[4]: code = 56, form = 10, offset = 109
+abbrev[116]: code = 9, tag = 15, children = 0
+abbrev[116]: attr[0]: code = 11, form = 11, offset = 116
+abbrev[123]: code = 10, tag = 15, children = 0
+abbrev[123]: attr[0]: code = 11, form = 11, offset = 123
+abbrev[123]: attr[1]: code = 73, form = 19, offset = 125
+abbrev[132]: code = 11, tag = 19, children = 1
+abbrev[132]: attr[0]: code = 1, form = 19, offset = 132
+abbrev[132]: attr[1]: code = 11, form = 11, offset = 134
+abbrev[132]: attr[2]: code = 58, form = 11, offset = 136
+abbrev[132]: attr[3]: code = 59, form = 11, offset = 138
+abbrev[145]: code = 12, tag = 1, children = 1
+abbrev[145]: attr[0]: code = 1, form = 19, offset = 145
+abbrev[145]: attr[1]: code = 73, form = 19, offset = 147
+abbrev[154]: code = 13, tag = 22, children = 0
+abbrev[154]: attr[0]: code = 3, form = 8, offset = 154
+abbrev[154]: attr[1]: code = 58, form = 11, offset = 156
+abbrev[154]: attr[2]: code = 59, form = 5, offset = 158
+abbrev[154]: attr[3]: code = 73, form = 19, offset = 160
+abbrev[167]: code = 14, tag = 19, children = 0
+abbrev[167]: attr[0]: code = 3, form = 8, offset = 167
+abbrev[167]: attr[1]: code = 60, form = 12, offset = 169
+abbrev[176]: code = 15, tag = 22, children = 0
+abbrev[176]: attr[0]: code = 3, form = 8, offset = 176
+abbrev[176]: attr[1]: code = 58, form = 11, offset = 178
+abbrev[176]: attr[2]: code = 59, form = 11, offset = 180
+abbrev[187]: code = 16, tag = 21, children = 1
+abbrev[187]: attr[0]: code = 1, form = 19, offset = 187
+abbrev[187]: attr[1]: code = 39, form = 12, offset = 189
+abbrev[187]: attr[2]: code = 73, form = 19, offset = 191
+abbrev[198]: code = 17, tag = 5, children = 0
+abbrev[198]: attr[0]: code = 73, form = 19, offset = 198
+abbrev[205]: code = 18, tag = 38, children = 0
+abbrev[205]: attr[0]: code = 73, form = 19, offset = 205
+abbrev[0]: code = 1, tag = 17, children = 1
+abbrev[0]: attr[0]: code = 16, form = 6, offset = 213
+abbrev[0]: attr[1]: code = 18, form = 1, offset = 215
+abbrev[0]: attr[2]: code = 17, form = 1, offset = 217
+abbrev[0]: attr[3]: code = 3, form = 8, offset = 219
+abbrev[0]: attr[4]: code = 27, form = 8, offset = 221
+abbrev[0]: attr[5]: code = 37, form = 8, offset = 223
+abbrev[0]: attr[6]: code = 19, form = 11, offset = 225
+abbrev[19]: code = 2, tag = 46, children = 0
+abbrev[19]: attr[0]: code = 63, form = 12, offset = 232
+abbrev[19]: attr[1]: code = 3, form = 8, offset = 234
+abbrev[19]: attr[2]: code = 58, form = 11, offset = 236
+abbrev[19]: attr[3]: code = 59, form = 11, offset = 238
+abbrev[19]: attr[4]: code = 39, form = 12, offset = 240
+abbrev[19]: attr[5]: code = 73, form = 19, offset = 242
+abbrev[19]: attr[6]: code = 17, form = 1, offset = 244
+abbrev[19]: attr[7]: code = 18, form = 1, offset = 246
+abbrev[19]: attr[8]: code = 64, form = 10, offset = 248
+abbrev[42]: code = 3, tag = 36, children = 0
+abbrev[42]: attr[0]: code = 3, form = 8, offset = 255
+abbrev[42]: attr[1]: code = 11, form = 11, offset = 257
+abbrev[42]: attr[2]: code = 62, form = 11, offset = 259
+abbrev[0]: code = 1, tag = 17, children = 1
+abbrev[0]: attr[0]: code = 16, form = 6, offset = 267
+abbrev[0]: attr[1]: code = 18, form = 1, offset = 269
+abbrev[0]: attr[2]: code = 17, form = 1, offset = 271
+abbrev[0]: attr[3]: code = 3, form = 8, offset = 273
+abbrev[0]: attr[4]: code = 27, form = 8, offset = 275
+abbrev[0]: attr[5]: code = 37, form = 8, offset = 277
+abbrev[0]: attr[6]: code = 19, form = 11, offset = 279
+abbrev[19]: code = 2, tag = 46, children = 1
+abbrev[19]: attr[0]: code = 1, form = 19, offset = 286
+abbrev[19]: attr[1]: code = 63, form = 12, offset = 288
+abbrev[19]: attr[2]: code = 3, form = 8, offset = 290
+abbrev[19]: attr[3]: code = 58, form = 11, offset = 292
+abbrev[19]: attr[4]: code = 59, form = 11, offset = 294
+abbrev[19]: attr[5]: code = 39, form = 12, offset = 296
+abbrev[19]: attr[6]: code = 73, form = 19, offset = 298
+abbrev[19]: attr[7]: code = 17, form = 1, offset = 300
+abbrev[19]: attr[8]: code = 18, form = 1, offset = 302
+abbrev[19]: attr[9]: code = 64, form = 10, offset = 304
+abbrev[44]: code = 3, tag = 46, children = 1
+abbrev[44]: attr[0]: code = 1, form = 19, offset = 311
+abbrev[44]: attr[1]: code = 63, form = 12, offset = 313
+abbrev[44]: attr[2]: code = 3, form = 8, offset = 315
+abbrev[44]: attr[3]: code = 58, form = 11, offset = 317
+abbrev[44]: attr[4]: code = 59, form = 11, offset = 319
+abbrev[44]: attr[5]: code = 73, form = 19, offset = 321
+abbrev[44]: attr[6]: code = 60, form = 12, offset = 323
+abbrev[63]: code = 4, tag = 24, children = 0
+abbrev[68]: code = 5, tag = 46, children = 1
+abbrev[68]: attr[0]: code = 63, form = 12, offset = 335
+abbrev[68]: attr[1]: code = 3, form = 8, offset = 337
+abbrev[68]: attr[2]: code = 58, form = 11, offset = 339
+abbrev[68]: attr[3]: code = 59, form = 11, offset = 341
+abbrev[68]: attr[4]: code = 73, form = 19, offset = 343
+abbrev[68]: attr[5]: code = 60, form = 12, offset = 345
+abbrev[85]: code = 6, tag = 36, children = 0
+abbrev[85]: attr[0]: code = 3, form = 8, offset = 352
+abbrev[85]: attr[1]: code = 11, form = 11, offset = 354
+abbrev[85]: attr[2]: code = 62, form = 11, offset = 356
+abbrev[96]: code = 7, tag = 52, children = 0
+abbrev[96]: attr[0]: code = 3, form = 8, offset = 363
+abbrev[96]: attr[1]: code = 58, form = 11, offset = 365
+abbrev[96]: attr[2]: code = 59, form = 11, offset = 367
+abbrev[96]: attr[3]: code = 73, form = 19, offset = 369
+abbrev[96]: attr[4]: code = 63, form = 12, offset = 371
+abbrev[96]: attr[5]: code = 2, form = 10, offset = 373
+EOF
+
+rm -f testfile testfile2 show-abbrev.out
+
+exit 0
diff --git a/tests/run-show-ciefde.sh b/tests/run-show-ciefde.sh
new file mode 100644
index 0000000..b335533
--- /dev/null
+++ b/tests/run-show-ciefde.sh
@@ -0,0 +1,319 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile3.bz2 > testfile3 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile4.bz2 > testfile4 2>/dev/null || exit 0
+
+./show-ciefde testfile3 testfile4 > show-ciefde.out
+
+diff -u show-ciefde.out - <<"EOF"
+testfile3 has 1 CIEs and 1 FDEs
+CIE[0]: bytes_in_cie = 16, version = 1, augmenter = ""
+CIE[0]: code_alignment_factor = 1
+CIE[0]: data_alignment_factor = fffffffffffffffc
+CIE[0]: return_address_register = 8
+CIE[0]: bytes = 0c 04 04 88 01 00 00
+FDE[0]: low_pc = 0x804842c, length = 41
+FDE[0]: bytes = 18 00 00 00 18 00 00 00 2c 84 04 08 29 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[0]: cie_offset = 0, cie_index = 0, fde_offset = 24
+FDE[0]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+no FDE at 8048400
+FDE[@804842c]: cie_offset = 0, cie_index = 0, fde_offset = 24
+FDE[@8048454]: cie_offset = 0, cie_index = 0, fde_offset = 24
+no FDE at 8048455
+no FDE at 80493fc
+testfile4 has 5 CIEs and 61 FDEs
+CIE[0]: bytes_in_cie = 20, version = 1, augmenter = "eh"
+CIE[0]: code_alignment_factor = 1
+CIE[0]: data_alignment_factor = fffffffffffffffc
+CIE[0]: return_address_register = 8
+CIE[0]: bytes = 0c 04 04 88 01
+CIE[1]: bytes_in_cie = 16, version = 1, augmenter = ""
+CIE[1]: code_alignment_factor = 1
+CIE[1]: data_alignment_factor = fffffffffffffffc
+CIE[1]: return_address_register = 8
+CIE[1]: bytes = 0c 04 04 88 01 00 00
+CIE[2]: bytes_in_cie = 16, version = 1, augmenter = ""
+CIE[2]: code_alignment_factor = 1
+CIE[2]: data_alignment_factor = fffffffffffffffc
+CIE[2]: return_address_register = 8
+CIE[2]: bytes = 0c 04 04 88 01 00 00
+CIE[3]: bytes_in_cie = 20, version = 1, augmenter = "eh"
+CIE[3]: code_alignment_factor = 1
+CIE[3]: data_alignment_factor = fffffffffffffffc
+CIE[3]: return_address_register = 8
+CIE[3]: bytes = 0c 04 04 88 01
+CIE[4]: bytes_in_cie = 16, version = 1, augmenter = ""
+CIE[4]: code_alignment_factor = 1
+CIE[4]: data_alignment_factor = fffffffffffffffc
+CIE[4]: return_address_register = 8
+CIE[4]: bytes = 0c 04 04 88 01 00 00
+FDE[0]: low_pc = 0x80493fc, length = 154
+FDE[0]: bytes = 2c 00 00 00 1c 00 00 00 fc 93 04 08 9a 00 00 00 41 0e 08 85 02 42 0d 05 53 2e 08 50 2e 10 48 2e 00 58 2e 10 62 2e 00 63 2e 10 45 2e 00 00 00 00
+FDE[0]: cie_offset = 0, cie_index = 0, fde_offset = 28
+FDE[0]: instructions = 41 0e 08 85 02 42 0d 05 53 2e 08 50 2e 10 48 2e 00 58 2e 10 62 2e 00 63 2e 10 45 2e 00 00 00 00
+FDE[1]: low_pc = 0x8049498, length = 49
+FDE[1]: bytes = 18 00 00 00 4c 00 00 00 98 94 04 08 31 00 00 00 41 0e 08 85 02 42 0d 05 4c 2e 10 00
+FDE[1]: cie_offset = 0, cie_index = 0, fde_offset = 76
+FDE[1]: instructions = 41 0e 08 85 02 42 0d 05 4c 2e 10 00
+FDE[2]: low_pc = 0x80494d4, length = 23
+FDE[2]: bytes = 18 00 00 00 18 00 00 00 d4 94 04 08 17 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[2]: cie_offset = 100, cie_index = 1, fde_offset = 24
+FDE[2]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[3]: low_pc = 0x80494f0, length = 26
+FDE[3]: bytes = 18 00 00 00 34 00 00 00 f0 94 04 08 1a 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[3]: cie_offset = 100, cie_index = 1, fde_offset = 52
+FDE[3]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[4]: low_pc = 0x8049560, length = 85
+FDE[4]: bytes = 24 00 00 00 50 00 00 00 60 95 04 08 55 00 00 00 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 53 2e 10 4e 2e 00 55 2e 10 00
+FDE[4]: cie_offset = 100, cie_index = 1, fde_offset = 80
+FDE[4]: instructions = 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 53 2e 10 4e 2e 00 55 2e 10 00
+FDE[5]: low_pc = 0x80495c0, length = 66
+FDE[5]: bytes = 20 00 00 00 78 00 00 00 c0 95 04 08 42 00 00 00 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 5e 2e 10 00 00 00
+FDE[5]: cie_offset = 100, cie_index = 1, fde_offset = 120
+FDE[5]: instructions = 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 5e 2e 10 00 00 00
+FDE[6]: low_pc = 0x8049610, length = 28
+FDE[6]: bytes = 18 00 00 00 9c 00 00 00 10 96 04 08 1c 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[6]: cie_offset = 100, cie_index = 1, fde_offset = 156
+FDE[6]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[7]: low_pc = 0x8049630, length = 31
+FDE[7]: bytes = 18 00 00 00 b8 00 00 00 30 96 04 08 1f 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[7]: cie_offset = 100, cie_index = 1, fde_offset = 184
+FDE[7]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[8]: low_pc = 0x80496e0, length = 71
+FDE[8]: bytes = 1c 00 00 00 d4 00 00 00 e0 96 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 5c 2e 10 00 00
+FDE[8]: cie_offset = 100, cie_index = 1, fde_offset = 212
+FDE[8]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 5c 2e 10 00 00
+FDE[9]: low_pc = 0x8049730, length = 165
+FDE[9]: bytes = 20 00 00 00 f4 00 00 00 30 97 04 08 a5 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 69 2e 10 02 66 2e 00 00 00
+FDE[9]: cie_offset = 100, cie_index = 1, fde_offset = 244
+FDE[9]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 69 2e 10 02 66 2e 00 00 00
+FDE[10]: low_pc = 0x80497e0, length = 89
+FDE[10]: bytes = 1c 00 00 00 18 01 00 00 e0 97 04 08 59 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 74 2e 10 00 00
+FDE[10]: cie_offset = 100, cie_index = 1, fde_offset = 280
+FDE[10]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 74 2e 10 00 00
+FDE[11]: low_pc = 0x8049840, length = 89
+FDE[11]: bytes = 28 00 00 00 38 01 00 00 40 98 04 08 59 00 00 00 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 55 2e 10 4e 2e 00 52 2e 10 4c 2e 00 00 00
+FDE[11]: cie_offset = 100, cie_index = 1, fde_offset = 312
+FDE[11]: instructions = 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 55 2e 10 4e 2e 00 52 2e 10 4c 2e 00 00 00
+FDE[12]: low_pc = 0x80498a0, length = 176
+FDE[12]: bytes = 24 00 00 00 64 01 00 00 a0 98 04 08 b0 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5e 2e 10 4c 2e 00 00
+FDE[12]: cie_offset = 100, cie_index = 1, fde_offset = 356
+FDE[12]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5e 2e 10 4c 2e 00 00
+FDE[13]: low_pc = 0x8049950, length = 116
+FDE[13]: bytes = 24 00 00 00 8c 01 00 00 50 99 04 08 74 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 5e 2e 10 00 00 00
+FDE[13]: cie_offset = 100, cie_index = 1, fde_offset = 396
+FDE[13]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 5e 2e 10 00 00 00
+FDE[14]: low_pc = 0x80499d0, length = 31
+FDE[14]: bytes = 18 00 00 00 b4 01 00 00 d0 99 04 08 1f 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[14]: cie_offset = 100, cie_index = 1, fde_offset = 436
+FDE[14]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[15]: low_pc = 0x80499f0, length = 313
+FDE[15]: bytes = 24 00 00 00 d0 01 00 00 f0 99 04 08 39 01 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 d8 2e 10 62 2e 00
+FDE[15]: cie_offset = 100, cie_index = 1, fde_offset = 464
+FDE[15]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 d8 2e 10 62 2e 00
+FDE[16]: low_pc = 0x8049b30, length = 262
+FDE[16]: bytes = 24 00 00 00 f8 01 00 00 30 9b 04 08 06 01 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 c8 2e 10 62 2e 00
+FDE[16]: cie_offset = 100, cie_index = 1, fde_offset = 504
+FDE[16]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 c8 2e 10 62 2e 00
+FDE[17]: low_pc = 0x8049c40, length = 95
+FDE[17]: bytes = 1c 00 00 00 20 02 00 00 40 9c 04 08 5f 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 6e 2e 10 00 00
+FDE[17]: cie_offset = 100, cie_index = 1, fde_offset = 544
+FDE[17]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 6e 2e 10 00 00
+FDE[18]: low_pc = 0x8049d60, length = 230
+FDE[18]: bytes = 20 00 00 00 40 02 00 00 60 9d 04 08 e6 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 02 9a 2e 10 00 00
+FDE[18]: cie_offset = 100, cie_index = 1, fde_offset = 576
+FDE[18]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 02 9a 2e 10 00 00
+FDE[19]: low_pc = 0x8049e50, length = 85
+FDE[19]: bytes = 18 00 00 00 64 02 00 00 50 9e 04 08 55 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[19]: cie_offset = 100, cie_index = 1, fde_offset = 612
+FDE[19]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[20]: low_pc = 0x8049eb0, length = 144
+FDE[20]: bytes = 20 00 00 00 80 02 00 00 b0 9e 04 08 90 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5b 2e 10
+FDE[20]: cie_offset = 100, cie_index = 1, fde_offset = 640
+FDE[20]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5b 2e 10
+FDE[21]: low_pc = 0x8049f40, length = 115
+FDE[21]: bytes = 20 00 00 00 a4 02 00 00 40 9f 04 08 73 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 59 2e 10
+FDE[21]: cie_offset = 100, cie_index = 1, fde_offset = 676
+FDE[21]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 59 2e 10
+FDE[22]: low_pc = 0x8049fd0, length = 948
+FDE[22]: bytes = 30 00 00 00 c8 02 00 00 d0 9f 04 08 b4 03 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 f7 2e 20 02 64 2e 10 03 15 01 2e 00 02 9f 2e 10 00 00
+FDE[22]: cie_offset = 100, cie_index = 1, fde_offset = 712
+FDE[22]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 f7 2e 20 02 64 2e 10 03 15 01 2e 00 02 9f 2e 10 00 00
+FDE[23]: low_pc = 0x804a390, length = 201
+FDE[23]: bytes = 28 00 00 00 fc 02 00 00 90 a3 04 08 c9 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 58 2e 10 52 2e 00 75 2e 10 00
+FDE[23]: cie_offset = 100, cie_index = 1, fde_offset = 764
+FDE[23]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 58 2e 10 52 2e 00 75 2e 10 00
+FDE[24]: low_pc = 0x804a460, length = 206
+FDE[24]: bytes = 28 00 00 00 28 03 00 00 60 a4 04 08 ce 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 64 2e 10 52 2e 00 6e 2e 10 00
+FDE[24]: cie_offset = 100, cie_index = 1, fde_offset = 808
+FDE[24]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 64 2e 10 52 2e 00 6e 2e 10 00
+FDE[25]: low_pc = 0x804b970, length = 1274
+FDE[25]: bytes = 44 00 00 00 18 00 00 00 70 b9 04 08 fa 04 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 66 2e 10 7b 2e 20 03 7f 01 2e 10 53 2e 08 4c 2e 10 79 2e 20 02 54 2e 10 7e 2e 20 03 6c 01 2e 10 02 45 2e 20 00 00 00
+FDE[25]: cie_offset = 948, cie_index = 2, fde_offset = 24
+FDE[25]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 66 2e 10 7b 2e 20 03 7f 01 2e 10 53 2e 08 4c 2e 10 79 2e 20 02 54 2e 10 7e 2e 20 03 6c 01 2e 10 02 45 2e 20 00 00 00
+FDE[26]: low_pc = 0x804be70, length = 60
+FDE[26]: bytes = 1c 00 00 00 60 00 00 00 70 be 04 08 3c 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 5e 2e 10 00 00
+FDE[26]: cie_offset = 948, cie_index = 2, fde_offset = 96
+FDE[26]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 5e 2e 10 00 00
+FDE[27]: low_pc = 0x804c090, length = 85
+FDE[27]: bytes = 24 00 00 00 80 00 00 00 90 c0 04 08 55 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 66 2e 04 4d 2e 0c 4c 2e 04 46 2e 20 00
+FDE[27]: cie_offset = 948, cie_index = 2, fde_offset = 128
+FDE[27]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 66 2e 04 4d 2e 0c 4c 2e 04 46 2e 20 00
+FDE[28]: low_pc = 0x804c0f0, length = 75
+FDE[28]: bytes = 2c 00 00 00 a8 00 00 00 f0 c0 04 08 4b 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5b 2e 04 4a 2e 0c 4d 2e 04 46 2e 20 00 00 00
+FDE[28]: cie_offset = 948, cie_index = 2, fde_offset = 168
+FDE[28]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5b 2e 04 4a 2e 0c 4d 2e 04 46 2e 20 00 00 00
+FDE[29]: low_pc = 0x804d8e0, length = 71
+FDE[29]: bytes = 20 00 00 00 d8 00 00 00 e0 d8 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[29]: cie_offset = 948, cie_index = 2, fde_offset = 216
+FDE[29]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[30]: low_pc = 0x804d980, length = 71
+FDE[30]: bytes = 20 00 00 00 fc 00 00 00 80 d9 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[30]: cie_offset = 948, cie_index = 2, fde_offset = 252
+FDE[30]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[31]: low_pc = 0x804da20, length = 71
+FDE[31]: bytes = 20 00 00 00 20 01 00 00 20 da 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[31]: cie_offset = 948, cie_index = 2, fde_offset = 288
+FDE[31]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[32]: low_pc = 0x804dac0, length = 71
+FDE[32]: bytes = 20 00 00 00 44 01 00 00 c0 da 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[32]: cie_offset = 948, cie_index = 2, fde_offset = 324
+FDE[32]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[33]: low_pc = 0x804db60, length = 71
+FDE[33]: bytes = 20 00 00 00 68 01 00 00 60 db 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[33]: cie_offset = 948, cie_index = 2, fde_offset = 360
+FDE[33]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[34]: low_pc = 0x804dc00, length = 71
+FDE[34]: bytes = 20 00 00 00 8c 01 00 00 00 dc 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[34]: cie_offset = 948, cie_index = 2, fde_offset = 396
+FDE[34]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[35]: low_pc = 0x804dca0, length = 71
+FDE[35]: bytes = 20 00 00 00 b0 01 00 00 a0 dc 04 08 47 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[35]: cie_offset = 948, cie_index = 2, fde_offset = 432
+FDE[35]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 60 2e 10
+FDE[36]: low_pc = 0x804c5b4, length = 26
+FDE[36]: bytes = 18 00 00 00 1c 00 00 00 b4 c5 04 08 1a 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[36]: cie_offset = 1412, cie_index = 3, fde_offset = 28
+FDE[36]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[37]: low_pc = 0x804c5d0, length = 23
+FDE[37]: bytes = 18 00 00 00 38 00 00 00 d0 c5 04 08 17 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[37]: cie_offset = 1412, cie_index = 3, fde_offset = 56
+FDE[37]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[38]: low_pc = 0x804c640, length = 24
+FDE[38]: bytes = 18 00 00 00 54 00 00 00 40 c6 04 08 18 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[38]: cie_offset = 1412, cie_index = 3, fde_offset = 84
+FDE[38]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[39]: low_pc = 0x804c660, length = 32
+FDE[39]: bytes = 18 00 00 00 70 00 00 00 60 c6 04 08 20 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[39]: cie_offset = 1412, cie_index = 3, fde_offset = 112
+FDE[39]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[40]: low_pc = 0x804c680, length = 29
+FDE[40]: bytes = 18 00 00 00 8c 00 00 00 80 c6 04 08 1d 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[40]: cie_offset = 1412, cie_index = 3, fde_offset = 140
+FDE[40]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[41]: low_pc = 0x804c6a0, length = 36
+FDE[41]: bytes = 18 00 00 00 a8 00 00 00 a0 c6 04 08 24 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[41]: cie_offset = 1412, cie_index = 3, fde_offset = 168
+FDE[41]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[42]: low_pc = 0x804c6d0, length = 98
+FDE[42]: bytes = 24 00 00 00 c4 00 00 00 d0 c6 04 08 62 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 43 2e 10 00 00 00
+FDE[42]: cie_offset = 1412, cie_index = 3, fde_offset = 196
+FDE[42]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 43 2e 10 00 00 00
+FDE[43]: low_pc = 0x804c740, length = 107
+FDE[43]: bytes = 24 00 00 00 ec 00 00 00 40 c7 04 08 6b 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 53 2e 10 7b 2e 00 00
+FDE[43]: cie_offset = 1412, cie_index = 3, fde_offset = 236
+FDE[43]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 53 2e 10 7b 2e 00 00
+FDE[44]: low_pc = 0x804c7b0, length = 256
+FDE[44]: bytes = 24 00 00 00 14 01 00 00 b0 c7 04 08 00 01 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 bf 2e 10 00 00 00
+FDE[44]: cie_offset = 1412, cie_index = 3, fde_offset = 276
+FDE[44]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 02 bf 2e 10 00 00 00
+FDE[45]: low_pc = 0x804c8b0, length = 78
+FDE[45]: bytes = 1c 00 00 00 3c 01 00 00 b0 c8 04 08 4e 00 00 00 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 00 00
+FDE[45]: cie_offset = 1412, cie_index = 3, fde_offset = 316
+FDE[45]: instructions = 41 0e 08 85 02 42 0d 05 41 86 03 41 83 04 00 00
+FDE[46]: low_pc = 0x804c900, length = 480
+FDE[46]: bytes = 40 00 00 00 5c 01 00 00 00 c9 04 08 e0 01 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 7d 2e 10 4c 2e 00 02 48 2e 10 02 54 2e 00 78 2e 10 4c 2e 00 02 44 2e 10 79 2e 08 49 2e 10 48 2e 00 00 00
+FDE[46]: cie_offset = 1412, cie_index = 3, fde_offset = 348
+FDE[46]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 7d 2e 10 4c 2e 00 02 48 2e 10 02 54 2e 00 78 2e 10 4c 2e 00 02 44 2e 10 79 2e 08 49 2e 10 48 2e 00 00 00
+FDE[47]: low_pc = 0x804cae0, length = 37
+FDE[47]: bytes = 1c 00 00 00 a0 01 00 00 e0 ca 04 08 25 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 52 2e 10 00 00
+FDE[47]: cie_offset = 1412, cie_index = 3, fde_offset = 416
+FDE[47]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 52 2e 10 00 00
+FDE[48]: low_pc = 0x804cb10, length = 128
+FDE[48]: bytes = 2c 00 00 00 c0 01 00 00 10 cb 04 08 80 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 62 2e 10 56 2e 08 49 2e 10 48 2e 00 6c 2e 10
+FDE[48]: cie_offset = 1412, cie_index = 3, fde_offset = 448
+FDE[48]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 62 2e 10 56 2e 08 49 2e 10 48 2e 00 6c 2e 10
+FDE[49]: low_pc = 0x804cb90, length = 128
+FDE[49]: bytes = 2c 00 00 00 f0 01 00 00 90 cb 04 08 80 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 62 2e 10 56 2e 08 49 2e 10 48 2e 00 6c 2e 10
+FDE[49]: cie_offset = 1412, cie_index = 3, fde_offset = 496
+FDE[49]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 62 2e 10 56 2e 08 49 2e 10 48 2e 00 6c 2e 10
+FDE[50]: low_pc = 0x804cc10, length = 45
+FDE[50]: bytes = 18 00 00 00 20 02 00 00 10 cc 04 08 2d 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[50]: cie_offset = 1412, cie_index = 3, fde_offset = 544
+FDE[50]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[51]: low_pc = 0x804cc40, length = 43
+FDE[51]: bytes = 18 00 00 00 3c 02 00 00 40 cc 04 08 2b 00 00 00 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[51]: cie_offset = 1412, cie_index = 3, fde_offset = 572
+FDE[51]: instructions = 41 0e 08 85 02 42 0d 05 41 83 03 00
+FDE[52]: low_pc = 0x804cde0, length = 89
+FDE[52]: bytes = 20 00 00 00 18 00 00 00 e0 cd 04 08 59 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 6d 2e 20 00 00 00
+FDE[52]: cie_offset = 2008, cie_index = 4, fde_offset = 24
+FDE[52]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 6d 2e 20 00 00 00
+FDE[53]: low_pc = 0x804ce40, length = 217
+FDE[53]: bytes = 20 00 00 00 3c 00 00 00 40 ce 04 08 d9 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 02 40 2e 20 00 00
+FDE[53]: cie_offset = 2008, cie_index = 4, fde_offset = 60
+FDE[53]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 02 40 2e 20 00 00
+FDE[54]: low_pc = 0x804d010, length = 117
+FDE[54]: bytes = 24 00 00 00 60 00 00 00 10 d0 04 08 75 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5c 2e 10 02 48 2e 20
+FDE[54]: cie_offset = 2008, cie_index = 4, fde_offset = 96
+FDE[54]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 5c 2e 10 02 48 2e 20
+FDE[55]: low_pc = 0x804d090, length = 190
+FDE[55]: bytes = 24 00 00 00 88 00 00 00 90 d0 04 08 be 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 64 2e 10 02 89 2e 20
+FDE[55]: cie_offset = 2008, cie_index = 4, fde_offset = 136
+FDE[55]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 64 2e 10 02 89 2e 20
+FDE[56]: low_pc = 0x804d150, length = 101
+FDE[56]: bytes = 24 00 00 00 b0 00 00 00 50 d1 04 08 65 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 61 2e 10 73 2e 20 00
+FDE[56]: cie_offset = 2008, cie_index = 4, fde_offset = 176
+FDE[56]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 61 2e 10 73 2e 20 00
+FDE[57]: low_pc = 0x804d1c0, length = 480
+FDE[57]: bytes = 28 00 00 00 d8 00 00 00 c0 d1 04 08 e0 01 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 56 2e 10 02 f5 2e 20 02 91 2e 10
+FDE[57]: cie_offset = 2008, cie_index = 4, fde_offset = 216
+FDE[57]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 56 2e 10 02 f5 2e 20 02 91 2e 10
+FDE[58]: low_pc = 0x804d3a0, length = 897
+FDE[58]: bytes = 28 00 00 00 04 01 00 00 a0 d3 04 08 81 03 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 61 2e 10 03 61 01 2e 20 00 00 00
+FDE[58]: cie_offset = 2008, cie_index = 4, fde_offset = 260
+FDE[58]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 61 2e 10 03 61 01 2e 20 00 00 00
+FDE[59]: low_pc = 0x804d730, length = 238
+FDE[59]: bytes = 24 00 00 00 30 01 00 00 30 d7 04 08 ee 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 61 2e 10 02 8f 2e 20
+FDE[59]: cie_offset = 2008, cie_index = 4, fde_offset = 304
+FDE[59]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 41 86 04 41 83 05 61 2e 10 02 8f 2e 20
+FDE[60]: low_pc = 0x804e220, length = 73
+FDE[60]: bytes = 20 00 00 00 58 01 00 00 20 e2 04 08 49 00 00 00 41 0e 08 85 02 42 0d 05 41 87 03 44 86 04 74 2e 20 00 00 00
+FDE[60]: cie_offset = 2008, cie_index = 4, fde_offset = 344
+FDE[60]: instructions = 41 0e 08 85 02 42 0d 05 41 87 03 44 86 04 74 2e 20 00 00 00
+no FDE at 8048400
+no FDE at 804842c
+no FDE at 8048454
+no FDE at 8048455
+FDE[@80493fc]: cie_offset = 0, cie_index = 0, fde_offset = 28
+EOF
+
+rm -f testfile3 testfile4 show-ciefde.out
+
+exit 0
diff --git a/tests/run-show-die-info.sh b/tests/run-show-die-info.sh
new file mode 100644
index 0000000..0426326
--- /dev/null
+++ b/tests/run-show-die-info.sh
@@ -0,0 +1,988 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2003, 2004 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile5.bz2 > testfile5 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/testfile2.bz2 > testfile2 2>/dev/null || exit 0
+
+./show-die-info testfile5 testfile2 > show-die-info.out
+
+diff -u show-die-info.out - <<"EOF"
+file: testfile5
+New CU: off = 0, hsize = 11, ab = 0, as = 4, os = 4
+ DW_TAG_compile_unit
+ Name : b.c
+ Offset : 11
+ CU offset : 11
+ Attrs : name stmt_list low_pc high_pc language comp_dir producer
+ low PC : 0x804842c
+ high PC : 0x8048436
+ language : 1
+ directory : /home/drepper/gnu/new-bu/build/ttt
+ producer : GNU C 2.96 20000731 (Red Hat Linux 7.0)
+ DW_TAG_subprogram
+ Name : bar
+ Offset : 104
+ CU offset : 104
+ Attrs : name low_pc high_pc prototyped decl_file decl_line external frame_base type
+ low PC : 0x804842c
+ high PC : 0x8048436
+ DW_TAG_base_type
+ Name : int
+ Offset : 127
+ CU offset : 127
+ Attrs : name byte_size encoding
+ byte size : 4
+New CU: off = 135, hsize = 11, ab = 54, as = 4, os = 4
+ DW_TAG_compile_unit
+ Name : f.c
+ Offset : 146
+ CU offset : 11
+ Attrs : name stmt_list low_pc high_pc language comp_dir producer
+ low PC : 0x8048438
+ high PC : 0x8048442
+ language : 1
+ directory : /home/drepper/gnu/new-bu/build/ttt
+ producer : GNU C 2.96 20000731 (Red Hat Linux 7.0)
+ DW_TAG_subprogram
+ Name : foo
+ Offset : 239
+ CU offset : 104
+ Attrs : name low_pc high_pc prototyped decl_file decl_line external frame_base type
+ low PC : 0x8048438
+ high PC : 0x8048442
+ DW_TAG_base_type
+ Name : int
+ Offset : 262
+ CU offset : 127
+ Attrs : name byte_size encoding
+ byte size : 4
+New CU: off = 270, hsize = 11, ab = 108, as = 4, os = 4
+ DW_TAG_compile_unit
+ Name : m.c
+ Offset : 281
+ CU offset : 11
+ Attrs : name stmt_list low_pc high_pc language comp_dir producer
+ low PC : 0x8048444
+ high PC : 0x8048472
+ language : 1
+ directory : /home/drepper/gnu/new-bu/build/ttt
+ producer : GNU C 2.96 20000731 (Red Hat Linux 7.0)
+ DW_TAG_subprogram
+ Name : main
+ Offset : 374
+ CU offset : 104
+ Attrs : sibling name low_pc high_pc prototyped decl_file decl_line external frame_base type
+ low PC : 0x8048444
+ high PC : 0x8048472
+ DW_TAG_subprogram
+ Name : bar
+ Offset : 402
+ CU offset : 132
+ Attrs : sibling name decl_file decl_line declaration external type
+ DW_TAG_unspecified_parameters
+ Name : * NO NAME *
+ Offset : 419
+ CU offset : 149
+ Attrs :
+ DW_TAG_subprogram
+ Name : foo
+ Offset : 421
+ CU offset : 151
+ Attrs : name decl_file decl_line declaration external type
+ DW_TAG_unspecified_parameters
+ Name : * NO NAME *
+ Offset : 434
+ CU offset : 164
+ Attrs :
+ DW_TAG_base_type
+ Name : int
+ Offset : 437
+ CU offset : 167
+ Attrs : name byte_size encoding
+ byte size : 4
+ DW_TAG_variable
+ Name : a
+ Offset : 444
+ CU offset : 174
+ Attrs : location name decl_file decl_line external type
+file: testfile2
+New CU: off = 0, hsize = 11, ab = 0, as = 4, os = 4
+ DW_TAG_compile_unit
+ Name : b.c
+ Offset : 11
+ CU offset : 11
+ Attrs : name stmt_list low_pc high_pc language comp_dir producer
+ low PC : 0x10000470
+ high PC : 0x10000490
+ language : 1
+ directory : /shoggoth/drepper
+ producer : GNU C 2.96-laurel-000912
+ DW_TAG_subprogram
+ Name : bar
+ Offset : 72
+ CU offset : 72
+ Attrs : name low_pc high_pc prototyped decl_file decl_line external frame_base type
+ low PC : 0x10000470
+ high PC : 0x10000490
+ DW_TAG_base_type
+ Name : int
+ Offset : 95
+ CU offset : 95
+ Attrs : name byte_size encoding
+ byte size : 4
+ DW_TAG_typedef
+ Name : size_t
+ Offset : 102
+ CU offset : 102
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : unsigned int
+ Offset : 116
+ CU offset : 116
+ Attrs : name byte_size encoding
+ byte size : 4
+ DW_TAG_typedef
+ Name : __gnuc_va_list
+ Offset : 132
+ CU offset : 132
+ Attrs : name decl_file decl_line type
+ DW_TAG_array_type
+ Name : __builtin_va_list
+ Offset : 154
+ CU offset : 154
+ Attrs : sibling name type
+ DW_TAG_subrange_type
+ Name : * NO NAME *
+ Offset : 181
+ CU offset : 181
+ Attrs : upper_bound type
+ DW_TAG_base_type
+ Name : unsigned int
+ Offset : 188
+ CU offset : 188
+ Attrs : name byte_size encoding
+ byte size : 4
+ DW_TAG_structure_type
+ Name : __va_list_tag
+ Offset : 204
+ CU offset : 204
+ Attrs : sibling name byte_size decl_file decl_line
+ byte size : 12
+ DW_TAG_member
+ Name : gpr
+ Offset : 226
+ CU offset : 226
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : fpr
+ Offset : 240
+ CU offset : 240
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : overflow_arg_area
+ Offset : 254
+ CU offset : 254
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : reg_save_area
+ Offset : 282
+ CU offset : 282
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_base_type
+ Name : unsigned char
+ Offset : 307
+ CU offset : 307
+ Attrs : name byte_size encoding
+ byte size : 1
+ DW_TAG_pointer_type
+ Name : * NO NAME *
+ Offset : 324
+ CU offset : 324
+ Attrs : byte_size
+ byte size : 4
+ DW_TAG_typedef
+ Name : __u_char
+ Offset : 326
+ CU offset : 326
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __u_short
+ Offset : 342
+ CU offset : 342
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : short unsigned int
+ Offset : 359
+ CU offset : 359
+ Attrs : name byte_size encoding
+ byte size : 2
+ DW_TAG_typedef
+ Name : __u_int
+ Offset : 381
+ CU offset : 381
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __u_long
+ Offset : 396
+ CU offset : 396
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : long unsigned int
+ Offset : 412
+ CU offset : 412
+ Attrs : name byte_size encoding
+ byte size : 4
+ DW_TAG_typedef
+ Name : __u_quad_t
+ Offset : 433
+ CU offset : 433
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : long long unsigned int
+ Offset : 451
+ CU offset : 451
+ Attrs : name byte_size encoding
+ byte size : 8
+ DW_TAG_typedef
+ Name : __quad_t
+ Offset : 477
+ CU offset : 477
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : long long int
+ Offset : 493
+ CU offset : 493
+ Attrs : name byte_size encoding
+ byte size : 8
+ DW_TAG_typedef
+ Name : __int8_t
+ Offset : 510
+ CU offset : 510
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : signed char
+ Offset : 526
+ CU offset : 526
+ Attrs : name byte_size encoding
+ byte size : 1
+ DW_TAG_typedef
+ Name : __uint8_t
+ Offset : 541
+ CU offset : 541
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __int16_t
+ Offset : 558
+ CU offset : 558
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : short int
+ Offset : 575
+ CU offset : 575
+ Attrs : name byte_size encoding
+ byte size : 2
+ DW_TAG_typedef
+ Name : __uint16_t
+ Offset : 588
+ CU offset : 588
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __int32_t
+ Offset : 606
+ CU offset : 606
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __uint32_t
+ Offset : 623
+ CU offset : 623
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __int64_t
+ Offset : 641
+ CU offset : 641
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __uint64_t
+ Offset : 658
+ CU offset : 658
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __qaddr_t
+ Offset : 676
+ CU offset : 676
+ Attrs : name decl_file decl_line type
+ DW_TAG_pointer_type
+ Name : * NO NAME *
+ Offset : 693
+ CU offset : 693
+ Attrs : byte_size type
+ byte size : 4
+ DW_TAG_typedef
+ Name : __dev_t
+ Offset : 699
+ CU offset : 699
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __uid_t
+ Offset : 714
+ CU offset : 714
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __gid_t
+ Offset : 729
+ CU offset : 729
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __ino_t
+ Offset : 744
+ CU offset : 744
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __mode_t
+ Offset : 759
+ CU offset : 759
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __nlink_t
+ Offset : 775
+ CU offset : 775
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __off_t
+ Offset : 792
+ CU offset : 792
+ Attrs : name decl_file decl_line type
+ DW_TAG_base_type
+ Name : long int
+ Offset : 807
+ CU offset : 807
+ Attrs : name byte_size encoding
+ byte size : 4
+ DW_TAG_typedef
+ Name : __loff_t
+ Offset : 819
+ CU offset : 819
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __pid_t
+ Offset : 835
+ CU offset : 835
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __ssize_t
+ Offset : 850
+ CU offset : 850
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __rlim_t
+ Offset : 867
+ CU offset : 867
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __rlim64_t
+ Offset : 883
+ CU offset : 883
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __id_t
+ Offset : 901
+ CU offset : 901
+ Attrs : name decl_file decl_line type
+ DW_TAG_structure_type
+ Name : * NO NAME *
+ Offset : 915
+ CU offset : 915
+ Attrs : sibling byte_size decl_file decl_line
+ byte size : 8
+ DW_TAG_member
+ Name : __val
+ Offset : 923
+ CU offset : 923
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_array_type
+ Name : * NO NAME *
+ Offset : 940
+ CU offset : 940
+ Attrs : sibling type
+ DW_TAG_subrange_type
+ Name : * NO NAME *
+ Offset : 949
+ CU offset : 949
+ Attrs : upper_bound type
+ DW_TAG_typedef
+ Name : __fsid_t
+ Offset : 956
+ CU offset : 956
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __daddr_t
+ Offset : 972
+ CU offset : 972
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __caddr_t
+ Offset : 989
+ CU offset : 989
+ Attrs : name decl_file decl_line type
+ DW_TAG_pointer_type
+ Name : * NO NAME *
+ Offset : 1006
+ CU offset : 1006
+ Attrs : byte_size type
+ byte size : 4
+ DW_TAG_base_type
+ Name : char
+ Offset : 1012
+ CU offset : 1012
+ Attrs : name byte_size encoding
+ byte size : 1
+ DW_TAG_typedef
+ Name : __time_t
+ Offset : 1020
+ CU offset : 1020
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __swblk_t
+ Offset : 1036
+ CU offset : 1036
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __clock_t
+ Offset : 1053
+ CU offset : 1053
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __fd_mask
+ Offset : 1070
+ CU offset : 1070
+ Attrs : name decl_file decl_line type
+ DW_TAG_structure_type
+ Name : * NO NAME *
+ Offset : 1087
+ CU offset : 1087
+ Attrs : sibling byte_size decl_file decl_line
+ byte size : 128
+ DW_TAG_member
+ Name : __fds_bits
+ Offset : 1095
+ CU offset : 1095
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_array_type
+ Name : * NO NAME *
+ Offset : 1117
+ CU offset : 1117
+ Attrs : sibling type
+ DW_TAG_subrange_type
+ Name : * NO NAME *
+ Offset : 1126
+ CU offset : 1126
+ Attrs : upper_bound type
+ DW_TAG_typedef
+ Name : __fd_set
+ Offset : 1133
+ CU offset : 1133
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __key_t
+ Offset : 1149
+ CU offset : 1149
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __ipc_pid_t
+ Offset : 1164
+ CU offset : 1164
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __blkcnt_t
+ Offset : 1183
+ CU offset : 1183
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __blkcnt64_t
+ Offset : 1201
+ CU offset : 1201
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __fsblkcnt_t
+ Offset : 1221
+ CU offset : 1221
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __fsblkcnt64_t
+ Offset : 1241
+ CU offset : 1241
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __fsfilcnt_t
+ Offset : 1263
+ CU offset : 1263
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __fsfilcnt64_t
+ Offset : 1283
+ CU offset : 1283
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __ino64_t
+ Offset : 1305
+ CU offset : 1305
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __off64_t
+ Offset : 1322
+ CU offset : 1322
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __t_scalar_t
+ Offset : 1339
+ CU offset : 1339
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __t_uscalar_t
+ Offset : 1359
+ CU offset : 1359
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : __intptr_t
+ Offset : 1380
+ CU offset : 1380
+ Attrs : name decl_file decl_line type
+ DW_TAG_structure_type
+ Name : _IO_FILE
+ Offset : 1398
+ CU offset : 1398
+ Attrs : sibling name byte_size decl_file decl_line
+ byte size : 152
+ DW_TAG_member
+ Name : _flags
+ Offset : 1415
+ CU offset : 1415
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_read_ptr
+ Offset : 1432
+ CU offset : 1432
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_read_end
+ Offset : 1455
+ CU offset : 1455
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_read_base
+ Offset : 1478
+ CU offset : 1478
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_write_base
+ Offset : 1502
+ CU offset : 1502
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_write_ptr
+ Offset : 1527
+ CU offset : 1527
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_write_end
+ Offset : 1551
+ CU offset : 1551
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_buf_base
+ Offset : 1575
+ CU offset : 1575
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_buf_end
+ Offset : 1598
+ CU offset : 1598
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_save_base
+ Offset : 1620
+ CU offset : 1620
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_backup_base
+ Offset : 1644
+ CU offset : 1644
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _IO_save_end
+ Offset : 1670
+ CU offset : 1670
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _markers
+ Offset : 1693
+ CU offset : 1693
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _chain
+ Offset : 1712
+ CU offset : 1712
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _fileno
+ Offset : 1729
+ CU offset : 1729
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _blksize
+ Offset : 1747
+ CU offset : 1747
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _old_offset
+ Offset : 1766
+ CU offset : 1766
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _cur_column
+ Offset : 1788
+ CU offset : 1788
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _vtable_offset
+ Offset : 1810
+ CU offset : 1810
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _shortbuf
+ Offset : 1835
+ CU offset : 1835
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _lock
+ Offset : 1855
+ CU offset : 1855
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _offset
+ Offset : 1871
+ CU offset : 1871
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _unused2
+ Offset : 1889
+ CU offset : 1889
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_structure_type
+ Name : _IO_marker
+ Offset : 1909
+ CU offset : 1909
+ Attrs : sibling name byte_size decl_file decl_line
+ byte size : 12
+ DW_TAG_member
+ Name : _next
+ Offset : 1928
+ CU offset : 1928
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _sbuf
+ Offset : 1944
+ CU offset : 1944
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_member
+ Name : _pos
+ Offset : 1960
+ CU offset : 1960
+ Attrs : name data_member_location decl_file decl_line type
+ DW_TAG_pointer_type
+ Name : * NO NAME *
+ Offset : 1976
+ CU offset : 1976
+ Attrs : byte_size type
+ byte size : 4
+ DW_TAG_pointer_type
+ Name : * NO NAME *
+ Offset : 1982
+ CU offset : 1982
+ Attrs : byte_size type
+ byte size : 4
+ DW_TAG_array_type
+ Name : * NO NAME *
+ Offset : 1988
+ CU offset : 1988
+ Attrs : sibling type
+ DW_TAG_subrange_type
+ Name : * NO NAME *
+ Offset : 1997
+ CU offset : 1997
+ Attrs : upper_bound type
+ DW_TAG_pointer_type
+ Name : * NO NAME *
+ Offset : 2004
+ CU offset : 2004
+ Attrs : byte_size
+ byte size : 4
+ DW_TAG_array_type
+ Name : * NO NAME *
+ Offset : 2006
+ CU offset : 2006
+ Attrs : sibling type
+ DW_TAG_subrange_type
+ Name : * NO NAME *
+ Offset : 2015
+ CU offset : 2015
+ Attrs : upper_bound type
+ DW_TAG_typedef
+ Name : FILE
+ Offset : 2022
+ CU offset : 2022
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : wchar_t
+ Offset : 2034
+ CU offset : 2034
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : wint_t
+ Offset : 2050
+ CU offset : 2050
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : _G_int16_t
+ Offset : 2065
+ CU offset : 2065
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : _G_int32_t
+ Offset : 2083
+ CU offset : 2083
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : _G_uint16_t
+ Offset : 2101
+ CU offset : 2101
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : _G_uint32_t
+ Offset : 2120
+ CU offset : 2120
+ Attrs : name decl_file decl_line type
+ DW_TAG_structure_type
+ Name : _IO_jump_t
+ Offset : 2139
+ CU offset : 2139
+ Attrs : name declaration
+ DW_TAG_typedef
+ Name : _IO_lock_t
+ Offset : 2152
+ CU offset : 2152
+ Attrs : name decl_file decl_line
+ DW_TAG_typedef
+ Name : _IO_FILE
+ Offset : 2166
+ CU offset : 2166
+ Attrs : name decl_file decl_line type
+ DW_TAG_structure_type
+ Name : _IO_FILE_plus
+ Offset : 2182
+ CU offset : 2182
+ Attrs : name declaration
+ DW_TAG_typedef
+ Name : __io_read_fn
+ Offset : 2198
+ CU offset : 2198
+ Attrs : name decl_file decl_line type
+ DW_TAG_subroutine_type
+ Name : * NO NAME *
+ Offset : 2219
+ CU offset : 2219
+ Attrs : sibling prototyped type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2229
+ CU offset : 2229
+ Attrs : type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2234
+ CU offset : 2234
+ Attrs : type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2239
+ CU offset : 2239
+ Attrs : type
+ DW_TAG_typedef
+ Name : __io_write_fn
+ Offset : 2245
+ CU offset : 2245
+ Attrs : name decl_file decl_line type
+ DW_TAG_subroutine_type
+ Name : * NO NAME *
+ Offset : 2267
+ CU offset : 2267
+ Attrs : sibling prototyped type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2277
+ CU offset : 2277
+ Attrs : type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2282
+ CU offset : 2282
+ Attrs : type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2287
+ CU offset : 2287
+ Attrs : type
+ DW_TAG_pointer_type
+ Name : * NO NAME *
+ Offset : 2293
+ CU offset : 2293
+ Attrs : byte_size type
+ byte size : 4
+ DW_TAG_const_type
+ Name : * NO NAME *
+ Offset : 2299
+ CU offset : 2299
+ Attrs : type
+ DW_TAG_typedef
+ Name : __io_seek_fn
+ Offset : 2304
+ CU offset : 2304
+ Attrs : name decl_file decl_line type
+ DW_TAG_subroutine_type
+ Name : * NO NAME *
+ Offset : 2325
+ CU offset : 2325
+ Attrs : sibling prototyped type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2335
+ CU offset : 2335
+ Attrs : type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2340
+ CU offset : 2340
+ Attrs : type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2345
+ CU offset : 2345
+ Attrs : type
+ DW_TAG_typedef
+ Name : __io_close_fn
+ Offset : 2351
+ CU offset : 2351
+ Attrs : name decl_file decl_line type
+ DW_TAG_subroutine_type
+ Name : * NO NAME *
+ Offset : 2373
+ CU offset : 2373
+ Attrs : sibling prototyped type
+ DW_TAG_formal_parameter
+ Name : * NO NAME *
+ Offset : 2383
+ CU offset : 2383
+ Attrs : type
+ DW_TAG_typedef
+ Name : fpos_t
+ Offset : 2389
+ CU offset : 2389
+ Attrs : name decl_file decl_line type
+ DW_TAG_typedef
+ Name : off_t
+ Offset : 2403
+ CU offset : 2403
+ Attrs : name decl_file decl_line type
+New CU: off = 2418, hsize = 11, ab = 213, as = 4, os = 4
+ DW_TAG_compile_unit
+ Name : f.c
+ Offset : 2429
+ CU offset : 11
+ Attrs : name stmt_list low_pc high_pc language comp_dir producer
+ low PC : 0x10000490
+ high PC : 0x100004b0
+ language : 1
+ directory : /shoggoth/drepper
+ producer : GNU C 2.96-laurel-000912
+ DW_TAG_subprogram
+ Name : foo
+ Offset : 2490
+ CU offset : 72
+ Attrs : name low_pc high_pc prototyped decl_file decl_line external frame_base type
+ low PC : 0x10000490
+ high PC : 0x100004b0
+ DW_TAG_base_type
+ Name : int
+ Offset : 2513
+ CU offset : 95
+ Attrs : name byte_size encoding
+ byte size : 4
+New CU: off = 2521, hsize = 11, ab = 267, as = 4, os = 4
+ DW_TAG_compile_unit
+ Name : m.c
+ Offset : 2532
+ CU offset : 11
+ Attrs : name stmt_list low_pc high_pc language comp_dir producer
+ low PC : 0x100004b0
+ high PC : 0x10000514
+ language : 1
+ directory : /shoggoth/drepper
+ producer : GNU C 2.96-laurel-000912
+ DW_TAG_subprogram
+ Name : main
+ Offset : 2593
+ CU offset : 72
+ Attrs : sibling name low_pc high_pc prototyped decl_file decl_line external frame_base type
+ low PC : 0x100004b0
+ high PC : 0x10000514
+ DW_TAG_subprogram
+ Name : bar
+ Offset : 2621
+ CU offset : 100
+ Attrs : sibling name decl_file decl_line declaration external type
+ DW_TAG_unspecified_parameters
+ Name : * NO NAME *
+ Offset : 2638
+ CU offset : 117
+ Attrs :
+ DW_TAG_subprogram
+ Name : foo
+ Offset : 2640
+ CU offset : 119
+ Attrs : name decl_file decl_line declaration external type
+ DW_TAG_unspecified_parameters
+ Name : * NO NAME *
+ Offset : 2653
+ CU offset : 132
+ Attrs :
+ DW_TAG_base_type
+ Name : int
+ Offset : 2656
+ CU offset : 135
+ Attrs : name byte_size encoding
+ byte size : 4
+ DW_TAG_variable
+ Name : a
+ Offset : 2663
+ CU offset : 142
+ Attrs : location name decl_file decl_line external type
+EOF
+
+rm -f testfile2 testfile5 show-die-info.out
+
+exit 0
diff --git a/tests/run-strip-test.sh b/tests/run-strip-test.sh
new file mode 100644
index 0000000..526eb09
--- /dev/null
+++ b/tests/run-strip-test.sh
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2003, 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+set -e
+
+original=${original:-testfile11}
+stripped=${stripped:-testfile7}
+debugout=${debugfile:+-f testfile.debug.temp -F $debugfile}
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/$original.bz2 > $original 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+bunzip2 -c $srcdir/$stripped.bz2 > $stripped 2>/dev/null || exit 0
+
+# Don't fail if we cannot decompress the file.
+test -z "$debugfile" ||
+bunzip2 -c $srcdir/$debugfile.bz2 > $debugfile 2>/dev/null || exit 0
+
+LD_LIBRARY_PATH=../libebl:../libelf${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH \
+ ../src/strip -o testfile.temp $debugout $original
+
+cmp $stripped testfile.temp
+
+# Check elflint and the expected result.
+LD_LIBRARY_PATH=../libebl:../libelf${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH \
+ ../src/elflint -q testfile.temp
+
+test -z "$debugfile" || {
+cmp $debugfile testfile.debug.temp
+
+# Check elflint and the expected result.
+LD_LIBRARY_PATH=../libebl:../libelf${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH \
+ ../src/elflint -q -d testfile.debug.temp
+
+rm -f "$debugfile"
+}
+
+rm -f $original $stripped testfile.temp testfile.debug.temp
+
+exit 0
diff --git a/tests/run-strip-test2.sh b/tests/run-strip-test2.sh
new file mode 100644
index 0000000..824361c
--- /dev/null
+++ b/tests/run-strip-test2.sh
@@ -0,0 +1,17 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+
+original=testfile8
+stripped=testfile9
+. $srcdir/run-strip-test.sh
diff --git a/tests/run-strip-test3.sh b/tests/run-strip-test3.sh
new file mode 100644
index 0000000..3e8ac87
--- /dev/null
+++ b/tests/run-strip-test3.sh
@@ -0,0 +1,17 @@
+#! /bin/sh
+# Copyright (C) 1999, 2000, 2002, 2003, 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
+#
+# This program is Open Source software; you can redistribute it and/or
+# modify it under the terms of the Open Software License version 1.0 as
+# published by the Open Source Initiative.
+#
+# You should have received a copy of the Open Software License along
+# with this program; if not, you may obtain a copy of the Open Software
+# License version 1.0 from http://www.opensource.org/licenses/osl.php or
+# by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+# 3001 King Ranch Road, Ukiah, CA 95482.
+
+original=testfile12
+stripped=testfile13
+. $srcdir/run-strip-test.sh
diff --git a/tests/run-strip-test4.sh b/tests/run-strip-test4.sh
new file mode 100644
index 0000000..8e9be22
--- /dev/null
+++ b/tests/run-strip-test4.sh
@@ -0,0 +1,5 @@
+original=testfile11
+stripped=testfile15
+debugfile=testfile15.debug
+
+. $srcdir/run-strip-test.sh
diff --git a/tests/run-strip-test5.sh b/tests/run-strip-test5.sh
new file mode 100644
index 0000000..9fa9ebe
--- /dev/null
+++ b/tests/run-strip-test5.sh
@@ -0,0 +1,5 @@
+original=testfile8
+stripped=testfile16
+debugfile=testfile16.debug
+
+. $srcdir/run-strip-test.sh
diff --git a/tests/run-strip-test6.sh b/tests/run-strip-test6.sh
new file mode 100644
index 0000000..8ee5f02
--- /dev/null
+++ b/tests/run-strip-test6.sh
@@ -0,0 +1,5 @@
+original=testfile12
+stripped=testfile17
+debugfile=testfile17.debug
+
+. $srcdir/run-strip-test.sh
diff --git a/tests/saridx.c b/tests/saridx.c
new file mode 100644
index 0000000..4abc892
--- /dev/null
+++ b/tests/saridx.c
@@ -0,0 +1,253 @@
+/* Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1998.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <error.h>
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+
+static const char *machines[] =
+{
+#define MACHINE(name) [name] = #name
+ MACHINE (EM_NONE),
+ MACHINE (EM_M32),
+ MACHINE (EM_SPARC),
+ MACHINE (EM_386),
+ MACHINE (EM_68K),
+ MACHINE (EM_88K),
+ MACHINE (EM_860),
+ MACHINE (EM_MIPS),
+ MACHINE (EM_MIPS_RS3_LE),
+ MACHINE (EM_PARISC),
+ MACHINE (EM_VPP500),
+ MACHINE (EM_SPARC32PLUS),
+ MACHINE (EM_960),
+ MACHINE (EM_PPC),
+ MACHINE (EM_PPC64),
+ MACHINE (EM_V800),
+ MACHINE (EM_FR20),
+ MACHINE (EM_RH32),
+ MACHINE (EM_RCE),
+ MACHINE (EM_ARM),
+ MACHINE (EM_FAKE_ALPHA),
+ MACHINE (EM_SH),
+ MACHINE (EM_SPARCV9),
+ MACHINE (EM_TRICORE),
+ MACHINE (EM_ARC),
+ MACHINE (EM_H8_300),
+ MACHINE (EM_H8_300H),
+ MACHINE (EM_H8S),
+ MACHINE (EM_H8_500),
+ MACHINE (EM_IA_64),
+ MACHINE (EM_MIPS_X),
+ MACHINE (EM_COLDFIRE),
+ MACHINE (EM_68HC12),
+ MACHINE (EM_MMA),
+ MACHINE (EM_PCP),
+ MACHINE (EM_NCPU),
+ MACHINE (EM_NDR1),
+ MACHINE (EM_STARCORE),
+ MACHINE (EM_ME16),
+ MACHINE (EM_ST100),
+ MACHINE (EM_TINYJ),
+ MACHINE (EM_FX66),
+ MACHINE (EM_ST9PLUS),
+ MACHINE (EM_ST7),
+ MACHINE (EM_68HC16),
+ MACHINE (EM_68HC11),
+ MACHINE (EM_68HC08),
+ MACHINE (EM_68HC05),
+ MACHINE (EM_SVX),
+ MACHINE (EM_ST19),
+ MACHINE (EM_VAX)
+};
+
+
+int
+main (int argc, char *argv[])
+{
+ int fd;
+ Elf *elf;
+ Elf_Cmd cmd;
+ size_t n;
+ int arg = 1;
+ int verbose = 0;
+
+ /* Recognize optional verbosity flag. */
+ if (arg < argc && strcmp (argv[arg], "-v") == 0)
+ {
+ verbose = 1;
+ ++arg;
+ }
+
+ /* Any more arguments available. */
+ if (arg >= argc)
+ error (EXIT_FAILURE, 0, "No input file given");
+
+ /* Open the input file. */
+ fd = open (argv[arg], O_RDONLY);
+ if (fd == -1)
+ {
+ perror ("cannot open input file");
+ exit (1);
+ }
+
+ /* Set the ELF version we are using here. */
+ if (elf_version (EV_CURRENT) == EV_NONE)
+ {
+ puts ("ELF library too old");
+ exit (1);
+ }
+
+ /* Start reading the file. */
+ cmd = ELF_C_READ;
+ elf = elf_begin (fd, cmd, NULL);
+ if (elf == NULL)
+ {
+ printf ("elf_begin: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* If it is no archive punt. */
+ if (elf_kind (elf) != ELF_K_AR)
+ {
+ printf ("%s is not an archive\n", argv[1]);
+ exit (1);
+ }
+
+ if (verbose)
+ {
+ /* The verbose variant. We print a lot of information. */
+ Elf *subelf;
+ char buf[100];
+ time_t t;
+
+ /* Get the elements of the archive one after the other. */
+ while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
+ {
+ /* The the header for this element. */
+ Elf_Arhdr *arhdr = elf_getarhdr (subelf);
+
+ if (arhdr == NULL)
+ {
+ printf ("cannot get arhdr: %s\n", elf_errmsg (-1));
+ break;
+ }
+
+ switch (elf_kind (subelf))
+ {
+ case ELF_K_ELF:
+ fputs ("ELF file:\n", stdout);
+ break;
+
+ case ELF_K_AR:
+ fputs ("archive:\n", stdout);
+ break;
+
+ default:
+ fputs ("unknown file:\n", stdout);
+ break;
+ }
+
+ /* Print general information. */
+ t = arhdr->ar_date;
+ strftime (buf, sizeof buf, "%Y-%m-%dT%H:%M:%S%z", gmtime (&t));
+ printf (" name : \"%s\"\n"
+ " time : %s\n"
+ " uid : %ld\n"
+ " gid : %ld\n"
+ " mode : %o\n"
+ " size : %ld\n"
+ " rawname : \"%s\"\n",
+ arhdr->ar_name,
+ buf,
+ (long int) arhdr->ar_uid,
+ (long int) arhdr->ar_gid,
+ arhdr->ar_mode,
+ (long int) arhdr->ar_size,
+ arhdr->ar_rawname);
+
+ /* For ELF files we can provide some more information. */
+ if (elf_kind (subelf) == ELF_K_ELF)
+ {
+ GElf_Ehdr ehdr;
+
+ /* Get the ELF header. */
+ if (gelf_getehdr (subelf, &ehdr) == NULL)
+ printf (" *** cannot get ELF header: %s\n", elf_errmsg (-1));
+ else
+ {
+ printf (" binary class : %s\n",
+ ehdr.e_ident[EI_CLASS] == ELFCLASS32
+ ? "ELFCLASS32" : "ELFCLASS64");
+ printf (" data encoding: %s\n",
+ ehdr.e_ident[EI_DATA] == ELFDATA2LSB
+ ? "ELFDATA2LSB" : "ELFDATA2MSB");
+ printf (" binary type : %s\n",
+ ehdr.e_type == ET_REL
+ ? "relocatable"
+ : (ehdr.e_type == ET_EXEC
+ ? "executable"
+ : (ehdr.e_type == ET_DYN
+ ? "dynamic"
+ : "core file")));
+ printf (" machine : %s\n",
+ (ehdr.e_machine >= (sizeof (machines)
+ / sizeof (machines[0]))
+ || machines[ehdr.e_machine] == NULL)
+ ? "???"
+ : machines[ehdr.e_machine]);
+ }
+ }
+
+ /* Get next archive element. */
+ cmd = elf_next (subelf);
+ if (elf_end (subelf) != 0)
+ printf ("error while freeing sub-ELF descriptor: %s\n",
+ elf_errmsg (-1));
+ }
+ }
+ else
+ {
+ /* The simple version. Only print a bit of information. */
+ Elf_Arsym *arsym = elf_getarsym (elf, &n);
+
+ if (n == 0)
+ printf ("no symbol table in archive: %s\n", elf_errmsg (-1));
+ else
+ {
+ --n;
+
+ while (n-- > 0)
+ printf ("name = \"%s\", offset = %ld, hash = %lx\n",
+ arsym[n].as_name, (long int) arsym[n].as_off,
+ arsym[n].as_hash);
+ }
+ }
+
+ /* Free the ELF handle. */
+ if (elf_end (elf) != 0)
+ printf ("error while freeing ELF descriptor: %s\n", elf_errmsg (-1));
+
+ /* Close the underlying file. */
+ close (fd);
+
+ return 0;
+}
diff --git a/tests/scnnames.c b/tests/scnnames.c
new file mode 100644
index 0000000..14f428d
--- /dev/null
+++ b/tests/scnnames.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 1998, 1999, 2000, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1998.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+ Elf *elf;
+ int fd;
+ GElf_Ehdr ehdr;
+ size_t strndx;
+ Elf_Scn *scn;
+
+ if (argc < 2)
+ {
+ puts ("missing parameter");
+ exit (1);
+ }
+
+ fd = open (argv[1], O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open \"%s\": %s\n", argv[1], strerror (errno));
+ exit (1);
+ }
+
+ elf_version (EV_CURRENT);
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot open ELF file: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ printf ("\"%s\" is not an ELF file\n", argv[1]);
+ exit (1);
+ }
+
+ if (gelf_getehdr (elf, &ehdr) == NULL)
+ {
+ printf ("cannot get the ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ strndx = ehdr.e_shstrndx;
+
+ scn = NULL;
+ while ((scn = elf_nextscn (elf, scn)) != NULL)
+ {
+ char *name = NULL;
+ GElf_Shdr shdr;
+
+ if (gelf_getshdr (scn, &shdr) != NULL)
+ name = elf_strptr (elf, strndx, (size_t) shdr.sh_name);
+
+ printf ("section: `%s'\n", name);
+ }
+
+ if (elf_end (elf) != 0)
+ {
+ printf ("error while freeing ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/tests/sectiondump.c b/tests/sectiondump.c
new file mode 100644
index 0000000..f19a215
--- /dev/null
+++ b/tests/sectiondump.c
@@ -0,0 +1,178 @@
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1998.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#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>
+
+
+/* Prototypes for local functions. */
+static int handle_section (Elf *elf, Elf_Scn *scn);
+static void print_bytes (Elf_Data *data);
+static void print_symtab (Elf *elf, Elf_Data *data);
+
+
+int
+main (int argc, char *argv[])
+{
+ Elf *elf;
+ int fd;
+ int cnt;
+
+ if (argc <= 1)
+ exit (1);
+
+ /* Open the test file. This is given as the first parameter to the
+ program. */
+ fd = open (argv[1], O_RDONLY);
+ if (fd == -1)
+ error (EXIT_FAILURE, errno, "cannot open input file `%s'", argv[1]);
+
+ /* Set the library versio we expect. */
+ elf_version (EV_CURRENT);
+
+ /* Create the ELF descriptor. */
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ error (EXIT_FAILURE, 0, "cannot create ELF descriptor: %s",
+ elf_errmsg (0));
+
+ /* Now proces all the sections mentioned in the rest of the command line. */
+ for (cnt = 2; cnt < argc; ++cnt)
+ if (handle_section (elf, elf_getscn (elf, atoi (argv[cnt]))) != 0)
+ /* When we encounter an error stop immediately. */
+ error (EXIT_FAILURE, 0, "while processing section %d: %s", cnt,
+ elf_errmsg (0));
+
+ /* Close the descriptor. */
+ if (elf_end (elf) != 0)
+ error (EXIT_FAILURE, 0, "failure while closing ELF descriptor: %s",
+ elf_errmsg (0));
+
+ return 0;
+}
+
+
+static int
+handle_section (Elf *elf, Elf_Scn *scn)
+{
+ GElf_Ehdr *ehdr;
+ GElf_Ehdr ehdr_mem;
+ GElf_Shdr *shdr;
+ GElf_Shdr shdr_mem;
+ Elf_Data *data;
+
+ /* First get the ELF and section header. */
+ ehdr = gelf_getehdr (elf, &ehdr_mem);
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (ehdr == NULL || shdr == NULL)
+ return 1;
+
+ /* Print the information from the ELF section header. */
+ printf ("name = %s\n"
+ "type = %" PRId32 "\n"
+ "flags = %" PRIx64 "\n"
+ "addr = %" PRIx64 "\n"
+ "offset = %" PRIx64 "\n"
+ "size = %" PRId64 "\n"
+ "link = %" PRId32 "\n"
+ "info = %" PRIx32 "\n"
+ "addralign = %" PRIx64 "\n"
+ "entsize = %" PRId64 "\n",
+ elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name),
+ shdr->sh_type,
+ shdr->sh_flags,
+ shdr->sh_addr,
+ shdr->sh_offset,
+ shdr->sh_size,
+ shdr->sh_link,
+ shdr->sh_info,
+ shdr->sh_addralign,
+ shdr->sh_entsize);
+
+ /* Get the section data now. */
+ data = elf_getdata (scn, NULL);
+ if (data == NULL)
+ return 1;
+
+ /* Now proces the different section types accordingly. */
+ switch (shdr->sh_type)
+ {
+ case SHT_SYMTAB:
+ print_symtab (elf, data);
+ break;
+
+ case SHT_PROGBITS:
+ default:
+ print_bytes (data);
+ break;
+ }
+
+ /* Separate form the next section. */
+ puts ("");
+
+ /* All done correctly. */
+ return 0;
+}
+
+
+static void
+print_bytes (Elf_Data *data)
+{
+ size_t size = data->d_size;
+ off_t offset = data->d_off;
+ unsigned char *buf = (unsigned char *) data->d_buf;
+ size_t cnt;
+
+ for (cnt = 0; cnt < size; cnt += 16)
+ {
+ size_t inner;
+
+ printf ("%*Zx: ", sizeof (size_t) == 4 ? 8 : 16, (size_t) offset + cnt);
+
+ for (inner = 0; inner < 16 && cnt + inner < size; ++inner)
+ printf (" %02hhx", buf[cnt + inner]);
+
+ puts ("");
+ }
+}
+
+
+static void
+print_symtab (Elf *elf, Elf_Data *data)
+{
+ int class = gelf_getclass (elf);
+ size_t nsym = data->d_size / (class == ELFCLASS32
+ ? sizeof (Elf32_Sym) : sizeof (Elf64_Sym));
+ size_t cnt;
+
+ for (cnt = 0; cnt < nsym; ++cnt)
+ {
+ GElf_Sym sym_mem;
+ GElf_Sym *sym = gelf_getsym (data, cnt, &sym_mem);
+
+ printf ("%5Zu: %*" PRIx64 " %6" PRIx64 " %4d\n",
+ cnt,
+ class == ELFCLASS32 ? 8 : 16,
+ sym->st_value,
+ sym->st_size,
+ GELF_ST_TYPE (sym->st_info));
+ }
+}
diff --git a/tests/show-abbrev.c b/tests/show-abbrev.c
new file mode 100644
index 0000000..fba7375
--- /dev/null
+++ b/tests/show-abbrev.c
@@ -0,0 +1,127 @@
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1998.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libdw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
+ close (fd);
+ continue;
+ }
+
+ Dwarf_Off cuoff = 0;
+ Dwarf_Off old_cuoff = 0;
+ size_t hsize;
+ while (dwarf_nextcu (dbg, cuoff, &cuoff, &hsize, NULL, NULL, NULL) == 0)
+ {
+ /* Get the DIE for the CU. */
+ Dwarf_Die die;
+ if (dwarf_offdie (dbg, old_cuoff + hsize, &die) == NULL)
+ /* Something went wrong. */
+ break;
+
+ Dwarf_Off offset = 0;
+
+ while (1)
+ {
+ size_t length;
+ Dwarf_Abbrev *abbrev = dwarf_getabbrev (&die, offset, &length);
+ if (abbrev == NULL || abbrev == DWARF_END_ABBREV)
+ /* End of the list. */
+ break;
+
+ unsigned tag = dwarf_getabbrevtag (abbrev);
+ if (tag == 0)
+ {
+ printf ("dwarf_getabbrevtag at offset %llu returned error: %s\n",
+ (unsigned long long int) offset,
+ dwarf_errmsg (-1));
+ break;
+ }
+
+ unsigned code = dwarf_getabbrevcode (abbrev);
+ if (code == 0)
+ {
+ printf ("dwarf_getabbrevcode at offset %llu returned error: %s\n",
+ (unsigned long long int) offset,
+ dwarf_errmsg (-1));
+ break;
+ }
+
+ int children = dwarf_abbrevhaschildren (abbrev);
+ if (children < 0)
+ {
+ printf ("dwarf_abbrevhaschildren at offset %llu returned error: %s\n",
+ (unsigned long long int) offset,
+ dwarf_errmsg (-1));
+ break;
+ }
+
+ printf ("abbrev[%llu]: code = %u, tag = %u, children = %d\n",
+ (unsigned long long int) offset, code, tag, children);
+
+ size_t attrcnt;
+ if (dwarf_getattrcnt (abbrev, &attrcnt) != 0)
+ {
+ printf ("dwarf_getattrcnt at offset %llu returned error: %s\n",
+ (unsigned long long int) offset,
+ dwarf_errmsg (-1));
+ break;
+ }
+
+ unsigned int attr_num;
+ unsigned int attr_form;
+ Dwarf_Off aboffset;
+ size_t j;
+ for (j = 0; j < attrcnt; ++j)
+ if (dwarf_getabbrevattr (abbrev, j, &attr_num, &attr_form,
+ &aboffset))
+ printf ("dwarf_getabbrevattr for abbrev[%llu] and index %zu failed\n",
+ (unsigned long long int) offset, j);
+ else
+ printf ("abbrev[%llu]: attr[%zu]: code = %u, form = %u, offset = %" PRIu64 "\n",
+ (unsigned long long int) offset, j, attr_num,
+ attr_form, (uint64_t) aboffset);
+
+ offset += length;
+ }
+
+ old_cuoff = cuoff;
+ }
+
+ if (dwarf_end (dbg) != 0)
+ printf ("dwarf_end failed for %s: %s\n", argv[cnt],
+ dwarf_errmsg (-1));
+
+ close (fd);
+ }
+
+ return 0;
+}
diff --git a/tests/show-ciefde.c b/tests/show-ciefde.c
new file mode 100644
index 0000000..58eae34
--- /dev/null
+++ b/tests/show-ciefde.c
@@ -0,0 +1,218 @@
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1998.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <fcntl.h>
+#include <libelf.h>
+#include <libdwarf.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main (int argc, char *argv[])
+{
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+ Dwarf_Debug dbg;
+ Dwarf_Signed cie_cnt;
+ Dwarf_Cie *cie_data;
+ Dwarf_Signed fde_cnt;
+ Dwarf_Fde *fde_data;
+ Dwarf_Error err;
+
+ if (dwarf_init (fd, DW_DLC_READ, NULL, NULL, &dbg, &err) != DW_DLV_OK)
+ {
+ printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (err));
+ continue;
+ }
+ else if (dwarf_get_fde_list_eh (dbg, &cie_data, &cie_cnt, &fde_data,
+ &fde_cnt, &err) != DW_DLV_OK)
+ printf ("cannot get CIEs and FDEs from %s: %s\n", argv[cnt],
+ dwarf_errmsg (err));
+ else
+ {
+ Dwarf_Addr low_pc;
+ Dwarf_Addr high_pc;
+ Dwarf_Unsigned func_length;
+ Dwarf_Ptr fde_bytes;
+ Dwarf_Unsigned fde_byte_length;
+ Dwarf_Off cie_offset;
+ Dwarf_Signed cie_index;
+ Dwarf_Off fde_offset;
+ Dwarf_Fde fde;
+ int i;
+
+ printf ("%s has %lld CIEs and %lld FDEs\n",
+ basename (argv[cnt]),
+ (long long int) cie_cnt, (long long int) fde_cnt);
+
+ for (i = 0; i < cie_cnt; ++i)
+ {
+ Dwarf_Unsigned bytes_in_cie;
+ Dwarf_Small version;
+ char *augmenter;
+ Dwarf_Unsigned code_alignment_factor;
+ Dwarf_Signed data_alignment_factor;
+ Dwarf_Half return_address_register;
+ Dwarf_Ptr initial_instructions;
+ Dwarf_Unsigned initial_instructions_length;
+
+ if (dwarf_get_cie_info (cie_data[i], &bytes_in_cie, &version,
+ &augmenter, &code_alignment_factor,
+ &data_alignment_factor,
+ &return_address_register,
+ &initial_instructions,
+ &initial_instructions_length, &err)
+ != DW_DLV_OK)
+ printf ("cannot get info for CIE %d: %s\n", i,
+ dwarf_errmsg (err));
+ else
+ {
+ size_t j;
+
+ printf ("CIE[%d]: bytes_in_cie = %llu, version = %hhd, augmenter = \"%s\"\n",
+ i, (unsigned long long int) bytes_in_cie, version,
+ augmenter);
+ printf ("CIE[%d]: code_alignment_factor = %llx\n"
+ "CIE[%d]: data_alignment_factor = %llx\n"
+ "CIE[%d]: return_address_register = %hu\n"
+ "CIE[%d]: bytes =",
+ i, (unsigned long long int) code_alignment_factor,
+ i, (unsigned long long int) data_alignment_factor,
+ i, return_address_register, i);
+
+ for (j = 0; j < initial_instructions_length; ++j)
+ printf (" %02hhx",
+ ((unsigned char *) initial_instructions)[j]);
+
+ putchar ('\n');
+ }
+ }
+
+ for (i = 0; i < fde_cnt; ++i)
+ {
+ Dwarf_Cie cie;
+
+ if (dwarf_get_fde_range (fde_data[i], &low_pc, &func_length,
+ &fde_bytes, &fde_byte_length,
+ &cie_offset, &cie_index, &fde_offset,
+ &err) != DW_DLV_OK)
+ printf ("cannot get range of FDE %d: %s\n", i,
+ dwarf_errmsg (err));
+ else
+ {
+ size_t j;
+ Dwarf_Ptr instrs;
+ Dwarf_Unsigned len;
+
+ printf ("FDE[%d]: low_pc = %#llx, length = %llu\n", i,
+ (unsigned long long int) low_pc,
+ (unsigned long long int) func_length);
+ printf ("FDE[%d]: bytes =", i);
+
+ for (j = 0; j < fde_byte_length; ++j)
+ printf (" %02hhx", ((unsigned char *) fde_bytes)[j]);
+
+ printf ("\nFDE[%d]: cie_offset = %lld, cie_index = %lld, fde_offset = %lld\n",
+ i, (long long int) cie_offset,
+ (long long int) cie_index,
+ (long long int) fde_offset);
+
+ if (dwarf_get_fde_instr_bytes (fde_data[i], &instrs, &len,
+ &err) != DW_DLV_OK)
+ printf ("cannot get instructions of FDE %d: %s\n", i,
+ dwarf_errmsg (err));
+ else
+ {
+ printf ("FDE[%d]: instructions =", i);
+
+ for (j = 0; j < len; ++j)
+ printf (" %02hhx", ((unsigned char *) instrs)[j]);
+
+ putchar ('\n');
+ }
+
+ /* Consistency check. */
+ if (dwarf_get_cie_of_fde (fde_data[i], &cie, &err)
+ != DW_DLV_OK)
+ printf ("cannot get CIE of FDE %d: %s\n", i,
+ dwarf_errmsg (err));
+ else if (cie_data[cie_index] != cie)
+ puts ("cie_index for FDE[%d] does not match dwarf_get_cie_of_fde result");
+ }
+
+ if (dwarf_get_fde_n (fde_data, i, &fde, &err) != DW_DLV_OK)
+ printf ("dwarf_get_fde_n for FDE[%d] failed\n", i);
+ else if (fde != fde_data[i])
+ printf ("dwarf_get_fde_n for FDE[%d] didn't return the right value\n", i);
+ }
+
+ if (dwarf_get_fde_n (fde_data, fde_cnt, &fde, &err)
+ != DW_DLV_NO_ENTRY)
+ puts ("dwarf_get_fde_n for invalid index doesn't return DW_DLV_NO_ENTRY");
+
+ {
+ const unsigned int addrs[] =
+ {
+ 0x8048400, 0x804842c, 0x8048454, 0x8048455, 0x80493fc
+ };
+ const int naddrs = sizeof (addrs) / sizeof (addrs[0]);
+
+ for (i = 0; i < naddrs; ++i)
+ if (dwarf_get_fde_at_pc (fde_data, addrs[i], &fde, &low_pc,
+ &high_pc, &err) != DW_DLV_OK)
+ printf ("no FDE at %x\n", addrs[i]);
+ else
+ {
+ Dwarf_Addr other_low_pc;
+
+ if (dwarf_get_fde_range (fde, &other_low_pc, &func_length,
+ &fde_bytes, &fde_byte_length,
+ &cie_offset, &cie_index,
+ &fde_offset, &err) != DW_DLV_OK)
+ printf ("cannot get range of FDE returned by dwarf_get_fde_at_pc for %u: %s\n",
+ addrs[i], dwarf_errmsg (err));
+ else
+ {
+ printf ("FDE[@%x]: cie_offset = %lld, cie_index = %lld, fde_offset = %lld\n",
+ addrs[i],
+ (long long int) cie_offset,
+ (long long int) cie_index,
+ (long long int) fde_offset);
+
+ if (low_pc != other_low_pc)
+ printf ("low_pc returned by dwarf_get_fde_at_pc for %x and dwarf_get_fde_range differs",
+ addrs[i]);
+
+ if (high_pc != low_pc + func_length - 1)
+ printf ("high_pc returned by dwarf_get_fde_at_pc for %x and dwarf_get_fde_range differs",
+ addrs[i]);
+ }
+ }
+ }
+ }
+
+ if (dwarf_finish (dbg, &err) != DW_DLV_OK)
+ printf ("dwarf_finish failed for %s: %s\n", argv[cnt],
+ dwarf_errmsg (err));
+
+ close (fd);
+ }
+
+ return 0;
+}
diff --git a/tests/show-die-info.c b/tests/show-die-info.c
new file mode 100644
index 0000000..d4f992f
--- /dev/null
+++ b/tests/show-die-info.c
@@ -0,0 +1,475 @@
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1998.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <dwarf.h>
+#include <inttypes.h>
+#include <libelf.h>
+#include <libdw.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static const char *tagnames[] =
+{
+ [DW_TAG_array_type] = "DW_TAG_array_type",
+ [DW_TAG_class_type] = "DW_TAG_class_type",
+ [DW_TAG_entry_point] = "DW_TAG_entry_point",
+ [DW_TAG_enumeration_type] = "DW_TAG_enumeration_type",
+ [DW_TAG_formal_parameter] = "DW_TAG_formal_parameter",
+ [DW_TAG_imported_declaration] = "DW_TAG_imported_declaration",
+ [DW_TAG_label] = "DW_TAG_label",
+ [DW_TAG_lexical_block] = "DW_TAG_lexical_block",
+ [DW_TAG_member] = "DW_TAG_member",
+ [DW_TAG_pointer_type] = "DW_TAG_pointer_type",
+ [DW_TAG_reference_type] = "DW_TAG_reference_type",
+ [DW_TAG_compile_unit] = "DW_TAG_compile_unit",
+ [DW_TAG_string_type] = "DW_TAG_string_type",
+ [DW_TAG_structure_type] = "DW_TAG_structure_type",
+ [DW_TAG_subroutine_type] = "DW_TAG_subroutine_type",
+ [DW_TAG_typedef] = "DW_TAG_typedef",
+ [DW_TAG_union_type] = "DW_TAG_union_type",
+ [DW_TAG_unspecified_parameters] = "DW_TAG_unspecified_parameters",
+ [DW_TAG_variant] = "DW_TAG_variant",
+ [DW_TAG_common_block] = "DW_TAG_common_block",
+ [DW_TAG_common_inclusion] = "DW_TAG_common_inclusion",
+ [DW_TAG_inheritance] = "DW_TAG_inheritance",
+ [DW_TAG_inlined_subroutine] = "DW_TAG_inlined_subroutine",
+ [DW_TAG_module] = "DW_TAG_module",
+ [DW_TAG_ptr_to_member_type] = "DW_TAG_ptr_to_member_type",
+ [DW_TAG_set_type] = "DW_TAG_set_type",
+ [DW_TAG_subrange_type] = "DW_TAG_subrange_type",
+ [DW_TAG_with_stmt] = "DW_TAG_with_stmt",
+ [DW_TAG_access_declaration] = "DW_TAG_access_declaration",
+ [DW_TAG_base_type] = "DW_TAG_base_type",
+ [DW_TAG_catch_block] = "DW_TAG_catch_block",
+ [DW_TAG_const_type] = "DW_TAG_const_type",
+ [DW_TAG_constant] = "DW_TAG_constant",
+ [DW_TAG_enumerator] = "DW_TAG_enumerator",
+ [DW_TAG_file_type] = "DW_TAG_file_type",
+ [DW_TAG_friend] = "DW_TAG_friend",
+ [DW_TAG_namelist] = "DW_TAG_namelist",
+ [DW_TAG_namelist_item] = "DW_TAG_namelist_item",
+ [DW_TAG_packed_type] = "DW_TAG_packed_type",
+ [DW_TAG_subprogram] = "DW_TAG_subprogram",
+ [DW_TAG_template_type_param] = "DW_TAG_template_type_param",
+ [DW_TAG_template_value_param] = "DW_TAG_template_value_param",
+ [DW_TAG_thrown_type] = "DW_TAG_thrown_type",
+ [DW_TAG_try_block] = "DW_TAG_try_block",
+ [DW_TAG_variant_part] = "DW_TAG_variant_part",
+ [DW_TAG_variable] = "DW_TAG_variable",
+ [DW_TAG_volatile_type] = "DW_TAG_volatile_type"
+};
+#define ntagnames (sizeof (tagnames) / sizeof (tagnames[0]))
+
+
+const struct
+{
+ int code;
+ const char *name;
+} attrs[] =
+{
+ { DW_AT_sibling, "sibling" },
+ { DW_AT_location, "location" },
+ { DW_AT_name, "name" },
+ { DW_AT_ordering, "ordering" },
+ { DW_AT_subscr_data, "subscr_data" },
+ { DW_AT_byte_size, "byte_size" },
+ { DW_AT_bit_offset, "bit_offset" },
+ { DW_AT_bit_size, "bit_size" },
+ { DW_AT_element_list, "element_list" },
+ { DW_AT_stmt_list, "stmt_list" },
+ { DW_AT_low_pc, "low_pc" },
+ { DW_AT_high_pc, "high_pc" },
+ { DW_AT_language, "language" },
+ { DW_AT_member, "member" },
+ { DW_AT_discr, "discr" },
+ { DW_AT_discr_value, "discr_value" },
+ { DW_AT_visibility, "visibility" },
+ { DW_AT_import, "import" },
+ { DW_AT_string_length, "string_length" },
+ { DW_AT_common_reference, "common_reference" },
+ { DW_AT_comp_dir, "comp_dir" },
+ { DW_AT_const_value, "const_value" },
+ { DW_AT_containing_type, "containing_type" },
+ { DW_AT_default_value, "default_value" },
+ { DW_AT_inline, "inline" },
+ { DW_AT_is_optional, "is_optional" },
+ { DW_AT_lower_bound, "lower_bound" },
+ { DW_AT_producer, "producer" },
+ { DW_AT_prototyped, "prototyped" },
+ { DW_AT_return_addr, "return_addr" },
+ { DW_AT_start_scope, "start_scope" },
+ { DW_AT_stride_size, "stride_size" },
+ { DW_AT_upper_bound, "upper_bound" },
+ { DW_AT_abstract_origin, "abstract_origin" },
+ { DW_AT_accessibility, "accessibility" },
+ { DW_AT_address_class, "address_class" },
+ { DW_AT_artificial, "artificial" },
+ { DW_AT_base_types, "base_types" },
+ { DW_AT_calling_convention, "calling_convention" },
+ { DW_AT_count, "count" },
+ { DW_AT_data_member_location, "data_member_location" },
+ { DW_AT_decl_column, "decl_column" },
+ { DW_AT_decl_file, "decl_file" },
+ { DW_AT_decl_line, "decl_line" },
+ { DW_AT_declaration, "declaration" },
+ { DW_AT_discr_list, "discr_list" },
+ { DW_AT_encoding, "encoding" },
+ { DW_AT_external, "external" },
+ { DW_AT_frame_base, "frame_base" },
+ { DW_AT_friend, "friend" },
+ { DW_AT_identifier_case, "identifier_case" },
+ { DW_AT_macro_info, "macro_info" },
+ { DW_AT_namelist_items, "namelist_items" },
+ { DW_AT_priority, "priority" },
+ { DW_AT_segment, "segment" },
+ { DW_AT_specification, "specification" },
+ { DW_AT_static_link, "static_link" },
+ { DW_AT_type, "type" },
+ { DW_AT_use_location, "use_location" },
+ { DW_AT_variable_parameter, "variable_parameter" },
+ { DW_AT_virtuality, "virtuality" },
+ { DW_AT_vtable_elem_location, "vtable_elem_location" },
+ { DW_AT_MIPS_fde, "MIPS_fde" },
+ { DW_AT_MIPS_loop_begin, "MIPS_loop_begin" },
+ { DW_AT_MIPS_tail_loop_begin, "MIPS_tail_loop_begin" },
+ { DW_AT_MIPS_epilog_begin, "MIPS_epilog_begin" },
+ { DW_AT_MIPS_loop_unroll_factor, "MIPS_loop_unroll_factor" },
+ { DW_AT_MIPS_software_pipeline_depth, "MIPS_software_pipeline_depth" },
+ { DW_AT_MIPS_linkage_name, "MIPS_linkage_name" },
+ { DW_AT_MIPS_stride, "MIPS_stride" },
+ { DW_AT_MIPS_abstract_name, "MIPS_abstract_name" },
+ { DW_AT_MIPS_clone_origin, "MIPS_clone_origin" },
+ { DW_AT_MIPS_has_inlines, "MIPS_has_inlines" },
+ { DW_AT_MIPS_stride_byte, "MIPS_stride_byte" },
+ { DW_AT_MIPS_stride_elem, "MIPS_stride_elem" },
+ { DW_AT_MIPS_ptr_dopetype, "MIPS_ptr_dopetype" },
+ { DW_AT_MIPS_allocatable_dopetype, "MIPS_allocatable_dopetype" },
+ { DW_AT_MIPS_assumed_shape_dopetype, "MIPS_assumed_shape_dopetype" },
+ { DW_AT_MIPS_assumed_size, "MIPS_assumed_size" },
+ { DW_AT_sf_names, "sf_names" },
+ { DW_AT_src_info, "src_info" },
+ { DW_AT_mac_info, "mac_info" },
+ { DW_AT_src_coords, "src_coords" },
+ { DW_AT_body_begin, "body_begin" },
+ { DW_AT_body_end, "body_end" }
+};
+#define nattrs (sizeof (attrs) / sizeof (attrs[0]))
+
+
+void
+handle (Dwarf *dbg, Dwarf_Die *die, int n)
+{
+ Dwarf_Die child;
+ unsigned int tag;
+ const char *str;
+ char buf[30];
+ const char *name;
+ Dwarf_Off off;
+ Dwarf_Off cuoff;
+ size_t cnt;
+ Dwarf_Addr addr;
+ int i;
+
+ tag = dwarf_tag (die);
+ if (tag != DW_TAG_invalid)
+ {
+ if (tag < ntagnames)
+ str = tagnames[tag];
+ else
+ {
+ snprintf (buf, sizeof buf, "%#x", tag);
+ str = buf;
+ }
+ }
+ else
+ str = "* NO TAG *";
+
+ name = dwarf_diename (die);
+ if (name == 0)
+ name = "* NO NAME *";
+
+ off = dwarf_dieoffset (die);
+ cuoff = dwarf_cuoffset (die);
+
+ printf ("%*s%s\n", n * 5, "", str);
+ printf ("%*s Name : %s\n", n * 5, "", name);
+ printf ("%*s Offset : %lld\n", n * 5, "", (long long int) off);
+ printf ("%*s CU offset : %lld\n", n * 5, "", (long long int) cuoff);
+
+ printf ("%*s Attrs :", n * 5, "");
+ for (cnt = 0; cnt < nattrs; ++cnt)
+ if (dwarf_hasattr (die, attrs[cnt].code))
+ printf (" %s", attrs[cnt].name);
+ puts ("");
+
+ if (dwarf_hasattr (die, DW_AT_low_pc) && dwarf_lowpc (die, &addr) == 0)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Addr addr2;
+ printf ("%*s low PC : %#llx\n",
+ n * 5, "", (unsigned long long int) addr);
+
+ if (dwarf_attr (die, DW_AT_low_pc, &attr) == NULL
+ || dwarf_formaddr (&attr, &addr2) != 0
+ || addr != addr2)
+ puts ("************* DW_AT_low_pc verify failed ************");
+ else if (! dwarf_hasform (&attr, DW_FORM_addr))
+ puts ("************* DW_AT_low_pc form failed ************");
+ else if (dwarf_whatform (&attr) != DW_FORM_addr)
+ puts ("************* DW_AT_low_pc form (2) failed ************");
+ else if (dwarf_whatattr (&attr) != DW_AT_low_pc)
+ puts ("************* DW_AT_low_pc attr failed ************");
+ }
+ if (dwarf_hasattr (die, DW_AT_high_pc) && dwarf_highpc (die, &addr) == 0)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Addr addr2;
+ printf ("%*s high PC : %#llx\n",
+ n * 5, "", (unsigned long long int) addr);
+ if (dwarf_attr (die, DW_AT_high_pc, &attr) == NULL
+ || dwarf_formaddr (&attr, &addr2) != 0
+ || addr != addr2)
+ puts ("************* DW_AT_high_pc verify failed ************");
+ else if (! dwarf_hasform (&attr, DW_FORM_addr))
+ puts ("************* DW_AT_high_pc form failed ************");
+ else if (dwarf_whatform (&attr) != DW_FORM_addr)
+ puts ("************* DW_AT_high_pc form (2) failed ************");
+ else if (dwarf_whatattr (&attr) != DW_AT_high_pc)
+ puts ("************* DW_AT_high_pc attr failed ************");
+ }
+
+ if (dwarf_hasattr (die, DW_AT_byte_size) && (i = dwarf_bytesize (die)) != -1)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Word u2;
+ unsigned int u;
+ printf ("%*s byte size : %d\n", n * 5, "", i);
+ if (dwarf_attr (die, DW_AT_byte_size, &attr) == NULL
+ || dwarf_formudata (&attr, &u2) != 0
+ || i != (int) u2)
+ puts ("************* DW_AT_byte_size verify failed ************");
+ else if (! dwarf_hasform (&attr, DW_FORM_data1)
+ && ! dwarf_hasform (&attr, DW_FORM_data2)
+ && ! dwarf_hasform (&attr, DW_FORM_data4)
+ && ! dwarf_hasform (&attr, DW_FORM_data8)
+ && ! dwarf_hasform (&attr, DW_FORM_sdata)
+ && ! dwarf_hasform (&attr, DW_FORM_udata))
+ puts ("************* DW_AT_byte_size form failed ************");
+ else if ((u = dwarf_whatform (&attr)) == 0
+ || (u != DW_FORM_data1
+ && u != DW_FORM_data2
+ && u != DW_FORM_data4
+ && u != DW_FORM_data8
+ && u != DW_FORM_sdata
+ && u != DW_FORM_udata))
+ puts ("************* DW_AT_byte_size form (2) failed ************");
+ else if (dwarf_whatattr (&attr) != DW_AT_byte_size)
+ puts ("************* DW_AT_byte_size attr failed ************");
+ }
+ if (dwarf_hasattr (die, DW_AT_bit_size) && (i = dwarf_bitsize (die)) != -1)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Word u2;
+ unsigned int u;
+ printf ("%*s bit size : %d\n", n * 5, "", i);
+ if (dwarf_attr (die, DW_AT_bit_size, &attr) == NULL
+ || dwarf_formudata (&attr, &u2) != 0
+ || i != (int) u2)
+ puts ("************* DW_AT_bit_size test failed ************");
+ else if (! dwarf_hasform (&attr, DW_FORM_data1)
+ && ! dwarf_hasform (&attr, DW_FORM_data2)
+ && ! dwarf_hasform (&attr, DW_FORM_data4)
+ && ! dwarf_hasform (&attr, DW_FORM_data8)
+ && ! dwarf_hasform (&attr, DW_FORM_sdata)
+ && ! dwarf_hasform (&attr, DW_FORM_udata))
+ puts ("************* DW_AT_bit_size form failed ************");
+ else if ((u = dwarf_whatform (&attr)) == 0
+ || (u != DW_FORM_data1
+ && u != DW_FORM_data2
+ && u != DW_FORM_data4
+ && u != DW_FORM_data8
+ && u != DW_FORM_sdata
+ && u != DW_FORM_udata))
+ puts ("************* DW_AT_bit_size form (2) failed ************");
+ else if (dwarf_whatattr (&attr) != DW_AT_bit_size)
+ puts ("************* DW_AT_bit_size attr failed ************");
+ }
+ if (dwarf_hasattr (die, DW_AT_bit_offset)
+ && (i = dwarf_bitoffset (die)) != -1)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Word u2;
+ unsigned int u;
+ printf ("%*s bit offset: %d\n", n * 5, "", i);
+ if (dwarf_attr (die, DW_AT_bit_offset, &attr) == NULL
+ || dwarf_formudata (&attr, &u2) != 0
+ || i != (int) u2)
+ puts ("************* DW_AT_bit_offset test failed ************");
+ else if (! dwarf_hasform (&attr, DW_FORM_data1)
+ && ! dwarf_hasform (&attr, DW_FORM_data2)
+ && ! dwarf_hasform (&attr, DW_FORM_data4)
+ && ! dwarf_hasform (&attr, DW_FORM_data8)
+ && ! dwarf_hasform (&attr, DW_FORM_sdata)
+ && ! dwarf_hasform (&attr, DW_FORM_udata))
+ puts ("************* DW_AT_bit_offset form failed ************");
+ else if ((u = dwarf_whatform (&attr)) == 0
+ || (u != DW_FORM_data1
+ && u != DW_FORM_data2
+ && u != DW_FORM_data4
+ && u != DW_FORM_data8
+ && u != DW_FORM_sdata
+ && u != DW_FORM_udata))
+ puts ("************* DW_AT_bit_offset form (2) failed ************");
+ else if (dwarf_whatattr (&attr) != DW_AT_bit_offset)
+ puts ("************* DW_AT_bit_offset attr failed ************");
+ }
+
+ if (dwarf_hasattr (die, DW_AT_language) && (i = dwarf_srclang (die)) != -1)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Word u2;
+ unsigned int u;
+ printf ("%*s language : %d\n", n * 5, "", i);
+ if (dwarf_attr (die, DW_AT_language, &attr) == NULL
+ || dwarf_formudata (&attr, &u2) != 0
+ || i != (int) u2)
+ puts ("************* DW_AT_language test failed ************");
+ else if (! dwarf_hasform (&attr, DW_FORM_data1)
+ && ! dwarf_hasform (&attr, DW_FORM_data2)
+ && ! dwarf_hasform (&attr, DW_FORM_data4)
+ && ! dwarf_hasform (&attr, DW_FORM_data8)
+ && ! dwarf_hasform (&attr, DW_FORM_sdata)
+ && ! dwarf_hasform (&attr, DW_FORM_udata))
+ puts ("************* DW_AT_language form failed ************");
+ else if ((u = dwarf_whatform (&attr)) == 0
+ || (u != DW_FORM_data1
+ && u != DW_FORM_data2
+ && u != DW_FORM_data4
+ && u != DW_FORM_data8
+ && u != DW_FORM_sdata
+ && u != DW_FORM_udata))
+ puts ("************* DW_AT_language form (2) failed ************");
+ else if (dwarf_whatattr (&attr) != DW_AT_language)
+ puts ("************* DW_AT_language attr failed ************");
+ }
+
+ if (dwarf_hasattr (die, DW_AT_ordering)
+ && (i = dwarf_arrayorder (die)) != -1)
+ {
+ Dwarf_Attribute attr;
+ Dwarf_Word u2;
+ unsigned int u;
+ printf ("%*s ordering : %d\n", n * 5, "", i);
+ if (dwarf_attr (die, DW_AT_ordering, &attr) == NULL
+ || dwarf_formudata (&attr, &u2) != 0
+ || i != (int) u2)
+ puts ("************* DW_AT_ordering test failed ************");
+ else if (! dwarf_hasform (&attr, DW_FORM_data1)
+ && ! dwarf_hasform (&attr, DW_FORM_data2)
+ && ! dwarf_hasform (&attr, DW_FORM_data4)
+ && ! dwarf_hasform (&attr, DW_FORM_data8)
+ && ! dwarf_hasform (&attr, DW_FORM_sdata)
+ && ! dwarf_hasform (&attr, DW_FORM_udata))
+ puts ("************* DW_AT_ordering failed ************");
+ else if ((u = dwarf_whatform (&attr)) == 0
+ || (u != DW_FORM_data1
+ && u != DW_FORM_data2
+ && u != DW_FORM_data4
+ && u != DW_FORM_data8
+ && u != DW_FORM_sdata
+ && u != DW_FORM_udata))
+ puts ("************* DW_AT_ordering form (2) failed ************");
+ else if (dwarf_whatattr (&attr) != DW_AT_ordering)
+ puts ("************* DW_AT_ordering attr failed ************");
+ }
+
+ if (dwarf_hasattr (die, DW_AT_comp_dir))
+ {
+ Dwarf_Attribute attr;
+ if (dwarf_attr (die, DW_AT_comp_dir, &attr) == NULL
+ || (name = dwarf_formstring (&attr)) == NULL)
+ puts ("************* DW_AT_comp_dir attr failed ************");
+ else
+ printf ("%*s directory : %s\n", n * 5, "", name);
+ }
+
+ if (dwarf_hasattr (die, DW_AT_producer))
+ {
+ Dwarf_Attribute attr;
+ if (dwarf_attr (die, DW_AT_producer, &attr) == NULL
+ || (name = dwarf_formstring (&attr)) == NULL)
+ puts ("************* DW_AT_comp_dir attr failed ************");
+ else
+ printf ("%*s producer : %s\n", n * 5, "", name);
+ }
+
+ if (dwarf_haschildren (die) != 0 && dwarf_child (die, &child) == 0)
+ handle (dbg, &child, n + 1);
+ if (dwarf_siblingof (die, die) == 0)
+ handle (dbg, die, n);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+ Dwarf *dbg;
+
+ printf ("file: %s\n", basename (argv[cnt]));
+
+ dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable\n", argv[cnt]);
+ close (fd);
+ continue;
+ }
+
+ Dwarf_Off off = 0;
+ Dwarf_Off old_off = 0;
+ size_t hsize;
+ Dwarf_Off abbrev;
+ uint8_t addresssize;
+ uint8_t offsetsize;
+ while (dwarf_nextcu (dbg, off, &off, &hsize, &abbrev, &addresssize,
+ &offsetsize) == 0)
+ {
+ printf ("New CU: off = %llu, hsize = %zu, ab = %llu, as = %" PRIu8
+ ", os = %" PRIu8 "\n",
+ (unsigned long long int) old_off, hsize,
+ (unsigned long long int) abbrev, addresssize,
+ offsetsize);
+
+ Dwarf_Die die;
+ if (dwarf_offdie (dbg, old_off + hsize, &die) != NULL)
+ handle (dbg, &die, 1);
+
+ old_off = off;
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+ }
+
+ return 0;
+}
diff --git a/tests/showptable.c b/tests/showptable.c
new file mode 100644
index 0000000..21247c8
--- /dev/null
+++ b/tests/showptable.c
@@ -0,0 +1,135 @@
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 1998.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <config.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+ Elf *elf;
+ int fd;
+ GElf_Ehdr ehdr;
+ int cnt;
+
+ if (argc < 2)
+ {
+ puts ("missing parameter");
+ exit (1);
+ }
+
+ fd = open (argv[1], O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open \"%s\": %s\n", argv[1], strerror (errno));
+ exit (1);
+ }
+
+ elf_version (EV_CURRENT);
+
+ elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot open ELF file: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ if (elf_kind (elf) != ELF_K_ELF)
+ {
+ printf ("\"%s\" is not an ELF file\n", argv[1]);
+ exit (1);
+ }
+
+ if (gelf_getehdr (elf, &ehdr) == NULL)
+ {
+ printf ("cannot get the ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ printf ("idx type %*s %*s %*s %*s %*s align flags\n",
+ gelf_getclass (elf) == ELFCLASS32 ? 9 : 17, "offset",
+ gelf_getclass (elf) == ELFCLASS32 ? 10 : 18, "vaddr",
+ gelf_getclass (elf) == ELFCLASS32 ? 10 : 18, "paddr",
+ gelf_getclass (elf) == ELFCLASS32 ? 9 : 12, "filesz",
+ gelf_getclass (elf) == ELFCLASS32 ? 9 : 12, "memsz");
+
+ for (cnt = 0; cnt < ehdr.e_phnum; ++cnt)
+ {
+ static const char *typenames[] =
+ {
+ [PT_NULL] = "NULL",
+ [PT_LOAD] = "LOAD",
+ [PT_DYNAMIC] = "DYNAMIC",
+ [PT_INTERP] = "INTERP",
+ [PT_NOTE] = "NOTE",
+ [PT_SHLIB] = "SHLIB",
+ [PT_PHDR] = "PHDR"
+ };
+ GElf_Phdr mem;
+ GElf_Phdr *phdr = gelf_getphdr (elf, cnt, &mem);
+ char buf[19];
+ const char *p_type = typenames[phdr->p_type];
+
+ /* If we don't know the name of the type we use the number value. */
+ if (phdr->p_type >= PT_NUM)
+ {
+ snprintf (buf, sizeof (buf), "%x", phdr->p_type);
+ p_type = buf;
+ }
+
+ printf ("%3d %-7s %#0*llx %#0*llx %#0*llx %#0*llx %#0*llx %#6llx ",
+ cnt, p_type,
+ gelf_getclass (elf) == ELFCLASS32 ? 9 : 17,
+ (unsigned long long int) phdr->p_offset,
+ gelf_getclass (elf) == ELFCLASS32 ? 10 : 18,
+ (unsigned long long int) phdr->p_vaddr,
+ gelf_getclass (elf) == ELFCLASS32 ? 10 : 18,
+ (unsigned long long int) phdr->p_paddr,
+ gelf_getclass (elf) == ELFCLASS32 ? 9 : 12,
+ (unsigned long long int) phdr->p_filesz,
+ gelf_getclass (elf) == ELFCLASS32 ? 9 : 12,
+ (unsigned long long int) phdr->p_memsz,
+ (unsigned long long int) phdr->p_align);
+
+ putc_unlocked ((phdr->p_flags & PF_X) ? 'X' : ' ', stdout);
+ putc_unlocked ((phdr->p_flags & PF_W) ? 'W' : ' ', stdout);
+ putc_unlocked ((phdr->p_flags & PF_R) ? 'R' : ' ', stdout);
+
+ putc_unlocked ('\n', stdout);
+
+ if (phdr->p_type == PT_INTERP)
+ {
+ /* We can show the user the name of the interpreter. */
+ size_t maxsize;
+ char *filedata = elf_rawfile (elf, &maxsize);
+
+ if (filedata != NULL && phdr->p_offset < maxsize)
+ printf ("\t[Requesting program interpreter: %s]\n",
+ filedata + phdr->p_offset);
+ }
+ }
+
+ if (elf_end (elf) != 0)
+ {
+ printf ("error while freeing ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/tests/test-nlist.c b/tests/test-nlist.c
new file mode 100644
index 0000000..1a3f3ec
--- /dev/null
+++ b/tests/test-nlist.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#include <nlist.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int var = 1;
+
+int bss;
+
+
+int
+foo (int a)
+{
+ return a;
+}
+
+int
+main (int argc, char *argv[] __attribute__ ((unused)))
+{
+ struct nlist nl[6] =
+ {
+ [0] = { .n_name = "var" },
+ [1] = { .n_name = "bss" },
+ [2] = { .n_name = "main" },
+ [3] = { .n_name = "foo" },
+ [4] = { .n_name = "not-there" },
+ [5] = { .n_name = NULL },
+ };
+ int cnt;
+ int result = 0;
+
+ if (nlist (".libs/test-nlist", nl) != 0
+ && nlist ("./test-nlist", nl) != 0)
+ {
+ puts ("nlist failed");
+ exit (1);
+ }
+
+ for (cnt = 0; nl[cnt].n_name != NULL; ++cnt)
+ {
+ if (argc > 1)
+ /* For debugging. */
+ printf ("nl[%d].n_name = \"%s\"\n"
+ "nl[%d].n_value = %ld\n"
+ "nl[%d].n_scnum = %d\n"
+ "nl[%d].n_type = %u\n"
+ "nl[%d].n_sclass = %d\n"
+ "nl[%d].n_numaux = %d\n\n",
+ cnt, nl[cnt].n_name,
+ cnt, nl[cnt].n_value,
+ cnt, nl[cnt].n_scnum,
+ cnt, nl[cnt].n_type,
+ cnt, nl[cnt].n_sclass,
+ cnt, nl[cnt].n_numaux);
+
+ if ((cnt != 4 && nl[cnt].n_value == 0 && nl[cnt].n_scnum == 0
+ && nl[cnt].n_type == 0 && nl[cnt].n_sclass == 0
+ && nl[cnt].n_numaux == 0)
+ || (cnt == 4 && (nl[cnt].n_value != 0 || nl[cnt].n_scnum != 0
+ || nl[cnt].n_type != 0 || nl[cnt].n_sclass != 0
+ || nl[cnt].n_numaux != 0)))
+ result = 1;
+ }
+
+ return foo (result);
+}
diff --git a/tests/testfile.bz2 b/tests/testfile.bz2
new file mode 100644
index 0000000..bde9b12
--- /dev/null
+++ b/tests/testfile.bz2
Binary files differ
diff --git a/tests/testfile10.bz2 b/tests/testfile10.bz2
new file mode 100644
index 0000000..e9dd504
--- /dev/null
+++ b/tests/testfile10.bz2
Binary files differ
diff --git a/tests/testfile11.bz2 b/tests/testfile11.bz2
new file mode 100644
index 0000000..d094b84
--- /dev/null
+++ b/tests/testfile11.bz2
Binary files differ
diff --git a/tests/testfile12.bz2 b/tests/testfile12.bz2
new file mode 100644
index 0000000..8bb5ad3
--- /dev/null
+++ b/tests/testfile12.bz2
Binary files differ
diff --git a/tests/testfile13.bz2 b/tests/testfile13.bz2
new file mode 100644
index 0000000..3b0bcb9
--- /dev/null
+++ b/tests/testfile13.bz2
Binary files differ
diff --git a/tests/testfile14.bz2 b/tests/testfile14.bz2
new file mode 100644
index 0000000..ac7c69e
--- /dev/null
+++ b/tests/testfile14.bz2
Binary files differ
diff --git a/tests/testfile15.bz2 b/tests/testfile15.bz2
new file mode 100644
index 0000000..e75f457
--- /dev/null
+++ b/tests/testfile15.bz2
Binary files differ
diff --git a/tests/testfile15.debug.bz2 b/tests/testfile15.debug.bz2
new file mode 100644
index 0000000..5c86900
--- /dev/null
+++ b/tests/testfile15.debug.bz2
Binary files differ
diff --git a/tests/testfile16.bz2 b/tests/testfile16.bz2
new file mode 100644
index 0000000..909e225
--- /dev/null
+++ b/tests/testfile16.bz2
Binary files differ
diff --git a/tests/testfile16.debug.bz2 b/tests/testfile16.debug.bz2
new file mode 100644
index 0000000..48d651f
--- /dev/null
+++ b/tests/testfile16.debug.bz2
Binary files differ
diff --git a/tests/testfile17.bz2 b/tests/testfile17.bz2
new file mode 100644
index 0000000..5a12320
--- /dev/null
+++ b/tests/testfile17.bz2
Binary files differ
diff --git a/tests/testfile17.debug.bz2 b/tests/testfile17.debug.bz2
new file mode 100644
index 0000000..86a76ab
--- /dev/null
+++ b/tests/testfile17.debug.bz2
Binary files differ
diff --git a/tests/testfile18.bz2 b/tests/testfile18.bz2
new file mode 100644
index 0000000..8b5326c
--- /dev/null
+++ b/tests/testfile18.bz2
Binary files differ
diff --git a/tests/testfile2.bz2 b/tests/testfile2.bz2
new file mode 100644
index 0000000..0771311
--- /dev/null
+++ b/tests/testfile2.bz2
Binary files differ
diff --git a/tests/testfile3.bz2 b/tests/testfile3.bz2
new file mode 100644
index 0000000..30a456c
--- /dev/null
+++ b/tests/testfile3.bz2
Binary files differ
diff --git a/tests/testfile4.bz2 b/tests/testfile4.bz2
new file mode 100644
index 0000000..25b25df
--- /dev/null
+++ b/tests/testfile4.bz2
Binary files differ
diff --git a/tests/testfile5.bz2 b/tests/testfile5.bz2
new file mode 100644
index 0000000..247313e
--- /dev/null
+++ b/tests/testfile5.bz2
Binary files differ
diff --git a/tests/testfile6.bz2 b/tests/testfile6.bz2
new file mode 100644
index 0000000..fd376b2
--- /dev/null
+++ b/tests/testfile6.bz2
Binary files differ
diff --git a/tests/testfile7.bz2 b/tests/testfile7.bz2
new file mode 100644
index 0000000..73452bb
--- /dev/null
+++ b/tests/testfile7.bz2
Binary files differ
diff --git a/tests/testfile8.bz2 b/tests/testfile8.bz2
new file mode 100644
index 0000000..1ff4994
--- /dev/null
+++ b/tests/testfile8.bz2
Binary files differ
diff --git a/tests/testfile9.bz2 b/tests/testfile9.bz2
new file mode 100644
index 0000000..40454bc
--- /dev/null
+++ b/tests/testfile9.bz2
Binary files differ
diff --git a/tests/update1.c b/tests/update1.c
new file mode 100644
index 0000000..cf2d625
--- /dev/null
+++ b/tests/update1.c
@@ -0,0 +1,120 @@
+/* Test program for elf_update function.
+ Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+int
+main (int argc, char *argv[] __attribute__ ((unused)))
+{
+ const char *fname = "xxx";
+ int fd;
+ Elf *elf;
+ Elf32_Ehdr *ehdr;
+ int i;
+
+ fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+ if (fd == -1)
+ {
+ printf ("cannot open `%s': %s\n", fname, strerror (errno));
+ exit (1);
+ }
+
+ elf_version (EV_CURRENT);
+
+ elf = elf_begin (fd, ELF_C_WRITE, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Create an ELF header. */
+ ehdr = elf32_newehdr (elf);
+ if (ehdr == NULL)
+ {
+ printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ ehdr->e_ident[0] = 42;
+ ehdr->e_ident[4] = 1;
+ ehdr->e_ident[5] = 1;
+ ehdr->e_ident[6] = 2;
+ ehdr->e_ident[9] = 2;
+ ehdr->e_version = 1;
+ ehdr->e_ehsize = 1;
+
+ /* Write out the file. */
+ if (elf_update (elf, ELF_C_WRITE) < 0)
+ {
+ printf ("failure in elf_update: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Create an ELF header. */
+ ehdr = elf32_newehdr (elf);
+ if (ehdr == NULL)
+ {
+ printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ if (elf_end (elf) != 0)
+ {
+ printf ("failure in elf_end: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/tests/update2.c b/tests/update2.c
new file mode 100644
index 0000000..743bfd2
--- /dev/null
+++ b/tests/update2.c
@@ -0,0 +1,143 @@
+/* Test program for elf_update function.
+ Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+int
+main (int argc, char *argv[] __attribute__ ((unused)))
+{
+ const char *fname = "xxx";
+ int fd;
+ Elf *elf;
+ Elf32_Ehdr *ehdr;
+ Elf32_Phdr *phdr;
+ int i;
+
+ fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+ if (fd == -1)
+ {
+ printf ("cannot open `%s': %s\n", fname, strerror (errno));
+ exit (1);
+ }
+
+ elf_version (EV_CURRENT);
+
+ elf = elf_begin (fd, ELF_C_WRITE, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Create an ELF header. */
+ ehdr = elf32_newehdr (elf);
+ if (ehdr == NULL)
+ {
+ printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ ehdr->e_ident[0] = 42;
+ ehdr->e_ident[4] = 1;
+ ehdr->e_ident[5] = 1;
+ ehdr->e_ident[6] = 2;
+ ehdr->e_type = ET_EXEC;
+ ehdr->e_version = 1;
+ ehdr->e_ehsize = 1;
+ elf_flagehdr (elf, ELF_C_SET, ELF_F_DIRTY);
+
+ /* Create the program header. */
+ phdr = elf32_newphdr (elf, 1);
+ if (phdr == NULL)
+ {
+ printf ("cannot create program header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ phdr[0].p_type = PT_PHDR;
+ elf_flagphdr (elf, ELF_C_SET, ELF_F_DIRTY);
+
+ /* Let the library compute the internal structure information. */
+ if (elf_update (elf, ELF_C_NULL) < 0)
+ {
+ printf ("failure in elf_update(NULL): %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ ehdr = elf32_getehdr (elf);
+
+ phdr[0].p_offset = ehdr->e_phoff;
+ phdr[0].p_offset = ehdr->e_phoff;
+ phdr[0].p_vaddr = ehdr->e_phoff;
+ phdr[0].p_paddr = ehdr->e_phoff;
+ phdr[0].p_flags = PF_R | PF_X;
+ phdr[0].p_filesz = ehdr->e_phnum * elf32_fsize (ELF_T_PHDR, 1, EV_CURRENT);
+ phdr[0].p_memsz = ehdr->e_phnum * elf32_fsize (ELF_T_PHDR, 1, EV_CURRENT);
+ phdr[0].p_align = sizeof (Elf32_Word);
+
+ /* Write out the file. */
+ if (elf_update (elf, ELF_C_WRITE) < 0)
+ {
+ printf ("failure in elf_update(WRITE): %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ if (elf_end (elf) != 0)
+ {
+ printf ("failure in elf_end: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/tests/update3.c b/tests/update3.c
new file mode 100644
index 0000000..160adf1
--- /dev/null
+++ b/tests/update3.c
@@ -0,0 +1,198 @@
+/* Test program for elf_update function.
+ Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libebl.h>
+
+
+int
+main (int argc, char *argv[] __attribute__ ((unused)))
+{
+ const char *fname = "xxx";
+ int fd;
+ Elf *elf;
+ Elf32_Ehdr *ehdr;
+ Elf32_Phdr *phdr;
+ Elf_Scn *scn;
+ Elf32_Shdr *shdr;
+ Elf_Data *data;
+ struct Ebl_Strtab *shst;
+ struct Ebl_Strent *shstrtabse;
+ int i;
+
+ fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+ if (fd == -1)
+ {
+ printf ("cannot open `%s': %s\n", fname, strerror (errno));
+ exit (1);
+ }
+
+ elf_version (EV_CURRENT);
+
+ elf_fill (0x42);
+
+ elf = elf_begin (fd, ELF_C_WRITE, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Create an ELF header. */
+ ehdr = elf32_newehdr (elf);
+ if (ehdr == NULL)
+ {
+ printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ ehdr->e_ident[0] = 42;
+ ehdr->e_ident[4] = 1;
+ ehdr->e_ident[5] = 1;
+ ehdr->e_ident[6] = 2;
+ ehdr->e_type = ET_EXEC;
+ ehdr->e_version = 1;
+ ehdr->e_ehsize = 1;
+ elf_flagehdr (elf, ELF_C_SET, ELF_F_DIRTY);
+
+ /* Create the program header. */
+ phdr = elf32_newphdr (elf, 1);
+ if (phdr == NULL)
+ {
+ printf ("cannot create program header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ phdr[0].p_type = PT_PHDR;
+ elf_flagphdr (elf, ELF_C_SET, ELF_F_DIRTY);
+
+ shst = ebl_strtabinit (true);
+
+ scn = elf_newscn (elf);
+ if (scn == NULL)
+ {
+ printf ("cannot create SHSTRTAB section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for SHSTRTAB section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ shstrtabse = ebl_strtabadd (shst, ".shstrtab", 0);
+
+ 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;
+
+ /* We have to store the section index in the ELF header. */
+ ehdr->e_shstrndx = elf_ndxscn (scn);
+
+ data = elf_newdata (scn);
+ if (data == NULL)
+ {
+ printf ("cannot create data SHSTRTAB section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* No more sections, finalize the section header string table. */
+ ebl_strtabfinalize (shst, data);
+
+ shdr->sh_name = ebl_strtaboffset (shstrtabse);
+
+ /* Let the library compute the internal structure information. */
+ if (elf_update (elf, ELF_C_NULL) < 0)
+ {
+ printf ("failure in elf_update(NULL): %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ ehdr = elf32_getehdr (elf);
+
+ phdr[0].p_offset = ehdr->e_phoff;
+ phdr[0].p_offset = ehdr->e_phoff;
+ phdr[0].p_vaddr = ehdr->e_phoff;
+ phdr[0].p_paddr = ehdr->e_phoff;
+ phdr[0].p_flags = PF_R | PF_X;
+ phdr[0].p_filesz = ehdr->e_phnum * elf32_fsize (ELF_T_PHDR, 1, EV_CURRENT);
+ phdr[0].p_memsz = ehdr->e_phnum * elf32_fsize (ELF_T_PHDR, 1, EV_CURRENT);
+ phdr[0].p_align = sizeof (Elf32_Word);
+
+ /* Write out the file. */
+ if (elf_update (elf, ELF_C_WRITE) < 0)
+ {
+ printf ("failure in elf_update(WRITE): %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* We don't need the string table anymore. */
+ ebl_strtabfree (shst);
+
+ /* And the data allocated in the .shstrtab section. */
+ free (data->d_buf);
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ if (elf_end (elf) != 0)
+ {
+ printf ("failure in elf_end: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/tests/update4.c b/tests/update4.c
new file mode 100644
index 0000000..30f3a07
--- /dev/null
+++ b/tests/update4.c
@@ -0,0 +1,353 @@
+/* Test program for elf_update function.
+ Copyright (C) 2000, 2001, 2002, 2005 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <libelf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <libebl.h>
+
+
+int
+main (int argc, char *argv[] __attribute__ ((unused)))
+{
+ const char fname[] = "xxx";
+ int fd;
+ Elf *elf;
+ Elf32_Ehdr *ehdr;
+ Elf32_Phdr *phdr;
+ Elf_Scn *scn;
+ Elf32_Shdr *shdr;
+ Elf_Data *data;
+ struct Ebl_Strtab *shst;
+ struct Ebl_Strent *firstse;
+ struct Ebl_Strent *secondse;
+ struct Ebl_Strent *thirdse;
+ struct Ebl_Strent *fourthse;
+ struct Ebl_Strent *shstrtabse;
+ int i;
+
+ fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+ if (fd == -1)
+ {
+ printf ("cannot open `%s': %s\n", fname, strerror (errno));
+ exit (1);
+ }
+
+ elf_version (EV_CURRENT);
+
+ elf_fill (0x42);
+
+ elf = elf_begin (fd, ELF_C_WRITE, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Create an ELF header. */
+ ehdr = elf32_newehdr (elf);
+ if (ehdr == NULL)
+ {
+ printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ ehdr->e_ident[0] = 42;
+ ehdr->e_ident[4] = 1;
+ ehdr->e_ident[5] = 1;
+ ehdr->e_ident[6] = 2;
+ ehdr->e_type = ET_EXEC;
+ ehdr->e_version = 1;
+ ehdr->e_ehsize = 1;
+ elf_flagehdr (elf, ELF_C_SET, ELF_F_DIRTY);
+
+ /* Create the program header. */
+ phdr = elf32_newphdr (elf, 1);
+ if (phdr == NULL)
+ {
+ printf ("cannot create program header: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ phdr[0].p_type = PT_PHDR;
+ elf_flagphdr (elf, ELF_C_SET, ELF_F_DIRTY);
+
+ shst = ebl_strtabinit (true);
+
+ scn = elf_newscn (elf);
+ if (scn == NULL)
+ {
+ printf ("cannot create first section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for first section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ firstse = ebl_strtabadd (shst, ".first", 0);
+
+ shdr->sh_type = SHT_PROGBITS;
+ shdr->sh_flags = SHF_ALLOC | SHF_EXECINSTR;
+ shdr->sh_addr = 0;
+ shdr->sh_link = 0;
+ shdr->sh_info = 0;
+ shdr->sh_entsize = 1;
+
+ data = elf_newdata (scn);
+ if (data == NULL)
+ {
+ printf ("cannot create data first section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ data->d_buf = "hello";
+ data->d_type = ELF_T_BYTE;
+ data->d_version = EV_CURRENT;
+ data->d_size = 5;
+ data->d_align = 16;
+
+
+ scn = elf_newscn (elf);
+ if (scn == NULL)
+ {
+ printf ("cannot create second section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for second section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ secondse = ebl_strtabadd (shst, ".second", 0);
+
+ shdr->sh_type = SHT_PROGBITS;
+ shdr->sh_flags = SHF_ALLOC | SHF_WRITE;
+ shdr->sh_addr = 0;
+ shdr->sh_link = 0;
+ shdr->sh_info = 0;
+ shdr->sh_entsize = 1;
+
+ data = elf_newdata (scn);
+ if (data == NULL)
+ {
+ printf ("cannot create data second section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ data->d_buf = "world";
+ data->d_type = ELF_T_BYTE;
+ data->d_version = EV_CURRENT;
+ data->d_size = 5;
+ data->d_align = 16;
+
+
+ scn = elf_newscn (elf);
+ if (scn == NULL)
+ {
+ printf ("cannot create third section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for third section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ thirdse = ebl_strtabadd (shst, ".third", 0);
+
+ shdr->sh_type = SHT_PROGBITS;
+ shdr->sh_flags = SHF_ALLOC | SHF_EXECINSTR;
+ shdr->sh_addr = 0;
+ shdr->sh_link = 0;
+ shdr->sh_info = 0;
+ shdr->sh_entsize = 1;
+
+ data = elf_newdata (scn);
+ if (data == NULL)
+ {
+ printf ("cannot create data third section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ data->d_buf = "!!!!!";
+ data->d_type = ELF_T_BYTE;
+ data->d_version = EV_CURRENT;
+ data->d_size = 5;
+ data->d_align = 16;
+
+
+ scn = elf_newscn (elf);
+ if (scn == NULL)
+ {
+ printf ("cannot create fourth section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for fourth section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ fourthse = ebl_strtabadd (shst, ".fourth", 0);
+
+ shdr->sh_type = SHT_NOBITS;
+ shdr->sh_flags = SHF_ALLOC | SHF_EXECINSTR;
+ shdr->sh_addr = 0;
+ shdr->sh_link = 0;
+ shdr->sh_info = 0;
+ shdr->sh_entsize = 1;
+ shdr->sh_size = 100;
+
+ data = elf_newdata (scn);
+ if (data == NULL)
+ {
+ printf ("cannot create data fourth section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ data->d_buf = NULL;
+ data->d_type = ELF_T_BYTE;
+ data->d_version = EV_CURRENT;
+ data->d_size = 100;
+ data->d_align = 16;
+
+
+ scn = elf_newscn (elf);
+ if (scn == NULL)
+ {
+ printf ("cannot create SHSTRTAB section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+ shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ {
+ printf ("cannot get header for SHSTRTAB section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ shstrtabse = ebl_strtabadd (shst, ".shstrtab", 0);
+
+ 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_entsize = 1;
+
+ /* We have to store the section index in the ELF header. */
+ ehdr->e_shstrndx = elf_ndxscn (scn);
+
+ data = elf_newdata (scn);
+ if (data == NULL)
+ {
+ printf ("cannot create data SHSTRTAB section: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* No more sections, finalize the section header string table. */
+ ebl_strtabfinalize (shst, data);
+
+ elf32_getshdr (elf_getscn (elf, 1))->sh_name = ebl_strtaboffset (firstse);
+ elf32_getshdr (elf_getscn (elf, 2))->sh_name = ebl_strtaboffset (secondse);
+ elf32_getshdr (elf_getscn (elf, 3))->sh_name = ebl_strtaboffset (thirdse);
+ elf32_getshdr (elf_getscn (elf, 4))->sh_name = ebl_strtaboffset (fourthse);
+ shdr->sh_name = ebl_strtaboffset (shstrtabse);
+
+ /* Let the library compute the internal structure information. */
+ if (elf_update (elf, ELF_C_NULL) < 0)
+ {
+ printf ("failure in elf_update(NULL): %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ ehdr = elf32_getehdr (elf);
+
+ phdr[0].p_offset = ehdr->e_phoff;
+ phdr[0].p_offset = ehdr->e_phoff;
+ phdr[0].p_vaddr = ehdr->e_phoff;
+ phdr[0].p_paddr = ehdr->e_phoff;
+ phdr[0].p_flags = PF_R | PF_X;
+ phdr[0].p_filesz = ehdr->e_phnum * elf32_fsize (ELF_T_PHDR, 1, EV_CURRENT);
+ phdr[0].p_memsz = ehdr->e_phnum * elf32_fsize (ELF_T_PHDR, 1, EV_CURRENT);
+ phdr[0].p_align = sizeof (Elf32_Word);
+
+ /* Write out the file. */
+ if (elf_update (elf, ELF_C_WRITE) < 0)
+ {
+ printf ("failure in elf_update(WRITE): %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ /* We don't need the string table anymore. */
+ ebl_strtabfree (shst);
+
+ /* And the data allocated in the .shstrtab section. */
+ free (data->d_buf);
+
+ /* Print the ELF header values. */
+ if (argc > 1)
+ {
+ for (i = 0; i < EI_NIDENT; ++i)
+ printf (" %02x", ehdr->e_ident[i]);
+ printf ("\
+\ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
+ "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
+ "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
+ ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
+ ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
+ ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
+ ehdr->e_shnum, ehdr->e_shstrndx);
+ }
+
+ if (elf_end (elf) != 0)
+ {
+ printf ("failure in elf_end: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
+ unlink (fname);
+
+ return 0;
+}