Skip to content

Commit bafa9b3

Browse files
authored
merge main into amd-staging (llvm#2277)
2 parents 73aa7a0 + db5bbf8 commit bafa9b3

File tree

297 files changed

+21932
-2406
lines changed

Some content is hidden

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

297 files changed

+21932
-2406
lines changed

.ci/generate_test_report_lib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def plural(num_tests):
9292
]
9393
)
9494
elif failures:
95-
report.extend(["", "## Failed Tests", "(click on a test name to see its output)"])
95+
report.extend(
96+
["", "## Failed Tests", "(click on a test name to see its output)"]
97+
)
9698

9799
for testsuite_name, failures in failures.items():
98100
report.extend(["", f"### {testsuite_name}"])

.ci/metrics/metrics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
# remain small.
6868
BUILDKITE_GRAPHQL_BUILDS_PER_PAGE = 50
6969

70+
7071
@dataclass
7172
class JobMetrics:
7273
job_name: str
@@ -77,6 +78,7 @@ class JobMetrics:
7778
workflow_id: int
7879
workflow_name: str
7980

81+
8082
@dataclass
8183
class GaugeMetric:
8284
name: str
@@ -258,6 +260,7 @@ def buildkite_get_metrics(
258260

259261
return output, incomplete_now
260262

263+
261264
def github_get_metrics(
262265
github_repo: github.Repository, last_workflows_seen_as_completed: set[int]
263266
) -> tuple[list[JobMetrics], int]:

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MCSymbol;
4949
class raw_ostream;
5050

5151
namespace bolt {
52+
class BinaryBasicBlock;
5253
class BinaryFunction;
5354

5455
/// Different types of indirect branches encountered during disassembly.
@@ -572,6 +573,11 @@ class MCPlusBuilder {
572573
return false;
573574
}
574575

576+
virtual MCPhysReg getSignedReg(const MCInst &Inst) const {
577+
llvm_unreachable("not implemented");
578+
return getNoRegister();
579+
}
580+
575581
virtual ErrorOr<MCPhysReg> getRegUsedAsRetDest(const MCInst &Inst) const {
576582
llvm_unreachable("not implemented");
577583
return getNoRegister();
@@ -622,6 +628,54 @@ class MCPlusBuilder {
622628
return std::make_pair(getNoRegister(), getNoRegister());
623629
}
624630

631+
/// Analyzes if a pointer is checked to be authenticated successfully
632+
/// by the end of the basic block.
633+
///
634+
/// It is possible for pointer authentication instructions not to terminate
635+
/// the program abnormally on authentication failure and return some invalid
636+
/// pointer instead (like it is done on AArch64 when FEAT_FPAC is not
637+
/// implemented). This might be enough to crash on invalid memory access when
638+
/// the pointer is later used as the destination of a load, store, or branch
639+
/// instruction. On the other hand, when the pointer is not used right away,
640+
/// it may be important for the compiler to check the address explicitly not
641+
/// to introduce a signing or authentication oracle.
642+
///
643+
/// This function is intended to detect a complex, multi-instruction pointer-
644+
/// checking sequence spanning a contiguous range of instructions at the end
645+
/// of the basic block (as these sequences are expected to end with a
646+
/// conditional branch - this is how they are implemented on AArch64 by LLVM).
647+
/// If a (Reg, FirstInst) pair is returned and before execution of FirstInst
648+
/// Reg was last written to by an authentication instruction, then it is known
649+
/// that in any successor of BB either
650+
/// * the authentication instruction that last wrote to Reg succeeded, or
651+
/// * the program is terminated abnormally without introducing any signing
652+
/// or authentication oracles
653+
///
654+
/// Note that this function is not expected to repeat the results returned
655+
/// by getAuthCheckedReg(Inst, MayOverwrite) function below.
656+
virtual std::optional<std::pair<MCPhysReg, MCInst *>>
657+
getAuthCheckedReg(BinaryBasicBlock &BB) const {
658+
llvm_unreachable("not implemented");
659+
return std::nullopt;
660+
}
661+
662+
/// Returns the register that is checked to be authenticated successfully.
663+
///
664+
/// If the returned register was last written to by an authentication
665+
/// instruction and that authentication failed, then the program is known
666+
/// to be terminated abnormally as a result of execution of Inst.
667+
///
668+
/// Additionally, if MayOverwrite is false, it is known that the authenticated
669+
/// pointer is not clobbered by Inst itself.
670+
///
671+
/// Use this function for simple, single-instruction patterns instead of
672+
/// its getAuthCheckedReg(BB) counterpart.
673+
virtual MCPhysReg getAuthCheckedReg(const MCInst &Inst,
674+
bool MayOverwrite) const {
675+
llvm_unreachable("not implemented");
676+
return getNoRegister();
677+
}
678+
625679
virtual bool isTerminator(const MCInst &Inst) const;
626680

627681
virtual bool isNoop(const MCInst &Inst) const {

bolt/include/bolt/Passes/PAuthGadgetScanner.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "bolt/Core/BinaryContext.h"
1313
#include "bolt/Core/BinaryFunction.h"
1414
#include "bolt/Passes/BinaryPasses.h"
15-
#include "llvm/ADT/SmallSet.h"
1615
#include "llvm/Support/raw_ostream.h"
1716
#include <memory>
1817

@@ -197,9 +196,6 @@ raw_ostream &operator<<(raw_ostream &OS, const MCInstReference &);
197196

198197
namespace PAuthGadgetScanner {
199198

200-
class SrcSafetyAnalysis;
201-
struct SrcState;
202-
203199
/// Description of a gadget kind that can be detected. Intended to be
204200
/// statically allocated to be attached to reports by reference.
205201
class GadgetKind {
@@ -208,7 +204,7 @@ class GadgetKind {
208204
public:
209205
GadgetKind(const char *Description) : Description(Description) {}
210206

211-
const StringRef getDescription() const { return Description; }
207+
StringRef getDescription() const { return Description; }
212208
};
213209

214210
/// Base report located at some instruction, without any additional information.
@@ -223,8 +219,8 @@ struct Report {
223219

224220
// The two methods below are called by Analysis::computeDetailedInfo when
225221
// iterating over the reports.
226-
virtual const ArrayRef<MCPhysReg> getAffectedRegisters() const { return {}; }
227-
virtual void setOverwritingInstrs(const ArrayRef<MCInstReference> Instrs) {}
222+
virtual ArrayRef<MCPhysReg> getAffectedRegisters() const { return {}; }
223+
virtual void setOverwritingInstrs(ArrayRef<MCInstReference> Instrs) {}
228224

229225
void printBasicInfo(raw_ostream &OS, const BinaryContext &BC,
230226
StringRef IssueKind) const;
@@ -247,19 +243,19 @@ struct GadgetReport : public Report {
247243

248244
void generateReport(raw_ostream &OS, const BinaryContext &BC) const override;
249245

250-
const ArrayRef<MCPhysReg> getAffectedRegisters() const override {
246+
ArrayRef<MCPhysReg> getAffectedRegisters() const override {
251247
return AffectedRegisters;
252248
}
253249

254-
void setOverwritingInstrs(const ArrayRef<MCInstReference> Instrs) override {
250+
void setOverwritingInstrs(ArrayRef<MCInstReference> Instrs) override {
255251
OverwritingInstrs.assign(Instrs.begin(), Instrs.end());
256252
}
257253
};
258254

259255
/// Report with a free-form message attached.
260256
struct GenericReport : public Report {
261257
std::string Text;
262-
GenericReport(MCInstReference Location, const std::string &Text)
258+
GenericReport(MCInstReference Location, StringRef Text)
263259
: Report(Location), Text(Text) {}
264260
virtual void generateReport(raw_ostream &OS,
265261
const BinaryContext &BC) const override;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,10 +1783,22 @@ bool BinaryFunction::scanExternalRefs() {
17831783
// On AArch64, we use instruction patches for fixing references. We make an
17841784
// exception for branch instructions since they require optional
17851785
// relocations.
1786-
if (BC.isAArch64() && !BranchTargetSymbol) {
1787-
LLVM_DEBUG(BC.printInstruction(dbgs(), Instruction, AbsoluteInstrAddr));
1788-
InstructionPatches.push_back({AbsoluteInstrAddr, Instruction});
1789-
continue;
1786+
if (BC.isAArch64()) {
1787+
if (!BranchTargetSymbol) {
1788+
LLVM_DEBUG(BC.printInstruction(dbgs(), Instruction, AbsoluteInstrAddr));
1789+
InstructionPatches.push_back({AbsoluteInstrAddr, Instruction});
1790+
continue;
1791+
}
1792+
1793+
// Conditional tail calls require new relocation types that are currently
1794+
// not supported. https://github.com/llvm/llvm-project/issues/138264
1795+
if (BC.MIB->isConditionalBranch(Instruction)) {
1796+
if (BinaryFunction *TargetBF =
1797+
BC.getFunctionForSymbol(BranchTargetSymbol)) {
1798+
TargetBF->setNeedsPatch(true);
1799+
continue;
1800+
}
1801+
}
17901802
}
17911803

17921804
// Emit the instruction using temp emitter and generate relocations.

0 commit comments

Comments
 (0)