Skip to content

Commit 3228086

Browse files
authored
Merge branch 'main' into riscv-address-resolution
2 parents b738bf1 + 7031280 commit 3228086

File tree

4,380 files changed

+185092
-70751
lines changed

Some content is hidden

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

4,380 files changed

+185092
-70751
lines changed

.github/new-prs-labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,10 @@ backend:NVPTX:
777777
- 'llvm/**/*nvptx*/**'
778778
- 'llvm/**/*NVPTX*/**'
779779

780+
backend:MIPS:
781+
- '**/*mips*'
782+
- '**/*Mips*'
783+
780784
backend:RISC-V:
781785
- clang/**/*riscv*
782786
- clang/**/*RISCV*

.github/workflows/email-check.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
COMMENT: >-
3333
⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.<br/>
3434
Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account.<br/>
35-
See [LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information.
35+
See [LLVM Developer Policy](https://llvm.org/docs/DeveloperPolicy.html#email-addresses) and
36+
[LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information.
3637
run: |
3738
cat << EOF > comments
3839
[{"body" : "$COMMENT"}]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ jobs:
5252
cxx: [ 'clang++-21' ]
5353
include:
5454
- config: 'generic-gcc'
55-
cc: 'gcc-14'
56-
cxx: 'g++-14'
55+
cc: 'gcc-15'
56+
cxx: 'g++-15'
5757
steps:
5858
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5959
- name: ${{ matrix.config }}.${{ matrix.cxx }}
@@ -92,8 +92,8 @@ jobs:
9292
cxx: [ 'clang++-21' ]
9393
include:
9494
- config: 'generic-gcc-cxx11'
95-
cc: 'gcc-14'
96-
cxx: 'g++-14'
95+
cc: 'gcc-15'
96+
cxx: 'g++-15'
9797
- config: 'generic-cxx26'
9898
cc: 'clang-20'
9999
cxx: 'clang++-20'

.github/workflows/libcxx-restart-preempted-jobs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
with:
3434
script: |
3535
const failure_regex = /Process completed with exit code 1./
36-
const preemption_regex = /The runner has received a shutdown signal/
36+
const preemption_regex = /(The runner has received a shutdown signal)|(The operation was canceled)/
3737
3838
const wf_run = context.payload.workflow_run
3939
core.notice(`Running on "${wf_run.display_title}" by @${wf_run.actor.login} (event: ${wf_run.event})\nWorkflow run URL: ${wf_run.html_url}`)

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ class BinaryFunction {
388388
/// The profile data for the number of times the function was executed.
389389
uint64_t ExecutionCount{COUNT_NO_PROFILE};
390390

391+
/// Profile data for the number of times this function was entered from
392+
/// external code (DSO, JIT, etc).
393+
uint64_t ExternEntryCount{0};
394+
391395
/// Profile match ratio.
392396
float ProfileMatchRatio{0.0f};
393397

@@ -1877,6 +1881,10 @@ class BinaryFunction {
18771881
return *this;
18781882
}
18791883

1884+
/// Set the profile data for the number of times the function was entered from
1885+
/// external code (DSO/JIT).
1886+
void setExternEntryCount(uint64_t Count) { ExternEntryCount = Count; }
1887+
18801888
/// Adjust execution count for the function by a given \p Count. The value
18811889
/// \p Count will be subtracted from the current function count.
18821890
///
@@ -1904,6 +1912,10 @@ class BinaryFunction {
19041912
/// Return COUNT_NO_PROFILE if there's no profile info.
19051913
uint64_t getExecutionCount() const { return ExecutionCount; }
19061914

1915+
/// Return the profile information about the number of times the function was
1916+
/// entered from external code (DSO/JIT).
1917+
uint64_t getExternEntryCount() const { return ExternEntryCount; }
1918+
19071919
/// Return the raw profile information about the number of branch
19081920
/// executions corresponding to this function.
19091921
uint64_t getRawSampleCount() const { return RawSampleCount; }

bolt/include/bolt/Passes/PAuthGadgetScanner.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ namespace PAuthGadgetScanner {
199199
// to distinguish intermediate and final results at the type level.
200200
//
201201
// Here is an overview of issue life-cycle:
202-
// * an analysis (SrcSafetyAnalysis at now, DstSafetyAnalysis will be added
203-
// later to support the detection of authentication oracles) computes register
202+
// * an analysis (SrcSafetyAnalysis or DstSafetyAnalysis) computes register
204203
// state for each instruction in the function.
205204
// * for each instruction, it is checked whether it is a gadget of some kind,
206205
// taking the computed state into account. If a gadget is found, its kind
@@ -273,6 +272,11 @@ class ExtraInfo {
273272
virtual ~ExtraInfo() {}
274273
};
275274

275+
/// The set of instructions writing to the affected register in an unsafe
276+
/// manner.
277+
///
278+
/// This is a hint to be printed alongside the report. It should be further
279+
/// analyzed by the user.
276280
class ClobberingInfo : public ExtraInfo {
277281
SmallVector<MCInstReference> ClobberingInstrs;
278282

@@ -282,6 +286,20 @@ class ClobberingInfo : public ExtraInfo {
282286
void print(raw_ostream &OS, const MCInstReference Location) const override;
283287
};
284288

289+
/// The set of instructions leaking the authenticated pointer before the
290+
/// result of authentication was checked.
291+
///
292+
/// This is a hint to be printed alongside the report. It should be further
293+
/// analyzed by the user.
294+
class LeakageInfo : public ExtraInfo {
295+
SmallVector<MCInstReference> LeakingInstrs;
296+
297+
public:
298+
LeakageInfo(ArrayRef<MCInstReference> Instrs) : LeakingInstrs(Instrs) {}
299+
300+
void print(raw_ostream &OS, const MCInstReference Location) const override;
301+
};
302+
285303
/// A brief version of a report that can be further augmented with the details.
286304
///
287305
/// A half-baked report produced on the first run of the analysis. An extra,
@@ -322,6 +340,9 @@ class FunctionAnalysisContext {
322340
void findUnsafeUses(SmallVector<PartialReport<MCPhysReg>> &Reports);
323341
void augmentUnsafeUseReports(ArrayRef<PartialReport<MCPhysReg>> Reports);
324342

343+
void findUnsafeDefs(SmallVector<PartialReport<MCPhysReg>> &Reports);
344+
void augmentUnsafeDefReports(ArrayRef<PartialReport<MCPhysReg>> Reports);
345+
325346
/// Process the reports which do not have to be augmented, and remove them
326347
/// from Reports.
327348
void handleSimpleReports(SmallVector<PartialReport<MCPhysReg>> &Reports);

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class DataAggregator : public DataReader {
8585
};
8686
friend raw_ostream &operator<<(raw_ostream &OS, const LBREntry &);
8787

88+
friend struct PerfSpeEventsTestHelper;
89+
8890
struct PerfBranchSample {
8991
SmallVector<LBREntry, 32> LBR;
9092
};
@@ -99,24 +101,29 @@ class DataAggregator : public DataReader {
99101
uint64_t Addr;
100102
};
101103

104+
/// Container for the unit of branch data, matching pre-aggregated trace type.
105+
/// Backwards compatible with branch and fall-through types:
106+
/// - if \p To is < 0, the trace only contains branch data (BR_ONLY),
107+
/// - if \p Branch is < 0, the trace only contains fall-through data
108+
/// (FT_ONLY, FT_EXTERNAL_ORIGIN, or FT_EXTERNAL_RETURN).
102109
struct Trace {
110+
static constexpr const uint64_t EXTERNAL = 0ULL;
111+
static constexpr const uint64_t BR_ONLY = -1ULL;
112+
static constexpr const uint64_t FT_ONLY = -1ULL;
113+
static constexpr const uint64_t FT_EXTERNAL_ORIGIN = -2ULL;
114+
static constexpr const uint64_t FT_EXTERNAL_RETURN = -3ULL;
115+
116+
uint64_t Branch;
103117
uint64_t From;
104118
uint64_t To;
105-
Trace(uint64_t From, uint64_t To) : From(From), To(To) {}
106-
bool operator==(const Trace &Other) const {
107-
return From == Other.From && To == Other.To;
108-
}
119+
auto tie() const { return std::tie(Branch, From, To); }
120+
bool operator==(const Trace &Other) const { return tie() == Other.tie(); }
121+
bool operator<(const Trace &Other) const { return tie() < Other.tie(); }
109122
};
123+
friend raw_ostream &operator<<(raw_ostream &OS, const Trace &);
110124

111125
struct TraceHash {
112-
size_t operator()(const Trace &L) const {
113-
return std::hash<uint64_t>()(L.From << 32 | L.To);
114-
}
115-
};
116-
117-
struct FTInfo {
118-
uint64_t InternCount{0};
119-
uint64_t ExternCount{0};
126+
size_t operator()(const Trace &L) const { return hash_combine(L.tie()); }
120127
};
121128

122129
struct TakenBranchInfo {
@@ -126,8 +133,11 @@ class DataAggregator : public DataReader {
126133

127134
/// Intermediate storage for profile data. We save the results of parsing
128135
/// and use them later for processing and assigning profile.
129-
std::unordered_map<Trace, TakenBranchInfo, TraceHash> BranchLBRs;
130-
std::unordered_map<Trace, FTInfo, TraceHash> FallthroughLBRs;
136+
std::unordered_map<Trace, TakenBranchInfo, TraceHash> TraceMap;
137+
std::vector<std::pair<Trace, TakenBranchInfo>> Traces;
138+
/// Pre-populated addresses of returns, coming from pre-aggregated data or
139+
/// disassembly. Used to disambiguate call-continuation fall-throughs.
140+
std::unordered_set<uint64_t> Returns;
131141
std::unordered_map<uint64_t, uint64_t> BasicSamples;
132142
std::vector<PerfMemSample> MemSamples;
133143

@@ -200,8 +210,8 @@ class DataAggregator : public DataReader {
200210
/// Return a vector of offsets corresponding to a trace in a function
201211
/// if the trace is valid, std::nullopt otherwise.
202212
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
203-
getFallthroughsInTrace(BinaryFunction &BF, const LBREntry &First,
204-
const LBREntry &Second, uint64_t Count = 1) const;
213+
getFallthroughsInTrace(BinaryFunction &BF, const Trace &Trace, uint64_t Count,
214+
bool IsReturn) const;
205215

206216
/// Record external entry into the function \p BF.
207217
///
@@ -261,12 +271,14 @@ class DataAggregator : public DataReader {
261271
uint64_t From, uint64_t To, uint64_t Count,
262272
uint64_t Mispreds);
263273

274+
/// Checks if \p Addr corresponds to a return instruction.
275+
bool checkReturn(uint64_t Addr);
276+
264277
/// Register a \p Branch.
265278
bool doBranch(uint64_t From, uint64_t To, uint64_t Count, uint64_t Mispreds);
266279

267280
/// Register a trace between two LBR entries supplied in execution order.
268-
bool doTrace(const LBREntry &First, const LBREntry &Second,
269-
uint64_t Count = 1);
281+
bool doTrace(const Trace &Trace, uint64_t Count, bool IsReturn);
270282

271283
/// Parser helpers
272284
/// Return false if we exhausted our parser buffer and finished parsing
@@ -379,9 +391,9 @@ class DataAggregator : public DataReader {
379391
/// File format syntax:
380392
/// E <event>
381393
/// S <start> <count>
382-
/// T <start> <end> <ft_end> <count>
394+
/// [TR] <start> <end> <ft_end> <count>
383395
/// B <start> <end> <count> <mispred_count>
384-
/// [Ff] <start> <end> <count>
396+
/// [Ffr] <start> <end> <count>
385397
///
386398
/// where <start>, <end>, <ft_end> have the format [<id>:]<offset>
387399
///
@@ -392,8 +404,11 @@ class DataAggregator : public DataReader {
392404
/// f - an aggregated fall-through with external origin - used to disambiguate
393405
/// between a return hitting a basic block head and a regular internal
394406
/// jump to the block
407+
/// r - an aggregated fall-through originating at an external return, no
408+
/// checks are performed for a fallthrough start
395409
/// T - an aggregated trace: branch from <start> to <end> with a fall-through
396410
/// to <ft_end>
411+
/// R - an aggregated trace originating at a return
397412
///
398413
/// <id> - build id of the object containing the address. We can skip it for
399414
/// the main binary and use "X" for an unknown object. This will save some
@@ -516,6 +531,26 @@ inline raw_ostream &operator<<(raw_ostream &OS,
516531
OS << formatv("{0:x} -> {1:x}/{2}", L.From, L.To, L.Mispred ? 'M' : 'P');
517532
return OS;
518533
}
534+
535+
inline raw_ostream &operator<<(raw_ostream &OS,
536+
const DataAggregator::Trace &T) {
537+
switch (T.Branch) {
538+
case DataAggregator::Trace::FT_ONLY:
539+
break;
540+
case DataAggregator::Trace::FT_EXTERNAL_ORIGIN:
541+
OS << "X:0 -> ";
542+
break;
543+
case DataAggregator::Trace::FT_EXTERNAL_RETURN:
544+
OS << "X:R -> ";
545+
break;
546+
default:
547+
OS << Twine::utohexstr(T.Branch) << " -> ";
548+
}
549+
OS << Twine::utohexstr(T.From);
550+
if (T.To != DataAggregator::Trace::BR_ONLY)
551+
OS << " ... " << Twine::utohexstr(T.To);
552+
return OS;
553+
}
519554
} // namespace bolt
520555
} // namespace llvm
521556

bolt/include/bolt/Profile/DataReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ struct FuncBranchData {
9797
/// Total execution count for the function.
9898
int64_t ExecutionCount{0};
9999

100+
/// Total entry count from external code for the function.
101+
uint64_t ExternEntryCount{0};
102+
100103
/// Indicate if the data was used.
101104
bool Used{false};
102105

bolt/include/bolt/Profile/ProfileYAMLMapping.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ struct BinaryFunctionProfile {
206206
uint32_t Id{0};
207207
llvm::yaml::Hex64 Hash{0};
208208
uint64_t ExecCount{0};
209+
uint64_t ExternEntryCount{0};
209210
std::vector<BinaryBasicBlockProfile> Blocks;
210211
std::vector<InlineTreeNode> InlineTree;
211212
bool Used{false};
@@ -218,6 +219,7 @@ template <> struct MappingTraits<bolt::BinaryFunctionProfile> {
218219
YamlIO.mapRequired("fid", BFP.Id);
219220
YamlIO.mapRequired("hash", BFP.Hash);
220221
YamlIO.mapRequired("exec", BFP.ExecCount);
222+
YamlIO.mapOptional("extern", BFP.ExternEntryCount, 0);
221223
YamlIO.mapRequired("nblocks", BFP.NumBasicBlocks);
222224
YamlIO.mapOptional("blocks", BFP.Blocks,
223225
std::vector<bolt::BinaryBasicBlockProfile>());

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern llvm::cl::OptionCategory BinaryAnalysisCategory;
4848
extern llvm::cl::opt<unsigned> AlignText;
4949
extern llvm::cl::opt<unsigned> AlignFunctions;
5050
extern llvm::cl::opt<bool> AggregateOnly;
51+
extern llvm::cl::opt<bool> ArmSPE;
5152
extern llvm::cl::opt<unsigned> BucketsPerLine;
5253
extern llvm::cl::opt<bool> CompactCodeModel;
5354
extern llvm::cl::opt<bool> DiffOnly;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
471471
OS << "\n Sample Count: " << RawSampleCount;
472472
OS << "\n Profile Acc : " << format("%.1f%%", ProfileMatchRatio * 100.0f);
473473
}
474+
if (ExternEntryCount)
475+
OS << "\n Extern Entry Count: " << ExternEntryCount;
474476

475477
if (opts::PrintDynoStats && !getLayout().block_empty()) {
476478
OS << '\n';

0 commit comments

Comments
 (0)