Also fix finding the flags in the ELF header for riscv32; the existing
code only worked for 64-bit ELF files.
---
 lib/elf.c         | 7 +++++--
 tests/file.test   | 2 +-
 toys/posix/file.c | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)
From c7a4bcbe819b8d3e50d42bd2bc3ff80259713586 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 2 Nov 2023 16:18:37 -0700
Subject: [PATCH] file: add arm32 ELF flag decoding.

Also fix finding the flags in the ELF header for riscv32; the existing
code only worked for 64-bit ELF files.
---
 lib/elf.c         | 7 +++++--
 tests/file.test   | 2 +-
 toys/posix/file.c | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/elf.c b/lib/elf.c
index 93d5e86c..4ea75d68 100644
--- a/lib/elf.c
+++ b/lib/elf.c
@@ -35,8 +35,11 @@ char *elf_arch_name(int type)
 
 void elf_print_flags(int arch, int flags)
 {
-  // riscv
-  if (arch == 243) {
+  if (arch == 40) { // arm32
+    printf(", EABI%u", (flags >> 24) & 0xf);
+    if (flags & 0x200) printf(", soft float");
+    else if (flags & 0x400) printf(", hard float");
+  } else if (arch == 243) { // riscv
     if (flags & 1) printf(", C");
     if (flags & 8) printf(", E");
     if (flags & 0x10) printf(", TSO");
diff --git a/tests/file.test b/tests/file.test
index bd023ace..a749c695 100755
--- a/tests/file.test
+++ b/tests/file.test
@@ -67,7 +67,7 @@ rm -f android.dex
 toyonly test_line "Android NDK full ELF note" "elf/ndk-elf-note-full" \
     "ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
 toyonly test_line "Android NDK short ELF note" "elf/ndk-elf-note-short" \
-    "ELF shared object, 32-bit LSB arm, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
+    "ELF shared object, 32-bit LSB arm, EABI5, soft float, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
 toyonly test_line "ELF static fdpic" "elf/fdstatic" \
     "ELF executable (fdpic), 32-bit MSB sh, static, stripped\n" "" ""
 
diff --git a/toys/posix/file.c b/toys/posix/file.c
index 25edb58e..cada80e1 100644
--- a/toys/posix/file.c
+++ b/toys/posix/file.c
@@ -69,7 +69,7 @@ static void do_elf_file(int fd)
 
   // "x86".
   printf("%s", elf_arch_name(arch = elf_int(toybuf+18, 2)));
-  elf_print_flags(arch, elf_int(toybuf+44+4*bits, 4));
+  elf_print_flags(arch, elf_int(toybuf+36+12*bits, 4));
 
   // If what we've seen so far doesn't seem consistent, bail.
   if (bail) goto bad;
-- 
2.42.0.869.gea05f2083d-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to