@@ -1581,6 +1581,74 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
1581
1581
}
1582
1582
}
1583
1583
1584
+ // See DarwinClang::addClangTargetOptions()
1585
+ static void handlePAuthABIOption(const ArgList &DriverArgs,
1586
+ ArgStringList &CC1Args,
1587
+ const Driver &D) {
1588
+ // The ptrauth ABI version is 0 by default, but can be overridden.
1589
+ static const constexpr unsigned DefaultPtrauthABIVersion = 0;
1590
+
1591
+ unsigned PtrAuthABIVersion = DefaultPtrauthABIVersion;
1592
+ const Arg *A = DriverArgs.getLastArg(options::OPT_fptrauth_abi_version_EQ,
1593
+ options::OPT_fno_ptrauth_abi_version);
1594
+ bool HasVersionArg =
1595
+ A && A->getOption().matches(options::OPT_fptrauth_abi_version_EQ);
1596
+ if (HasVersionArg) {
1597
+ unsigned PtrAuthABIVersionArg;
1598
+ if (StringRef(A->getValue()).getAsInteger(10, PtrAuthABIVersionArg))
1599
+ D.Diag(diag::err_drv_invalid_value)
1600
+ << A->getAsString(DriverArgs) << A->getValue();
1601
+ else
1602
+ PtrAuthABIVersion = PtrAuthABIVersionArg;
1603
+ }
1604
+
1605
+ // Pass the ABI version to -cc1, regardless of its value, if the user asked
1606
+ // for it or if the user didn't explicitly disable it.
1607
+ if (HasVersionArg ||
1608
+ !DriverArgs.hasArg(options::OPT_fno_ptrauth_abi_version)) {
1609
+ CC1Args.push_back(DriverArgs.MakeArgString(
1610
+ "-fptrauth-abi-version=" + llvm::utostr(PtrAuthABIVersion)));
1611
+ }
1612
+
1613
+ if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
1614
+ options::OPT_fno_ptrauth_returns))
1615
+ CC1Args.push_back("-fptrauth-returns");
1616
+
1617
+ if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
1618
+ options::OPT_fno_ptrauth_intrinsics))
1619
+ CC1Args.push_back("-fptrauth-intrinsics");
1620
+
1621
+ if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
1622
+ options::OPT_fno_ptrauth_calls))
1623
+ CC1Args.push_back("-fptrauth-calls");
1624
+
1625
+ if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
1626
+ options::OPT_fno_ptrauth_auth_traps))
1627
+ CC1Args.push_back("-fptrauth-auth-traps");
1628
+
1629
+ #if 1
1630
+ if (!DriverArgs.hasArg(
1631
+ options::OPT_fptrauth_block_descriptor_pointers,
1632
+ options::OPT_fno_ptrauth_block_descriptor_pointers))
1633
+ CC1Args.push_back("-fptrauth-block-descriptor-pointers");
1634
+
1635
+ if (!DriverArgs.hasArg(
1636
+ options::OPT_fptrauth_vtable_pointer_address_discrimination,
1637
+ options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
1638
+ CC1Args.push_back("-fptrauth-vtable-pointer-address-discrimination");
1639
+
1640
+ if (!DriverArgs.hasArg(
1641
+ options::OPT_fptrauth_vtable_pointer_type_discrimination,
1642
+ options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
1643
+ CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
1644
+
1645
+ if (!DriverArgs.hasArg(
1646
+ options::OPT_fptrauth_function_pointer_type_discrimination,
1647
+ options::OPT_fno_ptrauth_function_pointer_type_discrimination))
1648
+ CC1Args.push_back("-fptrauth-function-pointer-type-discrimination");
1649
+ #endif
1650
+ }
1651
+
1584
1652
static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
1585
1653
ArgStringList &CmdArgs, bool isAArch64) {
1586
1654
const Arg *A = isAArch64
@@ -1615,9 +1683,14 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
1615
1683
if (!isAArch64 && PBP.Key == "b_key")
1616
1684
D.Diag(diag::warn_unsupported_branch_protection)
1617
1685
<< "b-key" << A->getAsString(Args);
1686
+ if (!isAArch64 && PBP.HasPauthABI)
1687
+ D.Diag(diag::warn_unsupported_branch_protection)
1688
+ << "pauthabi" << A->getAsString(Args);
1618
1689
Scope = PBP.Scope;
1619
1690
Key = PBP.Key;
1620
1691
IndirectBranches = PBP.BranchTargetEnforcement;
1692
+ if (isAArch64 && PBP.HasPauthABI)
1693
+ handlePAuthABIOption(Args, CmdArgs, D);
1621
1694
}
1622
1695
1623
1696
CmdArgs.push_back(
0 commit comments