diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2005-09-23 19:02:30 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2005-09-23 19:02:30 +0000 |
commit | 402d5d42fc37bea2a77e73ab65ed0b8e29cd42a3 (patch) | |
tree | 7da2748abdd0533ce8212f4ddf2b7316cc4cd022 /regress/libexec/ld.so | |
parent | 79da5b07e676be2caec0827b9ef5d6ff9fd34db7 (diff) |
make sure a undefined weak doesn't interfere with a defined one of the
same name in a different shared lib. also make sure first weak symbol
is selected when duplicates exist.
Diffstat (limited to 'regress/libexec/ld.so')
10 files changed, 198 insertions, 0 deletions
diff --git a/regress/libexec/ld.so/edgecases/test3/Makefile b/regress/libexec/ld.so/edgecases/test3/Makefile new file mode 100644 index 00000000000..3fd50c06ccd --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/23 19:02:29 kurt Exp $ + +SUBDIR+= libbb libaa prog1 + +.include <bsd.subdir.mk> diff --git a/regress/libexec/ld.so/edgecases/test3/Makefile.inc b/regress/libexec/ld.so/edgecases/test3/Makefile.inc new file mode 100644 index 00000000000..45307da615b --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/Makefile.inc @@ -0,0 +1,19 @@ +# $OpenBSD: Makefile.inc,v 1.1.1.1 2005/09/23 19:02:29 kurt Exp $ + +.include <bsd.obj.mk> + +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/edgecases/test3/libaa/Makefile b/regress/libexec/ld.so/edgecases/test3/libaa/Makefile new file mode 100644 index 00000000000..9e02e29fbd5 --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/libaa/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/23 19:02:29 kurt Exp $ + +LIB= aa +SRCS= aa.c + +regress: all + +.include <bsd.lib.mk> diff --git a/regress/libexec/ld.so/edgecases/test3/libaa/aa.c b/regress/libexec/ld.so/edgecases/test3/libaa/aa.c new file mode 100644 index 00000000000..a407ae0f6af --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/libaa/aa.c @@ -0,0 +1,32 @@ +/* $OpenBSD: aa.c,v 1.1.1.1 2005/09/23 19:02:29 kurt Exp $ */ + +/* + * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org> + * + * 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 weakFunction1(void) __attribute__((weak)); + +int weakFunction2(void) __attribute__((weak)); + +/* this function should get called instead of the one in libbb */ +int +weakFunction2() +{ + /* this is just to make sure weakFunction1 is refereed to */ + if (weakFunction1) + weakFunction1(); + + return 0; +} diff --git a/regress/libexec/ld.so/edgecases/test3/libaa/shlib_version b/regress/libexec/ld.so/edgecases/test3/libaa/shlib_version new file mode 100644 index 00000000000..987ef746955 --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/libaa/shlib_version @@ -0,0 +1,2 @@ +major=1 +minor=0 diff --git a/regress/libexec/ld.so/edgecases/test3/libbb/Makefile b/regress/libexec/ld.so/edgecases/test3/libbb/Makefile new file mode 100644 index 00000000000..1d1d82ddaf8 --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/libbb/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/23 19:02:29 kurt Exp $ + +LIB= bb +SRCS= bb.c + +regress: all + +.include <bsd.lib.mk> diff --git a/regress/libexec/ld.so/edgecases/test3/libbb/bb.c b/regress/libexec/ld.so/edgecases/test3/libbb/bb.c new file mode 100644 index 00000000000..85eca098724 --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/libbb/bb.c @@ -0,0 +1,63 @@ +/* $OpenBSD: bb.c,v 1.1 2005/09/23 19:02:29 kurt Exp $ */ + +/* + * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org> + * + * 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 weakFunction1(void) __attribute__((weak)); +int weakFunction2(void) __attribute__((weak)); + +/* this function should be called */ +int +weakFunction1() +{ + return 0; +} + +/* this function should be not be called, the one it libaa should */ +int +weakFunction2() +{ + return 1; +} + +int +bbTest1() +{ + int ret = 0; + + /* + * make sure weakFunction1 from libaa (undefined weak) doesn't + * interfere with calling weakFunction1 here + */ + if (weakFunction1) { + weakFunction1(); + } else { + printf("weakFunction1() overwritten by undefined weak " + "in libaa\n"); + ret = 1; + } + + /* + * make sure weakFunction2 from libaa is called instead of the + * one here + */ + if (weakFunction2()) { + printf("wrong weakFunction2() called\n"); + ret = 1; + } + + return (ret); +} diff --git a/regress/libexec/ld.so/edgecases/test3/libbb/shlib_version b/regress/libexec/ld.so/edgecases/test3/libbb/shlib_version new file mode 100644 index 00000000000..987ef746955 --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/libbb/shlib_version @@ -0,0 +1,2 @@ +major=1 +minor=0 diff --git a/regress/libexec/ld.so/edgecases/test3/prog1/Makefile b/regress/libexec/ld.so/edgecases/test3/prog1/Makefile new file mode 100644 index 00000000000..094ccf36d62 --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/prog1/Makefile @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2005/09/23 19:02:29 kurt Exp $ + +PROG= prog1 +SRCS= main.c +LDFLAGS+= -Wl,-E +LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) +LDFLAGS+= -Wl,-rpath,$(BB_OBJDIR) + +.include <bsd.regress.mk> diff --git a/regress/libexec/ld.so/edgecases/test3/prog1/main.c b/regress/libexec/ld.so/edgecases/test3/prog1/main.c new file mode 100644 index 00000000000..c02ab4c4c15 --- /dev/null +++ b/regress/libexec/ld.so/edgecases/test3/prog1/main.c @@ -0,0 +1,50 @@ +/* $OpenBSD: main.c,v 1.1.1.1 2005/09/23 19:02:29 kurt Exp $ */ + +/* + * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org> + * + * 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 <dlfcn.h> +#include <stdio.h> + +int +main() +{ + int ret = 0; + void *libaa; + void *libbb; + int (*bbTest1)(void); + + libaa = dlopen("libaa.so", RTLD_LAZY|RTLD_GLOBAL); + if (libaa == NULL) { + printf("dlopen(\"libaa.so\", RTLD_LAZY) FAILED\n"); + return (1); + } + + libbb = dlopen("libbb.so", RTLD_LAZY|RTLD_GLOBAL); + if (libbb == NULL) { + printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n"); + return (1); + } + + bbTest1 = dlsym(libbb, "bbTest1"); + + ret = (*bbTest1)(); + + dlclose(libaa); + dlclose(libbb); + + return (ret); +} |