Skip to content

Commit 2a500dd

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-all-regions-as-transform
2 parents 29f6ddf + 1657331 commit 2a500dd

File tree

431 files changed

+6685
-3516
lines changed

Some content is hidden

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

431 files changed

+6685
-3516
lines changed

.ci/monolithic-linux.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ targets="${2}"
5353
lit_args="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml --use-unique-output-file-name --timeout=1200 --time-tests"
5454

5555
echo "--- cmake"
56-
pip install -q -r "${MONOREPO_ROOT}"/mlir/python/requirements.txt
57-
pip install -q -r "${MONOREPO_ROOT}"/lldb/test/requirements.txt
58-
pip install -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
56+
pip install --break-system-packages -q -r "${MONOREPO_ROOT}"/mlir/python/requirements.txt
57+
pip install --break-system-packages -q -r "${MONOREPO_ROOT}"/lldb/test/requirements.txt
58+
pip install --break-system-packages -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
5959
cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
6060
-D LLVM_ENABLE_PROJECTS="${projects}" \
6161
-G Ninja \

.github/workflows/containers/github-action-ci-windows/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ RUN choco install -y handle
108108
109109
RUN pip3 install pywin32 buildbot-worker==2.8.4
110110
111-
ARG RUNNER_VERSION=2.322.0
111+
ARG RUNNER_VERSION=2.323.0
112112
ENV RUNNER_VERSION=$RUNNER_VERSION
113113
114114
RUN powershell -Command \

.github/workflows/containers/github-action-ci/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ WORKDIR /home/gha
9595

9696
FROM ci-container as ci-container-agent
9797

98-
ENV GITHUB_RUNNER_VERSION=2.322.0
98+
ENV GITHUB_RUNNER_VERSION=2.323.0
9999

100100
RUN mkdir actions-runner && \
101101
cd actions-runner && \

bolt/include/bolt/Core/Relocation.h

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ class Relocation {
8686
/// Adjust value depending on relocation type (make it PC relative or not).
8787
static uint64_t encodeValue(uint32_t Type, uint64_t Value, uint64_t PC);
8888

89+
/// Return true if there are enough bits to encode the relocation value.
90+
static bool canEncodeValue(uint32_t Type, uint64_t Value, uint64_t PC);
91+
8992
/// Extract current relocated value from binary contents. This is used for
9093
/// RISC architectures where values are encoded in specific bits depending
9194
/// on the relocation value. For X86, we limit to sign extending the value

bolt/lib/Core/BinaryFunction.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,8 @@ bool BinaryFunction::scanExternalRefs() {
17951795
// Create relocation for every fixup.
17961796
for (const MCFixup &Fixup : Fixups) {
17971797
std::optional<Relocation> Rel = BC.MIB->createRelocation(Fixup, *BC.MAB);
1798+
// Can be skipped in case of overlow during relocation value encoding.
1799+
Rel->setOptional();
17981800
if (!Rel) {
17991801
Success = false;
18001802
continue;

bolt/lib/Core/BinarySection.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "bolt/Core/BinarySection.h"
1414
#include "bolt/Core/BinaryContext.h"
15+
#include "bolt/Utils/CommandLineOpts.h"
1516
#include "bolt/Utils/Utils.h"
1617
#include "llvm/MC/MCStreamer.h"
1718
#include "llvm/Support/CommandLine.h"
@@ -22,8 +23,8 @@ using namespace llvm;
2223
using namespace bolt;
2324

2425
namespace opts {
25-
extern cl::opt<bool> PrintRelocations;
2626
extern cl::opt<bool> HotData;
27+
extern cl::opt<bool> PrintRelocations;
2728
} // namespace opts
2829

2930
uint64_t BinarySection::Count = 0;
@@ -174,11 +175,30 @@ void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS,
174175
OS.pwrite(Patch.Bytes.data(), Patch.Bytes.size(),
175176
SectionFileOffset + Patch.Offset);
176177

178+
uint64_t SkippedPendingRelocations = 0;
177179
for (Relocation &Reloc : PendingRelocations) {
178180
uint64_t Value = Reloc.Addend;
179181
if (Reloc.Symbol)
180182
Value += Resolver(Reloc.Symbol);
181183

184+
// Safely skip any optional pending relocation that cannot be encoded.
185+
if (Reloc.isOptional() &&
186+
!Relocation::canEncodeValue(Reloc.Type, Value,
187+
SectionAddress + Reloc.Offset)) {
188+
189+
// A successful run of 'scanExternalRefs' means that all pending
190+
// relocations are flushed. Otherwise, PatchEntries should run.
191+
if (!opts::ForcePatch) {
192+
BC.errs()
193+
<< "BOLT-ERROR: cannot encode relocation for symbol "
194+
<< Reloc.Symbol->getName()
195+
<< " as it is out-of-range. To proceed must use -force-patch\n";
196+
exit(1);
197+
}
198+
199+
++SkippedPendingRelocations;
200+
continue;
201+
}
182202
Value = Relocation::encodeValue(Reloc.Type, Value,
183203
SectionAddress + Reloc.Offset);
184204

@@ -197,6 +217,11 @@ void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS,
197217
}
198218

199219
clearList(PendingRelocations);
220+
221+
if (SkippedPendingRelocations > 0 && opts::Verbosity >= 1) {
222+
BC.outs() << "BOLT-INFO: skipped " << SkippedPendingRelocations
223+
<< " out-of-range optional relocations\n";
224+
}
200225
}
201226

202227
BinarySection::~BinarySection() { updateContents(nullptr, 0); }

bolt/lib/Core/Relocation.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ static uint64_t encodeValueX86(uint32_t Type, uint64_t Value, uint64_t PC) {
271271
return Value;
272272
}
273273

274+
static bool canEncodeValueAArch64(uint32_t Type, uint64_t Value, uint64_t PC) {
275+
switch (Type) {
276+
default:
277+
llvm_unreachable("unsupported relocation");
278+
case ELF::R_AARCH64_CALL26:
279+
case ELF::R_AARCH64_JUMP26:
280+
return isInt<28>(Value - PC);
281+
}
282+
}
283+
274284
static uint64_t encodeValueAArch64(uint32_t Type, uint64_t Value, uint64_t PC) {
275285
switch (Type) {
276286
default:
@@ -303,6 +313,16 @@ static uint64_t encodeValueAArch64(uint32_t Type, uint64_t Value, uint64_t PC) {
303313
return Value;
304314
}
305315

316+
static uint64_t canEncodeValueRISCV(uint32_t Type, uint64_t Value,
317+
uint64_t PC) {
318+
switch (Type) {
319+
default:
320+
llvm_unreachable("unsupported relocation");
321+
case ELF::R_RISCV_64:
322+
return true;
323+
}
324+
}
325+
306326
static uint64_t encodeValueRISCV(uint32_t Type, uint64_t Value, uint64_t PC) {
307327
switch (Type) {
308328
default:
@@ -739,6 +759,19 @@ uint64_t Relocation::encodeValue(uint32_t Type, uint64_t Value, uint64_t PC) {
739759
}
740760
}
741761

762+
bool Relocation::canEncodeValue(uint32_t Type, uint64_t Value, uint64_t PC) {
763+
switch (Arch) {
764+
default:
765+
llvm_unreachable("Unsupported architecture");
766+
case Triple::aarch64:
767+
return canEncodeValueAArch64(Type, Value, PC);
768+
case Triple::riscv64:
769+
return canEncodeValueRISCV(Type, Value, PC);
770+
case Triple::x86_64:
771+
return true;
772+
}
773+
}
774+
742775
uint64_t Relocation::extractValue(uint32_t Type, uint64_t Contents,
743776
uint64_t PC) {
744777
switch (Arch) {

bolt/lib/Rewrite/RewriteInstance.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -2827,9 +2827,10 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
28272827
if (SymbolAddress == 0)
28282828
ReferencedSymbol = BC->registerNameAtAddress(SymbolName, 0, 0, 0);
28292829

2830-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: forcing relocation against symbol "
2831-
<< ReferencedSymbol->getName() << " with addend "
2832-
<< Addend << '\n');
2830+
LLVM_DEBUG(
2831+
dbgs() << "BOLT-DEBUG: forcing relocation against symbol "
2832+
<< (ReferencedSymbol ? ReferencedSymbol->getName() : "<none>")
2833+
<< " with addend " << Addend << '\n');
28332834
} else if (ReferencedBF) {
28342835
ReferencedSymbol = ReferencedBF->getSymbol();
28352836
uint64_t RefFunctionOffset = 0;

bolt/lib/Target/AArch64/AArch64MCSymbolizer.cpp

+24-11
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,39 @@ AArch64MCSymbolizer::adjustRelocation(const Relocation &Rel,
119119
// The ADRP+LDR sequence was converted into ADRP+ADD. We are looking at the
120120
// second instruction and have to use the relocation type for ADD.
121121
AdjustedRel.Type = ELF::R_AARCH64_ADD_ABS_LO12_NC;
122-
} else {
123-
// For instructions that reference GOT, ignore the referenced symbol and
124-
// use value at the relocation site. FixRelaxationPass will look at
125-
// instruction pairs and will perform necessary adjustments.
122+
return AdjustedRel;
123+
}
124+
125+
// ADRP is a special case since the linker can leave the instruction opcode
126+
// intact and modify only the operand. We are doing our best to detect when
127+
// such conversion has happened without looking at the next instruction.
128+
//
129+
// If we detect that a page referenced by the ADRP cannot belong to GOT, and
130+
// that it matches the symbol from the relocation, then we can be certain
131+
// that the linker converted the GOT reference into the local one. Otherwise,
132+
// we leave the disambiguation resolution to FixRelaxationPass.
133+
//
134+
// Note that ADRP relaxation described above cannot happen for TLS relocation.
135+
// Since TLS relocations may not even have a valid symbol (not supported by
136+
// BOLT), we explicitly exclude them from the check.
137+
if (BC.MIB->isADRP(Inst) && Rel.Addend == 0 && !Relocation::isTLS(Rel.Type)) {
126138
ErrorOr<uint64_t> SymbolValue = BC.getSymbolValue(*Rel.Symbol);
127139
assert(SymbolValue && "Symbol value should be set");
128140
const uint64_t SymbolPageAddr = *SymbolValue & ~0xfffULL;
129141

130-
// Check if defined symbol and GOT are on the same page. If they are not,
131-
// disambiguate the operand.
132-
if (BC.MIB->isADRP(Inst) && Rel.Addend == 0 &&
133-
SymbolPageAddr == Rel.Value &&
142+
if (SymbolPageAddr == Rel.Value &&
134143
!isPageAddressValidForGOT(SymbolPageAddr)) {
135144
AdjustedRel.Type = ELF::R_AARCH64_ADR_PREL_PG_HI21;
136-
} else {
137-
AdjustedRel.Symbol = BC.registerNameAtAddress("__BOLT_got_zero", 0, 0, 0);
138-
AdjustedRel.Addend = Rel.Value;
145+
return AdjustedRel;
139146
}
140147
}
141148

149+
// For instructions that reference GOT, ignore the referenced symbol and
150+
// use value at the relocation site. FixRelaxationPass will look at
151+
// instruction pairs and will perform necessary adjustments.
152+
AdjustedRel.Symbol = BC.registerNameAtAddress("__BOLT_got_zero", 0, 0, 0);
153+
AdjustedRel.Addend = Rel.Value;
154+
142155
return AdjustedRel;
143156
}
144157

bolt/test/AArch64/tls.c

+8
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ int main() {
3434
// RUN: -target aarch64-linux -fuse-ld=lld \
3535
// RUN: -nostdlib
3636
// RUN: llvm-bolt %t_pie.exe -o %t.bolt
37+
38+
// RUN: %clang %cflags -fPIC -shared %s -o %t.so -Wl,-q -fuse-ld=lld
39+
// RUN: llvm-objdump -d -r --disassemble-symbols=main %t.so | FileCheck %s
40+
// RUN: llvm-bolt %t.so -o %t.bolt.so
41+
42+
// Verify that unoptimized TLS access was generated for shared object.
43+
// CHECK: adrp x0
44+
// CHECK-NEXT: R_AARCH64_TLSDESC_ADR_PAGE21 tbssstruct

bolt/unittests/Core/BinaryContext.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "bolt/Core/BinaryContext.h"
10+
#include "bolt/Utils/CommandLineOpts.h"
1011
#include "llvm/BinaryFormat/ELF.h"
1112
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1213
#include "llvm/Support/TargetSelect.h"
@@ -161,6 +162,67 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
161162
<< "Wrong forward branch value\n";
162163
}
163164

165+
TEST_P(BinaryContextTester,
166+
FlushOptionalOutOfRangePendingRelocCALL26_ForcePatchOff) {
167+
if (GetParam() != Triple::aarch64)
168+
GTEST_SKIP();
169+
170+
// Tests that flushPendingRelocations exits if any pending relocation is out
171+
// of range and PatchEntries hasn't run. Pending relocations are added by
172+
// scanExternalRefs, so this ensures that either all scanExternalRefs
173+
// relocations were flushed or PatchEntries ran.
174+
175+
BinarySection &BS = BC->registerOrUpdateSection(
176+
".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
177+
// Create symbol 'Func0x4'
178+
MCSymbol *RelSymbol = BC->getOrCreateGlobalSymbol(4, "Func");
179+
ASSERT_TRUE(RelSymbol);
180+
Relocation Reloc{8, RelSymbol, ELF::R_AARCH64_CALL26, 0, 0};
181+
Reloc.setOptional();
182+
BS.addPendingRelocation(Reloc);
183+
184+
SmallVector<char> Vect;
185+
raw_svector_ostream OS(Vect);
186+
187+
// Resolve relocation symbol to a high value so encoding will be out of range.
188+
EXPECT_EXIT(BS.flushPendingRelocations(
189+
OS, [&](const MCSymbol *S) { return 0x800000F; }),
190+
::testing::ExitedWithCode(1),
191+
"BOLT-ERROR: cannot encode relocation for symbol Func0x4 as it is"
192+
" out-of-range. To proceed must use -force-patch");
193+
}
194+
195+
TEST_P(BinaryContextTester,
196+
FlushOptionalOutOfRangePendingRelocCALL26_ForcePatchOn) {
197+
if (GetParam() != Triple::aarch64)
198+
GTEST_SKIP();
199+
200+
// Tests that flushPendingRelocations can skip flushing any optional pending
201+
// relocations that cannot be encoded, given that PatchEntries runs.
202+
opts::ForcePatch = true;
203+
204+
opts::Verbosity = 1;
205+
testing::internal::CaptureStdout();
206+
207+
BinarySection &BS = BC->registerOrUpdateSection(
208+
".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
209+
MCSymbol *RelSymbol = BC->getOrCreateGlobalSymbol(4, "Func");
210+
ASSERT_TRUE(RelSymbol);
211+
Relocation Reloc{8, RelSymbol, ELF::R_AARCH64_CALL26, 0, 0};
212+
Reloc.setOptional();
213+
BS.addPendingRelocation(Reloc);
214+
215+
SmallVector<char> Vect;
216+
raw_svector_ostream OS(Vect);
217+
218+
// Resolve relocation symbol to a high value so encoding will be out of range.
219+
BS.flushPendingRelocations(OS, [&](const MCSymbol *S) { return 0x800000F; });
220+
outs().flush();
221+
std::string CapturedStdOut = testing::internal::GetCapturedStdout();
222+
EXPECT_EQ(CapturedStdOut,
223+
"BOLT-INFO: skipped 1 out-of-range optional relocations\n");
224+
}
225+
164226
#endif
165227

166228
TEST_P(BinaryContextTester, BaseAddress) {

bolt/unittests/Core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ target_link_libraries(CoreTests
1919
LLVMBOLTCore
2020
LLVMBOLTRewrite
2121
LLVMBOLTProfile
22+
LLVMBOLTUtils
2223
LLVMTestingSupport
2324
)
2425

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,14 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
8989
HeaderInfo = std::make_unique<HeaderSearch>(HSOpts, Sources, Diags, LangOpts,
9090
&Compiler.getTarget());
9191

92-
auto PO = std::make_shared<PreprocessorOptions>();
93-
*PO = Compiler.getPreprocessorOpts();
94-
95-
PP = std::make_unique<clang::Preprocessor>(PO, Diags, LangOpts, Sources,
96-
*HeaderInfo, ModuleLoader,
97-
/*IILookup=*/nullptr,
98-
/*OwnsHeaderSearch=*/false);
92+
PP = std::make_unique<clang::Preprocessor>(Compiler.getPreprocessorOpts(),
93+
Diags, LangOpts, Sources,
94+
*HeaderInfo, ModuleLoader,
95+
/*IILookup=*/nullptr,
96+
/*OwnsHeaderSearch=*/false);
9997
PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
100-
InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
98+
InitializePreprocessor(*PP, Compiler.getPreprocessorOpts(),
99+
Compiler.getPCHContainerReader(),
101100
Compiler.getFrontendOpts(), Compiler.getCodeGenOpts());
102101
ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
103102
Compiler.getTarget().getTriple());

clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -927,18 +927,6 @@ static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp,
927927
if (Lil && Ril)
928928
return Lil->getValue() == Ril->getValue();
929929

930-
const auto *LStrl = dyn_cast<StringLiteral>(Lhs);
931-
const auto *RStrl = dyn_cast<StringLiteral>(Rhs);
932-
if (Lil && Ril) {
933-
const llvm::StringRef L = Lexer::getSourceText(
934-
CharSourceRange::getTokenRange(LStrl->getBeginLoc()), SM,
935-
Context->getLangOpts(), 0);
936-
const llvm::StringRef R = Lexer::getSourceText(
937-
CharSourceRange::getTokenRange(RStrl->getBeginLoc()), SM,
938-
Context->getLangOpts(), 0);
939-
return L.compare(R) == 0;
940-
}
941-
942930
const auto *Lbl = dyn_cast<CXXBoolLiteralExpr>(Lhs);
943931
const auto *Rbl = dyn_cast<CXXBoolLiteralExpr>(Rhs);
944932
if (Lbl && Rbl)

clang-tools-extra/clangd/ModulesBuilder.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
202202
HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts,
203203
/*Target=*/nullptr);
204204

205+
PreprocessorOptions PPOpts;
205206
TrivialModuleLoader ModuleLoader;
206-
Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts,
207-
SourceMgr, HeaderInfo, ModuleLoader);
207+
Preprocessor PP(PPOpts, *Diags, LangOpts, SourceMgr, HeaderInfo,
208+
ModuleLoader);
208209

209210
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
210211
PCHContainerOperations PCHOperations;

0 commit comments

Comments
 (0)