Skip to content

[BOLT] Make Relocations a class and add optional field #131638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025
Merged
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
20 changes: 19 additions & 1 deletion bolt/include/bolt/Core/Relocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ enum { R_X86_64_converted_reloc_bit = 0x80 };
namespace bolt {

/// Relocation class.
struct Relocation {
class Relocation {
public:
Relocation(uint64_t Offset, MCSymbol *Symbol, uint32_t Type, uint64_t Addend,
uint64_t Value)
: Offset(Offset), Symbol(Symbol), Type(Type), Optional(false),
Addend(Addend), Value(Value) {}

Relocation()
: Offset(0), Symbol(0), Type(0), Optional(0), Addend(0), Value(0) {}

static Triple::ArchType Arch; /// set by BinaryContext ctor.

/// The offset of this relocation in the object it is contained in.
Expand All @@ -47,6 +56,11 @@ struct Relocation {
/// Relocation type.
uint32_t Type;

private:
/// Relocations added by optimizations can be optional.
bool Optional = false;

public:
/// The offset from the \p Symbol base used to compute the final
/// value of this relocation.
uint64_t Addend;
Expand All @@ -58,6 +72,10 @@ struct Relocation {
/// Return size in bytes of the given relocation \p Type.
static size_t getSizeForType(uint32_t Type);

/// Some relocations added by optimizations are optional, meaning they can be
/// omitted under certain circumstances.
void setOptional() { Optional = true; }

/// Return size of this relocation.
size_t getSize() const { return getSizeForType(Type); }

Expand Down