diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2009-11-23 23:35:19 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2009-11-23 23:35:19 +0000 |
commit | 108c838093704650378b194fe9afc5ebb9e91455 (patch) | |
tree | f6a58b2c3951066ba79198ca44ee230de6f632a3 /unittests | |
parent | dbc3577ea17eb76722cacd1a723a2085e407599b (diff) |
* Move stub allocation inside the JITEmitter, instead of exposing a
way for each TargetJITInfo subclass to allocate its own stubs. This
means stubs aren't as exactly-sized anymore, but it lets us get rid of
TargetJITInfo::emitFunctionStubAtAddr(), which lets ARM and PPC
support the eager JIT, fixing http://llvm.org/PR4816.
* Rename the JITEmitter's stub creation functions to describe the kind
of stub they create. So far, all of them create lazy-compilation
stubs, but they sometimes get used when far-call stubs are needed.
Fixing http://llvm.org/PR5201 will involve fixing this.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89715 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 98b292244f..b676ee41b2 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -183,6 +183,7 @@ class JITTest : public testing::Test { M = new Module("<main>", Context); MP = new ExistingModuleProvider(M); RJMM = new RecordingJITMemoryManager; + RJMM->setPoisonMemory(true); std::string Error; TheJIT.reset(EngineBuilder(MP).setEngineKind(EngineKind::JIT) .setJITMemoryManager(RJMM) @@ -311,7 +312,6 @@ TEST_F(JITTest, FarCallToKnownFunction) { EXPECT_EQ(8, TestFunctionPtr()); } -#if !defined(__arm__) && !defined(__powerpc__) && !defined(__ppc__) // Test a function C which calls A and B which call each other. TEST_F(JITTest, NonLazyCompilationStillNeedsStubs) { TheJIT->DisableLazyCompilation(true); @@ -407,7 +407,6 @@ TEST_F(JITTest, NonLazyLeaksNoStubs) { EXPECT_EQ(Func2->getNumUses(), 0u); Func2->eraseFromParent(); } -#endif TEST_F(JITTest, ModuleDeletion) { TheJIT->DisableLazyCompilation(false); @@ -458,7 +457,6 @@ TEST_F(JITTest, ModuleDeletion) { NumTablesDeallocated); } -#if !defined(__arm__) && !defined(__powerpc__) && !defined(__ppc__) typedef int (*FooPtr) (); TEST_F(JITTest, NoStubs) { @@ -496,7 +494,40 @@ TEST_F(JITTest, NoStubs) { ASSERT_EQ(stubsBefore, RJMM->stubsAllocated); } + +TEST_F(JITTest, FunctionPointersOutliveTheirCreator) { + TheJIT->DisableLazyCompilation(true); + LoadAssembly("define i8()* @get_foo_addr() { " + " ret i8()* @foo " + "} " + " " + "define i8 @foo() { " + " ret i8 42 " + "} "); + Function *F_get_foo_addr = M->getFunction("get_foo_addr"); + + typedef char(*fooT)(); + fooT (*get_foo_addr)() = reinterpret_cast<fooT(*)()>( + (intptr_t)TheJIT->getPointerToFunction(F_get_foo_addr)); + fooT foo_addr = get_foo_addr(); + + // Now free get_foo_addr. This should not free the machine code for foo or + // any call stub returned as foo's canonical address. + TheJIT->freeMachineCodeForFunction(F_get_foo_addr); + + // Check by calling the reported address of foo. + EXPECT_EQ(42, foo_addr()); + + // The reported address should also be the same as the result of a subsequent + // getPointerToFunction(foo). +#if 0 + // Fails until PR5126 is fixed: + Function *F_foo = M->getFunction("foo"); + fooT foo = reinterpret_cast<fooT>( + (intptr_t)TheJIT->getPointerToFunction(F_foo)); + EXPECT_EQ((intptr_t)foo, (intptr_t)foo_addr); #endif +} // This code is copied from JITEventListenerTest, but it only runs once for all // the tests in this directory. Everything seems fine, but that's strange |