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.
This commit is contained in:
Ulrich Drepper 1999-01-20 00:34:52 +00:00
parent b25d4ff04d
commit 3d91edb219
10 changed files with 157 additions and 4 deletions

View file

@ -1,3 +1,18 @@
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.

View file

@ -75,7 +75,7 @@ others += ldconfig
install-rootsbin += ldconfig
endif
tests = loadtest restest1
tests = loadtest restest1 preloadtest
include ../Rules
@ -214,14 +214,20 @@ $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
$(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)
@ -235,6 +241,10 @@ $(objpfx)restest1: $(objpfx)libdl.so
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
# muwahaha

View file

@ -7,7 +7,7 @@
/* How many load/unload operations do we do. */
#define TEST_ROUNDS 100
#define TEST_ROUNDS 1000
static struct
@ -21,6 +21,9 @@ 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]))
@ -47,6 +50,18 @@ static const struct
{ "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]))

19
elf/preloadtest.c Normal file
View file

@ -0,0 +1,19 @@
#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;
}

View file

@ -1,3 +1,5 @@
#include <dlfcn.h>
int
obj1func1 (int a __attribute__ ((unused)))
{
@ -9,3 +11,12 @@ obj1func2 (int a)
{
return foo (a) + 10;
}
int
preload (int a)
{
int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
if (fp != NULL)
return fp (a) + 10;
return 10;
}

View file

@ -1,3 +1,5 @@
#include <dlfcn.h>
int
obj2func1 (int a __attribute__ ((unused)))
{
@ -9,3 +11,12 @@ obj2func2 (int a)
{
return obj1func1 (a) + 10;
}
int
preload (int a)
{
int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
if (fp != NULL)
return fp (a) + 10;
return 10;
}

View file

@ -1,3 +1,5 @@
#include <dlfcn.h>
int
obj3func1 (int a __attribute__ ((unused)))
{
@ -9,3 +11,12 @@ obj3func2 (int a)
{
return foo (a) + 42;
}
int
preload (int a)
{
int (*fp) (int) = dlsym (RTLD_NEXT, "preload");
if (fp != NULL)
return fp (a) + 10;
return 10;
}

22
elf/testobj4.c Normal file
View file

@ -0,0 +1,22 @@
#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;
}

22
elf/testobj5.c Normal file
View file

@ -0,0 +1,22 @@
#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;
}

17
elf/testobj6.c Normal file
View file

@ -0,0 +1,17 @@
int
obj6func1 (int a __attribute__ ((unused)))
{
return 77;
}
int
obj6func2 (int a)
{
return foo (a) + 46;
}
int
preload (int a)
{
return a;
}