Skip to content

Commit 68832dc

Browse files
authored
Merge branch 'main' into remove-clangDriver-dep-from-clangDependencyScanning
2 parents 450f189 + 9349cb1 commit 68832dc

File tree

500 files changed

+56247
-58845
lines changed

Some content is hidden

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

500 files changed

+56247
-58845
lines changed

.ci/generate_test_report_lib.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ def _parse_ninja_log(ninja_log: list[str]) -> list[tuple[str, str]]:
6262
# aligned with the failure.
6363
failing_action = ninja_log[index].split("FAILED: ")[1]
6464
failure_log = []
65+
66+
# Parse the lines above the FAILED: string if the line does not come
67+
# immediately after a progress indicator to ensure that we capture the
68+
# entire failure message.
69+
if not ninja_log[index - 1].startswith("["):
70+
before_index = index - 1
71+
while before_index > 0 and not ninja_log[before_index].startswith("["):
72+
failure_log.append(ninja_log[before_index])
73+
before_index = before_index - 1
74+
failure_log.reverse()
75+
76+
# Parse the failure information, which comes after the FAILED: tag.
6577
while (
6678
index < len(ninja_log)
6779
and not ninja_log[index].startswith("[")

.ci/generate_test_report_lib_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def test_ninja_log_mismatched_failed(self):
181181
"tools/check-langley",
182182
dedent(
183183
"""\
184+
ModuleNotFoundError: No module named 'mount_langley'
184185
FAILED: tools/check-langley
185186
Wow! This system is really broken!"""
186187
),

.github/workflows/issue-write.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,4 @@ jobs:
162162
if: >-
163163
always() &&
164164
steps.download-artifact.outputs.artifact-ids != ''
165-
run: cat comments
165+
run: cat comments*

.github/workflows/premerge.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
fetch-depth: 2
6464
- name: Build and Test
6565
timeout-minutes: 120
66-
continue-on-error: ${{ runner.arch == 'ARM64' }}
6766
env:
6867
GITHUB_TOKEN: ${{ github.token }}
6968
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ intended audience is BOLT developers. The document is an updated version of the
1010
in assembly, or `OpNegateRAState` in BOLT sources. In this document, I will use
1111
**negate-ra-state** as a shorthand.
1212

13+
Note: there are two resolutions for CFI:
14+
- Call Frame Instruction: individual DWARF instruction, e.g. negate-ra-state
15+
- Control Flow Integrity: a security mechanism, e.g. pointer authentication.
16+
1317
## Introduction
1418

1519
### Pointer Authentication
@@ -104,9 +108,9 @@ negate-ra-state CFIs will become invalid during BasicBlock reordering.
104108
## Solution design
105109

106110
The implementation introduces two new passes:
107-
1. `MarkRAStatesPass`: assigns the RA state to each instruction based on the CFIs
108-
in the input binary
109-
2. `InsertNegateRAStatePass`: reads those assigned instruction RA states after
111+
1. `PointerAuthCFIAnalyzer`: assigns the RA state to each instruction based on
112+
the CFIs in the input binary
113+
2. `PointerAuthCFIFixup`: reads those assigned instruction RA states after
110114
optimizations, and emits `DW_CFA_AARCH64_negate_ra_state` CFIs at the correct
111115
places: wherever there is a state change between two consecutive instructions
112116
in the layout order.
@@ -129,7 +133,7 @@ instruction.
129133
This special case is handled by adding an `initialRAState` bool to each BinaryFunction.
130134
If the `Offset` the CFI refers to is zero, we don't store an annotation, but set
131135
the `initialRAState` in `FillCFIInfoFor`. This information is then used in
132-
`MarkRAStates`.
136+
`PointerAuthCFIAnalyzer`.
133137

134138
### Binaries without DWARF info
135139

@@ -146,7 +150,7 @@ In summary:
146150
- pointer auth is used, and we have DWARF CFIs: passes run, and rewrite the
147151
negate-ra-state CFI.
148152

149-
### MarkRAStates pass
153+
### PointerAuthCFIAnalyzer pass
150154

151155
This pass runs before optimizations reorder anything.
152156

@@ -173,9 +177,9 @@ what we have before the pass, and after it.
173177
| autiasp | negate-ra-state | signed |
174178
| ret | | unsigned |
175179

176-
##### Error handling in MarkRAState Pass:
180+
##### Error handling in PointerAuthCFIAnalyzer pass:
177181

178-
Whenever the MarkRAStates pass finds inconsistencies in the current
182+
Whenever the PointerAuthCFIAnalyzer pass finds inconsistencies in the current
179183
BinaryFunction, it marks the function as ignored using `BF.setIgnored()`. BOLT
180184
will not optimize this function but will emit it unchanged in the original section
181185
(`.bolt.org.text`).
@@ -188,16 +192,17 @@ The inconsistencies are as follows:
188192
Users will be informed about the number of ignored functions in the pass, the
189193
exact functions ignored, and the found inconsistency.
190194

191-
### InsertNegateRAStatePass
195+
### PointerAuthCFIFixup
192196

193-
This pass runs after optimizations. It performns the _inverse_ of MarkRAState pa s:
197+
This pass runs after optimizations. It performs the _inverse_ of PointerAuthCFIAnalyzer
198+
pass:
194199
1. it reads the RA state annotations attached to the instructions, and
195200
2. whenever the state changes, it adds a PseudoInstruction that holds an
196201
OpNegateRAState CFI.
197202

198203
##### Covering newly generated instructions:
199204

200-
Some BOLT passes can add new Instructions. In InsertNegateRAStatePass, we have
205+
Some BOLT passes can add new Instructions. In PointerAuthCFIFixup, we have
201206
to know what RA state these have.
202207

203208
> [!important]
@@ -224,7 +229,7 @@ freely. The only special case is function splitting. When a function is split,
224229
the split part becomes a new function in the emitted binary. For unwinding to
225230
work, it needs to "replay" all CFIs that lead up to the split point. BOLT does
226231
this for other CFIs. As negate-ra-state is not read (only stored as an Annotation),
227-
we have to do this manually in InsertNegateRAStatePass. Here, if the split part
232+
we have to do this manually in PointerAuthCFIFixup. Here, if the split part
228233
starts with an instruction that has Signed RA state, we add a negate-ra-state CFI
229234
to indicate this.
230235

bolt/include/bolt/Passes/IdenticalCodeFolding.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ class IdenticalCodeFolding : public BinaryFunctionPass {
3737
Error runOnFunctions(BinaryContext &BC) override;
3838

3939
private:
40+
static constexpr uint64_t VTableAddressGranularity = 4;
41+
4042
/// Bit vector of memory addresses of vtables.
4143
llvm::SparseBitVector<> VTableBitVector;
4244

4345
/// Return true if the memory address is in a vtable.
4446
bool isAddressInVTable(uint64_t Address) const {
45-
return VTableBitVector.test(Address / 8);
47+
return VTableBitVector.test(Address / VTableAddressGranularity);
4648
}
4749

4850
/// Mark memory address of a vtable as used.
4951
void setAddressUsedInVTable(uint64_t Address) {
50-
VTableBitVector.set(Address / 8);
52+
VTableBitVector.set(Address / VTableAddressGranularity);
5153
}
5254

5355
/// Scan symbol table and mark memory addresses of

bolt/include/bolt/Passes/MarkRAStates.h renamed to bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
//===- bolt/Passes/MarkRAStates.cpp ---------------------------------===//
1+
//===- bolt/Passes/PointerAuthCFIAnalyzer.h -------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements the MarkRAStates class.
9+
// This file implements the PointerAuthCFIAnalyzer class.
1010
//
1111
//===----------------------------------------------------------------------===//
12-
#ifndef BOLT_PASSES_MARK_RA_STATES
13-
#define BOLT_PASSES_MARK_RA_STATES
12+
#ifndef BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER
13+
#define BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER
1414

1515
#include "bolt/Passes/BinaryPasses.h"
1616
#include <mutex>
1717

1818
namespace llvm {
1919
namespace bolt {
2020

21-
class MarkRAStates : public BinaryFunctionPass {
21+
class PointerAuthCFIAnalyzer : public BinaryFunctionPass {
2222
// setIgnored() is not thread-safe, but the pass is running on functions in
2323
// parallel.
2424
std::mutex IgnoreMutex;
2525

2626
public:
27-
explicit MarkRAStates() : BinaryFunctionPass(false) {}
27+
explicit PointerAuthCFIAnalyzer(const cl::opt<bool> &PrintPass)
28+
: BinaryFunctionPass(PrintPass) {}
2829

29-
const char *getName() const override { return "mark-ra-states"; }
30+
const char *getName() const override { return "pointer-auth-cfi-analyzer"; }
3031

3132
/// Pass entry point
3233
Error runOnFunctions(BinaryContext &BC) override;

bolt/include/bolt/Passes/InsertNegateRAStatePass.h renamed to bolt/include/bolt/Passes/PointerAuthCFIFixup.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
//===- bolt/Passes/InsertNegateRAStatePass.h ------------------------------===//
1+
//===- bolt/Passes/PointerAuthCFIFixup.h ----------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements the InsertNegateRAStatePass class.
9+
// This file implements the PointerAuthCFIFixup class.
1010
//
1111
//===----------------------------------------------------------------------===//
12-
#ifndef BOLT_PASSES_INSERT_NEGATE_RA_STATE_PASS
13-
#define BOLT_PASSES_INSERT_NEGATE_RA_STATE_PASS
12+
#ifndef BOLT_PASSES_POINTER_AUTH_CFI_FIXUP
13+
#define BOLT_PASSES_POINTER_AUTH_CFI_FIXUP
1414

1515
#include "bolt/Passes/BinaryPasses.h"
1616

1717
namespace llvm {
1818
namespace bolt {
1919

20-
class InsertNegateRAState : public BinaryFunctionPass {
20+
class PointerAuthCFIFixup : public BinaryFunctionPass {
2121
public:
22-
explicit InsertNegateRAState() : BinaryFunctionPass(false) {}
22+
explicit PointerAuthCFIFixup(const cl::opt<bool> &PrintPass)
23+
: BinaryFunctionPass(PrintPass) {}
2324

24-
const char *getName() const override { return "insert-negate-ra-state-pass"; }
25+
const char *getName() const override { return "pointer-auth-cfi-fixup"; }
2526

2627
/// Pass entry point
2728
Error runOnFunctions(BinaryContext &BC) override;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,9 +1408,7 @@ Error BinaryFunction::disassemble() {
14081408
// A recursive call. Calls to internal blocks are handled by
14091409
// ValidateInternalCalls pass.
14101410
TargetSymbol = getSymbol();
1411-
}
1412-
1413-
if (!TargetSymbol) {
1411+
} else {
14141412
// Create either local label or external symbol.
14151413
if (containsAddress(TargetAddress)) {
14161414
TargetSymbol = getOrCreateLocalLabel(TargetAddress);

bolt/lib/Core/Exceptions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
572572
if (Function.getBinaryContext().isAArch64()) {
573573
// Support for pointer authentication:
574574
// We need to annotate instructions that modify the RA State, to work
575-
// out the state of each instruction in MarkRAStates Pass.
575+
// out the state of each instruction in PointerAuthCFIAnalyzer Pass.
576576
if (Offset != 0)
577577
Function.setInstModifiesRAState(DW_CFA_remember_state, Offset);
578578
}
@@ -583,7 +583,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
583583
if (Function.getBinaryContext().isAArch64()) {
584584
// Support for pointer authentication:
585585
// We need to annotate instructions that modify the RA State, to work
586-
// out the state of each instruction in MarkRAStates Pass.
586+
// out the state of each instruction in PointerAuthCFIAnalyzer Pass.
587587
if (Offset != 0)
588588
Function.setInstModifiesRAState(DW_CFA_restore_state, Offset);
589589
}
@@ -652,15 +652,15 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
652652
// BasicBlocks, which changes during optimizations. Instead of adding
653653
// OpNegateRAState CFIs, an annotation is added to the instruction, to
654654
// mark that the instruction modifies the RA State. The actual state for
655-
// instructions are worked out in MarkRAStates based on these
655+
// instructions are worked out in PointerAuthCFIAnalyzer based on these
656656
// annotations.
657657
if (Offset != 0)
658658
Function.setInstModifiesRAState(DW_CFA_AARCH64_negate_ra_state,
659659
Offset);
660660
else
661661
// We cannot Annotate an instruction at Offset == 0.
662662
// Instead, we save the initial (Signed) state, and push it to
663-
// MarkRAStates' RAStateStack.
663+
// PointerAuthCFIAnalyzer's RAStateStack.
664664
Function.setInitialRAState(true);
665665
break;
666666
}

0 commit comments

Comments
 (0)