Skip to content

Commit 5f6d9b4

Browse files
[BOLT] Make Relocations a class and add optional field (#131638)
This patch converts `Relocations` from a struct to a class, and introduces the `Optional` field. Patch #116964 will use it. Some optimizations, like `scanExternalRefs`, create relocations that patch the old code. Under certain circumstances these may be skipped without correctness implications.
1 parent 10624e6 commit 5f6d9b4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

bolt/include/bolt/Core/Relocation.h

Lines changed: 19 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,6 +56,11 @@ struct Relocation {
4756
/// Relocation type.
4857
uint32_t Type;
4958

59+
private:
60+
/// Relocations added by optimizations can be optional.
61+
bool Optional = false;
62+
63+
public:
5064
/// The offset from the \p Symbol base used to compute the final
5165
/// value of this relocation.
5266
uint64_t Addend;
@@ -58,6 +72,10 @@ struct Relocation {
5872
/// Return size in bytes of the given relocation \p Type.
5973
static size_t getSizeForType(uint32_t Type);
6074

75+
/// Some relocations added by optimizations are optional, meaning they can be
76+
/// omitted under certain circumstances.
77+
void setOptional() { Optional = true; }
78+
6179
/// Return size of this relocation.
6280
size_t getSize() const { return getSizeForType(Type); }
6381

0 commit comments

Comments
 (0)