[llvm] 15d4a84 - [PAC][ELF][AArch64] Encode signed GOT flag in PAuth core info (#96159)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 08:24:06 PDT 2024
Author: Daniil Kovalev
Date: 2024-08-06T18:24:01+03:00
New Revision: 15d4a84e7977725dc0661995963a12ff8605b03c
URL: https://github.com/llvm/llvm-project/commit/15d4a84e7977725dc0661995963a12ff8605b03c
DIFF: https://github.com/llvm/llvm-project/commit/15d4a84e7977725dc0661995963a12ff8605b03c.diff
LOG: [PAC][ELF][AArch64] Encode signed GOT flag in PAuth core info (#96159)
Treat 8th bit of version value for llvm_linux platform as signed GOT
flag.
- clang: define `PointerAuthELFGOT` LangOption and set 8th bit of
`aarch64-elf-pauthabi-version` LLVM module flag correspondingly;
- llvm-readobj: print `PointerAuthELFGOT` or `!PointerAuthELFGOT` in
version description of llvm_linux platform depending on whether the flag
is set.
Added:
Modified:
clang/include/clang/Basic/LangOptions.def
clang/lib/CodeGen/CodeGenModule.cpp
llvm/include/llvm/BinaryFormat/ELF.h
llvm/test/CodeGen/AArch64/note-gnu-property-elf-pauthabi.ll
llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index 53f15acdd5cd1..6945f8b01e91c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -175,6 +175,7 @@ BENIGN_LANGOPT(PointerAuthFunctionTypeDiscrimination, 1, 0,
LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini arrays")
LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0,
"incorporate address discrimination in authenticated function pointers in init/fini arrays")
+LANGOPT(PointerAuthELFGOT, 1, 0, "authenticate pointers from GOT")
LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes")
LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of attributes")
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 50484a00a9265..9aaf90ccfe04f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1218,11 +1218,12 @@ void CodeGenModule::Release() {
(LangOpts.PointerAuthInitFini
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI) |
(LangOpts.PointerAuthInitFiniAddressDiscrimination
- << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC);
- static_assert(
- AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC ==
- AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
- "Update when new enum items are defined");
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC) |
+ (LangOpts.PointerAuthELFGOT
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_GOT);
+ static_assert(AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_GOT ==
+ AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
+ "Update when new enum items are defined");
if (PAuthABIVersion != 0) {
getModule().addModuleFlag(llvm::Module::Error,
"aarch64-elf-pauthabi-platform",
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index 29419469775ca..c21bb41d386ac 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1800,8 +1800,9 @@ enum : unsigned {
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_VPTRTYPEDISCR = 5,
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI = 6,
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC = 7,
+ AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_GOT = 8,
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST =
- AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC,
+ AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_GOT,
};
// x86 processor feature bits.
diff --git a/llvm/test/CodeGen/AArch64/note-gnu-property-elf-pauthabi.ll b/llvm/test/CodeGen/AArch64/note-gnu-property-elf-pauthabi.ll
index 4005ff461f5e2..b2ebf1fc04113 100644
--- a/llvm/test/CodeGen/AArch64/note-gnu-property-elf-pauthabi.ll
+++ b/llvm/test/CodeGen/AArch64/note-gnu-property-elf-pauthabi.ll
@@ -10,7 +10,7 @@
!llvm.module.flags = !{!0, !1}
!0 = !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
-!1 = !{i32 1, !"aarch64-elf-pauthabi-version", i32 85}
+!1 = !{i32 1, !"aarch64-elf-pauthabi-version", i32 341}
; ASM: .section .note.gnu.property,"a", at note
; ASM-NEXT: .p2align 3, 0x0
@@ -22,12 +22,12 @@
; ASM-NEXT: .word 3221225473
; ASM-NEXT: .word 16
; ASM-NEXT: .xword 268435458
-; ASM-NEXT: .xword 85
+; ASM-NEXT: .xword 341
; OBJ: Displaying notes found in: .note.gnu.property
; OBJ-NEXT: Owner Data size Description
; OBJ-NEXT: GNU 0x00000018 NT_GNU_PROPERTY_TYPE_0 (property note)
-; OBJ-NEXT: AArch64 PAuth ABI core info: platform 0x10000002 (llvm_linux), version 0x55 (PointerAuthIntrinsics, !PointerAuthCalls, PointerAuthReturns, !PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination)
+; OBJ-NEXT: AArch64 PAuth ABI core info: platform 0x10000002 (llvm_linux), version 0x155 (PointerAuthIntrinsics, !PointerAuthCalls, PointerAuthReturns, !PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination, PointerAuthELFGOT)
; ERR: either both or no 'aarch64-elf-pauthabi-platform' and 'aarch64-elf-pauthabi-version' module flags must be present
diff --git a/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s b/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
index c897cdf3e6dc7..a71f8a231545f 100644
--- a/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
+++ b/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
@@ -89,7 +89,7 @@ end:
# RUN: llvm-readobj --notes gnu-1-0.o | \
# RUN: FileCheck --check-prefix=OBJ -DPLATFORM="0x1 (baremetal)" -DVERSION=0x0 %s
-#--- gnu-0x10000002-85.s
+#--- gnu-0x10000002-0.s
.section ".note.gnu.property", "a"
.long 4 // Name length is always 4 ("GNU")
.long end - begin // Data length
@@ -101,19 +101,91 @@ begin:
.long 0xc0000001 // Type: GNU_PROPERTY_AARCH64_FEATURE_PAUTH
.long 16 // Data size
.quad 0x10000002 // PAuth ABI platform
- .quad 85 // PAuth ABI version
+ .quad 0 // PAuth ABI version
+ .p2align 3 // Align to 8 byte for 64 bit
+end:
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-0x10000002-0.s -o gnu-0x10000002-0.o
+# RUN: llvm-readelf --notes gnu-0x10000002-0.o | \
+# RUN: FileCheck --check-prefix=ELF -DPLATFORM="0x10000002 (llvm_linux)" \
+# RUN: -DVERSION="0x0 (!PointerAuthIntrinsics, !PointerAuthCalls, !PointerAuthReturns, !PointerAuthAuthTraps, !PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, !PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination, !PointerAuthELFGOT)" %s
+# RUN: llvm-readobj --notes gnu-0x10000002-0.o | \
+# RUN: FileCheck --check-prefix=OBJ -DPLATFORM="0x10000002 (llvm_linux)" \
+# RUN: -DVERSION="0x0 (!PointerAuthIntrinsics, !PointerAuthCalls, !PointerAuthReturns, !PointerAuthAuthTraps, !PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, !PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination, !PointerAuthELFGOT)" %s
+
+#--- gnu-0x10000002-341.s
+.section ".note.gnu.property", "a"
+ .long 4 // Name length is always 4 ("GNU")
+ .long end - begin // Data length
+ .long 5 // Type: NT_GNU_PROPERTY_TYPE_0
+ .asciz "GNU" // Name
+ .p2align 3
+begin:
+ # PAuth ABI property note
+ .long 0xc0000001 // Type: GNU_PROPERTY_AARCH64_FEATURE_PAUTH
+ .long 16 // Data size
+ .quad 0x10000002 // PAuth ABI platform
+ .quad 341 // PAuth ABI version
+ .p2align 3 // Align to 8 byte for 64 bit
+end:
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-0x10000002-341.s -o gnu-0x10000002-341.o
+# RUN: llvm-readelf --notes gnu-0x10000002-341.o | \
+# RUN: FileCheck --check-prefix=ELF -DPLATFORM="0x10000002 (llvm_linux)" \
+# RUN: -DVERSION="0x155 (PointerAuthIntrinsics, !PointerAuthCalls, PointerAuthReturns, !PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination, PointerAuthELFGOT)" %s
+# RUN: llvm-readobj --notes gnu-0x10000002-341.o | \
+# RUN: FileCheck --check-prefix=OBJ -DPLATFORM="0x10000002 (llvm_linux)" \
+# RUN: -DVERSION="0x155 (PointerAuthIntrinsics, !PointerAuthCalls, PointerAuthReturns, !PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination, PointerAuthELFGOT)" %s
+
+#--- gnu-0x10000002-170.s
+.section ".note.gnu.property", "a"
+ .long 4 // Name length is always 4 ("GNU")
+ .long end - begin // Data length
+ .long 5 // Type: NT_GNU_PROPERTY_TYPE_0
+ .asciz "GNU" // Name
+ .p2align 3
+begin:
+ # PAuth ABI property note
+ .long 0xc0000001 // Type: GNU_PROPERTY_AARCH64_FEATURE_PAUTH
+ .long 16 // Data size
+ .quad 0x10000002 // PAuth ABI platform
+ .quad 170 // PAuth ABI version
+ .p2align 3 // Align to 8 byte for 64 bit
+end:
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-0x10000002-170.s -o gnu-0x10000002-170.o
+# RUN: llvm-readelf --notes gnu-0x10000002-170.o | \
+# RUN: FileCheck --check-prefix=ELF -DPLATFORM="0x10000002 (llvm_linux)" \
+# RUN: -DVERSION="0xaa (!PointerAuthIntrinsics, PointerAuthCalls, !PointerAuthReturns, PointerAuthAuthTraps, !PointerAuthVTPtrAddressDiscrimination, PointerAuthVTPtrTypeDiscrimination, !PointerAuthInitFini, PointerAuthInitFiniAddressDiscrimination, !PointerAuthELFGOT)" %s
+# RUN: llvm-readobj --notes gnu-0x10000002-170.o | \
+# RUN: FileCheck --check-prefix=OBJ -DPLATFORM="0x10000002 (llvm_linux)" \
+# RUN: -DVERSION="0xaa (!PointerAuthIntrinsics, PointerAuthCalls, !PointerAuthReturns, PointerAuthAuthTraps, !PointerAuthVTPtrAddressDiscrimination, PointerAuthVTPtrTypeDiscrimination, !PointerAuthInitFini, PointerAuthInitFiniAddressDiscrimination, !PointerAuthELFGOT)" %s
+
+#--- gnu-0x10000002-511.s
+.section ".note.gnu.property", "a"
+ .long 4 // Name length is always 4 ("GNU")
+ .long end - begin // Data length
+ .long 5 // Type: NT_GNU_PROPERTY_TYPE_0
+ .asciz "GNU" // Name
+ .p2align 3
+begin:
+ # PAuth ABI property note
+ .long 0xc0000001 // Type: GNU_PROPERTY_AARCH64_FEATURE_PAUTH
+ .long 16 // Data size
+ .quad 0x10000002 // PAuth ABI platform
+ .quad 511 // PAuth ABI version
.p2align 3 // Align to 8 byte for 64 bit
end:
-# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-0x10000002-85.s -o gnu-0x10000002-85.o
-# RUN: llvm-readelf --notes gnu-0x10000002-85.o | \
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-0x10000002-511.s -o gnu-0x10000002-511.o
+# RUN: llvm-readelf --notes gnu-0x10000002-511.o | \
# RUN: FileCheck --check-prefix=ELF -DPLATFORM="0x10000002 (llvm_linux)" \
-# RUN: -DVERSION="0x55 (PointerAuthIntrinsics, !PointerAuthCalls, PointerAuthReturns, !PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination)" %s
-# RUN: llvm-readobj --notes gnu-0x10000002-85.o | \
+# RUN: -DVERSION="0x1ff (PointerAuthIntrinsics, PointerAuthCalls, PointerAuthReturns, PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, PointerAuthInitFiniAddressDiscrimination, PointerAuthELFGOT)" %s
+# RUN: llvm-readobj --notes gnu-0x10000002-511.o | \
# RUN: FileCheck --check-prefix=OBJ -DPLATFORM="0x10000002 (llvm_linux)" \
-# RUN: -DVERSION="0x55 (PointerAuthIntrinsics, !PointerAuthCalls, PointerAuthReturns, !PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, !PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, !PointerAuthInitFiniAddressDiscrimination)" %s
+# RUN: -DVERSION="0x1ff (PointerAuthIntrinsics, PointerAuthCalls, PointerAuthReturns, PointerAuthAuthTraps, PointerAuthVTPtrAddressDiscrimination, PointerAuthVTPtrTypeDiscrimination, PointerAuthInitFini, PointerAuthInitFiniAddressDiscrimination, PointerAuthELFGOT)" %s
-#--- gnu-0x10000002-256.s
+#--- gnu-0x10000002-512.s
.section ".note.gnu.property", "a"
.long 4 // Name length is always 4 ("GNU")
.long end - begin // Data length
@@ -125,15 +197,15 @@ begin:
.long 0xc0000001 // Type: GNU_PROPERTY_AARCH64_FEATURE_PAUTH
.long 16 // Data size
.quad 0x10000002 // PAuth ABI platform
- .quad 256 // PAuth ABI version
+ .quad 512 // PAuth ABI version
.p2align 3 // Align to 8 byte for 64 bit
end:
-# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-0x10000002-256.s -o gnu-0x10000002-256.o
-# RUN: llvm-readelf --notes gnu-0x10000002-256.o | \
-# RUN: FileCheck --check-prefix=ELF -DPLATFORM="0x10000002 (llvm_linux)" -DVERSION="0x100 (unknown)" %s
-# RUN: llvm-readobj --notes gnu-0x10000002-256.o | \
-# RUN: FileCheck --check-prefix=OBJ -DPLATFORM="0x10000002 (llvm_linux)" -DVERSION="0x100 (unknown)" %s
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-0x10000002-512.s -o gnu-0x10000002-512.o
+# RUN: llvm-readelf --notes gnu-0x10000002-512.o | \
+# RUN: FileCheck --check-prefix=ELF -DPLATFORM="0x10000002 (llvm_linux)" -DVERSION="0x200 (unknown)" %s
+# RUN: llvm-readobj --notes gnu-0x10000002-512.o | \
+# RUN: FileCheck --check-prefix=OBJ -DPLATFORM="0x10000002 (llvm_linux)" -DVERSION="0x200 (unknown)" %s
#--- gnu-short.s
.section ".note.gnu.property", "a"
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index b9704b15f02d4..1457ae8cb4173 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5286,8 +5286,9 @@ static bool printAArch64PAuthABICoreInfo(raw_ostream &OS, uint32_t DataSize,
Flags[AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI] = "InitFini";
Flags[AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC] =
"InitFiniAddressDiscrimination";
+ Flags[AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_GOT] = "ELFGOT";
- static_assert(AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC ==
+ static_assert(AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_GOT ==
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
"Update when new enum items are defined");
More information about the llvm-commits
mailing list