[llvm] [ARM] Honour -mno-movt in stack protector handling (PR #109022)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 10:37:08 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-arm
Author: Ard Biesheuvel (ardbiesheuvel)
<details>
<summary>Changes</summary>
When -mno-movt is passed to Clang, the ARM codegen correctly avoids movt/movw pairs to take the address of __stack_chk_guard in the stack protector code emitted into the function pro- and epilogues. However, the Thumb2 codegen fails to do so, and happily emits movw/movt pairs unless it is generating an ELF binary and the symbol might be in a different DSO. Let's incorporate a check for useMovt() in the logic here, so movt/movw are never emitted when -mno-movt is specified.
Suggestions welcome for how/where to add a test case for this.
---
Full diff: https://github.com/llvm/llvm-project/pull/109022.diff
1 Files Affected:
- (modified) llvm/lib/Target/ARM/Thumb2InstrInfo.cpp (+2-1)
``````````diff
diff --git a/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp b/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp
index d1e07b6703a5e6..ce6bc0681a5028 100644
--- a/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp
+++ b/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp
@@ -264,7 +264,8 @@ void Thumb2InstrInfo::expandLoadStackGuard(
}
const auto *GV = cast<GlobalValue>((*MI->memoperands_begin())->getValue());
- if (MF.getSubtarget<ARMSubtarget>().isTargetELF() && !GV->isDSOLocal())
+ const ARMSubtarget &Subtarget = MF.getSubtarget<ARMSubtarget>();
+ if ((Subtarget.isTargetELF() && !GV->isDSOLocal()) || !Subtarget.useMovt())
expandLoadStackGuardBase(MI, ARM::t2LDRLIT_ga_pcrel, ARM::t2LDRi12);
else if (MF.getTarget().isPositionIndependent())
expandLoadStackGuardBase(MI, ARM::t2MOV_ga_pcrel, ARM::t2LDRi12);
``````````
</details>
https://github.com/llvm/llvm-project/pull/109022
More information about the llvm-commits
mailing list