Skip to content

Commit ebd7d2b

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-min-iters-check
2 parents 91a1dff + f3520c5 commit ebd7d2b

File tree

1,109 files changed

+50888
-14399
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,109 files changed

+50888
-14399
lines changed

.ci/metrics/metrics.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,29 @@ def github_get_metrics(
336336
name_suffix = GITHUB_JOB_TO_TRACK[name_prefix][job.name]
337337
metric_name = name_prefix + "_" + name_suffix
338338

339+
ag_metric_name = None
340+
if libcxx_testing:
341+
job_key = None
342+
if job.name.find("stage1") != -1:
343+
job_key = "stage1"
344+
elif job.name.find("stage2") != -1:
345+
job_key = "stage2"
346+
elif job.name.find("stage3") != -1:
347+
job_key = "stage3"
348+
if job_key:
349+
ag_name = (
350+
name_prefix + "_" + GITHUB_JOB_TO_TRACK[name_prefix][job_key]
351+
)
352+
339353
if task.status != "completed":
340354
if job.status == "queued":
341355
queued_count[metric_name] += 1
356+
if libcxx_testing:
357+
queued_count[ag_name] += 1
342358
elif job.status == "in_progress":
343359
running_count[metric_name] += 1
360+
if libcxx_testing:
361+
running_count[ag_name] += 1
344362
continue
345363

346364
job_result = int(job.conclusion == "success" or job.conclusion == "skipped")

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@
112112
/mlir/**/NVGPU*/ @grypp
113113
/mlir/test/**/CUDA/ @grypp
114114

115+
# MLIR GPU Dialect
116+
/mlir/**/GPU*/ @fabianmcg
117+
115118
# MLIR NVVM Dialect in MLIR
116119
/mlir/**/LLVMIR/**/BasicPtxBuilderInterface* @grypp
117120
/mlir/**/NVVM* @grypp

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,20 @@ class MCPlusBuilder {
718718
return false;
719719
}
720720

721+
/// Returns true if Inst is a trap instruction.
722+
///
723+
/// Tests if Inst is an instruction that immediately causes an abnormal
724+
/// program termination, for example when a security violation is detected
725+
/// by a compiler-inserted check.
726+
///
727+
/// @note An implementation of this method should likely return false for
728+
/// calls to library functions like abort(), as it is possible that the
729+
/// execution state is partially attacker-controlled at this point.
730+
virtual bool isTrap(const MCInst &Inst) const {
731+
llvm_unreachable("not implemented");
732+
return false;
733+
}
734+
721735
virtual bool isBreakpoint(const MCInst &Inst) const {
722736
llvm_unreachable("not implemented");
723737
return false;

bolt/lib/Core/BinaryBasicBlock.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,18 @@ bool BinaryBasicBlock::validateSuccessorInvariants() {
103103
Valid &= (Sym == Function->getFunctionEndLabel() ||
104104
Sym == Function->getFunctionEndLabel(getFragmentNum()));
105105
if (!Valid) {
106-
BC.errs() << "BOLT-WARNING: Jump table contains illegal entry: "
107-
<< Sym->getName() << "\n";
106+
const BinaryFunction *TargetBF = BC.getFunctionForSymbol(Sym);
107+
if (TargetBF) {
108+
// It's possible for another function to be in the jump table entry
109+
// as a result of built-in unreachable.
110+
Valid = true;
111+
} else {
112+
BC.errs() << "BOLT-WARNING: Jump table contains illegal entry: "
113+
<< Sym->getName() << "\n";
114+
}
108115
}
116+
if (!Valid)
117+
break;
109118
}
110119
}
111120
} else {

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,9 @@ void BinaryFunction::postProcessJumpTables() {
19591959
return EntryAddress == Parent->getAddress() + Parent->getSize();
19601960
});
19611961
if (IsBuiltinUnreachable) {
1962-
MCSymbol *Label = getOrCreateLocalLabel(EntryAddress, true);
1962+
BinaryFunction *TargetBF = BC.getBinaryFunctionAtAddress(EntryAddress);
1963+
MCSymbol *Label = TargetBF ? TargetBF->getSymbol()
1964+
: getOrCreateLocalLabel(EntryAddress, true);
19631965
JT.Entries.push_back(Label);
19641966
continue;
19651967
}

bolt/lib/Passes/IndirectCallPromotion.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,7 @@ IndirectCallPromotion::getCallTargets(BinaryBasicBlock &BB,
261261
for (size_t I = Range.first; I < Range.second; ++I, JI += JIAdj) {
262262
MCSymbol *Entry = JT->Entries[I];
263263
const BinaryBasicBlock *ToBB = BF.getBasicBlockForLabel(Entry);
264-
assert(ToBB || Entry == BF.getFunctionEndLabel() ||
265-
Entry == BF.getFunctionEndLabel(FragmentNum::cold()));
266-
if (Entry == BF.getFunctionEndLabel() ||
267-
Entry == BF.getFunctionEndLabel(FragmentNum::cold()))
264+
if (!ToBB)
268265
continue;
269266
const Location To(Entry);
270267
const BinaryBasicBlock::BinaryBranchInfo &BI = BB.getBranchInfo(*ToBB);

bolt/lib/Passes/PAuthGadgetScanner.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,15 @@ class DstSafetyAnalysis {
10781078
dbgs() << ")\n";
10791079
});
10801080

1081+
// If this instruction terminates the program immediately, no
1082+
// authentication oracles are possible past this point.
1083+
if (BC.MIB->isTrap(Point)) {
1084+
LLVM_DEBUG({ traceInst(BC, "Trap instruction found", Point); });
1085+
DstState Next(NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters());
1086+
Next.CannotEscapeUnchecked.set();
1087+
return Next;
1088+
}
1089+
10811090
// If this instruction is reachable by the analysis, a non-empty state will
10821091
// be propagated to it sooner or later. Until then, skip computeNext().
10831092
if (Cur.empty()) {
@@ -1185,8 +1194,8 @@ class DataflowDstSafetyAnalysis
11851194
//
11861195
// A basic block without any successors, on the other hand, can be
11871196
// pessimistically initialized to everything-is-unsafe: this will naturally
1188-
// handle both return and tail call instructions and is harmless for
1189-
// internal indirect branch instructions (such as computed gotos).
1197+
// handle return, trap and tail call instructions. At the same time, it is
1198+
// harmless for internal indirect branch instructions, like computed gotos.
11901199
if (BB.succ_empty())
11911200
return createUnsafeState();
11921201

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,9 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
382382
// the list of successors of this basic block as appropriate.
383383

384384
// Any of the above code sequences assume the fall-through basic block
385-
// is a dead-end BRK instruction (any immediate operand is accepted).
385+
// is a dead-end trap instruction.
386386
const BinaryBasicBlock *BreakBB = BB.getFallthrough();
387-
if (!BreakBB || BreakBB->empty() ||
388-
BreakBB->front().getOpcode() != AArch64::BRK)
387+
if (!BreakBB || BreakBB->empty() || !isTrap(BreakBB->front()))
389388
return std::nullopt;
390389

391390
// Iterate over the instructions of BB in reverse order, matching opcodes
@@ -1744,6 +1743,34 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
17441743
Inst.addOperand(MCOperand::createImm(0));
17451744
}
17461745

1746+
bool isTrap(const MCInst &Inst) const override {
1747+
if (Inst.getOpcode() != AArch64::BRK)
1748+
return false;
1749+
// Only match the immediate values that are likely to indicate this BRK
1750+
// instruction is emitted to terminate the program immediately and not to
1751+
// be handled by a SIGTRAP handler, for example.
1752+
switch (Inst.getOperand(0).getImm()) {
1753+
case 0xc470:
1754+
case 0xc471:
1755+
case 0xc472:
1756+
case 0xc473:
1757+
// Explicit Pointer Authentication check failed, see
1758+
// AArch64AsmPrinter::emitPtrauthCheckAuthenticatedValue().
1759+
return true;
1760+
case 0x1:
1761+
// __builtin_trap(), as emitted by Clang.
1762+
return true;
1763+
case 0x3e8: // decimal 1000
1764+
// __builtin_trap(), as emitted by GCC.
1765+
return true;
1766+
default:
1767+
// Some constants may indicate intentionally recoverable break-points.
1768+
// This is the case at least for 0xf000, which is used by
1769+
// __builtin_debugtrap() supported by Clang.
1770+
return false;
1771+
}
1772+
}
1773+
17471774
bool isStorePair(const MCInst &Inst) const {
17481775
const unsigned opcode = Inst.getOpcode();
17491776

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## Check that llvm-bolt correctly updates ambiguous jump table entries that
2+
## can correspond to either builtin_unreachable() or could be a pointer to
3+
## the next function.
4+
5+
# REQUIRES: system-linux
6+
7+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
8+
# RUN: %clang %cflags %t.o -o %t.exe -no-pie -Wl,-q
9+
10+
# RUN: llvm-bolt %t.exe --print-normalized --print-only=foo -o %t.out \
11+
# RUN: 2>&1 | FileCheck %s
12+
13+
14+
15+
.text
16+
.globl _start
17+
.type _start, %function
18+
_start:
19+
.cfi_startproc
20+
call foo
21+
ret
22+
.cfi_endproc
23+
.size _start, .-_start
24+
25+
.globl foo
26+
.type foo, %function
27+
foo:
28+
.cfi_startproc
29+
.LBB00:
30+
movq 0x8(%rdi), %rdi
31+
movzbl 0x1(%rdi), %eax
32+
.LBB00_br:
33+
jmpq *"JUMP_TABLE/foo.0"(,%rax,8)
34+
# CHECK: jmpq {{.*}} # JUMPTABLE
35+
# CHECK-NEXT: Successors: {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}
36+
37+
.Ltmp87085:
38+
xorl %eax, %eax
39+
retq
40+
41+
.Ltmp87086:
42+
cmpb $0x0, 0x8(%rdi)
43+
setne %al
44+
retq
45+
46+
.Ltmp87088:
47+
movb $0x1, %al
48+
retq
49+
50+
.Ltmp87087:
51+
movzbl 0x14(%rdi), %eax
52+
andb $0x2, %al
53+
shrb %al
54+
retq
55+
56+
.cfi_endproc
57+
.size foo, .-foo
58+
59+
.globl bar
60+
.type bar, %function
61+
bar:
62+
.cfi_startproc
63+
ret
64+
.cfi_endproc
65+
.size bar, .-bar
66+
67+
# Jump tables
68+
.section .rodata
69+
.global jump_table
70+
jump_table:
71+
"JUMP_TABLE/foo.0":
72+
.quad bar
73+
.quad .Ltmp87085
74+
.quad bar
75+
.quad .Ltmp87086
76+
.quad .Ltmp87087
77+
.quad .LBB00
78+
.quad .Ltmp87088
79+
.quad bar
80+
.quad .LBB00
81+
82+
# CHECK: Jump table {{.*}} for function foo
83+
# CHECK-NEXT: 0x{{.*}} : bar
84+
# CHECK-NEXT: 0x{{.*}} :
85+
# CHECK-NEXT: 0x{{.*}} : bar
86+
# CHECK-NEXT: 0x{{.*}} :
87+
# CHECK-NEXT: 0x{{.*}} :

0 commit comments

Comments
 (0)