diff options
author | Akira Hatanaka <ahatanak@gmail.com> | 2024-07-11 09:09:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-11 09:09:20 -0700 |
commit | ae18b9410297963a379e03b94eae7433ff69a62b (patch) | |
tree | df73765bfae37808db79f30846151405bb177f1e /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 1cbddcebb9a9f97ed04f35a859e31d55f6b9b824 (diff) | |
download | llvm-ae18b9410297963a379e03b94eae7433ff69a62b.zip llvm-ae18b9410297963a379e03b94eae7433ff69a62b.tar.gz llvm-ae18b9410297963a379e03b94eae7433ff69a62b.tar.bz2 |
[PAC] Implement function pointer type discrimination (#96992)
Give users an option (-fptrauth-function-pointer-type-discrimination) to
sign a function pointer using a non-zero discriminator based on the
function type.
The discriminator is computed by first translating the function type to
a string and then computing the hash value of the string. Two function
types that are compatible in C must be translated to the same string
with the exception of function types that use typedefs of anonymous
structs in their return type or parameter types.
This patch doesn't have the code to resign function pointers, which is
needed when a function pointer is converted to a different function
type. That will be implemented in another patch.
Co-authored-by: John McCall <rjmccall@apple.com>
---------
Co-authored-by: John McCall <rjmccall@apple.com>
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 0082c15..bf57add 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1479,8 +1479,10 @@ void CompilerInvocation::setDefaultPointerAuthOptions( using Key = PointerAuthSchema::ARM8_3Key; using Discrimination = PointerAuthSchema::Discrimination; // If you change anything here, be sure to update <ptrauth.h>. - Opts.FunctionPointers = - PointerAuthSchema(Key::ASIA, false, Discrimination::None); + Opts.FunctionPointers = PointerAuthSchema( + Key::ASIA, false, + LangOpts.PointerAuthFunctionTypeDiscrimination ? Discrimination::Type + : Discrimination::None); Opts.CXXVTablePointers = PointerAuthSchema( Key::ASDA, LangOpts.PointerAuthVTPtrAddressDiscrimination, @@ -3411,6 +3413,8 @@ static void GeneratePointerAuthArgs(const LangOptions &Opts, GenerateArg(Consumer, OPT_fptrauth_vtable_pointer_type_discrimination); if (Opts.PointerAuthInitFini) GenerateArg(Consumer, OPT_fptrauth_init_fini); + if (Opts.PointerAuthFunctionTypeDiscrimination) + GenerateArg(Consumer, OPT_fptrauth_function_pointer_type_discrimination); } static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args, @@ -3424,6 +3428,8 @@ static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args, Opts.PointerAuthVTPtrTypeDiscrimination = Args.hasArg(OPT_fptrauth_vtable_pointer_type_discrimination); Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini); + Opts.PointerAuthFunctionTypeDiscrimination = + Args.hasArg(OPT_fptrauth_function_pointer_type_discrimination); } /// Check if input file kind and language standard are compatible. |