Skip to content

Commit 075cca3

Browse files
vchuravytstellar
authored andcommitted
[RTDYLD] support absolute relocations where needed
These appear in some sections, such as DWARF tables, since RuntimeDyldELF explicitly maps to this as a sentinel value: https://github.com/llvm/llvm-project/blob/29d1fba7b5335d969e3e5daa84b7a25cd1fa75ef/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp#L1199 That could then be a source of problems if it tried to examine these sections (for example, with either setProcessAllSections(true) or ORCv2 on i686). Replaces https://reviews.llvm.org/D89241 Reviewed By: lhames, vchuravy Differential Revision: https://reviews.llvm.org/D90722 (cherry picked from commit 85f4be0)
1 parent d8e8ae1 commit 075cca3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
308308
<< " SID: " << SectionID
309309
<< " Offset: " << format("%p", (uintptr_t)Addr)
310310
<< " flags: " << *FlagsOrErr << "\n");
311-
GlobalSymbolTable[Name] = SymbolTableEntry(SectionID, Addr, *JITSymFlags);
311+
if (!Name.empty()) // Skip absolute symbol relocations.
312+
GlobalSymbolTable[Name] =
313+
SymbolTableEntry(SectionID, Addr, *JITSymFlags);
312314
} else if (SymType == object::SymbolRef::ST_Function ||
313315
SymType == object::SymbolRef::ST_Data ||
314316
SymType == object::SymbolRef::ST_Unknown ||
@@ -340,8 +342,9 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
340342
<< " SID: " << SectionID
341343
<< " Offset: " << format("%p", (uintptr_t)SectOffset)
342344
<< " flags: " << *FlagsOrErr << "\n");
343-
GlobalSymbolTable[Name] =
344-
SymbolTableEntry(SectionID, SectOffset, *JITSymFlags);
345+
if (!Name.empty()) // Skip absolute symbol relocations
346+
GlobalSymbolTable[Name] =
347+
SymbolTableEntry(SectionID, SectOffset, *JITSymFlags);
345348
}
346349
}
347350

@@ -769,8 +772,9 @@ Error RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
769772

770773
LLVM_DEBUG(dbgs() << "Allocating common symbol " << Name << " address "
771774
<< format("%p", Addr) << "\n");
772-
GlobalSymbolTable[Name] =
773-
SymbolTableEntry(SectionID, Offset, std::move(*JITSymFlags));
775+
if (!Name.empty()) // Skip absolute symbol relocations.
776+
GlobalSymbolTable[Name] =
777+
SymbolTableEntry(SectionID, Offset, std::move(*JITSymFlags));
774778
Offset += Size;
775779
Addr += Size;
776780
}
@@ -930,6 +934,8 @@ void RuntimeDyldImpl::addRelocationForSymbol(const RelocationEntry &RE,
930934
if (Loc == GlobalSymbolTable.end()) {
931935
ExternalSymbolRelocations[SymbolName].push_back(RE);
932936
} else {
937+
assert(!SymbolName.empty() &&
938+
"Empty symbol should not be in GlobalSymbolTable");
933939
// Copy the RE since we want to modify its addend.
934940
RelocationEntry RECopy = RE;
935941
const auto &SymInfo = Loc->second;
@@ -1234,7 +1240,8 @@ void RuntimeDyldImpl::finalizeAsync(
12341240

12351241
for (auto &RelocKV : SharedThis->ExternalSymbolRelocations) {
12361242
StringRef Name = RelocKV.first();
1237-
assert(!Name.empty() && "Symbol has no name?");
1243+
if (Name.empty()) // Skip absolute symbol relocations.
1244+
continue;
12381245
assert(!SharedThis->GlobalSymbolTable.count(Name) &&
12391246
"Name already processed. RuntimeDyld instances can not be re-used "
12401247
"when finalizing with finalizeAsync.");

0 commit comments

Comments
 (0)