[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

Daniil Kovalev via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 5 05:50:22 PDT 2024


================
@@ -1537,11 +1570,16 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
     if (!isAArch64 && PBP.Key == "b_key")
       D.Diag(diag::warn_unsupported_branch_protection)
           << "b-key" << A->getAsString(Args);
+    if (!isAArch64 && PBP.HasPauthABI)
+      D.Diag(diag::warn_unsupported_branch_protection)
+          << "pauthabi" << A->getAsString(Args);
     Scope = PBP.Scope;
     Key = PBP.Key;
     BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
     IndirectBranches = PBP.BranchTargetEnforcement;
     GuardedControlStack = PBP.GuardedControlStack;
+    if (isAArch64 && PBP.HasPauthABI)
----------------
kovdan01 wrote:

@DanielKristofKiss Thanks! Yes, I now see that authenticating branch instructions also set the `PSTATE.BTYPE`. So, I agree that we can allow pauthabi+bti. The codegen when `pauthabi+bti` is passed as branch protection looks OK on downstream:
- for functions which do not sign LR (w/o `pacibsp` in the beginning, e.g. leaf functions), a proper `bti` instruction is emitted in the beginning of the function;
- for function which sign LR (with `pacibsp` in the beginning), no additional `bti` instruction is emitted since `pacibsp` also has `bti` built-in, see `SetBTypeCompatible` in https://developer.arm.com/documentation/ddi0602/2022-06/Base-Instructions/PACIB--PACIB1716--PACIBSP--PACIBZ--PACIZB--Pointer-Authentication-Code-for-Instruction-address--using-key-B-

In mainline, codegen with `-fptrauth-returns` is not implemented yet, so I can't provide tests verifying generated assembly correctness right now. I'll add them as soon as codegen support for this flag is merged.

I've implemented a check which only allows `bti` with `pauthabi` and does not allow `pac-ret[+leaf,+pc,+b-key]` and `gcs`. See 3067c934a957eed21cb3ae73404675242425e5cb

Tagging @smithp35



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


More information about the llvm-commits mailing list