Skip to content

Commit 3d19e83

Browse files
committed
Merge remote-tracking branch 'origin/main' into req-attach
2 parents b11201f + 334e05b commit 3d19e83

File tree

1,270 files changed

+24675
-12452
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,270 files changed

+24675
-12452
lines changed

.github/workflows/libc-fullbuild-tests.yml

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@ jobs:
1919
include:
2020
- os: ubuntu-24.04
2121
ccache-variant: sccache
22-
c_compiler: clang-20
23-
cpp_compiler: clang++-20
22+
c_compiler: clang-21
23+
cpp_compiler: clang++-21
24+
target: x86_64-unknown-linux-llvm
25+
include_scudo: ON
2426
# TODO: remove ccache logic when https://github.com/hendrikmuhs/ccache-action/issues/279 is resolved.
2527
- os: ubuntu-24.04-arm
2628
ccache-variant: ccache
27-
c_compiler: clang-20
28-
cpp_compiler: clang++-20
29+
c_compiler: clang-21
30+
cpp_compiler: clang++-21
31+
target: aarch64-unknown-linux-llvm
32+
include_scudo: ON
33+
- os: ubuntu-24.04
34+
ccache-variant: ccache
35+
c_compiler: clang-21
36+
cpp_compiler: clang++-21
37+
target: x86_64-unknown-uefi-llvm
38+
include_scudo: OFF
2939
# TODO: add back gcc build when it is fixed
3040
# - c_compiler: gcc
3141
# cpp_compiler: g++
@@ -53,7 +63,7 @@ jobs:
5363
run: |
5464
wget https://apt.llvm.org/llvm.sh
5565
chmod +x llvm.sh
56-
sudo ./llvm.sh 20
66+
sudo ./llvm.sh 21
5767
sudo apt-get update
5868
sudo apt-get install -y libmpfr-dev libgmp-dev libmpc-dev ninja-build linux-libc-dev
5969
sudo ln -sf /usr/include/$(uname -p)-linux-gnu/asm /usr/include/asm
@@ -68,22 +78,31 @@ jobs:
6878
# Configure libc fullbuild with scudo.
6979
# Use MinSizeRel to reduce the size of the build.
7080
- name: Configure CMake
71-
run: >
72-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
73-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
74-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
75-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
76-
-DCMAKE_C_COMPILER_LAUNCHER=${{ matrix.ccache-variant }}
77-
-DCMAKE_CXX_COMPILER_LAUNCHER=${{ matrix.ccache-variant }}
78-
-DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }}
79-
-DLLVM_ENABLE_RUNTIMES="libc;compiler-rt"
80-
-DLLVM_LIBC_FULL_BUILD=ON
81-
-DLLVM_LIBC_INCLUDE_SCUDO=ON
82-
-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON
83-
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
84-
-DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF
85-
-G Ninja
86-
-S ${{ github.workspace }}/runtimes
81+
run: |
82+
export RUNTIMES="libc"
83+
84+
if [[ ${{ matrix.include_scudo}} == "ON" ]]; then
85+
export RUNTIMES="$RUNTIMES;compiler-rt"
86+
export CMAKE_FLAGS="
87+
-DLLVM_LIBC_INCLUDE_SCUDO=ON
88+
-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON
89+
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
90+
-DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF"
91+
fi
92+
93+
cmake -B ${{ steps.strings.outputs.build-output-dir }} \
94+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
95+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
96+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
97+
-DCMAKE_C_COMPILER_LAUNCHER=${{ matrix.ccache-variant }} \
98+
-DCMAKE_CXX_COMPILER_LAUNCHER=${{ matrix.ccache-variant }} \
99+
-DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }} \
100+
-DLLVM_RUNTIMES_TARGET=${{ matrix.target }} \
101+
-DLLVM_ENABLE_RUNTIMES="$RUNTIMES" \
102+
-DLLVM_LIBC_FULL_BUILD=ON \
103+
-G Ninja \
104+
-S ${{ github.workspace }}/runtimes \
105+
$CMAKE_FLAGS
87106
88107
- name: Build
89108
run: >
@@ -93,6 +112,8 @@ jobs:
93112
--target install
94113
95114
- name: Test
115+
# Skip UEFI tests until we have testing set up.
116+
if: ${{ ! endsWith(matrix.target, '-uefi-llvm') }}
96117
run: >
97118
cmake
98119
--build ${{ steps.strings.outputs.build-output-dir }}

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)