Skip to content

Commit 65dbabf

Browse files
authored
Merge branch 'main' into android-tests-r536225
2 parents 813cd63 + 012dd8b commit 65dbabf

File tree

505 files changed

+11562
-4812
lines changed

Some content is hidden

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

505 files changed

+11562
-4812
lines changed

.github/new-issues-labeler.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@
2727

2828
'bolt':
2929
- '/\bbolt(?!\-)\b/i'
30+
31+
'infra:commit-access-request':
32+
- '/Request Commit Access/'

bolt/include/bolt/Core/BinarySection.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class BinarySection {
8787
// been renamed)
8888
uint64_t OutputAddress{0}; // Section address for the rewritten binary.
8989
uint64_t OutputSize{0}; // Section size in the rewritten binary.
90+
// Can exceed OutputContents with padding.
9091
uint64_t OutputFileOffset{0}; // File offset in the rewritten binary file.
9192
StringRef OutputContents; // Rewritten section contents.
9293
const uint64_t SectionNumber; // Order in which the section was created.
@@ -474,6 +475,11 @@ class BinarySection {
474475
/// Use name \p SectionName for the section during the emission.
475476
void emitAsData(MCStreamer &Streamer, const Twine &SectionName) const;
476477

478+
/// Write finalized contents of the section. If OutputSize exceeds the size of
479+
/// the OutputContents, append zero padding to the stream and return the
480+
/// number of byte written which should match the OutputSize.
481+
uint64_t write(raw_ostream &OS) const;
482+
477483
using SymbolResolverFuncTy = llvm::function_ref<uint64_t(const MCSymbol *)>;
478484

479485
/// Flush all pending relocations to patch original contents of sections
@@ -497,6 +503,9 @@ class BinarySection {
497503
IsFinalized = true;
498504
}
499505

506+
/// When writing section contents, add \p PaddingSize zero bytes at the end.
507+
void addPadding(uint64_t PaddingSize) { OutputSize += PaddingSize; }
508+
500509
/// Reorder the contents of this section according to /p Order. If
501510
/// /p Inplace is true, the entire contents of the section is reordered,
502511
/// otherwise the new contents contain only the reordered data.

bolt/lib/Core/BinarySection.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ void BinarySection::emitAsData(MCStreamer &Streamer,
142142
Streamer.emitLabel(BC.Ctx->getOrCreateSymbol("__hot_data_end"));
143143
}
144144

145+
uint64_t BinarySection::write(raw_ostream &OS) const {
146+
const uint64_t NumValidContentBytes =
147+
std::min<uint64_t>(getOutputContents().size(), getOutputSize());
148+
OS.write(getOutputContents().data(), NumValidContentBytes);
149+
if (getOutputSize() > NumValidContentBytes)
150+
OS.write_zeros(getOutputSize() - NumValidContentBytes);
151+
return getOutputSize();
152+
}
153+
145154
void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS,
146155
SymbolResolverFuncTy Resolver) {
147156
if (PendingRelocations.empty() && Patches.empty())

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 96 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,6 +3887,43 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
38873887

38883888
void RewriteInstance::mapAllocatableSections(
38893889
BOLTLinker::SectionMapper MapSection) {
3890+
3891+
if (opts::UseOldText || opts::StrictMode) {
3892+
auto tryRewriteSection = [&](BinarySection &OldSection,
3893+
BinarySection &NewSection) {
3894+
if (OldSection.getSize() < NewSection.getOutputSize())
3895+
return;
3896+
3897+
BC->outs() << "BOLT-INFO: rewriting " << OldSection.getName()
3898+
<< " in-place\n";
3899+
3900+
NewSection.setOutputAddress(OldSection.getAddress());
3901+
NewSection.setOutputFileOffset(OldSection.getInputFileOffset());
3902+
MapSection(NewSection, OldSection.getAddress());
3903+
3904+
// Pad contents with zeros.
3905+
NewSection.addPadding(OldSection.getSize() - NewSection.getOutputSize());
3906+
3907+
// Prevent the original section name from appearing in the section header
3908+
// table.
3909+
OldSection.setAnonymous(true);
3910+
};
3911+
3912+
if (EHFrameSection) {
3913+
BinarySection *NewEHFrameSection =
3914+
getSection(getNewSecPrefix() + getEHFrameSectionName());
3915+
assert(NewEHFrameSection && "New contents expected for .eh_frame");
3916+
tryRewriteSection(*EHFrameSection, *NewEHFrameSection);
3917+
}
3918+
BinarySection *EHSection = getSection(".gcc_except_table");
3919+
BinarySection *NewEHSection =
3920+
getSection(getNewSecPrefix() + ".gcc_except_table");
3921+
if (EHSection) {
3922+
assert(NewEHSection && "New contents expected for .gcc_except_table");
3923+
tryRewriteSection(*EHSection, *NewEHSection);
3924+
}
3925+
}
3926+
38903927
// Allocate read-only sections first, then writable sections.
38913928
enum : uint8_t { ST_READONLY, ST_READWRITE };
38923929
for (uint8_t SType = ST_READONLY; SType <= ST_READWRITE; ++SType) {
@@ -4164,7 +4201,6 @@ void RewriteInstance::rewriteNoteSections() {
41644201
// New section size.
41654202
uint64_t Size = 0;
41664203
bool DataWritten = false;
4167-
uint8_t *SectionData = nullptr;
41684204
// Copy over section contents unless it's one of the sections we overwrite.
41694205
if (!willOverwriteSection(SectionName)) {
41704206
Size = Section.sh_size;
@@ -4196,12 +4232,7 @@ void RewriteInstance::rewriteNoteSections() {
41964232
if (BSec->getAllocAddress()) {
41974233
assert(!DataWritten && "Writing section twice.");
41984234
(void)DataWritten;
4199-
SectionData = BSec->getOutputData();
4200-
4201-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: " << (Size ? "appending" : "writing")
4202-
<< " contents to section " << SectionName << '\n');
4203-
OS.write(reinterpret_cast<char *>(SectionData), BSec->getOutputSize());
4204-
Size += BSec->getOutputSize();
4235+
Size += BSec->write(OS);
42054236
}
42064237

42074238
BSec->setOutputFileOffset(NextAvailableOffset);
@@ -4232,8 +4263,7 @@ void RewriteInstance::rewriteNoteSections() {
42324263
<< " of size " << Section.getOutputSize() << " at offset 0x"
42334264
<< Twine::utohexstr(Section.getOutputFileOffset()) << '\n');
42344265

4235-
OS.write(Section.getOutputContents().data(), Section.getOutputSize());
4236-
NextAvailableOffset += Section.getOutputSize();
4266+
NextAvailableOffset += Section.write(OS);
42374267
}
42384268
}
42394269

@@ -4347,6 +4377,10 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
43474377
BinarySection *BinSec = BC->getSectionForSectionRef(SecRef);
43484378
assert(BinSec && "Matching BinarySection should exist.");
43494379

4380+
// Exclude anonymous sections.
4381+
if (BinSec->isAnonymous())
4382+
continue;
4383+
43504384
addSection(Section, *BinSec);
43514385
}
43524386

@@ -5699,8 +5733,8 @@ void RewriteInstance::rewriteFile() {
56995733
<< Twine::utohexstr(Section.getAllocAddress()) << "\n of size "
57005734
<< Section.getOutputSize() << "\n at offset "
57015735
<< Section.getOutputFileOffset() << '\n';
5702-
OS.pwrite(reinterpret_cast<const char *>(Section.getOutputData()),
5703-
Section.getOutputSize(), Section.getOutputFileOffset());
5736+
OS.seek(Section.getOutputFileOffset());
5737+
Section.write(OS);
57045738
}
57055739

57065740
for (BinarySection &Section : BC->allocatableSections())
@@ -5791,42 +5825,64 @@ void RewriteInstance::writeEHFrameHeader() {
57915825
LLVM_DEBUG(dbgs() << "BOLT: writing a new " << getEHFrameHdrSectionName()
57925826
<< '\n');
57935827

5794-
NextAvailableAddress =
5795-
appendPadding(Out->os(), NextAvailableAddress, EHFrameHdrAlign);
5828+
// Try to overwrite the original .eh_frame_hdr if the size permits.
5829+
uint64_t EHFrameHdrOutputAddress = 0;
5830+
uint64_t EHFrameHdrFileOffset = 0;
5831+
std::vector<char> NewEHFrameHdr;
5832+
BinarySection *OldEHFrameHdrSection = getSection(getEHFrameHdrSectionName());
5833+
if (OldEHFrameHdrSection) {
5834+
NewEHFrameHdr = CFIRdWrt->generateEHFrameHeader(
5835+
RelocatedEHFrame, NewEHFrame, OldEHFrameHdrSection->getAddress());
5836+
if (NewEHFrameHdr.size() <= OldEHFrameHdrSection->getSize()) {
5837+
BC->outs() << "BOLT-INFO: rewriting " << getEHFrameHdrSectionName()
5838+
<< " in-place\n";
5839+
EHFrameHdrOutputAddress = OldEHFrameHdrSection->getAddress();
5840+
EHFrameHdrFileOffset = OldEHFrameHdrSection->getInputFileOffset();
5841+
} else {
5842+
OldEHFrameHdrSection->setOutputName(getOrgSecPrefix() +
5843+
getEHFrameHdrSectionName());
5844+
OldEHFrameHdrSection = nullptr;
5845+
}
5846+
}
57965847

5797-
const uint64_t EHFrameHdrOutputAddress = NextAvailableAddress;
5798-
const uint64_t EHFrameHdrFileOffset =
5799-
getFileOffsetForAddress(NextAvailableAddress);
5848+
// If there was not enough space, allocate more memory for .eh_frame_hdr.
5849+
if (!OldEHFrameHdrSection) {
5850+
NextAvailableAddress =
5851+
appendPadding(Out->os(), NextAvailableAddress, EHFrameHdrAlign);
58005852

5801-
std::vector<char> NewEHFrameHdr = CFIRdWrt->generateEHFrameHeader(
5802-
RelocatedEHFrame, NewEHFrame, EHFrameHdrOutputAddress);
5853+
EHFrameHdrOutputAddress = NextAvailableAddress;
5854+
EHFrameHdrFileOffset = getFileOffsetForAddress(NextAvailableAddress);
5855+
5856+
NewEHFrameHdr = CFIRdWrt->generateEHFrameHeader(
5857+
RelocatedEHFrame, NewEHFrame, EHFrameHdrOutputAddress);
5858+
5859+
NextAvailableAddress += NewEHFrameHdr.size();
5860+
if (!BC->BOLTReserved.empty() &&
5861+
(NextAvailableAddress > BC->BOLTReserved.end())) {
5862+
BC->errs() << "BOLT-ERROR: unable to fit " << getEHFrameHdrSectionName()
5863+
<< " into reserved space\n";
5864+
exit(1);
5865+
}
5866+
5867+
// Create a new entry in the section header table.
5868+
const unsigned Flags = BinarySection::getFlags(/*IsReadOnly=*/true,
5869+
/*IsText=*/false,
5870+
/*IsAllocatable=*/true);
5871+
BinarySection &EHFrameHdrSec = BC->registerOrUpdateSection(
5872+
getNewSecPrefix() + getEHFrameHdrSectionName(), ELF::SHT_PROGBITS,
5873+
Flags, nullptr, NewEHFrameHdr.size(), /*Alignment=*/1);
5874+
EHFrameHdrSec.setOutputFileOffset(EHFrameHdrFileOffset);
5875+
EHFrameHdrSec.setOutputAddress(EHFrameHdrOutputAddress);
5876+
EHFrameHdrSec.setOutputName(getEHFrameHdrSectionName());
5877+
}
58035878

58045879
Out->os().seek(EHFrameHdrFileOffset);
58055880
Out->os().write(NewEHFrameHdr.data(), NewEHFrameHdr.size());
58065881

5807-
const unsigned Flags = BinarySection::getFlags(/*IsReadOnly=*/true,
5808-
/*IsText=*/false,
5809-
/*IsAllocatable=*/true);
5810-
BinarySection *OldEHFrameHdrSection = getSection(getEHFrameHdrSectionName());
5882+
// Pad the contents if overwriting in-place.
58115883
if (OldEHFrameHdrSection)
5812-
OldEHFrameHdrSection->setOutputName(getOrgSecPrefix() +
5813-
getEHFrameHdrSectionName());
5814-
5815-
BinarySection &EHFrameHdrSec = BC->registerOrUpdateSection(
5816-
getNewSecPrefix() + getEHFrameHdrSectionName(), ELF::SHT_PROGBITS, Flags,
5817-
nullptr, NewEHFrameHdr.size(), /*Alignment=*/1);
5818-
EHFrameHdrSec.setOutputFileOffset(EHFrameHdrFileOffset);
5819-
EHFrameHdrSec.setOutputAddress(EHFrameHdrOutputAddress);
5820-
EHFrameHdrSec.setOutputName(getEHFrameHdrSectionName());
5821-
5822-
NextAvailableAddress += EHFrameHdrSec.getOutputSize();
5823-
5824-
if (!BC->BOLTReserved.empty() &&
5825-
(NextAvailableAddress > BC->BOLTReserved.end())) {
5826-
BC->errs() << "BOLT-ERROR: unable to fit " << getEHFrameHdrSectionName()
5827-
<< " into reserved space\n";
5828-
exit(1);
5829-
}
5884+
Out->os().write_zeros(OldEHFrameHdrSection->getSize() -
5885+
NewEHFrameHdr.size());
58305886

58315887
// Merge new .eh_frame with the relocated original so that gdb can locate all
58325888
// FDEs.

bolt/test/eh-frame-hdr.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Check that llvm-bolt overwrites .eh_frame_hdr in-place.
2+
3+
REQUIRES: system-linux
4+
5+
RUN: %clang %cflags %p/Inputs/hello.c -o %t -Wl,-q
6+
RUN: llvm-bolt %t -o %t.bolt --use-old-text \
7+
RUN: | FileCheck %s --check-prefix=CHECK-BOLT
8+
RUN: llvm-readelf -WS %t.bolt | FileCheck %s
9+
10+
CHECK-BOLT: rewriting .eh_frame_hdr in-place
11+
12+
CHECK-NOT: .bolt.org.eh_frame_hdr

bolt/test/eh-frame-overwrite.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Check that llvm-bolt can overwrite .eh_frame section in-place.
2+
3+
REQUIRES: system-linux
4+
5+
RUN: %clang %cflags %p/Inputs/hello.c -o %t -Wl,-q
6+
RUN: llvm-bolt %t -o %t.bolt --strict | FileCheck %s
7+
8+
CHECK: rewriting .eh_frame in-place

clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace {
2020

2121
AST_MATCHER_P(FunctionDecl, isEnabled, llvm::StringSet<>,
2222
FunctionsThatShouldNotThrow) {
23-
return FunctionsThatShouldNotThrow.count(Node.getNameAsString()) > 0;
23+
return FunctionsThatShouldNotThrow.contains(Node.getNameAsString());
2424
}
2525

2626
AST_MATCHER(FunctionDecl, isExplicitThrow) {

clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ ExceptionAnalyzer::ExceptionInfo::filterIgnoredExceptions(
418418
if (TD->getDeclName().isIdentifier()) {
419419
if ((IgnoreBadAlloc &&
420420
(TD->getName() == "bad_alloc" && TD->isInStdNamespace())) ||
421-
(IgnoredTypes.count(TD->getName()) > 0))
421+
(IgnoredTypes.contains(TD->getName())))
422422
TypesToDelete.push_back(T);
423423
}
424424
}
@@ -449,7 +449,8 @@ void ExceptionAnalyzer::ExceptionInfo::reevaluateBehaviour() {
449449
ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::throwsException(
450450
const FunctionDecl *Func, const ExceptionInfo::Throwables &Caught,
451451
llvm::SmallSet<const FunctionDecl *, 32> &CallStack) {
452-
if (!Func || CallStack.count(Func) || (!CallStack.empty() && !canThrow(Func)))
452+
if (!Func || CallStack.contains(Func) ||
453+
(!CallStack.empty() && !canThrow(Func)))
453454
return ExceptionInfo::createNonThrowing();
454455

455456
if (const Stmt *Body = Func->getBody()) {
@@ -507,7 +508,7 @@ ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::throwsException(
507508
for (unsigned I = 0; I < Try->getNumHandlers(); ++I) {
508509
const CXXCatchStmt *Catch = Try->getHandler(I);
509510

510-
// Everything is catched through 'catch(...)'.
511+
// Everything is caught through 'catch(...)'.
511512
if (!Catch->getExceptionDecl()) {
512513
ExceptionInfo Rethrown = throwsException(
513514
Catch->getHandlerBlock(), Uncaught.getExceptionTypes(), CallStack);

clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class ExceptionAnalyzer {
101101
/// Recalculate the 'Behaviour' for example after filtering.
102102
void reevaluateBehaviour();
103103

104-
/// Keep track if the entity related to this 'ExceptionInfo' can in princple
105-
/// throw, if it's unknown or if it won't throw.
104+
/// Keep track if the entity related to this 'ExceptionInfo' can in
105+
/// principle throw, if it's unknown or if it won't throw.
106106
State Behaviour;
107107

108108
/// Keep track if the entity contains any unknown elements to keep track

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,35 @@ bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R,
511511
if (auto EditsNearCursor = Completion->getBoolean("editsNearCursor"))
512512
R.CompletionFixes |= *EditsNearCursor;
513513
}
514+
if (auto *References = TextDocument->getObject("references")) {
515+
if (auto ContainerSupport = References->getBoolean("container")) {
516+
R.ReferenceContainer |= *ContainerSupport;
517+
}
518+
}
519+
if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
520+
if (auto CodeActions = Diagnostics->getBoolean("codeActionsInline")) {
521+
R.DiagnosticFixes |= *CodeActions;
522+
}
523+
}
524+
if (auto *InactiveRegions =
525+
TextDocument->getObject("inactiveRegionsCapabilities")) {
526+
if (auto InactiveRegionsSupport =
527+
InactiveRegions->getBoolean("inactiveRegions")) {
528+
R.InactiveRegions |= *InactiveRegionsSupport;
529+
}
530+
}
531+
}
532+
if (auto *Window = Experimental->getObject("window")) {
533+
if (auto Implicit =
534+
Window->getBoolean("implicitWorkDoneProgressCreate")) {
535+
R.ImplicitProgressCreation |= *Implicit;
536+
}
537+
}
538+
if (auto *OffsetEncoding = Experimental->get("offsetEncoding")) {
539+
R.offsetEncoding.emplace();
540+
if (!fromJSON(*OffsetEncoding, *R.offsetEncoding,
541+
P.field("offsetEncoding")))
542+
return false;
514543
}
515544
}
516545

0 commit comments

Comments
 (0)