[llvm] [hwasan] Add intrinsics for fixed shadow on Aarch64 (PR #89319)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 15:15:43 PDT 2024


================
@@ -625,14 +635,32 @@ void AArch64AsmPrinter::emitHwasanMemaccessSymbols(Module &M) {
                                      .addImm(4)
                                      .addImm(55),
                                  *STI);
-    OutStreamer->emitInstruction(
-        MCInstBuilder(AArch64::LDRBBroX)
-            .addReg(AArch64::W16)
-            .addReg(IsShort ? AArch64::X20 : AArch64::X9)
-            .addReg(AArch64::X16)
-            .addImm(0)
-            .addImm(0),
-        *STI);
+
+    if (HwasanFixedShadowBase.has_value()) {
+      OutStreamer->emitInstruction(
+          MCInstBuilder(AArch64::MOVZXi)
+              .addReg(AArch64::X17)
+              .addImm(HwasanFixedShadowBase.value() >> 32)
+              .addImm(32),
+          *STI);
+      OutStreamer->emitInstruction(MCInstBuilder(AArch64::LDRBBroX)
----------------
thurstond wrote:

In the existing (non-fixed shadow) version, x20 or x9 are used to pass the shadow base offset. This difference is eliminated in the fixed shadow version because we no longer need to pass the offset as a parameter.

emitHwasanMemaccessSymbols has some other code that does vary for short vs. non-short, which applies to both fixed and non-fixed shadow, so it's not part of this patch:
```
    if (IsShort) {
      OutStreamer->emitInstruction(MCInstBuilder(AArch64::SUBSWri)
                                       .addReg(AArch64::WZR)
                                       .addReg(AArch64::W16)
                                       .addImm(15)
                                       .addImm(0),
                                   *STI);
      MCSymbol *HandleMismatchSym = OutContext.createTempSymbol();
    ...
```

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


More information about the llvm-commits mailing list