|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | #include "AArch64.h" |
| 14 | +#include "clang/Basic/DiagnosticDriver.h" |
14 | 15 | #include "clang/Basic/LangOptions.h" |
| 16 | +#include "clang/Basic/PointerAuthOptions.h" |
15 | 17 | #include "clang/Basic/TargetBuiltins.h" |
16 | 18 | #include "clang/Basic/TargetInfo.h" |
17 | 19 | #include "llvm/ADT/APSInt.h" |
@@ -197,6 +199,34 @@ AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple, |
197 | 199 | Opts.EABIVersion == llvm::EABI::GNU ? "\01_mcount" : "mcount"; |
198 | 200 | } |
199 | 201 |
|
| 202 | +void AArch64TargetInfo::validatePAuthOptions( |
| 203 | + DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts) const { |
| 204 | + auto NeedsHWSupport = [](const PointerAuthSchema &Schema) { |
| 205 | + switch (Schema.getKind()) { |
| 206 | + case PointerAuthSchema::Kind::None: |
| 207 | + case PointerAuthSchema::Kind::Soft: |
| 208 | + return false; |
| 209 | + case PointerAuthSchema::Kind::ARM8_3: |
| 210 | + return true; |
| 211 | + } |
| 212 | + llvm_unreachable("Unexpected authentication kind"); |
| 213 | + }; |
| 214 | + |
| 215 | + bool NeedsFeatPAuth = false; |
| 216 | + NeedsFeatPAuth |= CGOpts.PointerAuth.ReturnAddresses; |
| 217 | + for (auto Schema : CGOpts.PointerAuth.getAllUsedSchemas()) |
| 218 | + NeedsFeatPAuth |= NeedsHWSupport(Schema); |
| 219 | + |
| 220 | + if (NeedsFeatPAuth && !HasPAuth) |
| 221 | + Diags.Report(diag::err_pauth_cpu_feature_missing); |
| 222 | +} |
| 223 | + |
| 224 | +void AArch64TargetInfo::adjustTargetOptions(DiagnosticsEngine &Diags, |
| 225 | + const CodeGenOptions &CGOpts, |
| 226 | + TargetOptions &TargetOpts) const { |
| 227 | + validatePAuthOptions(Diags, CGOpts); |
| 228 | +} |
| 229 | + |
200 | 230 | StringRef AArch64TargetInfo::getABI() const { return ABI; } |
201 | 231 |
|
202 | 232 | bool AArch64TargetInfo::setABI(const std::string &Name) { |
|
0 commit comments