From a34910a6e58f4c441b1ef314898308720542ce6c Mon Sep 17 00:00:00 2001 From: Daniil Kovalev Date: Thu, 25 Jan 2024 00:32:48 +0300 Subject: [PATCH] [AArch64][PAC][CodeGen] Fix emitting `DW_AT_LLVM_ptrauth_address_discriminated` The Dwarf attribute `DW_AT_LLVM_ptrauth_address_discriminated` was emitted for all ptrauth-qualified types, even if the address discrimination was disabled. This was related to incorrect usage of `std::optional` holding the value of the attribute. --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 2 +- llvm/test/DebugInfo/AArch64/ptrauth.ll | 67 +++++++++++++---------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 97eda02a730b..f42cf9cf8727 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -805,7 +805,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) { if (auto Key = DTy->getPtrAuthKey()) addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_key, dwarf::DW_FORM_data1, *Key); if (auto AddrDisc = DTy->isPtrAuthAddressDiscriminated()) - if (AddrDisc) + if (AddrDisc.value()) addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_address_discriminated); if (auto Disc = DTy->getPtrAuthExtraDiscriminator()) addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_extra_discriminator, diff --git a/llvm/test/DebugInfo/AArch64/ptrauth.ll b/llvm/test/DebugInfo/AArch64/ptrauth.ll index 067063c4d1d5..4f84fe4f9629 100644 --- a/llvm/test/DebugInfo/AArch64/ptrauth.ll +++ b/llvm/test/DebugInfo/AArch64/ptrauth.ll @@ -1,35 +1,41 @@ ; RUN: llc %s -filetype=obj -mtriple arm64e-apple-darwin -o - \ ; RUN: | llvm-dwarfdump - | FileCheck %s -; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d2)") +; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 0, 0x04d2)") ; CHECK: 0x{{0+}}[[TY]]: DW_TAG_LLVM_ptrauth_type ; CHECK-NEXT: DW_AT_type {{.*}}"void *" ; CHECK-NEXT: DW_AT_LLVM_ptrauth_key (0x04) -; CHECK-NEXT: DW_AT_LLVM_ptrauth_address_discriminated (true) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d2) -; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d3, "isa-pointer")") +; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d3)") ; CHECK: 0x{{0+}}[[TY]]: DW_TAG_LLVM_ptrauth_type ; CHECK-NEXT: DW_AT_type {{.*}}"void *" ; CHECK-NEXT: DW_AT_LLVM_ptrauth_key (0x04) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_address_discriminated (true) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d3) -; CHECK-NEXT: DW_AT_LLVM_ptrauth_isa_pointer (true) -; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d4, "authenticates-null-values")") +; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d4, "isa-pointer")") ; CHECK: 0x{{0+}}[[TY]]: DW_TAG_LLVM_ptrauth_type ; CHECK-NEXT: DW_AT_type {{.*}}"void *" ; CHECK-NEXT: DW_AT_LLVM_ptrauth_key (0x04) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_address_discriminated (true) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d4) -; CHECK-NEXT: DW_AT_LLVM_ptrauth_authenticates_null_values (true) +; CHECK-NEXT: DW_AT_LLVM_ptrauth_isa_pointer (true) -; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d5, "isa-pointer,authenticates-null-values")") +; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d5, "authenticates-null-values")") ; CHECK: 0x{{0+}}[[TY]]: DW_TAG_LLVM_ptrauth_type ; CHECK-NEXT: DW_AT_type {{.*}}"void *" ; CHECK-NEXT: DW_AT_LLVM_ptrauth_key (0x04) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_address_discriminated (true) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d5) +; CHECK-NEXT: DW_AT_LLVM_ptrauth_authenticates_null_values (true) + +; CHECK: DW_AT_type (0x{{0+}}[[TY:.*]] "void *__ptrauth(4, 1, 0x04d6, "isa-pointer,authenticates-null-values")") +; CHECK: 0x{{0+}}[[TY]]: DW_TAG_LLVM_ptrauth_type +; CHECK-NEXT: DW_AT_type {{.*}}"void *" +; CHECK-NEXT: DW_AT_LLVM_ptrauth_key (0x04) +; CHECK-NEXT: DW_AT_LLVM_ptrauth_address_discriminated (true) +; CHECK-NEXT: DW_AT_LLVM_ptrauth_extra_discriminator (0x04d6) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_isa_pointer (true) ; CHECK-NEXT: DW_AT_LLVM_ptrauth_authenticates_null_values (true) @@ -37,25 +43,28 @@ target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" @p = common global i8* null, align 8, !dbg !0 -!llvm.dbg.cu = !{!8} -!llvm.module.flags = !{!16, !17} - -!0 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression()) -!1 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) -!2 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression()) -!3 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) -!4 = distinct !DIGlobalVariable(name: "p1", scope: !8, file: !9, line: 1, type: !12, isLocal: false, isDefinition: true) -!5 = distinct !DIGlobalVariable(name: "p2", scope: !8, file: !9, line: 1, type: !13, isLocal: false, isDefinition: true) -!6 = distinct !DIGlobalVariable(name: "p3", scope: !8, file: !9, line: 1, type: !14, isLocal: false, isDefinition: true) -!7 = distinct !DIGlobalVariable(name: "p4", scope: !8, file: !9, line: 1, type: !15, isLocal: false, isDefinition: true) -!8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !9, emissionKind: FullDebug, globals: !11) -!9 = !DIFile(filename: "/tmp/p.c", directory: "/") -!10 = !{} -!11 = !{!0,!1,!2,!3} -!12 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !18, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1234) -!13 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !18, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1235, ptrAuthIsaPointer: true) -!14 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !18, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1236, ptrAuthAuthenticatesNullValues: true) -!15 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !18, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1237, ptrAuthIsaPointer: true, ptrAuthAuthenticatesNullValues: true) -!16 = !{i32 2, !"Dwarf Version", i32 4} -!17 = !{i32 2, !"Debug Info Version", i32 3} -!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null) +!llvm.dbg.cu = !{!10} +!llvm.module.flags = !{!19, !20} + +!0 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) +!1 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression()) +!2 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) +!3 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression()) +!4 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression()) +!5 = distinct !DIGlobalVariable(name: "p1", scope: !10, file: !11, line: 1, type: !14, isLocal: false, isDefinition: true) +!6 = distinct !DIGlobalVariable(name: "p2", scope: !10, file: !11, line: 1, type: !15, isLocal: false, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "p3", scope: !10, file: !11, line: 1, type: !16, isLocal: false, isDefinition: true) +!8 = distinct !DIGlobalVariable(name: "p4", scope: !10, file: !11, line: 1, type: !17, isLocal: false, isDefinition: true) +!9 = distinct !DIGlobalVariable(name: "p5", scope: !10, file: !11, line: 1, type: !18, isLocal: false, isDefinition: true) +!10 = distinct !DICompileUnit(language: DW_LANG_C99, file: !11, emissionKind: FullDebug, globals: !13) +!11 = !DIFile(filename: "/tmp/p.c", directory: "/") +!12 = !{} +!13 = !{!0,!1,!2,!3,!4} +!14 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !21, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: false, ptrAuthExtraDiscriminator: 1234) +!15 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !21, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1235) +!16 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !21, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1236, ptrAuthIsaPointer: true) +!17 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !21, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1237, ptrAuthAuthenticatesNullValues: true) +!18 = !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type, baseType: !21, ptrAuthKey: 4, ptrAuthIsAddressDiscriminated: true, ptrAuthExtraDiscriminator: 1238, ptrAuthIsaPointer: true, ptrAuthAuthenticatesNullValues: true) +!19 = !{i32 2, !"Dwarf Version", i32 4} +!20 = !{i32 2, !"Debug Info Version", i32 3} +!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null)