Skip to content

Commit 010e67f

Browse files
committed
merge main into amd-staging
2 parents af8d766 + e8ae779 commit 010e67f

File tree

415 files changed

+7302
-4656
lines changed

Some content is hidden

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

415 files changed

+7302
-4656
lines changed

bolt/docs/BinaryAnalysis.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ The following are current known cases of false negatives:
180180
[prototype branch](
181181
https://github.com/llvm/llvm-project/compare/main...kbeyls:llvm-project:bolt-gadget-scanner-prototype).
182182

183-
BOLT cannot currently handle functions with `cfi_negate_ra_state` correctly,
184-
i.e. any binaries built with `-mbranch-protection=pac-ret`. The scanner is meant
185-
to be used on specifically such binaries, so this is a major limitation! Work is
186-
going on in PR [#120064](https://github.com/llvm/llvm-project/pull/120064) to
187-
fix this.
188-
189183
## How to add your own binary analysis
190184

191185
_TODO: this section needs to be written. Ideally, we should have a simple

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ extern cl::opt<bool> StrictMode;
6565
extern cl::opt<bool> UpdateDebugSections;
6666
extern cl::opt<unsigned> Verbosity;
6767

68+
extern bool BinaryAnalysisMode;
69+
extern bool HeatmapMode;
6870
extern bool processAllFunctions();
6971

7072
static cl::opt<bool> CheckEncoding(
@@ -2760,13 +2762,19 @@ struct CFISnapshot {
27602762
}
27612763
case MCCFIInstruction::OpAdjustCfaOffset:
27622764
case MCCFIInstruction::OpWindowSave:
2763-
case MCCFIInstruction::OpNegateRAState:
27642765
case MCCFIInstruction::OpNegateRAStateWithPC:
27652766
case MCCFIInstruction::OpLLVMDefAspaceCfa:
27662767
case MCCFIInstruction::OpLabel:
27672768
case MCCFIInstruction::OpValOffset:
27682769
llvm_unreachable("unsupported CFI opcode");
27692770
break;
2771+
case MCCFIInstruction::OpNegateRAState:
2772+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) {
2773+
llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. "
2774+
"as produced by '-mbranch-protection=pac-ret') are "
2775+
"currently not supported by BOLT.");
2776+
}
2777+
break;
27702778
case MCCFIInstruction::OpRememberState:
27712779
case MCCFIInstruction::OpRestoreState:
27722780
case MCCFIInstruction::OpGnuArgsSize:
@@ -2900,13 +2908,19 @@ struct CFISnapshotDiff : public CFISnapshot {
29002908
return CFAReg == Instr.getRegister() && CFAOffset == Instr.getOffset();
29012909
case MCCFIInstruction::OpAdjustCfaOffset:
29022910
case MCCFIInstruction::OpWindowSave:
2903-
case MCCFIInstruction::OpNegateRAState:
29042911
case MCCFIInstruction::OpNegateRAStateWithPC:
29052912
case MCCFIInstruction::OpLLVMDefAspaceCfa:
29062913
case MCCFIInstruction::OpLabel:
29072914
case MCCFIInstruction::OpValOffset:
29082915
llvm_unreachable("unsupported CFI opcode");
29092916
return false;
2917+
case MCCFIInstruction::OpNegateRAState:
2918+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) {
2919+
llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. "
2920+
"as produced by '-mbranch-protection=pac-ret') are "
2921+
"currently not supported by BOLT.");
2922+
}
2923+
break;
29102924
case MCCFIInstruction::OpRememberState:
29112925
case MCCFIInstruction::OpRestoreState:
29122926
case MCCFIInstruction::OpGnuArgsSize:
@@ -3051,13 +3065,19 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState,
30513065
break;
30523066
case MCCFIInstruction::OpAdjustCfaOffset:
30533067
case MCCFIInstruction::OpWindowSave:
3054-
case MCCFIInstruction::OpNegateRAState:
30553068
case MCCFIInstruction::OpNegateRAStateWithPC:
30563069
case MCCFIInstruction::OpLLVMDefAspaceCfa:
30573070
case MCCFIInstruction::OpLabel:
30583071
case MCCFIInstruction::OpValOffset:
30593072
llvm_unreachable("unsupported CFI opcode");
30603073
break;
3074+
case MCCFIInstruction::OpNegateRAState:
3075+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) {
3076+
llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. "
3077+
"as produced by '-mbranch-protection=pac-ret') are "
3078+
"currently not supported by BOLT.");
3079+
}
3080+
break;
30613081
case MCCFIInstruction::OpGnuArgsSize:
30623082
// do not affect CFI state
30633083
break;

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ static llvm::Error decodeRecord(const Record &R, std::optional<Location> &Field,
7979
if (R[0] > INT_MAX)
8080
return llvm::createStringError(llvm::inconvertibleErrorCode(),
8181
"integer too large to parse");
82-
Field.emplace(static_cast<int>(R[0]), Blob, static_cast<bool>(R[1]));
82+
Field.emplace(static_cast<int>(R[0]), static_cast<int>(R[1]), Blob,
83+
static_cast<bool>(R[2]));
8384
return llvm::Error::success();
8485
}
8586

@@ -130,7 +131,8 @@ static llvm::Error decodeRecord(const Record &R,
130131
if (R[0] > INT_MAX)
131132
return llvm::createStringError(llvm::inconvertibleErrorCode(),
132133
"integer too large to parse");
133-
Field.emplace_back(static_cast<int>(R[0]), Blob, static_cast<bool>(R[1]));
134+
Field.emplace_back(static_cast<int>(R[0]), static_cast<int>(R[1]), Blob,
135+
static_cast<bool>(R[2]));
134136
return llvm::Error::success();
135137
}
136138

clang-tools-extra/clang-doc/BitcodeWriter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ static void genLocationAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
7878
{// 0. Fixed-size integer (line number)
7979
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
8080
BitCodeConstants::LineNumberSize),
81-
// 1. Boolean (IsFileInRootDir)
81+
// 1. Fixed-size integer (start line number)
82+
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
83+
BitCodeConstants::LineNumberSize),
84+
// 2. Boolean (IsFileInRootDir)
8285
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
8386
BitCodeConstants::BoolSize),
84-
// 2. Fixed-size integer (length of the following string (filename))
87+
// 3. Fixed-size integer (length of the following string (filename))
8588
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
8689
BitCodeConstants::StringLengthSize),
87-
// 3. The string blob
90+
// 4. The string blob
8891
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
8992
}
9093

@@ -357,7 +360,8 @@ void ClangDocBitcodeWriter::emitRecord(const Location &Loc, RecordId ID) {
357360
if (!prepRecordData(ID, true))
358361
return;
359362
// FIXME: Assert that the line number is of the appropriate size.
360-
Record.push_back(Loc.LineNumber);
363+
Record.push_back(Loc.StartLineNumber);
364+
Record.push_back(Loc.EndLineNumber);
361365
assert(Loc.Filename.size() < (1U << BitCodeConstants::StringLengthSize));
362366
Record.push_back(Loc.IsFileInRootDir);
363367
Record.push_back(Loc.Filename.size());

clang-tools-extra/clang-doc/HTMLGenerator.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static std::unique_ptr<TagNode> writeSourceFileRef(const ClangDocContext &CDCtx,
455455

456456
if (!L.IsFileInRootDir && !CDCtx.RepositoryUrl)
457457
return std::make_unique<TagNode>(
458-
HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
458+
HTMLTag::TAG_P, "Defined at line " + std::to_string(L.StartLineNumber) +
459459
" of file " + L.Filename);
460460

461461
SmallString<128> FileURL(CDCtx.RepositoryUrl.value_or(""));
@@ -472,13 +472,14 @@ static std::unique_ptr<TagNode> writeSourceFileRef(const ClangDocContext &CDCtx,
472472
llvm::sys::path::Style::windows));
473473
auto Node = std::make_unique<TagNode>(HTMLTag::TAG_P);
474474
Node->Children.emplace_back(std::make_unique<TextNode>("Defined at line "));
475-
auto LocNumberNode =
476-
std::make_unique<TagNode>(HTMLTag::TAG_A, std::to_string(L.LineNumber));
475+
auto LocNumberNode = std::make_unique<TagNode>(
476+
HTMLTag::TAG_A, std::to_string(L.StartLineNumber));
477477
// The links to a specific line in the source code use the github /
478478
// googlesource notation so it won't work for all hosting pages.
479479
LocNumberNode->Attributes.emplace_back(
480-
"href", formatv("{0}#{1}{2}", FileURL,
481-
CDCtx.RepositoryLinePrefix.value_or(""), L.LineNumber));
480+
"href",
481+
formatv("{0}#{1}{2}", FileURL, CDCtx.RepositoryLinePrefix.value_or(""),
482+
L.StartLineNumber));
482483
Node->Children.emplace_back(std::move(LocNumberNode));
483484
Node->Children.emplace_back(std::make_unique<TextNode>(" of file "));
484485
auto LocFileNode = std::make_unique<TagNode>(

clang-tools-extra/clang-doc/MDGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ static void writeSourceFileRef(const ClangDocContext &CDCtx, const Location &L,
5656
raw_ostream &OS) {
5757

5858
if (!CDCtx.RepositoryUrl) {
59-
OS << "*Defined at " << L.Filename << "#" << std::to_string(L.LineNumber)
60-
<< "*";
59+
OS << "*Defined at " << L.Filename << "#"
60+
<< std::to_string(L.StartLineNumber) << "*";
6161
} else {
6262

6363
OS << formatv("*Defined at [#{0}{1}{2}](#{0}{1}{3})*",
64-
CDCtx.RepositoryLinePrefix.value_or(""), L.LineNumber,
64+
CDCtx.RepositoryLinePrefix.value_or(""), L.StartLineNumber,
6565
L.Filename, *CDCtx.RepositoryUrl);
6666
}
6767
OS << "\n\n";

clang-tools-extra/clang-doc/Mapper.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ template <typename T> static bool isTypedefAnonRecord(const T *D) {
2828
return false;
2929
}
3030

31+
Location MapASTVisitor::getDeclLocation(const NamedDecl *D) const {
32+
bool IsFileInRootDir;
33+
llvm::SmallString<128> File =
34+
getFile(D, D->getASTContext(), CDCtx.SourceRoot, IsFileInRootDir);
35+
SourceManager &SM = D->getASTContext().getSourceManager();
36+
int Start = SM.getPresumedLoc(D->getBeginLoc()).getLine();
37+
int End = SM.getPresumedLoc(D->getEndLoc()).getLine();
38+
39+
return Location(Start, End, File, IsFileInRootDir);
40+
}
41+
3142
void MapASTVisitor::HandleTranslationUnit(ASTContext &Context) {
3243
TraverseDecl(Context.getTranslationUnitDecl());
3344
}
@@ -59,9 +70,9 @@ bool MapASTVisitor::mapDecl(const T *D, bool IsDefinition) {
5970
bool IsFileInRootDir;
6071
llvm::SmallString<128> File =
6172
getFile(D, D->getASTContext(), CDCtx.SourceRoot, IsFileInRootDir);
62-
auto [Child, Parent] = serialize::emitInfo(
63-
D, getComment(D, D->getASTContext()), getLine(D, D->getASTContext()),
64-
File, IsFileInRootDir, CDCtx.PublicOnly);
73+
auto [Child, Parent] =
74+
serialize::emitInfo(D, getComment(D, D->getASTContext()),
75+
getDeclLocation(D), CDCtx.PublicOnly);
6576

6677
// A null in place of a valid Info indicates that the serializer is skipping
6778
// this decl for some reason (e.g. we're only reporting public decls).

clang-tools-extra/clang-doc/Mapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>,
4646
template <typename T> bool mapDecl(const T *D, bool IsDefinition);
4747

4848
int getLine(const NamedDecl *D, const ASTContext &Context) const;
49+
50+
Location getDeclLocation(const NamedDecl *D) const;
51+
4952
llvm::SmallString<128> getFile(const NamedDecl *D, const ASTContext &Context,
5053
StringRef RootDir,
5154
bool &IsFileInRootDir) const;

clang-tools-extra/clang-doc/Representation.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,31 +241,29 @@ struct MemberTypeInfo : public FieldTypeInfo {
241241
};
242242

243243
struct Location {
244-
Location(int LineNumber = 0, StringRef Filename = StringRef(),
245-
bool IsFileInRootDir = false)
246-
: LineNumber(LineNumber), Filename(Filename),
247-
IsFileInRootDir(IsFileInRootDir) {}
244+
Location(int StartLineNumber = 0, int EndLineNumber = 0,
245+
StringRef Filename = StringRef(), bool IsFileInRootDir = false)
246+
: StartLineNumber(StartLineNumber), EndLineNumber(EndLineNumber),
247+
Filename(Filename), IsFileInRootDir(IsFileInRootDir) {}
248248

249249
bool operator==(const Location &Other) const {
250-
return std::tie(LineNumber, Filename) ==
251-
std::tie(Other.LineNumber, Other.Filename);
250+
return std::tie(StartLineNumber, EndLineNumber, Filename) ==
251+
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
252252
}
253253

254-
bool operator!=(const Location &Other) const {
255-
return std::tie(LineNumber, Filename) !=
256-
std::tie(Other.LineNumber, Other.Filename);
257-
}
254+
bool operator!=(const Location &Other) const { return !(*this == Other); }
258255

259256
// This operator is used to sort a vector of Locations.
260257
// No specific order (attributes more important than others) is required. Any
261258
// sort is enough, the order is only needed to call std::unique after sorting
262259
// the vector.
263260
bool operator<(const Location &Other) const {
264-
return std::tie(LineNumber, Filename) <
265-
std::tie(Other.LineNumber, Other.Filename);
261+
return std::tie(StartLineNumber, EndLineNumber, Filename) <
262+
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
266263
}
267264

268-
int LineNumber = 0; // Line number of this Location.
265+
int StartLineNumber = 0; // Line number of this Location.
266+
int EndLineNumber = 0;
269267
SmallString<32> Filename; // File for this Location.
270268
bool IsFileInRootDir = false; // Indicates if file is inside root directory
271269
};

0 commit comments

Comments
 (0)