mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-17 21:35:07 +00:00
It doesn't make sense to move symbol relocations to section relocations when
relocations are resolved. It's much more reasonable to do this decision when relocations are just being added - we have all the information at that point. Also a bit of renaming and extra comments to clarify extensions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155819 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5ff30e70f8
commit
37bc5a2000
@ -39,7 +39,7 @@ namespace {
|
|||||||
// Resolve the relocations for all symbols we currently know about.
|
// Resolve the relocations for all symbols we currently know about.
|
||||||
void RuntimeDyldImpl::resolveRelocations() {
|
void RuntimeDyldImpl::resolveRelocations() {
|
||||||
// First, resolve relocations associated with external symbols.
|
// First, resolve relocations associated with external symbols.
|
||||||
resolveSymbols();
|
resolveExternalSymbols();
|
||||||
|
|
||||||
// Just iterate over the sections we have and resolve all the relocations
|
// Just iterate over the sections we have and resolve all the relocations
|
||||||
// in them. Gross overkill, but it gets the job done.
|
// in them. Gross overkill, but it gets the job done.
|
||||||
@ -324,12 +324,20 @@ void RuntimeDyldImpl::addRelocation(const RelocationValueRef &Value,
|
|||||||
Offset,
|
Offset,
|
||||||
RelType,
|
RelType,
|
||||||
Value.Addend));
|
Value.Addend));
|
||||||
} else
|
} else {
|
||||||
SymbolRelocations[Value.SymbolName].push_back(RelocationEntry(
|
// Relocation by symbol. If the symbol is found in the global symbol table,
|
||||||
SectionID,
|
// create an appropriate section relocation. Otherwise, add it to
|
||||||
Offset,
|
// ExternalSymbolRelocations.
|
||||||
RelType,
|
RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
|
||||||
Value.Addend));
|
|
||||||
|
StringMap<SymbolLoc>::const_iterator Loc = SymbolTable.find(Value.SymbolName);
|
||||||
|
if (Loc == SymbolTable.end()) {
|
||||||
|
ExternalSymbolRelocations[Value.SymbolName].push_back(RE);
|
||||||
|
} else {
|
||||||
|
RE.Addend += Loc->second.second;
|
||||||
|
Relocations[Loc->second.first].push_back(RE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *RuntimeDyldImpl::createStubFunction(uint8_t *Addr) {
|
uint8_t *RuntimeDyldImpl::createStubFunction(uint8_t *Addr) {
|
||||||
@ -386,11 +394,9 @@ void RuntimeDyldImpl::resolveRelocationList(const RelocationList &Relocs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveSymbols - Resolve any relocations to the specified symbols if
|
void RuntimeDyldImpl::resolveExternalSymbols() {
|
||||||
// we know where it lives.
|
StringMap<RelocationList>::iterator i = ExternalSymbolRelocations.begin(),
|
||||||
void RuntimeDyldImpl::resolveSymbols() {
|
e = ExternalSymbolRelocations.end();
|
||||||
StringMap<RelocationList>::iterator i = SymbolRelocations.begin(),
|
|
||||||
e = SymbolRelocations.end();
|
|
||||||
for (; i != e; i++) {
|
for (; i != e; i++) {
|
||||||
StringRef Name = i->first();
|
StringRef Name = i->first();
|
||||||
RelocationList &Relocs = i->second;
|
RelocationList &Relocs = i->second;
|
||||||
@ -405,15 +411,7 @@ void RuntimeDyldImpl::resolveSymbols() {
|
|||||||
<< "\n");
|
<< "\n");
|
||||||
resolveRelocationList(Relocs, (uintptr_t)Addr);
|
resolveRelocationList(Relocs, (uintptr_t)Addr);
|
||||||
} else {
|
} else {
|
||||||
// Change the relocation to be section relative rather than symbol
|
report_fatal_error("Expected external symbol");
|
||||||
// relative and move it to the resolved relocation list.
|
|
||||||
DEBUG(dbgs() << "Resolving symbol '" << Name << "'\n");
|
|
||||||
for (int i = 0, e = Relocs.size(); i != e; ++i) {
|
|
||||||
RelocationEntry Entry = Relocs[i];
|
|
||||||
Entry.Addend += Loc->second.second;
|
|
||||||
Relocations[Loc->second.first].push_back(Entry);
|
|
||||||
}
|
|
||||||
Relocs.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ protected:
|
|||||||
// references it.
|
// references it.
|
||||||
typedef std::map<SectionRef, unsigned> ObjSectionToIDMap;
|
typedef std::map<SectionRef, unsigned> ObjSectionToIDMap;
|
||||||
|
|
||||||
// Master symbol table. As modules are loaded and external symbols are
|
// Master symbol table. As modules are loaded and symbols are
|
||||||
// resolved, their addresses are stored here as a SectionID/Offset pair.
|
// resolved, their addresses are stored here as a SectionID/Offset pair.
|
||||||
typedef std::pair<unsigned, uintptr_t> SymbolLoc;
|
typedef std::pair<unsigned, uintptr_t> SymbolLoc;
|
||||||
StringMap<SymbolLoc> SymbolTable;
|
StringMap<SymbolLoc> SymbolTable;
|
||||||
@ -148,9 +148,11 @@ protected:
|
|||||||
// source of the address. The target where the address will be writen is
|
// source of the address. The target where the address will be writen is
|
||||||
// SectionID/Offset in the relocation itself.
|
// SectionID/Offset in the relocation itself.
|
||||||
DenseMap<unsigned, RelocationList> Relocations;
|
DenseMap<unsigned, RelocationList> Relocations;
|
||||||
// Relocations to external symbols that are not yet resolved.
|
|
||||||
// Indexed by symbol name.
|
// Relocations to external symbols that are not yet resolved. Symbols are
|
||||||
StringMap<RelocationList> SymbolRelocations;
|
// external when they aren't found in the global symbol table of all loaded
|
||||||
|
// modules. This map is indexed by symbol name.
|
||||||
|
StringMap<RelocationList> ExternalSymbolRelocations;
|
||||||
|
|
||||||
typedef std::map<RelocationValueRef, uintptr_t> StubMap;
|
typedef std::map<RelocationValueRef, uintptr_t> StubMap;
|
||||||
|
|
||||||
@ -235,7 +237,8 @@ protected:
|
|||||||
LocalSymbolMap &Symbols,
|
LocalSymbolMap &Symbols,
|
||||||
StubMap &Stubs) = 0;
|
StubMap &Stubs) = 0;
|
||||||
|
|
||||||
void resolveSymbols();
|
/// \brief Resolve relocations to external symbols.
|
||||||
|
void resolveExternalSymbols();
|
||||||
virtual ObjectImage *createObjectImage(const MemoryBuffer *InputBuffer);
|
virtual ObjectImage *createObjectImage(const MemoryBuffer *InputBuffer);
|
||||||
virtual void handleObjectLoaded(ObjectImage *Obj)
|
virtual void handleObjectLoaded(ObjectImage *Obj)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user