[Toybox] [PATCH] file: basic Mach-O universal binary support.

enh enh at google.com
Wed Sep 1 13:20:09 PDT 2021


On Wed, Sep 1, 2021 at 1:04 PM Rob Landley <rob at landley.net> wrote:

> On 8/31/21 6:23 PM, enh via Toybox wrote:
> > PowerPC may be dead and gone, but arm64 is the new x86-64, and
> > x86-64 the new PowerPC :-)
> > ---
> >  tests/file.test   |  4 ++++
> >  toys/posix/file.c | 36 +++++++++++++++++++++++++++++++-----
>
> Grrr, clashes a lot with my tests/file.test local changes. (My tree
> accumulating
> unfinished changes is yet another tabsplosion-style accumulation of minor
> technical debt.) Anyway, backed my changes out to apply yours, then
> applied them
> again.
>
> It's a pity you don't use bash to run the test suite, because
> $'\x0a\xbc\xde' in
> the "input" argument would be a more concise way of doing those tests.
> (Yes, I
> need to find time to work on toysh again...)
>

speaking of which... your use of fancy bash stuff upsets both Android and
macOS. here's the complaint from macOS, but iirc Android is similar:

~/toybox$ make test_file
scripts/test.sh file
scripts/runtest.sh: line 217: syntax error near unexpected token `;'
scripts/runtest.sh: line 217: `      R) LEN=0; B=1; ;&'

seems not to actually cause trouble in either case, though, so i'd been
ignoring it for now.


> Your TEST_HOST output didn't match my TEST_HOST output on devuan. Is this
> version skew in the "file" command or did you not run TEST_HOST? I get:
>
>   universal: Mach-O universal binary with 2 architectures: [x86_64] [arm64]
>
> Which has [name] instead of commas, and uses x86_64 instead of x86-64.
>

oh, interesting. *my* host file wasn't giving output that useful. (and
macOS file is different from linux file here.)

yeah, i'm not particularly wedded to the specific format i used, and macOS
used [] too, but included more info:

~/toybox$ file /bin/sh
/bin/sh: Mach-O universal binary with 2 architectures: [x86_64:Mach-O
64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/bin/sh (for architecture x86_64): Mach-O 64-bit executable x86_64
/bin/sh (for architecture arm64e): Mach-O 64-bit executable arm64e

(note that that's really three lines for one file, which seems quite a
major script-breaker!)

anyway, my choice of x86-64 was just because that's what we've used for
everything else; ELF, Windows, and even regular single-architecture Mach-O
files. personally i tend towards internal consistency rather than outward
consistency when they differ, but the opposite argument is obviously
equally valid. you can't really win. but if we change mach-o universal
binaries, we should probably change regular mach-o binaries too?


> Hmmm, I have a big list of tests I need to add to file.test and some of
> them are...
>
>   $ echo hello > test; chmod 000 test; file test
>   test: regular file, no read permission
>   $ toybox file test
>   file: test: Permission denied
>   test: unknown
>
> Eh, how much do we care about matching exactly in the corner cases? Hmmm...
>

yeah, there's also fancy stuff like UTF-8 vs ASCII, and guessing the
language if it's UTF-8, but although they're kind of cool, they do cost
time as well as code, and i haven't personally had a use for them yet, so
i've been ignoring all the fancy bits.

(the specific motivating case for adding mach-o universal binary support
was a script that's just checking for "universal binary", so they'd be fine
if you want to change the output format.)


> Rob
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20210901/27854d27/attachment.htm>


More information about the Toybox mailing list