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 (libfoo.so) with the linker.
7 // - Find the address of the "Foo" function in it.
8 // - Call the function.
9 // - Close the library.
12 #include <crazy_linker.h>
14 #include "test_util.h"
16 typedef void (*FunctionPtr
)();
19 crazy_context_t
* context
= crazy_context_create();
20 crazy_library_t
* library
;
23 crazy_context_set_load_address(context
, 0x20000000);
26 if (!crazy_library_open(&library
, "libfoo.so", context
)) {
27 Panic("Could not open library: %s\n", crazy_context_get_error(context
));
30 // Find the "Foo" symbol.
32 if (!crazy_library_find_symbol(
33 library
, "Foo", reinterpret_cast<void**>(&foo_func
))) {
34 Panic("Could not find 'Foo' in libfoo.so\n");
41 printf("Closing libfoo.so\n");
42 crazy_library_close(library
);
44 crazy_context_destroy(context
);