[llvm] r299449 - [RuntimeDyld] Make RuntimeDyld honor the ProcessAllSections flag.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 10:03:49 PDT 2017


Author: lhames
Date: Tue Apr  4 12:03:49 2017
New Revision: 299449

URL: http://llvm.org/viewvc/llvm-project?rev=299449&view=rev
Log:
[RuntimeDyld] Make RuntimeDyld honor the ProcessAllSections flag.

When the ProcessAllSections flag (introduced in r204398) is set RuntimeDyld is
supposed to make a call to the client's memory manager for every section in each
object that is loaded. Due to some missing checks, this was not happening in all
cases. This patch adds the missing cases, and fixes the Orc unit test that
verifies correct behavior for ProcessAllSections (The unit test had been
silently bailing out due to an ordering issue: a change in the test order meant
that this unit-test was running before the native target was registered. This
issue has also been fixed in this patch).

This fixes <rdar://problem/22789965>


Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
    llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.cpp
    llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h
    llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=299449&r1=299448&r2=299449&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Tue Apr  4 12:03:49 2017
@@ -443,7 +443,7 @@ Error RuntimeDyldImpl::computeTotalAlloc
        SI != SE; ++SI) {
     const SectionRef &Section = *SI;
 
-    bool IsRequired = isRequiredForExecution(Section);
+    bool IsRequired = isRequiredForExecution(Section) || ProcessAllSections;
 
     // Consider only the sections that are required to be loaded for execution
     if (IsRequired) {
@@ -703,7 +703,7 @@ RuntimeDyldImpl::emitSection(const Objec
   unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;
   unsigned PaddingSize = 0;
   unsigned StubBufSize = 0;
-  bool IsRequired = isRequiredForExecution(Section);
+  bool IsRequired = isRequiredForExecution(Section) || ProcessAllSections;
   bool IsVirtual = Section.isVirtual();
   bool IsZeroInit = isZeroInit(Section);
   bool IsReadOnly = isReadOnlyData(Section);

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.cpp?rev=299449&r1=299448&r2=299449&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.cpp Tue Apr  4 12:03:49 2017
@@ -15,7 +15,7 @@
 
 using namespace llvm;
 
-bool OrcExecutionTest::NativeTargetInitialized = false;
+bool OrcNativeTarget::NativeTargetInitialized = false;
 
 ModuleBuilder::ModuleBuilder(LLVMContext &Context, StringRef Triple,
                              StringRef Name)

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h?rev=299449&r1=299448&r2=299449&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h Tue Apr  4 12:03:49 2017
@@ -28,17 +28,29 @@
 
 namespace llvm {
 
-// Base class for Orc tests that will execute code.
-class OrcExecutionTest {
+class OrcNativeTarget {
 public:
-
-  OrcExecutionTest() {
+  static void initialize() {
     if (!NativeTargetInitialized) {
       InitializeNativeTarget();
       InitializeNativeTargetAsmParser();
       InitializeNativeTargetAsmPrinter();
       NativeTargetInitialized = true;
     }
+  }
+
+private:
+  static bool NativeTargetInitialized;
+};
+
+// Base class for Orc tests that will execute code.
+class OrcExecutionTest {
+public:
+
+  OrcExecutionTest() {
+
+    // Initialize the native target if it hasn't been done already.
+    OrcNativeTarget::initialize();
 
     // Try to select a TargetMachine for the host.
     TM.reset(EngineBuilder().selectTarget());

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp?rev=299449&r1=299448&r2=299449&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp Tue Apr  4 12:03:49 2017
@@ -60,7 +60,7 @@ TEST(RTDyldObjectLinkingLayerTest, TestS
                                                          IsReadOnly);
     }
   private:
-    bool DebugSeen;
+    bool &DebugSeen;
   };
 
   RTDyldObjectLinkingLayer<> ObjLayer;
@@ -75,6 +75,10 @@ TEST(RTDyldObjectLinkingLayerTest, TestS
 
   GV->setSection(".debug_str");
 
+
+  // Initialize the native target in case this is the first unit test
+  // to try to build a TM.
+  OrcNativeTarget::initialize();
   std::unique_ptr<TargetMachine> TM(
     EngineBuilder().selectTarget(Triple(M->getTargetTriple()), "", "",
                                  SmallVector<std::string, 1>()));
@@ -99,6 +103,7 @@ TEST(RTDyldObjectLinkingLayerTest, TestS
   {
     // Test with ProcessAllSections = false (the default).
     auto H = ObjLayer.addObjectSet(Objs, &SMMW, &*Resolver);
+    ObjLayer.emitAndFinalize(H);
     EXPECT_EQ(DebugSectionSeen, false)
       << "Unexpected debug info section";
     ObjLayer.removeObjectSet(H);
@@ -108,6 +113,7 @@ TEST(RTDyldObjectLinkingLayerTest, TestS
     // Test with ProcessAllSections = true.
     ObjLayer.setProcessAllSections(true);
     auto H = ObjLayer.addObjectSet(Objs, &SMMW, &*Resolver);
+    ObjLayer.emitAndFinalize(H);
     EXPECT_EQ(DebugSectionSeen, true)
       << "Expected debug info section not seen";
     ObjLayer.removeObjectSet(H);




More information about the llvm-commits mailing list