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 (libbar.so) with the linker, which depends on
7 // another library (libfoo.so)
8 // - Find the address of the "Bar" function in libbar.so.
9 // - Call the Bar() function, which ends up calling Foo() in libfoo.so
10 // - Close the library.
13 #include <crazy_linker.h>
15 #include "test_util.h"
17 typedef void (*FunctionPtr
)();
20 crazy_context_t
* context
= crazy_context_create();
21 crazy_library_t
* library
;
24 crazy_context_set_load_address(context
, 0x20000000);
27 if (!crazy_library_open(&library
, "libbar.so", context
)) {
28 Panic("Could not open library: %s\n", crazy_context_get_error(context
));
31 // Find the "Bar" symbol.
33 if (!crazy_library_find_symbol(
34 library
, "Bar", reinterpret_cast<void**>(&bar_func
))) {
35 Panic("Could not find 'Bar' in libbar.so\n");
41 // Find the "Foo" symbol from libbar.so
43 if (!crazy_library_find_symbol(
44 library
, "Foo", reinterpret_cast<void**>(&foo_func
))) {
45 Panic("Could not find 'Foo' from libbar.so\n");
49 printf("Closing libbar.so\n");
50 crazy_library_close(library
);
52 crazy_context_destroy(context
);