[llvm] r234299 - [RuntimeDyld] Always allocate at least 1 byte for object sections in the JIT to

Lang Hames lhames at gmail.com
Mon Apr 6 23:27:56 PDT 2015


Author: lhames
Date: Tue Apr  7 01:27:56 2015
New Revision: 234299

URL: http://llvm.org/viewvc/llvm-project?rev=234299&view=rev
Log:
[RuntimeDyld] Always allocate at least 1 byte for object sections in the JIT to
ensure that section addresses are distinct.

mapSectionAddress will fail if two sections are allocated the same address,
which can happen if any section has zero size (since malloc(0) is implementation
defined). Unfortunately I've been unable to repro this with a simple test case.

Fixes <rdar://problem/20314015>.


Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=234299&r1=234298&r2=234299&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Tue Apr  7 01:27:56 2015
@@ -361,19 +361,20 @@ void RuntimeDyldImpl::computeTotalAllocS
       if (Name == ".eh_frame")
         SectionSize += 4;
 
-      if (SectionSize > 0) {
-        // save the total size of the section
-        if (IsCode) {
-          CodeSectionSizes.push_back(SectionSize);
-        } else if (IsReadOnly) {
-          ROSectionSizes.push_back(SectionSize);
-        } else {
-          RWSectionSizes.push_back(SectionSize);
-        }
-        // update the max alignment
-        if (Alignment > MaxAlignment) {
-          MaxAlignment = Alignment;
-        }
+      if (!SectionSize)
+        SectionSize = 1;
+
+      if (IsCode) {
+        CodeSectionSizes.push_back(SectionSize);
+      } else if (IsReadOnly) {
+        ROSectionSizes.push_back(SectionSize);
+      } else {
+        RWSectionSizes.push_back(SectionSize);
+      }
+
+      // update the max alignment
+      if (Alignment > MaxAlignment) {
+        MaxAlignment = Alignment;
       }
     }
   }
@@ -578,6 +579,8 @@ unsigned RuntimeDyldImpl::emitSection(co
   if (IsRequired) {
     Check(Section.getContents(data));
     Allocate = DataSize + PaddingSize + StubBufSize;
+    if (!Allocate)
+      Allocate = 1;
     Addr = IsCode ? MemMgr.allocateCodeSection(Allocate, Alignment, SectionID,
                                                Name)
                   : MemMgr.allocateDataSection(Allocate, Alignment, SectionID,





More information about the llvm-commits mailing list