-
Notifications
You must be signed in to change notification settings - Fork 15k
[ARM][KCFI] Fix bundle sizes to reflect worst-case expansion #164917
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
Conversation
The KCFI_CHECK pseudo-instruction size for ARM got miscalculated. These should represent worst-case expansion to ensure correct branch range calculations and code layout. Update the Size field for each ARM sub-architecture: - ARM: 28 → 40 bytes (10 instructions @ 4 bytes when r3 spill needed) - Thumb2: 32 → 34 bytes (mixed 16/32-bit instructions with r3 spill) - Thumb1: 50 → 38 bytes (19 instructions @ 2 bytes with r2+r3 spills) The ARM and Thumb2 sizes were underestimating the case where the target register is r12, requiring r3 to be used as scratch and spilled/restored. The Thumb1 size was overestimated and has been corrected to the actual worst-case of 19 instructions.
|
@llvm/pr-subscribers-backend-arm Author: Kees Cook (kees) ChangesThe KCFI_CHECK pseudo-instruction size for ARM got miscalculated. These should represent worst-case expansion to ensure correct branch range calculations and code layout. Update the Size field for each ARM sub-architecture:
The ARM and Thumb2 sizes were underestimating the case where the target register is r12, requiring r3 to be used as scratch and spilled/restored. The Thumb1 size was overestimated and has been corrected to the actual worst-case of 19 instructions. cc @nathanchance Full diff: https://github.com/llvm/llvm-project/pull/164917.diff 1 Files Affected:
diff --git a/llvm/lib/Target/ARM/ARMInstrInfo.td b/llvm/lib/Target/ARM/ARMInstrInfo.td
index 53be1677b96e3..ce79029b17d12 100644
--- a/llvm/lib/Target/ARM/ARMInstrInfo.td
+++ b/llvm/lib/Target/ARM/ARMInstrInfo.td
@@ -6546,7 +6546,8 @@ def KCFI_CHECK_ARM
: PseudoInst<(outs), (ins GPR:$ptr, i32imm:$type), NoItinerary, []>,
Sched<[]>,
Requires<[IsARM]> {
- let Size = 28; // 7 instructions (bic, ldr, 4x eor, beq, udf)
+ let Size = 40; // worst-case 10 instructions @ 4 bytes each
+ // (push, bic, ldr, 4x eor, pop, beq, udf)
}
def KCFI_CHECK_Thumb2
@@ -6554,15 +6555,15 @@ def KCFI_CHECK_Thumb2
Sched<[]>,
Requires<[IsThumb2]> {
let Size =
- 32; // worst-case 9 instructions (push, bic, ldr, 4x eor, pop, beq.w, udf)
+ 34; // worst-case (push.w[2], bic[4], ldr[4], 4x eor[16], pop.w[2], beq.w[4], udf[2])
}
def KCFI_CHECK_Thumb1
: PseudoInst<(outs), (ins GPR:$ptr, i32imm:$type), NoItinerary, []>,
Sched<[]>,
Requires<[IsThumb1Only]> {
- let Size = 50; // worst-case 25 instructions (pushes, bic helper, type
- // building, cmp, pops)
+ let Size = 38; // worst-case 19 instructions @ 2 bytes each
+ // (2x push, 3x bic-helper, subs+ldr, 13x type-building, cmp, 2x pop, beq, bkpt)
}
//===----------------------------------------------------------------------===//
|
|
Thanks, this survives |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/20148 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/13441 Here is the relevant piece of the build log for the reference |
…4917) The KCFI_CHECK pseudo-instruction size for ARM got miscalculated. These should represent worst-case expansion to ensure correct branch range calculations and code layout. Update the Size field for each ARM sub-architecture: - ARM: 28 → 40 bytes (10 instructions @ 4 bytes when r3 spill needed) - Thumb2: 32 → 34 bytes (mixed 16/32-bit instructions with r3 spill) - Thumb1: 50 → 38 bytes (19 instructions @ 2 bytes with r2+r3 spills) The ARM and Thumb2 sizes were underestimating the case where the target register is r12, requiring r3 to be used as scratch and spilled/restored. The Thumb1 size was overestimated and has been corrected to the actual worst-case of 19 instructions.
…4917) The KCFI_CHECK pseudo-instruction size for ARM got miscalculated. These should represent worst-case expansion to ensure correct branch range calculations and code layout. Update the Size field for each ARM sub-architecture: - ARM: 28 → 40 bytes (10 instructions @ 4 bytes when r3 spill needed) - Thumb2: 32 → 34 bytes (mixed 16/32-bit instructions with r3 spill) - Thumb1: 50 → 38 bytes (19 instructions @ 2 bytes with r2+r3 spills) The ARM and Thumb2 sizes were underestimating the case where the target register is r12, requiring r3 to be used as scratch and spilled/restored. The Thumb1 size was overestimated and has been corrected to the actual worst-case of 19 instructions.
…4917) The KCFI_CHECK pseudo-instruction size for ARM got miscalculated. These should represent worst-case expansion to ensure correct branch range calculations and code layout. Update the Size field for each ARM sub-architecture: - ARM: 28 → 40 bytes (10 instructions @ 4 bytes when r3 spill needed) - Thumb2: 32 → 34 bytes (mixed 16/32-bit instructions with r3 spill) - Thumb1: 50 → 38 bytes (19 instructions @ 2 bytes with r2+r3 spills) The ARM and Thumb2 sizes were underestimating the case where the target register is r12, requiring r3 to be used as scratch and spilled/restored. The Thumb1 size was overestimated and has been corrected to the actual worst-case of 19 instructions.
The KCFI_CHECK pseudo-instruction size for ARM got miscalculated. These should represent worst-case expansion to ensure correct branch range calculations and code layout.
Update the Size field for each ARM sub-architecture:
The ARM and Thumb2 sizes were underestimating the case where the target register is r12, requiring r3 to be used as scratch and spilled/restored. The Thumb1 size was overestimated and has been corrected to the actual worst-case of 19 instructions.
cc @nathanchance