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

enh enh at google.com
Tue Jul 5 13:52:33 PDT 2016


On Tue, Jul 5, 2016 at 12:16 PM, Rob Landley <rob at landley.net> wrote:
> On 07/04/2016 08:31 AM, Ed Maste wrote:
>> 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.
>
> FYI this looks interesting but I'm not doing anything with it because
> I'm not a regular user of this info and can't judge what's best to do
> here. I leave turning this into a proper patch (or not) to... Elliott, I
> guess?
>
>> 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.
>
> Exactly my problem: I dunno what success looks like here.
>
> (What does NT GNU mean anyway? GNU/Windows NT?)

NT_ is "note type" for that set of constants, similar to the ELF PT_*
and DT_* constants.

i agree with the "not ... much value in reporting the type". it's not
actually recorded, and binutils ld lets you set the build id to *any*
byte sequence you choose. (so 20 might mean sha1, or it might mean you
used --build-id to encode some arbitrary 20-byte sequence.)

there were only two reasons i added this in:

1. i was worried that someone might actually be grepping for
BuildId[sha1]= but (a) i can find no evidence of that in the Android
tree and (b) most other places in Android that output build ids just
say "BuildId" anyway, so i think we can ignore that.

2. i noticed that /usr/bin on my ubuntu 14.04 box has a mix of sha1
and md5 for some reason. (but Android is sha1-only, so i don't care.)

but, yeah, we really have no idea what we're looking at, so let's stop
pretending. patch attached.

> Rob



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Don-t-try-to-guess-the-build-id-type-in-file-1.patch
Type: text/x-patch
Size: 1056 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20160705/5e2ba323/attachment-0004.bin>


More information about the Toybox mailing list