diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp')
| -rw-r--r-- | llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 687fd839805f..f16c6bdbfa4f 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -520,6 +520,13 @@ static bool isZeroInit(const SectionRef Section) { SectionType == MachO::S_GB_ZEROFILL; } +static bool isTLS(const SectionRef Section) { + const ObjectFile *Obj = Section.getObject(); + if (isa<object::ELFObjectFileBase>(Obj)) + return ELFSectionRef(Section).getFlags() & ELF::SHF_TLS; + return false; +} + // Compute an upper bound of the memory size that is required to load all // sections Error RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj, @@ -549,6 +556,7 @@ Error RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj, unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL; bool IsCode = Section.isText(); bool IsReadOnly = isReadOnlyData(Section); + bool IsTLS = isTLS(Section); Expected<StringRef> NameOrErr = Section.getName(); if (!NameOrErr) @@ -582,7 +590,7 @@ Error RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj, } else if (IsReadOnly) { RODataAlign = std::max(RODataAlign, Alignment); ROSectionSizes.push_back(SectionSize); - } else { + } else if (!IsTLS) { RWDataAlign = std::max(RWDataAlign, Alignment); RWSectionSizes.push_back(SectionSize); } @@ -672,7 +680,7 @@ unsigned RuntimeDyldImpl::computeSectionStubBufSize(const ObjectFile &Obj, Expected<section_iterator> RelSecOrErr = SI->getRelocatedSection(); if (!RelSecOrErr) - report_fatal_error(toString(RelSecOrErr.takeError())); + report_fatal_error(Twine(toString(RelSecOrErr.takeError()))); section_iterator RelSecI = *RelSecOrErr; if (!(RelSecI == Section)) @@ -800,6 +808,7 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj, bool IsVirtual = Section.isVirtual(); bool IsZeroInit = isZeroInit(Section); bool IsReadOnly = isReadOnlyData(Section); + bool IsTLS = isTLS(Section); uint64_t DataSize = Section.getSize(); // An alignment of 0 (at least with ELF) is identical to an alignment of 1, @@ -823,6 +832,7 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj, uintptr_t Allocate; unsigned SectionID = Sections.size(); uint8_t *Addr; + uint64_t LoadAddress = 0; const char *pData = nullptr; // If this section contains any bits (i.e. isn't a virtual or bss section), @@ -851,10 +861,17 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj, Allocate = DataSize + PaddingSize + StubBufSize; if (!Allocate) Allocate = 1; - Addr = IsCode ? MemMgr.allocateCodeSection(Allocate, Alignment, SectionID, - Name) - : MemMgr.allocateDataSection(Allocate, Alignment, SectionID, - Name, IsReadOnly); + if (IsTLS) { + auto TLSSection = + MemMgr.allocateTLSSection(Allocate, Alignment, SectionID, Name); + Addr = TLSSection.InitializationImage; + LoadAddress = TLSSection.Offset; + } else if (IsCode) { + Addr = MemMgr.allocateCodeSection(Allocate, Alignment, SectionID, Name); + } else { + Addr = MemMgr.allocateDataSection(Allocate, Alignment, SectionID, Name, + IsReadOnly); + } if (!Addr) report_fatal_error("Unable to allocate section memory!"); @@ -897,6 +914,10 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj, Sections.push_back( SectionEntry(Name, Addr, DataSize, Allocate, (uintptr_t)pData)); + // The load address of a TLS section is not equal to the address of its + // initialization image + if (IsTLS) + Sections.back().setLoadAddress(LoadAddress); // Debug info sections are linked as if their load address was zero if (!IsRequired) Sections.back().setLoadAddress(0); @@ -1118,7 +1139,7 @@ void RuntimeDyldImpl::applyExternalSymbolRelocations( // FIXME: Implement error handling that doesn't kill the host program! if (!Addr && !Resolver.allowsZeroSymbols()) - report_fatal_error("Program used external function '" + Name + + report_fatal_error(Twine("Program used external function '") + Name + "' which could not be resolved!"); // If Resolver returned UINT64_MAX, the client wants to handle this symbol @@ -1261,6 +1282,14 @@ uint64_t RuntimeDyld::LoadedObjectInfo::getSectionLoadAddress( return 0; } +RuntimeDyld::MemoryManager::TLSSection +RuntimeDyld::MemoryManager::allocateTLSSection(uintptr_t Size, + unsigned Alignment, + unsigned SectionID, + StringRef SectionName) { + report_fatal_error("allocation of TLS not implemented"); +} + void RuntimeDyld::MemoryManager::anchor() {} void JITSymbolResolver::anchor() {} void LegacyJITSymbolResolver::anchor() {} |
