[llvm] r182085 - Minor changes to the MCJITTest unittests to use the correct API for finalizing

Amara Emerson amara.emerson at arm.com
Fri May 17 05:48:01 PDT 2013


Hi David,

The buildbot failure on the ARM pandaboard is due to an assertion failure:
"Assertion `(*TargetPtr & 0x000F0FFF) == 0' failed." In the ARM RuntimeDyld.

This particular assertion is one I added last year as a sanity check that
the relocation target address didn't already have an addend in it. Since the
object code may now be relocated before these are resolved, this assumption
may not be valid anymore.

I don't removing this assertion should cause any problems.

Regards,
Amara

-----Original Message-----
From: llvm-commits-bounces at cs.uiuc.edu
[mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of David Tweed
Sent: 17 May 2013 11:02
To: llvm-commits at cs.uiuc.edu
Subject: [llvm] r182085 - Minor changes to the MCJITTest unittests to use
the correct API for finalizing

Author: davidtweed
Date: Fri May 17 05:01:46 2013
New Revision: 182085

URL: http://llvm.org/viewvc/llvm-project?rev=182085&view=rev
Log:
Minor changes to the MCJITTest unittests to use the correct API for
finalizing
the JIT object (including XFAIL an ARM test that now needs fixing). Also
renames
internal function for consistency.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
    llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h
    llvm/trunk/include/llvm/ExecutionEngine/SectionMemoryManager.h
    llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
    llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp
    llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
    llvm/trunk/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
    llvm/trunk/tools/lli/RecordingMemoryManager.h
    llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
    llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
    llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp
    llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp
    llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/
ExecutionEngine.h?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Fri May 17
05:01:46 2013
@@ -252,11 +252,14 @@ public:
                      "EE!");
   }
 
-  // finalizeObject - This method should be called after sections within an
-  // object have been relocated using mapSectionAddress.  When this method
is
-  // called the MCJIT execution engine will reapply relocations for a
loaded
-  // object.  This method has no effect for the legacy JIT engine or the
-  // interpeter.
+  /// finalizeObject - ensure the module is fully processed and is usable.
+  ///
+  /// It is the user-level function for completing the process of making
the
+  /// object usable for execution.  It should be called after sections
within an
+  /// object have been relocated using mapSectionAddress.  When this method
is
+  /// called the MCJIT execution engine will reapply relocations for a
loaded
+  /// object.  This method has no effect for the legacy JIT engine or the
+  /// interpeter.
   virtual void finalizeObject() {}
 
   /// runStaticConstructorsDestructors - This method is used to execute all
of

Modified: llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/
RuntimeDyld.h?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/RuntimeDyld.h Fri May 17
05:01:46 2013
@@ -62,10 +62,12 @@ public:
   /// permissions can be applied.  It is up to the memory manager
implementation
   /// to decide whether or not to act on this method.  The memory manager
will
   /// typically allocate all sections as read-write and then apply specific
-  /// permissions when this method is called.
+  /// permissions when this method is called.  Code sections cannot be
executed
+  /// until this function has been called.  In addition, any cache
coherency
+  /// operations needed to reliably use the memory are also performed.
   ///
   /// Returns true if an error occurred, false otherwise.
-  virtual bool applyPermissions(std::string *ErrMsg = 0) = 0;
+  virtual bool finalizeMemory(std::string *ErrMsg = 0) = 0;
 
   /// Register the EH frames with the runtime so that c++ exceptions work.
The
   /// default implementation does nothing. Look at SectionMemoryManager for
one

Modified: llvm/trunk/include/llvm/ExecutionEngine/SectionMemoryManager.h
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/
SectionMemoryManager.h?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/include/llvm/ExecutionEngine/SectionMemoryManager.h
(original)
+++ llvm/trunk/include/llvm/ExecutionEngine/SectionMemoryManager.h Fri May
17 05:01:46 2013
@@ -33,7 +33,7 @@ namespace llvm {
 /// Any client using this memory manager MUST ensure that section-specific
 /// page permissions have been applied before attempting to execute
functions
 /// in the JITed object.  Permissions can be applied either by calling
-/// MCJIT::finalizeObject or by calling
SectionMemoryManager::applyPermissions
+/// MCJIT::finalizeObject or by calling
SectionMemoryManager::finalizeMemory
 /// directly.  Clients of MCJIT should call MCJIT::finalizeObject.
 class SectionMemoryManager : public RTDyldMemoryManager {
   SectionMemoryManager(const SectionMemoryManager&) LLVM_DELETED_FUNCTION;
@@ -60,17 +60,18 @@ public:
                                        unsigned SectionID,
                                        bool isReadOnly);
 
-  /// \brief Applies section-specific memory permissions.
+  /// \brief Update section-specific memory permissions and other
attributes.
   ///
   /// This method is called when object loading is complete and section
page
   /// permissions can be applied.  It is up to the memory manager
implementation
   /// to decide whether or not to act on this method.  The memory manager
will
   /// typically allocate all sections as read-write and then apply specific
   /// permissions when this method is called.  Code sections cannot be
executed
-  /// until this function has been called.
+  /// until this function has been called.  In addition, any cache
coherency
+  /// operations needed to reliably use the memory are also performed.
   ///
   /// \returns true if an error occurred, false otherwise.
-  virtual bool applyPermissions(std::string *ErrMsg = 0);
+  virtual bool finalizeMemory(std::string *ErrMsg = 0);
 
   void registerEHFrames(StringRef SectionData);
 
@@ -89,7 +90,7 @@ public:
   /// explicit cache flush, otherwise JIT code manipulations (like resolved
   /// relocations) will get to the data cache but not to the instruction
cache.
   ///
-  /// This method is called from applyPermissions.
+  /// This method is called from finalizeMemory.
   virtual void invalidateInstructionCache();
 
 private:

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITMe
moryManager.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Fri May 17
05:01:46 2013
@@ -509,7 +509,7 @@ namespace {
       return (uint8_t*)DataAllocator.Allocate(Size, Alignment);
     }
 
-    bool applyPermissions(std::string *ErrMsg) {
+    bool finalizeMemory(std::string *ErrMsg) {
       return false;
     }
 

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJ
IT.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp Fri May 17 05:01:46 2013
@@ -178,7 +178,7 @@ void MCJIT::finalizeObject() {
     MemMgr->registerEHFrames(EHData);
 
   // Set page permissions.
-  MemMgr->applyPermissions();
+  MemMgr->finalizeMemory();
 }
 
 void *MCJIT::getPointerToBasicBlock(BasicBlock *BB) {

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJ
IT.h?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h Fri May 17 05:01:46 2013
@@ -52,6 +52,13 @@ public:
   /// Sets the object manager that MCJIT should use to avoid compilation.
   virtual void setObjectCache(ObjectCache *manager);
 
+  /// finalizeObject - ensure the module is fully processed and is usable.
+  ///
+  /// It is the user-level function for completing the process of making
the
+  /// object usable for execution. It should be called after sections
within an
+  /// object have been relocated using mapSectionAddress.  When this method
is
+  /// called the MCJIT execution engine will reapply relocations for a
loaded
+  /// object.
   virtual void finalizeObject();
 
   virtual void *getPointerToBasicBlock(BasicBlock *BB);

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/Sec
tionMemoryManager.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp Fri May 17
05:01:46 2013
@@ -111,7 +111,7 @@ uint8_t *SectionMemoryManager::allocateS
   return (uint8_t*)Addr;
 }
 
-bool SectionMemoryManager::applyPermissions(std::string *ErrMsg)
+bool SectionMemoryManager::finalizeMemory(std::string *ErrMsg)
 {
   // FIXME: Should in-progress permissions be reverted if an error occurs?
   error_code ec;

Modified: llvm/trunk/tools/lli/RecordingMemoryManager.h
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/RecordingMemoryMana
ger.h?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/tools/lli/RecordingMemoryManager.h (original)
+++ llvm/trunk/tools/lli/RecordingMemoryManager.h Fri May 17 05:01:46 2013
@@ -58,7 +58,7 @@ public:
   void *getPointerToNamedFunction(const std::string &Name,
                                   bool AbortOnFailure = true);
 
-  bool applyPermissions(std::string *ErrMsg) { return false; }
+  bool finalizeMemory(std::string *ErrMsg) { return false; }
 
   // The following obsolete JITMemoryManager calls are stubbed out for
   // this model.

Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld
.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)
+++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Fri May 17 05:01:46 2013
@@ -69,7 +69,7 @@ public:
     return 0;
   }
 
-  bool applyPermissions(std::string *ErrMsg) { return false; }
+  bool finalizeMemory(std::string *ErrMsg) { return false; }
 
   // Invalidate instruction cache for sections with execute permissions.
   // Some platforms with separate data cache and instruction cache require

Modified: llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/JIT
/JITTest.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp Fri May 17 05:01:46
2013
@@ -127,7 +127,7 @@ public:
                                        unsigned SectionID) {
     return Base->allocateCodeSection(Size, Alignment, SectionID);
   }
-  virtual bool applyPermissions(std::string *ErrMsg) { return false; }
+  virtual bool finalizeMemory(std::string *ErrMsg) { return false; }
   virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
     return Base->allocateSpace(Size, Alignment);
   }

Modified:
llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJ
IT/MCJITMemoryManagerTest.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp
(original)
+++ llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp
Fri May 17 05:01:46 2013
@@ -46,7 +46,7 @@ TEST(MCJITMemoryManagerTest, BasicAlloca
   }
 
   std::string Error;
-  EXPECT_FALSE(MemMgr->applyPermissions(&Error));
+  EXPECT_FALSE(MemMgr->finalizeMemory(&Error));
 }
 
 TEST(MCJITMemoryManagerTest, LargeAllocations) {
@@ -79,7 +79,7 @@ TEST(MCJITMemoryManagerTest, LargeAlloca
   }
 
   std::string Error;
-  EXPECT_FALSE(MemMgr->applyPermissions(&Error));
+  EXPECT_FALSE(MemMgr->finalizeMemory(&Error));
 }
 
 TEST(MCJITMemoryManagerTest, ManyAllocations) {
@@ -114,7 +114,7 @@ TEST(MCJITMemoryManagerTest, ManyAllocat
   }
 
   std::string Error;
-  EXPECT_FALSE(MemMgr->applyPermissions(&Error));
+  EXPECT_FALSE(MemMgr->finalizeMemory(&Error));
 }
 
 TEST(MCJITMemoryManagerTest, ManyVariedAllocations) {

Modified:
llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJ
IT/MCJITObjectCacheTest.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp
(original)
+++ llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp Fri
May 17 05:01:46 2013
@@ -101,11 +101,10 @@ protected:
     ASSERT_TRUE(TheJIT.isValid());
     ASSERT_TRUE(0 != Main);
 
+    // We may be using a null cache, so ensure compilation is valid.
     TheJIT->finalizeObject();
     void *vPtr = TheJIT->getPointerToFunction(Main);
 
-    static_cast<SectionMemoryManager*>(MM)->invalidateInstructionCache();
-
     EXPECT_TRUE(0 != vPtr)
       << "Unable to get pointer to main() from JIT";
 

Modified: llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJ
IT/MCJITTest.cpp?rev=182085&r1=182084&r2=182085&view=diff
============================================================================
==
--- llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp Fri May 17
05:01:46 2013
@@ -34,6 +34,7 @@ namespace {
 /*
 TEST_F(MCJITTest, empty_module) {
   createJIT(M.take());
+  TheJIT->finalizeObject();
   //EXPECT_NE(0, TheJIT->getObjectImage())
   //  << "Unable to generate executable loaded object image";
 }
@@ -46,8 +47,7 @@ TEST_F(MCJITTest, global_variable) {
   GlobalValue *Global = insertGlobalInt32(M.get(), "test_global",
initialValue);
   createJIT(M.take());
   void *globalPtr =  TheJIT->getPointerToGlobal(Global);
-  MM->applyPermissions();
-  static_cast<SectionMemoryManager*>(MM)->invalidateInstructionCache();
+  TheJIT->finalizeObject();
   EXPECT_TRUE(0 != globalPtr)
     << "Unable to get pointer to global value from JIT";
 
@@ -61,8 +61,7 @@ TEST_F(MCJITTest, add_function) {
   Function *F = insertAddFunction(M.get());
   createJIT(M.take());
   void *addPtr = TheJIT->getPointerToFunction(F);
-  MM->applyPermissions();
-  static_cast<SectionMemoryManager*>(MM)->invalidateInstructionCache();
+  TheJIT->finalizeObject();
   EXPECT_TRUE(0 != addPtr)
     << "Unable to get pointer to function from JIT";
 
@@ -79,8 +78,7 @@ TEST_F(MCJITTest, run_main) {
   Function *Main = insertMainFunction(M.get(), 6);
   createJIT(M.take());
   void *vPtr = TheJIT->getPointerToFunction(Main);
-  MM->applyPermissions();
-  static_cast<SectionMemoryManager*>(MM)->invalidateInstructionCache();
+  TheJIT->finalizeObject();
   EXPECT_TRUE(0 != vPtr)
     << "Unable to get pointer to main() from JIT";
 
@@ -102,8 +100,7 @@ TEST_F(MCJITTest, return_global) {
 
   createJIT(M.take());
   void *rgvPtr = TheJIT->getPointerToFunction(ReturnGlobal);
-  MM->applyPermissions();
-  static_cast<SectionMemoryManager*>(MM)->invalidateInstructionCache();
+  TheJIT->finalizeObject();
   EXPECT_TRUE(0 != rgvPtr);
 
   int32_t(*FuncPtr)(void) = (int32_t(*)(void))(intptr_t)rgvPtr;
@@ -134,6 +131,7 @@ TEST_F(MCJITTest, increment_global) {
 
   createJIT(M.take());
   void *gvPtr = TheJIT->getPointerToGlobal(GV);
+  TheJIT->finalizeObject();
   EXPECT_EQ(initialNum, *(int32_t*)gvPtr);
 
   void *vPtr = TheJIT->getPointerToFunction(IncrementGlobal);
@@ -150,6 +148,9 @@ TEST_F(MCJITTest, increment_global) {
 }
 */
 
+// PR16013: XFAIL this test on ARM, which currently can't handle multiple
relocations.
+#if !defined(__arm__)
+
 TEST_F(MCJITTest, multiple_functions) {
   SKIP_UNSUPPORTED_PLATFORM;
 
@@ -172,8 +173,7 @@ TEST_F(MCJITTest, multiple_functions) {
 
   createJIT(M.take());
   void *vPtr = TheJIT->getPointerToFunction(Outer);
-  MM->applyPermissions();
-  static_cast<SectionMemoryManager*>(MM)->invalidateInstructionCache();
+  TheJIT->finalizeObject();
   EXPECT_TRUE(0 != vPtr)
     << "Unable to get pointer to outer function from JIT";
 
@@ -182,6 +182,8 @@ TEST_F(MCJITTest, multiple_functions) {
     << "Incorrect result returned from function";
 }
 
+#endif /*!defined(__arm__)*/
+
 // FIXME: ExecutionEngine has no support empty modules
 /*
 TEST_F(MCJITTest, multiple_empty_modules) {
@@ -219,6 +221,7 @@ TEST_F(MCJITTest, multiple_modules) {
 
   // get a function pointer in a module that was not used in EE
construction
   void *vPtr = TheJIT->getPointerToFunction(Caller);
+  TheJIT->finalizeObject();
   EXPECT_NE(0, vPtr)
     << "Unable to get pointer to caller function from JIT";
 


_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits








More information about the llvm-commits mailing list