Skip to content

Commit 513d9f2

Browse files
authored
[ptrauth] Teach LLVM & LLDB about LLVM_ptrauth_authentication_mode (#82272)
Teach LLVM & LLDB about `DW_AT_LLVM_ptrauth_authentication_mode`
1 parent 61a96e5 commit 513d9f2

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,14 @@ void DWARFDIE::AppendTypeName(Stream &s) const {
316316
GetAttributeValueAsUnsigned(DW_AT_LLVM_ptrauth_extra_discriminator, 0);
317317
bool isaPointer =
318318
GetAttributeValueAsUnsigned(DW_AT_LLVM_ptrauth_isa_pointer, 0);
319-
s.Printf("__ptrauth(%d, %d, 0x0%x, %d)", key, isAddressDiscriminated,
320-
extraDiscriminator, isaPointer);
319+
bool authenticatesNullValues = GetAttributeValueAsUnsigned(
320+
DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
321+
unsigned authenticationMode =
322+
GetAttributeValueAsUnsigned(DW_AT_LLVM_ptrauth_authentication_mode, 3);
323+
324+
s.Printf("__ptrauth(%d, %d, 0x0%x, %d, %d, %d)", key,
325+
isAddressDiscriminated, extraDiscriminator, isaPointer,
326+
authenticatesNullValues, authenticationMode);
321327
break;
322328
}
323329
default:

llvm/include/llvm/BinaryFormat/Dwarf.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ HANDLE_DW_AT(0x3e06, LLVM_ptrauth_extra_discriminator, 0, LLVM)
611611
HANDLE_DW_AT(0x3e07, LLVM_apinotes, 0, APPLE)
612612
HANDLE_DW_AT(0x3e08, LLVM_ptrauth_isa_pointer, 0, LLVM)
613613
HANDLE_DW_AT(0x3e09, LLVM_ptrauth_authenticates_null_values, 0, LLVM)
614+
HANDLE_DW_AT(0x3e0a, LLVM_ptrauth_authentication_mode, 0, LLVM)
614615

615616
// Apple extensions.
616617

llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ void DWARFTypePrinter::appendUnqualifiedNameAfter(
251251
optionsVec.push_back("isa-pointer");
252252
if (getValOrNull(DW_AT_LLVM_ptrauth_authenticates_null_values))
253253
optionsVec.push_back("authenticates-null-values");
254+
if (auto AuthenticationMode =
255+
D.find(DW_AT_LLVM_ptrauth_authentication_mode)) {
256+
switch (*AuthenticationMode->getAsUnsignedConstant()) {
257+
case 0:
258+
case 1:
259+
optionsVec.push_back("strip");
260+
break;
261+
case 2:
262+
optionsVec.push_back("sign-and-strip");
263+
break;
264+
default:
265+
// Default authentication policy
266+
break;
267+
}
268+
}
254269
std::string options;
255270
for (const auto *option : optionsVec) {
256271
if (options.size())

llvm/test/tools/llvm-dwarfdump/AArch64/ptrauth.s

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323

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

2828
# CHECK: 0x0000005a: DW_TAG_LLVM_ptrauth_type
2929
# CHECK: DW_AT_LLVM_ptrauth_key (0x04)
3030
# CHECK: DW_AT_LLVM_ptrauth_address_discriminated (true)
3131
# CHECK: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d4)
3232
# CHECK: DW_AT_LLVM_ptrauth_authenticates_null_values (true)
3333

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

38-
# CHECK: 0x0000006d: DW_TAG_LLVM_ptrauth_type
38+
# CHECK: 0x0000006e: DW_TAG_LLVM_ptrauth_type
3939
# CHECK: DW_AT_LLVM_ptrauth_key (0x04)
4040
# CHECK: DW_AT_LLVM_ptrauth_address_discriminated (true)
4141
# CHECK: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d5)
@@ -44,7 +44,7 @@
4444

4545
.section __TEXT,__text,regular,pure_instructions
4646
.file 1 "/" "/tmp/p.c"
47-
.comm _p,8 ; @p
47+
.comm _p,8,3 ; @p
4848
.section __DWARF,__debug_abbrev,regular,debug
4949
Lsection_abbrev:
5050
.byte 1 ; Abbreviation Code
@@ -140,6 +140,8 @@ Lsection_abbrev:
140140
.byte 5 ; DW_FORM_data2
141141
.ascii "\211|" ; DW_AT_LLVM_ptrauth_authenticates_null_values
142142
.byte 25 ; DW_FORM_flag_present
143+
.ascii "\212|" ; DW_AT_LLVM_ptrauth_authentication_mode
144+
.byte 11 ; DW_FORM_data1
143145
.byte 0 ; EOM(1)
144146
.byte 0 ; EOM(2)
145147
.byte 8 ; Abbreviation Code
@@ -157,6 +159,8 @@ Lsection_abbrev:
157159
.byte 25 ; DW_FORM_flag_present
158160
.ascii "\211|" ; DW_AT_LLVM_ptrauth_authenticates_null_values
159161
.byte 25 ; DW_FORM_flag_present
162+
.ascii "\212|" ; DW_AT_LLVM_ptrauth_authentication_mode
163+
.byte 11 ; DW_FORM_data1
160164
.byte 0 ; EOM(1)
161165
.byte 0 ; EOM(2)
162166
.byte 0 ; EOM(3)
@@ -170,7 +174,7 @@ Ldebug_info_start0:
170174
.set Lset1, Lsection_abbrev-Lsection_abbrev ; Offset Into Abbrev. Section
171175
.long Lset1
172176
.byte 8 ; Address Size (in bytes)
173-
.byte 1 ; Abbrev [1] 0xb:0x6b DW_TAG_compile_unit
177+
.byte 1 ; Abbrev [1] 0xb:0x6d DW_TAG_compile_unit
174178
.long 0 ; DW_AT_producer
175179
.short 12 ; DW_AT_language
176180
.long 1 ; DW_AT_name
@@ -210,25 +214,27 @@ Ldebug_info_start0:
210214
; DW_AT_external
211215
.byte 1 ; DW_AT_decl_file
212216
.byte 1 ; DW_AT_decl_line
213-
.byte 7 ; Abbrev [7] 0x5a:0x8 DW_TAG_LLVM_ptrauth_type
217+
.byte 7 ; Abbrev [7] 0x5a:0x9 DW_TAG_LLVM_ptrauth_type
214218
.long 59 ; DW_AT_type
215219
.byte 4 ; DW_AT_LLVM_ptrauth_key
216220
; DW_AT_LLVM_ptrauth_address_discriminated
217221
.short 1236 ; DW_AT_LLVM_ptrauth_extra_discriminator
218222
; DW_AT_LLVM_ptrauth_authenticates_null_values
219-
.byte 5 ; Abbrev [5] 0x62:0xb DW_TAG_variable
223+
.byte 1 ; DW_AT_LLVM_ptrauth_authentication_mode
224+
.byte 5 ; Abbrev [5] 0x63:0xb DW_TAG_variable
220225
.long 21 ; DW_AT_name
221-
.long 109 ; DW_AT_type
226+
.long 110 ; DW_AT_type
222227
; DW_AT_external
223228
.byte 1 ; DW_AT_decl_file
224229
.byte 1 ; DW_AT_decl_line
225-
.byte 8 ; Abbrev [8] 0x6d:0x8 DW_TAG_LLVM_ptrauth_type
230+
.byte 8 ; Abbrev [8] 0x6e:0x9 DW_TAG_LLVM_ptrauth_type
226231
.long 59 ; DW_AT_type
227232
.byte 4 ; DW_AT_LLVM_ptrauth_key
228233
; DW_AT_LLVM_ptrauth_address_discriminated
229234
.short 1237 ; DW_AT_LLVM_ptrauth_extra_discriminator
230235
; DW_AT_LLVM_ptrauth_isa_pointer
231236
; DW_AT_LLVM_ptrauth_authenticates_null_values
237+
.byte 2 ; DW_AT_LLVM_ptrauth_authentication_mode
232238
.byte 0 ; End Of Children Mark
233239
Ldebug_info_end0:
234240
.section __DWARF,__debug_str,regular,debug

0 commit comments

Comments
 (0)