[Lldb-commits] [lldb] 513d9f2 - [ptrauth] Teach LLVM & LLDB about LLVM_ptrauth_authentication_mode (#82272)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Feb 19 15:29:03 PST 2024
Author: Jonas Devlieghere
Date: 2024-02-19T15:29:00-08:00
New Revision: 513d9f2395ea017e72602ca6e747a2e061ab8c3f
URL: https://github.com/llvm/llvm-project/commit/513d9f2395ea017e72602ca6e747a2e061ab8c3f
DIFF: https://github.com/llvm/llvm-project/commit/513d9f2395ea017e72602ca6e747a2e061ab8c3f.diff
LOG: [ptrauth] Teach LLVM & LLDB about LLVM_ptrauth_authentication_mode (#82272)
Teach LLVM & LLDB about `DW_AT_LLVM_ptrauth_authentication_mode`
Added:
Modified:
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
llvm/include/llvm/BinaryFormat/Dwarf.def
llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
llvm/test/tools/llvm-dwarfdump/AArch64/ptrauth.s
Removed:
################################################################################
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index d4446befd83b05..4884374ef94729 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -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:
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.def b/llvm/include/llvm/BinaryFormat/Dwarf.def
index 3a08eeaa791aa6..e70b58d5ea50fc 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.def
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -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.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
index ef8ded8ebb66c1..05dee8a3d71298 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
@@ -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())
diff --git a/llvm/test/tools/llvm-dwarfdump/AArch64/ptrauth.s b/llvm/test/tools/llvm-dwarfdump/AArch64/ptrauth.s
index d24a60d99bdac3..befd0fa86ef99c 100644
--- a/llvm/test/tools/llvm-dwarfdump/AArch64/ptrauth.s
+++ b/llvm/test/tools/llvm-dwarfdump/AArch64/ptrauth.s
@@ -23,7 +23,7 @@
# 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)
@@ -31,11 +31,11 @@
# 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)
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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
More information about the lldb-commits
mailing list