1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

regression test for lazy binding.

"people need never hold off on adding stuff to regress" deraadt@
This commit is contained in:
matthieu 2008-01-02 18:36:59 +00:00
parent f1a76e771b
commit 20dfae2598
9 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,7 @@
# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
SUBDIR += libfoo libbar prog
install:
.include <bsd.subdir.mk>

View File

@ -0,0 +1,8 @@
# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
LIB= bar
SRCS= bar.c
regress: all
.include <bsd.lib.mk>

View File

@ -0,0 +1,11 @@
/* $OpenBSD: bar.c,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $ */
/* Public Domain, 2008, Matthieu Herrb */
#include <stdio.h>
int
bar(void)
{
printf("bar\n");
return 0;
}

View File

@ -0,0 +1,2 @@
major=0
minor=0

View File

@ -0,0 +1,18 @@
# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
.include <bsd.obj.mk>
LIB= foo
SRCS= foo.c
BARDIR!= if test -d ${.CURDIR}/../libbar/${__objdir}; then \
echo "${.CURDIR}/../libbar/${__objdir}"; \
else \
echo "${.CURDIR}/../libbar"; \
fi
CPPFLAGS= -DBAR=\"${BARDIR}/libbar.so\"
regress: all
.include <bsd.lib.mk>

View File

@ -0,0 +1,26 @@
/* $OpenBSD: foo.c,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $ */
/* Public domain. 2008, Matthieu Herrb */
#include <dlfcn.h>
#include <stdio.h>
static void *h = NULL;
void
foo_init(void)
{
printf("loading %s\n", BAR);
h = dlopen(BAR, RTLD_LAZY|RTLD_GLOBAL);
if (h == NULL)
errx(1, "dlopen %s: %s\n", BAR, dlerror());
printf("loaded: %s\n", BAR);
}
int
foo(void)
{
if (h == NULL)
foo_init();
return bar();
}

View File

@ -0,0 +1,2 @@
major=0
minor=0

View File

@ -0,0 +1,15 @@
# $OpenBSD: Makefile,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $
.include <bsd.obj.mk>
PROG= prog
FOODIR!= if test -d ${.CURDIR}/../libfoo/${__objdir}; then \
echo "${.CURDIR}/../libfoo/${__objdir}"; \
else \
echo "${.CURDIR}/../libfoo"; \
fi
CPPFLAGS= -DFOO=\"${FOODIR}/libfoo.so\"
.include <bsd.regress.mk>

View File

@ -0,0 +1,29 @@
/* $OpenBSD: prog.c,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $ */
/* Public Domain, 2008, Matthieu Herrb */
#include <dlfcn.h>
#include <stdio.h>
void *handle = NULL;
typedef int (*foofunc)(void);
int
main(int argc, char *argv[])
{
foofunc foo;
int i;
printf("loading: %s\n", FOO);
handle = dlopen(FOO, RTLD_LAZY|RTLD_GLOBAL);
if (handle == NULL) {
errx(1, "dlopen: %s: %s\n", FOO, dlerror());
}
printf("loaded: %s\n", FOO);
printf("looking up foo\n");
foo = (foofunc)dlsym(handle, "foo");
printf("found %p - calling it\n", foo);
i = foo();
printf("done.\n");
exit(i);
}