From f6ba7c6383d734dbd781a6d1b5cc9451658083f8 Mon Sep 17 00:00:00 2001 From: Kurt Miller Date: Wed, 28 Sep 2005 15:42:33 +0000 Subject: two new regresses for dlclose. double dlopen("foo") with single dlclose(foo). mozilla lazy binding example (load_object confusion) --- regress/libexec/ld.so/dlclose/Makefile | 5 +++ regress/libexec/ld.so/dlclose/test1/Makefile | 5 +++ regress/libexec/ld.so/dlclose/test1/Makefile.inc | 19 +++++++++ regress/libexec/ld.so/dlclose/test1/libaa/Makefile | 11 +++++ regress/libexec/ld.so/dlclose/test1/libaa/aa.c | 20 +++++++++ .../ld.so/dlclose/test1/libaa/shlib_version | 2 + regress/libexec/ld.so/dlclose/test1/libbb/Makefile | 8 ++++ regress/libexec/ld.so/dlclose/test1/libbb/bb.c | 45 ++++++++++++++++++++ .../ld.so/dlclose/test1/libbb/shlib_version | 2 + regress/libexec/ld.so/dlclose/test1/prog1/Makefile | 8 ++++ regress/libexec/ld.so/dlclose/test1/prog1/main.c | 48 +++++++++++++++++++++ regress/libexec/ld.so/dlclose/test1/prog2/Makefile | 9 ++++ regress/libexec/ld.so/dlclose/test1/prog2/main.c | 49 ++++++++++++++++++++++ 13 files changed, 231 insertions(+) create mode 100644 regress/libexec/ld.so/dlclose/Makefile create mode 100644 regress/libexec/ld.so/dlclose/test1/Makefile create mode 100644 regress/libexec/ld.so/dlclose/test1/Makefile.inc create mode 100644 regress/libexec/ld.so/dlclose/test1/libaa/Makefile create mode 100644 regress/libexec/ld.so/dlclose/test1/libaa/aa.c create mode 100644 regress/libexec/ld.so/dlclose/test1/libaa/shlib_version create mode 100644 regress/libexec/ld.so/dlclose/test1/libbb/Makefile create mode 100644 regress/libexec/ld.so/dlclose/test1/libbb/bb.c create mode 100644 regress/libexec/ld.so/dlclose/test1/libbb/shlib_version create mode 100644 regress/libexec/ld.so/dlclose/test1/prog1/Makefile create mode 100644 regress/libexec/ld.so/dlclose/test1/prog1/main.c create mode 100644 regress/libexec/ld.so/dlclose/test1/prog2/Makefile create mode 100644 regress/libexec/ld.so/dlclose/test1/prog2/main.c (limited to 'regress/libexec/ld.so/dlclose') diff --git a/regress/libexec/ld.so/dlclose/Makefile b/regress/libexec/ld.so/dlclose/Makefile new file mode 100644 index 00000000000..88bb255992b --- /dev/null +++ b/regress/libexec/ld.so/dlclose/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2005/09/28 15:42:32 kurt Exp $ + +SUBDIR+= test1 + +.include diff --git a/regress/libexec/ld.so/dlclose/test1/Makefile b/regress/libexec/ld.so/dlclose/test1/Makefile new file mode 100644 index 00000000000..68072a1f832 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2005/09/28 15:42:32 kurt Exp $ + +SUBDIR+= libbb libaa prog1 prog2 + +.include diff --git a/regress/libexec/ld.so/dlclose/test1/Makefile.inc b/regress/libexec/ld.so/dlclose/test1/Makefile.inc new file mode 100644 index 00000000000..7950cc7b0f3 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/Makefile.inc @@ -0,0 +1,19 @@ +# $OpenBSD: Makefile.inc,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ + +.include + +AA_DIR=${.CURDIR}/../libaa + +AA_OBJDIR!= if [ -d $(AA_DIR)/${__objdir} ]; then \ + echo "$(AA_DIR)/${__objdir}"; \ + else \ + echo "$(AA_DIR)"; \ + fi + +BB_DIR=${.CURDIR}/../libbb + +BB_OBJDIR!= if [ -d $(BB_DIR)/${__objdir} ]; then \ + echo "$(BB_DIR)/${__objdir}"; \ + else \ + echo "$(BB_DIR)"; \ + fi diff --git a/regress/libexec/ld.so/dlclose/test1/libaa/Makefile b/regress/libexec/ld.so/dlclose/test1/libaa/Makefile new file mode 100644 index 00000000000..1cc2d2ea07d --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/libaa/Makefile @@ -0,0 +1,11 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ + +LIB= aa +SRCS= aa.c +LDADD+= -Wl,-E +LDADD+= -Wl,-rpath,$(BB_OBJDIR) +LDADD+= -L$(BB_OBJDIR) -lbb + +regress: all + +.include diff --git a/regress/libexec/ld.so/dlclose/test1/libaa/aa.c b/regress/libexec/ld.so/dlclose/test1/libaa/aa.c new file mode 100644 index 00000000000..64e3f5e1362 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/libaa/aa.c @@ -0,0 +1,20 @@ +/* $OpenBSD: aa.c,v 1.1 2005/09/28 15:42:32 kurt Exp $ */ + +/* + * Copyright (c) 2005 Kurt Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +int aaSymbol; diff --git a/regress/libexec/ld.so/dlclose/test1/libaa/shlib_version b/regress/libexec/ld.so/dlclose/test1/libaa/shlib_version new file mode 100644 index 00000000000..987ef746955 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/libaa/shlib_version @@ -0,0 +1,2 @@ +major=1 +minor=0 diff --git a/regress/libexec/ld.so/dlclose/test1/libbb/Makefile b/regress/libexec/ld.so/dlclose/test1/libbb/Makefile new file mode 100644 index 00000000000..e3b2464432a --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/libbb/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ + +LIB= bb +SRCS= bb.c + +regress: all + +.include diff --git a/regress/libexec/ld.so/dlclose/test1/libbb/bb.c b/regress/libexec/ld.so/dlclose/test1/libbb/bb.c new file mode 100644 index 00000000000..debccfd76d5 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/libbb/bb.c @@ -0,0 +1,45 @@ +/* $OpenBSD: bb.c,v 1.1 2005/09/28 15:42:32 kurt Exp $ */ + +/* + * Copyright (c) 2005 Kurt Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include +#include + +int bbSymbol; + +void +bbLazyFun() +{ + +} + +int +bbTest1() +{ + int ret = 0; + + /* RTLD_DEFAULT should see bbSymbol */ + if (dlsym(RTLD_DEFAULT, "bbSymbol") == NULL) { + printf("dlsym(RTLD_DEFAULT, \"bbSymbol\") == NULL\n"); + ret = 1; + } + + bbLazyFun(); + + return (ret); +} diff --git a/regress/libexec/ld.so/dlclose/test1/libbb/shlib_version b/regress/libexec/ld.so/dlclose/test1/libbb/shlib_version new file mode 100644 index 00000000000..987ef746955 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/libbb/shlib_version @@ -0,0 +1,2 @@ +major=1 +minor=0 diff --git a/regress/libexec/ld.so/dlclose/test1/prog1/Makefile b/regress/libexec/ld.so/dlclose/test1/prog1/Makefile new file mode 100644 index 00000000000..5c81adf1f43 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/prog1/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ + +PROG= prog1 +SRCS= main.c +LDFLAGS+= -Wl,-E +LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) + +.include diff --git a/regress/libexec/ld.so/dlclose/test1/prog1/main.c b/regress/libexec/ld.so/dlclose/test1/prog1/main.c new file mode 100644 index 00000000000..4807dd57223 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/prog1/main.c @@ -0,0 +1,48 @@ +/* $OpenBSD: main.c,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ */ + +/* + * Copyright (c) 2005 Kurt Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +int +main() +{ + int ret = 0; + void *libaa; + + libaa = dlopen("libaa.so", RTLD_LAZY|RTLD_GLOBAL); + + if (libaa == NULL) { + printf("dlopen(\"libaa.so\", RTLD_LAZY|RTLD_GLOBAL) FAILED\n"); + return (1); + } + + libaa = dlopen("libaa.so", RTLD_LAZY|RTLD_GLOBAL); + + dlclose(libaa); + + /* RTLD_DEFAULT should see aaSymbol */ + if (dlsym(RTLD_DEFAULT, "aaSymbol") == NULL) { + printf("dlsym(RTLD_DEFAULT, \"aaSymbol\") == NULL\n"); + ret = 1; + } + + dlclose(libaa); + + return (ret); +} diff --git a/regress/libexec/ld.so/dlclose/test1/prog2/Makefile b/regress/libexec/ld.so/dlclose/test1/prog2/Makefile new file mode 100644 index 00000000000..c1eb152956d --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/prog2/Makefile @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ + +PROG= prog2 +SRCS= main.c +LDFLAGS+= -Wl,-E +LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) +LDFLAGS+= -Wl,-rpath,$(BB_OBJDIR) + +.include diff --git a/regress/libexec/ld.so/dlclose/test1/prog2/main.c b/regress/libexec/ld.so/dlclose/test1/prog2/main.c new file mode 100644 index 00000000000..bcfef7b59a0 --- /dev/null +++ b/regress/libexec/ld.so/dlclose/test1/prog2/main.c @@ -0,0 +1,49 @@ +/* $OpenBSD: main.c,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ */ + +/* + * Copyright (c) 2005 Kurt Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +int +main() +{ + int ret = 0; + int (*bbTest1)(void); + void *libbb = dlopen("libbb.so", RTLD_LAZY); + void *libaa = dlopen("libaa.so", RTLD_LAZY); + + if (libbb == NULL) { + printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n"); + return (1); + } + + if (libaa == NULL) { + printf("dlopen(\"libaa.so\", RTLD_LAZY) FAILED\n"); + return (1); + } + + bbTest1 = dlsym(libbb, "bbTest1"); + + dlclose(libbb); + + ret = (*bbTest1)(); + + dlclose(libaa); + + return (ret); +} -- cgit v1.2.3