[Toybox] [PATCH] Improve file(1)'s ELF support.

Ed Maste emaste at freebsd.org
Mon Jul 4 06:31:25 PDT 2016


On 2 July 2016 at 16:01, enh <enh at google.com> wrote:
> Read any PT_NOTE sections to look for NT_GNU_BUILD_ID or Android API
> level notes. I deliberately didn't NT_GNU_ABI_TAG because it's noisy --
> every Linux executable has one -- but not something most command-line
> users will have any use for. (And you can ask readelf(1) anyway.)

+          if (n_type == 3 /*NT_GNU_BUILD_ID*/) {
+            printf(", BuildID[%s]=", (n_descsz==20)?"sha1":"md5");
+            for (j = 0; j < n_descsz; ++j) printf("%02x", note[16 + j]);
+          }

There are build ID notes that are not 20 bytes long, and are not md5.
Specifically, a 16 byte build ID may be a UUID, LLVM's lld can
generate 8-byte fnv1, and the user may specify an arbitrary number of
hex bytes for build ID.

I have a patch for Zoulas file that does:

+               switch (descsz) {
+               case 8:
+                   type = "fnv1";
+                   break;
+               case 16:
+                   type = "md5/uuid";
+                   break;
+               case 20:
+                   type = "sha1";
+                   break;
+               default:
+                   type = "unknown";
+                   break;
+               }

but given that there's no requirement on exactly what's included in a
sha1 or md5 build ID anyway I'm not sure there's much value in
reporting the type.



More information about the Toybox mailing list