Test case for problem in libelf with writing out existing ELF file with
authorUlrich Drepper <drepper@redhat.com>
Tue, 4 Apr 2006 21:31:16 +0000 (21:31 +0000)
committerUlrich Drepper <drepper@redhat.com>
Tue, 4 Apr 2006 21:31:16 +0000 (21:31 +0000)
different location of the section headers.

tests/ChangeLog
tests/Makefile.am
tests/rdwrmmap.c [new file with mode: 0644]
tests/run-bug1-test.sh [new file with mode: 0755]
tests/testfile28.bz2 [new file with mode: 0644]
tests/testfile28.rdwr.bz2 [new file with mode: 0644]

index bccd736..16b1491 100644 (file)
@@ -1,3 +1,11 @@
+2006-04-04  Ulrich Drepper  <drepper@redhat.com>
+
+       * Makefile.am: Add rules to run run-bug1-test.sh.
+       * rdwrmmap.c: New file.
+       * run-bug1-test.sh: New file.
+       * testfile28.bz2: New file.
+       * testfile28.rdwr.bz2: New file.
+
 2006-03-09  Roland McGrath  <roland@redhat.com>
 
        * Makefile.am (AM_LDFLAGS): Define to pass -rpath-link.
index 9288109..a88836b 100644 (file)
@@ -45,7 +45,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
                  show-die-info get-files get-lines get-pubnames \
                  get-aranges allfcts line2addr addrscopes funcscopes \
                  show-abbrev hash newscn ecp dwflmodtest \
-                 find-prologues funcretval allregs
+                 find-prologues funcretval allregs rdwrmmap
 # get-ciefde
 asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
            asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -62,7 +62,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
        run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \
        run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \
        run-find-prologues.sh run-allregs.sh run-readelf-test1.sh \
-       run-native-test.sh
+       run-native-test.sh run-bug1-test.sh
 # run-show-ciefde.sh
 
 if !STANDALONE
@@ -99,7 +99,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             testfile21.bz2 testfile21.index.bz2 \
             testfile22.bz2 testfile23.bz2 testfile24.bz2 testfile25.bz2 \
             testfile26.bz2 testfile27.bz2 \
-            coverage.sh test-subr.sh test-wrapper.sh run-readelf-test1.sh
+            coverage.sh test-subr.sh test-wrapper.sh run-readelf-test1.sh \
+            run-bug1-test.sh testfile28.bz2 testfile28.rdwr.bz2
 
 installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
                              bindir=$(DESTDIR)$(bindir) \
@@ -181,6 +182,7 @@ asm_tst7_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
 asm_tst8_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
 asm_tst9_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
 dwflmodtest_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+rdwrmmap_LDADD = $(libelf)
 
 CLEANFILES = xxx *.gcno *.gcda *gconv
 
diff --git a/tests/rdwrmmap.c b/tests/rdwrmmap.c
new file mode 100644 (file)
index 0000000..263be0f
--- /dev/null
@@ -0,0 +1,29 @@
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <libelf.h>
+
+int
+main (int argc __attribute__ ((unused)), char *argv[])
+{
+  int fd = open (argv[1], O_RDWR);
+  if (fd < 0)
+    error (2, errno, "open: %s", argv[1]);
+
+  if (elf_version (EV_CURRENT) == EV_NONE)
+    error (1, 0, "libelf version mismatch");
+
+  Elf *elf = elf_begin (fd, ELF_C_RDWR_MMAP, NULL);
+  if (elf == NULL)
+    error (1, 0, "elf_begin: %s", elf_errmsg (-1));
+
+  if (elf_update (elf, ELF_C_WRITE) < 0)
+    error (1, 0, "elf_update: %s", elf_errmsg (-1));
+
+  elf_end (elf);
+  close (fd);
+
+  return 0;
+}
diff --git a/tests/run-bug1-test.sh b/tests/run-bug1-test.sh
new file mode 100755 (executable)
index 0000000..4e12b77
--- /dev/null
@@ -0,0 +1,22 @@
+#! /bin/sh
+# Copyright (C) 2006 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 2006.
+#
+# 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.
+. $srcdir/test-subr.sh
+
+testfiles testfile28 testfile28.rdwr
+
+testrun ./rdwrmmap testfile28
+
+cmp testfile28 testfile28.rdwr
+
+exit 0
diff --git a/tests/testfile28.bz2 b/tests/testfile28.bz2
new file mode 100644 (file)
index 0000000..ca0dff3
Binary files /dev/null and b/tests/testfile28.bz2 differ
diff --git a/tests/testfile28.rdwr.bz2 b/tests/testfile28.rdwr.bz2
new file mode 100644 (file)
index 0000000..4c65848
Binary files /dev/null and b/tests/testfile28.rdwr.bz2 differ