It's necessary to distinguish x86 and x86-64 to be able to recognize the
way x32 is encoded in ELF. (Plus it's customary to distinguish the variants,
so people are probably eyeballing the architecture rather than paying
attention to the ELF class.)

If we're not going to use the same strings as traditional file(1) -- which
is what I'd tried to do -- we should probably use the strings from the ELF
spec rather than the Linux kernel, which often deliberately goes against
the manufacturer's wishes: "arm64" versus "aarch64", for example. But that's
an issue for another day.
---
 toys/pending/file.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
From b74924bde313524d64fa6182fa45c47528a54c61 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Wed, 17 Feb 2016 08:15:35 -0800
Subject: [PATCH] Distinguish 32- and 64-bit variants in file(1) for x32.

It's necessary to distinguish x86 and x86-64 to be able to recognize the
way x32 is encoded in ELF. (Plus it's customary to distinguish the variants,
so people are probably eyeballing the architecture rather than paying
attention to the ELF class.)

If we're not going to use the same strings as traditional file(1) -- which
is what I'd tried to do -- we should probably use the strings from the ELF
spec rather than the Linux kernel, which often deliberately goes against
the manufacturer's wishes: "arm64" versus "aarch64", for example. But that's
an issue for another day.
---
 toys/pending/file.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/toys/pending/file.c b/toys/pending/file.c
index 2c2f286..7490efb 100644
--- a/toys/pending/file.c
+++ b/toys/pending/file.c
@@ -27,15 +27,17 @@ static void do_elf_file()
   int elf_endian = toybuf[5], e_type, e_machine, i;
   int64_t (*elf_int)(void *ptr, unsigned size) = peek_le;
   // Values from include/linux/elf-em.h (plus arch/*/include/asm/elf.h)
-  // Names are linux/arch/ directory name
+  // Names are linux/arch/ directory name except where Linux collapses
+  // the 32- and 64-bit architectures into one name. ELF needs to distinguish
+  // them because that's how the "x32" variants are encoded.
   struct {int val; char *name;} type[] = {{0x9026, "alpha"},
-    {40, "arm"}, {183, "arm"}, {0x18ad, "avr32"}, {106, "blackfin"},
+    {40, "arm"}, {183, "aarch64"}, {0x18ad, "avr32"}, {106, "blackfin"},
     {76, "cris"}, {0x5441, "frv"}, {46, "h8300"}, {50, "ia64"},//ia intel ftaghn
     {88, "m32r"}, {4, "m68k"}, {0xbaab, "microblaze"}, {8, "mips"},
     {10, "mips"}, {89, "mn10300"}, {15, "parisc"}, {22, "s390"},
-    {135, "score"}, {42, "sh"}, {2, "sparc"}, {18, "sparc"}, {43, "sparc"},
+    {135, "score"}, {42, "sh"}, {2, "sparc"}, {18, "sparc"}, {43, "sparc64"},
     {187, "tile"}, {188, "tile"}, {191, "tile"}, {3, "x86"}, {6, "x86"},
-    {62, "x86"}, {94, "xtensa"}, {0xabc7, "xtensa"}};
+    {62, "x86-64"}, {94, "xtensa"}, {0xabc7, "xtensa"}};
 
   xprintf("ELF ");
 
-- 
2.7.0.rc3.207.g0ac5344

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

Reply via email to