summaryrefslogtreecommitdiffstats
path: root/trunk/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/testsuite')
-rw-r--r--trunk/testsuite/Makefile.am56
-rw-r--r--trunk/testsuite/Makefile.in344
-rw-r--r--trunk/testsuite/cxx1.C26
-rw-r--r--trunk/testsuite/cxx1.h19
-rwxr-xr-xtrunk/testsuite/cxx1.sh20
-rw-r--r--trunk/testsuite/cxx1lib1.C34
-rw-r--r--trunk/testsuite/cxx1lib2.C28
-rwxr-xr-xtrunk/testsuite/cycle1.sh25
-rwxr-xr-xtrunk/testsuite/cycle2.sh28
-rw-r--r--trunk/testsuite/deps1.c18
-rw-r--r--trunk/testsuite/deps1.h4
-rwxr-xr-xtrunk/testsuite/deps1.sh60
-rw-r--r--trunk/testsuite/deps1lib1.c21
-rw-r--r--trunk/testsuite/deps1lib2.c11
-rwxr-xr-xtrunk/testsuite/deps2.sh57
-rw-r--r--trunk/testsuite/deps2lib1.c26
-rwxr-xr-xtrunk/testsuite/functions.sh26
-rw-r--r--trunk/testsuite/layout.C3
-rwxr-xr-xtrunk/testsuite/layout1.sh24
-rwxr-xr-xtrunk/testsuite/layout2.sh23
-rw-r--r--trunk/testsuite/layoutlib.C10
-rwxr-xr-xtrunk/testsuite/movelibs.sh35
-rw-r--r--trunk/testsuite/quick1.c21
-rwxr-xr-xtrunk/testsuite/quick1.sh212
-rw-r--r--trunk/testsuite/quick1lib1.c9
-rw-r--r--trunk/testsuite/quick1lib2.c11
-rw-r--r--trunk/testsuite/quick1lib3.c7
-rw-r--r--trunk/testsuite/quick1lib4.c2
-rwxr-xr-xtrunk/testsuite/quick2.sh288
-rwxr-xr-xtrunk/testsuite/quick3.sh110
-rw-r--r--trunk/testsuite/reloc1.c16
-rw-r--r--trunk/testsuite/reloc1.h12
-rwxr-xr-xtrunk/testsuite/reloc1.sh20
-rw-r--r--trunk/testsuite/reloc10.c19
-rwxr-xr-xtrunk/testsuite/reloc10.sh23
-rw-r--r--trunk/testsuite/reloc10lib1.c12
-rw-r--r--trunk/testsuite/reloc10lib2.c11
-rw-r--r--trunk/testsuite/reloc10lib3.c3
-rw-r--r--trunk/testsuite/reloc10lib4.c1
-rw-r--r--trunk/testsuite/reloc10lib5.c12
-rw-r--r--trunk/testsuite/reloc11.c16
-rwxr-xr-xtrunk/testsuite/reloc11.sh21
-rw-r--r--trunk/testsuite/reloc11lib2.c16
-rw-r--r--trunk/testsuite/reloc11lib3.c7
-rw-r--r--trunk/testsuite/reloc1lib1.c16
-rw-r--r--trunk/testsuite/reloc1lib2.c6
-rw-r--r--trunk/testsuite/reloc2.c13
-rwxr-xr-xtrunk/testsuite/reloc2.sh26
-rw-r--r--trunk/testsuite/reloc2lib1.c4
-rw-r--r--trunk/testsuite/reloc2lib2.c15
-rw-r--r--trunk/testsuite/reloc3.c29
-rwxr-xr-xtrunk/testsuite/reloc3.sh21
-rw-r--r--trunk/testsuite/reloc3lib1.c21
-rw-r--r--trunk/testsuite/reloc4.c14
-rwxr-xr-xtrunk/testsuite/reloc4.sh36
-rw-r--r--trunk/testsuite/reloc4lib1.c9
-rw-r--r--trunk/testsuite/reloc4lib2.c17
-rw-r--r--trunk/testsuite/reloc4lib3.c9
-rw-r--r--trunk/testsuite/reloc5.c24
-rwxr-xr-xtrunk/testsuite/reloc5.sh22
-rwxr-xr-xtrunk/testsuite/reloc6.sh36
-rw-r--r--trunk/testsuite/reloc7.c38
-rwxr-xr-xtrunk/testsuite/reloc7.sh20
-rwxr-xr-xtrunk/testsuite/reloc8.sh28
-rwxr-xr-xtrunk/testsuite/reloc9.sh28
-rwxr-xr-xtrunk/testsuite/shuffle1.sh24
-rw-r--r--trunk/testsuite/shuffle2.c27
-rwxr-xr-xtrunk/testsuite/shuffle2.sh29
-rwxr-xr-xtrunk/testsuite/shuffle3.sh30
-rwxr-xr-xtrunk/testsuite/shuffle4.sh22
-rwxr-xr-xtrunk/testsuite/shuffle5.sh24
-rwxr-xr-xtrunk/testsuite/shuffle6.sh37
-rw-r--r--trunk/testsuite/shuffle6lib1.c20
-rw-r--r--trunk/testsuite/shuffle6lib2.c16
-rwxr-xr-xtrunk/testsuite/shuffle7.sh50
-rw-r--r--trunk/testsuite/shuffle8.c20
-rwxr-xr-xtrunk/testsuite/shuffle8.sh21
-rw-r--r--trunk/testsuite/tls1.c36
-rw-r--r--trunk/testsuite/tls1.h30
-rwxr-xr-xtrunk/testsuite/tls1.sh25
-rw-r--r--trunk/testsuite/tls1lib1.c89
-rw-r--r--trunk/testsuite/tls1lib2.c62
-rw-r--r--trunk/testsuite/tls2.c25
-rwxr-xr-xtrunk/testsuite/tls2.sh26
-rw-r--r--trunk/testsuite/tls2lib1.c87
-rwxr-xr-xtrunk/testsuite/tls3.sh30
-rw-r--r--trunk/testsuite/tls3lib2.c68
-rw-r--r--trunk/testsuite/tls4.c16
-rwxr-xr-xtrunk/testsuite/tls4.sh26
-rw-r--r--trunk/testsuite/tls4lib1.c5
-rw-r--r--trunk/testsuite/tls4lib2.c12
-rwxr-xr-xtrunk/testsuite/tls5.sh34
-rw-r--r--trunk/testsuite/tls5lib1.c96
-rwxr-xr-xtrunk/testsuite/tls6.sh36
-rw-r--r--trunk/testsuite/tls6lib1.c94
-rw-r--r--trunk/testsuite/tls7.c10
-rwxr-xr-xtrunk/testsuite/tls7.sh23
-rwxr-xr-xtrunk/testsuite/undo1.sh24
-rwxr-xr-xtrunk/testsuite/undosyslibs.sh4
99 files changed, 3357 insertions, 0 deletions
diff --git a/trunk/testsuite/Makefile.am b/trunk/testsuite/Makefile.am
new file mode 100644
index 0000000..3af929b
--- /dev/null
+++ b/trunk/testsuite/Makefile.am
@@ -0,0 +1,56 @@
+## Process this file with automake to create Makefile.in
+
+AUTOMAKE_OPTIONS = 1.4 gnu
+
+DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -Wall
+AM_CFLAGS = -Wall
+
+TESTS = movelibs.sh \
+ reloc1.sh reloc2.sh reloc3.sh reloc4.sh reloc5.sh reloc6.sh \
+ reloc7.sh reloc8.sh reloc9.sh reloc10.sh reloc11.sh \
+ shuffle1.sh shuffle2.sh shuffle3.sh shuffle4.sh shuffle5.sh \
+ shuffle6.sh shuffle7.sh shuffle8.sh undo1.sh \
+ layout1.sh layout2.sh \
+ tls1.sh tls2.sh tls3.sh tls4.sh tls5.sh tls6.sh tls7.sh \
+ cxx1.sh quick1.sh quick2.sh quick3.sh cycle1.sh cycle2.sh \
+ deps1.sh deps2.sh \
+ undosyslibs.sh
+TESTS_ENVIRONMENT = \
+ PRELINK="../src/prelink -c ./prelink.conf -C ./prelink.cache --ld-library-path=. --dynamic-linker=`echo ./ld*.so.*[0-9]`" \
+ CC="$(CC) $(LINKOPTS)" CCLINK="$(CC) -Wl,--dynamic-linker=`echo ./ld*.so.*[0-9]`" \
+ CXX="$(CXX) $(LINKOPTS)" CXXLINK="$(CXX) -Wl,--dynamic-linker=`echo ./ld*.so.*[0-9]`" \
+ $(SHELL)
+
+extra_DIST = $(TESTS) functions.sh
+
+CLEANFILES = *.so *.so.* *.nop syslib.list syslnk.list prelink.cache prelink.conf \
+ $(TESTS:%.sh=%) $(TESTS:%.sh=%.log) $(TESTS:%.sh=%.lds) \
+ *.orig *.new core* *.\#prelink\#* tlstest *.first *.second
+
+clean-am: clean-dirs
+
+clean-dirs:
+ rm -rf *.tree
+
+.NOTPARALLEL:
+
+check-cycle:
+ @optlist=.; \
+ if [ "`uname -m | sed s/i.86/i.86/`" = i.86 ]; then \
+ optlist="--no-exec-shield --exec-shield"; \
+ fi; \
+ for opts2 in $$optlist; do \
+ for opts in -v -vm -vR -vmR; do \
+ PRELINK_OPTS="$$opts"; \
+ [ $$opts2 != . ] && PRELINK_OPTS="$$opts $$opts2"; \
+ echo "Checking with $$PRELINK_OPTS"; \
+ PRELINK_OPTS="$$PRELINK_OPTS" $(MAKE) $(AM_MAKEFLAGS) check || exit; \
+ $(MAKE) $(AM_MAKEFLAGS) clean || exit; \
+ done; \
+ done; \
+ echo "Checking with -Wl,-z,nocombreloc"; \
+ LINKOPTS=-Wl,-z,nocombreloc $(MAKE) $(AM_MAKEFLAGS) check || exit; \
+ $(MAKE) $(AM_MAKEFLAGS) clean || exit
+
+check-harder:
+ @CHECK_ME_HARDER=1 $(MAKE) $(AM_MAKEFLAGS) check || exit
diff --git a/trunk/testsuite/Makefile.in b/trunk/testsuite/Makefile.in
new file mode 100644
index 0000000..205f6e3
--- /dev/null
+++ b/trunk/testsuite/Makefile.in
@@ -0,0 +1,344 @@
+# Makefile.in generated by automake 1.6.3 from Makefile.am.
+# @configure_input@
+
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = @program_transform_name@
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+host_alias = @host_alias@
+host_triplet = @host@
+
+EXEEXT = @EXEEXT@
+OBJEXT = @OBJEXT@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AWK = @AWK@
+CC = @CC@
+CPP = @CPP@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+ECHO = @ECHO@
+EGREP = @EGREP@
+F77 = @F77@
+GCJ = @GCJ@
+GCJFLAGS = @GCJFLAGS@
+GELFINCLUDE = @GELFINCLUDE@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LIBGELF = @LIBGELF@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+OBJDUMP = @OBJDUMP@
+PACKAGE = @PACKAGE@
+RANLIB = @RANLIB@
+RC = @RC@
+STRIP = @STRIP@
+VERSION = @VERSION@
+am__include = @am__include@
+am__quote = @am__quote@
+install_sh = @install_sh@
+
+AUTOMAKE_OPTIONS = 1.4 gnu
+
+DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -Wall
+AM_CFLAGS = -Wall
+
+TESTS = movelibs.sh \
+ reloc1.sh reloc2.sh reloc3.sh reloc4.sh reloc5.sh reloc6.sh \
+ reloc7.sh reloc8.sh reloc9.sh reloc10.sh reloc11.sh \
+ shuffle1.sh shuffle2.sh shuffle3.sh shuffle4.sh shuffle5.sh \
+ shuffle6.sh shuffle7.sh shuffle8.sh undo1.sh \
+ layout1.sh layout2.sh \
+ tls1.sh tls2.sh tls3.sh tls4.sh tls5.sh tls6.sh tls7.sh \
+ cxx1.sh quick1.sh quick2.sh quick3.sh cycle1.sh cycle2.sh \
+ deps1.sh deps2.sh \
+ undosyslibs.sh
+
+TESTS_ENVIRONMENT = \
+ PRELINK="../src/prelink -c ./prelink.conf -C ./prelink.cache --ld-library-path=. --dynamic-linker=`echo ./ld*.so.*[0-9]`" \
+ CC="$(CC) $(LINKOPTS)" CCLINK="$(CC) -Wl,--dynamic-linker=`echo ./ld*.so.*[0-9]`" \
+ CXX="$(CXX) $(LINKOPTS)" CXXLINK="$(CXX) -Wl,--dynamic-linker=`echo ./ld*.so.*[0-9]`" \
+ $(SHELL)
+
+
+extra_DIST = $(TESTS) functions.sh
+
+CLEANFILES = *.so *.so.* *.nop syslib.list syslnk.list prelink.cache prelink.conf \
+ $(TESTS:%.sh=%) $(TESTS:%.sh=%.log) $(TESTS:%.sh=%.lds) \
+ *.orig *.new core* *.\#prelink\#* tlstest *.first *.second
+
+subdir = testsuite
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+DIST_SOURCES =
+DIST_COMMON = Makefile.am Makefile.in
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu testsuite/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
+tags: TAGS
+TAGS:
+
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list='$(TESTS)'; \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ $(TESTS_ENVIRONMENT) $${dir}$$tst; \
+ ret=$$?; \
+ if test $$ret -eq 0; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ echo "XPASS: $$tst"; \
+ ;; \
+ *) \
+ echo "PASS: $$tst"; \
+ ;; \
+ esac; \
+ elif test $$ret -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xfail=`expr $$xfail + 1`; \
+ echo "XFAIL: $$tst ($$ret)"; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ echo "FAIL: $$tst ($$ret)"; \
+ ;; \
+ esac; \
+ fi; \
+ done; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="All $$all tests passed"; \
+ else \
+ banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all tests failed"; \
+ else \
+ banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
+ fi; \
+ fi; \
+ dashes=`echo "$$banner" | sed s/./=/g`; \
+ echo "$$dashes"; \
+ echo "$$banner"; \
+ echo "$$dashes"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = ..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+ @list='$(DISTFILES)'; for file in $$list; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkinstalldirs) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile
+
+installdirs:
+
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+
+distclean-am: clean-am distclean-generic distclean-libtool
+
+dvi: dvi-am
+
+dvi-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+uninstall-am: uninstall-info-am
+
+.PHONY: all all-am check check-TESTS check-am clean clean-generic \
+ clean-libtool distclean distclean-generic distclean-libtool \
+ distdir dvi dvi-am info info-am install install-am install-data \
+ install-data-am install-exec install-exec-am install-info \
+ install-info-am install-man install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic \
+ mostlyclean-libtool uninstall uninstall-am uninstall-info-am
+
+
+clean-am: clean-dirs
+
+clean-dirs:
+ rm -rf *.tree
+
+.NOTPARALLEL:
+
+check-cycle:
+ @optlist=.; \
+ if [ "`uname -m | sed s/i.86/i.86/`" = i.86 ]; then \
+ optlist="--no-exec-shield --exec-shield"; \
+ fi; \
+ for opts2 in $$optlist; do \
+ for opts in -v -vm -vR -vmR; do \
+ PRELINK_OPTS="$$opts"; \
+ [ $$opts2 != . ] && PRELINK_OPTS="$$opts $$opts2"; \
+ echo "Checking with $$PRELINK_OPTS"; \
+ PRELINK_OPTS="$$PRELINK_OPTS" $(MAKE) $(AM_MAKEFLAGS) check || exit; \
+ $(MAKE) $(AM_MAKEFLAGS) clean || exit; \
+ done; \
+ done; \
+ echo "Checking with -Wl,-z,nocombreloc"; \
+ LINKOPTS=-Wl,-z,nocombreloc $(MAKE) $(AM_MAKEFLAGS) check || exit; \
+ $(MAKE) $(AM_MAKEFLAGS) clean || exit
+
+check-harder:
+ @CHECK_ME_HARDER=1 $(MAKE) $(AM_MAKEFLAGS) check || exit
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/trunk/testsuite/cxx1.C b/trunk/testsuite/cxx1.C
new file mode 100644
index 0000000..9c11a6d
--- /dev/null
+++ b/trunk/testsuite/cxx1.C
@@ -0,0 +1,26 @@
+#include "cxx1.h"
+extern "C" void abort (void);
+
+void
+check (A *x, B *y)
+{
+ C d;
+ if (x->b () != 21)
+ abort ();
+ if (y->B::a () != 22)
+ abort ();
+ if (d.a () != 23)
+ abort ();
+ if (d.C::b () != 24)
+ abort ();
+}
+
+int
+main ()
+{
+ A x;
+ if (x.a () != 20)
+ abort ();
+ do_check (check, &x);
+ return 0;
+}
diff --git a/trunk/testsuite/cxx1.h b/trunk/testsuite/cxx1.h
new file mode 100644
index 0000000..d6efe9b
--- /dev/null
+++ b/trunk/testsuite/cxx1.h
@@ -0,0 +1,19 @@
+struct A
+ {
+ virtual int a ();
+ virtual int b ();
+ int c;
+ };
+struct B
+ {
+ virtual int a ();
+ int b;
+ };
+struct C
+ {
+ virtual int a ();
+ virtual int b ();
+ int c;
+ };
+
+void do_check (void (*check) (A *x, B *y), A *x);
diff --git a/trunk/testsuite/cxx1.sh b/trunk/testsuite/cxx1.sh
new file mode 100755
index 0000000..81428c2
--- /dev/null
+++ b/trunk/testsuite/cxx1.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f cxx1 cxx1lib*.so cxx1.log
+rm -f prelink.cache
+$CXX -shared -O2 -fpic -o cxx1lib1.so $srcdir/cxx1lib1.C
+$CXX -shared -O2 -fpic -o cxx1lib2.so $srcdir/cxx1lib2.C cxx1lib1.so
+BINS="cxx1"
+LIBS="cxx1lib1.so cxx1lib2.so"
+$CXXLINK -o cxx1 $srcdir/cxx1.C -Wl,--rpath-link,. cxx1lib2.so
+savelibs
+echo $PRELINK -vvvv ${PRELINK_OPTS--vm} ./cxx1 > cxx1.log
+$PRELINK -vvvv ${PRELINK_OPTS--vm} ./cxx1 >> cxx1.log 2>&1 || exit 1
+grep ^`echo $PRELINK | sed 's/ .*$/: /'` cxx1.log | grep -q -v 'C++ conflict' && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./cxx1 || exit 3
+fi
+readelf -a ./cxx1 >> cxx1.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./cxx1
+comparelibs >> cxx1.log 2>&1 || exit 5
diff --git a/trunk/testsuite/cxx1lib1.C b/trunk/testsuite/cxx1lib1.C
new file mode 100644
index 0000000..1eb192a
--- /dev/null
+++ b/trunk/testsuite/cxx1lib1.C
@@ -0,0 +1,34 @@
+#include "cxx1.h"
+
+int A::a ()
+{
+ return 10;
+}
+
+int A::b ()
+{
+ return 11;
+}
+
+int B::a ()
+{
+ return 12;
+}
+
+int C::a ()
+{
+ return 13;
+}
+
+int C::b ()
+{
+ return 14;
+}
+
+void
+do_check (void (*check) (A *x, B *y), A *x)
+{
+ B y;
+
+ check (x, &y);
+}
diff --git a/trunk/testsuite/cxx1lib2.C b/trunk/testsuite/cxx1lib2.C
new file mode 100644
index 0000000..77055da
--- /dev/null
+++ b/trunk/testsuite/cxx1lib2.C
@@ -0,0 +1,28 @@
+#include "cxx1.h"
+
+int A::a ()
+{
+ return 20;
+}
+
+int A::b ()
+{
+ return 21;
+}
+
+int B::a ()
+{
+ return 22;
+}
+
+int C::a ()
+{
+ return 23;
+}
+
+int C::b ()
+{
+ return 24;
+}
+
+C c;
diff --git a/trunk/testsuite/cycle1.sh b/trunk/testsuite/cycle1.sh
new file mode 100755
index 0000000..caf7864
--- /dev/null
+++ b/trunk/testsuite/cycle1.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f cycle1 cycle1lib*.so cycle1.log
+rm -f prelink.cache
+# Test whether prelink doesn't segfault or loop endlessly on
+# bogus library dependency chains
+echo 'int foo;' | $CC -shared -O2 -fpic -o cycle1lib1.so -xc -
+echo 'int bar;' | $CC -shared -O2 -fpic -o cycle1lib2.so -xc - -xnone cycle1lib1.so
+echo 'int foo;' | $CC -shared -O2 -fpic -o cycle1lib1.so -xc - -xnone cycle1lib2.so
+BINS="cycle1"
+LIBS="cycle1lib1.so cycle1lib2.so"
+echo 'int main (void) { return 0; } ' \
+ | $CCLINK -o cycle1 -xc - -xnone -Wl,--rpath-link,. cycle1lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./cycle1 > cycle1.log
+$PRELINK ${PRELINK_OPTS--vm} ./cycle1 >> cycle1.log 2>&1 || exit 1
+grep -v 'has a dependency cycle' cycle1.log \
+ | grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` && exit 2
+grep -q "^`echo $PRELINK | sed 's/ .*$/: .*has a dependency cycle/'`" \
+ cycle1.log || exit 3
+if [ "x$CROSS" = "x" ] ; then
+ LD_LIBRARY_PATH=. ./cycle1 || exit 4
+fi
+# So that it is not prelinked again
+chmod -x ./cycle1
diff --git a/trunk/testsuite/cycle2.sh b/trunk/testsuite/cycle2.sh
new file mode 100755
index 0000000..a160a3a
--- /dev/null
+++ b/trunk/testsuite/cycle2.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f cycle2 cycle2lib*.so cycle2.log
+rm -f prelink.cache
+# Test whether prelink doesn't segfault or loop endlessly on
+# bogus library dependency chains
+echo 'int i1;' | $CC -shared -O2 -fpic -o cycle2lib1.so -xc -
+echo 'int i2;' | $CC -shared -O2 -fpic -o cycle2lib2.so -xc - -xnone cycle2lib1.so
+echo 'int i3;' | $CC -shared -O2 -fpic -o cycle2lib3.so -xc - -xnone cycle2lib2.so
+echo 'int i4;' | $CC -shared -O2 -fpic -o cycle2lib4.so -xc - -xnone cycle2lib3.so
+echo 'int i5;' | $CC -shared -O2 -fpic -o cycle2lib5.so -xc - -xnone cycle2lib4.so
+echo 'int i1;' | $CC -shared -O2 -fpic -o cycle2lib1.so -xc - -xnone cycle2lib5.so
+BINS="cycle2"
+LIBS="cycle2lib1.so cycle2lib2.so cycle2lib3.so cycle2lib4.so cycle2lib5.so"
+echo 'int main (void) { return 0; } ' \
+ | $CCLINK -o cycle2 -xc - -xnone -Wl,--rpath-link,. cycle2lib5.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./cycle2 > cycle2.log
+$PRELINK ${PRELINK_OPTS--vm} ./cycle2 >> cycle2.log 2>&1 || exit 1
+grep -v 'has a dependency cycle' cycle2.log \
+ | grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` && exit 2
+grep -q "^`echo $PRELINK | sed 's/ .*$/: .*has a dependency cycle/'`" \
+ cycle2.log || exit 3
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./cycle2 || exit 4
+fi
+# So that it is not prelinked again
+chmod -x ./cycle2
diff --git a/trunk/testsuite/deps1.c b/trunk/testsuite/deps1.c
new file mode 100644
index 0000000..331546c
--- /dev/null
+++ b/trunk/testsuite/deps1.c
@@ -0,0 +1,18 @@
+#include "reloc1.h"
+#include <stdlib.h>
+
+static struct A local = { 77, &local, &bar + 4 };
+
+int main()
+{
+ if (foo.a != 1 || foo.b != &foo || foo.c != &bar || bar != 26)
+ abort ();
+ if (f1 () != 1 || f2 () != 2)
+ abort ();
+ local.c -= 4;
+ if (local.a != 77 || local.b != &local || local.c != &bar)
+ abort ();
+ if (f8 () != 17)
+ abort ();
+ exit (0);
+}
diff --git a/trunk/testsuite/deps1.h b/trunk/testsuite/deps1.h
new file mode 100644
index 0000000..d5868f7
--- /dev/null
+++ b/trunk/testsuite/deps1.h
@@ -0,0 +1,4 @@
+#include "reloc1.h"
+
+extern int f8 (void);
+extern int f9 (void);
diff --git a/trunk/testsuite/deps1.sh b/trunk/testsuite/deps1.sh
new file mode 100755
index 0000000..96395fa
--- /dev/null
+++ b/trunk/testsuite/deps1.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+
+PRELINK=`echo $PRELINK \
+ | sed -e 's, \./\(prelink\.\(cache\|conf\)\), deps1.tree/etc/\1,g' \
+ -e 's,path=\.,path=deps1.tree/lib:deps1.tree/usr/lib:deps1.tree/opt/lib,' \
+ -e 's,linker=\./,linker=deps1.tree/lib/,'`
+CCLINK=`echo $CCLINK \
+ | sed -e 's,linker=\./,linker=deps1.tree/lib/,'`
+rm -rf deps1.tree
+rm -f deps1.log
+mkdir -p deps1.tree/{lib,etc,usr/lib,opt/lib,usr/bin}
+$CC -shared -O2 -fpic -o deps1.tree/usr/lib/lib1.so $srcdir/deps1lib1.c
+$CC -shared -O2 -fpic -o deps1.tree/opt/lib/lib1.so $srcdir/deps1lib1.c
+$CC -shared -O2 -fpic -o deps1.tree/usr/lib/lib2.so $srcdir/deps1lib2.c \
+ -L deps1.tree/opt/lib -Wl,-rpath,deps1.tree/opt/lib -l1
+echo '' | $CC -shared -O2 -fpic -o deps1.tree/usr/lib/lib3.so -xc - -xnone \
+ -L deps1.tree/usr/lib -L deps1.tree/opt/lib -Wl,-rpath,deps1.tree/usr/lib \
+ -l1 -l2
+for lib in `cat syslib.list`; do
+ cp -p $lib.orig deps1.tree/lib/$lib
+ cp -p $lib.orig deps1.tree/lib/$lib.orig
+done
+for lib in `cat syslnk.list`; do
+ cp -dp $lib deps1.tree/lib
+done
+$CCLINK -o deps1.tree/usr/bin/bin1 $srcdir/deps1.c \
+ -Wl,-rpath,deps1.tree/usr/lib -L deps1.tree/usr/lib -l3
+cat > deps1.tree/etc/prelink.conf <<EOF
+deps1.tree/usr/bin
+deps1.tree/lib
+deps1.tree/usr/lib
+deps1.tree/opt/lib
+EOF
+LIBS="deps1.tree/usr/lib/lib1.so deps1.tree/usr/lib/lib2.so"
+LIBS="$LIBS deps1.tree/usr/lib/lib3.so deps1.tree/opt/lib/lib1.so"
+LIBS="$LIBS `sed 's|^|deps1.tree/lib/|' syslib.list`"
+BINS="deps1.tree/usr/bin/bin1"
+savelibs
+chmod 644 `ls $BINS | sed 's|$|.orig|'`
+echo $PRELINK ${PRELINK_OPTS--v} -avvvvv > deps1.log
+$PRELINK ${PRELINK_OPTS--v} -avvvvv > deps1.tree/etc/log1 2>&1 || exit 1
+cat deps1.tree/etc/log1 >> deps1.log
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=deps1.tree/lib deps1.tree/usr/bin/bin1 || exit 2
+fi
+readelf -d deps1.tree/{usr,opt}/lib/lib1.so 2>&1 | grep CHECKSUM >> deps1.log || exit 3
+readelf -A deps1.tree/usr/lib/lib1.so >> deps1.log 2>&1 || exit 4
+readelf -A deps1.tree/opt/lib/lib1.so >> deps1.log 2>&1 || exit 5
+readelf -A deps1.tree/usr/lib/lib2.so >> deps1.log 2>&1 || exit 6
+readelf -A deps1.tree/usr/lib/lib3.so >> deps1.log 2>&1 || exit 7
+readelf -A deps1.tree/usr/bin/bin1 >> deps1.log 2>&1 || exit 8
+LIBS="deps1.tree/usr/lib/lib1.so deps1.tree/usr/lib/lib2.so"
+LIBS="$LIBS deps1.tree/opt/lib/lib1.so"
+readelf -S deps1.tree/usr/lib/lib3.so | grep -q .gnu.prelink_undo \
+ && LIBS="$LIBS deps1.tree/usr/lib/lib3.so"
+readelf -S deps1.tree/usr/bin/bin1 | grep -q .gnu.prelink_undo \
+ || BINS=
+comparelibs >> deps1.log 2>&1 || exit 8
+exit 0
diff --git a/trunk/testsuite/deps1lib1.c b/trunk/testsuite/deps1lib1.c
new file mode 100644
index 0000000..d4ab28b
--- /dev/null
+++ b/trunk/testsuite/deps1lib1.c
@@ -0,0 +1,21 @@
+#include "deps1.h"
+
+int bar = 26;
+int baz = 28;
+
+struct A foo = { 1, &foo, &bar };
+
+int f1 (void)
+{
+ return 1;
+}
+
+int f2 (void)
+{
+ return f1 () + 1;
+}
+
+int f9 (void)
+{
+ return 18;
+}
diff --git a/trunk/testsuite/deps1lib2.c b/trunk/testsuite/deps1lib2.c
new file mode 100644
index 0000000..f73b456
--- /dev/null
+++ b/trunk/testsuite/deps1lib2.c
@@ -0,0 +1,11 @@
+#include "reloc1.h"
+
+int f1 (void)
+{
+ return 11;
+}
+
+int f8 (void)
+{
+ return f9 () - 1;
+}
diff --git a/trunk/testsuite/deps2.sh b/trunk/testsuite/deps2.sh
new file mode 100755
index 0000000..4838f9b
--- /dev/null
+++ b/trunk/testsuite/deps2.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+
+PRELINK=`echo $PRELINK \
+ | sed -e 's, \./\(prelink\.\(cache\|conf\)\), deps2.tree/etc/\1,g' \
+ -e 's,path=\.,path=deps2.tree/lib:deps2.tree/usr/lib:deps2.tree/opt/lib,' \
+ -e 's,linker=\./,linker=deps2.tree/lib/,'`
+CCLINK=`echo $CCLINK \
+ | sed -e 's,linker=\./,linker=deps2.tree/lib/,'`
+rm -rf deps2.tree
+rm -f deps2.log
+mkdir -p deps2.tree/{lib,etc,usr/lib,opt/lib,usr/bin}
+$CC -shared -O2 -fpic -o deps2.tree/usr/lib/lib1.so $srcdir/deps1lib1.c
+$CC -shared -O2 -fpic -o deps2.tree/opt/lib/lib1.so $srcdir/deps2lib1.c
+$CC -shared -O2 -fpic -o deps2.tree/usr/lib/lib2.so $srcdir/deps1lib2.c \
+ -L deps2.tree/opt/lib -Wl,-rpath,deps2.tree/opt/lib -l1
+echo '' | $CC -shared -O2 -fpic -o deps2.tree/usr/lib/lib3.so -xc - -xnone \
+ -L deps2.tree/usr/lib -L deps2.tree/opt/lib -Wl,-rpath,deps2.tree/usr/lib \
+ -l1 -l2
+for lib in `cat syslib.list`; do
+ cp -p $lib.orig deps2.tree/lib/$lib
+ cp -p $lib.orig deps2.tree/lib/$lib.orig
+done
+for lib in `cat syslnk.list`; do
+ cp -dp $lib deps2.tree/lib
+done
+$CCLINK -o deps2.tree/usr/bin/bin1 $srcdir/deps1.c \
+ -Wl,-rpath,deps2.tree/usr/lib -L deps2.tree/usr/lib -l3
+cat > deps2.tree/etc/prelink.conf <<EOF
+deps2.tree/usr/bin
+deps2.tree/lib
+deps2.tree/usr/lib
+deps2.tree/opt/lib
+EOF
+LIBS="deps2.tree/usr/lib/lib1.so deps2.tree/usr/lib/lib2.so"
+LIBS="$LIBS deps2.tree/usr/lib/lib3.so deps2.tree/opt/lib/lib1.so"
+LIBS="$LIBS `sed 's|^|deps2.tree/lib/|' syslib.list`"
+BINS="deps2.tree/usr/bin/bin1"
+savelibs
+chmod 644 `ls $BINS | sed 's|$|.orig|'`
+echo $PRELINK ${PRELINK_OPTS--v} -avvvvv > deps2.log
+$PRELINK ${PRELINK_OPTS--v} -avvvvv > deps2.tree/etc/log1 2>&1 || exit 1
+cat deps2.tree/etc/log1 >> deps2.log
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=deps2.tree/lib deps2.tree/usr/bin/bin1 || exit 2
+fi
+readelf -d deps2.tree/{usr,opt}/lib/lib1.so 2>&1 | grep CHECKSUM >> deps2.log || exit 3
+readelf -A deps2.tree/usr/lib/lib1.so >> deps2.log 2>&1 || exit 4
+readelf -A deps2.tree/opt/lib/lib1.so >> deps2.log 2>&1 || exit 5
+readelf -A deps2.tree/usr/lib/lib2.so >> deps2.log 2>&1 || exit 6
+readelf -A deps2.tree/usr/lib/lib3.so >> deps2.log 2>&1 || exit 7
+readelf -A deps2.tree/usr/bin/bin1 >> deps2.log 2>&1 || exit 8
+LIBS="deps2.tree/usr/lib/lib1.so deps2.tree/usr/lib/lib2.so"
+LIBS="$LIBS deps2.tree/opt/lib/lib1.so"
+BINS=
+comparelibs >> deps2.log 2>&1 || exit 9
+exit 0
diff --git a/trunk/testsuite/deps2lib1.c b/trunk/testsuite/deps2lib1.c
new file mode 100644
index 0000000..9d4b2de
--- /dev/null
+++ b/trunk/testsuite/deps2lib1.c
@@ -0,0 +1,26 @@
+#include "deps1.h"
+
+int bar = 26;
+int baz = 28;
+
+struct A foo = { 1, &foo, &bar };
+
+int f0 (void)
+{
+ return f1 () + f2 () + f9 () + bar + baz;
+}
+
+int f1 (void)
+{
+ return 1;
+}
+
+int f2 (void)
+{
+ return f1 () + 1;
+}
+
+int f9 (void)
+{
+ return 18;
+}
diff --git a/trunk/testsuite/functions.sh b/trunk/testsuite/functions.sh
new file mode 100755
index 0000000..c351fd1
--- /dev/null
+++ b/trunk/testsuite/functions.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+CC="${CC:-gcc} ${LINKOPTS}"
+CCLINK=${CCLINK:-${CC} -Wl,--dynamic-linker=`echo ./ld*.so.*[0-9]`}
+CXX="${CXX:-g++} ${LINKOPTS}"
+CXXLINK=${CXXLINK:-${CXX} -Wl,--dynamic-linker=`echo ./ld*.so.*[0-9]`}
+PRELINK=${PRELINK:-../src/prelink -c ./prelink.conf -C ./prelink.cache --ld-library-path=. --dynamic-linker=`echo ./ld*.so.*[0-9]`}
+LDD=${LDD:-../src/prelink-rtld}
+STRIP=${STRIP:-strip}
+HOST_CC=${HOST_CC:-$CC}
+srcdir=${srcdir:-`dirname $0`}
+savelibs() {
+ for i in $LIBS $BINS; do cp -p $i $i.orig; done
+}
+comparelibs() {
+ for i in $LIBS $BINS; do
+ cp -p $i $i.new
+ echo $PRELINK -u $i.new
+ $PRELINK -u $i.new || exit
+ cmp -s $i.orig $i.new || exit
+ rm -f $i.new
+ echo $PRELINK -y $i \> $i.new
+ $PRELINK -y $i > $i.new || exit
+ cmp -s $i.orig $i.new || exit
+ rm -f $i.new
+ done
+}
diff --git a/trunk/testsuite/layout.C b/trunk/testsuite/layout.C
new file mode 100644
index 0000000..5047a34
--- /dev/null
+++ b/trunk/testsuite/layout.C
@@ -0,0 +1,3 @@
+int main()
+{
+}
diff --git a/trunk/testsuite/layout1.sh b/trunk/testsuite/layout1.sh
new file mode 100755
index 0000000..e217dea
--- /dev/null
+++ b/trunk/testsuite/layout1.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f prelink.cache
+rm -f layout1 layoutlib*.so layout1.log
+i=10
+BINS="layout1"
+LIBS=
+while [ $i -lt 74 ]; do
+ $CXX -shared -fpic -o layout1lib$i.so $srcdir/layoutlib.C
+ LIBS="$LIBS layout1lib$i.so"
+ i=`expr $i + 1`
+done
+$CXXLINK -o layout1 $srcdir/layout.C layout1lib*.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vR} ./layout1 > layout1.log
+$PRELINK ${PRELINK_OPTS--vR} ./layout1 >> layout1.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` layout1.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./layout1 || exit 3
+fi
+readelf -a ./layout1 >> layout1.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./layout1
+comparelibs >> layout1.log 2>&1 || exit 5
diff --git a/trunk/testsuite/layout2.sh b/trunk/testsuite/layout2.sh
new file mode 100755
index 0000000..2307a42
--- /dev/null
+++ b/trunk/testsuite/layout2.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f layout2 layout2lib*.so layout2.log
+i=1
+BINS="layout2"
+LIBS=
+while [ $i -lt 6 ]; do
+ $CXX -shared -fpic -o layout2lib$i.so $srcdir/layoutlib.C
+ LIBS="$LIBS layout2lib$i.so"
+ i=`expr $i + 1`
+done
+$CXXLINK -o layout2 $srcdir/layout.C layout2lib*.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vR} ./layout2 > layout2.log
+$PRELINK ${PRELINK_OPTS--vR} ./layout2 >> layout2.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` layout2.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./layout2 || exit 3
+fi
+readelf -a ./layout2 >> layout2.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./layout2
+comparelibs >> layout2.log 2>&1 || exit 5
diff --git a/trunk/testsuite/layoutlib.C b/trunk/testsuite/layoutlib.C
new file mode 100644
index 0000000..8162515
--- /dev/null
+++ b/trunk/testsuite/layoutlib.C
@@ -0,0 +1,10 @@
+struct A
+ {
+ virtual int a();
+ int b;
+ };
+
+int A::a()
+{
+ return 10;
+}
diff --git a/trunk/testsuite/movelibs.sh b/trunk/testsuite/movelibs.sh
new file mode 100755
index 0000000..010e0e7
--- /dev/null
+++ b/trunk/testsuite/movelibs.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# This script copies needed C and C++ libraries into the test directory
+echo 'int main() { }' > movelibs.C
+$CXX -o movelibs movelibs.C
+> syslib.list
+> syslnk.list
+for i in `RTLD_TRACE_PRELINKING=1 LD_WARN= $LDD ./movelibs \
+ | awk '$1 !~ /^\.\/movelibs/ { print $3 } '`; do
+ k=`basename $i`
+ if [ -L $i ]; then
+ j=`ls -l $i | sed 's/^.* -> //'`
+ if echo $j | grep / >/dev/null 2>&1; then
+ cp -p $i .
+ echo $k >> syslib.list
+ else
+ cp -dp $i .
+ cp -p `dirname $i`/$j .
+ echo $j >> syslib.list
+ echo $k >> syslnk.list
+ fi
+ else
+ cp -p $i .
+ echo $k >> syslib.list
+ fi
+done
+rm -f movelibs.C movelibs
+pwd > prelink.conf
+for i in `cat syslib.list`; do
+ if readelf -WS $i 2>/dev/null | grep -q .gnu.prelink_undo; then
+ $PRELINK -u $i > /dev/null 2>&1 || exit 1
+ fi
+ cp -p $i $i.orig
+done
+exit 77
diff --git a/trunk/testsuite/quick1.c b/trunk/testsuite/quick1.c
new file mode 100644
index 0000000..dc98441
--- /dev/null
+++ b/trunk/testsuite/quick1.c
@@ -0,0 +1,21 @@
+#include "reloc1.h"
+#include <stdlib.h>
+
+static struct A local = { 77, &local, &bar + 4 };
+extern int baz;
+static char *bazp0 = (char *) &baz;
+static char *bazp1 = ((char *) &baz) + 1;
+
+int main()
+{
+ if (foo.a != 1 || foo.b != &foo || foo.c != &bar || bar != 26)
+ abort ();
+ if (f1 () != 11 || f2 () != 12)
+ abort ();
+ local.c -= 4;
+ if (local.a != 77 || local.b != &local || local.c != &bar)
+ abort ();
+ if (bazp1 - bazp0 != 1)
+ abort ();
+ exit (0);
+}
diff --git a/trunk/testsuite/quick1.sh b/trunk/testsuite/quick1.sh
new file mode 100755
index 0000000..f3f80a8
--- /dev/null
+++ b/trunk/testsuite/quick1.sh
@@ -0,0 +1,212 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+check_one() {
+ cnt=0
+ log=$1
+ echo -n . >> quick1.log
+ text="$2"
+ shift 2
+ while [ $# -gt 0 ]; do
+ grep -q "^$text .*$1" $log || exit 40
+ cnt=$((++cnt))
+ shift
+ done
+ [ `grep "^$text " $log | wc -l` = $cnt ] || exit 41
+}
+check_log() {
+ log=$1
+ echo -n "Checking $1 " >> quick1.log
+ check_one $log 'Checking executable' $CHECKE
+ check_one $log 'Checking shared library' $CHECKL
+ check_one $log 'Assuming prelinked' $ASSUME
+ check_one $log 'Prelinking' $PREL
+ echo >> quick1.log
+}
+
+PRELINK=`echo $PRELINK \
+ | sed -e 's, \./\(prelink\.\(cache\|conf\)\), quick1.tree/etc/\1,g' \
+ -e 's,path=\.,path=quick1.tree/lib:quick1.tree/usr/lib,' \
+ -e 's,linker=\./,linker=quick1.tree/lib/,'`
+CCLINK=`echo $CCLINK \
+ | sed -e 's,linker=\./,linker=quick1.tree/lib/,'`
+rm -rf quick1.tree
+rm -f quick1.log
+mkdir -p quick1.tree/{lib,etc,usr/lib,usr/bin}
+$CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib2.so $srcdir/reloc1lib2.c \
+ -L quick1.tree/usr/lib -l1
+$CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib3.so $srcdir/quick1lib1.c
+$CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib2.later.so \
+ $srcdir/quick1lib2.c -L quick1.tree/usr/lib -l1 -l3
+echo 'int foo;' | $CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib4.so -xc -
+$CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib5.so $srcdir/quick1lib3.c \
+ -L quick1.tree/usr/lib -Wl,--rpath-link,quick1.tree/usr/lib -l2
+$CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib6.so $srcdir/quick1lib4.c \
+ -L quick1.tree/usr/lib -Wl,--rpath-link,quick1.tree/usr/lib -l5
+echo 'int baz;' | $CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib7.so -xc - \
+ -L quick1.tree/usr/lib -Wl,--rpath-link,quick1.tree/usr/lib -l6
+echo 'int baz;' | $CC -shared -O2 -fpic -o quick1.tree/usr/lib/lib7.later.so \
+ -xc - -L quick1.tree/usr/lib -Wl,--rpath-link,quick1.tree/usr/lib -l2
+for lib in `cat syslib.list`; do
+ cp -p $lib.orig quick1.tree/lib/$lib
+ cp -p $lib.orig quick1.tree/lib/$lib.orig
+done
+for lib in `cat syslnk.list`; do
+ cp -dp $lib quick1.tree/lib
+done
+$CCLINK -o quick1.tree/usr/bin/bin1 $srcdir/reloc1.c \
+ -Wl,--rpath-link,quick1.tree/usr/lib -L quick1.tree/usr/lib -l2
+echo 'int main () { extern int foo; return foo; }' \
+ | $CCLINK -o quick1.tree/usr/bin/bin2 -xc - -xnone \
+ -L quick1.tree/usr/lib -l4
+$CCLINK -o quick1.tree/usr/bin/bin3 $srcdir/reloc1.c \
+ -Wl,--rpath-link,quick1.tree/usr/lib -L quick1.tree/usr/lib -l7
+$CCLINK -o quick1.tree/usr/bin/bin4 $srcdir/quick1.c \
+ -Wl,--rpath-link,quick1.tree/usr/lib -L quick1.tree/usr/lib -l2
+$CCLINK -o quick1.tree/usr/bin/bin5 $srcdir/quick1.c \
+ -Wl,--rpath-link,quick1.tree/usr/lib -L quick1.tree/usr/lib -l7
+echo 'int main () { return 0; }' \
+ | $CCLINK -o quick1.tree/usr/bin/bin6 -xc - -xnone \
+ -Wl,--rpath-link,quick1.tree/usr/lib -L quick1.tree/usr/lib -l6
+cat > quick1.tree/etc/prelink.conf <<EOF
+quick1.tree/usr/bin
+quick1.tree/lib
+quick1.tree/usr/lib
+EOF
+LIBS="quick1.tree/usr/lib/lib1.so quick1.tree/usr/lib/lib2.so"
+LIBS="$LIBS quick1.tree/usr/lib/lib3.so quick1.tree/usr/lib/lib4.so"
+LIBS="$LIBS quick1.tree/usr/lib/lib5.so quick1.tree/usr/lib/lib6.so"
+LIBS="$LIBS quick1.tree/usr/lib/lib7.so"
+LIBS="$LIBS `sed 's|^|quick1.tree/lib/|' syslib.list`"
+BINS="quick1.tree/usr/bin/bin1 quick1.tree/usr/bin/bin2"
+BINS="$BINS quick1.tree/usr/bin/bin3 quick1.tree/usr/bin/bin4"
+BINS="$BINS quick1.tree/usr/bin/bin5 quick1.tree/usr/bin/bin6"
+savelibs
+chmod 644 `ls $BINS | sed 's|$|.orig|'`
+# Make sure prelinked binaries and libraries will have different ctimes
+# than mtimes
+sleep 3s
+# lib2.later.so needs different timestamps than lib2.so for the tests below
+touch quick1.tree/usr/lib/lib2.later.so
+cp -p quick1.tree/usr/lib/lib2.later.so{,.orig}
+# lib7.later.so needs different timestamps than lib7.so for the tests below
+touch quick1.tree/usr/lib/lib7.later.so
+cp -p quick1.tree/usr/lib/lib7.later.so{,.orig}
+echo $PRELINK ${PRELINK_OPTS--vm} -avvvvv > quick1.log
+$PRELINK ${PRELINK_OPTS--vm} -avvvvv > quick1.tree/etc/log1 2>&1 || exit 1
+cat quick1.tree/etc/log1 >> quick1.log
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick1.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick1.tree/etc/log2 2>&1 || exit 2
+cat quick1.tree/etc/log2 >> quick1.log
+stat quick1.tree/usr/lib/lib2.so >> quick1.log
+echo chmod 644 quick1.tree/usr/lib/lib2.so >> quick1.log
+chmod 644 quick1.tree/usr/lib/lib2.so
+sleep 3s
+echo chmod 755 quick1.tree/usr/lib/lib2.so >> quick1.log
+chmod 755 quick1.tree/usr/lib/lib2.so
+stat quick1.tree/usr/lib/lib2.so >> quick1.log
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick1.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick1.tree/etc/log3 2>&1 || exit 3
+cat quick1.tree/etc/log3 >> quick1.log
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick1.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick1.tree/etc/log4 2>&1 || exit 4
+cat quick1.tree/etc/log4 >> quick1.log
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin1 || exit 5
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin2 || exit 6
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin3 || exit 7
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin4 || exit 8
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin5 || exit 9
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin6 || exit 10
+fi
+readelf -a quick1.tree/usr/bin/bin1 >> quick1.log 2>&1 || exit 11
+readelf -a quick1.tree/usr/bin/bin3 >> quick1.log 2>&1 || exit 12
+readelf -a quick1.tree/usr/bin/bin4 >> quick1.log 2>&1 || exit 13
+readelf -a quick1.tree/usr/bin/bin5 >> quick1.log 2>&1 || exit 14
+readelf -a quick1.tree/usr/bin/bin6 >> quick1.log 2>&1 || exit 15
+BINS="quick1.tree/usr/bin/bin1 quick1.tree/usr/bin/bin3"
+BINS="$BINS quick1.tree/usr/bin/bin4 quick1.tree/usr/bin/bin5"
+BINS="$BINS quick1.tree/usr/bin/bin6"
+LIBS="quick1.tree/usr/lib/lib2.so quick1.tree/usr/lib/lib7.so"
+comparelibs >> quick1.log 2>&1 || exit 16
+for l in 2 7; do
+ mv -f quick1.tree/usr/lib/lib$l.so{,.old}
+ mv -f quick1.tree/usr/lib/lib$l.so{,.old}.orig
+ cp -p quick1.tree/usr/lib/lib$l{.later,}.so
+ cp -p quick1.tree/usr/lib/lib$l{.later,}.so.orig
+done
+for b in 1 3 4 5 6; do
+ cp -p quick1.tree/usr/bin/bin$b{,.old}
+ chmod 644 quick1.tree/usr/bin/bin$b.old
+done
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick1.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick1.tree/etc/log5 2>&1 || exit 17
+cat quick1.tree/etc/log5 >> quick1.log
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin1 || exit 18
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin2 || exit 19
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin3 || exit 20
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin4 || exit 21
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin5 || exit 22
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick1.tree/lib:quick1.tree/usr/lib quick1.tree/usr/bin/bin6 || exit 23
+fi
+readelf -a quick1.tree/usr/bin/bin1 >> quick1.log 2>&1 || exit 24
+readelf -a quick1.tree/usr/bin/bin3 >> quick1.log 2>&1 || exit 25
+readelf -a quick1.tree/usr/bin/bin4 >> quick1.log 2>&1 || exit 26
+readelf -a quick1.tree/usr/bin/bin5 >> quick1.log 2>&1 || exit 27
+readelf -a quick1.tree/usr/bin/bin6 >> quick1.log 2>&1 || exit 28
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` quick1.log && exit 29
+L=quick1.tree/usr/lib/lib
+L1=${L}1.so; L2=${L}2.so; L3=${L}3.so; L4=${L}4.so
+L5=${L}5.so; L6=${L}6.so; L7=${L}7.so
+B=quick1.tree/usr/bin/bin
+B1=${B}1; B2=${B}2; B3=${B}3; B4=${B}4; B5=${B}5; B6=${B}6
+SL=`grep -f syslib.list quick1.tree/etc/log1 \
+ | sed -n '/^Prelinking/s|^.*\(quick1.tree/lib/\)|\1|p'`
+CHECKE="$B1 $B2 $B3 $B4 $B5 $B6"; CHECKL="$SL $L1 $L2 $L4 $L5 $L6 $L7" PREL="$CHECKE $CHECKL"; ASSUME=""
+check_log quick1.tree/etc/log1
+CHECKE=""; CHECKL=""; PREL=""; ASSUME="$B1 $B2 $B3 $B4 $B5 $B6 $SL $L1 $L2 $L4 $L5 $L6 $L7"
+check_log quick1.tree/etc/log2
+CHECKE="$B1 $B3 $B4 $B5 $B6"; CHECKL="$SL $L1 $L2 $L5 $L6 $L7"; PREL=""; ASSUME="$B2 $L4"
+check_log quick1.tree/etc/log3
+CHECKE=""; CHECKL=""; PREL=""; ASSUME="$B1 $B2 $B3 $B4 $B5 $B6 $SL $L1 $L2 $L4 $L5 $L6 $L7"
+check_log quick1.tree/etc/log4
+CHECKE="$B1 $B3 $B4 $B5 $B6"; CHECKL="$SL $L1 $L2 $L3 $L5 $L7 $L7"; PREL="$B1 $B3 $B4 $B5 $B6 $L2 $L3 $L5 $L6 $L7"; ASSUME="$B2 $L4"
+check_log quick1.tree/etc/log5
+BINS="$B1 $B2 $B3 $B4 $B5 $B6"
+LIBS="$SL $L1 $L2 $L3 $L4 $L5 $L6 $L7 $L2.old"
+comparelibs >> quick1.log 2>&1 || exit 30
+for i in $BINS $SL $L1 $L2 $L3 $L4 $L5 $L6 $L7; do
+ cp -p $i $i.prelinked
+done
+for i in $BINS; do
+ chmod 644 $i.prelinked
+done
+echo $PRELINK -uavvvvvv >> quick1.log
+$PRELINK -uavvvvvv >> quick1.log 2>&1 || exit 31
+for i in $BINS $SL $L1 $L2 $L3 $L4 $L5 $L6 $L7; do
+ cmp -s $i.orig $i || exit 32
+ mv -f $i.prelinked $i
+done
+chmod 755 $BINS
+exit 0
diff --git a/trunk/testsuite/quick1lib1.c b/trunk/testsuite/quick1lib1.c
new file mode 100644
index 0000000..41767ce
--- /dev/null
+++ b/trunk/testsuite/quick1lib1.c
@@ -0,0 +1,9 @@
+int q1 (void)
+{
+ return q2 () + 1;
+}
+
+int q2 (void)
+{
+ return 77;
+}
diff --git a/trunk/testsuite/quick1lib2.c b/trunk/testsuite/quick1lib2.c
new file mode 100644
index 0000000..b545086
--- /dev/null
+++ b/trunk/testsuite/quick1lib2.c
@@ -0,0 +1,11 @@
+extern int q1 (void);
+
+int f1 (void)
+{
+ return q1 () + 1;
+}
+
+int q2 (void)
+{
+ return 9;
+}
diff --git a/trunk/testsuite/quick1lib3.c b/trunk/testsuite/quick1lib3.c
new file mode 100644
index 0000000..06760a3
--- /dev/null
+++ b/trunk/testsuite/quick1lib3.c
@@ -0,0 +1,7 @@
+#ifndef D1
+#define D1(n) int qvar##n; int *qpvar##n = &qvar##n;
+#endif
+#define D2(n) D1(n##0) D1(n##1) D1(n##2) D1(n##3) D1(n##4)
+#define D3(n) D2(n##0) D2(n##1) D2(n##2) D2(n##3) D2(n##4)
+#define D4(n) D3(n##0) D3(n##1) D3(n##2) D3(n##3) D3(n##4)
+D4(0) D4(1)
diff --git a/trunk/testsuite/quick1lib4.c b/trunk/testsuite/quick1lib4.c
new file mode 100644
index 0000000..53e23d7
--- /dev/null
+++ b/trunk/testsuite/quick1lib4.c
@@ -0,0 +1,2 @@
+#define D1(n) int qvar##n;
+#include "quick1lib3.c"
diff --git a/trunk/testsuite/quick2.sh b/trunk/testsuite/quick2.sh
new file mode 100755
index 0000000..87138ae
--- /dev/null
+++ b/trunk/testsuite/quick2.sh
@@ -0,0 +1,288 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+check_one() {
+ cnt=0
+ log=$1
+ echo -n . >> quick2.log
+ text="$2"
+ shift 2
+ while [ $# -gt 0 ]; do
+ grep -q "^$text .*$1" $log || exit 40
+ cnt=$((++cnt))
+ shift
+ done
+ [ `grep "^$text " $log | wc -l` = $cnt ] || exit 41
+}
+check_log() {
+ log=$1
+ echo -n "Checking $1 " >> quick2.log
+ check_one $log 'Checking executable' $CHECKE
+ check_one $log 'Checking shared library' $CHECKL
+ check_one $log 'Assuming prelinked' $ASSUME
+ check_one $log 'Prelinking' $PREL
+ check_one $log 'Assuming non-prelinkable' $UNPREL
+ echo >> quick2.log
+}
+
+PRELINK=`echo $PRELINK \
+ | sed -e 's, \./\(prelink\.\(cache\|conf\)\), quick2.tree/etc/\1,g' \
+ -e 's,path=\.,path=quick2.tree/lib:quick2.tree/usr/lib,' \
+ -e 's,linker=\./,linker=quick2.tree/lib/,'`
+CCLINK=`echo $CCLINK \
+ | sed -e 's,linker=\./,linker=quick2.tree/lib/,'`
+rm -rf quick2.tree
+rm -f quick2.log
+mkdir -p quick2.tree/{lib,etc,usr/lib,usr/bin}
+$CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib2.so $srcdir/reloc1lib2.c \
+ -L quick2.tree/usr/lib -l1
+$CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib3.so $srcdir/quick1lib1.c
+$CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib2.later.so \
+ $srcdir/quick1lib2.c -L quick2.tree/usr/lib -l1 -l3
+echo 'int foo;' | $CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib4.so -xc -
+$CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib5.so $srcdir/quick1lib3.c \
+ -L quick2.tree/usr/lib -Wl,--rpath-link,quick2.tree/usr/lib -l2
+$CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib6.so $srcdir/quick1lib4.c \
+ -L quick2.tree/usr/lib -Wl,--rpath-link,quick2.tree/usr/lib -l5
+echo 'int baz;' | $CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib7.so -xc - \
+ -L quick2.tree/usr/lib -Wl,--rpath-link,quick2.tree/usr/lib -l6 \
+ -Wl,--spare-dynamic-tags=0
+echo 'int baz;' | $CC -shared -O2 -fpic -o quick2.tree/usr/lib/lib7.later.so \
+ -xc - -L quick2.tree/usr/lib -Wl,--rpath-link,quick2.tree/usr/lib -l2
+for lib in `cat syslib.list`; do
+ cp -p $lib.orig quick2.tree/lib/$lib
+ cp -p $lib.orig quick2.tree/lib/$lib.orig
+done
+for lib in `cat syslnk.list`; do
+ cp -dp $lib quick2.tree/lib
+done
+$CCLINK -o quick2.tree/usr/bin/bin1 $srcdir/reloc1.c \
+ -Wl,--rpath-link,quick2.tree/usr/lib -L quick2.tree/usr/lib -l2
+echo 'int main () { extern int foo; return foo; }' \
+ | $CCLINK -o quick2.tree/usr/bin/bin2 -xc - -xnone \
+ -L quick2.tree/usr/lib -l4
+$CCLINK -o quick2.tree/usr/bin/bin3 $srcdir/reloc1.c \
+ -Wl,--rpath-link,quick2.tree/usr/lib -L quick2.tree/usr/lib -l7
+$CCLINK -o quick2.tree/usr/bin/bin4 $srcdir/quick1.c \
+ -Wl,--rpath-link,quick2.tree/usr/lib -L quick2.tree/usr/lib -l2
+$CCLINK -o quick2.tree/usr/bin/bin5 $srcdir/quick1.c \
+ -Wl,--rpath-link,quick2.tree/usr/lib -L quick2.tree/usr/lib -l7
+echo 'int main () { return 0; }' \
+ | $CCLINK -o quick2.tree/usr/bin/bin6 -xc - -xnone \
+ -Wl,--rpath-link,quick2.tree/usr/lib -L quick2.tree/usr/lib -l6
+echo 'int main () { return 0; }' \
+ | $CCLINK -o quick2.tree/usr/bin/bin7 -static -xc - -xnone
+cat > quick2.tree/usr/bin/bin8 <<EOF
+#!/bin/sh
+echo This is a sample shell script
+echo used to test whether even shell scripts
+echo and other executable non-ELF files
+echo are cached as non-prelinkable
+echo in /etc/prelink.cache and thus do not
+echo need to be reread every time prelink -aq
+echo is run.
+exit 0
+EOF
+chmod 755 quick2.tree/usr/bin/bin8
+cat > quick2.tree/usr/bin/bin9.sh <<EOF
+#!/bin/sh
+echo This is another sample shell script,
+echo this time with a .sh extension.
+echo This does not need to be even cached
+echo as non-prelinkable, provided -b *.sh
+echo is present in prelink.conf.
+exit 0
+EOF
+chmod 755 quick2.tree/usr/bin/bin9.sh
+cat > quick2.tree/usr/bin/bin10.py <<EOF
+#! /usr/bin/env python
+print "This is a sample python script."
+print "This does not need to be even cached"
+print "as non-prelinkable, provided -b *.py"
+print "is present in prelink.conf."
+EOF
+chmod 755 quick2.tree/usr/bin/bin10.py
+cat > quick2.tree/usr/bin/bin11.script <<EOF
+#!/bin/sh
+echo This is another sample shell script,
+echo this time matching b*11*r[hijk]*t shell pattern.
+echo This does not need to be even cached
+echo as non-prelinkable, provided -b b*11*r[hijk]*t
+echo is present in prelink.conf.
+exit 0
+EOF
+chmod 755 quick2.tree/usr/bin/bin11.script
+if [ `$CC -dumpmachine | sed "s/-.*-.*-.*//"` = "arm" ]; then
+ cat > quick2.tree/usr/bin/bin12 << EOF
+#!/bin/sh
+echo -pie -fPIE is not supported on our ARM architectures
+echo this script will serve to disable that part of the test.
+exit 0
+EOF
+chmod 0755 quick2.tree/usr/bin/bin12
+else
+ echo 'int main () { return 0; }' \
+ | $CCLINK -o quick2.tree/usr/bin/bin12 -pie -fPIE -xc - -xnone
+fi
+cat > quick2.tree/etc/prelink.conf <<EOF
+-b *.sh
+-b *.py
+-b b*11*r[hijk]*t
+quick2.tree/usr/bin
+quick2.tree/lib
+quick2.tree/usr/lib
+EOF
+LIBS="quick2.tree/usr/lib/lib1.so quick2.tree/usr/lib/lib2.so"
+LIBS="$LIBS quick2.tree/usr/lib/lib3.so quick2.tree/usr/lib/lib4.so"
+LIBS="$LIBS quick2.tree/usr/lib/lib5.so quick2.tree/usr/lib/lib6.so"
+LIBS="$LIBS quick2.tree/usr/lib/lib7.so"
+LIBS="$LIBS `sed 's|^|quick2.tree/lib/|' syslib.list`"
+BINS="quick2.tree/usr/bin/bin1 quick2.tree/usr/bin/bin2"
+BINS="$BINS quick2.tree/usr/bin/bin3 quick2.tree/usr/bin/bin4"
+BINS="$BINS quick2.tree/usr/bin/bin5 quick2.tree/usr/bin/bin6"
+BINS="$BINS quick2.tree/usr/bin/bin7 quick2.tree/usr/bin/bin8"
+savelibs
+chmod 644 `ls $BINS | sed 's|$|.orig|'`
+# Make sure prelinked binaries and libraries will have different ctimes
+# than mtimes
+sleep 3s
+# lib2.later.so needs different timestamps than lib2.so for the tests below
+touch quick2.tree/usr/lib/lib2.later.so
+cp -p quick2.tree/usr/lib/lib2.later.so{,.orig}
+# lib7.later.so needs different timestamps than lib7.so for the tests below
+touch quick2.tree/usr/lib/lib7.later.so
+cp -p quick2.tree/usr/lib/lib7.later.so{,.orig}
+echo $PRELINK ${PRELINK_OPTS--vm} -avvvvv > quick2.log
+$PRELINK ${PRELINK_OPTS--vm} -avvvvv > quick2.tree/etc/log1 2>&1 || exit 1
+cat quick2.tree/etc/log1 >> quick2.log
+grep -q 'lib7.so: Not enough room to add .dynamic entry' \
+ quick2.tree/etc/log1 || exit 60
+grep -q 'Could not prelink .*bin3 because its dependency .*lib7.so could not be prelinked' \
+ quick2.tree/etc/log1 || exit 61
+grep -q 'Could not prelink .*bin5 because its dependency .*lib7.so could not be prelinked' \
+ quick2.tree/etc/log1 || exit 62
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick2.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick2.tree/etc/log2 2>&1 || exit 2
+cat quick2.tree/etc/log2 >> quick2.log
+stat quick2.tree/usr/lib/lib2.so >> quick2.log
+echo chmod 644 quick2.tree/usr/lib/lib2.so >> quick2.log
+chmod 644 quick2.tree/usr/lib/lib2.so
+sleep 3s
+echo chmod 755 quick2.tree/usr/lib/lib2.so >> quick2.log
+chmod 755 quick2.tree/usr/lib/lib2.so
+stat quick2.tree/usr/lib/lib2.so >> quick2.log
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick2.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick2.tree/etc/log3 2>&1 || exit 3
+cat quick2.tree/etc/log3 >> quick2.log
+grep -q 'lib7.so: Not enough room to add .dynamic entry' \
+ quick2.tree/etc/log3 || exit 63
+grep -q 'Could not prelink .*bin3 because its dependency .*lib7.so could not be prelinked' \
+ quick2.tree/etc/log3 || exit 64
+grep -q 'Could not prelink .*bin5 because its dependency .*lib7.so could not be prelinked' \
+ quick2.tree/etc/log3 || exit 65
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick2.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick2.tree/etc/log4 2>&1 || exit 4
+cat quick2.tree/etc/log4 >> quick2.log
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin1 || exit 5
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin2 || exit 6
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin3 || exit 7
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin4 || exit 8
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin5 || exit 9
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin6 || exit 10
+fi
+readelf -a quick2.tree/usr/bin/bin1 >> quick2.log 2>&1 || exit 11
+readelf -a quick2.tree/usr/bin/bin3 >> quick2.log 2>&1 || exit 12
+readelf -a quick2.tree/usr/bin/bin4 >> quick2.log 2>&1 || exit 13
+readelf -a quick2.tree/usr/bin/bin5 >> quick2.log 2>&1 || exit 14
+readelf -a quick2.tree/usr/bin/bin6 >> quick2.log 2>&1 || exit 15
+BINS="quick2.tree/usr/bin/bin1 quick2.tree/usr/bin/bin4"
+BINS="$BINS quick2.tree/usr/bin/bin6"
+LIBS="quick2.tree/usr/lib/lib2.so"
+comparelibs >> quick2.log 2>&1 || exit 16
+for l in 2 7; do
+ mv -f quick2.tree/usr/lib/lib$l.so{,.old}
+ mv -f quick2.tree/usr/lib/lib$l.so{,.old}.orig
+ cp -p quick2.tree/usr/lib/lib$l{.later,}.so
+ cp -p quick2.tree/usr/lib/lib$l{.later,}.so.orig
+done
+for b in 1 3 4 5 6; do
+ cp -p quick2.tree/usr/bin/bin$b{,.old}
+ chmod 644 quick2.tree/usr/bin/bin$b.old
+done
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick2.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick2.tree/etc/log5 2>&1 || exit 17
+cat quick2.tree/etc/log5 >> quick2.log
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin1 || exit 18
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin2 || exit 19
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin3 || exit 20
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin4 || exit 21
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin5 || exit 22
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick2.tree/lib:quick2.tree/usr/lib quick2.tree/usr/bin/bin6 || exit 23
+fi
+readelf -a quick2.tree/usr/bin/bin1 >> quick2.log 2>&1 || exit 24
+readelf -a quick2.tree/usr/bin/bin3 >> quick2.log 2>&1 || exit 25
+readelf -a quick2.tree/usr/bin/bin4 >> quick2.log 2>&1 || exit 26
+readelf -a quick2.tree/usr/bin/bin5 >> quick2.log 2>&1 || exit 27
+readelf -a quick2.tree/usr/bin/bin6 >> quick2.log 2>&1 || exit 28
+# In both etc/log1 and etc/log3 there should be one
+# "Not enough room" and two "Could not prelink" warnings.
+[ $(grep ^`echo $PRELINK | sed 's/ .*$/: /'` quick2.log | wc -l) -eq 6 ] || exit 29
+L=quick2.tree/usr/lib/lib
+L1=${L}1.so; L2=${L}2.so; L3=${L}3.so; L4=${L}4.so
+L5=${L}5.so; L6=${L}6.so; L7=${L}7.so
+B=quick2.tree/usr/bin/bin
+B1=${B}1; B2=${B}2; B3=${B}3; B4=${B}4; B5=${B}5
+B6=${B}6; B7=${B}7; B8=${B}8; B12=${B}12
+SL=`grep -f syslib.list quick2.tree/etc/log1 \
+ | sed -n '/^Prelinking/s|^.*\(quick2.tree/lib/\)|\1|p'`
+CHECK_E="$B1 $B2 $B4 $B6"; CHECKE="$CHECK_E $B3 $B5 $B7"
+CHECKL="$SL $L1 $L2 $L4 $L5 $L6 $L7"; PREL="$CHECK_E $CHECKL"; ASSUME=""; UNPREL=""
+check_log quick2.tree/etc/log1
+CHECKE=""; CHECKL=""; PREL=""; ASSUME="$B1 $B2 $B4 $B6 $SL $L1 $L2 $L4 $L5 $L6"
+UNPREL="$B3 $B5 $B7 $B8 $B12 $L7"
+check_log quick2.tree/etc/log2
+CHECKE="$B1 $B3 $B4 $B5 $B6"; CHECKL="$SL $L1 $L2 $L5 $L6 $L7"; PREL="$L7"; ASSUME="$B2 $L4"; UNPREL="$B7 $B8 $B12"
+check_log quick2.tree/etc/log3
+CHECKE=""; CHECKL=""; PREL=""; ASSUME="$B1 $B2 $B4 $B6 $SL $L1 $L2 $L4 $L5 $L6"; UNPREL="$B3 $B5 $B7 $B8 $B12 $L7"
+check_log quick2.tree/etc/log4
+CHECKE="$B1 $B3 $B4 $B5 $B6"; CHECKL="$SL $L1 $L2 $L3 $L5 $L7 $L7"; PREL="$B1 $B3 $B4 $B5 $B6 $L2 $L3 $L5 $L6 $L7"; ASSUME="$B2 $L4"; UNPREL="$B7 $B8 $B12"
+check_log quick2.tree/etc/log5
+BINS="$B1 $B2 $B3 $B4 $B5 $B6"
+LIBS="$SL $L1 $L2 $L3 $L4 $L5 $L6 $L7 $L2.old"
+comparelibs >> quick2.log 2>&1 || exit 30
+for i in $BINS $SL $L1 $L2 $L3 $L4 $L5 $L6 $L7; do
+ cp -p $i $i.prelinked
+done
+for i in $BINS; do
+ chmod 644 $i.prelinked
+done
+echo $PRELINK -uavvvvvv >> quick2.log
+$PRELINK -uavvvvvv >> quick2.log 2>&1 || exit 31
+for i in $BINS $SL $L1 $L2 $L3 $L4 $L5 $L6 $L7; do
+ cmp -s $i.orig $i || exit 32
+ mv -f $i.prelinked $i
+done
+chmod 755 $BINS
+exit 0
diff --git a/trunk/testsuite/quick3.sh b/trunk/testsuite/quick3.sh
new file mode 100755
index 0000000..0562e52
--- /dev/null
+++ b/trunk/testsuite/quick3.sh
@@ -0,0 +1,110 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+check_one() {
+ cnt=0
+ log=$1
+ echo -n . >> quick3.log
+ text="$2"
+ shift 2
+ while [ $# -gt 0 ]; do
+ grep -q "^$text .*$1" $log || exit 40
+ cnt=$((++cnt))
+ shift
+ done
+ [ `grep "^$text " $log | wc -l` = $cnt ] || exit 41
+}
+check_log() {
+ log=$1
+ echo -n "Checking $1 " >> quick3.log
+ check_one $log 'Checking executable' $CHECKE
+ check_one $log 'Checking shared library' $CHECKL
+ check_one $log 'Assuming prelinked' $ASSUME
+ check_one $log 'Prelinking' $PREL
+ echo >> quick3.log
+}
+
+PRELINK=`echo $PRELINK \
+ | sed -e 's, \./\(prelink\.\(cache\|conf\)\), quick3.tree/etc/\1,g' \
+ -e 's,path=\.,path=quick3.tree/lib:quick3.tree/usr/lib,' \
+ -e 's,linker=\./,linker=quick3.tree/lib/,'`
+CCLINK=`echo $CCLINK \
+ | sed -e 's,linker=\./,linker=quick3.tree/lib/,'`
+rm -rf quick3.tree
+rm -f quick3.log
+mkdir -p quick3.tree/{lib,etc,usr/lib,usr/bin}
+$CC -shared -O2 -fpic -o quick3.tree/usr/lib/lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o quick3.tree/usr/lib/lib2.so $srcdir/reloc1lib2.c \
+ -L quick3.tree/usr/lib -l1 -Wl,-soname,lib2.so
+for lib in `cat syslib.list`; do
+ cp -p $lib.orig quick3.tree/lib/$lib
+ cp -p $lib.orig quick3.tree/lib/$lib.orig
+done
+for lib in `cat syslnk.list`; do
+ cp -dp $lib quick3.tree/lib
+done
+$CCLINK -o quick3.tree/usr/bin/bin1 $srcdir/reloc1.c \
+ -Wl,--rpath-link,quick3.tree/usr/lib -L quick3.tree/usr/lib -l2
+cat > quick3.tree/etc/prelink.conf <<EOF
+quick3.tree/usr/bin
+quick3.tree/lib
+quick3.tree/usr/lib
+EOF
+LIBS="quick3.tree/usr/lib/lib1.so quick3.tree/usr/lib/lib2.so"
+LIBS="$LIBS `sed 's|^|quick3.tree/lib/|' syslib.list`"
+BINS="quick3.tree/usr/bin/bin1"
+savelibs
+chmod 644 `ls $BINS | sed 's|$|.orig|'`
+# Make sure prelinked binaries and libraries will have different ctimes
+# than mtimes
+sleep 3s
+echo $PRELINK ${PRELINK_OPTS--vm} -avvvvv > quick3.log
+$PRELINK ${PRELINK_OPTS--vm} -avvvvv > quick3.tree/etc/log1 2>&1 || exit 1
+cat quick3.tree/etc/log1 >> quick3.log
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick3.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick3.tree/etc/log2 2>&1 || exit 2
+cat quick3.tree/etc/log2 >> quick3.log
+$CC -shared -O2 -fpic -o quick3.tree/usr/lib/lib2.so.0 $srcdir/reloc1lib2.c \
+ -L quick3.tree/usr/lib -l1 -Wl,-soname,lib2.so
+rm -f quick3.tree/usr/lib/lib2.so{,.orig}
+cp -p quick3.tree/usr/lib/lib2.so.0{,.orig}
+ln -sf lib2.so.0 quick3.tree/usr/lib/lib2.so
+sleep 3s
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick3.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick3.tree/etc/log3 2>&1 || exit 3
+cat quick3.tree/etc/log3 >> quick3.log
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=quick3.tree/lib:quick3.tree/usr/lib quick3.tree/usr/bin/bin1 || exit 4
+fi
+LIBS="quick3.tree/usr/lib/lib1.so quick3.tree/usr/lib/lib2.so.0"
+echo $PRELINK ${PRELINK_OPTS--vm} -aqvvvvv >> quick3.log
+$PRELINK ${PRELINK_OPTS--vm} -aqvvvvv > quick3.tree/etc/log4 2>&1 || exit 5
+cat quick3.tree/etc/log4 >> quick3.log
+comparelibs >> quick3.log 2>&1 || exit 6
+[ -L quick3.tree/usr/lib/lib2.so ] || exit 7
+L=quick3.tree/usr/lib/lib
+L1=${L}1.so; L2=${L}2.so; L3=${L}2.so.0
+B1=quick3.tree/usr/bin/bin1
+SL=`grep -f syslib.list quick3.tree/etc/log1 \
+ | sed -n '/^Prelinking/s|^.*\(quick3.tree/lib/\)|\1|p'`
+CHECKE="$B1"; CHECKL="$SL $L1 $L2" PREL="$CHECKE $CHECKL"; ASSUME=""
+check_log quick3.tree/etc/log1
+CHECKE=""; CHECKL=""; PREL=""; ASSUME="$B1 $L1 $L2 $SL"
+check_log quick3.tree/etc/log2
+CHECKE="$B1"; CHECKL="$SL $L1 $L3"; PREL="$B1 $L3"; ASSUME=""
+check_log quick3.tree/etc/log3
+CHECKE=""; CHECKL=""; PREL=""; ASSUME="$B1 $L1 $L3 $SL"
+check_log quick3.tree/etc/log4
+for i in $B1 $SL $L1 $L3; do
+ cp -p $i $i.prelinked
+done
+for i in $B1; do
+ chmod 644 $i.prelinked
+done
+echo $PRELINK -uavvvvvv >> quick3.log
+$PRELINK -uavvvvvv >> quick3.log 2>&1 || exit 31
+for i in $B1 $SL $L1 $L3; do
+ cmp -s $i.orig $i || exit 32
+ mv -f $i.prelinked $i
+done
+chmod 755 $BINS
+exit 0
diff --git a/trunk/testsuite/reloc1.c b/trunk/testsuite/reloc1.c
new file mode 100644
index 0000000..e679bed
--- /dev/null
+++ b/trunk/testsuite/reloc1.c
@@ -0,0 +1,16 @@
+#include "reloc1.h"
+#include <stdlib.h>
+
+static struct A local = { 77, &local, &bar + 4 };
+
+int main()
+{
+ if (foo.a != 1 || foo.b != &foo || foo.c != &bar || bar != 26)
+ abort ();
+ if (f1 () != 11 || f2 () != 12)
+ abort ();
+ local.c -= 4;
+ if (local.a != 77 || local.b != &local || local.c != &bar)
+ abort ();
+ exit (0);
+}
diff --git a/trunk/testsuite/reloc1.h b/trunk/testsuite/reloc1.h
new file mode 100644
index 0000000..093dd3a
--- /dev/null
+++ b/trunk/testsuite/reloc1.h
@@ -0,0 +1,12 @@
+struct A
+ {
+ char a;
+ struct A *b;
+ int *c;
+ };
+
+extern struct A foo;
+extern int bar;
+extern int f1 (void);
+extern int f2 (void);
+extern struct A *f3 (void);
diff --git a/trunk/testsuite/reloc1.sh b/trunk/testsuite/reloc1.sh
new file mode 100755
index 0000000..ade05c9
--- /dev/null
+++ b/trunk/testsuite/reloc1.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f reloc1 reloc1lib*.so reloc1.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o reloc1lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o reloc1lib2.so $srcdir/reloc1lib2.c reloc1lib1.so
+BINS="reloc1"
+LIBS="reloc1lib1.so reloc1lib2.so"
+$CCLINK -o reloc1 $srcdir/reloc1.c -Wl,--rpath-link,. reloc1lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc1 > reloc1.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc1 >> reloc1.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc1.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc1 || exit 3
+fi
+readelf -a ./reloc1 >> reloc1.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc1
+comparelibs >> reloc1.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc10.c b/trunk/testsuite/reloc10.c
new file mode 100644
index 0000000..5720d33
--- /dev/null
+++ b/trunk/testsuite/reloc10.c
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+
+extern int bar, baz, *barp, *bazp, dummy;
+extern int f1 (void), f2 (void), f3 (void), f4 (void);
+/* Try to use COPY reloc for bar and get away without COPY
+ reloc for baz. Similarly for barp and bazp. */
+int *bazp2 = &baz;
+int **bazp3 = &bazp;
+
+int main (void)
+{
+ if (f1 () != 11 || f2 () != 12 || bar != 36 || *bazp2 != 38)
+ abort ();
+ if (f3 () != 14 || f4 () != 16 || *barp != 36 || **bazp3 != 38)
+ abort ();
+ if (dummy != 24)
+ abort ();
+ exit (0);
+}
diff --git a/trunk/testsuite/reloc10.sh b/trunk/testsuite/reloc10.sh
new file mode 100755
index 0000000..66dd438
--- /dev/null
+++ b/trunk/testsuite/reloc10.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f reloc10 reloc10lib*.so reloc10.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o reloc10lib1.so $srcdir/reloc10lib1.c
+$CC -shared -O2 -nostdlib -fpic -o reloc10lib2.so $srcdir/reloc10lib2.c reloc10lib1.so
+$CC -shared -O2 -nostdlib -fpic -o reloc10lib3.so $srcdir/reloc10lib3.c reloc10lib1.so
+$CC -shared -O2 -nostdlib -fpic -o reloc10lib4.so $srcdir/reloc10lib4.c reloc10lib1.so
+$CC -shared -O2 -fpic -o reloc10lib5.so $srcdir/reloc10lib5.c reloc10lib2.so reloc10lib3.so reloc10lib4.so
+BINS="reloc10"
+LIBS="reloc10lib1.so reloc10lib2.so reloc10lib3.so reloc10lib4.so reloc10lib5.so"
+$CCLINK -o reloc10 $srcdir/reloc10.c -Wl,--rpath-link,. reloc10lib5.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc10 > reloc10.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc10 >> reloc10.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc10.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc10 || exit 3
+fi
+readelf -a ./reloc10 >> reloc10.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc10
+comparelibs >> reloc10.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc10lib1.c b/trunk/testsuite/reloc10lib1.c
new file mode 100644
index 0000000..2ee06d2
--- /dev/null
+++ b/trunk/testsuite/reloc10lib1.c
@@ -0,0 +1,12 @@
+int bar = 26;
+int baz = 28;
+
+int f1 (void)
+{
+ return 1;
+}
+
+int f2 (void)
+{
+ return 2;
+}
diff --git a/trunk/testsuite/reloc10lib2.c b/trunk/testsuite/reloc10lib2.c
new file mode 100644
index 0000000..fc327fc
--- /dev/null
+++ b/trunk/testsuite/reloc10lib2.c
@@ -0,0 +1,11 @@
+extern int bar, baz, f1 (void), f2 (void);
+
+int f3 (void)
+{
+ return f1 () + 3;
+}
+
+int f4 (void)
+{
+ return f2 () + 4;
+}
diff --git a/trunk/testsuite/reloc10lib3.c b/trunk/testsuite/reloc10lib3.c
new file mode 100644
index 0000000..2ec80ab
--- /dev/null
+++ b/trunk/testsuite/reloc10lib3.c
@@ -0,0 +1,3 @@
+extern int bar, baz, f1 (void), f2 (void);
+
+int *barp = &bar, *bazp = &baz;
diff --git a/trunk/testsuite/reloc10lib4.c b/trunk/testsuite/reloc10lib4.c
new file mode 100644
index 0000000..4376249
--- /dev/null
+++ b/trunk/testsuite/reloc10lib4.c
@@ -0,0 +1 @@
+int dummy = 24;
diff --git a/trunk/testsuite/reloc10lib5.c b/trunk/testsuite/reloc10lib5.c
new file mode 100644
index 0000000..19fd925
--- /dev/null
+++ b/trunk/testsuite/reloc10lib5.c
@@ -0,0 +1,12 @@
+int bar = 36;
+int baz = 38;
+
+int f1 (void)
+{
+ return 11;
+}
+
+int f2 (void)
+{
+ return 12;
+}
diff --git a/trunk/testsuite/reloc11.c b/trunk/testsuite/reloc11.c
new file mode 100644
index 0000000..923aff4
--- /dev/null
+++ b/trunk/testsuite/reloc11.c
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+
+extern int dummy;
+extern int var, var2, varp1 (), var2m1 (), bar ();
+int *pvar = &var, *pvar2 = &var2;
+
+int main (void)
+{
+ if (dummy != 24)
+ abort ();
+ if (*pvar != 32 || *pvar2 != 16)
+ abort ();
+ if (varp1 () != 33 || var2m1 () != 6 || bar () != 40)
+ abort ();
+ exit (0);
+}
diff --git a/trunk/testsuite/reloc11.sh b/trunk/testsuite/reloc11.sh
new file mode 100755
index 0000000..ab0cbee
--- /dev/null
+++ b/trunk/testsuite/reloc11.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f reloc11 reloc11lib*.so reloc11.log
+rm -f prelink.cache
+$CC -shared -O2 -nostdlib -fpic -o reloc11lib1.so $srcdir/reloc10lib4.c
+$CC -shared -O2 -nostdlib -fpic -o reloc11lib2.so $srcdir/reloc11lib2.c
+$CC -shared -O2 -nostdlib -fpic -o reloc11lib3.so $srcdir/reloc11lib3.c reloc11lib2.so
+BINS="reloc11"
+LIBS="reloc11lib1.so reloc11lib2.so reloc11lib3.so"
+$CCLINK -o reloc11 $srcdir/reloc11.c -Wl,--rpath-link,. reloc11lib1.so reloc11lib3.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc11 > reloc11.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc11 >> reloc11.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc11.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc11 || exit 3
+fi
+readelf -a ./reloc11 >> reloc11.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc11
+comparelibs >> reloc11.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc11lib2.c b/trunk/testsuite/reloc11lib2.c
new file mode 100644
index 0000000..6a2191c
--- /dev/null
+++ b/trunk/testsuite/reloc11lib2.c
@@ -0,0 +1,16 @@
+int var = 24, var2 = 16;
+
+int varp1 (void)
+{
+ return var + 1;
+}
+
+int var2m1 (void)
+{
+ return var2 - 1;
+}
+
+int bar (void)
+{
+ return varp1 () + var2m1 () + 1;
+}
diff --git a/trunk/testsuite/reloc11lib3.c b/trunk/testsuite/reloc11lib3.c
new file mode 100644
index 0000000..0cea7f3
--- /dev/null
+++ b/trunk/testsuite/reloc11lib3.c
@@ -0,0 +1,7 @@
+int var = 32;
+extern int var2;
+
+int var2m1 (void)
+{
+ return var2 - 10;
+}
diff --git a/trunk/testsuite/reloc1lib1.c b/trunk/testsuite/reloc1lib1.c
new file mode 100644
index 0000000..8aa0628
--- /dev/null
+++ b/trunk/testsuite/reloc1lib1.c
@@ -0,0 +1,16 @@
+#include "reloc1.h"
+
+int bar = 26;
+int baz = 28;
+
+struct A foo = { 1, &foo, &bar };
+
+int f1 (void)
+{
+ return 1;
+}
+
+int f2 (void)
+{
+ return f1 () + 1;
+}
diff --git a/trunk/testsuite/reloc1lib2.c b/trunk/testsuite/reloc1lib2.c
new file mode 100644
index 0000000..a338c1d
--- /dev/null
+++ b/trunk/testsuite/reloc1lib2.c
@@ -0,0 +1,6 @@
+#include "reloc1.h"
+
+int f1 (void)
+{
+ return 11;
+}
diff --git a/trunk/testsuite/reloc2.c b/trunk/testsuite/reloc2.c
new file mode 100644
index 0000000..6c7fed5
--- /dev/null
+++ b/trunk/testsuite/reloc2.c
@@ -0,0 +1,13 @@
+#include <stdlib.h>
+
+extern int f2 (int add);
+extern void * f3 (void);
+
+int main()
+{
+ if (f2 (1) != 27 || f2 (0) != 1)
+ abort ();
+ if (f3 () != (void *) f3)
+ abort ();
+ exit (0);
+}
diff --git a/trunk/testsuite/reloc2.sh b/trunk/testsuite/reloc2.sh
new file mode 100755
index 0000000..4d180c6
--- /dev/null
+++ b/trunk/testsuite/reloc2.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+SHFLAGS=
+case "`uname -m`" in
+ ia64|ppc*|x86_64|mips*) SHFLAGS=-fpic;; # Does not support non-pic shared libs
+ s390*) if file reloc1lib1.so | grep -q 64-bit; then SHFLAGS=-fpic; fi;;
+esac
+rm -f reloc2 reloc2lib*.so reloc2.log
+$CC -shared $SHFLAGS -O2 -o reloc2lib1.so $srcdir/reloc2lib1.c
+$CC -shared $SHFLAGS -O2 -o reloc2lib2.so $srcdir/reloc2lib2.c \
+ reloc2lib1.so 2>/dev/null
+BINS="reloc2"
+LIBS="reloc2lib1.so reloc2lib2.so"
+$CCLINK -o reloc2 $srcdir/reloc2.c -Wl,--rpath-link,. reloc2lib2.so
+$STRIP -R .comment $BINS $LIBS
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc2 > reloc2.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc2 >> reloc2.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc2.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc2 || exit 3
+fi
+readelf -a ./reloc2 >> reloc2.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc2
+comparelibs >> reloc2.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc2lib1.c b/trunk/testsuite/reloc2lib1.c
new file mode 100644
index 0000000..3551704
--- /dev/null
+++ b/trunk/testsuite/reloc2lib1.c
@@ -0,0 +1,4 @@
+int f1 (int dummy)
+{
+ return 1;
+}
diff --git a/trunk/testsuite/reloc2lib2.c b/trunk/testsuite/reloc2lib2.c
new file mode 100644
index 0000000..094daad
--- /dev/null
+++ b/trunk/testsuite/reloc2lib2.c
@@ -0,0 +1,15 @@
+extern int f1 (int dummy);
+
+int f2 (int add)
+{
+ if (add)
+ return f1 (0) + 26;
+ return f1 (0);
+}
+
+/* Make sure conflict in f3 is not against read-only segment. */
+asm (".section trampoline, \"awx\"; .previous");
+void * __attribute__((section ("trampoline"))) f3 (void)
+{
+ return (void *) f3;
+}
diff --git a/trunk/testsuite/reloc3.c b/trunk/testsuite/reloc3.c
new file mode 100644
index 0000000..2f455d7
--- /dev/null
+++ b/trunk/testsuite/reloc3.c
@@ -0,0 +1,29 @@
+#include "reloc1.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+int i;
+int j __attribute__((aligned (32)));
+int k[2048];
+int l = 26;
+
+void f5 (FILE *f)
+{
+ fprintf (stdout, "OK");
+}
+
+int main()
+{
+ struct A *x;
+ foo.c -= 2;
+ if (foo.a != 1 || foo.b != &foo || foo.c[0] != 28 || foo.c[1] != 29
+ || foo.c[2] != 30)
+ abort ();
+ if (f1 () != 11 || f2 () != 12)
+ abort ();
+ x = f3 ();
+ if (x->a != 2 || x->b != x || x->c != foo.c + 1)
+ abort ();
+ f5 (stdout);
+ exit (0);
+}
diff --git a/trunk/testsuite/reloc3.sh b/trunk/testsuite/reloc3.sh
new file mode 100755
index 0000000..acf0497
--- /dev/null
+++ b/trunk/testsuite/reloc3.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f reloc3 reloc3lib*.so reloc3.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o reloc3lib1.so $srcdir/reloc3lib1.c
+$CC -shared -O2 -fpic -o reloc3lib2.so $srcdir/reloc1lib2.c reloc3lib1.so
+BINS="reloc3"
+LIBS="reloc3lib1.so reloc3lib2.so"
+$CCLINK -o reloc3 $srcdir/reloc3.c -Wl,--rpath-link,. reloc3lib2.so
+$STRIP -g $BINS $LIBS
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc3 > reloc3.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc3 >> reloc3.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc3.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc3 >> reloc3.log || exit 3
+fi
+readelf -a ./reloc3 >> reloc3.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc3
+comparelibs >> reloc3.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc3lib1.c b/trunk/testsuite/reloc3lib1.c
new file mode 100644
index 0000000..fd649c6
--- /dev/null
+++ b/trunk/testsuite/reloc3lib1.c
@@ -0,0 +1,21 @@
+#include "reloc1.h"
+
+int baz[3] = { 28, 29, 30 };
+
+struct A foo = { 1, &foo, &baz[2] };
+static struct A xfoo = { 2, &xfoo, &baz[1] };
+
+int f1 (void)
+{
+ return 1;
+}
+
+int f2 (void)
+{
+ return f1 () + 1;
+}
+
+struct A *f3 (void)
+{
+ return &xfoo;
+}
diff --git a/trunk/testsuite/reloc4.c b/trunk/testsuite/reloc4.c
new file mode 100644
index 0000000..cb3b17a
--- /dev/null
+++ b/trunk/testsuite/reloc4.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int main (void)
+{
+ int i;
+
+ printf ("#include <stdlib.h>\nextern int");
+ for (i = 0; i < 255; ++i)
+ printf (" bar%02x (int),", i);
+ printf (" barff (int);\nint main (void)\n{\n int x = 0;\n");
+ for (i = 0; i < 256; ++i)
+ printf (" x = bar%02x (x);\n", i);
+ printf (" if (x != 0x7fff8000) abort ();\n exit (0);\n}\n");
+}
diff --git a/trunk/testsuite/reloc4.sh b/trunk/testsuite/reloc4.sh
new file mode 100755
index 0000000..c20f8b5
--- /dev/null
+++ b/trunk/testsuite/reloc4.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# This test takes a lot of time, so skip it normally
+[ -z "$CHECK_ME_HARDER" ] && exit 77
+rm -f reloc4 reloc4lib*.so reloc4.log
+rm -f prelink.cache
+$HOST_CC -O2 -o reloc4lib1.tmp $srcdir/reloc4lib1.c
+$HOST_CC -O2 -o reloc4lib2.tmp $srcdir/reloc4lib2.c
+$HOST_CC -O2 -o reloc4lib3.tmp $srcdir/reloc4lib3.c
+$HOST_CC -O2 -o reloc4.tmp $srcdir/reloc4.c
+./reloc4lib1.tmp > reloc4lib1.tmp.c
+./reloc4lib2.tmp > reloc4lib2.tmp.c
+./reloc4lib3.tmp > reloc4lib3.tmp.c
+./reloc4.tmp > reloc4.tmp.c
+case "`$RUN uname -m`" in
+ mips*) extra=-mxgot ;;
+ *) extra= ;;
+esac
+$CC -shared -fpic $extra -o reloc4lib1.so reloc4lib1.tmp.c
+$CC -shared -fpic $extra -o reloc4lib2.so reloc4lib2.tmp.c reloc4lib1.so
+$CC -shared -fpic $extra -o reloc4lib3.so reloc4lib3.tmp.c reloc4lib2.so
+BINS="reloc4"
+LIBS="reloc4lib1.so reloc4lib2.so reloc4lib3.so"
+$CCLINK $extra -o reloc4 reloc4.tmp.c -Wl,--rpath-link,. reloc4lib3.so
+savelibs
+rm -f reloc4*.tmp reloc4*.tmp.c
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc4 > reloc4.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc4 >> reloc4.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc4.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc4 || exit 3
+fi
+readelf -a ./reloc4 >> reloc4.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc4
+comparelibs >> reloc4.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc4lib1.c b/trunk/testsuite/reloc4lib1.c
new file mode 100644
index 0000000..f1297d8
--- /dev/null
+++ b/trunk/testsuite/reloc4lib1.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+ int i;
+
+ for (i = 0; i < 65536; ++i)
+ printf ("int foo%04x (void) { return %d; }\n", i, (i & 31) == 0 ? 0 : i);
+}
diff --git a/trunk/testsuite/reloc4lib2.c b/trunk/testsuite/reloc4lib2.c
new file mode 100644
index 0000000..07aa721
--- /dev/null
+++ b/trunk/testsuite/reloc4lib2.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main (void)
+{
+ int i, j;
+
+ for (i = 0; i < 256; ++i)
+ {
+ printf ("extern int ");
+ for (j = 0; j < 255; ++j)
+ printf ("foo%02x%02x (void), ", i, j);
+ printf ("foo%02xff (void);\nint bar%02x (int x) { return x", i, i);
+ for (j = 0; j < 256; ++j)
+ printf (" + foo%02x%02x ()", i, j);
+ printf ("; }\n");
+ }
+}
diff --git a/trunk/testsuite/reloc4lib3.c b/trunk/testsuite/reloc4lib3.c
new file mode 100644
index 0000000..1f30817
--- /dev/null
+++ b/trunk/testsuite/reloc4lib3.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+ int i;
+
+ for (i = 0; i < 65536; i += 32)
+ printf ("int foo%04x (void) { return %d; }\n", i, i);
+}
diff --git a/trunk/testsuite/reloc5.c b/trunk/testsuite/reloc5.c
new file mode 100644
index 0000000..b174bcf
--- /dev/null
+++ b/trunk/testsuite/reloc5.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main (void)
+{
+ int i;
+
+ printf ("#include <stdlib.h>\nextern char testzero[16384];\nextern int");
+ for (i = 0; i < 255; ++i)
+ printf (" bar%02x (int),", i);
+ printf (" barff (int);\nint main (void)\n{\n int x = 0;\n");
+ for (i = 0; i < 256; ++i)
+ printf (" x = bar%02x (x);\n", i);
+ printf (" if (x != 0x7fff8000) abort ();\n");
+ printf (" for (x = 0; x < 16384; ++x)\n");
+ printf (" if (testzero[x]) abort ();\n");
+ printf (" exit (0);\n}\n\n");
+ printf ("#ifdef __arm__\n");
+ printf ("asm (\".section nonalloced,\\\"aw\\\",%%nobits\\n\\t\"\n");
+ printf ("#else\n");
+ printf ("asm (\".section nonalloced,\\\"aw\\\",@nobits\\n\\t\"\n");
+ printf ("#endif\n");
+ printf (" \".globl testzero\\n\\t\"\n");
+ printf (" \"testzero: .skip 16384\");\n");
+}
diff --git a/trunk/testsuite/reloc5.sh b/trunk/testsuite/reloc5.sh
new file mode 100755
index 0000000..f543f69
--- /dev/null
+++ b/trunk/testsuite/reloc5.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# This test takes a lot of time, so skip it normally
+[ -z "$CHECK_ME_HARDER" ] && exit 77
+rm -f reloc5 reloc5.log
+rm -f prelink.cache
+$HOST_CC -O2 -o reloc5.tmp $srcdir/reloc5.c
+./reloc5.tmp > reloc5.tmp.c
+BINS="reloc5"
+$CCLINK -o reloc5 reloc5.tmp.c -Wl,--rpath-link,. reloc4lib3.so
+savelibs
+rm -f reloc5*.tmp reloc5*.tmp.c
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc5 > reloc5.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc5 >> reloc5.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc5.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc5 || exit 3
+fi
+readelf -a ./reloc5 >> reloc5.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc5
+comparelibs >> reloc5.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc6.sh b/trunk/testsuite/reloc6.sh
new file mode 100755
index 0000000..7f72936
--- /dev/null
+++ b/trunk/testsuite/reloc6.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f reloc6 reloc6lib*.so reloc6.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o reloc6lib1.so $srcdir/reloc3lib1.c
+$CC -shared -O2 -fpic -o reloc6lib2.so $srcdir/reloc1lib2.c reloc6lib1.so
+$CCLINK -o reloc6 $srcdir/reloc3.c -Wl,--rpath-link,. reloc6lib2.so
+$CCLINK -o reloc6.nop $srcdir/reloc3.c -Wl,--rpath-link,. reloc6lib2.so
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc6 > reloc6.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc6 >> reloc6.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc6.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc6 >> reloc6.log || exit 3
+fi
+readelf -a ./reloc6 >> reloc6.log 2>&1 || exit 4
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc6.nop >> reloc6.log || exit 5
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. LD_BIND_NOW=1 ./reloc6.nop >> reloc6.log || exit 6
+fi
+mv -f reloc6lib2.so reloc6lib2.so.p
+$CC -shared -O2 -fpic -o reloc6lib2.so $srcdir/reloc1lib2.c reloc6lib1.so
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc6 >> reloc6.log || exit 7
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc6.nop >> reloc6.log || exit 8
+fi
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. LD_BIND_NOW=1 ./reloc6.nop >> reloc6.log || exit 9
+fi
+mv -f reloc6lib2.so reloc6lib2.so.nop
+mv -f reloc6lib2.so.p reloc6lib2.so
+# So that it is not prelinked again
+chmod -x ./reloc6 ./reloc6.nop
diff --git a/trunk/testsuite/reloc7.c b/trunk/testsuite/reloc7.c
new file mode 100644
index 0000000..c1f6dc8
--- /dev/null
+++ b/trunk/testsuite/reloc7.c
@@ -0,0 +1,38 @@
+#include "reloc1.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+int i;
+int j __attribute__((aligned (32)));
+int k[2048];
+int l = 26;
+int m[3] = { 28, 29, 30 };
+extern int baz[3];
+
+struct A n __attribute__((section("nsec"))) = { 1, &n, &m[2] };
+static struct A o __attribute__((section("osec"))) = { 2, &o, &baz[1] };
+
+void f5 (FILE *f)
+{
+ fprintf (stdout, "OK");
+}
+
+int main()
+{
+ struct A *x;
+ foo.c -= 2;
+ if (foo.a != 1 || foo.b != &foo || foo.c[0] != 28 || foo.c[1] != 29
+ || foo.c[2] != 30)
+ abort ();
+ if (f1 () != 11 || f2 () != 12)
+ abort ();
+ x = f3 ();
+ if (x->a != 2 || x->b != x || x->c != foo.c + 1)
+ abort ();
+ if (n.a != 1 || n.b != &n || n.c != m + 2)
+ abort ();
+ if (o.a != 2 || o.b != &o || o.c != baz + 1)
+ abort ();
+ f5 (stdout);
+ exit (0);
+}
diff --git a/trunk/testsuite/reloc7.sh b/trunk/testsuite/reloc7.sh
new file mode 100755
index 0000000..edbbcbf
--- /dev/null
+++ b/trunk/testsuite/reloc7.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f reloc7 reloc7lib*.so reloc7.log
+rm -f prelink.cache
+$CC -shared -O2 -Wl,-z,nocombreloc -fpic -o reloc7lib1.so $srcdir/reloc3lib1.c
+$CC -shared -O2 -Wl,-z,nocombreloc -fpic -o reloc7lib2.so $srcdir/reloc1lib2.c reloc7lib1.so
+BINS="reloc7"
+LIBS="reloc7lib1.so reloc7lib2.so"
+$CCLINK -o reloc7 -Wl,-z,nocombreloc $srcdir/reloc7.c -Wl,--rpath-link,. reloc7lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc7 > reloc7.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc7 >> reloc7.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc7.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc7 >> reloc7.log || exit 3
+fi
+readelf -a ./reloc7 >> reloc7.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc7
+comparelibs >> reloc7.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc8.sh b/trunk/testsuite/reloc8.sh
new file mode 100755
index 0000000..9f5e1fb
--- /dev/null
+++ b/trunk/testsuite/reloc8.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# Disable this test under SELinux
+if [ "x$CROSS" = "x" ]; then
+ test -x /usr/sbin/getenforce -a "`/usr/sbin/getenforce`" = Enforcing && exit 77
+fi
+rm -f reloc8 reloc8lib*.so reloc8.log
+rm -f prelink.cache
+NOCOPYRELOC=-Wl,-z,nocopyreloc
+case "`uname -m`" in
+ x86_64|s390*) if file reloc1lib1.so | grep -q 64-bit; then NOCOPYRELOC=; fi;;
+esac
+$CC -shared -O2 -Wl,-z,nocombreloc -fpic -o reloc8lib1.so $srcdir/reloc3lib1.c
+$CC -shared -O2 -Wl,-z,nocombreloc -fpic -o reloc8lib2.so $srcdir/reloc1lib2.c reloc8lib1.so
+BINS="reloc8"
+LIBS="reloc8lib1.so reloc8lib2.so"
+$CCLINK -o reloc8 $NOCOPYRELOC $srcdir/reloc7.c -Wl,--rpath-link,. reloc8lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc8 > reloc8.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc8 >> reloc8.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc8.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc8 >> reloc8.log || exit 3
+fi
+readelf -a ./reloc8 >> reloc8.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc8
+comparelibs >> reloc8.log 2>&1 || exit 5
diff --git a/trunk/testsuite/reloc9.sh b/trunk/testsuite/reloc9.sh
new file mode 100755
index 0000000..d3a449c
--- /dev/null
+++ b/trunk/testsuite/reloc9.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# Disable this test under SELinux
+if [ "x$CROSS" = "x" ]; then
+ test -x /usr/sbin/getenforce -a "`/usr/sbin/getenforce`" = Enforcing && exit 77
+fi
+rm -f reloc9 reloc9lib*.so reloc9.log
+rm -f prelink.cache
+NOCOPYRELOC=-Wl,-z,nocopyreloc
+case "`uname -m`" in
+ x86_64|s390*) if file reloc1lib1.so | grep -q 64-bit; then NOCOPYRELOC=; fi;;
+esac
+$CC -shared -O2 -Wl,-z,nocombreloc -fpic -o reloc9lib1.so $srcdir/reloc3lib1.c
+$CC -shared -O2 -Wl,-z,nocombreloc -fpic -o reloc9lib2.so $srcdir/reloc1lib2.c reloc9lib1.so
+BINS="reloc9"
+LIBS="reloc9lib1.so reloc9lib2.so"
+$CCLINK -o reloc9 -Wl,-z,nocombreloc $NOCOPYRELOC $srcdir/reloc7.c -Wl,--rpath-link,. reloc9lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./reloc9 > reloc9.log
+$PRELINK ${PRELINK_OPTS--vm} ./reloc9 >> reloc9.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` reloc9.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./reloc9 >> reloc9.log || exit 3
+fi
+readelf -a ./reloc9 >> reloc9.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./reloc9
+comparelibs >> reloc9.log 2>&1 || exit 5
diff --git a/trunk/testsuite/shuffle1.sh b/trunk/testsuite/shuffle1.sh
new file mode 100755
index 0000000..4553d2e
--- /dev/null
+++ b/trunk/testsuite/shuffle1.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f shuffle1 shuffle1lib*.so shuffle1.log shuffle1.lds
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o shuffle1lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o shuffle1lib2.so $srcdir/reloc1lib2.c shuffle1lib1.so
+BINS="shuffle1"
+LIBS="shuffle1lib1.so shuffle1lib2.so"
+$CCLINK -o shuffle1 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle1lib2.so \
+ -Wl,--verbose 2>&1 | sed -e '/^=========/,/^=========/!d;/^=========/d' \
+ -e 's/0x08048000/0x08000000/;s/SIZEOF_HEADERS.*$/& . += 56;/' > shuffle1.lds
+$CCLINK -o shuffle1 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle1lib2.so \
+ -Wl,-T,shuffle1.lds
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle1 > shuffle1.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle1 >> shuffle1.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle1.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle1 || exit 3
+fi
+readelf -a ./shuffle1 >> shuffle1.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./shuffle1
+comparelibs >> shuffle1.log 2>&1 || exit 5
diff --git a/trunk/testsuite/shuffle2.c b/trunk/testsuite/shuffle2.c
new file mode 100644
index 0000000..c9f03ce
--- /dev/null
+++ b/trunk/testsuite/shuffle2.c
@@ -0,0 +1,27 @@
+#include "reloc1.h"
+#include <stdlib.h>
+
+extern char testzero[16384];
+
+int main()
+{
+ int i;
+ if (foo.a != 1 || foo.b != &foo || foo.c != &bar || bar != 26)
+ abort ();
+ if (f1 () != 11 || f2 () != 12)
+ abort ();
+ for (i = 0; i < 16384; ++i)
+ if (testzero[i])
+ abort ();
+ exit (0);
+}
+
+#ifdef __arm__
+asm (".section nonalloced,\"aw\",%nobits\n\t"
+ ".globl testzero\n\t"
+ "testzero: .skip 16384");
+#else
+asm (".section nonalloced,\"aw\",@nobits\n\t"
+ ".globl testzero\n\t"
+ "testzero: .skip 16384");
+#endif
diff --git a/trunk/testsuite/shuffle2.sh b/trunk/testsuite/shuffle2.sh
new file mode 100755
index 0000000..fdaf03e
--- /dev/null
+++ b/trunk/testsuite/shuffle2.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# Kernels before 2.4.10 are known not to work
+if [ "x$CROSS" = "x" ]; then
+ case "`uname -r`" in
+ [01].*|2.[0-3].*|2.4.[0-9]|2.4.[0-9][^0-9]*) exit 77;;
+ esac
+fi
+rm -f shuffle2 shuffle2lib*.so shuffle2.log shuffle2.lds
+$CC -shared -O2 -fpic -o shuffle2lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o shuffle2lib2.so $srcdir/reloc1lib2.c shuffle2lib1.so
+BINS="shuffle2"
+LIBS="shuffle2lib1.so shuffle2lib2.so"
+$CCLINK -o shuffle2 $srcdir/shuffle2.c -Wl,--rpath-link,. shuffle2lib2.so \
+ -Wl,--verbose 2>&1 | sed -e '/^=========/,/^=========/!d;/^=========/d' \
+ -e 's/0x08048000/0x08000000/;s/SIZEOF_HEADERS.*$/& . += 56;/' > shuffle2.lds
+$CCLINK -o shuffle2 $srcdir/shuffle2.c -Wl,--rpath-link,. shuffle2lib2.so \
+ -Wl,-T,shuffle2.lds
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle2 > shuffle2.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle2 >> shuffle2.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle2.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle2 || exit 3
+fi
+readelf -a ./shuffle2 >> shuffle2.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./shuffle2
+comparelibs >> shuffle2.log 2>&1 || exit 5
diff --git a/trunk/testsuite/shuffle3.sh b/trunk/testsuite/shuffle3.sh
new file mode 100755
index 0000000..989bfcb
--- /dev/null
+++ b/trunk/testsuite/shuffle3.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# Kernels before 2.4.10 are known not to work
+if [ "x$CROSS" = "x" ]; then
+ case "`uname -r`" in
+ [01].*|2.[0-3].*|2.4.[0-9]|2.4.[0-9][^0-9]*) exit 77;;
+ esac
+fi
+rm -f shuffle3 shuffle3lib*.so shuffle3.log shuffle3.lds
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o shuffle3lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o shuffle3lib2.so $srcdir/reloc1lib2.c shuffle3lib1.so
+BINS="shuffle3"
+LIBS="shuffle3lib1.so shuffle3lib2.so"
+$CCLINK -o shuffle3 $srcdir/shuffle2.c -Wl,--rpath-link,. shuffle3lib2.so \
+ -Wl,--verbose 2>&1 | sed -e '/^=========/,/^=========/!d;/^=========/d' \
+ -e 's/0x08048000/0x08000000/' > shuffle3.lds
+$CCLINK -o shuffle3 $srcdir/shuffle2.c -Wl,--rpath-link,. shuffle3lib2.so \
+ -Wl,-T,shuffle3.lds
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle3 > shuffle3.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle3 >> shuffle3.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle3.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle3 || exit 3
+fi
+readelf -a ./shuffle3 >> shuffle3.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./shuffle3
+comparelibs >> shuffle3.log 2>&1 || exit 5
diff --git a/trunk/testsuite/shuffle4.sh b/trunk/testsuite/shuffle4.sh
new file mode 100755
index 0000000..781431c
--- /dev/null
+++ b/trunk/testsuite/shuffle4.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# Kernels before 2.4.10 are known not to work
+if [ "x$CROSS" = "x" ]; then
+ case "`uname -r`" in
+ [01].*|2.[0-3].*|2.4.[0-9]|2.4.[0-9][^0-9]*) exit 77;;
+ esac
+fi
+rm -f shuffle4 shuffle4.log
+BINS="shuffle4"
+$CCLINK -o shuffle4 $srcdir/shuffle2.c -Wl,--rpath-link,. shuffle3lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle4 > shuffle4.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle4 >> shuffle4.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle4.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle4 || exit 3
+fi
+readelf -a ./shuffle4 >> shuffle4.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./shuffle4
+comparelibs >> shuffle4.log 2>&1 || exit 5
diff --git a/trunk/testsuite/shuffle5.sh b/trunk/testsuite/shuffle5.sh
new file mode 100755
index 0000000..db722e8
--- /dev/null
+++ b/trunk/testsuite/shuffle5.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f shuffle5 shuffle5lib*.so shuffle5.log shuffle5.lds
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o shuffle5lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o shuffle5lib2.so $srcdir/reloc1lib2.c shuffle5lib1.so
+BINS="shuffle5"
+LIBS="shuffle5lib1.so shuffle5lib2.so"
+$CCLINK -o shuffle5 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle5lib2.so \
+ -Wl,--verbose 2>&1 | sed -e '/^=========/,/^=========/!d;/^=========/d' \
+ -e 's/0x08048000/0x08000000/;s/SIZEOF_HEADERS.*$/& . += 180;/' > shuffle5.lds
+$CCLINK -o shuffle5 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle5lib2.so \
+ -Wl,-T,shuffle5.lds
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle5 > shuffle5.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle5 >> shuffle5.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle5.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle5 || exit 3
+fi
+readelf -a ./shuffle5 >> shuffle5.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./shuffle5
+comparelibs >> shuffle5.log 2>&1 || exit 5
diff --git a/trunk/testsuite/shuffle6.sh b/trunk/testsuite/shuffle6.sh
new file mode 100755
index 0000000..eb28d62
--- /dev/null
+++ b/trunk/testsuite/shuffle6.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f shuffle6 shuffle6lib*.so shuffle6.log shuffle6.lds
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o shuffle6lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o shuffle6lib2.so $srcdir/reloc1lib2.c shuffle6lib1.so
+BINS="shuffle6"
+LIBS="shuffle6lib1.so shuffle6lib2.so"
+$CCLINK -o shuffle6 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle6lib2.so \
+ -Wl,--verbose 2>&1 | sed -e '/^=========/,/^=========/!d;/^=========/d' \
+ -e 's/0x08048000/0x08000000/;s/SIZEOF_HEADERS.*$/& . += 56;/' > shuffle6.lds
+$CCLINK -o shuffle6 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle6lib2.so \
+ -Wl,-T,shuffle6.lds
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle6 > shuffle6.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle6 >> shuffle6.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle6.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle6 || exit 3
+fi
+readelf -a ./shuffle6 >> shuffle6.log 2>&1 || exit 4
+comparelibs >> shuffle6.log 2>&1 || exit 5
+for l in shuffle6lib{1,2}.so{,.orig}; do mv -f $l $l.first; done
+cp -p shuffle6 shuffle6.first
+$CC -shared -O2 -fpic -o shuffle6lib1.so $srcdir/shuffle6lib1.c
+$CC -shared -O2 -fpic -o shuffle6lib2.so $srcdir/shuffle6lib2.c shuffle6lib1.so
+for l in shuffle6lib{1,2}.so; do cp -p $l $l.orig; done
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle6 >> shuffle6.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle6 >> shuffle6.log 2>&1 || exit 6
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle6.log && exit 7
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle6 || exit 8
+fi
+readelf -a ./shuffle6 >> shuffle6.log 2>&1 || exit 9
+# So that it is not prelinked again
+chmod -x ./shuffle6
+comparelibs >> shuffle6.log 2>&1 || exit 10
diff --git a/trunk/testsuite/shuffle6lib1.c b/trunk/testsuite/shuffle6lib1.c
new file mode 100644
index 0000000..8053293
--- /dev/null
+++ b/trunk/testsuite/shuffle6lib1.c
@@ -0,0 +1,20 @@
+#include "reloc1.h"
+
+int bar = 26;
+int baz = 28;
+#define M(i) int b##i, *pb##i = &b##i;
+M(0) M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8) M(9)
+M(10) M(11) M(12) M(13) M(14) M(15) M(16) M(17) M(18) M(19)
+#undef M
+
+struct A foo = { 1, &foo, &bar };
+
+int f1 (void)
+{
+ return 1;
+}
+
+int f2 (void)
+{
+ return f1 () + 1;
+}
diff --git a/trunk/testsuite/shuffle6lib2.c b/trunk/testsuite/shuffle6lib2.c
new file mode 100644
index 0000000..ed18f6b
--- /dev/null
+++ b/trunk/testsuite/shuffle6lib2.c
@@ -0,0 +1,16 @@
+#include "reloc1.h"
+#include <stdlib.h>
+
+#define M(i) int b##i; extern *pb##i;
+M(0) M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8) M(9)
+M(10) M(11) M(12) M(13) M(14) M(15) M(16) M(17) M(18) M(19)
+#undef M
+
+int f1 (void)
+{
+#define M(i) if (pb##i != &b##i) abort ();
+M(0) M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8) M(9)
+M(10) M(11) M(12) M(13) M(14) M(15) M(16) M(17) M(18) M(19)
+#undef M
+ return 11;
+}
diff --git a/trunk/testsuite/shuffle7.sh b/trunk/testsuite/shuffle7.sh
new file mode 100755
index 0000000..c6449c8
--- /dev/null
+++ b/trunk/testsuite/shuffle7.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f shuffle7 shuffle7lib*.so shuffle7.log shuffle7.lds
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o shuffle7lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o shuffle7lib2.so $srcdir/reloc1lib2.c shuffle7lib1.so
+BINS="shuffle7"
+LIBS="shuffle7lib1.so shuffle7lib2.so"
+$CCLINK -o shuffle7 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle7lib2.so \
+ -Wl,--verbose 2>&1 | sed -e '/^=========/,/^=========/!d;/^=========/d' \
+ -e '/\.hash/a\
+ . = . + 0x300;' > shuffle7.lds
+$CCLINK -o shuffle7 $srcdir/reloc1.c -Wl,--rpath-link,. shuffle7lib2.so \
+ -Wl,-T,shuffle7.lds
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle7 > shuffle7.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle7 >> shuffle7.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle7.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle7 || exit 3
+fi
+readelf -a ./shuffle7 >> shuffle7.log 2>&1 || exit 4
+comparelibs >> shuffle7.log 2>&1 || exit 5
+for l in shuffle7lib{1,2}.so{,.orig}; do mv -f $l $l.first; done
+cp -p shuffle7 shuffle7.first
+$CC -shared -O2 -fpic -o shuffle7lib1.so $srcdir/shuffle6lib1.c
+$CC -shared -O2 -fpic -o shuffle7lib2.so $srcdir/shuffle6lib2.c shuffle7lib1.so
+for l in shuffle7lib{1,2}.so; do cp -p $l $l.orig; done
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle7 >> shuffle7.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle7 >> shuffle7.log 2>&1 || exit 6
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle7.log && exit 7
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle7 || exit 8
+fi
+readelf -a ./shuffle7 >> shuffle7.log 2>&1 || exit 9
+comparelibs >> shuffle7.log 2>&1 || exit 10
+for l in shuffle7lib{1,2}.so{,.orig}; do mv -f $l $l.second; done
+cp -p shuffle7 shuffle7.second
+for l in shuffle7lib{1,2}.so{,.orig}; do cp -p $l.first $l; done
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle7 >> shuffle7.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle7 >> shuffle7.log 2>&1 || exit 11
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle7.log && exit 12
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle7 || exit 13
+fi
+readelf -a ./shuffle7 >> shuffle7.log 2>&1 || exit 14
+comparelibs >> shuffle7.log 2>&1 || exit 15
+cmp -s shuffle7{,.first} || exit 16
+# So that it is not prelinked again
+chmod -x ./shuffle7
diff --git a/trunk/testsuite/shuffle8.c b/trunk/testsuite/shuffle8.c
new file mode 100644
index 0000000..4e80184
--- /dev/null
+++ b/trunk/testsuite/shuffle8.c
@@ -0,0 +1,20 @@
+#include "reloc1.h"
+#include <stdlib.h>
+
+static struct A local = { 77, &local, &bar + 4 };
+int vbss[16384] __attribute__((aligned (4096)));
+int vdata __attribute__((aligned (4096))) = 5;
+
+asm (".text; .balign 4096; vtext:; .previous");
+
+int main()
+{
+ if (foo.a != 1 || foo.b != &foo || foo.c != &bar || bar != 26)
+ abort ();
+ if (f1 () != 11 || f2 () != 12)
+ abort ();
+ local.c -= 4;
+ if (local.a != 77 || local.b != &local || local.c != &bar)
+ abort ();
+ exit (vbss[31] + vdata - 5);
+}
diff --git a/trunk/testsuite/shuffle8.sh b/trunk/testsuite/shuffle8.sh
new file mode 100755
index 0000000..51dcc4c
--- /dev/null
+++ b/trunk/testsuite/shuffle8.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f shuffle8 shuffle8lib*.so shuffle8.log shuffle8.lds
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o shuffle8lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o shuffle8lib2.so $srcdir/reloc1lib2.c shuffle8lib1.so
+BINS="shuffle8"
+LIBS="shuffle8lib1.so shuffle8lib2.so"
+$CCLINK -o shuffle8 $srcdir/shuffle8.c -Wl,--rpath-link,. shuffle8lib2.so
+$STRIP -R .comment shuffle8
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./shuffle8 > shuffle8.log
+$PRELINK ${PRELINK_OPTS--vm} ./shuffle8 >> shuffle8.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` shuffle8.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./shuffle8 || exit 3
+fi
+readelf -a ./shuffle8 >> shuffle8.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./shuffle8
+comparelibs >> shuffle8.log 2>&1 || exit 5
diff --git a/trunk/testsuite/tls1.c b/trunk/testsuite/tls1.c
new file mode 100644
index 0000000..08bd26f
--- /dev/null
+++ b/trunk/testsuite/tls1.c
@@ -0,0 +1,36 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+static __thread int dummy = 12;
+__thread struct A local = { 1, 2, 3 };
+
+#define CHECK(N, S) \
+ p = f##N##a (); \
+ if (p->a != S || p->b != S + 1 || p->c != S + 2) \
+ abort ()
+
+int main()
+{
+ struct A *p;
+ if (local.a != 1 || local.b != 2 || local.c != 3)
+ abort ();
+ if (a1.a != 4 || a1.b != 5 || a1.c != 6)
+ abort ();
+ if (a2.a != 22 || a2.b != 23 || a2.c != 24)
+ abort ();
+ if (a3.a != 10 || a3.b != 11 || a3.c != 12)
+ abort ();
+ if (a4.a != 25 || a4.b != 26 || a4.c != 27)
+ abort ();
+ check1 ();
+ check2 ();
+ if (f1a () != &a1 || f2a () != &a2 || f3a () != &a3 || f4a () != &a4)
+ abort ();
+ CHECK (5, 16);
+ CHECK (6, 19);
+ if (f7a () != &a2 || f8a () != &a4)
+ abort ();
+ CHECK (9, 28);
+ CHECK (10, 31);
+ exit (0);
+}
diff --git a/trunk/testsuite/tls1.h b/trunk/testsuite/tls1.h
new file mode 100644
index 0000000..d627340
--- /dev/null
+++ b/trunk/testsuite/tls1.h
@@ -0,0 +1,30 @@
+struct A
+ {
+ char a;
+ int b;
+ long long c;
+ };
+
+extern __thread struct A a1, a2, a3, a4;
+extern struct A *f1a (void);
+extern struct A *f2a (void);
+extern struct A *f3a (void);
+extern struct A *f4a (void);
+extern struct A *f5a (void);
+extern struct A *f6a (void);
+extern struct A *f7a (void);
+extern struct A *f8a (void);
+extern struct A *f9a (void);
+extern struct A *f10a (void);
+extern int f1b (void);
+extern int f2b (void);
+extern int f3b (void);
+extern int f4b (void);
+extern int f5b (void);
+extern int f6b (void);
+extern int f7b (void);
+extern int f8b (void);
+extern int f9b (void);
+extern int f10b (void);
+extern void check1 (void);
+extern void check2 (void);
diff --git a/trunk/testsuite/tls1.sh b/trunk/testsuite/tls1.sh
new file mode 100755
index 0000000..f3d2113
--- /dev/null
+++ b/trunk/testsuite/tls1.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# First check if __thread is supported by ld.so/gcc/ld/as:
+rm -f tlstest
+#echo '__thread int a; int main (void) { return a; }' \
+# | $CC -xc - -o tlstest > /dev/null 2>&1 || exit 77
+#( ./tlstest || { rm -f tlstest; exit 77; } ) 2>/dev/null || exit 77
+rm -f tls1 tls1lib*.so tls1.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o tls1lib1.so $srcdir/tls1lib1.c
+$CC -shared -O2 -fpic -o tls1lib2.so $srcdir/tls1lib2.c tls1lib1.so
+BINS="tls1"
+LIBS="tls1lib1.so tls1lib2.so"
+$CCLINK -o tls1 $srcdir/tls1.c -Wl,--rpath-link,. tls1lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls1 > tls1.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls1 >> tls1.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` tls1.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls1 || exit 3
+fi
+readelf -a ./tls1 >> tls1.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./tls1
+comparelibs >> tls1.log 2>&1 || exit 5
diff --git a/trunk/testsuite/tls1lib1.c b/trunk/testsuite/tls1lib1.c
new file mode 100644
index 0000000..eb0734b
--- /dev/null
+++ b/trunk/testsuite/tls1lib1.c
@@ -0,0 +1,89 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+static __thread int dummy = 12;
+__thread struct A a1 = { 4, 5, 6 };
+__thread struct A a2 = { 7, 8, 9 };
+__thread struct A a3 __attribute__((tls_model("initial-exec")))
+ = { 10, 11, 12 };
+__thread struct A a4 __attribute__((tls_model("initial-exec")))
+ = { 13, 14, 15 };
+static __thread struct A local1 = { 16, 17, 18 };
+static __thread struct A local2 __attribute__((tls_model("initial-exec")))
+ = { 19, 20, 21 };
+
+void check1 (void)
+{
+ if (a1.a != 4 || a1.b != 5 || a1.c != 6)
+ abort ();
+ if (a2.a != 22 || a2.b != 23 || a2.c != 24)
+ abort ();
+ if (a3.a != 10 || a3.b != 11 || a3.c != 12)
+ abort ();
+ if (a4.a != 25 || a4.b != 26 || a4.c != 27)
+ abort ();
+ if (local1.a != 16 || local1.b != 17 || local1.c != 18)
+ abort ();
+ if (local2.a != 19 || local2.b != 20 || local2.c != 21)
+ abort ();
+}
+
+struct A *f1a (void)
+{
+ return &a1;
+}
+
+struct A *f2a (void)
+{
+ return &a2;
+}
+
+struct A *f3a (void)
+{
+ return &a3;
+}
+
+struct A *f4a (void)
+{
+ return &a4;
+}
+
+struct A *f5a (void)
+{
+ return &local1;
+}
+
+struct A *f6a (void)
+{
+ return &local2;
+}
+
+int f1b (void)
+{
+ return a1.a;
+}
+
+int f2b (void)
+{
+ return a2.b;
+}
+
+int f3b (void)
+{
+ return a3.c;
+}
+
+int f4b (void)
+{
+ return a4.a;
+}
+
+int f5b (void)
+{
+ return local1.b;
+}
+
+int f6b (void)
+{
+ return local2.c;
+}
diff --git a/trunk/testsuite/tls1lib2.c b/trunk/testsuite/tls1lib2.c
new file mode 100644
index 0000000..eee03a9
--- /dev/null
+++ b/trunk/testsuite/tls1lib2.c
@@ -0,0 +1,62 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+static __thread long long dummy = 12;
+__thread struct A a2 = { 22, 23, 24 };
+__thread struct A a4 __attribute__((tls_model("initial-exec")))
+ = { 25, 26, 27 };
+static __thread struct A local1 = { 28, 29, 30 };
+static __thread struct A local2 __attribute__((tls_model("initial-exec")))
+ = { 31, 32, 33 };
+
+void check2 (void)
+{
+ if (a2.a != 22 || a2.b != 23 || a2.c != 24)
+ abort ();
+ if (a4.a != 25 || a4.b != 26 || a4.c != 27)
+ abort ();
+ if (local1.a != 28 || local1.b != 29 || local1.c != 30)
+ abort ();
+ if (local2.a != 31 || local2.b != 32 || local2.c != 33)
+ abort ();
+}
+
+struct A *f7a (void)
+{
+ return &a2;
+}
+
+struct A *f8a (void)
+{
+ return &a4;
+}
+
+struct A *f9a (void)
+{
+ return &local1;
+}
+
+struct A *f10a (void)
+{
+ return &local2;
+}
+
+int f7b (void)
+{
+ return a2.b;
+}
+
+int f8b (void)
+{
+ return a4.a;
+}
+
+int f9b (void)
+{
+ return local1.b;
+}
+
+int f10b (void)
+{
+ return local2.c;
+}
diff --git a/trunk/testsuite/tls2.c b/trunk/testsuite/tls2.c
new file mode 100644
index 0000000..1246165
--- /dev/null
+++ b/trunk/testsuite/tls2.c
@@ -0,0 +1,25 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+#define CHECK(N, S) \
+ p = f##N##a (); \
+ if (p->a != S || p->b != S + 1 || p->c != S + 2) \
+ abort ()
+
+int main()
+{
+ struct A *p;
+ check1 ();
+ check2 ();
+ CHECK (1, 4);
+ CHECK (2, 22);
+ CHECK (3, 10);
+ CHECK (4, 25);
+ CHECK (5, 16);
+ CHECK (6, 19);
+ CHECK (7, 22);
+ CHECK (8, 25);
+ CHECK (9, 28);
+ CHECK (10, 31);
+ exit (0);
+}
diff --git a/trunk/testsuite/tls2.sh b/trunk/testsuite/tls2.sh
new file mode 100755
index 0000000..4b515b0
--- /dev/null
+++ b/trunk/testsuite/tls2.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# First check if __thread is supported by ld.so/gcc/ld/as:
+rm -f tlstest
+#echo '__thread int a; int main (void) { return a; }' \
+# | $CC -xc - -o tlstest > /dev/null 2>&1 || exit 77
+#( ./tlstest || { rm -f tlstest; exit 77; } ) 2>/dev/null || exit 77
+rm -f tls2 tls2lib*.so tls2.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o tls2lib1.so $srcdir/tls2lib1.c
+$CC -shared -O2 -fpic -o tls2lib2.so $srcdir/tls1lib2.c tls2lib1.so
+BINS="tls2"
+LIBS="tls2lib1.so tls2lib2.so"
+$CCLINK -o tls2 $srcdir/tls2.c -Wl,--rpath-link,. tls2lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls2 > tls2.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls2 >> tls2.log 2>&1 || exit 1
+grep -v 'has undefined non-weak symbols' tls2.log \
+ | grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls2 || exit 3
+fi
+readelf -a ./tls2 >> tls2.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./tls2
+comparelibs >> tls2.log 2>&1 || exit 5
diff --git a/trunk/testsuite/tls2lib1.c b/trunk/testsuite/tls2lib1.c
new file mode 100644
index 0000000..24b7555
--- /dev/null
+++ b/trunk/testsuite/tls2lib1.c
@@ -0,0 +1,87 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+static __thread int dummy = 12;
+__thread struct A a1 = { 4, 5, 6 };
+__thread struct A a3 __attribute__((tls_model("initial-exec")))
+ = { 10, 11, 12 };
+extern __thread struct A a4 __attribute__((tls_model("initial-exec")));
+static __thread struct A local1 = { 16, 17, 18 };
+static __thread struct A local2 __attribute__((tls_model("initial-exec")))
+ = { 19, 20, 21 };
+
+void check1 (void)
+{
+ if (a1.a != 4 || a1.b != 5 || a1.c != 6)
+ abort ();
+ if (a2.a != 22 || a2.b != 23 || a2.c != 24)
+ abort ();
+ if (a3.a != 10 || a3.b != 11 || a3.c != 12)
+ abort ();
+ if (a4.a != 25 || a4.b != 26 || a4.c != 27)
+ abort ();
+ if (local1.a != 16 || local1.b != 17 || local1.c != 18)
+ abort ();
+ if (local2.a != 19 || local2.b != 20 || local2.c != 21)
+ abort ();
+}
+
+struct A *f1a (void)
+{
+ return &a1;
+}
+
+struct A *f2a (void)
+{
+ return &a2;
+}
+
+struct A *f3a (void)
+{
+ return &a3;
+}
+
+struct A *f4a (void)
+{
+ return &a4;
+}
+
+struct A *f5a (void)
+{
+ return &local1;
+}
+
+struct A *f6a (void)
+{
+ return &local2;
+}
+
+int f1b (void)
+{
+ return a1.a;
+}
+
+int f2b (void)
+{
+ return a2.b;
+}
+
+int f3b (void)
+{
+ return a3.c;
+}
+
+int f4b (void)
+{
+ return a4.a;
+}
+
+int f5b (void)
+{
+ return local1.b;
+}
+
+int f6b (void)
+{
+ return local2.c;
+}
diff --git a/trunk/testsuite/tls3.sh b/trunk/testsuite/tls3.sh
new file mode 100755
index 0000000..e7270e9
--- /dev/null
+++ b/trunk/testsuite/tls3.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# First check if __thread is supported by ld.so/gcc/ld/as:
+rm -f tlstest
+#echo '__thread int a; int main (void) { return a; }' \
+# | $CC -xc - -o tlstest > /dev/null 2>&1 || exit 77
+#( ./tlstest || { rm -f tlstest; exit 77; } ) 2>/dev/null || exit 77
+SHFLAGS=
+case "`uname -m`" in
+ ia64|ppc*|x86_64|alpha*|s390*|mips*) SHFLAGS=-fpic;; # Does not support non-pic shared libs
+esac
+rm -f tls3 tls3lib*.so tls3.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o tls3lib1.so $srcdir/tls1lib1.c
+$CC -shared -O2 $SHFLAGS -o tls3lib2.so $srcdir/tls3lib2.c \
+ tls3lib1.so 2>/dev/null
+BINS="tls3"
+LIBS="tls3lib1.so tls3lib2.so"
+$CCLINK -o tls3 $srcdir/tls1.c -Wl,--rpath-link,. tls3lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls3 > tls3.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls3 >> tls3.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` tls3.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls3 || exit 3
+fi
+readelf -a ./tls3 >> tls3.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./tls3
+comparelibs >> tls3.log 2>&1 || exit 5
diff --git a/trunk/testsuite/tls3lib2.c b/trunk/testsuite/tls3lib2.c
new file mode 100644
index 0000000..ba485d3
--- /dev/null
+++ b/trunk/testsuite/tls3lib2.c
@@ -0,0 +1,68 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+asm (".section trampoline, \"awx\"; .previous");
+
+#if !defined __sparc__ || defined __pic__ || defined __PIC__
+#define ieattr __attribute__((tls_model("initial-exec")))
+#else
+#define ieattr
+#endif
+
+static __thread long long dummy = 12;
+__thread struct A a2 = { 22, 23, 24 };
+__thread struct A a4 ieattr = { 25, 26, 27 };
+static __thread struct A local1 = { 28, 29, 30 };
+static __thread struct A local2 ieattr = { 31, 32, 33 };
+
+void __attribute__((section ("trampoline"))) check2 (void)
+{
+ if (a2.a != 22 || a2.b != 23 || a2.c != 24)
+ abort ();
+ if (a4.a != 25 || a4.b != 26 || a4.c != 27)
+ abort ();
+ if (local1.a != 28 || local1.b != 29 || local1.c != 30)
+ abort ();
+ if (local2.a != 31 || local2.b != 32 || local2.c != 33)
+ abort ();
+}
+
+struct A * __attribute__((section ("trampoline"))) f7a (void)
+{
+ return &a2;
+}
+
+struct A * __attribute__((section ("trampoline"))) f8a (void)
+{
+ return &a4;
+}
+
+struct A * __attribute__((section ("trampoline"))) f9a (void)
+{
+ return &local1;
+}
+
+struct A * __attribute__((section ("trampoline"))) f10a (void)
+{
+ return &local2;
+}
+
+int __attribute__((section ("trampoline"))) f7b (void)
+{
+ return a2.b;
+}
+
+int __attribute__((section ("trampoline"))) f8b (void)
+{
+ return a4.a;
+}
+
+int __attribute__((section ("trampoline"))) f9b (void)
+{
+ return local1.b;
+}
+
+int __attribute__((section ("trampoline"))) f10b (void)
+{
+ return local2.c;
+}
diff --git a/trunk/testsuite/tls4.c b/trunk/testsuite/tls4.c
new file mode 100644
index 0000000..0882f07
--- /dev/null
+++ b/trunk/testsuite/tls4.c
@@ -0,0 +1,16 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+#define CHECK(N, S) \
+ p = &a##N; \
+ if (p->a != S || p->b != S + 1 || p->c != S + 2) \
+ abort ()
+
+int main()
+{
+ struct A *p;
+ check1 ();
+ CHECK (1, 4);
+ CHECK (2, 7);
+ exit (0);
+}
diff --git a/trunk/testsuite/tls4.sh b/trunk/testsuite/tls4.sh
new file mode 100755
index 0000000..e6bdde2
--- /dev/null
+++ b/trunk/testsuite/tls4.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# First check if __thread is supported by ld.so/gcc/ld/as:
+rm -f tlstest
+#echo '__thread int a; int main (void) { return a; }' \
+# | $CC -xc - -o tlstest > /dev/null 2>&1 || exit 77
+#( ./tlstest || { rm -f tlstest; exit 77; } ) 2>/dev/null || exit 77
+rm -f tls4 tls4lib*.so tls4.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o tls4lib1.so $srcdir/tls4lib1.c
+$CC -shared -O2 -fpic -o tls4lib2.so $srcdir/tls4lib2.c \
+ tls4lib1.so 2>/dev/null
+BINS="tls4"
+LIBS="tls4lib1.so tls4lib2.so"
+$CCLINK -o tls4 $srcdir/tls4.c -Wl,--rpath-link,. tls4lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls4 > tls4.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls4 >> tls4.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` tls4.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls4 || exit 3
+fi
+readelf -a ./tls4 >> tls4.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./tls4
+comparelibs >> tls4.log 2>&1 || exit 5
diff --git a/trunk/testsuite/tls4lib1.c b/trunk/testsuite/tls4lib1.c
new file mode 100644
index 0000000..a03af0b
--- /dev/null
+++ b/trunk/testsuite/tls4lib1.c
@@ -0,0 +1,5 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+__thread struct A a1 = { 4, 5, 6 };
+__thread struct A a2 = { 7, 8, 9 };
diff --git a/trunk/testsuite/tls4lib2.c b/trunk/testsuite/tls4lib2.c
new file mode 100644
index 0000000..309504b
--- /dev/null
+++ b/trunk/testsuite/tls4lib2.c
@@ -0,0 +1,12 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+extern __thread struct A a2 __attribute__((tls_model("initial-exec")));
+
+void check1 (void)
+{
+ if (a1.a != 4 || a1.b != 5 || a1.c != 6)
+ abort ();
+ if (a2.a != 7 || a2.b != 8 || a2.c != 9)
+ abort ();
+}
diff --git a/trunk/testsuite/tls5.sh b/trunk/testsuite/tls5.sh
new file mode 100755
index 0000000..68ec82f
--- /dev/null
+++ b/trunk/testsuite/tls5.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# First check if __thread is supported by ld.so/gcc/ld/as:
+rm -f tlstest
+#echo '__thread int a; int main (void) { return a; }' \
+# | $CC -xc - -o tlstest > /dev/null 2>&1 || exit 77
+#( ./tlstest || { rm -f tlstest; exit 77; } ) 2>/dev/null || exit 77
+rm -f tls5 tls5lib*.so tls5.log
+rm -f prelink.cache
+echo 'int tls5;' | $CC -shared -O2 -fpic -xc - -o tls5lib3.so
+$CC -shared -O2 -fpic -o tls5lib1.so $srcdir/tls5lib1.c tls5lib3.so
+$CC -shared -O2 -fpic -o tls5lib2.so $srcdir/tls1lib2.c \
+ -Wl,--rpath-link,. tls5lib1.so
+BINS="tls5"
+LIBS="tls5lib1.so tls5lib2.so tls5lib3.so"
+$CCLINK -o tls5 $srcdir/tls1.c -Wl,--rpath-link,. tls5lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls5 > tls5.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls5 >> tls5.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` tls5.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls5 || exit 3
+fi
+$PRELINK -u tls5lib3.so || exit 4
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls5 >> tls5.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls5 >> tls5.log 2>&1 || exit 5
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` tls5.log && exit 6
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls5 || exit 7
+fi
+readelf -a ./tls5 >> tls5.log 2>&1 || exit 8
+# So that it is not prelinked again
+chmod -x ./tls5
+comparelibs >> tls5.log 2>&1 || exit 9
diff --git a/trunk/testsuite/tls5lib1.c b/trunk/testsuite/tls5lib1.c
new file mode 100644
index 0000000..9677848
--- /dev/null
+++ b/trunk/testsuite/tls5lib1.c
@@ -0,0 +1,96 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+static __thread int dummy = 12;
+__thread struct A a1 = { 4, 5, 6 };
+__thread struct A a2 = { 7, 8, 9 };
+__thread struct A a3 __attribute__((tls_model("initial-exec")))
+ = { 10, 11, 12 };
+__thread struct A a4 __attribute__((tls_model("initial-exec")))
+ = { 13, 14, 15 };
+static __thread struct A local1 = { 16, 17, 18 };
+static __thread struct A local2 __attribute__((tls_model("initial-exec")))
+ = { 19, 20, 21 };
+struct Z { char a; struct Z *b; int *c; };
+int y[2];
+struct Z z[2] = { { 1, &z[1], &y[0] }, { 2, &z[0], &y[1] } };
+
+void check1 (void)
+{
+ if (a1.a != 4 || a1.b != 5 || a1.c != 6)
+ abort ();
+ if (a2.a != 22 || a2.b != 23 || a2.c != 24)
+ abort ();
+ if (a3.a != 10 || a3.b != 11 || a3.c != 12)
+ abort ();
+ if (a4.a != 25 || a4.b != 26 || a4.c != 27)
+ abort ();
+ if (local1.a != 16 || local1.b != 17 || local1.c != 18)
+ abort ();
+ if (local2.a != 19 || local2.b != 20 || local2.c != 21)
+ abort ();
+ if (z[0].a != 1 || z[0].b != &z[1] || z[0].c != &y[0])
+ abort ();
+ if (z[1].a != 2 || z[1].b != &z[0] || z[1].c != &y[1])
+ abort ();
+}
+
+struct A *f1a (void)
+{
+ return &a1;
+}
+
+struct A *f2a (void)
+{
+ return &a2;
+}
+
+struct A *f3a (void)
+{
+ return &a3;
+}
+
+struct A *f4a (void)
+{
+ return &a4;
+}
+
+struct A *f5a (void)
+{
+ return &local1;
+}
+
+struct A *f6a (void)
+{
+ return &local2;
+}
+
+int f1b (void)
+{
+ return a1.a;
+}
+
+int f2b (void)
+{
+ return a2.b;
+}
+
+int f3b (void)
+{
+ return a3.c;
+}
+
+int f4b (void)
+{
+ return a4.a;
+}
+
+int f5b (void)
+{
+ return local1.b;
+}
+
+int f6b (void)
+{
+ return local2.c;
+}
diff --git a/trunk/testsuite/tls6.sh b/trunk/testsuite/tls6.sh
new file mode 100755
index 0000000..60ae492
--- /dev/null
+++ b/trunk/testsuite/tls6.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# First check if __thread is supported by ld.so/gcc/ld/as:
+rm -f tlstest
+#echo '__thread int a; int main (void) { return a; }' \
+# | $CC -xc - -o tlstest > /dev/null 2>&1 || exit 77
+#( ./tlstest || { rm -f tlstest; exit 77; } ) 2>/dev/null || exit 77
+rm -f tls6 tls6lib*.so tls6.log
+rm -f prelink.cache
+echo 'int tls6;' | $CC -shared -O2 -fpic -xc - -o tls6lib3.so
+$CC -shared -O2 -fpic -o tls6lib1.so $srcdir/tls6lib1.c tls6lib3.so
+$CC -shared -O2 -fpic -o tls6lib2.so $srcdir/tls1lib2.c \
+ -Wl,--rpath-link,. tls6lib1.so
+BINS="tls6"
+LIBS="tls6lib1.so tls6lib2.so tls6lib3.so"
+$CCLINK -o tls6 $srcdir/tls2.c -Wl,--rpath-link,. tls6lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls6 > tls6.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls6 >> tls6.log 2>&1 || exit 1
+grep -v 'has undefined non-weak symbols' tls6.log \
+ | grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls6 || exit 3
+fi
+$PRELINK -u tls6lib3.so || exit 4
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls6 >> tls6.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls6 >> tls6.log 2>&1 || exit 5
+grep -v 'has undefined non-weak symbols' tls6.log \
+ | grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` && exit 6
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls6 || exit 7
+fi
+readelf -a ./tls6 >> tls6.log 2>&1 || exit 8
+# So that it is not prelinked again
+chmod -x ./tls6
+comparelibs >> tls6.log 2>&1 || exit 9
diff --git a/trunk/testsuite/tls6lib1.c b/trunk/testsuite/tls6lib1.c
new file mode 100644
index 0000000..5310c06
--- /dev/null
+++ b/trunk/testsuite/tls6lib1.c
@@ -0,0 +1,94 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+static __thread int dummy = 12;
+__thread struct A a1 = { 4, 5, 6 };
+__thread struct A a3 __attribute__((tls_model("initial-exec")))
+ = { 10, 11, 12 };
+extern __thread struct A a4 __attribute__((tls_model("initial-exec")));
+static __thread struct A local1 = { 16, 17, 18 };
+static __thread struct A local2 __attribute__((tls_model("initial-exec")))
+ = { 19, 20, 21 };
+struct Z { char a; struct Z *b; int *c; };
+int y[2];
+struct Z z[2] = { { 1, &z[1], &y[0] }, { 2, &z[0], &y[1] } };
+
+void check1 (void)
+{
+ if (a1.a != 4 || a1.b != 5 || a1.c != 6)
+ abort ();
+ if (a2.a != 22 || a2.b != 23 || a2.c != 24)
+ abort ();
+ if (a3.a != 10 || a3.b != 11 || a3.c != 12)
+ abort ();
+ if (a4.a != 25 || a4.b != 26 || a4.c != 27)
+ abort ();
+ if (local1.a != 16 || local1.b != 17 || local1.c != 18)
+ abort ();
+ if (local2.a != 19 || local2.b != 20 || local2.c != 21)
+ abort ();
+ if (z[0].a != 1 || z[0].b != &z[1] || z[0].c != &y[0])
+ abort ();
+ if (z[1].a != 2 || z[1].b != &z[0] || z[1].c != &y[1])
+ abort ();
+}
+
+struct A *f1a (void)
+{
+ return &a1;
+}
+
+struct A *f2a (void)
+{
+ return &a2;
+}
+
+struct A *f3a (void)
+{
+ return &a3;
+}
+
+struct A *f4a (void)
+{
+ return &a4;
+}
+
+struct A *f5a (void)
+{
+ return &local1;
+}
+
+struct A *f6a (void)
+{
+ return &local2;
+}
+
+int f1b (void)
+{
+ return a1.a;
+}
+
+int f2b (void)
+{
+ return a2.b;
+}
+
+int f3b (void)
+{
+ return a3.c;
+}
+
+int f4b (void)
+{
+ return a4.a;
+}
+
+int f5b (void)
+{
+ return local1.b;
+}
+
+int f6b (void)
+{
+ return local2.c;
+}
diff --git a/trunk/testsuite/tls7.c b/trunk/testsuite/tls7.c
new file mode 100644
index 0000000..4a3db24
--- /dev/null
+++ b/trunk/testsuite/tls7.c
@@ -0,0 +1,10 @@
+#include "tls1.h"
+#include <stdlib.h>
+
+static __thread int dummy;
+__thread struct A local;
+
+int main()
+{
+ exit (dummy + local.a + local.b + local.c);
+}
diff --git a/trunk/testsuite/tls7.sh b/trunk/testsuite/tls7.sh
new file mode 100755
index 0000000..216a379
--- /dev/null
+++ b/trunk/testsuite/tls7.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+# First check if __thread is supported by ld.so/gcc/ld/as:
+rm -f tlstest
+#echo '__thread int a; int main (void) { return a; }' \
+# | $CC -xc - -o tlstest > /dev/null 2>&1 || exit 77
+#( ./tlstest || { rm -f tlstest; exit 77; } ) 2>/dev/null || exit 77
+rm -f tls7 tls7.log
+rm -f prelink.cache
+BINS="tls7"
+LIBS=""
+$CCLINK -o tls7 $srcdir/tls7.c
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./tls7 > tls7.log
+$PRELINK ${PRELINK_OPTS--vm} ./tls7 >> tls7.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` tls7.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./tls7 || exit 3
+fi
+readelf -a ./tls7 >> tls7.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./tls7
+comparelibs >> tls7.log 2>&1 || exit 5
diff --git a/trunk/testsuite/undo1.sh b/trunk/testsuite/undo1.sh
new file mode 100755
index 0000000..ed61b6b
--- /dev/null
+++ b/trunk/testsuite/undo1.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+rm -f undo1 undo1lib*.so undo1.log
+rm -f prelink.cache
+$CC -shared -O2 -fpic -o undo1lib1.so $srcdir/reloc1lib1.c
+$CC -shared -O2 -fpic -o undo1lib2.so $srcdir/reloc1lib2.c undo1lib1.so
+BINS="undo1"
+LIBS="undo1lib1.so undo1lib2.so"
+$CCLINK -o undo1 $srcdir/reloc1.c -Wl,--rpath-link,. undo1lib2.so
+savelibs
+echo $PRELINK ${PRELINK_OPTS--vm} ./undo1 > undo1.log
+$PRELINK ${PRELINK_OPTS--vm} ./undo1 >> undo1.log 2>&1 || exit 1
+grep -q ^`echo $PRELINK | sed 's/ .*$/: /'` undo1.log && exit 2
+if [ "x$CROSS" = "x" ]; then
+ LD_LIBRARY_PATH=. ./undo1 || exit 3
+fi
+readelf -a ./undo1 >> undo1.log 2>&1 || exit 4
+# So that it is not prelinked again
+chmod -x ./undo1
+echo $PRELINK -uo undo1.undo undo1 >> undo1.log
+$PRELINK -uo undo1.undo undo1 >> undo1.log 2>&1 || exit 5
+cmp -s undo1.undo undo1.orig >> undo1.log 2>&1 || exit 6
+rm -f undo1.undo
+comparelibs >> undo1.log 2>&1 || exit 7
diff --git a/trunk/testsuite/undosyslibs.sh b/trunk/testsuite/undosyslibs.sh
new file mode 100755
index 0000000..1ce136d
--- /dev/null
+++ b/trunk/testsuite/undosyslibs.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+. `dirname $0`/functions.sh
+LIBS=`cat syslib.list`
+comparelibs >> undosyslibs.log 2>&1 || exit 1