[llvm] [ARM] Fix access to dso_preemptable __stack_chk_guard with static relocation model (PR #70014)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 16:53:53 PDT 2023


================
@@ -104,11 +104,12 @@ void ARMInstrInfo::expandLoadStackGuard(MachineBasicBlock::iterator MI) const {
   const GlobalValue *GV =
       cast<GlobalValue>((*MI->memoperands_begin())->getValue());
 
-  if (!Subtarget.useMovt() || Subtarget.isGVInGOT(GV)) {
----------------
MaskRay wrote:

Technically with dso_preemptable `__stack_chk_guard` with static relocation model, we could emit
```
        ldr     r0, .LCPI0_0   // from LDRLIT_ga_abs
        ldr     r0, [r0]
        ldr     r0, [r0]
...
.LCPI0_0:
        .long   __stack_chk_guard at GOT
```

Unfortunately, such a GOT-generating relocation with computation `GOT(S) + A` does not exist for AArch32.
(The integrated assembler and GNU assembler have an issue that `@GOT` is not rejected)

Therefore, we have to use LDRLIT_ga_pcrel and expand to the PIC+GOT code sequence:
```
.LCPI0_0:
.Ltmp0:
        .long   __stack_chk_guard(GOT_PREL)-((.LPC0_0+8)-.Ltmp0)
```

https://github.com/llvm/llvm-project/pull/70014


More information about the llvm-commits mailing list