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
8 changes: 3 additions & 5 deletions bolt/include/bolt/Core/BinaryFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,11 @@ class BinaryFunction {
}

/// Return a label at a given \p Address in the function. If the label does
/// not exist - create it. Assert if the \p Address does not belong to
/// the function. If \p CreatePastEnd is true, then return the function
/// end label when the \p Address points immediately past the last byte
/// of the function.
/// not exist - create it.
///
/// NOTE: the function always returns a local (temp) symbol, even if there's
/// a global symbol that corresponds to an entry at this address.
MCSymbol *getOrCreateLocalLabel(uint64_t Address, bool CreatePastEnd = false);
MCSymbol *getOrCreateLocalLabel(uint64_t Address);

/// Register an data entry at a given \p Offset into the function.
void markDataAtOffset(uint64_t Offset) {
Expand Down
13 changes: 6 additions & 7 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,13 +1035,9 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
return BranchType;
}

MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
bool CreatePastEnd) {
MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address) {
const uint64_t Offset = Address - getAddress();

if ((Offset == getSize()) && CreatePastEnd)
return getFunctionEndLabel();

auto LI = Labels.find(Offset);
if (LI != Labels.end())
return LI->second;
Expand All @@ -1052,6 +1048,9 @@ MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
return IslandSym;
}

if (Offset == getSize())
return getFunctionEndLabel();

MCSymbol *Label = BC.Ctx->createNamedTempSymbol();
Labels[Offset] = Label;

Expand Down Expand Up @@ -1995,7 +1994,7 @@ void BinaryFunction::postProcessJumpTables() {
if (IsBuiltinUnreachable) {
BinaryFunction *TargetBF = BC.getBinaryFunctionAtAddress(EntryAddress);
MCSymbol *Label = TargetBF ? TargetBF->getSymbol()
: getOrCreateLocalLabel(EntryAddress, true);
: getOrCreateLocalLabel(EntryAddress);
JT.Entries.push_back(Label);
continue;
}
Expand All @@ -2006,7 +2005,7 @@ void BinaryFunction::postProcessJumpTables() {
BC.getBinaryFunctionContainingAddress(EntryAddress);
MCSymbol *Label;
if (HasOneParent && TargetBF == this) {
Label = getOrCreateLocalLabel(EntryAddress, true);
Label = getOrCreateLocalLabel(EntryAddress);
} else {
const uint64_t Offset = EntryAddress - TargetBF->getAddress();
Label = Offset ? TargetBF->addEntryPointAtOffset(Offset)
Expand Down
4 changes: 1 addition & 3 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2942,9 +2942,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
ReferencedSymbol =
ReferencedBF->addEntryPointAtOffset(RefFunctionOffset);
} else {
ReferencedSymbol =
ReferencedBF->getOrCreateLocalLabel(Address,
/*CreatePastEnd =*/true);
ReferencedSymbol = ReferencedBF->getOrCreateLocalLabel(Address);

// If ContainingBF != nullptr, it equals ReferencedBF (see
// if-condition above) so we're handling a relocation from a function
Expand Down
Loading