Index: third_party/crazy_linker/crazy_linker/tests/zoo.cpp |
diff --git a/third_party/crazy_linker/crazy_linker/tests/zoo.cpp b/third_party/crazy_linker/crazy_linker/tests/zoo.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cedb213fba6f23de0384b22f3a18e255a8d8304f |
--- /dev/null |
+++ b/third_party/crazy_linker/crazy_linker/tests/zoo.cpp |
@@ -0,0 +1,36 @@ |
+// Copyright (c) 2013 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. |
+ |
+#include <dlfcn.h> |
+#include <stdio.h> |
+ |
+extern "C" bool Zoo() { |
+ printf("%s: Entering\n", __FUNCTION__); |
+ void* bar_lib = dlopen("libbar.so", RTLD_NOW); |
+ if (!bar_lib) { |
+ fprintf(stderr, "Could not libbar.so: %s\n", dlerror()); |
+ return false; |
+ } |
+ printf("%s: Opened libbar.so @%p\n", __FUNCTION__, bar_lib); |
+ |
+ |
+ void (*bar_func)(); |
+ |
+ bar_func = reinterpret_cast<void(*)()>(dlsym(bar_lib, "Bar")); |
+ if (!bar_func) { |
+ fprintf(stderr, "Could not find 'Bar' symbol in libbar.so\n"); |
+ return false; |
+ } |
+ printf("%s: Found 'Bar' symbol at @%p\n", __FUNCTION__, bar_func); |
+ |
+ // Call it. |
+ printf("%s: Calling Bar()\n", __FUNCTION__); |
+ (*bar_func)(); |
+ |
+ printf("%s: Closing libbar.so\n", __FUNCTION__); |
+ dlclose(bar_lib); |
+ |
+ printf("%s: Exiting\n", __FUNCTION__); |
+ return true; |
+} |