Skip to content

Commit c1493e0

Browse files
authored
Merge branch 'main' into subchannel-quant-impl
2 parents 0813721 + cb2ee1e commit c1493e0

File tree

1,532 files changed

+35625
-37703
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,532 files changed

+35625
-37703
lines changed

.ci/metrics/metrics.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,25 +215,14 @@ def buildkite_get_metrics(
215215
if job["name"] not in BUILDKITE_WORKFLOW_TO_TRACK:
216216
continue
217217

218+
# Don't count canceled jobs.
219+
if job["canceled_at"]:
220+
continue
221+
218222
created_at = dateutil.parser.isoparse(job["created_at"])
219-
scheduled_at = (
220-
created_at
221-
if job["scheduled_at"] is None
222-
else dateutil.parser.isoparse(job["scheduled_at"])
223-
)
224-
started_at = (
225-
scheduled_at
226-
if job["started_at"] is None
227-
else dateutil.parser.isoparse(job["started_at"])
228-
)
229-
if job["canceled_at"] is None:
230-
finished_at = (
231-
started_at
232-
if job["finished_at"] is None
233-
else dateutil.parser.isoparse(job["finished_at"])
234-
)
235-
else:
236-
finished_at = dateutil.parser.isoparse(job["canceled_at"])
223+
scheduled_at = dateutil.parser.isoparse(job["scheduled_at"])
224+
started_at = dateutil.parser.isoparse(job["started_at"])
225+
finished_at = dateutil.parser.isoparse(job["finished_at"])
237226

238227
job_name = BUILDKITE_WORKFLOW_TO_TRACK[job["name"]]
239228
queue_time = (started_at - scheduled_at).seconds

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ jobs:
137137
'generic-hardening-mode-fast',
138138
'generic-hardening-mode-fast-with-abi-breaks',
139139
'generic-merged',
140-
'generic-modules-lsv',
140+
'generic-modules-cxx17-lsv',
141141
'generic-no-exceptions',
142142
'generic-no-experimental',
143143
'generic-no-filesystem',

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

bolt/include/bolt/Passes/NonPacProtectedRetAnalysis.h renamed to bolt/include/bolt/Passes/PAuthGadgetScanner.h

Lines changed: 69 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===- bolt/Passes/NonPacProtectedRetAnalysis.h -----------------*- C++ -*-===//
1+
//===- bolt/Passes/PAuthGadgetScanner.h -------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef BOLT_PASSES_NONPACPROTECTEDRETANALYSIS_H
10-
#define BOLT_PASSES_NONPACPROTECTEDRETANALYSIS_H
9+
#ifndef BOLT_PASSES_PAUTHGADGETSCANNER_H
10+
#define BOLT_PASSES_PAUTHGADGETSCANNER_H
1111

1212
#include "bolt/Core/BinaryContext.h"
1313
#include "bolt/Core/BinaryFunction.h"
@@ -173,85 +173,104 @@ struct MCInstReference {
173173

174174
raw_ostream &operator<<(raw_ostream &OS, const MCInstReference &);
175175

176-
struct GeneralDiagnostic {
177-
std::string Text;
178-
GeneralDiagnostic(const std::string &Text) : Text(Text) {}
179-
bool operator==(const GeneralDiagnostic &RHS) const {
180-
return Text == RHS.Text;
181-
}
176+
namespace PAuthGadgetScanner {
177+
178+
class PacRetAnalysis;
179+
struct State;
180+
181+
/// Description of a gadget kind that can be detected. Intended to be
182+
/// statically allocated to be attached to reports by reference.
183+
class GadgetKind {
184+
const char *Description;
185+
186+
public:
187+
GadgetKind(const char *Description) : Description(Description) {}
188+
189+
const StringRef getDescription() const { return Description; }
182190
};
183191

184-
raw_ostream &operator<<(raw_ostream &OS, const GeneralDiagnostic &Diag);
192+
/// Base report located at some instruction, without any additional information.
193+
struct Report {
194+
MCInstReference Location;
195+
196+
Report(MCInstReference Location) : Location(Location) {}
197+
virtual ~Report() {}
185198

186-
namespace NonPacProtectedRetAnalysis {
187-
struct Annotation {
188-
MCInstReference RetInst;
189-
Annotation(MCInstReference RetInst) : RetInst(RetInst) {}
190-
virtual bool operator==(const Annotation &RHS) const {
191-
return RetInst == RHS.RetInst;
192-
}
193-
Annotation &operator=(const Annotation &Other) {
194-
if (this == &Other)
195-
return *this;
196-
RetInst = Other.RetInst;
197-
return *this;
198-
}
199-
virtual ~Annotation() {}
200199
virtual void generateReport(raw_ostream &OS,
201200
const BinaryContext &BC) const = 0;
201+
202+
// The two methods below are called by Analysis::computeDetailedInfo when
203+
// iterating over the reports.
204+
virtual const ArrayRef<MCPhysReg> getAffectedRegisters() const { return {}; }
205+
virtual void setOverwritingInstrs(const ArrayRef<MCInstReference> Instrs) {}
206+
207+
void printBasicInfo(raw_ostream &OS, const BinaryContext &BC,
208+
StringRef IssueKind) const;
202209
};
203210

204-
struct Gadget : public Annotation {
205-
std::vector<MCInstReference> OverwritingRetRegInst;
206-
virtual bool operator==(const Gadget &RHS) const {
207-
return Annotation::operator==(RHS) &&
208-
OverwritingRetRegInst == RHS.OverwritingRetRegInst;
211+
struct GadgetReport : public Report {
212+
// The particular kind of gadget that is detected.
213+
const GadgetKind &Kind;
214+
// The set of registers related to this gadget report (possibly empty).
215+
SmallVector<MCPhysReg> AffectedRegisters;
216+
// The instructions that clobber the affected registers.
217+
// There is no one-to-one correspondence with AffectedRegisters: for example,
218+
// the same register can be overwritten by different instructions in different
219+
// preceding basic blocks.
220+
SmallVector<MCInstReference> OverwritingInstrs;
221+
222+
GadgetReport(const GadgetKind &Kind, MCInstReference Location,
223+
const BitVector &AffectedRegisters)
224+
: Report(Location), Kind(Kind),
225+
AffectedRegisters(AffectedRegisters.set_bits()) {}
226+
227+
void generateReport(raw_ostream &OS, const BinaryContext &BC) const override;
228+
229+
const ArrayRef<MCPhysReg> getAffectedRegisters() const override {
230+
return AffectedRegisters;
209231
}
210-
Gadget(MCInstReference RetInst,
211-
const std::vector<MCInstReference> &OverwritingRetRegInst)
212-
: Annotation(RetInst), OverwritingRetRegInst(OverwritingRetRegInst) {}
213-
virtual void generateReport(raw_ostream &OS,
214-
const BinaryContext &BC) const override;
215-
};
216232

217-
struct GenDiag : public Annotation {
218-
GeneralDiagnostic Diag;
219-
virtual bool operator==(const GenDiag &RHS) const {
220-
return Annotation::operator==(RHS) && Diag == RHS.Diag;
233+
void setOverwritingInstrs(const ArrayRef<MCInstReference> Instrs) override {
234+
OverwritingInstrs.assign(Instrs.begin(), Instrs.end());
221235
}
222-
GenDiag(MCInstReference RetInst, const std::string &Text)
223-
: Annotation(RetInst), Diag(Text) {}
236+
};
237+
238+
/// Report with a free-form message attached.
239+
struct GenericReport : public Report {
240+
std::string Text;
241+
GenericReport(MCInstReference Location, const std::string &Text)
242+
: Report(Location), Text(Text) {}
224243
virtual void generateReport(raw_ostream &OS,
225244
const BinaryContext &BC) const override;
226245
};
227246

228-
class PacRetAnalysis;
229-
230247
struct FunctionAnalysisResult {
231-
SmallSet<MCPhysReg, 1> RegistersAffected;
232-
std::vector<std::shared_ptr<Annotation>> Diagnostics;
248+
std::vector<std::shared_ptr<Report>> Diagnostics;
233249
};
234250

235251
class Analysis : public BinaryFunctionPass {
236252
void runOnFunction(BinaryFunction &Function,
237253
MCPlusBuilder::AllocatorIdTy AllocatorId);
238-
FunctionAnalysisResult
239-
computeDfState(PacRetAnalysis &PRA, BinaryFunction &BF,
240-
MCPlusBuilder::AllocatorIdTy AllocatorId);
254+
FunctionAnalysisResult findGadgets(BinaryFunction &BF,
255+
MCPlusBuilder::AllocatorIdTy AllocatorId);
256+
257+
void computeDetailedInfo(BinaryFunction &BF,
258+
MCPlusBuilder::AllocatorIdTy AllocatorId,
259+
FunctionAnalysisResult &Result);
241260

242261
std::map<const BinaryFunction *, FunctionAnalysisResult> AnalysisResults;
243262
std::mutex AnalysisResultsMutex;
244263

245264
public:
246265
explicit Analysis() : BinaryFunctionPass(false) {}
247266

248-
const char *getName() const override { return "non-pac-protected-rets"; }
267+
const char *getName() const override { return "pauth-gadget-scanner"; }
249268

250269
/// Pass entry point
251270
Error runOnFunctions(BinaryContext &BC) override;
252271
};
253272

254-
} // namespace NonPacProtectedRetAnalysis
273+
} // namespace PAuthGadgetScanner
255274
} // namespace bolt
256275
} // namespace llvm
257276

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern llvm::cl::opt<unsigned> BucketsPerLine;
3737
extern llvm::cl::opt<bool> DiffOnly;
3838
extern llvm::cl::opt<bool> EnableBAT;
3939
extern llvm::cl::opt<bool> EqualizeBBCounts;
40+
extern llvm::cl::opt<bool> ForcePatch;
4041
extern llvm::cl::opt<bool> RemoveSymtab;
4142
extern llvm::cl::opt<unsigned> ExecutionCountThreshold;
4243
extern llvm::cl::opt<unsigned> HeatmapBlock;

bolt/lib/Passes/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ add_llvm_library(LLVMBOLTPasses
2323
LoopInversionPass.cpp
2424
LivenessAnalysis.cpp
2525
MCF.cpp
26-
NonPacProtectedRetAnalysis.cpp
2726
PatchEntries.cpp
27+
PAuthGadgetScanner.cpp
2828
PettisAndHansen.cpp
2929
PLTCall.cpp
3030
ProfileQualityStats.cpp

0 commit comments

Comments
 (0)