[llvm] r250639 - [RuntimeDyld] Add support for absolute symbols.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 17 18:41:37 PDT 2015
Author: lhames
Date: Sat Oct 17 20:41:37 2015
New Revision: 250639
URL: http://llvm.org/viewvc/llvm-project?rev=250639&view=rev
Log:
[RuntimeDyld] Add support for absolute symbols.
Modified:
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=250639&r1=250638&r2=250639&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Sat Oct 17 20:41:37 2015
@@ -162,38 +162,55 @@ RuntimeDyldImpl::loadObjectImpl(const ob
++I) {
uint32_t Flags = I->getFlags();
- bool IsCommon = Flags & SymbolRef::SF_Common;
- if (IsCommon)
+ if (Flags & SymbolRef::SF_Common)
CommonSymbols.push_back(*I);
else {
object::SymbolRef::Type SymType = I->getType();
- if (SymType == object::SymbolRef::ST_Function ||
- SymType == object::SymbolRef::ST_Data ||
- SymType == object::SymbolRef::ST_Unknown) {
-
- ErrorOr<StringRef> NameOrErr = I->getName();
- Check(NameOrErr.getError());
- StringRef Name = *NameOrErr;
+ // Get symbol name.
+ ErrorOr<StringRef> NameOrErr = I->getName();
+ Check(NameOrErr.getError());
+ StringRef Name = *NameOrErr;
+
+ // Compute JIT symbol flags.
+ JITSymbolFlags RTDyldSymFlags = JITSymbolFlags::None;
+ if (Flags & SymbolRef::SF_Weak)
+ RTDyldSymFlags |= JITSymbolFlags::Weak;
+ if (Flags & SymbolRef::SF_Exported)
+ RTDyldSymFlags |= JITSymbolFlags::Exported;
+
+ if (Flags & SymbolRef::SF_Absolute) {
+ auto Addr = I->getAddress();
+ Check(Addr.getError());
+ uint64_t SectOffset = *Addr;
+ unsigned SectionID = AbsoluteSymbolSection;
+
+ DEBUG(dbgs() << "\tType: " << SymType << " (absolute) Name: " << Name
+ << " SID: " << SectionID << " Offset: "
+ << format("%p", (uintptr_t)SectOffset)
+ << " flags: " << Flags << "\n");
+ GlobalSymbolTable[Name] =
+ SymbolTableEntry(SectionID, SectOffset, RTDyldSymFlags);
+ } else if (SymType == object::SymbolRef::ST_Function ||
+ SymType == object::SymbolRef::ST_Data ||
+ SymType == object::SymbolRef::ST_Unknown ||
+ SymType == object::SymbolRef::ST_Other) {
+
ErrorOr<section_iterator> SIOrErr = I->getSection();
Check(SIOrErr.getError());
section_iterator SI = *SIOrErr;
if (SI == Obj.section_end())
continue;
+ // Get symbol offset.
uint64_t SectOffset;
Check(getOffset(*I, *SI, SectOffset));
bool IsCode = SI->isText();
- unsigned SectionID =
- findOrEmitSection(Obj, *SI, IsCode, LocalSections);
+ unsigned SectionID = findOrEmitSection(Obj, *SI, IsCode, LocalSections);
+
DEBUG(dbgs() << "\tType: " << SymType << " Name: " << Name
<< " SID: " << SectionID << " Offset: "
<< format("%p", (uintptr_t)SectOffset)
<< " flags: " << Flags << "\n");
- JITSymbolFlags RTDyldSymFlags = JITSymbolFlags::None;
- if (Flags & SymbolRef::SF_Weak)
- RTDyldSymFlags |= JITSymbolFlags::Weak;
- if (Flags & SymbolRef::SF_Exported)
- RTDyldSymFlags |= JITSymbolFlags::Exported;
GlobalSymbolTable[Name] =
SymbolTableEntry(SectionID, SectOffset, RTDyldSymFlags);
}
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp?rev=250639&r1=250638&r2=250639&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp Sat Oct 17 20:41:37 2015
@@ -727,7 +727,7 @@ bool RuntimeDyldCheckerImpl::checkAllRul
}
bool RuntimeDyldCheckerImpl::isSymbolValid(StringRef Symbol) const {
- if (getRTDyld().getSymbolLocalAddress(Symbol))
+ if (getRTDyld().getSymbol(Symbol))
return true;
return !!getRTDyld().Resolver.findSymbol(Symbol);
}
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h?rev=250639&r1=250638&r2=250639&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h Sat Oct 17 20:41:37 2015
@@ -188,6 +188,8 @@ class RuntimeDyldImpl {
friend class RuntimeDyld::LoadedObjectInfo;
friend class RuntimeDyldCheckerImpl;
protected:
+ static const unsigned AbsoluteSymbolSection = ~0U;
+
// The MemoryManager to load objects into.
RuntimeDyld::MemoryManager &MemMgr;
@@ -407,6 +409,9 @@ public:
if (pos == GlobalSymbolTable.end())
return nullptr;
const auto &SymInfo = pos->second;
+ // Absolute symbols do not have a local address.
+ if (SymInfo.getSectionID() == AbsoluteSymbolSection)
+ return nullptr;
return getSectionAddress(SymInfo.getSectionID()) + SymInfo.getOffset();
}
@@ -417,8 +422,10 @@ public:
if (pos == GlobalSymbolTable.end())
return nullptr;
const auto &SymEntry = pos->second;
- uint64_t TargetAddr =
- getSectionLoadAddress(SymEntry.getSectionID()) + SymEntry.getOffset();
+ uint64_t SectionAddr = 0;
+ if (SymEntry.getSectionID() != AbsoluteSymbolSection)
+ SectionAddr = getSectionLoadAddress(SymEntry.getSectionID());
+ uint64_t TargetAddr = SectionAddr + SymEntry.getOffset();
return RuntimeDyld::SymbolInfo(TargetAddr, SymEntry.getFlags());
}
Modified: llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s?rev=250639&r1=250638&r2=250639&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s (original)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s Sat Oct 17 20:41:37 2015
@@ -57,7 +57,12 @@ z1:
z2:
.quad ds2
-# Test subtractor relocations.
+# Test absolute symbols.
+# rtdyld-check: abssym = 0xdeadbeef
+ .globl abssym
+abssym = 0xdeadbeef
+
+ # Test subtractor relocations.
# rtdyld-check: *{8}z3 = z4 - z5 + 4
z3:
.quad z4 - z5 + 4
More information about the llvm-commits
mailing list