1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // A crazy linker test to:
6 // - Load a library (libzoo.so) with the linker.
7 // - Find the address of the "Zoo" function in libzoo.so.
8 // - Call the Zoo() function, which will use dlopen() / dlsym() to
9 // find libbar.so (which depends on libfoo.so).
10 // - Close the library.
12 // This tests the dlopen/dlsym/dlclose wrappers provided by the crazy
13 // linker to loaded libraries.
16 #include <crazy_linker.h>
18 #include "test_util.h"
20 typedef bool (*FunctionPtr
)();
23 crazy_context_t
* context
= crazy_context_create();
24 crazy_library_t
* library
;
27 if (!crazy_library_open(&library
, "libzoo.so", context
)) {
28 Panic("Could not open library: %s\n", crazy_context_get_error(context
));
31 // Find the "Zoo" symbol.
33 if (!crazy_library_find_symbol(
34 library
, "Zoo", reinterpret_cast<void**>(&zoo_func
))) {
35 Panic("Could not find 'Zoo' in libzoo.so\n");
39 bool ret
= (*zoo_func
)();
41 Panic("'Zoo' function failed!");
44 printf("Closing libzoo.so\n");
45 crazy_library_close(library
);
47 crazy_context_destroy(context
);