Skip to content

Commit 3dd54b8

Browse files
authored
Merge branch 'main' into sdag/arm/glue/vfp-cmp
2 parents d906394 + d0522f4 commit 3dd54b8

File tree

415 files changed

+5221
-3159
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

+5221
-3159
lines changed

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/BinaryEmitter.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,6 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
416416
BF.duplicateConstantIslands();
417417
}
418418

419-
if (!FF.empty() && FF.front()->isLandingPad()) {
420-
assert(!FF.front()->isEntryPoint() &&
421-
"Landing pad cannot be entry point of function");
422-
// If the first block of the fragment is a landing pad, it's offset from the
423-
// start of the area that the corresponding LSDA describes is zero. In this
424-
// case, the call site entries in that LSDA have 0 as offset to the landing
425-
// pad, which the runtime interprets as "no handler". To prevent this,
426-
// insert some padding.
427-
Streamer.emitBytes(BC.MIB->getTrapFillValue());
428-
}
429-
430419
// Track the first emitted instruction with debug info.
431420
bool FirstInstr = true;
432421
for (BinaryBasicBlock *const BB : FF) {
@@ -926,39 +915,54 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
926915
// Emit the LSDA header.
927916

928917
// If LPStart is omitted, then the start of the FDE is used as a base for
929-
// landing pad displacements. Then if a cold fragment starts with
930-
// a landing pad, this means that the first landing pad offset will be 0.
931-
// As a result, the exception handling runtime will ignore this landing pad
932-
// because zero offset denotes the absence of a landing pad.
933-
// For this reason, when the binary has fixed starting address we emit LPStart
934-
// as 0 and output the absolute value of the landing pad in the table.
918+
// landing pad displacements. Then, if a cold fragment starts with a landing
919+
// pad, this means that the first landing pad offset will be 0. However, C++
920+
// runtime treats 0 as if there is no landing pad present, thus we *must* emit
921+
// non-zero offsets for all valid LPs.
935922
//
936-
// If the base address can change, we cannot use absolute addresses for
937-
// landing pads (at least not without runtime relocations). Hence, we fall
938-
// back to emitting landing pads relative to the FDE start.
939-
// As we are emitting label differences, we have to guarantee both labels are
940-
// defined in the same section and hence cannot place the landing pad into a
941-
// cold fragment when the corresponding call site is in the hot fragment.
942-
// Because of this issue and the previously described issue of possible
943-
// zero-offset landing pad we have to place landing pads in the same section
944-
// as the corresponding invokes for shared objects.
923+
// As a solution, for fixed-address binaries we set LPStart to 0, and for
924+
// position-independent binaries we set LP start to FDE start minus one byte
925+
// for FDEs that start with a landing pad.
926+
const bool NeedsLPAdjustment = !FF.empty() && FF.front()->isLandingPad();
945927
std::function<void(const MCSymbol *)> emitLandingPad;
946928
if (BC.HasFixedLoadAddress) {
947929
Streamer.emitIntValue(dwarf::DW_EH_PE_udata4, 1); // LPStart format
948930
Streamer.emitIntValue(0, 4); // LPStart
949931
emitLandingPad = [&](const MCSymbol *LPSymbol) {
950-
if (!LPSymbol)
951-
Streamer.emitIntValue(0, 4);
952-
else
932+
if (LPSymbol)
953933
Streamer.emitSymbolValue(LPSymbol, 4);
934+
else
935+
Streamer.emitIntValue(0, 4);
954936
};
955937
} else {
956-
Streamer.emitIntValue(dwarf::DW_EH_PE_omit, 1); // LPStart format
938+
if (NeedsLPAdjustment) {
939+
// Use relative LPStart format and emit LPStart as [SymbolStart - 1].
940+
Streamer.emitIntValue(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4, 1);
941+
MCSymbol *DotSymbol = BC.Ctx->createTempSymbol("LPBase");
942+
Streamer.emitLabel(DotSymbol);
943+
944+
const MCExpr *LPStartExpr = MCBinaryExpr::createSub(
945+
MCSymbolRefExpr::create(StartSymbol, *BC.Ctx),
946+
MCSymbolRefExpr::create(DotSymbol, *BC.Ctx), *BC.Ctx);
947+
LPStartExpr = MCBinaryExpr::createSub(
948+
LPStartExpr, MCConstantExpr::create(1, *BC.Ctx), *BC.Ctx);
949+
Streamer.emitValue(LPStartExpr, 4);
950+
} else {
951+
// DW_EH_PE_omit means FDE start (StartSymbol) will be used as LPStart.
952+
Streamer.emitIntValue(dwarf::DW_EH_PE_omit, 1);
953+
}
957954
emitLandingPad = [&](const MCSymbol *LPSymbol) {
958-
if (!LPSymbol)
955+
if (LPSymbol) {
956+
const MCExpr *LPOffsetExpr = MCBinaryExpr::createSub(
957+
MCSymbolRefExpr::create(LPSymbol, *BC.Ctx),
958+
MCSymbolRefExpr::create(StartSymbol, *BC.Ctx), *BC.Ctx);
959+
if (NeedsLPAdjustment)
960+
LPOffsetExpr = MCBinaryExpr::createAdd(
961+
LPOffsetExpr, MCConstantExpr::create(1, *BC.Ctx), *BC.Ctx);
962+
Streamer.emitValue(LPOffsetExpr, 4);
963+
} else {
959964
Streamer.emitIntValue(0, 4);
960-
else
961-
Streamer.emitAbsoluteSymbolDiff(LPSymbol, StartSymbol, 4);
965+
}
962966
};
963967
}
964968

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: 45 additions & 11 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())

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/clangd/refactor/tweaks/DefineOutline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ getFunctionSourceCode(const FunctionDecl *FD, const DeclContext *TargetContext,
239239
return;
240240

241241
for (const NamedDecl *ND : Ref.Targets) {
242+
if (ND->getKind() == Decl::TemplateTypeParm)
243+
return;
242244
if (ND->getDeclContext() != Ref.Targets.front()->getDeclContext()) {
243245
elog("Targets from multiple contexts: {0}, {1}",
244246
printQualifiedName(*Ref.Targets.front()),

clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,29 +411,29 @@ inline typename O1<T, U...>::template O2<V, A>::E O1<T, U...>::template O2<V, A>
411411
R"cpp(
412412
struct Foo {
413413
template <typename T, bool B = true>
414-
void ^bar() {}
414+
T ^bar() { return {}; }
415415
};)cpp",
416416
R"cpp(
417417
struct Foo {
418418
template <typename T, bool B = true>
419-
void bar() ;
419+
T bar() ;
420420
};template <typename T, bool B>
421-
inline void Foo::bar() {}
421+
inline T Foo::bar() { return {}; }
422422
)cpp",
423423
""},
424424

425425
// Class template with member template
426426
{
427427
R"cpp(
428428
template <typename T> struct Foo {
429-
template <typename U> void ^bar(const T& t, const U& u) {}
429+
template <typename U> T ^bar(const T& t, const U& u) { return {}; }
430430
};)cpp",
431431
R"cpp(
432432
template <typename T> struct Foo {
433-
template <typename U> void bar(const T& t, const U& u) ;
433+
template <typename U> T bar(const T& t, const U& u) ;
434434
};template <typename T>
435435
template <typename U>
436-
inline void Foo<T>::bar(const T& t, const U& u) {}
436+
inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
437437
)cpp",
438438
""},
439439
};

clang/cmake/caches/CrossWinToARMLinux.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ if (NOT DEFINED CMAKE_BUILD_TYPE)
119119
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
120120
endif()
121121

122-
set(CMAKE_CROSSCOMPILING ON CACHE BOOL "")
123122
set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: " CACHE STRING "")
124123
# Required if COMPILER_RT_DEFAULT_TARGET_ONLY is ON
125124
set(CMAKE_C_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
@@ -219,6 +218,11 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI
219218
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
220219
# Merge libc++ and libc++abi libraries into the single libc++ library file.
221220
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
221+
# Forcely disable the libc++ benchmarks on Windows build hosts
222+
# (current benchmark test configuration does not support the cross builds there).
223+
if (WIN32)
224+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
225+
endif(WIN32)
222226

223227
# Avoid searching for the python3 interpreter during the runtimes configuration for the cross builds.
224228
# It starts searching the python3 package using the target's sysroot path, that usually is not compatible with the build host.

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ Non-comprehensive list of changes in this release
357357

358358
- ``__builtin_reduce_add`` function can now be used in constant expressions.
359359
- ``__builtin_reduce_mul`` function can now be used in constant expressions.
360+
- ``__builtin_reduce_and`` function can now be used in constant expressions.
360361

361362
New Compiler Flags
362363
------------------
@@ -556,6 +557,8 @@ Improvements to Clang's diagnostics
556557
getS(); // Now diagnoses "Reason 2", previously diagnoses "Reason 1"
557558
}
558559

560+
- Clang now diagnoses ``= delete("reason")`` extension warnings only in pedantic mode rather than on by default. (#GH109311).
561+
559562
Improvements to Clang's time-trace
560563
----------------------------------
561564

clang/docs/ThreadSafetyAnalysis.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -933,11 +933,25 @@ implementation.
933933
MutexLocker(Mutex *mu, defer_lock_t) EXCLUDES(mu) : mut(mu), locked(false) {}
934934
935935
// Same as constructors, but without tag types. (Requires C++17 copy elision.)
936-
static MutexLocker Lock(Mutex *mu) ACQUIRE(mu);
937-
static MutexLocker Adopt(Mutex *mu) REQUIRES(mu);
938-
static MutexLocker ReaderLock(Mutex *mu) ACQUIRE_SHARED(mu);
939-
static MutexLocker AdoptReaderLock(Mutex *mu) REQUIRES_SHARED(mu);
940-
static MutexLocker DeferLock(Mutex *mu) EXCLUDES(mu);
936+
static MutexLocker Lock(Mutex *mu) ACQUIRE(mu) {
937+
return MutexLocker(mu);
938+
}
939+
940+
static MutexLocker Adopt(Mutex *mu) REQUIRES(mu) {
941+
return MutexLocker(mu, adopt_lock);
942+
}
943+
944+
static MutexLocker ReaderLock(Mutex *mu) ACQUIRE_SHARED(mu) {
945+
return MutexLocker(mu, shared_lock);
946+
}
947+
948+
static MutexLocker AdoptReaderLock(Mutex *mu) REQUIRES_SHARED(mu) {
949+
return MutexLocker(mu, adopt_lock, shared_lock);
950+
}
951+
952+
static MutexLocker DeferLock(Mutex *mu) EXCLUDES(mu) {
953+
return MutexLocker(mu, defer_lock);
954+
}
941955
942956
// Release *this and all associated mutexes, if they are still held.
943957
// There is no warning if the scope was already unlocked before.

0 commit comments

Comments
 (0)