Skip to content

Commit 0a50892

Browse files
authored
Merge branch 'llvm:main' into main
2 parents 7f745f7 + 00d1966 commit 0a50892

File tree

1,425 files changed

+88503
-30877
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,425 files changed

+88503
-30877
lines changed

.github/workflows/repo-lockdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- 'clang/docs/**'
1515
- 'clang/unitests/Format/**'
1616
- 'clang/tools/clang-format/**'
17+
- 'llvm/utils/git/**'
1718

1819
permissions:
1920
pull-requests: write

bolt/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ foreach (tgt ${BOLT_TARGETS_TO_BUILD})
3232
endforeach()
3333

3434
set(BOLT_ENABLE_RUNTIME_default OFF)
35-
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
35+
if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
36+
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
3637
AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
37-
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
38-
AND "X86" IN_LIST BOLT_TARGETS_TO_BUILD)
38+
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
3939
set(BOLT_ENABLE_RUNTIME_default ON)
4040
endif()
4141
option(BOLT_ENABLE_RUNTIME "Enable BOLT runtime" ${BOLT_ENABLE_RUNTIME_default})

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ class MCPlusBuilder {
498498
}
499499

500500
/// Create increment contents of target by 1 for Instrumentation
501-
virtual InstructionListType createInstrIncMemory(const MCSymbol *Target,
502-
MCContext *Ctx,
503-
bool IsLeaf) const {
501+
virtual InstructionListType
502+
createInstrIncMemory(const MCSymbol *Target, MCContext *Ctx, bool IsLeaf,
503+
unsigned CodePointerSize) const {
504504
llvm_unreachable("not implemented");
505505
return InstructionListType();
506506
}
@@ -639,9 +639,12 @@ class MCPlusBuilder {
639639
return false;
640640
}
641641

642-
/// If non-zero, this is used to fill the executable space with instructions
643-
/// that will trap. Defaults to 0.
644-
virtual unsigned getTrapFillValue() const { return 0; }
642+
/// Used to fill the executable space with instructions
643+
/// that will trap.
644+
virtual StringRef getTrapFillValue() const {
645+
llvm_unreachable("not implemented");
646+
return StringRef();
647+
}
645648

646649
/// Interface and basic functionality of a MCInstMatcher. The idea is to make
647650
/// it easy to match one or more MCInsts against a tree-like pattern and
@@ -1597,16 +1600,9 @@ class MCPlusBuilder {
15971600
return false;
15981601
}
15991602

1600-
virtual void createLoadImmediate(MCInst &Inst, const MCPhysReg Dest,
1601-
uint32_t Imm) const {
1602-
llvm_unreachable("not implemented");
1603-
}
1604-
1605-
/// Create instruction to increment contents of target by 1
1606-
virtual bool createIncMemory(MCInst &Inst, const MCSymbol *Target,
1607-
MCContext *Ctx) const {
1603+
virtual InstructionListType createLoadImmediate(const MCPhysReg Dest,
1604+
uint64_t Imm) const {
16081605
llvm_unreachable("not implemented");
1609-
return false;
16101606
}
16111607

16121608
/// Create a fragment of code (sequence of instructions) that load a 32-bit
@@ -1737,6 +1733,48 @@ class MCPlusBuilder {
17371733
return true;
17381734
}
17391735

1736+
/// Extract a symbol and an addend out of the fixup value expression.
1737+
///
1738+
/// Only the following limited expression types are supported:
1739+
/// Symbol + Addend
1740+
/// Symbol + Constant + Addend
1741+
/// Const + Addend
1742+
/// Symbol
1743+
std::pair<MCSymbol *, uint64_t> extractFixupExpr(const MCFixup &Fixup) const {
1744+
uint64_t Addend = 0;
1745+
MCSymbol *Symbol = nullptr;
1746+
const MCExpr *ValueExpr = Fixup.getValue();
1747+
if (ValueExpr->getKind() == MCExpr::Binary) {
1748+
const auto *BinaryExpr = cast<MCBinaryExpr>(ValueExpr);
1749+
assert(BinaryExpr->getOpcode() == MCBinaryExpr::Add &&
1750+
"unexpected binary expression");
1751+
const MCExpr *LHS = BinaryExpr->getLHS();
1752+
if (LHS->getKind() == MCExpr::Constant) {
1753+
Addend = cast<MCConstantExpr>(LHS)->getValue();
1754+
} else if (LHS->getKind() == MCExpr::Binary) {
1755+
const auto *LHSBinaryExpr = cast<MCBinaryExpr>(LHS);
1756+
assert(LHSBinaryExpr->getOpcode() == MCBinaryExpr::Add &&
1757+
"unexpected binary expression");
1758+
const MCExpr *LLHS = LHSBinaryExpr->getLHS();
1759+
assert(LLHS->getKind() == MCExpr::SymbolRef && "unexpected LLHS");
1760+
Symbol = const_cast<MCSymbol *>(this->getTargetSymbol(LLHS));
1761+
const MCExpr *RLHS = LHSBinaryExpr->getRHS();
1762+
assert(RLHS->getKind() == MCExpr::Constant && "unexpected RLHS");
1763+
Addend = cast<MCConstantExpr>(RLHS)->getValue();
1764+
} else {
1765+
assert(LHS->getKind() == MCExpr::SymbolRef && "unexpected LHS");
1766+
Symbol = const_cast<MCSymbol *>(this->getTargetSymbol(LHS));
1767+
}
1768+
const MCExpr *RHS = BinaryExpr->getRHS();
1769+
assert(RHS->getKind() == MCExpr::Constant && "unexpected RHS");
1770+
Addend += cast<MCConstantExpr>(RHS)->getValue();
1771+
} else {
1772+
assert(ValueExpr->getKind() == MCExpr::SymbolRef && "unexpected value");
1773+
Symbol = const_cast<MCSymbol *>(this->getTargetSymbol(ValueExpr));
1774+
}
1775+
return std::make_pair(Symbol, Addend);
1776+
}
1777+
17401778
/// Return annotation index matching the \p Name.
17411779
std::optional<unsigned> getAnnotationIndex(StringRef Name) const {
17421780
auto AI = AnnotationNameIndexMap.find(Name);
@@ -1969,7 +2007,7 @@ class MCPlusBuilder {
19692007
}
19702008

19712009
virtual InstructionListType createSymbolTrampoline(const MCSymbol *TgtSym,
1972-
MCContext *Ctx) const {
2010+
MCContext *Ctx) {
19732011
llvm_unreachable("not implemented");
19742012
return InstructionListType();
19752013
}

bolt/lib/Core/AddressMap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ AddressMap AddressMap::parse(StringRef Buffer, const BinaryContext &BC) {
5252
while (Cursor && !DE.eof(Cursor)) {
5353
const auto Input = DE.getAddress(Cursor);
5454
const auto Output = DE.getAddress(Cursor);
55-
Parsed.Map.insert({Input, Output});
55+
if (!Parsed.Map.count(Input))
56+
Parsed.Map.insert({Input, Output});
5657
}
5758

5859
assert(Cursor && "Error reading address map section");

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
380380
}
381381

382382
if (opts::MarkFuncs)
383-
Streamer.emitIntValue(BC.MIB->getTrapFillValue(), 1);
383+
Streamer.emitBytes(BC.MIB->getTrapFillValue());
384384

385385
// Emit CFI end
386386
if (Function.hasCFI())
@@ -424,7 +424,7 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
424424
// case, the call site entries in that LSDA have 0 as offset to the landing
425425
// pad, which the runtime interprets as "no handler". To prevent this,
426426
// insert some padding.
427-
Streamer.emitIntValue(BC.MIB->getTrapFillValue(), 1);
427+
Streamer.emitBytes(BC.MIB->getTrapFillValue());
428428
}
429429

430430
// Track the first emitted instruction with debug info.

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,8 +4129,14 @@ void BinaryFunction::updateOutputValues(const MCAsmLayout &Layout) {
41294129
(void)FragmentBaseAddress;
41304130
}
41314131

4132-
const uint64_t BBAddress =
4133-
*BC.getIOAddressMap().lookup(BB->getInputOffset() + getAddress());
4132+
// Injected functions likely will fail lookup, as they have no
4133+
// input range. Just assign the BB the output address of the
4134+
// function.
4135+
auto MaybeBBAddress =
4136+
BC.getIOAddressMap().lookup(BB->getInputOffset() + getAddress());
4137+
const uint64_t BBAddress = MaybeBBAddress ? *MaybeBBAddress
4138+
: BB->isSplit() ? FF.getAddress()
4139+
: getOutputAddress();
41344140
BB->setOutputStartAddress(BBAddress);
41354141

41364142
if (PrevBB)

bolt/lib/Core/Relocation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@ static uint64_t encodeValueAArch64(uint64_t Type, uint64_t Value, uint64_t PC) {
345345
case ELF::R_AARCH64_PREL64:
346346
Value -= PC;
347347
break;
348+
case ELF::R_AARCH64_CALL26:
349+
Value -= PC;
350+
assert(isInt<28>(Value) && "only PC +/- 128MB is allowed for direct call");
351+
// Immediate goes in bits 25:0 of BL.
352+
// OP 1001_01 goes in bits 31:26 of BL.
353+
Value = (Value >> 2) | 0x94000000ULL;
354+
break;
348355
}
349356
return Value;
350357
}

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ Instrumentation::createInstrumentationSnippet(BinaryContext &BC, bool IsLeaf) {
176176
auto L = BC.scopeLock();
177177
MCSymbol *Label = BC.Ctx->createNamedTempSymbol("InstrEntry");
178178
Summary->Counters.emplace_back(Label);
179-
return BC.MIB->createInstrIncMemory(Label, BC.Ctx.get(), IsLeaf);
179+
return BC.MIB->createInstrIncMemory(Label, BC.Ctx.get(), IsLeaf,
180+
BC.AsmInfo->getCodePointerSize());
180181
}
181182

182183
// Helper instruction sequence insertion function
@@ -504,9 +505,6 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
504505
}
505506

506507
void Instrumentation::runOnFunctions(BinaryContext &BC) {
507-
if (!BC.isX86())
508-
return;
509-
510508
const unsigned Flags = BinarySection::getFlags(/*IsReadOnly=*/false,
511509
/*IsText=*/false,
512510
/*IsAllocatable=*/true);

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ void DWARFRewriter::convertToRangesPatchDebugInfo(
21932193
if (Unit.getVersion() >= 5)
21942194
RangeAttrVal = RangesSectionOffset;
21952195
// HighPC was conveted into DW_AT_ranges.
2196-
// For DWARF5 we only access ranges throught index.
2196+
// For DWARF5 we only access ranges through index.
21972197

21982198
DIEBldr.replaceValue(&Die, HighPCAttrInfo.getAttribute(), dwarf::DW_AT_ranges,
21992199
RangesForm, DIEInteger(RangeAttrVal));

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,8 +1845,9 @@ void RewriteInstance::adjustCommandLineOptions() {
18451845
exit(1);
18461846
}
18471847

1848-
if (opts::ReorderFunctions != ReorderFunctions::RT_NONE &&
1849-
!opts::HotText.getNumOccurrences()) {
1848+
if (opts::Instrument ||
1849+
(opts::ReorderFunctions != ReorderFunctions::RT_NONE &&
1850+
!opts::HotText.getNumOccurrences())) {
18501851
opts::HotText = true;
18511852
} else if (opts::HotText && !BC->HasRelocations) {
18521853
errs() << "BOLT-WARNING: hot text is disabled in non-relocation mode\n";
@@ -5285,8 +5286,10 @@ void RewriteInstance::rewriteFile() {
52855286
if (!BF.getFileOffset() || !BF.isEmitted())
52865287
continue;
52875288
OS.seek(BF.getFileOffset());
5288-
for (unsigned I = 0; I < BF.getMaxSize(); ++I)
5289-
OS.write((unsigned char)BC->MIB->getTrapFillValue());
5289+
StringRef TrapInstr = BC->MIB->getTrapFillValue();
5290+
unsigned NInstr = BF.getMaxSize() / TrapInstr.size();
5291+
for (unsigned I = 0; I < NInstr; ++I)
5292+
OS.write(TrapInstr.data(), TrapInstr.size());
52905293
}
52915294
OS.seek(SavedPos);
52925295
}

0 commit comments

Comments
 (0)