Index: llvm/lib/Target/AArch64/AArch64SLSHardening.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64SLSHardening.cpp +++ llvm/lib/Target/AArch64/AArch64SLSHardening.cpp @@ -217,7 +217,12 @@ // BR xN // barrierInsts Entry->addLiveIn(ThunkReg); - BuildMI(Entry, DebugLoc(), TII->get(AArch64::BR)).addReg(ThunkReg); + // MOV X16, ThunkReg == ORR X16, XZR, ThunkReg, LSL #0 + BuildMI(Entry, DebugLoc(), TII->get(AArch64::ORRXrs), AArch64::X16) + .addReg(AArch64::XZR) + .addReg(ThunkReg) + .addImm(0); + BuildMI(Entry, DebugLoc(), TII->get(AArch64::BR)).addReg(AArch64::X16); // Make sure the thunks do not make use of the SB extension in case there is // a function somewhere that will call to it that for some reason disabled // the SB extension locally on that function, even though it's enabled for Index: llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll =================================================================== --- llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll +++ llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll @@ -168,14 +168,16 @@ } ; HARDEN-label: __llvm_slsblr_thunk_x0: -; HARDEN: br x0 +; HARDEN: mov x16, x0 +; HARDEN: br x16 ; ISBDSB-NEXT: dsb sy ; ISBDSB-NEXT: isb ; SB-NEXT: dsb sy ; SB-NEXT: isb ; HARDEN-NEXT: .Lfunc_end ; HARDEN-label: __llvm_slsblr_thunk_x19: -; HARDEN: br x19 +; HARDEN: mov x16, x19 +; HARDEN: br x16 ; ISBDSB-NEXT: dsb sy ; ISBDSB-NEXT: isb ; SB-NEXT: dsb sy