Skip to content

[llvm][llvm-readobj] Add NT_ARM_GCS Linux core note type #117545

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 1 commit into from
Dec 11, 2024

Conversation

DavidSpickett
Copy link
Collaborator

@DavidSpickett DavidSpickett commented Nov 25, 2024

The ARM Guarded Control Stack extension (GCS) is similar to existing shadow stack extensions for other architectures.

The core note will include which features of GCS are enabled, which have been locked in their current state, and the stack pointer of the shadow stack.

Note that 0x40f is NT_ARM_POE, FPMR is supported by LLDB and GCS will be soon, POE is not at this time. So NT_ARM_POE will be added when that work starts.

See https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h.

The ARM Guarded Control Stack extension (GCS) is similar to existing
shadow stack extensions for other architectures.

The core note will include which features of GCS are enabled,
which have been locked in their current state, and the stack
pointer of the shadow stack.

Note that 0x40f is NT_ARM_POE, FPMR and GCS will be supported
by lldb, POE is not at this time.
@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2024

@llvm/pr-subscribers-objectyaml

@llvm/pr-subscribers-llvm-binary-utilities

Author: David Spickett (DavidSpickett)

Changes

The ARM Guarded Control Stack extension (GCS) is similar to existing shadow stack extensions for other architectures.

The core note will include which features of GCS are enabled, which have been locked in their current state, and the stack pointer of the shadow stack.

Note that 0x40f is NT_ARM_POE, FPMR and GCS will be supported by lldb, POE is not at this time.


Full diff: https://github.com/llvm/llvm-project/pull/117545.diff

4 Files Affected:

  • (modified) llvm/include/llvm/BinaryFormat/ELF.h (+1)
  • (modified) llvm/lib/ObjectYAML/ELFYAML.cpp (+1)
  • (modified) llvm/test/tools/llvm-readobj/ELF/note-core.test (+5)
  • (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+1)
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index fd32a6ec19652b..5356843f8ecf1a 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1724,6 +1724,7 @@ enum : unsigned {
   NT_ARM_ZA = 0x40c,
   NT_ARM_ZT = 0x40d,
   NT_ARM_FPMR = 0x40e,
+  NT_ARM_GCS = 0x410,
 
   NT_FILE = 0x46494c45,
   NT_PRXFPREG = 0x46e62b7f,
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index ca0ea03452d3be..f28e6766f734c0 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -136,6 +136,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_NT>::enumeration(
   ECase(NT_ARM_ZA);
   ECase(NT_ARM_ZT);
   ECase(NT_ARM_FPMR);
+  ECase(NT_ARM_GCS);
   ECase(NT_FILE);
   ECase(NT_PRXFPREG);
   ECase(NT_SIGINFO);
diff --git a/llvm/test/tools/llvm-readobj/ELF/note-core.test b/llvm/test/tools/llvm-readobj/ELF/note-core.test
index 1196d4b2507241..2c35178a97524b 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-core.test
+++ b/llvm/test/tools/llvm-readobj/ELF/note-core.test
@@ -265,6 +265,11 @@
 # RUN: llvm-readelf --notes %t_nt_arm_fpmr.o | FileCheck %s --check-prefix=CHECK-GNU  -DDESC="NT_ARM_FPMR (AArch64 Floating Point Mode Register)"
 # RUN: llvm-readobj --notes %t_nt_arm_fpmr.o | FileCheck %s --check-prefix=CHECK-LLVM -DDESC="NT_ARM_FPMR (AArch64 Floating Point Mode Register)"
 
+## Check ELF::NT_ARM_GCS
+# RUN: yaml2obj %s -DTYPE=0x410 -o %t_nt_arm_gcs.o
+# RUN: llvm-readelf --notes %t_nt_arm_gcs.o | FileCheck %s --check-prefix=CHECK-GNU  -DDESC="NT_ARM_GCS (AArch64 Guarded Control Stack state)"
+# RUN: llvm-readobj --notes %t_nt_arm_gcs.o | FileCheck %s --check-prefix=CHECK-LLVM -DDESC="NT_ARM_GCS (AArch64 Guarded Control Stack state)"
+
 ## Check ELF::NT_FILE.
 # RUN: yaml2obj %s -DTYPE=0x46494c45 -o %t_nt_file.o
 # RUN: llvm-readelf --notes %t_nt_file.o | FileCheck %s --check-prefix=CHECK-GNU  -DDESC="NT_FILE (mapped files)"
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index bb8ec41d87454c..bfca65aad52b44 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6057,6 +6057,7 @@ const NoteType CoreNoteTypes[] = {
     {ELF::NT_ARM_ZA, "NT_ARM_ZA (AArch64 SME ZA registers)"},
     {ELF::NT_ARM_ZT, "NT_ARM_ZT (AArch64 SME ZT registers)"},
     {ELF::NT_ARM_FPMR, "NT_ARM_FPMR (AArch64 Floating Point Mode Register)"},
+    {ELF::NT_ARM_GCS, "NT_ARM_GCS (AArch64 Guarded Control Stack state)"},
 
     {ELF::NT_FILE, "NT_FILE (mapped files)"},
     {ELF::NT_PRXFPREG, "NT_PRXFPREG (user_xfpregs structure)"},

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Perhaps worth getting someone else with ARM knowledge a chance to give it a once over (@smithp35?)

@DavidSpickett
Copy link
Collaborator Author

DavidSpickett commented Nov 26, 2024

@omjavaid is about to review the lldb patches even if he doesn't realise yet :)

https://github.com/search?q=repo%3Atorvalds%2Flinux%20NT_ARM_GCS&type=code should help validate it.

POE (permission overlay extension) support is planned for about a year from now, so I'm not going to add that constant until LLDB needs it.

Copy link
Contributor

@omjavaid omjavaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference NT_ARM_GCS is defined at:
https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h
#define NT_ARM_GCS 0x410 /* ARM GCS state */

@DavidSpickett DavidSpickett merged commit 088e74c into llvm:main Dec 11, 2024
11 checks passed
@DavidSpickett DavidSpickett deleted the gcs-pr1 branch December 11, 2024 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants