Skip to content

Commit a24c9fb

Browse files
Relocation is now a class.
1 parent 4b4bde5 commit a24c9fb

File tree

8 files changed

+30
-24
lines changed

8 files changed

+30
-24
lines changed

bolt/include/bolt/Core/BinarySection.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,13 @@ class BinarySection {
361361
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint32_t Type,
362362
uint64_t Addend, uint64_t Value = 0) {
363363
assert(Offset < getSize() && "offset not within section bounds");
364-
Relocations.emplace(
365-
Relocation{Offset, Symbol, Type, /* Optional */ false, Addend, Value});
364+
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
366365
}
367366

368367
/// Add a dynamic relocation at the given /p Offset.
369368
void addDynamicRelocation(uint64_t Offset, MCSymbol *Symbol, uint32_t Type,
370369
uint64_t Addend, uint64_t Value = 0) {
371-
addDynamicRelocation(
372-
Relocation{Offset, Symbol, Type, /*Optional*/ false, Addend, Value});
370+
addDynamicRelocation(Relocation{Offset, Symbol, Type, Addend, Value});
373371
}
374372

375373
void addDynamicRelocation(const Relocation &Reloc) {
@@ -403,13 +401,13 @@ class BinarySection {
403401

404402
/// Lookup the relocation (if any) at the given /p Offset.
405403
const Relocation *getDynamicRelocationAt(uint64_t Offset) const {
406-
Relocation Key{Offset, 0, 0, 0, 0, 0};
404+
Relocation Key{Offset, 0, 0, 0, 0};
407405
auto Itr = DynamicRelocations.find(Key);
408406
return Itr != DynamicRelocations.end() ? &*Itr : nullptr;
409407
}
410408

411409
std::optional<Relocation> takeDynamicRelocationAt(uint64_t Offset) {
412-
Relocation Key{Offset, 0, 0, 0, 0, 0};
410+
Relocation Key{Offset, 0, 0, 0, 0};
413411
auto Itr = DynamicRelocations.find(Key);
414412

415413
if (Itr == DynamicRelocations.end())

bolt/include/bolt/Core/Relocation.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ enum { R_X86_64_converted_reloc_bit = 0x80 };
3535
namespace bolt {
3636

3737
/// Relocation class.
38-
struct Relocation {
38+
class Relocation {
39+
public:
40+
Relocation(uint64_t Offset, MCSymbol *Symbol, uint32_t Type, uint64_t Addend,
41+
uint64_t Value)
42+
: Offset(Offset), Symbol(Symbol), Type(Type), Optional(false),
43+
Addend(Addend), Value(Value) {}
44+
45+
Relocation()
46+
: Offset(0), Symbol(0), Type(0), Optional(0), Addend(0), Value(0) {}
47+
3948
static Triple::ArchType Arch; /// set by BinaryContext ctor.
4049

4150
/// The offset of this relocation in the object it is contained in.
@@ -47,9 +56,11 @@ struct Relocation {
4756
/// Relocation type.
4857
uint32_t Type;
4958

59+
private:
5060
/// Relocations added by optimizations can be optional.
5161
bool Optional = false;
5262

63+
public:
5364
/// The offset from the \p Symbol base used to compute the final
5465
/// value of this relocation.
5566
uint64_t Addend;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4635,8 +4635,7 @@ 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] =
4639-
Relocation{Offset, Symbol, RelType, /*Optional*/ false, Addend, Value};
4638+
Rels[Offset] = Relocation{Offset, Symbol, RelType, Addend, Value};
46404639
}
46414640

46424641
} // namespace bolt

bolt/lib/Core/BinarySection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ BinarySection::hash(const BinaryData &BD,
4949

5050
uint64_t Offset = BD.getAddress() - getAddress();
5151
const uint64_t EndOffset = BD.getEndAddress() - getAddress();
52-
auto Begin = Relocations.lower_bound(Relocation{Offset, 0, 0, 0, 0, 0});
53-
auto End = Relocations.upper_bound(Relocation{EndOffset, 0, 0, 0, 0, 0});
52+
auto Begin = Relocations.lower_bound(Relocation{Offset, 0, 0, 0, 0});
53+
auto End = Relocations.upper_bound(Relocation{EndOffset, 0, 0, 0, 0});
5454
const StringRef Contents = getContents();
5555

5656
while (Begin != End) {

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ void RewriteInstance::updateRtFiniReloc() {
14201420
// desired value.
14211421
FiniArraySection->addPendingRelocation(Relocation{
14221422
/*Offset*/ 0, /*Symbol*/ nullptr, /*Type*/ Relocation::getAbs64(),
1423-
/*Optional*/ false, /*Addend*/ RT->getRuntimeFiniAddress(), /*Value*/ 0});
1423+
/*Addend*/ RT->getRuntimeFiniAddress(), /*Value*/ 0});
14241424
}
14251425

14261426
void RewriteInstance::registerFragments() {

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,8 +2291,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
22912291

22922292
auto [RelSymbol, RelAddend] = extractFixupExpr(Fixup);
22932293

2294-
return Relocation(
2295-
{RelOffset, RelSymbol, RelType, /*Optional*/ false, RelAddend, 0});
2294+
return Relocation({RelOffset, RelSymbol, RelType, RelAddend, 0});
22962295
}
22972296

22982297
uint16_t getMinFunctionAlignment() const override { return 4; }

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,8 +2467,7 @@ class X86MCPlusBuilder : public MCPlusBuilder {
24672467

24682468
auto [RelSymbol, RelAddend] = extractFixupExpr(Fixup);
24692469

2470-
return Relocation(
2471-
{RelOffset, RelSymbol, RelType, /*Optional*/ false, RelAddend, 0});
2470+
return Relocation({RelOffset, RelSymbol, RelType, RelAddend, 0});
24722471
}
24732472

24742473
bool replaceImmWithSymbolRef(MCInst &Inst, const MCSymbol *Symbol,

bolt/unittests/Core/BinaryContext.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ TEST_P(BinaryContextTester, FlushPendingRelocCALL26) {
9696
DataSize, 4);
9797
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
9898
ASSERT_TRUE(RelSymbol1);
99-
BS.addPendingRelocation(Relocation{8, RelSymbol1, ELF::R_AARCH64_CALL26,
100-
/*Optional*/ false, 0, 0});
99+
BS.addPendingRelocation(
100+
Relocation{8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0});
101101
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
102102
ASSERT_TRUE(RelSymbol2);
103-
BS.addPendingRelocation(Relocation{12, RelSymbol2, ELF::R_AARCH64_CALL26,
104-
/*Optional*/ false, 0, 0});
103+
BS.addPendingRelocation(
104+
Relocation{12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0});
105105

106106
SmallVector<char> Vect(DataSize);
107107
raw_svector_ostream OS(Vect);
@@ -138,12 +138,12 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
138138
(uint8_t *)Data, Size, 4);
139139
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
140140
ASSERT_TRUE(RelSymbol1);
141-
BS.addPendingRelocation(Relocation{8, RelSymbol1, ELF::R_AARCH64_JUMP26,
142-
/*Optional*/ false, 0, 0});
141+
BS.addPendingRelocation(
142+
Relocation{8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0});
143143
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
144144
ASSERT_TRUE(RelSymbol2);
145-
BS.addPendingRelocation(Relocation{12, RelSymbol2, ELF::R_AARCH64_JUMP26,
146-
/*Optional*/ false, 0, 0});
145+
BS.addPendingRelocation(
146+
Relocation{12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0});
147147

148148
SmallVector<char> Vect(Size);
149149
raw_svector_ostream OS(Vect);

0 commit comments

Comments
 (0)