Skip to content

Commit ceea9c9

Browse files
Merge branch 'main' into ib/fix_171494
2 parents 276056e + 11e457c commit ceea9c9

File tree

370 files changed

+8075
-3948
lines changed

Some content is hidden

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

370 files changed

+8075
-3948
lines changed

.github/workflows/release-documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ jobs:
9292
git config user.name "llvmbot"
9393
git commit -a -m "Add ${{ inputs.release-version }} documentation"
9494
git push --force "https://$GH_TOKEN@github.com/llvmbot/www-releases.git" HEAD:refs/heads/${{ inputs.release-version }}
95-
gh pr create -f -B main -H ${{ inputs.release-version }} -R llvmbot/www-releases
95+
gh pr create -f -B main -H llvmbot:${{ inputs.release-version }}

bolt/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,26 @@ $ merge-fdata *.fdata > combined.fdata
202202
Use `combined.fdata` for **Step 3** above to generate a universally optimized
203203
binary.
204204

205+
## Identifying a Binary Modified By BOLT
206+
207+
A binary that has been modified by BOLT will include a `bolt_info` note and may
208+
have extra sections with `bolt` in their name.
209+
210+
You can use `readelf` to find these:
211+
```
212+
$ readelf -S <your-binary> | grep bolt
213+
[11] .bolt.org.eh_frame PROGBITS <...>
214+
<...>
215+
[39] .note.bolt_info NOTE <...>
216+
```
217+
The note can be displayed with:
218+
```
219+
$ readelf -p .note.bolt_info <your-binary>
220+
String dump of section '.note.bolt_info':
221+
<...>
222+
[ 10] BOLT revision: <...>
223+
```
224+
205225
## License
206226

207227
BOLT is licensed under the [Apache License v2.0 with LLVM Exceptions](./LICENSE.TXT).

bolt/lib/Core/BinaryContext.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,9 @@ void BinaryContext::preprocessDebugInfo() {
18881888

18891889
preprocessDWODebugInfo();
18901890

1891+
// Check if required DWO files are missing.
1892+
uint64_t NumMissingDWOs = 0;
1893+
18911894
// Populate MCContext with DWARF files from all units.
18921895
StringRef GlobalPrefix = AsmInfo->getPrivateGlobalPrefix();
18931896
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
@@ -1909,19 +1912,23 @@ void BinaryContext::preprocessDebugInfo() {
19091912
std::optional<MD5::MD5Result> Checksum;
19101913
if (LineTable->Prologue.ContentTypes.HasMD5)
19111914
Checksum = LineTable->Prologue.FileNames[0].Checksum;
1912-
std::optional<const char *> Name =
1915+
const char *Name =
19131916
dwarf::toString(CU->getUnitDIE().find(dwarf::DW_AT_name), nullptr);
19141917
if (std::optional<uint64_t> DWOID = CU->getDWOId()) {
19151918
auto Iter = DWOCUs.find(*DWOID);
19161919
if (Iter == DWOCUs.end()) {
1917-
this->errs() << "BOLT-ERROR: DWO CU was not found for " << Name
1918-
<< '\n';
1919-
exit(1);
1920+
const char *DWOName =
1921+
dwarf::toString(CU->getUnitDIE().find(dwarf::DW_AT_dwo_name),
1922+
"<missing DW_AT_dwo_name>");
1923+
this->errs() << "BOLT-ERROR: unable to load " << DWOName
1924+
<< " for DWO_id 0x" << Twine::utohexstr(*DWOID) << '\n';
1925+
NumMissingDWOs++;
1926+
continue;
19201927
}
19211928
Name = dwarf::toString(
19221929
Iter->second->getUnitDIE().find(dwarf::DW_AT_name), nullptr);
19231930
}
1924-
BinaryLineTable.setRootFile(CU->getCompilationDir(), *Name, Checksum,
1931+
BinaryLineTable.setRootFile(CU->getCompilationDir(), Name, Checksum,
19251932
std::nullopt);
19261933
}
19271934

@@ -1956,6 +1963,14 @@ void BinaryContext::preprocessDebugInfo() {
19561963
DwarfVersion));
19571964
}
19581965
}
1966+
1967+
if (NumMissingDWOs) {
1968+
this->errs() << "BOLT-ERROR: " << NumMissingDWOs
1969+
<< " required DWO file(s) not found. Unable to update debug"
1970+
" info. Use --comp-dir-override to locate the file(s) or"
1971+
" --update-debug-sections=0 to remove debug info\n";
1972+
exit(1);
1973+
}
19591974
}
19601975

19611976
bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {

bolt/test/dwarf5-missing-dwo.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Check that llvm-bolt correctly reports a missing DWO file while updating
2+
// debug info.
3+
//
4+
// RUN: %clang %cflags -g -dwarf5 -gsplit-dwarf=single -c %s -o %t.o
5+
// RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
6+
// RUN: rm %t.o
7+
// RUN: not llvm-bolt %t.exe -o %t.bolt --update-debug-sections \
8+
// RUN: 2>&1 | FileCheck %s -DDWO=%t.o
9+
//
10+
// Check that llvm-bolt succeeds on the same binary with disabled debug info
11+
// update.
12+
//
13+
// RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections=0
14+
15+
// CHECK: BOLT-ERROR: unable to load [[DWO]]
16+
// CHECK-NEXT: BOLT-ERROR: 1 required DWO file(s) not found
17+
18+
int main() { return 0; }

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,23 @@ serializeLocation(const Location &Loc,
8484
return LocationObj;
8585
}
8686

87+
/// Insert comments into a key in the Description object.
88+
///
89+
/// \param Comment Either an Object or Array, depending on the comment type
90+
/// \param Key The type (Brief, Code, etc.) of comment to be inserted
8791
static void insertComment(Object &Description, json::Value &Comment,
8892
StringRef Key) {
93+
// The comment has a Children array for the actual text, with meta attributes
94+
// alongside it in the Object.
95+
if (auto *Obj = Comment.getAsObject()) {
96+
if (auto *Children = Obj->getArray("Children"); Children->empty())
97+
return;
98+
}
99+
// The comment is just an array of text comments.
100+
else if (auto *Array = Comment.getAsArray(); Array->empty()) {
101+
return;
102+
}
103+
89104
auto DescriptionIt = Description.find(Key);
90105

91106
if (DescriptionIt == Description.end()) {
@@ -98,10 +113,28 @@ static void insertComment(Object &Description, json::Value &Comment,
98113
}
99114
}
100115

116+
/// Takes the nested "Children" array from a comment Object.
117+
///
118+
/// \return a json::Array of comments, possible json::Value::Kind::Null
101119
static json::Value extractTextComments(Object *ParagraphComment) {
102120
if (!ParagraphComment)
103-
return json::Object();
104-
return *ParagraphComment->get("Children");
121+
return json::Value(nullptr);
122+
json::Value *Children = ParagraphComment->get("Children");
123+
if (!Children)
124+
return json::Value(nullptr);
125+
auto ChildrenArray = *Children->getAsArray();
126+
auto ChildrenIt = ChildrenArray.begin();
127+
while (ChildrenIt != ChildrenArray.end()) {
128+
auto *ChildObj = ChildrenIt->getAsObject();
129+
assert(ChildObj && "Invalid JSON object in Comment");
130+
auto TextComment = ChildObj->getString("TextComment");
131+
if (!TextComment || TextComment->empty()) {
132+
ChildrenIt = ChildrenArray.erase(ChildrenIt);
133+
continue;
134+
}
135+
++ChildrenIt;
136+
}
137+
return ChildrenArray;
105138
}
106139

107140
static json::Value extractVerbatimComments(json::Array VerbatimLines) {
@@ -131,7 +164,8 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
131164

132165
switch (I.Kind) {
133166
case CommentKind::CK_TextComment: {
134-
Obj.insert({commentKindToString(I.Kind), I.Text});
167+
if (!I.Text.empty())
168+
Obj.insert({commentKindToString(I.Kind), I.Text});
135169
return Obj;
136170
}
137171

@@ -265,6 +299,9 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
265299
if (auto *ParagraphComment = Comment.getAsObject();
266300
ParagraphComment->get("ParagraphComment")) {
267301
auto TextCommentsArray = extractTextComments(ParagraphComment);
302+
if (TextCommentsArray.kind() == json::Value::Null ||
303+
TextCommentsArray.getAsArray()->empty())
304+
continue;
268305
insertComment(Description, TextCommentsArray, "ParagraphComments");
269306
}
270307
}

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
554554
if (const auto &Dir = Params.initializationOptions.compilationDatabasePath)
555555
CDBOpts.CompileCommandsDir = Dir;
556556
CDBOpts.ContextProvider = Opts.ContextProvider;
557-
if (Opts.StrongWorkspaceMode)
558-
CDBOpts.applyFallbackWorkingDirectory(Opts.WorkspaceRoot);
559557
BaseCDB =
560558
std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
561559
}

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ class ClangdServer {
152152
/// FIXME: If not set, should use the current working directory.
153153
std::optional<std::string> WorkspaceRoot;
154154

155-
/// Sets an alternate mode of operation. Current effects are:
156-
/// - Using the current working directory as the working directory for
157-
/// fallback commands
158-
bool StrongWorkspaceMode;
159-
160155
/// The resource directory is used to find internal headers, overriding
161156
/// defaults and -resource-dir compiler flag).
162157
/// If std::nullopt, ClangdServer calls

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ GlobalCompilationDatabase::getFallbackCommand(PathRef File) const {
6464
if (FileExtension.empty() || FileExtension == ".h")
6565
Argv.push_back("-xobjective-c++-header");
6666
Argv.push_back(std::string(File));
67-
tooling::CompileCommand Cmd(FallbackWorkingDirectory
68-
? *FallbackWorkingDirectory
69-
: llvm::sys::path::parent_path(File),
67+
tooling::CompileCommand Cmd(llvm::sys::path::parent_path(File),
7068
llvm::sys::path::filename(File), std::move(Argv),
7169
/*Output=*/"");
7270
Cmd.Heuristic = "clangd fallback";
@@ -351,8 +349,7 @@ bool DirectoryBasedGlobalCompilationDatabase::DirectoryCache::load(
351349

352350
DirectoryBasedGlobalCompilationDatabase::
353351
DirectoryBasedGlobalCompilationDatabase(const Options &Opts)
354-
: GlobalCompilationDatabase(Opts.FallbackWorkingDirectory), Opts(Opts),
355-
Broadcaster(std::make_unique<BroadcastThread>(*this)) {
352+
: Opts(Opts), Broadcaster(std::make_unique<BroadcastThread>(*this)) {
356353
if (!this->Opts.ContextProvider)
357354
this->Opts.ContextProvider = [](llvm::StringRef) {
358355
return Context::current().clone();
@@ -463,21 +460,6 @@ DirectoryBasedGlobalCompilationDatabase::lookupCDB(
463460
return Result;
464461
}
465462

466-
void DirectoryBasedGlobalCompilationDatabase::Options::
467-
applyFallbackWorkingDirectory(
468-
std::optional<std::string> FallbackWorkingDirectory) {
469-
if (FallbackWorkingDirectory)
470-
this->FallbackWorkingDirectory = *FallbackWorkingDirectory;
471-
else {
472-
// Clangd is running in strong workspace mode but the client didn't
473-
// specify a workspace path in the `initialize` request.
474-
// Fallback to current working directory.
475-
SmallString<256> CWD;
476-
llvm::sys::fs::current_path(CWD);
477-
this->FallbackWorkingDirectory = std::string(CWD);
478-
}
479-
}
480-
481463
// The broadcast thread announces files with new compile commands to the world.
482464
// Primarily this is used to enqueue them for background indexing.
483465
//
@@ -777,10 +759,9 @@ DirectoryBasedGlobalCompilationDatabase::getProjectModules(PathRef File) const {
777759

778760
OverlayCDB::OverlayCDB(const GlobalCompilationDatabase *Base,
779761
std::vector<std::string> FallbackFlags,
780-
CommandMangler Mangler,
781-
std::optional<std::string> FallbackWorkingDirectory)
782-
: DelegatingCDB(Base, FallbackWorkingDirectory),
783-
Mangler(std::move(Mangler)), FallbackFlags(std::move(FallbackFlags)) {}
762+
CommandMangler Mangler)
763+
: DelegatingCDB(Base), Mangler(std::move(Mangler)),
764+
FallbackFlags(std::move(FallbackFlags)) {}
784765

785766
std::optional<tooling::CompileCommand>
786767
OverlayCDB::getCompileCommand(PathRef File) const {
@@ -863,20 +844,16 @@ OverlayCDB::getProjectModules(PathRef File) const {
863844
return MDB;
864845
}
865846

866-
DelegatingCDB::DelegatingCDB(
867-
const GlobalCompilationDatabase *Base,
868-
std::optional<std::string> FallbackWorkingDirectory)
869-
: GlobalCompilationDatabase(FallbackWorkingDirectory), Base(Base) {
847+
DelegatingCDB::DelegatingCDB(const GlobalCompilationDatabase *Base)
848+
: Base(Base) {
870849
if (Base)
871850
BaseChanged = Base->watch([this](const std::vector<std::string> Changes) {
872851
OnCommandChanged.broadcast(Changes);
873852
});
874853
}
875854

876-
DelegatingCDB::DelegatingCDB(
877-
std::unique_ptr<GlobalCompilationDatabase> Base,
878-
std::optional<std::string> FallbackWorkingDirectory)
879-
: DelegatingCDB(Base.get(), FallbackWorkingDirectory) {
855+
DelegatingCDB::DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base)
856+
: DelegatingCDB(Base.get()) {
880857
BaseOwner = std::move(Base);
881858
}
882859

clang-tools-extra/clangd/GlobalCompilationDatabase.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ struct ProjectInfo {
3535
/// Provides compilation arguments used for parsing C and C++ files.
3636
class GlobalCompilationDatabase {
3737
public:
38-
GlobalCompilationDatabase(
39-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt)
40-
: FallbackWorkingDirectory(FallbackWorkingDirectory) {}
4138
virtual ~GlobalCompilationDatabase() = default;
4239

4340
/// If there are any known-good commands for building this file, returns one.
@@ -72,19 +69,14 @@ class GlobalCompilationDatabase {
7269
}
7370

7471
protected:
75-
std::optional<std::string> FallbackWorkingDirectory;
7672
mutable CommandChanged OnCommandChanged;
7773
};
7874

7975
// Helper class for implementing GlobalCompilationDatabases that wrap others.
8076
class DelegatingCDB : public GlobalCompilationDatabase {
8177
public:
82-
DelegatingCDB(
83-
const GlobalCompilationDatabase *Base,
84-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
85-
DelegatingCDB(
86-
std::unique_ptr<GlobalCompilationDatabase> Base,
87-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
78+
DelegatingCDB(const GlobalCompilationDatabase *Base);
79+
DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base);
8880

8981
std::optional<tooling::CompileCommand>
9082
getCompileCommand(PathRef File) const override;
@@ -125,12 +117,6 @@ class DirectoryBasedGlobalCompilationDatabase
125117
// Only look for a compilation database in this one fixed directory.
126118
// FIXME: fold this into config/context mechanism.
127119
std::optional<Path> CompileCommandsDir;
128-
// Working directory for fallback commands
129-
// If unset, parent directory of file should be used
130-
std::optional<std::string> FallbackWorkingDirectory;
131-
132-
void applyFallbackWorkingDirectory(
133-
std::optional<std::string> FallbackWorkingDirectory);
134120
};
135121

136122
DirectoryBasedGlobalCompilationDatabase(const Options &Opts);
@@ -208,11 +194,9 @@ class OverlayCDB : public DelegatingCDB {
208194
// Base may be null, in which case no entries are inherited.
209195
// FallbackFlags are added to the fallback compile command.
210196
// Adjuster is applied to all commands, fallback or not.
211-
OverlayCDB(
212-
const GlobalCompilationDatabase *Base,
213-
std::vector<std::string> FallbackFlags = {},
214-
CommandMangler Mangler = nullptr,
215-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
197+
OverlayCDB(const GlobalCompilationDatabase *Base,
198+
std::vector<std::string> FallbackFlags = {},
199+
CommandMangler Mangler = nullptr);
216200

217201
std::optional<tooling::CompileCommand>
218202
getCompileCommand(PathRef File) const override;

clang-tools-extra/clangd/tool/Check.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ class Checker {
169169
bool buildCommand(const ThreadsafeFS &TFS) {
170170
log("Loading compilation database...");
171171
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
172-
if (Opts.StrongWorkspaceMode)
173-
CDBOpts.applyFallbackWorkingDirectory(Opts.WorkspaceRoot);
174172
CDBOpts.CompileCommandsDir =
175173
Config::current().CompileFlags.CDBSearch.FixedCDBPath;
176174
BaseCDB =
@@ -180,10 +178,8 @@ class Checker {
180178
getSystemIncludeExtractor(llvm::ArrayRef(Opts.QueryDriverGlobs));
181179
if (Opts.ResourceDir)
182180
Mangler.ResourceDir = *Opts.ResourceDir;
183-
184181
CDB = std::make_unique<OverlayCDB>(
185-
BaseCDB.get(), std::vector<std::string>{}, std::move(Mangler),
186-
CDBOpts.FallbackWorkingDirectory);
182+
BaseCDB.get(), std::vector<std::string>{}, std::move(Mangler));
187183

188184
if (auto TrueCmd = CDB->getCompileCommand(File)) {
189185
Cmd = std::move(*TrueCmd);
@@ -506,7 +502,7 @@ bool check(llvm::StringRef File, const ThreadsafeFS &TFS,
506502
config::DiagnosticCallback Diag) const override {
507503
config::Fragment F;
508504
// If we're timing clang-tidy checks, implicitly disabling the slow ones
509-
// is counterproductive!
505+
// is counterproductive!
510506
if (CheckTidyTime.getNumOccurrences())
511507
F.Diagnostics.ClangTidy.FastCheckFilter.emplace("None");
512508
return {std::move(F).compile(Diag)};

0 commit comments

Comments
 (0)