[Toybox] FYI: kernel builds rely on GNU expr extensions

enh enh at google.com
Wed May 1 13:23:55 PDT 2019


so you know how i said i wasn't going to use anything in pending for
the build? turns out i wasn't paying enough attention and accidentally
used expr...

i'm reverting that now (but keeping it for the device), but folks
building their kernels from within an Android tree hit this. (we
recommend that you _don't_ build your kernel that way, and we don't do
that ourselves, but realistically we're never going to stop everyone
from doing it. and i know "build the kernel with toybox" is
interesting to you anyway.)

so, yeah, the kernel build uses some GNU extensions. `index` looks
like it's there (though perhaps only for tests?), and the specific bug
report i got was about GNU unary + which the info page describes thus:

   Strings are not quoted for ‘expr’ itself, though you may need to
  quote them to protect characters with special meaning to the shell,
  e.g., spaces.  However, regardless of whether it is quoted, a string
  operand should not be a parenthesis or any of ‘expr’’s operators like
  ‘+’, so you cannot safely pass an arbitrary string ‘$str’ to expr merely
  by quoting it to the shell.  One way to work around this is to use the
  GNU extension ‘+’, (e.g., ‘+ "$str" = foo’); a more portable way is to
  use ‘" $str"’ and to adjust the rest of the expression to take the
  leading space into account (e.g., ‘" $str" = " foo"’).

though i'm honestly not convinced this is their real problem. the
specific example they give is this from scripts/Makefile.lib in the
kernel:

size_append = printf $(shell \
dec_size=0; \
for F in $1; do \
    fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \
    dec_size=$$(expr $$dec_size + $$fsize); \
done; \
...

but given the `dec_size=0` line, i think they're confused and whatever
failure they're seeing is coming from somewhere else...



More information about the Toybox mailing list