blob: 3ad46c7bc9a73c8d2945854a33a86f4c91fa4f44 [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// A crazy linker test to:
// - Load a library ( with the linker.
// - Find the address of the "Foo" function in it.
// - Call the function.
// - Close the library.
#include <stdio.h>
#include <crazy_linker.h>
#include "test_util.h"
typedef void (*FunctionPtr)();
#ifndef LIB_NAME
#define LIB_NAME ""
int main() {
crazy_context_t* context = crazy_context_create();
crazy_library_t* library;
crazy_context_set_load_address(context, 0x20000000);
// Load
if (!crazy_library_open(&library, LIB_NAME, context)) {
Panic("Could not open library: %s\n", crazy_context_get_error(context));
// Find the "Foo" symbol.
FunctionPtr foo_func;
if (!crazy_library_find_symbol(
library, "Foo", reinterpret_cast<void**>(&foo_func))) {
Panic("Could not find 'Foo' in %s\n", LIB_NAME);
// Call it.
// Close the library.
printf("Closing %s\n", LIB_NAME);
return 0;