]> git.saurik.com Git - apple/dyld.git/blob - unit-tests/test-cases/dlopen-RTLD_LOCAL-ignore/main.c
dyld-360.22.tar.gz
[apple/dyld.git] / unit-tests / test-cases / dlopen-RTLD_LOCAL-ignore / main.c
1 /*
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #include <stdio.h> // fprintf(), NULL
24 #include <stdlib.h> // exit(), EXIT_SUCCESS
25 #include <string.h>
26 #include <dlfcn.h>
27
28 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
29
30
31
32 int main(int argc, const char* argv[])
33 {
34 // main alreadly links with foo.dylib
35 // now dynamically link with bar.dylib
36 void* handle = dlopen("./bar.dylib", RTLD_GLOBAL);
37 if ( handle == NULL ) {
38 const char* msg = dlerror();
39 FAIL("dlopen(\"%s\", RTLD_GLOBAL) failed: %s", argv[1], msg);
40 return EXIT_SUCCESS;
41 }
42
43 // verify we can find _foo
44 void* fooSym = dlsym(RTLD_DEFAULT, "foo");
45 if ( fooSym == NULL ) {
46 const char* msg = dlerror();
47 FAIL("dlsym(RTLD_DEFAULT, \"foo\") failed: %s", msg);
48 return EXIT_SUCCESS;
49 }
50
51 // verify we can find _bar
52 void* barSym = dlsym(RTLD_DEFAULT, "bar");
53 if ( barSym == NULL ) {
54 const char* msg = dlerror();
55 FAIL("dlsym(RTLD_DEFAULT, \"bar\") failed: %s", msg);
56 return EXIT_SUCCESS;
57 }
58
59 // open foo privately (since it was already opened global, RTLD_LOCAL should have no effect
60 void* handleFoo = dlopen("./foo.dylib", RTLD_LOCAL);
61 if ( handleFoo == NULL ) {
62 const char* msg = dlerror();
63 FAIL("dlopen(\"%s\", RTLD_LOCAL) failed: %s", "./foo.dylib", msg);
64 return EXIT_SUCCESS;
65 }
66
67 // open foo privately (since it was already opened global, RTLD_LOCAL should have no effect
68 void* handleBar = dlopen("./bar.dylib", RTLD_LOCAL);
69 if ( handleBar == NULL ) {
70 const char* msg = dlerror();
71 FAIL("dlopen(\"%s\", RTLD_LOCAL) failed: %s", "./bar.dylib", msg);
72 return EXIT_SUCCESS;
73 }
74
75 // verify we can still find _foo
76 fooSym = dlsym(RTLD_DEFAULT, "foo");
77 if ( fooSym == NULL ) {
78 const char* msg = dlerror();
79 FAIL("dlsym(RTLD_DEFAULT, \"foo\") failed: %s", msg);
80 return EXIT_SUCCESS;
81 }
82
83 // verify we can still find _bar
84 barSym = dlsym(RTLD_DEFAULT, "bar");
85 if ( barSym == NULL ) {
86 const char* msg = dlerror();
87 FAIL("dlsym(RTLD_DEFAULT, \"bar\") failed: %s", msg);
88 return EXIT_SUCCESS;
89 }
90
91 PASS("dlopen-RTLD_LOCAL-ignore");
92 return EXIT_SUCCESS;
93 }