Skip to content

Commit 4b4bde5

Browse files
Default the Optional field to false.
1 parent 4e88d96 commit 4b4bde5

File tree

10 files changed

+42
-46
lines changed

10 files changed

+42
-46
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ class BinaryContext {
12961296

12971297
/// Add a Section relocation at a given \p Address.
12981298
void addRelocation(uint64_t Address, MCSymbol *Symbol, uint32_t Type,
1299-
bool Optional, uint64_t Addend = 0, uint64_t Value = 0);
1299+
uint64_t Addend = 0, uint64_t Value = 0);
13001300

13011301
/// Return a relocation registered at a given \p Address, or nullptr if there
13021302
/// is no relocation at such address.
@@ -1309,7 +1309,7 @@ class BinaryContext {
13091309

13101310
/// Register dynamic relocation at \p Address.
13111311
void addDynamicRelocation(uint64_t Address, MCSymbol *Symbol, uint32_t Type,
1312-
bool Optional, uint64_t Addend, uint64_t Value = 0);
1312+
uint64_t Addend, uint64_t Value = 0);
13131313

13141314
/// Return a dynamic relocation registered at a given \p Address, or nullptr
13151315
/// if there is no dynamic relocation at such address.

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ class BinaryFunction {
12611261
/// against \p Symbol.
12621262
/// Assert if the \p Address is not inside this function.
12631263
void addRelocation(uint64_t Address, MCSymbol *Symbol, uint32_t RelType,
1264-
bool Optional, uint64_t Addend, uint64_t Value);
1264+
uint64_t Addend, uint64_t Value);
12651265

12661266
/// Return the name of the section this function originated from.
12671267
std::optional<StringRef> getOriginSectionName() const {

bolt/include/bolt/Core/BinarySection.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,17 @@ class BinarySection {
359359

360360
/// Add a new relocation at the given /p Offset.
361361
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint32_t Type,
362-
bool Optional, uint64_t Addend, uint64_t Value = 0) {
362+
uint64_t Addend, uint64_t Value = 0) {
363363
assert(Offset < getSize() && "offset not within section bounds");
364364
Relocations.emplace(
365-
Relocation{Offset, Symbol, Type, Optional, Addend, Value});
365+
Relocation{Offset, Symbol, Type, /* Optional */ false, Addend, Value});
366366
}
367367

368368
/// Add a dynamic relocation at the given /p Offset.
369369
void addDynamicRelocation(uint64_t Offset, MCSymbol *Symbol, uint32_t Type,
370-
bool Optional, uint64_t Addend,
371-
uint64_t Value = 0) {
370+
uint64_t Addend, uint64_t Value = 0) {
372371
addDynamicRelocation(
373-
Relocation{Offset, Symbol, Type, Optional, Addend, Value});
372+
Relocation{Offset, Symbol, Type, /*Optional*/ false, Addend, Value});
374373
}
375374

376375
void addDynamicRelocation(const Relocation &Reloc) {

bolt/include/bolt/Core/Relocation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Relocation {
4848
uint32_t Type;
4949

5050
/// Relocations added by optimizations can be optional.
51-
bool Optional;
51+
bool Optional = false;
5252

5353
/// The offset from the \p Symbol base used to compute the final
5454
/// value of this relocation.
@@ -61,6 +61,10 @@ struct Relocation {
6161
/// Return size in bytes of the given relocation \p Type.
6262
static size_t getSizeForType(uint32_t Type);
6363

64+
/// Some relocations added by optimizations are optional, meaning they can be
65+
/// omitted under certain circumstances.
66+
void setOptional() { Optional = true; }
67+
6468
/// Return size of this relocation.
6569
size_t getSize() const { return getSizeForType(Type); }
6670

bolt/lib/Core/BinaryContext.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,21 +2284,21 @@ ErrorOr<int64_t> BinaryContext::getSignedValueAtAddress(uint64_t Address,
22842284
}
22852285

22862286
void BinaryContext::addRelocation(uint64_t Address, MCSymbol *Symbol,
2287-
uint32_t Type, bool Optional, uint64_t Addend,
2287+
uint32_t Type, uint64_t Addend,
22882288
uint64_t Value) {
22892289
ErrorOr<BinarySection &> Section = getSectionForAddress(Address);
22902290
assert(Section && "cannot find section for address");
2291-
Section->addRelocation(Address - Section->getAddress(), Symbol, Type,
2292-
Optional, Addend, Value);
2291+
Section->addRelocation(Address - Section->getAddress(), Symbol, Type, Addend,
2292+
Value);
22932293
}
22942294

22952295
void BinaryContext::addDynamicRelocation(uint64_t Address, MCSymbol *Symbol,
2296-
uint32_t Type, bool Optional,
2297-
uint64_t Addend, uint64_t Value) {
2296+
uint32_t Type, uint64_t Addend,
2297+
uint64_t Value) {
22982298
ErrorOr<BinarySection &> Section = getSectionForAddress(Address);
22992299
assert(Section && "cannot find section for address");
23002300
Section->addDynamicRelocation(Address - Section->getAddress(), Symbol, Type,
2301-
Optional, Addend, Value);
2301+
Addend, Value);
23022302
}
23032303

23042304
bool BinaryContext::removeRelocationAt(uint64_t Address) {

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4623,8 +4623,8 @@ bool BinaryFunction::isAArch64Veneer() const {
46234623
}
46244624

46254625
void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
4626-
uint32_t RelType, bool Optional,
4627-
uint64_t Addend, uint64_t Value) {
4626+
uint32_t RelType, uint64_t Addend,
4627+
uint64_t Value) {
46284628
assert(Address >= getAddress() && Address < getAddress() + getMaxSize() &&
46294629
"address is outside of the function");
46304630
uint64_t Offset = Address - getAddress();
@@ -4635,7 +4635,8 @@ void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
46354635
std::map<uint64_t, Relocation> &Rels =
46364636
IsCI ? Islands->Relocations : Relocations;
46374637
if (BC.MIB->shouldRecordCodeRelocation(RelType))
4638-
Rels[Offset] = Relocation{Offset, Symbol, RelType, Optional, Addend, Value};
4638+
Rels[Offset] =
4639+
Relocation{Offset, Symbol, RelType, /*Optional*/ false, Addend, Value};
46394640
}
46404641

46414642
} // namespace bolt

bolt/lib/Core/BinarySection.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ void BinarySection::reorderContents(const std::vector<BinaryData *> &Order,
275275
// of the reordered segment to force LLVM to recognize and map this
276276
// section.
277277
MCSymbol *ZeroSym = BC.registerNameAtAddress("Zero", 0, 0, 0);
278-
addRelocation(OS.tell(), ZeroSym, Relocation::getAbs64(),
279-
/*Optional*/ false, 0xdeadbeef);
278+
addRelocation(OS.tell(), ZeroSym, Relocation::getAbs64(), 0xdeadbeef);
280279

281280
uint64_t Zero = 0;
282281
OS.write(reinterpret_cast<const char *>(&Zero), sizeof(Zero));

bolt/lib/Core/JumpTable.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ void bolt::JumpTable::updateOriginal() {
9292
// to the original jump table.
9393
if (BC.HasRelocations)
9494
getOutputSection().removeRelocationAt(EntryOffset);
95-
getOutputSection().addRelocation(EntryOffset, Entry, RelType,
96-
/*Optional*/ false, RelAddend);
95+
getOutputSection().addRelocation(EntryOffset, Entry, RelType, RelAddend);
9796
EntryOffset += EntrySize;
9897
}
9998
}

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ void LinuxKernelRewriter::processLKKSymtab(bool IsGPL) {
487487
if (!BF)
488488
continue;
489489

490-
BC.addRelocation(EntryAddress, BF->getSymbol(), Relocation::getPC32(),
491-
/*Optional*/ false, 0, *Offset);
490+
BC.addRelocation(EntryAddress, BF->getSymbol(), Relocation::getPC32(), 0,
491+
*Offset);
492492
}
493493
}
494494

@@ -559,7 +559,7 @@ void LinuxKernelRewriter::processInstructionFixups() {
559559
Fixup.Section.addRelocation(Fixup.Offset, &Fixup.Label,
560560
Fixup.IsPCRelative ? ELF::R_X86_64_PC32
561561
: ELF::R_X86_64_64,
562-
/*Optional*/ false, /*Addend*/ 0);
562+
/*Addend*/ 0);
563563
}
564564
}
565565

@@ -828,8 +828,7 @@ Error LinuxKernelRewriter::rewriteORCTables() {
828828

829829
if (Label)
830830
ORCUnwindIPSection->addRelocation(UnwindIPWriter.getOffset(), Label,
831-
Relocation::getPC32(),
832-
/*Optional*/ false, /*Addend*/ 0);
831+
Relocation::getPC32(), /*Addend*/ 0);
833832

834833
const int32_t IPValue =
835834
IP - ORCUnwindIPSection->getAddress() - UnwindIPWriter.getOffset();
@@ -1075,8 +1074,7 @@ Error LinuxKernelRewriter::rewriteStaticCalls() {
10751074
StaticCallSection->getAddress() +
10761075
(Entry.ID - 1) * STATIC_CALL_ENTRY_SIZE;
10771076
StaticCallSection->addRelocation(EntryOffset, Entry.Label,
1078-
ELF::R_X86_64_PC32, /*Optional*/ false,
1079-
/*Addend*/ 0);
1077+
ELF::R_X86_64_PC32, /*Addend*/ 0);
10801078
}
10811079

10821080
return Error::success();
@@ -1380,7 +1378,7 @@ Error LinuxKernelRewriter::rewriteBugTable() {
13801378
BC.MIB->getOrCreateInstLabel(Inst, "__BUG_", BC.Ctx.get());
13811379
const uint64_t EntryOffset = (ID - 1) * BUG_TABLE_ENTRY_SIZE;
13821380
BugTableSection->addRelocation(EntryOffset, Label, ELF::R_X86_64_PC32,
1383-
/*Optional*/ false, /*Addend*/ 0);
1381+
/*Addend*/ 0);
13841382
}
13851383
}
13861384

@@ -1390,7 +1388,7 @@ Error LinuxKernelRewriter::rewriteBugTable() {
13901388
if (!EmittedIDs.count(ID)) {
13911389
const uint64_t EntryOffset = (ID - 1) * BUG_TABLE_ENTRY_SIZE;
13921390
BugTableSection->addRelocation(EntryOffset, nullptr, ELF::R_X86_64_PC32,
1393-
/*Optional*/ false, /*Addend*/ 0);
1391+
/*Addend*/ 0);
13941392
}
13951393
}
13961394
}
@@ -1906,10 +1904,9 @@ Error LinuxKernelRewriter::rewriteStaticKeysJumpTable() {
19061904
(EntryID - 1) * 16;
19071905
StaticKeysJumpSection->addRelocation(EntryOffset, Label,
19081906
ELF::R_X86_64_PC32,
1909-
/*Optional*/ false, /*Addend*/ 0);
1907+
/*Addend*/ 0);
19101908
StaticKeysJumpSection->addRelocation(EntryOffset + 4, Target,
1911-
ELF::R_X86_64_PC32,
1912-
/*Optional*/ false, /*Addend*/ 0);
1909+
ELF::R_X86_64_PC32, /*Addend*/ 0);
19131910
}
19141911
}
19151912
}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,8 +1919,7 @@ void RewriteInstance::relocateEHFrameSection() {
19191919
// Create a relocation against an absolute value since the goal is to
19201920
// preserve the contents of the section independent of the new values
19211921
// of referenced symbols.
1922-
RelocatedEHFrameSection->addRelocation(Offset, nullptr, RelType,
1923-
/*Optional*/ false, Value);
1922+
RelocatedEHFrameSection->addRelocation(Offset, nullptr, RelType, Value);
19241923
};
19251924

19261925
Error E = EHFrameParser::parse(DE, EHFrameSection->getAddress(), createReloc);
@@ -2456,8 +2455,7 @@ void RewriteInstance::readDynamicRelocations(const SectionRef &Section,
24562455
if (Symbol)
24572456
SymbolIndex[Symbol] = getRelocationSymbol(InputFile, Rel);
24582457

2459-
BC->addDynamicRelocation(Rel.getOffset(), Symbol, RType, /*Optional*/ false,
2460-
Addend);
2458+
BC->addDynamicRelocation(Rel.getOffset(), Symbol, RType, Addend);
24612459
}
24622460
}
24632461

@@ -2488,8 +2486,7 @@ void RewriteInstance::readDynamicRelrRelocations(BinarySection &Section) {
24882486
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: R_*_RELATIVE relocation at 0x"
24892487
<< Twine::utohexstr(Address) << " to 0x"
24902488
<< Twine::utohexstr(Addend) << '\n';);
2491-
BC->addDynamicRelocation(Address, nullptr, RType, /*Optional*/ false,
2492-
Addend);
2489+
BC->addDynamicRelocation(Address, nullptr, RType, Addend);
24932490
};
24942491

24952492
DataExtractor DE = DataExtractor(Section.getContents(),
@@ -2689,8 +2686,8 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26892686
// This might be a relocation for an ABS symbols like __global_pointer$ on
26902687
// RISC-V
26912688
ContainingBF->addRelocation(Rel.getOffset(), ReferencedSymbol,
2692-
Relocation::getType(Rel), /*Optional*/ false,
2693-
0, cantFail(Symbol.getValue()));
2689+
Relocation::getType(Rel), 0,
2690+
cantFail(Symbol.getValue()));
26942691
return;
26952692
}
26962693
}
@@ -2722,7 +2719,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
27222719
// the code. It's required to properly handle cases where
27232720
// "symbol + addend" references an object different from "symbol".
27242721
ContainingBF->addRelocation(Rel.getOffset(), ReferencedSymbol, RType,
2725-
/*Optional*/ false, Addend, ExtractedValue);
2722+
Addend, ExtractedValue);
27262723
} else {
27272724
LLVM_DEBUG({
27282725
dbgs() << "BOLT-DEBUG: not creating PC-relative relocation at"
@@ -2956,10 +2953,10 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
29562953

29572954
if (IsFromCode)
29582955
ContainingBF->addRelocation(Rel.getOffset(), ReferencedSymbol, RType,
2959-
/*Optional*/ false, Addend, ExtractedValue);
2956+
Addend, ExtractedValue);
29602957
else if (IsToCode || ForceRelocation)
2961-
BC->addRelocation(Rel.getOffset(), ReferencedSymbol, RType,
2962-
/*Optional*/ false, Addend, ExtractedValue);
2958+
BC->addRelocation(Rel.getOffset(), ReferencedSymbol, RType, Addend,
2959+
ExtractedValue);
29632960
else
29642961
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: ignoring relocation from data to data\n");
29652962
}

0 commit comments

Comments
 (0)