+1999-01-20 Ulrich Drepper <drepper@cygnus.com>
+
+ * elf/Makefile (tests): Add preloadtest. Add rules to build more test
+ modules and the preloadtest binary.
+ * elf/loadtest.c (TEST_ROUNDS): Increase to 1000.
+ (testobjs): Add more modules.
+ (tests): Add entries for new modules.
+ * elf/preloadtest.c: New file. Test for LD_PRELOAD.
+ * elf/testobj1.c: Add 'preload' function.
+ * elf/testobj2.c: Likewise.
+ * elf/testobj3.c: Likewise.
+ * elf/testobj4.c: New file.
+ * elf/testobj5.c: New file.
+ * elf/testobj6.c: New file.
+
1999-01-19 Ulrich Drepper <drepper@cygnus.com>
* elf/dl-object.c (_dl_new_object): Micro-optimization.
install-rootsbin += ldconfig
endif
-tests = loadtest restest1
+tests = loadtest restest1 preloadtest
include ../Rules
$(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
endef
-modules-names = testobj1 testobj2 testobj3 testobj1_1
+modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
+ testobj1_1
test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
generated += $(test-modules)
+LDLIBS-testobj1.so = -ldl
$(objpfx)testobj1_1.so: $(objpfx)testobj1.so
LDLIBS-testobj1_1.so = $(objpfx)testobj1.so
$(objpfx)testobj2.so: $(objpfx)testobj1.so
-LDLIBS-testobj2.so = $(objpfx)testobj1.so
+LDLIBS-testobj2.so = $(objpfx)testobj1.so -ldl
+LDLIBS-testobj3.so = -ldl
+LDLIBS-testobj4.so = -ldl
+LDLIBS-testobj5.so = -ldl
+LDLIBS-testobj6.so = -ldl
$(test-modules): $(objpfx)%.so: %.c
$(build-module)
LDFLAGS-restest1 = -rdynamic $(objpfx)testobj1.so $(objpfx)testobj1_1.so
$(objpfx)restest1.out: $(test-modules)
+
+$(objpfx)preloadtest.out: $(test-modules)
+LDFLAGS-preloadtest = -rdynamic $(objpfx)testobj6.so
+preloadtest-ENV = LD_PRELOAD=testobj1.so:testobj2.so:testobj3.so:testobj4.so:testobj5.so
\f
# muwahaha
/* How many load/unload operations do we do. */
-#define TEST_ROUNDS 100
+#define TEST_ROUNDS 1000
static struct
{ "testobj1.so", NULL },
{ "testobj2.so", NULL },
{ "testobj3.so", NULL },
+ { "testobj4.so", NULL },
+ { "testobj5.so", NULL },
+ { "testobj6.so", NULL },
};
#define NOBJS (sizeof (testobjs) / sizeof (testobjs[0]))
{ "obj3func1", 2, RTLD_LAZY | RTLD_GLOBAL },
{ "obj3func1", 2, RTLD_NOW },
{ "obj3func2", 2, RTLD_NOW | RTLD_GLOBAL },
+ { "obj4func2", 3, RTLD_LAZY },
+ { "obj4func1", 3, RTLD_LAZY | RTLD_GLOBAL },
+ { "obj4func1", 3, RTLD_NOW },
+ { "obj4func2", 3, RTLD_NOW | RTLD_GLOBAL },
+ { "obj5func2", 4, RTLD_LAZY },
+ { "obj5func1", 4, RTLD_LAZY | RTLD_GLOBAL },
+ { "obj5func1", 4, RTLD_NOW },
+ { "obj5func2", 4, RTLD_NOW | RTLD_GLOBAL },
+ { "obj6func2", 5, RTLD_LAZY },
+ { "obj6func1", 5, RTLD_LAZY | RTLD_GLOBAL },
+ { "obj6func1", 5, RTLD_NOW },
+ { "obj6func2", 5, RTLD_NOW | RTLD_GLOBAL },
};
#define NTESTS (sizeof (tests) / sizeof (tests[0]))
--- /dev/null
+#include <stdio.h>
+
+extern int preload (int);
+
+int
+main (void)
+{
+ int res = preload (42);
+
+ printf ("preload (42) = %d, %s\n", res, res == 92 ? "ok" : "wrong");
+
+ return res != 92;
+}
+
+int
+foo (int a)
+{
+ return a;
+}
+#include <dlfcn.h>
+
int
obj1func1 (int a __attribute__ ((unused)))
{
{
return foo (a) + 10;
}
+
+int
+preload (int a)
+{
+ int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
+ if (fp != NULL)
+ return fp (a) + 10;
+ return 10;
+}
+#include <dlfcn.h>
+
int
obj2func1 (int a __attribute__ ((unused)))
{
{
return obj1func1 (a) + 10;
}
+
+int
+preload (int a)
+{
+ int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
+ if (fp != NULL)
+ return fp (a) + 10;
+ return 10;
+}
+#include <dlfcn.h>
+
int
obj3func1 (int a __attribute__ ((unused)))
{
{
return foo (a) + 42;
}
+
+int
+preload (int a)
+{
+ int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
+ if (fp != NULL)
+ return fp (a) + 10;
+ return 10;
+}
--- /dev/null
+#include <dlfcn.h>
+
+int
+obj4func1 (int a __attribute__ ((unused)))
+{
+ return 55;
+}
+
+int
+obj4func2 (int a)
+{
+ return foo (a) + 43;
+}
+
+int
+preload (int a)
+{
+ int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
+ if (fp != NULL)
+ return fp (a) + 10;
+ return 10;
+}
--- /dev/null
+#include <dlfcn.h>
+
+int
+obj5func1 (int a __attribute__ ((unused)))
+{
+ return 66;
+}
+
+int
+obj5func2 (int a)
+{
+ return foo (a) + 44;
+}
+
+int
+preload (int a)
+{
+ int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
+ if (fp != NULL)
+ return fp (a) + 10;
+ return 10;
+}
--- /dev/null
+int
+obj6func1 (int a __attribute__ ((unused)))
+{
+ return 77;
+}
+
+int
+obj6func2 (int a)
+{
+ return foo (a) + 46;
+}
+
+int
+preload (int a)
+{
+ return a;
+}