[llvm] [ARM, ELF] 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
Wed Oct 25 15:34:05 PDT 2023


================
@@ -2019,7 +2019,9 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
     if (M.getDirectAccessExternalData() &&
         !TM.getTargetTriple().isWindowsGNUEnvironment() &&
         !TM.getTargetTriple().isOSFreeBSD() &&
-        !TM.getTargetTriple().isOSDarwin())
+        (!TM.getTargetTriple().isOSDarwin() ||
+         (TM.getTargetTriple().isARM() &&
----------------
MaskRay wrote:

I believe this patch does not change Mach-O behavior.

This `llvm/lib/CodeGen/TargetLoweringBase.cpp` change can also be removed and the behavior does not change. Sorry for including it here. However, the file is somewhat related.

I've added a commit to this PR and this now becomes
```
    if (M.getDirectAccessExternalData() &&
        !TM.getTargetTriple().isWindowsGNUEnvironment() &&
        !TM.getTargetTriple().isOSFreeBSD() &&
        (!TM.getTargetTriple().isOSDarwin() ||
         TM.getRelocationModel() == Reloc::Static))
      GV->setDSOLocal(true);
  }
```

This `TM.getRelocationModel() == Reloc::Static` condition refines 1ec30106a557b2c63d6d6c6b93634674aa65cdb9 .

I think Mach-O's static relocation model largely ignores `dso_local` IR markers and relies on `TM.shouldAssumeDSOLocal` to return true for static relocation code model. However, it seems more appropriate to me to encode this information correctly, which can probably enable code share between ELF and Mach-O.

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


More information about the llvm-commits mailing list