1*430659ebSdrahn /* $OpenBSD: bb.c,v 1.2 2005/09/19 21:50:27 drahn Exp $ */
264c25d97Skurt
364c25d97Skurt /*
464c25d97Skurt * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
564c25d97Skurt *
664c25d97Skurt * Permission to use, copy, modify, and distribute this software for any
764c25d97Skurt * purpose with or without fee is hereby granted, provided that the above
864c25d97Skurt * copyright notice and this permission notice appear in all copies.
964c25d97Skurt *
1064c25d97Skurt * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1164c25d97Skurt * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1264c25d97Skurt * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1364c25d97Skurt * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1464c25d97Skurt * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1564c25d97Skurt * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1664c25d97Skurt * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1764c25d97Skurt */
1864c25d97Skurt
1964c25d97Skurt #include <dlfcn.h>
2064c25d97Skurt #include <stdio.h>
2164c25d97Skurt
2264c25d97Skurt int bbSymbol;
23*430659ebSdrahn int commonSymbol;
2464c25d97Skurt
2564c25d97Skurt /*
2664c25d97Skurt * this test is setup where the main program group dlopen's libbb and libdd
2764c25d97Skurt * without RTLD_GLOBAL. libcc is part of libbb load group. libee is part of
2864c25d97Skurt * libdd load group.
2964c25d97Skurt */
3064c25d97Skurt int
bbTest1(void * libbb,void * libdd)3164c25d97Skurt bbTest1(void *libbb, void *libdd)
3264c25d97Skurt {
3364c25d97Skurt int ret = 0;
3464c25d97Skurt
3564c25d97Skurt /* check RTLD_DEFAULT can *not* see symbols in libdd object group */
3664c25d97Skurt if (dlsym(RTLD_DEFAULT, "ddSymbol") != NULL) {
3764c25d97Skurt printf("dlsym(RTLD_DEFAULT, \"ddSymbol\") != NULL\n");
3864c25d97Skurt ret = 1;
3964c25d97Skurt }
4064c25d97Skurt
4164c25d97Skurt /* check RTLD_SELF can *not* see symbols in libdd object group */
4264c25d97Skurt if (dlsym(RTLD_SELF, "ddSymbol") != NULL) {
4364c25d97Skurt printf("dlsym(RTLD_SELF, \"ddSymbol\") != NULL\n");
4464c25d97Skurt ret = 1;
4564c25d97Skurt }
4664c25d97Skurt
4764c25d97Skurt /* check RTLD_NEXT can *not* see symbols in libdd object group */
4864c25d97Skurt if (dlsym(RTLD_NEXT, "ddSymbol") != NULL) {
4964c25d97Skurt printf("dlsym(RTLD_NEXT, \"ddSymbol\") != NULL\n");
5064c25d97Skurt ret = 1;
5164c25d97Skurt }
5264c25d97Skurt
5364c25d97Skurt /* check NULL can *not* see symbols in libdd object group */
5464c25d97Skurt if (dlsym(NULL, "ddSymbol") != NULL) {
5564c25d97Skurt printf("dlsym(NULL, \"ddSymbol\") != NULL\n");
5664c25d97Skurt ret = 1;
5764c25d97Skurt }
5864c25d97Skurt
5964c25d97Skurt /* libbb should *not* see symbols in libdd or libee */
6064c25d97Skurt if (dlsym(libbb, "ddSymbol") != NULL) {
6164c25d97Skurt printf("dlsym(libbb, \"ddSymbol\") != NULL\n");
6264c25d97Skurt ret = 1;
6364c25d97Skurt }
6464c25d97Skurt
6564c25d97Skurt /* libdd should *not* see symbols in libbb or libcc */
6664c25d97Skurt if (dlsym(libdd, "bbSymbol") != NULL) {
6764c25d97Skurt printf("dlsym(libdd, \"bbSymbol\") != NULL\n");
6864c25d97Skurt ret = 1;
6964c25d97Skurt }
7064c25d97Skurt
7164c25d97Skurt /* libbb should see symbols in libbb and libcc */
7264c25d97Skurt if (dlsym(libbb, "ccSymbol") == NULL) {
7364c25d97Skurt printf("dlsym(libbb, \"ccSymbol\") == NULL\n");
7464c25d97Skurt ret = 1;
7564c25d97Skurt }
7664c25d97Skurt
7764c25d97Skurt /* libdd should see symbols in libbb and libee */
7864c25d97Skurt if (dlsym(libdd, "eeSymbol") == NULL) {
7964c25d97Skurt printf("dlsym(libdd, \"eeSymbol\") == NULL\n");
8064c25d97Skurt ret = 1;
8164c25d97Skurt }
8264c25d97Skurt
8364c25d97Skurt return (ret);
8464c25d97Skurt }
8564c25d97Skurt
8664c25d97Skurt /*
8764c25d97Skurt * this test is setup where the main program group dlopen's libbb and libdd.
8864c25d97Skurt * libdd is opened with RTLD_GLOBAL. libcc is part of libbb load group. libee
8964c25d97Skurt * is part of libdd load group.
9064c25d97Skurt */
9164c25d97Skurt int
bbTest2()9264c25d97Skurt bbTest2()
9364c25d97Skurt {
9464c25d97Skurt int ret = 0;
9564c25d97Skurt
9664c25d97Skurt /* check RTLD_DEFAULT can see symbols in libdd object group */
9764c25d97Skurt if (dlsym(RTLD_DEFAULT, "eeSymbol") != NULL) {
9864c25d97Skurt printf("dlsym(RTLD_DEFAULT, \"ddSymbol\") != NULL\n");
9964c25d97Skurt ret = 1;
10064c25d97Skurt }
10164c25d97Skurt
10264c25d97Skurt /* check RTLD_SELF can see symbols in libdd object group */
10364c25d97Skurt if (dlsym(RTLD_SELF, "eeSymbol") != NULL) {
10464c25d97Skurt printf("dlsym(RTLD_SELF, \"ddSymbol\") != NULL\n");
10564c25d97Skurt ret = 1;
10664c25d97Skurt }
10764c25d97Skurt
10864c25d97Skurt /* check RTLD_NEXT can see symbols in libdd object group */
10964c25d97Skurt if (dlsym(RTLD_NEXT, "eeSymbol") != NULL) {
11064c25d97Skurt printf("dlsym(RTLD_NEXT, \"ddSymbol\") != NULL\n");
11164c25d97Skurt ret = 1;
11264c25d97Skurt }
11364c25d97Skurt
11464c25d97Skurt return (ret);
11564c25d97Skurt }
116