summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
diff options
context:
space:
mode:
authorKeno Fischer <kfischer@college.harvard.edu>2015-01-27 20:02:31 +0000
committerKeno Fischer <kfischer@college.harvard.edu>2015-01-27 20:02:31 +0000
commit88cc26811bdbd8055dd2cd84c89009c22adf4875 (patch)
treeac42a5aed96d2c6da4b86030211ed3d6c46dfe5c /llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
parent5f92a08fc051d921f75af0cab01ce6a5b255b9c4 (diff)
downloadbcm5719-llvm-88cc26811bdbd8055dd2cd84c89009c22adf4875.tar.gz
bcm5719-llvm-88cc26811bdbd8055dd2cd84c89009c22adf4875.zip
[ExecutionEngine] Add weak symbol support to RuntimeDyld
Support weak symbols by first looking up if there is an externally visible symbol we can find, and only if that fails using the one in the object file we're loading. Reviewed By: lhames Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6950 llvm-svn: 227228
Diffstat (limited to 'llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp')
-rw-r--r--llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
index 64d8c2fca04..f9ca0fc8717 100644
--- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
+++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/MCJIT.h"
+#include "llvm/Support/DynamicLibrary.h"
#include "MCJITTestBase.h"
#include "gtest/gtest.h"
@@ -199,4 +200,45 @@ TEST_F(MCJITTest, multiple_decl_lookups) {
EXPECT_EQ(A, B) << "Repeat calls to getPointerToFunction fail.";
}
+// Test weak symbol linking when the weak symbol is present in a shared
+// library
+TEST_F(MCJITTest, weak_symbol_present) {
+ SKIP_UNSUPPORTED_PLATFORM;
+
+ int FakeWeakSymbol;
+ llvm::sys::DynamicLibrary::AddSymbol("FakeWeakSymbol", &FakeWeakSymbol);
+ createJITFromAssembly(
+ "$FakeWeakSymbol = comdat any\n"
+ "@FakeWeakSymbol = linkonce_odr global i32 42, comdat, align 4\n"
+ "define i32 @weak_test(i32* %arg) {\n"
+ " %r = icmp eq i32* %arg, @FakeWeakSymbol\n"
+ " %ret = zext i1 %r to i32\n"
+ " ret i32 %ret\n"
+ " }");
+
+ uint64_t Addr = TheJIT->getFunctionAddress("weak_test");;
+ EXPECT_TRUE(Addr != 0);
+ int32_t(*FuncPtr)(int32_t *) = (int32_t(*)(int32_t *))Addr;
+ EXPECT_EQ(FuncPtr(&FakeWeakSymbol),1);
+ EXPECT_TRUE(TheJIT->getGlobalValueAddress("FakeWeakSymbol") == 0);
+}
+
+// Test weak symbol linking when the weak symbol is not present in a
+// shared library
+TEST_F(MCJITTest, weak_symbol_absent) {
+ SKIP_UNSUPPORTED_PLATFORM;
+
+ SMDiagnostic Error;
+ createJITFromAssembly(
+ " $FakeWeakSymbol2 = comdat any\n"
+ " @FakeWeakSymbol2 = linkonce_odr global i32 42, comdat, align 4\n"
+ " define i32* @get_weak() {\n"
+ " ret i32* @FakeWeakSymbol2\n"
+ " }\n");
+ void*(*FuncPtr)() =
+ (void*(*)(void))TheJIT->getFunctionAddress("get_weak");
+ EXPECT_EQ(FuncPtr(),(void*)TheJIT->getGlobalValueAddress("FakeWeakSymbol2"));
+}
+
+
}
OpenPOWER on IntegriCloud