Skip to content

[ptrauth] Teach LLVM & LLDB about LLVM_ptrauth_authentication_mode #82272

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
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
10 changes: 8 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,14 @@ void DWARFDIE::AppendTypeName(Stream &s) const {
GetAttributeValueAsUnsigned(DW_AT_LLVM_ptrauth_extra_discriminator, 0);
bool isaPointer =
GetAttributeValueAsUnsigned(DW_AT_LLVM_ptrauth_isa_pointer, 0);
s.Printf("__ptrauth(%d, %d, 0x0%x, %d)", key, isAddressDiscriminated,
extraDiscriminator, isaPointer);
bool authenticatesNullValues = GetAttributeValueAsUnsigned(
DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
unsigned authenticationMode =
GetAttributeValueAsUnsigned(DW_AT_LLVM_ptrauth_authentication_mode, 3);

s.Printf("__ptrauth(%d, %d, 0x0%x, %d, %d, %d)", key,
isAddressDiscriminated, extraDiscriminator, isaPointer,
authenticatesNullValues, authenticationMode);
break;
}
default:
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/BinaryFormat/Dwarf.def
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ HANDLE_DW_AT(0x3e06, LLVM_ptrauth_extra_discriminator, 0, LLVM)
HANDLE_DW_AT(0x3e07, LLVM_apinotes, 0, APPLE)
HANDLE_DW_AT(0x3e08, LLVM_ptrauth_isa_pointer, 0, LLVM)
HANDLE_DW_AT(0x3e09, LLVM_ptrauth_authenticates_null_values, 0, LLVM)
HANDLE_DW_AT(0x3e0a, LLVM_ptrauth_authentication_mode, 0, LLVM)

// Apple extensions.

Expand Down
15 changes: 15 additions & 0 deletions llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ void DWARFTypePrinter::appendUnqualifiedNameAfter(
optionsVec.push_back("isa-pointer");
if (getValOrNull(DW_AT_LLVM_ptrauth_authenticates_null_values))
optionsVec.push_back("authenticates-null-values");
if (auto AuthenticationMode =
D.find(DW_AT_LLVM_ptrauth_authentication_mode)) {
switch (*AuthenticationMode->getAsUnsignedConstant()) {
case 0:
case 1:
optionsVec.push_back("strip");
break;
case 2:
optionsVec.push_back("sign-and-strip");
break;
default:
// Default authentication policy
break;
}
}
std::string options;
for (const auto *option : optionsVec) {
if (options.size())
Expand Down
26 changes: 16 additions & 10 deletions llvm/test/tools/llvm-dwarfdump/AArch64/ptrauth.s
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@

# CHECK: 0x0000004f: DW_TAG_variable
# CHECK: DW_AT_name ("p3")
# CHECK: DW_AT_type (0x0000005a "void *__ptrauth(4, 1, 0x04d4, "authenticates-null-values")")
# CHECK: DW_AT_type (0x0000005a "void *__ptrauth(4, 1, 0x04d4, "authenticates-null-values,strip")")

# CHECK: 0x0000005a: DW_TAG_LLVM_ptrauth_type
# CHECK: DW_AT_LLVM_ptrauth_key (0x04)
# CHECK: DW_AT_LLVM_ptrauth_address_discriminated (true)
# CHECK: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d4)
# CHECK: DW_AT_LLVM_ptrauth_authenticates_null_values (true)

# CHECK: 0x00000062: DW_TAG_variable
# CHECK: 0x00000063: DW_TAG_variable
# CHECK: DW_AT_name ("p4")
# CHECK: DW_AT_type (0x0000006d "void *__ptrauth(4, 1, 0x04d5, "isa-pointer,authenticates-null-values")")
# CHECK: DW_AT_type (0x0000006e "void *__ptrauth(4, 1, 0x04d5, "isa-pointer,authenticates-null-values,sign-and-strip")")

# CHECK: 0x0000006d: DW_TAG_LLVM_ptrauth_type
# CHECK: 0x0000006e: DW_TAG_LLVM_ptrauth_type
# CHECK: DW_AT_LLVM_ptrauth_key (0x04)
# CHECK: DW_AT_LLVM_ptrauth_address_discriminated (true)
# CHECK: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d5)
Expand All @@ -44,7 +44,7 @@

.section __TEXT,__text,regular,pure_instructions
.file 1 "/" "/tmp/p.c"
.comm _p,8 ; @p
.comm _p,8,3 ; @p
.section __DWARF,__debug_abbrev,regular,debug
Lsection_abbrev:
.byte 1 ; Abbreviation Code
Expand Down Expand Up @@ -140,6 +140,8 @@ Lsection_abbrev:
.byte 5 ; DW_FORM_data2
.ascii "\211|" ; DW_AT_LLVM_ptrauth_authenticates_null_values
.byte 25 ; DW_FORM_flag_present
.ascii "\212|" ; DW_AT_LLVM_ptrauth_authentication_mode
.byte 11 ; DW_FORM_data1
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 8 ; Abbreviation Code
Expand All @@ -157,6 +159,8 @@ Lsection_abbrev:
.byte 25 ; DW_FORM_flag_present
.ascii "\211|" ; DW_AT_LLVM_ptrauth_authenticates_null_values
.byte 25 ; DW_FORM_flag_present
.ascii "\212|" ; DW_AT_LLVM_ptrauth_authentication_mode
.byte 11 ; DW_FORM_data1
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 0 ; EOM(3)
Expand All @@ -170,7 +174,7 @@ Ldebug_info_start0:
.set Lset1, Lsection_abbrev-Lsection_abbrev ; Offset Into Abbrev. Section
.long Lset1
.byte 8 ; Address Size (in bytes)
.byte 1 ; Abbrev [1] 0xb:0x6b DW_TAG_compile_unit
.byte 1 ; Abbrev [1] 0xb:0x6d DW_TAG_compile_unit
.long 0 ; DW_AT_producer
.short 12 ; DW_AT_language
.long 1 ; DW_AT_name
Expand Down Expand Up @@ -210,25 +214,27 @@ Ldebug_info_start0:
; DW_AT_external
.byte 1 ; DW_AT_decl_file
.byte 1 ; DW_AT_decl_line
.byte 7 ; Abbrev [7] 0x5a:0x8 DW_TAG_LLVM_ptrauth_type
.byte 7 ; Abbrev [7] 0x5a:0x9 DW_TAG_LLVM_ptrauth_type
.long 59 ; DW_AT_type
.byte 4 ; DW_AT_LLVM_ptrauth_key
; DW_AT_LLVM_ptrauth_address_discriminated
.short 1236 ; DW_AT_LLVM_ptrauth_extra_discriminator
; DW_AT_LLVM_ptrauth_authenticates_null_values
.byte 5 ; Abbrev [5] 0x62:0xb DW_TAG_variable
.byte 1 ; DW_AT_LLVM_ptrauth_authentication_mode
.byte 5 ; Abbrev [5] 0x63:0xb DW_TAG_variable
.long 21 ; DW_AT_name
.long 109 ; DW_AT_type
.long 110 ; DW_AT_type
; DW_AT_external
.byte 1 ; DW_AT_decl_file
.byte 1 ; DW_AT_decl_line
.byte 8 ; Abbrev [8] 0x6d:0x8 DW_TAG_LLVM_ptrauth_type
.byte 8 ; Abbrev [8] 0x6e:0x9 DW_TAG_LLVM_ptrauth_type
.long 59 ; DW_AT_type
.byte 4 ; DW_AT_LLVM_ptrauth_key
; DW_AT_LLVM_ptrauth_address_discriminated
.short 1237 ; DW_AT_LLVM_ptrauth_extra_discriminator
; DW_AT_LLVM_ptrauth_isa_pointer
; DW_AT_LLVM_ptrauth_authenticates_null_values
.byte 2 ; DW_AT_LLVM_ptrauth_authentication_mode
.byte 0 ; End Of Children Mark
Ldebug_info_end0:
.section __DWARF,__debug_str,regular,debug
Expand Down