Skip to content

[ptrauth] Upstream ptrauth changes to DWARFASTParserClang #8239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ enum class ShaderStage {
Invalid,
};

enum class PointerAuthenticationMode : unsigned {
None,
Strip,
SignAndStrip,
SignAndAuth
};

/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
/// this large collection of bitfields is a trivial class type.
class LangOptionsBase {
Expand Down
58 changes: 58 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
case DW_TAG_const_type:
case DW_TAG_restrict_type:
case DW_TAG_volatile_type:
case DW_TAG_LLVM_ptrauth_type:
case DW_TAG_atomic_type:
case DW_TAG_unspecified_type: {
type_sp = ParseTypeModifier(sc, die, attrs);
Expand Down Expand Up @@ -676,6 +677,63 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
case DW_TAG_volatile_type:
encoding_data_type = Type::eEncodingIsVolatileUID;
break;
case DW_TAG_LLVM_ptrauth_type: {
DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
// FIXME: Fully resolving the type here may affect performance.
Type *res_type = dwarf->ResolveType(ptr_die);
if (!res_type)
break;
attrs.type.Clear();
encoding_data_type = Type::eEncodingIsUID;
resolve_state = Type::ResolveState::Full;

// Apply the ptrauth qualifier to the resolved type.
auto *ptr_type =
(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) {
return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
};
const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
const bool authenticates_null_values =
getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
const bool is_restricted_integral = !ptr_type->isPointerType();
const unsigned authentication_mode_int = getAttr(
DW_AT_LLVM_ptrauth_authentication_mode,
static_cast<unsigned>(clang::PointerAuthenticationMode::SignAndAuth));
clang::PointerAuthenticationMode authentication_mode =
clang::PointerAuthenticationMode::SignAndAuth;
if (authentication_mode_int >=
static_cast<unsigned>(clang::PointerAuthenticationMode::None) &&
authentication_mode_int <=
static_cast<unsigned>(
clang::PointerAuthenticationMode::SignAndAuth)) {
authentication_mode = static_cast<clang::PointerAuthenticationMode>(
authentication_mode_int);
} else {
dwarf->GetObjectFile()->GetModule()->ReportError(
"[{0:x16}]: invalid pointer authentication mode method {1:x4}",
die.GetOffset(), authentication_mode_int);
}

// FIXME: Use these variables when PointerAuthQualifier is more complete
// upstream.
(void)isapointer;
(void)authenticates_null_values;
(void)is_restricted_integral;
(void)authentication_mode;

clang::Qualifiers qualifiers;
clang::PointerAuthQualifier ptr_auth(key, addr_disc, extra);
qualifiers.setPointerAuth(ptr_auth);
auto &ctx = m_ast.getASTContext();
auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
clang_type =
CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
break;
}
case DW_TAG_atomic_type:
encoding_data_type = Type::eEncodingIsAtomicUID;
break;
Expand Down