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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 26 additions & 1 deletion
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

Lines changed: 33 additions & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 24 additions & 11 deletions
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

Lines changed: 8 additions & 0 deletions
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

0 commit comments

Comments
 (0)