Skip to content

Commit 9cbe2e4

Browse files
authored
Merge branch 'main' into cir_upstream_array_init
2 parents ea0aee4 + 14c95e0 commit 9cbe2e4

File tree

1,835 files changed

+167045
-136584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,835 files changed

+167045
-136584
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
fetch-depth: 1
6666
- name: Get subprojects that have doc changes
6767
id: docs-changed-subprojects
68-
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
68+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
6969
with:
7070
files_yaml: |
7171
llvm:

.github/workflows/pr-code-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- name: Get changed files
3434
id: changed-files
35-
uses: tj-actions/changed-files@fea790cb660e33aef4bdf07304e28fedd77dfa13 # v39.2.4
35+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
3636
with:
3737
separator: ","
3838
skip_initial_fetch: true

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ class BinaryContext {
12951295
void foldFunction(BinaryFunction &ChildBF, BinaryFunction &ParentBF);
12961296

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

13011301
/// Return a relocation registered at a given \p Address, or nullptr if there
@@ -1308,7 +1308,7 @@ class BinaryContext {
13081308
}
13091309

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

13141314
/// Return a dynamic relocation registered at a given \p Address, or nullptr

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ class BinaryFunction {
12601260
/// Register relocation type \p RelType at a given \p Address in the function
12611261
/// against \p Symbol.
12621262
/// Assert if the \p Address is not inside this function.
1263-
void addRelocation(uint64_t Address, MCSymbol *Symbol, uint64_t RelType,
1263+
void addRelocation(uint64_t Address, MCSymbol *Symbol, uint32_t RelType,
12641264
uint64_t Addend, uint64_t Value);
12651265

12661266
/// Return the name of the section this function originated from.

bolt/include/bolt/Core/BinarySection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,14 @@ class BinarySection {
358358
void clearRelocations();
359359

360360
/// Add a new relocation at the given /p Offset.
361-
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
361+
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");
364364
Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
365365
}
366366

367367
/// Add a dynamic relocation at the given /p Offset.
368-
void addDynamicRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
368+
void addDynamicRelocation(uint64_t Offset, MCSymbol *Symbol, uint32_t Type,
369369
uint64_t Addend, uint64_t Value = 0) {
370370
addDynamicRelocation(Relocation{Offset, Symbol, Type, Addend, Value});
371371
}

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class MCPlusBuilder {
473473
///
474474
/// For X86, they might be used in scanExternalRefs when we want to skip
475475
/// a function but still patch references inside it.
476-
virtual bool shouldRecordCodeRelocation(uint64_t RelType) const {
476+
virtual bool shouldRecordCodeRelocation(uint32_t RelType) const {
477477
llvm_unreachable("not implemented");
478478
return false;
479479
}
@@ -637,6 +637,16 @@ class MCPlusBuilder {
637637
return false;
638638
}
639639

640+
virtual bool isAddXri(const MCInst &Inst) const {
641+
llvm_unreachable("not implemented");
642+
return false;
643+
}
644+
645+
virtual bool isMOVW(const MCInst &Inst) const {
646+
llvm_unreachable("not implemented");
647+
return false;
648+
}
649+
640650
virtual bool isMoveMem2Reg(const MCInst &Inst) const { return false; }
641651

642652
virtual bool mayLoad(const MCInst &Inst) const {
@@ -1074,15 +1084,15 @@ class MCPlusBuilder {
10741084
/// MCExpr referencing \p Symbol + \p Addend.
10751085
virtual bool setOperandToSymbolRef(MCInst &Inst, int OpNum,
10761086
const MCSymbol *Symbol, int64_t Addend,
1077-
MCContext *Ctx, uint64_t RelType) const;
1087+
MCContext *Ctx, uint32_t RelType) const;
10781088

10791089
/// Replace an immediate operand in the instruction \p Inst with a reference
10801090
/// of the passed \p Symbol plus \p Addend. If the instruction does not have
10811091
/// an immediate operand or has more than one - then return false. Otherwise
10821092
/// return true.
10831093
virtual bool replaceImmWithSymbolRef(MCInst &Inst, const MCSymbol *Symbol,
10841094
int64_t Addend, MCContext *Ctx,
1085-
int64_t &Value, uint64_t RelType) const {
1095+
int64_t &Value, uint32_t RelType) const {
10861096
llvm_unreachable("not implemented");
10871097
return false;
10881098
}
@@ -1287,7 +1297,7 @@ class MCPlusBuilder {
12871297
/// Return the MCExpr used for absolute references in this target
12881298
virtual const MCExpr *getTargetExprFor(MCInst &Inst, const MCExpr *Expr,
12891299
MCContext &Ctx,
1290-
uint64_t RelType) const {
1300+
uint32_t RelType) const {
12911301
return Expr;
12921302
}
12931303

bolt/include/bolt/Core/Relocation.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
namespace llvm {
2222
class MCSymbol;
23+
24+
namespace object {
25+
class RelocationRef;
26+
} // namespace object
27+
2328
class raw_ostream;
2429

2530
namespace ELF {
@@ -40,7 +45,7 @@ struct Relocation {
4045
MCSymbol *Symbol;
4146

4247
/// Relocation type.
43-
uint64_t Type;
48+
uint32_t Type;
4449

4550
/// The offset from the \p Symbol base used to compute the final
4651
/// value of this relocation.
@@ -51,71 +56,70 @@ struct Relocation {
5156
uint64_t Value;
5257

5358
/// Return size in bytes of the given relocation \p Type.
54-
static size_t getSizeForType(uint64_t Type);
59+
static size_t getSizeForType(uint32_t Type);
5560

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

5964
/// Skip relocations that we don't want to handle in BOLT
60-
static bool skipRelocationType(uint64_t Type);
65+
static bool skipRelocationType(uint32_t Type);
6166

62-
/// Handle special cases when relocation should not be processed by BOLT or
63-
/// change relocation \p Type to proper one before continuing if \p Contents
64-
/// and \P Type mismatch occurred.
65-
static bool skipRelocationProcess(uint64_t &Type, uint64_t Contents);
66-
67-
// Adjust value depending on relocation type (make it PC relative or not)
68-
static uint64_t encodeValue(uint64_t Type, uint64_t Value, uint64_t PC);
67+
/// Adjust value depending on relocation type (make it PC relative or not).
68+
static uint64_t encodeValue(uint32_t Type, uint64_t Value, uint64_t PC);
6969

7070
/// Extract current relocated value from binary contents. This is used for
7171
/// RISC architectures where values are encoded in specific bits depending
7272
/// on the relocation value. For X86, we limit to sign extending the value
7373
/// if necessary.
74-
static uint64_t extractValue(uint64_t Type, uint64_t Contents, uint64_t PC);
74+
static uint64_t extractValue(uint32_t Type, uint64_t Contents, uint64_t PC);
7575

7676
/// Return true if relocation type is PC-relative. Return false otherwise.
77-
static bool isPCRelative(uint64_t Type);
77+
static bool isPCRelative(uint32_t Type);
7878

7979
/// Check if \p Type is a supported relocation type.
80-
static bool isSupported(uint64_t Type);
80+
static bool isSupported(uint32_t Type);
8181

8282
/// Return true if relocation type implies the creation of a GOT entry
83-
static bool isGOT(uint64_t Type);
83+
static bool isGOT(uint32_t Type);
8484

8585
/// Special relocation type that allows the linker to modify the instruction.
86-
static bool isX86GOTPCRELX(uint64_t Type);
87-
static bool isX86GOTPC64(uint64_t Type);
86+
static bool isX86GOTPCRELX(uint32_t Type);
87+
static bool isX86GOTPC64(uint32_t Type);
8888

8989
/// Return true if relocation type is NONE
90-
static bool isNone(uint64_t Type);
90+
static bool isNone(uint32_t Type);
9191

9292
/// Return true if relocation type is RELATIVE
93-
static bool isRelative(uint64_t Type);
93+
static bool isRelative(uint32_t Type);
9494

9595
/// Return true if relocation type is IRELATIVE
96-
static bool isIRelative(uint64_t Type);
96+
static bool isIRelative(uint32_t Type);
9797

9898
/// Return true if relocation type is for thread local storage.
99-
static bool isTLS(uint64_t Type);
99+
static bool isTLS(uint32_t Type);
100100

101101
/// Return true of relocation type is for referencing a specific instruction
102102
/// (as opposed to a function, basic block, etc).
103-
static bool isInstructionReference(uint64_t Type);
103+
static bool isInstructionReference(uint32_t Type);
104+
105+
/// Return the relocation type of \p Rel from llvm::object. It checks for
106+
/// overflows as BOLT uses 32 bits for the type.
107+
static uint32_t getType(const object::RelocationRef &Rel);
104108

105109
/// Return code for a NONE relocation
106-
static uint64_t getNone();
110+
static uint32_t getNone();
107111

108112
/// Return code for a PC-relative 4-byte relocation
109-
static uint64_t getPC32();
113+
static uint32_t getPC32();
110114

111115
/// Return code for a PC-relative 8-byte relocation
112-
static uint64_t getPC64();
116+
static uint32_t getPC64();
113117

114118
/// Return code for a ABS 8-byte relocation
115-
static uint64_t getAbs64();
119+
static uint32_t getAbs64();
116120

117121
/// Return code for a RELATIVE relocation
118-
static uint64_t getRelative();
122+
static uint32_t getRelative();
119123

120124
/// Return true if this relocation is PC-relative. Return false otherwise.
121125
bool isPCRelative() const { return isPCRelative(Type); }
@@ -161,7 +165,7 @@ struct Relocation {
161165
const MCExpr *createExpr(MCStreamer *Streamer) const;
162166
const MCExpr *createExpr(MCStreamer *Streamer,
163167
const MCExpr *RetainedValue) const;
164-
static MCBinaryExpr::Opcode getComposeOpcodeFor(uint64_t Type);
168+
static MCBinaryExpr::Opcode getComposeOpcodeFor(uint32_t Type);
165169
};
166170

167171
/// Relocation ordering by offset.

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class RewriteInstance {
248248
/// The \p SymbolName, \p SymbolAddress, \p Addend and \p ExtractedValue
249249
/// parameters will be set on success. The \p Skip argument indicates
250250
/// that the relocation was analyzed, but it must not be processed.
251-
bool analyzeRelocation(const object::RelocationRef &Rel, uint64_t &RType,
251+
bool analyzeRelocation(const object::RelocationRef &Rel, uint32_t &RType,
252252
std::string &SymbolName, bool &IsSectionRelocation,
253253
uint64_t &SymbolAddress, int64_t &Addend,
254254
uint64_t &ExtractedValue, bool &Skip) const;

bolt/lib/Core/BinaryContext.cpp

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

22862286
void BinaryContext::addRelocation(uint64_t Address, MCSymbol *Symbol,
2287-
uint64_t Type, 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");
@@ -2293,7 +2293,7 @@ void BinaryContext::addRelocation(uint64_t Address, MCSymbol *Symbol,
22932293
}
22942294

22952295
void BinaryContext::addDynamicRelocation(uint64_t Address, MCSymbol *Symbol,
2296-
uint64_t Type, uint64_t Addend,
2296+
uint32_t Type, uint64_t Addend,
22972297
uint64_t Value) {
22982298
ErrorOr<BinarySection &> Section = getSectionForAddress(Address);
22992299
assert(Section && "cannot find section for address");

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,10 +1473,19 @@ Error BinaryFunction::disassemble() {
14731473
}
14741474
}
14751475

1476+
uint64_t Addend = Relocation.Addend;
1477+
1478+
// For GOT relocations, create a reference against GOT entry ignoring
1479+
// the relocation symbol.
1480+
if (Relocation::isGOT(Relocation.Type)) {
1481+
assert(Relocation::isPCRelative(Relocation.Type) &&
1482+
"GOT relocation must be PC-relative on RISC-V");
1483+
Symbol = BC.registerNameAtAddress("__BOLT_got_zero", 0, 0, 0);
1484+
Addend = Relocation.Value + Relocation.Offset + getAddress();
1485+
}
14761486
int64_t Value = Relocation.Value;
14771487
const bool Result = BC.MIB->replaceImmWithSymbolRef(
1478-
Instruction, Symbol, Relocation.Addend, Ctx.get(), Value,
1479-
Relocation.Type);
1488+
Instruction, Symbol, Addend, Ctx.get(), Value, Relocation.Type);
14801489
(void)Result;
14811490
assert(Result && "cannot replace immediate with relocation");
14821491
}
@@ -4614,7 +4623,7 @@ bool BinaryFunction::isAArch64Veneer() const {
46144623
}
46154624

46164625
void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
4617-
uint64_t RelType, uint64_t Addend,
4626+
uint32_t RelType, uint64_t Addend,
46184627
uint64_t Value) {
46194628
assert(Address >= getAddress() && Address < getAddress() + getMaxSize() &&
46204629
"address is outside of the function");

bolt/lib/Core/JumpTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void bolt::JumpTable::updateOriginal() {
8484
const uint64_t BaseOffset = getAddress() - getSection().getAddress();
8585
uint64_t EntryOffset = BaseOffset;
8686
for (MCSymbol *Entry : Entries) {
87-
const uint64_t RelType =
87+
const uint32_t RelType =
8888
Type == JTT_NORMAL ? ELF::R_X86_64_64 : ELF::R_X86_64_PC32;
8989
const uint64_t RelAddend =
9090
Type == JTT_NORMAL ? 0 : EntryOffset - BaseOffset;

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ void MCPlusBuilder::initSizeMap() {
551551
bool MCPlusBuilder::setOperandToSymbolRef(MCInst &Inst, int OpNum,
552552
const MCSymbol *Symbol,
553553
int64_t Addend, MCContext *Ctx,
554-
uint64_t RelType) const {
554+
uint32_t RelType) const {
555555
MCOperand Operand;
556556
if (!Addend) {
557557
Operand = MCOperand::createExpr(getTargetExprFor(

0 commit comments

Comments
 (0)