Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LLVM RuntimeDyldELF SmallVector crash fix
--- lib\ExecutionEngine\RuntimeDyld\RuntimeDyldELF.cpp (A) 2020-02-01 21:42:12.039755300 +0100
+++ lib\ExecutionEngine\RuntimeDyld\RuntimeDyldELF.cpp (B) 2020-02-01 21:07:03.168621000 +0100
@@ -926,8 +926,7 @@
// symbol in the target address space.
void RuntimeDyldELF::resolveRelocation(const RelocationEntry &RE,
uint64_t Value) {
- const SectionEntry &Section = Sections[RE.SectionID];
- return resolveRelocation(Section, RE.Offset, Value, RE.RelType, RE.Addend,
+ return resolveRelocation(Sections[RE.SectionID], RE.Offset, Value, RE.RelType, RE.Addend,
RE.SymOffset, RE.SectionID);
}
@@ -1056,34 +1055,33 @@
StubMap &Stubs) {
LLVM_DEBUG(dbgs() << "\t\tThis is an AArch64 branch relocation.");
- SectionEntry &Section = Sections[SectionID];
uint64_t Offset = RelI->getOffset();
unsigned RelType = RelI->getType();
// Look for an existing stub.
StubMap::const_iterator i = Stubs.find(Value);
if (i != Stubs.end()) {
- resolveRelocation(Section, Offset,
- (uint64_t)Section.getAddressWithOffset(i->second),
+ resolveRelocation(Sections[SectionID], Offset,
+ (uint64_t)Sections[SectionID].getAddressWithOffset(i->second),
RelType, 0);
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else if (!resolveAArch64ShortBranch(SectionID, RelI, Value)) {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
- Stubs[Value] = Section.getStubOffset();
+ Stubs[Value] = Sections[SectionID].getStubOffset();
uint8_t *StubTargetAddr = createStubFunction(
- Section.getAddressWithOffset(Section.getStubOffset()));
+ Sections[SectionID].getAddressWithOffset(Sections[SectionID].getStubOffset()));
- RelocationEntry REmovz_g3(SectionID, StubTargetAddr - Section.getAddress(),
+ RelocationEntry REmovz_g3(SectionID, StubTargetAddr - Sections[SectionID].getAddress(),
ELF::R_AARCH64_MOVW_UABS_G3, Value.Addend);
RelocationEntry REmovk_g2(SectionID,
- StubTargetAddr - Section.getAddress() + 4,
+ StubTargetAddr - Sections[SectionID].getAddress() + 4,
ELF::R_AARCH64_MOVW_UABS_G2_NC, Value.Addend);
RelocationEntry REmovk_g1(SectionID,
- StubTargetAddr - Section.getAddress() + 8,
+ StubTargetAddr - Sections[SectionID].getAddress() + 8,
ELF::R_AARCH64_MOVW_UABS_G1_NC, Value.Addend);
RelocationEntry REmovk_g0(SectionID,
- StubTargetAddr - Section.getAddress() + 12,
+ StubTargetAddr - Sections[SectionID].getAddress() + 12,
ELF::R_AARCH64_MOVW_UABS_G0_NC, Value.Addend);
if (Value.SymbolName) {
@@ -1097,11 +1095,11 @@
addRelocationForSection(REmovk_g1, Value.SectionID);
addRelocationForSection(REmovk_g0, Value.SectionID);
}
- resolveRelocation(Section, Offset,
- reinterpret_cast<uint64_t>(Section.getAddressWithOffset(
- Section.getStubOffset())),
+ resolveRelocation(Sections[SectionID], Offset,
+ reinterpret_cast<uint64_t>(Sections[SectionID].getAddressWithOffset(
+ Sections[SectionID].getStubOffset())),
RelType, 0);
- Section.advanceStubOffset(getMaxStubSize());
+ Sections[SectionID].advanceStubOffset(getMaxStubSize());
}
}
@@ -1224,34 +1222,33 @@
RelType == ELF::R_ARM_JUMP24) {
// This is an ARM branch relocation, need to use a stub function.
LLVM_DEBUG(dbgs() << "\t\tThis is an ARM branch relocation.\n");
- SectionEntry &Section = Sections[SectionID];
// Look for an existing stub.
StubMap::const_iterator i = Stubs.find(Value);
if (i != Stubs.end()) {
resolveRelocation(
- Section, Offset,
- reinterpret_cast<uint64_t>(Section.getAddressWithOffset(i->second)),
+ Sections[SectionID], Offset,
+ reinterpret_cast<uint64_t>(Sections[SectionID].getAddressWithOffset(i->second)),
RelType, 0);
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
- Stubs[Value] = Section.getStubOffset();
+ Stubs[Value] = Sections[SectionID].getStubOffset();
uint8_t *StubTargetAddr = createStubFunction(
- Section.getAddressWithOffset(Section.getStubOffset()));
- RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(),
+ Sections[SectionID].getAddressWithOffset(Sections[SectionID].getStubOffset()));
+ RelocationEntry RE(SectionID, StubTargetAddr - Sections[SectionID].getAddress(),
ELF::R_ARM_ABS32, Value.Addend);
if (Value.SymbolName)
addRelocationForSymbol(RE, Value.SymbolName);
else
addRelocationForSection(RE, Value.SectionID);
- resolveRelocation(Section, Offset, reinterpret_cast<uint64_t>(
- Section.getAddressWithOffset(
- Section.getStubOffset())),
+ resolveRelocation(Sections[SectionID], Offset, reinterpret_cast<uint64_t>(
+ Sections[SectionID].getAddressWithOffset(
+ Sections[SectionID].getStubOffset())),
RelType, 0);
- Section.advanceStubOffset(getMaxStubSize());
+ Sections[SectionID].advanceStubOffset(getMaxStubSize());
}
} else {
uint32_t *Placeholder =
@@ -1272,7 +1269,6 @@
if (RelType == ELF::R_MIPS_26) {
// This is an Mips branch relocation, need to use a stub function.
LLVM_DEBUG(dbgs() << "\t\tThis is a Mips branch relocation.");
- SectionEntry &Section = Sections[SectionID];
// Extract the addend from the instruction.
// We shift up by two since the Value will be down shifted again
@@ -1290,18 +1286,18 @@
} else {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
- Stubs[Value] = Section.getStubOffset();
+ Stubs[Value] = Sections[SectionID].getStubOffset();
unsigned AbiVariant = Obj.getPlatformFlags();
uint8_t *StubTargetAddr = createStubFunction(
- Section.getAddressWithOffset(Section.getStubOffset()), AbiVariant);
+ Sections[SectionID].getAddressWithOffset(Sections[SectionID].getStubOffset()), AbiVariant);
// Creating Hi and Lo relocations for the filled stub instructions.
- RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(),
+ RelocationEntry REHi(SectionID, StubTargetAddr - Sections[SectionID].getAddress(),
ELF::R_MIPS_HI16, Value.Addend);
RelocationEntry RELo(SectionID,
- StubTargetAddr - Section.getAddress() + 4,
+ StubTargetAddr - Sections[SectionID].getAddress() + 4,
ELF::R_MIPS_LO16, Value.Addend);
if (Value.SymbolName) {
@@ -1312,9 +1308,9 @@
addRelocationForSection(RELo, Value.SectionID);
}
- RelocationEntry RE(SectionID, Offset, RelType, Section.getStubOffset());
+ RelocationEntry RE(SectionID, Offset, RelType, Sections[SectionID].getStubOffset());
addRelocationForSection(RE, SectionID);
- Section.advanceStubOffset(getMaxStubSize());
+ Sections[SectionID].advanceStubOffset(getMaxStubSize());
}
} else if (RelType == ELF::R_MIPS_HI16 || RelType == ELF::R_MIPS_PCHI16) {
int64_t Addend = (Opcode & 0x0000ffff) << 16;
@@ -1374,7 +1370,6 @@
} else if (RelType == ELF::R_MIPS_26) {
// This is an Mips branch relocation, need to use a stub function.
LLVM_DEBUG(dbgs() << "\t\tThis is a Mips branch relocation.");
- SectionEntry &Section = Sections[SectionID];
// Look up for existing stub.
StubMap::const_iterator i = Stubs.find(Value);
@@ -1385,19 +1380,19 @@
} else {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
- Stubs[Value] = Section.getStubOffset();
+ Stubs[Value] = Sections[SectionID].getStubOffset();
unsigned AbiVariant = Obj.getPlatformFlags();
uint8_t *StubTargetAddr = createStubFunction(
- Section.getAddressWithOffset(Section.getStubOffset()), AbiVariant);
+ Sections[SectionID].getAddressWithOffset(Sections[SectionID].getStubOffset()), AbiVariant);
if (IsMipsN32ABI) {
// Creating Hi and Lo relocations for the filled stub instructions.
- RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(),
+ RelocationEntry REHi(SectionID, StubTargetAddr - Sections[SectionID].getAddress(),
ELF::R_MIPS_HI16, Value.Addend);
RelocationEntry RELo(SectionID,
- StubTargetAddr - Section.getAddress() + 4,
+ StubTargetAddr - Sections[SectionID].getAddress() + 4,
ELF::R_MIPS_LO16, Value.Addend);
if (Value.SymbolName) {
addRelocationForSymbol(REHi, Value.SymbolName);
@@ -1410,16 +1405,16 @@
// Creating Highest, Higher, Hi and Lo relocations for the filled stub
// instructions.
RelocationEntry REHighest(SectionID,
- StubTargetAddr - Section.getAddress(),
+ StubTargetAddr - Sections[SectionID].getAddress(),
ELF::R_MIPS_HIGHEST, Value.Addend);
RelocationEntry REHigher(SectionID,
- StubTargetAddr - Section.getAddress() + 4,
+ StubTargetAddr - Sections[SectionID].getAddress() + 4,
ELF::R_MIPS_HIGHER, Value.Addend);
RelocationEntry REHi(SectionID,
- StubTargetAddr - Section.getAddress() + 12,
+ StubTargetAddr - Sections[SectionID].getAddress() + 12,
ELF::R_MIPS_HI16, Value.Addend);
RelocationEntry RELo(SectionID,
- StubTargetAddr - Section.getAddress() + 20,
+ StubTargetAddr - Sections[SectionID].getAddress() + 20,
ELF::R_MIPS_LO16, Value.Addend);
if (Value.SymbolName) {
addRelocationForSymbol(REHighest, Value.SymbolName);
@@ -1433,9 +1428,9 @@
addRelocationForSection(RELo, Value.SectionID);
}
}
- RelocationEntry RE(SectionID, Offset, RelType, Section.getStubOffset());
+ RelocationEntry RE(SectionID, Offset, RelType, Sections[SectionID].getStubOffset());
addRelocationForSection(RE, SectionID);
- Section.advanceStubOffset(getMaxStubSize());
+ Sections[SectionID].advanceStubOffset(getMaxStubSize());
}
} else {
processSimpleRelocation(SectionID, Offset, RelType, Value);
@@ -1450,8 +1445,7 @@
// an external symbol (either Value.SymbolName is set, or SymType is
// Symbol::ST_Unknown) or if the target address is not within the
// signed 24-bits branch address.
- SectionEntry &Section = Sections[SectionID];
- uint8_t *Target = Section.getAddressWithOffset(Offset);
+ uint8_t *Target = Sections[SectionID].getAddressWithOffset(Offset);
bool RangeOverflow = false;
bool IsExtern = Value.SymbolName || SymType == SymbolRef::ST_Unknown;
if (!IsExtern) {
@@ -1488,26 +1482,26 @@
StubMap::const_iterator i = Stubs.find(Value);
if (i != Stubs.end()) {
// Symbol function stub already created, just relocate to it
- resolveRelocation(Section, Offset,
+ resolveRelocation(Sections[SectionID], Offset,
reinterpret_cast<uint64_t>(
- Section.getAddressWithOffset(i->second)),
+ Sections[SectionID].getAddressWithOffset(i->second)),
RelType, 0);
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
- Stubs[Value] = Section.getStubOffset();
+ Stubs[Value] = Sections[SectionID].getStubOffset();
uint8_t *StubTargetAddr = createStubFunction(
- Section.getAddressWithOffset(Section.getStubOffset()),
+ Sections[SectionID].getAddressWithOffset(Sections[SectionID].getStubOffset()),
AbiVariant);
- RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(),
+ RelocationEntry RE(SectionID, StubTargetAddr - Sections[SectionID].getAddress(),
ELF::R_PPC64_ADDR64, Value.Addend);
// Generates the 64-bits address loads as exemplified in section
// 4.5.1 in PPC64 ELF ABI. Note that the relocations need to
// apply to the low part of the instructions, so we have to update
// the offset according to the target endianness.
- uint64_t StubRelocOffset = StubTargetAddr - Section.getAddress();
+ uint64_t StubRelocOffset = StubTargetAddr - Sections[SectionID].getAddress();
if (!IsTargetLittleEndian)
StubRelocOffset += 2;
@@ -1532,11 +1526,11 @@
addRelocationForSection(REl, Value.SectionID);
}
- resolveRelocation(Section, Offset, reinterpret_cast<uint64_t>(
- Section.getAddressWithOffset(
- Section.getStubOffset())),
+ resolveRelocation(Sections[SectionID], Offset, reinterpret_cast<uint64_t>(
+ Sections[SectionID].getAddressWithOffset(
+ Sections[SectionID].getStubOffset())),
RelType, 0);
- Section.advanceStubOffset(getMaxStubSize());
+ Sections[SectionID].advanceStubOffset(getMaxStubSize());
}
if (IsExtern || (AbiVariant == 2 && Value.SectionID != SectionID)) {
// Restore the TOC for external calls
@@ -1613,22 +1607,21 @@
// a stub for every relocation, so using a GOT in JIT code should be
// no less space efficient than using an explicit constant pool.
LLVM_DEBUG(dbgs() << "\t\tThis is a SystemZ indirect relocation.");
- SectionEntry &Section = Sections[SectionID];
// Look for an existing stub.
StubMap::const_iterator i = Stubs.find(Value);
uintptr_t StubAddress;
if (i != Stubs.end()) {
- StubAddress = uintptr_t(Section.getAddressWithOffset(i->second));
+ StubAddress = uintptr_t(Sections[SectionID].getAddressWithOffset(i->second));
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
- uintptr_t BaseAddress = uintptr_t(Section.getAddress());
+ uintptr_t BaseAddress = uintptr_t(Sections[SectionID].getAddress());
uintptr_t StubAlignment = getStubAlignment();
StubAddress =
- (BaseAddress + Section.getStubOffset() + StubAlignment - 1) &
+ (BaseAddress + Sections[SectionID].getStubOffset() + StubAlignment - 1) &
-StubAlignment;
unsigned StubOffset = StubAddress - BaseAddress;
@@ -1640,14 +1633,14 @@
addRelocationForSymbol(RE, Value.SymbolName);
else
addRelocationForSection(RE, Value.SectionID);
- Section.advanceStubOffset(getMaxStubSize());
+ Sections[SectionID].advanceStubOffset(getMaxStubSize());
}
if (RelType == ELF::R_390_GOTENT)
- resolveRelocation(Section, Offset, StubAddress + 8, ELF::R_390_PC32DBL,
+ resolveRelocation(Sections[SectionID], Offset, StubAddress + 8, ELF::R_390_PC32DBL,
Addend);
else
- resolveRelocation(Section, Offset, StubAddress, RelType, Addend);
+ resolveRelocation(Sections[SectionID], Offset, StubAddress, RelType, Addend);
} else if (Arch == Triple::x86_64) {
if (RelType == ELF::R_X86_64_PLT32) {
// The way the PLT relocations normally work is that the linker allocates
@@ -1669,27 +1662,26 @@
if (Value.SymbolName) {
// This is a call to an external function.
// Look for an existing stub.
- SectionEntry &Section = Sections[SectionID];
StubMap::const_iterator i = Stubs.find(Value);
uintptr_t StubAddress;
if (i != Stubs.end()) {
- StubAddress = uintptr_t(Section.getAddress()) + i->second;
+ StubAddress = uintptr_t(Sections[SectionID].getAddress()) + i->second;
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function (equivalent to a PLT entry).
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
- uintptr_t BaseAddress = uintptr_t(Section.getAddress());
+ uintptr_t BaseAddress = uintptr_t(Sections[SectionID].getAddress());
uintptr_t StubAlignment = getStubAlignment();
StubAddress =
- (BaseAddress + Section.getStubOffset() + StubAlignment - 1) &
+ (BaseAddress + Sections[SectionID].getStubOffset() + StubAlignment - 1) &
-StubAlignment;
unsigned StubOffset = StubAddress - BaseAddress;
Stubs[Value] = StubOffset;
createStubFunction((uint8_t *)StubAddress);
// Bump our stub offset counter
- Section.advanceStubOffset(getMaxStubSize());
+ Sections[SectionID].advanceStubOffset(getMaxStubSize());
// Allocate a GOT Entry
uint64_t GOTOffset = allocateGOTEntries(1);
@@ -1705,7 +1697,7 @@
}
// Make the target call a call into the stub table.
- resolveRelocation(Section, Offset, StubAddress, ELF::R_X86_64_PC32,
+ resolveRelocation(Sections[SectionID], Offset, StubAddress, ELF::R_X86_64_PC32,
Addend);
} else {
RelocationEntry RE(SectionID, Offset, ELF::R_X86_64_PC32, Value.Addend,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.