Skip to content

[AArch64] Move SLS later in pass pipeline #84210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,20 @@ void SLSBLRThunkInserter::populateThunk(MachineFunction &MF) {

const TargetInstrInfo *TII =
MF.getSubtarget<AArch64Subtarget>().getInstrInfo();
assert (MF.size() == 1);

// Depending on whether this pass is in the same FunctionPassManager as the
// IR->MIR conversion, the thunk may be completely empty, or contain a single
// basic block with a single return instruction. Normalise it to contain a
// single empty basic block.
if (MF.size() == 1) {
assert(MF.front().size() == 1);
assert(MF.front().front().getOpcode() == AArch64::RET);
MF.front().erase(MF.front().begin());
} else {
assert(MF.size() == 0);
MF.push_back(MF.CreateMachineBasicBlock());
}

MachineBasicBlock *Entry = &MF.front();
Entry->clear();

Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,6 @@ void AArch64PassConfig::addPreSched2() {
// info.
addPass(createAArch64SpeculationHardeningPass());

addPass(createAArch64IndirectThunks());
addPass(createAArch64SLSHardeningPass());

if (TM->getOptLevel() != CodeGenOptLevel::None) {
if (EnableFalkorHWPFFix)
addPass(createFalkorHWPFFixPass());
Expand Down Expand Up @@ -855,6 +852,8 @@ void AArch64PassConfig::addPreEmitPass() {
}

void AArch64PassConfig::addPostBBSections() {
addPass(createAArch64IndirectThunks());
addPass(createAArch64SLSHardeningPass());
addPass(createAArch64PointerAuthPass());
if (EnableBranchTargets)
addPass(createAArch64BranchTargetsPass());
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/AArch64/O0-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
; CHECK-NEXT: AArch64 pseudo instruction expansion pass
; CHECK-NEXT: Insert KCFI indirect call checks
; CHECK-NEXT: AArch64 speculation hardening pass
; CHECK-NEXT: AArch64 Indirect Thunks
; CHECK-NEXT: AArch64 sls hardening pass
; CHECK-NEXT: Analyze Machine Code For Garbage Collection
; CHECK-NEXT: Insert fentry calls
; CHECK-NEXT: Insert XRay ops
Expand All @@ -75,6 +73,8 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
; CHECK-NEXT: AArch64 Indirect Thunks
; CHECK-NEXT: AArch64 sls hardening pass
; CHECK-NEXT: AArch64 Pointer Authentication
; CHECK-NEXT: AArch64 Branch Targets
; CHECK-NEXT: Branch relaxation pass
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/AArch64/O3-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@
; CHECK-NEXT: AArch64 load / store optimization pass
; CHECK-NEXT: Insert KCFI indirect call checks
; CHECK-NEXT: AArch64 speculation hardening pass
; CHECK-NEXT: AArch64 Indirect Thunks
; CHECK-NEXT: AArch64 sls hardening pass
; CHECK-NEXT: MachineDominator Tree Construction
; CHECK-NEXT: Machine Natural Loop Construction
; CHECK-NEXT: Falkor HW Prefetch Fix Late Phase
Expand All @@ -227,6 +225,8 @@
; CHECK-NEXT: Machine Sanitizer Binary Metadata
; CHECK-NEXT: Machine Outliner
; CHECK-NEXT: FunctionPass Manager
; CHECK-NEXT: AArch64 Indirect Thunks
; CHECK-NEXT: AArch64 sls hardening pass
; CHECK-NEXT: AArch64 Pointer Authentication
; CHECK-NEXT: AArch64 Branch Targets
; CHECK-NEXT: Branch relaxation pass
Expand Down
24 changes: 20 additions & 4 deletions llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@

; HOTNESS: Freeing Pass 'Machine Outliner'
; HOTNESS-NEXT: Executing Pass 'Function Pass Manager'
; HOTNESS-NEXT: Executing Pass 'Verify generated machine code'
; HOTNESS-NEXT: Freeing Pass 'Verify generated machine code'
; HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
; HOTNESS-NEXT: Freeing Pass 'Verify generated machine code' on Function 'empty_func'...
; HOTNESS-NEXT: Executing Pass 'AArch64 Indirect Thunks' on Function 'empty_func'...
; HOTNESS-NEXT: Freeing Pass 'AArch64 Indirect Thunks' on Function 'empty_func'...
; HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
; HOTNESS-NEXT: Freeing Pass 'Verify generated machine code' on Function 'empty_func'...
; HOTNESS-NEXT: Executing Pass 'AArch64 sls hardening pass' on Function 'empty_func'...
; HOTNESS-NEXT: Freeing Pass 'AArch64 sls hardening pass' on Function 'empty_func'...
; HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
; HOTNESS-NEXT: Freeing Pass 'Verify generated machine code' on Function 'empty_func'...
; HOTNESS-NEXT: Executing Pass 'AArch64 Pointer Authentication' on Function 'empty_func'...
; HOTNESS-NEXT: Freeing Pass 'AArch64 Pointer Authentication' on Function 'empty_func'...
; HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
Expand Down Expand Up @@ -73,8 +81,16 @@

; NO_HOTNESS: Freeing Pass 'Machine Outliner'
; NO_HOTNESS-NEXT: Executing Pass 'Function Pass Manager'
; NO_HOTNESS-NEXT: Executing Pass 'Verify generated machine code'
; NO_HOTNESS-NEXT: Freeing Pass 'Verify generated machine code'
; NO_HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Freeing Pass 'Verify generated machine code' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Executing Pass 'AArch64 Indirect Thunks' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Freeing Pass 'AArch64 Indirect Thunks' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Freeing Pass 'Verify generated machine code' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Executing Pass 'AArch64 sls hardening pass' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Freeing Pass 'AArch64 sls hardening pass' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Freeing Pass 'Verify generated machine code' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Executing Pass 'AArch64 Pointer Authentication' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Freeing Pass 'AArch64 Pointer Authentication' on Function 'empty_func'...
; NO_HOTNESS-NEXT: Executing Pass 'Verify generated machine code' on Function 'empty_func'...
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/CodeGen/AArch64/sls-crash.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: llc -mtriple aarch64 -O0 < %s

define hidden void @foo() "target-features"="+harden-sls-blr" {
entry:
ret void
}
12 changes: 8 additions & 4 deletions llvm/test/CodeGen/AArch64/sls-stackprotector-outliner.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ define hidden void @_ZTv0_n24_N2C6D1Ev(ptr %this) minsize sspreq "target-feature
; CHECK-NEXT: b.ne .LBB0_2
; CHECK-NEXT: // %bb.1: // %entry
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
; CHECK-NEXT: bl OUTLINED_FUNCTION_1
; CHECK-NEXT: add x0, x0, x8
; CHECK-NEXT: add sp, sp, #32
; CHECK-NEXT: b _ZN2C6D1Ev
; CHECK-NEXT: dsb sy
; CHECK-NEXT: isb
Expand All @@ -45,7 +46,8 @@ define hidden void @_ZTv0_n24_N2C6D0Ev(ptr %this) minsize sspreq "target-feature
; CHECK-NEXT: b.ne .LBB1_2
; CHECK-NEXT: // %bb.1: // %entry
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
; CHECK-NEXT: bl OUTLINED_FUNCTION_1
; CHECK-NEXT: add x0, x0, x8
; CHECK-NEXT: add sp, sp, #32
; CHECK-NEXT: b _ZN2C6D0Ev
; CHECK-NEXT: dsb sy
; CHECK-NEXT: isb
Expand All @@ -71,7 +73,8 @@ define hidden void @_ZTv0_n24_N3C10D1Ev(ptr %this) minsize sspreq "target-featur
; CHECK-NEXT: b.ne .LBB2_2
; CHECK-NEXT: // %bb.1: // %entry
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
; CHECK-NEXT: bl OUTLINED_FUNCTION_1
; CHECK-NEXT: add x0, x0, x8
; CHECK-NEXT: add sp, sp, #32
; CHECK-NEXT: b _ZN3C10D1Ev
; CHECK-NEXT: dsb sy
; CHECK-NEXT: isb
Expand All @@ -97,7 +100,8 @@ define hidden void @_ZTv0_n24_N3C10D0Ev(ptr %this) minsize sspreq "target-featur
; CHECK-NEXT: b.ne .LBB3_2
; CHECK-NEXT: // %bb.1: // %entry
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
; CHECK-NEXT: bl OUTLINED_FUNCTION_1
; CHECK-NEXT: add x0, x0, x8
; CHECK-NEXT: add sp, sp, #32
; CHECK-NEXT: b _ZN3C10D0Ev
; CHECK-NEXT: dsb sy
; CHECK-NEXT: isb
Expand Down