Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,15 +1515,15 @@ void RuntimeDyldELF::resolveAArch64Branch(unsigned 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()) {
auto [It, Inserted] = Stubs.try_emplace(Value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem here is that before, we only added an entry to the map if resolveAArch64ShortBranch returned false. Now, it could return true and it's too late, we already added the entry to the map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidSpickett Ah, I see. Without this patch, we sometimes don't insert a new entry depending on the outcome of resolveAArch64ShortBranch.

Thanks for the revert!

if (!Inserted) {
resolveRelocation(Section, Offset,
Section.getLoadAddressWithOffset(i->second), RelType, 0);
Section.getLoadAddressWithOffset(It->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();
It->second = Section.getStubOffset();
uint8_t *StubTargetAddr = createStubFunction(
Section.getAddressWithOffset(Section.getStubOffset()));

Expand Down Expand Up @@ -1837,15 +1837,15 @@ RuntimeDyldELF::processRelocationRef(
SectionEntry &Section = Sections[SectionID];

// Look up for existing stub.
StubMap::const_iterator i = Stubs.find(Value);
if (i != Stubs.end()) {
RelocationEntry RE(SectionID, Offset, RelType, i->second);
auto [It, Inserted] = Stubs.try_emplace(Value);
if (!Inserted) {
RelocationEntry RE(SectionID, Offset, RelType, It->second);
addRelocationForSection(RE, SectionID);
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();
It->second = Section.getStubOffset();

unsigned AbiVariant = Obj.getPlatformFlags();

Expand Down Expand Up @@ -2075,10 +2075,10 @@ RuntimeDyldELF::processRelocationRef(
SectionEntry &Section = Sections[SectionID];

// Look for an existing stub.
StubMap::const_iterator i = Stubs.find(Value);
auto [It, Inserted] = Stubs.try_emplace(Value);
uintptr_t StubAddress;
if (i != Stubs.end()) {
StubAddress = uintptr_t(Section.getAddressWithOffset(i->second));
if (!Inserted) {
StubAddress = uintptr_t(Section.getAddressWithOffset(It->second));
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function.
Expand All @@ -2089,7 +2089,7 @@ RuntimeDyldELF::processRelocationRef(
alignTo(BaseAddress + Section.getStubOffset(), getStubAlignment());
unsigned StubOffset = StubAddress - BaseAddress;

Stubs[Value] = StubOffset;
It->second = StubOffset;
createStubFunction((uint8_t *)StubAddress);
RelocationEntry RE(SectionID, StubOffset + 8, ELF::R_390_64,
Value.Offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ class RuntimeDyldMachOARM
// This is an ARM branch relocation, need to use a stub function.
// Look up for existing stub.
SectionEntry &Section = Sections[RE.SectionID];
RuntimeDyldMachO::StubMap::const_iterator i = Stubs.find(Value);
auto [It, Inserted] = Stubs.try_emplace(Value);
uint8_t *Addr;
if (i != Stubs.end()) {
Addr = Section.getAddressWithOffset(i->second);
if (!Inserted) {
Addr = Section.getAddressWithOffset(It->second);
} else {
// Create a new stub function.
assert(Section.getStubOffset() % 4 == 0 && "Misaligned stub");
Stubs[Value] = Section.getStubOffset();
It->second = Section.getStubOffset();
uint32_t StubOpcode = 0;
if (RE.RelType == MachO::ARM_RELOC_BR24)
StubOpcode = 0xe51ff004; // ldr pc, [pc, #-4]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ class RuntimeDyldMachOX86_64
assert(RE.IsPCRel);
assert(RE.Size == 2);
Value.Offset -= RE.Addend;
RuntimeDyldMachO::StubMap::const_iterator i = Stubs.find(Value);
auto [It, Inserted] = Stubs.try_emplace(Value);
uint8_t *Addr;
if (i != Stubs.end()) {
Addr = Section.getAddressWithOffset(i->second);
if (!Inserted) {
Addr = Section.getAddressWithOffset(It->second);
} else {
Stubs[Value] = Section.getStubOffset();
It->second = Section.getStubOffset();
uint8_t *GOTEntry = Section.getAddressWithOffset(Section.getStubOffset());
RelocationEntry GOTRE(RE.SectionID, Section.getStubOffset(),
MachO::X86_64_RELOC_UNSIGNED, Value.Offset, false,
Expand Down