[RuntimeDyld] Track symbol visibility in RuntimeDyld.

RuntimeDyld symbol info previously consisted of just a Section/Offset pair. This
patch replaces that pair type with a SymbolInfo class that also tracks symbol
visibility. A new method, RuntimeDyld::getExportedSymbolLoadAddress, is
introduced which only returns a non-zero result for exported symbols. For
non-exported or non-existant symbols this method will return zero. The
RuntimeDyld::getSymbolAddress method retains its current behavior, returning
non-zero results for all symbols regardless of visibility.

No in-tree clients of RuntimeDyld are changed. The newly introduced
functionality will be used by the Orc APIs.

No test case: Since this patch doesn't modify the behavior for any in-tree
clients we don't have a good tool to test this with yet. Once Orc is in we can
use it to write regression tests that test these changes.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226341 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Lang Hames
2015-01-16 23:13:56 +00:00
parent b2bb846f17
commit 61bd005d1b
6 changed files with 95 additions and 40 deletions

View File

@@ -156,6 +156,28 @@ public:
}
};
/// @brief Symbol info for RuntimeDyld.
class SymbolInfo {
public:
typedef enum { Hidden = 0, Default = 1 } Visibility;
SymbolInfo() : Offset(0), SectionID(0), Vis(Hidden) {}
SymbolInfo(unsigned SectionID, uint64_t Offset, Visibility Vis)
: Offset(Offset), SectionID(SectionID), Vis(Vis) {}
unsigned getSectionID() const { return SectionID; }
uint64_t getOffset() const { return Offset; }
Visibility getVisibility() const { return Vis; }
private:
uint64_t Offset;
unsigned SectionID : 31;
Visibility Vis : 1;
};
typedef StringMap<SymbolInfo> RTDyldSymbolTable;
class RuntimeDyldImpl {
friend class RuntimeDyld::LoadedObjectInfo;
friend class RuntimeDyldCheckerImpl;
@@ -178,11 +200,8 @@ protected:
// references it.
typedef std::map<SectionRef, unsigned> ObjSectionToIDMap;
// A global symbol table for symbols from all loaded modules. Maps the
// symbol name to a (SectionID, offset in section) pair.
typedef std::pair<unsigned, uintptr_t> SymbolLoc;
typedef StringMap<SymbolLoc> SymbolTableMap;
SymbolTableMap GlobalSymbolTable;
// A global symbol table for symbols from all loaded modules.
RTDyldSymbolTable GlobalSymbolTable;
// Pair representing the size and alignment requirement for a common symbol.
typedef std::pair<unsigned, unsigned> CommonSymbolInfo;
@@ -289,7 +308,7 @@ protected:
/// symbol table.
void emitCommonSymbols(const ObjectFile &Obj,
const CommonSymbolMap &CommonSymbols,
uint64_t TotalSize, SymbolTableMap &SymbolTable);
uint64_t TotalSize, RTDyldSymbolTable &SymbolTable);
/// \brief Emits section data from the object file to the MemoryManager.
/// \param IsCode if it's true then allocateCodeSection() will be
@@ -374,21 +393,31 @@ public:
uint8_t* getSymbolAddress(StringRef Name) const {
// FIXME: Just look up as a function for now. Overly simple of course.
// Work in progress.
SymbolTableMap::const_iterator pos = GlobalSymbolTable.find(Name);
RTDyldSymbolTable::const_iterator pos = GlobalSymbolTable.find(Name);
if (pos == GlobalSymbolTable.end())
return nullptr;
SymbolLoc Loc = pos->second;
return getSectionAddress(Loc.first) + Loc.second;
const auto &SymInfo = pos->second;
return getSectionAddress(SymInfo.getSectionID()) + SymInfo.getOffset();
}
uint64_t getSymbolLoadAddress(StringRef Name) const {
// FIXME: Just look up as a function for now. Overly simple of course.
// Work in progress.
SymbolTableMap::const_iterator pos = GlobalSymbolTable.find(Name);
RTDyldSymbolTable::const_iterator pos = GlobalSymbolTable.find(Name);
if (pos == GlobalSymbolTable.end())
return 0;
SymbolLoc Loc = pos->second;
return getSectionLoadAddress(Loc.first) + Loc.second;
const auto &SymInfo = pos->second;
return getSectionLoadAddress(SymInfo.getSectionID()) + SymInfo.getOffset();
}
uint64_t getExportedSymbolLoadAddress(StringRef Name) const {
RTDyldSymbolTable::const_iterator pos = GlobalSymbolTable.find(Name);
if (pos == GlobalSymbolTable.end())
return 0;
const auto &SymInfo = pos->second;
if (SymInfo.getVisibility() == SymbolInfo::Hidden)
return 0;
return getSectionLoadAddress(SymInfo.getSectionID()) + SymInfo.getOffset();
}
void resolveRelocations();