From 2be1bbea7ec6f74f1415912005c05992548d06b6 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 7 Apr 2015 06:27:56 +0000 Subject: [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 . llvm-svn: 234299 --- .../ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp') diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index a12f0e00588..07aa20b3bc9 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -361,19 +361,20 @@ void RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj, 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(const ObjectFile &Obj, 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, -- cgit v1.2.3