Skip to content

Commit cbcd010

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW40)
LLVM: llvm/llvm-project@c72d3a0966af SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@deb6ee9
2 parents 8e2d345 + 1cf5302 commit cbcd010

File tree

1,719 files changed

+55376
-20618
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,719 files changed

+55376
-20618
lines changed

.github/new-issues-labeler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
'libc++':
1111
- '/libc[+x]{2}(?!\-)/i'
1212

13-
'libc++-abi':
14-
- '/libc[+x]{2}-abi/i'
13+
'libc++abi':
14+
- '/libc[+x]{2}-?abi/i'
1515

1616
'libc':
1717
- '/\blibc(?![-+])\b/i'

.github/new-prs-labeler.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ tools:llvm-mca:
309309
- llvm/include/llvm/MCA/**
310310
- llvm/lib/MCA/**
311311

312-
vectorizers:
313-
- llvm/lib/Transforms/Vectorize/**
314-
- llvm/include/llvm/Transforms/Vectorize/**
315-
316312
clang:
317313
- any:
318314
- clang/**

.github/workflows/llvm-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,17 @@ jobs:
170170
uses: actions/download-artifact@v3
171171
with:
172172
name: build-baseline
173+
path: build-baseline
173174
- name: Download latest
174175
uses: actions/download-artifact@v3
175176
with:
176177
name: build-latest
178+
path: build-latest
177179
- name: Download symbol list
178180
uses: actions/download-artifact@v3
179181
with:
180182
name: symbol-list
183+
path: symbol-list
181184

182185
- name: Install abi-compliance-checker
183186
run: sudo apt-get install abi-compliance-checker

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
matrix:
6969
target:
7070
- triple: x86_64-linux-gnu-ubuntu-22.04
71-
runs-on: ubuntu-22.04-8x32
71+
runs-on: ubuntu-22.04-16x64
7272
debian-build-deps: >
7373
chrpath
7474
gcc-multilib

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,15 @@ class BinaryContext {
871871
return nullptr;
872872
}
873873

874+
/// Retrieves a reference to ELF's _GLOBAL_OFFSET_TABLE_ symbol, which points
875+
/// at GOT, or null if it is not present in the input binary symtab.
876+
BinaryData *getGOTSymbol();
877+
878+
/// Checks if symbol name refers to ELF's _GLOBAL_OFFSET_TABLE_ symbol
879+
bool isGOTSymbol(StringRef SymName) const {
880+
return SymName == "_GLOBAL_OFFSET_TABLE_";
881+
}
882+
874883
/// Return true if \p SymbolName was generated internally and was not present
875884
/// in the input binary.
876885
bool isInternalSymbolName(const StringRef Name) {

bolt/include/bolt/Core/Relocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct Relocation {
8484

8585
/// Special relocation type that allows the linker to modify the instruction.
8686
static bool isX86GOTPCRELX(uint64_t Type);
87+
static bool isX86GOTPC64(uint64_t Type);
8788

8889
/// Return true if relocation type is NONE
8990
static bool isNone(uint64_t Type);

bolt/lib/Core/BinaryContext.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,31 @@ BinaryContext::getBinaryDataContainingAddressImpl(uint64_t Address) const {
10261026
return nullptr;
10271027
}
10281028

1029+
BinaryData *BinaryContext::getGOTSymbol() {
1030+
// First tries to find a global symbol with that name
1031+
BinaryData *GOTSymBD = getBinaryDataByName("_GLOBAL_OFFSET_TABLE_");
1032+
if (GOTSymBD)
1033+
return GOTSymBD;
1034+
1035+
// This symbol might be hidden from run-time link, so fetch the local
1036+
// definition if available.
1037+
GOTSymBD = getBinaryDataByName("_GLOBAL_OFFSET_TABLE_/1");
1038+
if (!GOTSymBD)
1039+
return nullptr;
1040+
1041+
// If the local symbol is not unique, fail
1042+
unsigned Index = 2;
1043+
SmallString<30> Storage;
1044+
while (const BinaryData *BD =
1045+
getBinaryDataByName(Twine("_GLOBAL_OFFSET_TABLE_/")
1046+
.concat(Twine(Index++))
1047+
.toStringRef(Storage)))
1048+
if (BD->getAddress() != GOTSymBD->getAddress())
1049+
return nullptr;
1050+
1051+
return GOTSymBD;
1052+
}
1053+
10291054
bool BinaryContext::setBinaryDataSize(uint64_t Address, uint64_t Size) {
10301055
auto NI = BinaryDataMap.find(Address);
10311056
assert(NI != BinaryDataMap.end());

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,8 @@ bool BinaryFunction::postProcessIndirectBranches(
17611761
uint64_t LastJT = 0;
17621762
uint16_t LastJTIndexReg = BC.MIB->getNoRegister();
17631763
for (BinaryBasicBlock &BB : blocks()) {
1764-
for (MCInst &Instr : BB) {
1764+
for (BinaryBasicBlock::iterator II = BB.begin(); II != BB.end(); ++II) {
1765+
MCInst &Instr = *II;
17651766
if (!BC.MIB->isIndirectBranch(Instr))
17661767
continue;
17671768

@@ -1789,7 +1790,7 @@ bool BinaryFunction::postProcessIndirectBranches(
17891790
const MCExpr *DispExpr;
17901791
MCInst *PCRelBaseInstr;
17911792
IndirectBranchType Type = BC.MIB->analyzeIndirectBranch(
1792-
Instr, BB.begin(), BB.end(), PtrSize, MemLocInstr, BaseRegNum,
1793+
Instr, BB.begin(), II, PtrSize, MemLocInstr, BaseRegNum,
17931794
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr);
17941795
if (Type != IndirectBranchType::UNKNOWN || MemLocInstr != nullptr)
17951796
continue;

bolt/lib/Core/DebugData.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ void DebugAddrWriterDwarf5::update(DIEBuilder &DIEBlder, DWARFUnit &CU) {
495495
const endianness Endian =
496496
BC->DwCtx->isLittleEndian() ? support::little : support::big;
497497
const DWARFSection &AddrSec = BC->DwCtx->getDWARFObj().getAddrSection();
498-
DWARFDataExtractor AddrData(BC->DwCtx->getDWARFObj(), AddrSec, Endian, 0);
498+
DWARFDataExtractor AddrData(BC->DwCtx->getDWARFObj(), AddrSec,
499+
Endian == support::little, 0);
499500
DWARFDebugAddrTable AddrTable;
500501
DIDumpOptions DumpOpts;
501502
constexpr uint32_t HeaderSize = 8;

bolt/lib/Core/Relocation.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
using namespace llvm;
2121
using namespace bolt;
2222

23+
namespace ELFReserved {
24+
enum {
25+
R_RISCV_TPREL_I = 49,
26+
R_RISCV_TPREL_S = 50,
27+
};
28+
} // namespace ELFReserved
29+
2330
Triple::ArchType Relocation::Arch;
2431

2532
static bool isSupportedX86(uint64_t Type) {
@@ -35,6 +42,7 @@ static bool isSupportedX86(uint64_t Type) {
3542
case ELF::R_X86_64_PC32:
3643
case ELF::R_X86_64_PC64:
3744
case ELF::R_X86_64_PLT32:
45+
case ELF::R_X86_64_GOTPC64:
3846
case ELF::R_X86_64_GOTPCREL:
3947
case ELF::R_X86_64_GOTTPOFF:
4048
case ELF::R_X86_64_TPOFF32:
@@ -110,6 +118,13 @@ static bool isSupportedRISCV(uint64_t Type) {
110118
case ELF::R_RISCV_LO12_I:
111119
case ELF::R_RISCV_LO12_S:
112120
case ELF::R_RISCV_64:
121+
case ELF::R_RISCV_TLS_GOT_HI20:
122+
case ELF::R_RISCV_TPREL_HI20:
123+
case ELF::R_RISCV_TPREL_ADD:
124+
case ELF::R_RISCV_TPREL_LO12_I:
125+
case ELF::R_RISCV_TPREL_LO12_S:
126+
case ELFReserved::R_RISCV_TPREL_I:
127+
case ELFReserved::R_RISCV_TPREL_S:
113128
return true;
114129
}
115130
}
@@ -136,6 +151,7 @@ static size_t getSizeForTypeX86(uint64_t Type) {
136151
return 4;
137152
case ELF::R_X86_64_PC64:
138153
case ELF::R_X86_64_64:
154+
case ELF::R_X86_64_GOTPC64:
139155
return 8;
140156
}
141157
}
@@ -212,6 +228,7 @@ static size_t getSizeForTypeRISCV(uint64_t Type) {
212228
return 4;
213229
case ELF::R_RISCV_64:
214230
case ELF::R_RISCV_GOT_HI20:
231+
case ELF::R_RISCV_TLS_GOT_HI20:
215232
// See extractValueRISCV for why this is necessary.
216233
return 8;
217234
}
@@ -530,6 +547,7 @@ static uint64_t extractValueRISCV(uint64_t Type, uint64_t Contents,
530547
case ELF::R_RISCV_BRANCH:
531548
return extractBImmRISCV(Contents);
532549
case ELF::R_RISCV_GOT_HI20:
550+
case ELF::R_RISCV_TLS_GOT_HI20:
533551
// We need to know the exact address of the GOT entry so we extract the
534552
// value from both the AUIPC and L[D|W]. We cannot rely on the symbol in the
535553
// relocation for this since it simply refers to the object that is stored
@@ -598,6 +616,7 @@ static bool isGOTRISCV(uint64_t Type) {
598616
default:
599617
return false;
600618
case ELF::R_RISCV_GOT_HI20:
619+
case ELF::R_RISCV_TLS_GOT_HI20:
601620
return true;
602621
}
603622
}
@@ -634,6 +653,14 @@ static bool isTLSRISCV(uint64_t Type) {
634653
switch (Type) {
635654
default:
636655
return false;
656+
case ELF::R_RISCV_TLS_GOT_HI20:
657+
case ELF::R_RISCV_TPREL_HI20:
658+
case ELF::R_RISCV_TPREL_ADD:
659+
case ELF::R_RISCV_TPREL_LO12_I:
660+
case ELF::R_RISCV_TPREL_LO12_S:
661+
case ELFReserved::R_RISCV_TPREL_I:
662+
case ELFReserved::R_RISCV_TPREL_S:
663+
return true;
637664
}
638665
}
639666

@@ -655,6 +682,7 @@ static bool isPCRelativeX86(uint64_t Type) {
655682
case ELF::R_X86_64_PLT32:
656683
case ELF::R_X86_64_GOTOFF64:
657684
case ELF::R_X86_64_GOTPC32:
685+
case ELF::R_X86_64_GOTPC64:
658686
case ELF::R_X86_64_GOTTPOFF:
659687
case ELF::R_X86_64_GOTPCRELX:
660688
case ELF::R_X86_64_REX_GOTPCRELX:
@@ -730,6 +758,7 @@ static bool isPCRelativeRISCV(uint64_t Type) {
730758
case ELF::R_RISCV_RVC_JUMP:
731759
case ELF::R_RISCV_RVC_BRANCH:
732760
case ELF::R_RISCV_32_PCREL:
761+
case ELF::R_RISCV_TLS_GOT_HI20:
733762
return true;
734763
}
735764
}
@@ -797,6 +826,12 @@ bool Relocation::isX86GOTPCRELX(uint64_t Type) {
797826
return Type == ELF::R_X86_64_GOTPCRELX || Type == ELF::R_X86_64_REX_GOTPCRELX;
798827
}
799828

829+
bool Relocation::isX86GOTPC64(uint64_t Type) {
830+
if (Arch != Triple::x86_64)
831+
return false;
832+
return Type == ELF::R_X86_64_GOTPC64;
833+
}
834+
800835
bool Relocation::isNone(uint64_t Type) { return Type == getNone(); }
801836

802837
bool Relocation::isRelative(uint64_t Type) {

bolt/lib/Passes/ADRRelaxationPass.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ static cl::opt<bool>
2929
namespace llvm {
3030
namespace bolt {
3131

32+
// We don't exit directly from runOnFunction since it would call ThreadPool
33+
// destructor which might result in internal assert if we're not finished
34+
// creating async jobs on the moment of exit. So we're finishing all parallel
35+
// jobs and checking the exit flag after it.
36+
static bool PassFailed = false;
37+
3238
void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
39+
if (PassFailed)
40+
return;
41+
3342
BinaryContext &BC = BF.getBinaryContext();
3443
for (BinaryBasicBlock &BB : BF) {
3544
for (auto It = BB.begin(); It != BB.end(); ++It) {
@@ -54,8 +63,12 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
5463
MCPhysReg Reg;
5564
BC.MIB->getADRReg(Inst, Reg);
5665
int64_t Addend = BC.MIB->getTargetAddend(Inst);
57-
InstructionListType Addr =
58-
BC.MIB->materializeAddress(Symbol, BC.Ctx.get(), Reg, Addend);
66+
InstructionListType Addr;
67+
68+
{
69+
auto L = BC.scopeLock();
70+
Addr = BC.MIB->materializeAddress(Symbol, BC.Ctx.get(), Reg, Addend);
71+
}
5972

6073
if (It != BB.begin() && BC.MIB->isNoop(*std::prev(It))) {
6174
It = BB.eraseInstruction(std::prev(It));
@@ -68,7 +81,8 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
6881
errs() << formatv("BOLT-ERROR: Cannot relax adr in non-simple function "
6982
"{0}. Can't proceed in current mode.\n",
7083
BF.getOneName());
71-
exit(1);
84+
PassFailed = true;
85+
return;
7286
}
7387
It = BB.replaceInstruction(It, Addr);
7488
}
@@ -85,7 +99,10 @@ void ADRRelaxationPass::runOnFunctions(BinaryContext &BC) {
8599

86100
ParallelUtilities::runOnEachFunction(
87101
BC, ParallelUtilities::SchedulingPolicy::SP_TRIVIAL, WorkFun, nullptr,
88-
"ADRRelaxationPass", /* ForceSequential */ true);
102+
"ADRRelaxationPass");
103+
104+
if (PassFailed)
105+
exit(1);
89106
}
90107

91108
} // end namespace bolt

bolt/lib/Passes/FixRISCVCallsPass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ void FixRISCVCallsPass::runOnFunction(BinaryFunction &BF) {
4343

4444
MCInst OldCall = *NextII;
4545
auto L = BC.scopeLock();
46-
MIB->createCall(*II, Target, Ctx);
46+
47+
if (MIB->isTailCall(*NextII))
48+
MIB->createTailCall(*II, Target, Ctx);
49+
else
50+
MIB->createCall(*II, Target, Ctx);
51+
4752
MIB->moveAnnotations(std::move(OldCall), *II);
4853

4954
// The original offset was set on the jalr of the auipc+jalr pair. Since

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static cl::opt<bool>
111111

112112
static cl::opt<bool> PrintJTFootprintReduction(
113113
"print-after-jt-footprint-reduction",
114-
cl::desc("print function after jt-footprint-reduction pass"),
114+
cl::desc("print function after jt-footprint-reduction pass"), cl::Hidden,
115115
cl::cat(BoltOptCategory));
116116

117117
static cl::opt<bool>
@@ -160,7 +160,7 @@ static cl::opt<bool>
160160

161161
static cl::opt<bool> PrintRetpolineInsertion(
162162
"print-retpoline-insertion",
163-
cl::desc("print functions after retpoline insertion pass"),
163+
cl::desc("print functions after retpoline insertion pass"), cl::Hidden,
164164
cl::cat(BoltCategory));
165165

166166
static cl::opt<bool> PrintSCTC(
@@ -179,21 +179,21 @@ static cl::opt<bool>
179179

180180
static cl::opt<bool>
181181
PrintStoke("print-stoke", cl::desc("print functions after stoke analysis"),
182-
cl::cat(BoltOptCategory));
182+
cl::Hidden, cl::cat(BoltOptCategory));
183183

184184
static cl::opt<bool>
185185
PrintFixRelaxations("print-fix-relaxations",
186186
cl::desc("print functions after fix relaxations pass"),
187-
cl::cat(BoltOptCategory));
187+
cl::Hidden, cl::cat(BoltOptCategory));
188188

189189
static cl::opt<bool>
190190
PrintFixRISCVCalls("print-fix-riscv-calls",
191191
cl::desc("print functions after fix RISCV calls pass"),
192-
cl::cat(BoltOptCategory));
192+
cl::Hidden, cl::cat(BoltOptCategory));
193193

194194
static cl::opt<bool> PrintVeneerElimination(
195195
"print-veneer-elimination",
196-
cl::desc("print functions after veneer elimination pass"),
196+
cl::desc("print functions after veneer elimination pass"), cl::Hidden,
197197
cl::cat(BoltOptCategory));
198198

199199
static cl::opt<bool>

bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct BOLTInFlightAlloc : ExecutableFileMemoryManager::InFlightAlloc {
9090
: Alloc(std::move(Alloc)) {}
9191

9292
virtual void abandon(OnAbandonedFunction OnAbandoned) override {
93-
llvm_unreachable("unexpected abandoned allocation");
93+
OnAbandoned(Error::success());
9494
}
9595

9696
virtual void finalize(OnFinalizedFunction OnFinalized) override {

bolt/lib/Rewrite/JITLinkLinker.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool hasSymbols(const jitlink::Block &B) {
3232
Error markSectionsLive(jitlink::LinkGraph &G) {
3333
for (auto &Section : G.sections()) {
3434
// We only need allocatable sections.
35-
if (Section.getMemLifetimePolicy() == orc::MemLifetimePolicy::NoAlloc)
35+
if (Section.getMemLifetime() == orc::MemLifetime::NoAlloc)
3636
continue;
3737

3838
// Skip empty sections.
@@ -141,6 +141,19 @@ struct JITLinkLinker::Context : jitlink::JITLinkContext {
141141
orc::ExecutorAddr(Address), JITSymbolFlags());
142142
continue;
143143
}
144+
145+
if (Linker.BC.isGOTSymbol(SymName)) {
146+
if (const BinaryData *I = Linker.BC.getGOTSymbol()) {
147+
uint64_t Address =
148+
I->isMoved() ? I->getOutputAddress() : I->getAddress();
149+
LLVM_DEBUG(dbgs() << "Resolved to address 0x"
150+
<< Twine::utohexstr(Address) << "\n");
151+
AllResults[Symbol.first] = orc::ExecutorSymbolDef(
152+
orc::ExecutorAddr(Address), JITSymbolFlags());
153+
continue;
154+
}
155+
}
156+
144157
LLVM_DEBUG(dbgs() << "Resolved to address 0x0\n");
145158
AllResults[Symbol.first] =
146159
orc::ExecutorSymbolDef(orc::ExecutorAddr(0), JITSymbolFlags());

0 commit comments

Comments
 (0)