I've added the x86 ISA requirement too, since that's the other one I see
on my (host!) system, but I'm really just here for arm64 PAC/BTI. There
are others, but YAGNI.

Also remove incorrect TODO comments: j is implicitly non-zero from the
loop (so we _could_ add `, j=1` but it seems redundant), and notematch()
doesn't advance the pointer unless it matches (like strstart()).
---
 toys/other/readelf.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
From 2c5fcff3710cdd4fc2f9f36eb891494e0d88c273 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Tue, 8 Aug 2023 13:33:53 -0700
Subject: [PATCH] readelf: add PAC and BTI decoding.

I've added the x86 ISA requirement too, since that's the other one I see
on my (host!) system, but I'm really just here for arm64 PAC/BTI. There
are others, but YAGNI.

Also remove incorrect TODO comments: j is implicitly non-zero from the
loop (so we _could_ add `, j=1` but it seems redundant), and notematch()
doesn't advance the pointer unless it matches (like strstart()).
---
 toys/other/readelf.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/toys/other/readelf.c b/toys/other/readelf.c
index 91d92272..54e6e22c 100644
--- a/toys/other/readelf.c
+++ b/toys/other/readelf.c
@@ -319,11 +319,38 @@ static void show_notes(unsigned long offset, unsigned long size)
         printf("NT_GNU_ABI_TAG\tOS: %s, ABI: %u.%u.%u",
           !elf_int(&p)?"Linux":"?", elf_int(&p), elf_int(&p), elf_int(&p)), j=1;
       } else if (type == 3) {
-// TODO should this set j=1?
         printf("NT_GNU_BUILD_ID\t");
         for (;j<descsz;j++) printf("%02x", *p++);
       } else if (type == 4) {
         printf("NT_GNU_GOLD_VERSION\t%.*s", descsz, p), j=1;
+      } else if (type == 5) {
+        printf("NT_GNU_PROPERTY_TYPE_0\t");
+        while (descsz-j > 8) { // Ignore 0-padding at the end.
+          int pr_type = elf_int(&p);
+          int pr_size = elf_int(&p), k, pr_data;
+
+          j += 8;
+          printf("\n    Properties:    ");
+          if (pr_size != 4) {
+            // Just hex dump anything we aren't familiar with.
+            for (k=0;k<pr_size;k++) printf("%02x", *p++);
+            xputc('\n');
+            j += pr_size;
+          } else {
+            pr_data = elf_int(&p);
+            j += 4;
+            if (pr_type == 0xc0000000) {
+              printf("arm64 features:");
+              if (pr_data & 1) printf(" bti");
+              if (pr_data & 2) printf(" pac");
+              xputc('\n');
+            } else if (pr_type == 0xc0008002) {
+              printf("x86 isa needed: x86-64v%d", ffs(pr_data));
+            } else {
+              printf("other (%#x): %#x", pr_type, pr_data);
+            }
+          }
+        }
       } else p -= 4;
     } else if (notematch(namesz, &p, "Android")) {
       if (type == 1) {
@@ -332,10 +359,8 @@ static void show_notes(unsigned long offset, unsigned long size)
       } else p -= 8;
     } else if (notematch(namesz, &p, "CORE")) {
       if (*(desc = nt_type_core(type)) != '0') printf("%s", desc), j=1;
-// TODO else p -= 5?
     } else if (notematch(namesz, &p, "LINUX")) {
       if (*(desc = nt_type_linux(type)) != '0') printf("%s", desc), j=1;
-// TODO else p -= 6?
     }
 
     // If we didn't do custom output above, show a hex dump.
-- 
2.41.0.640.ga95def55d0-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to