[llvm] [RISC-V] Adjust trampoline code for branch control flow protection (PR #141949)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 12:55:57 PDT 2025


================
@@ -8310,35 +8324,74 @@ SDValue RISCVTargetLowering::lowerINIT_TRAMPOLINE(SDValue Op,
   };
 
   SDValue OutChains[6];
-
-  uint32_t Encodings[] = {
-      // auipc t2, 0
-      // Loads the current PC into t2.
-      GetEncoding(MCInstBuilder(RISCV::AUIPC).addReg(RISCV::X7).addImm(0)),
-      // ld t0, 24(t2)
-      // Loads the function address into t0. Note that we are using offsets
-      // pc-relative to the first instruction of the trampoline.
-      GetEncoding(
-          MCInstBuilder(RISCV::LD).addReg(RISCV::X5).addReg(RISCV::X7).addImm(
-              FunctionAddressOffset)),
-      // ld t2, 16(t2)
-      // Load the value of the static chain.
-      GetEncoding(
-          MCInstBuilder(RISCV::LD).addReg(RISCV::X7).addReg(RISCV::X7).addImm(
-              StaticChainOffset)),
-      // jalr t0
-      // Jump to the function.
-      GetEncoding(MCInstBuilder(RISCV::JALR)
-                      .addReg(RISCV::X0)
-                      .addReg(RISCV::X5)
-                      .addImm(0))};
+  SDValue OutChainsLPAD[7];
----------------
lenary wrote:

A SmallVector can be turned into an ArrayRef implicitly (using the size it has) - this will happen automatically in the `getNode()` call if you pass a SmallVector.

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


More information about the llvm-commits mailing list