The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: crossd@gmail.com (Dan Cross)
Subject: [TUHS] /bin/true (was basic tools / Universal Unix)
Date: Thu, 19 Oct 2017 21:27:07 -0400	[thread overview]
Message-ID: <CAEoi9W5Z6WDPtD9TuFz8W7KsSrsrLcrXmhhq4h6P2dG4vOAF7Q@mail.gmail.com> (raw)
In-Reply-To: <CAEoi9W4zdJ3+RXjK5-5rAJ6rwx_0kx6N-bn1U61=txJGyLT_mw@mail.gmail.com>

[I tried to send this earlier, but was thwarted by list shenanigans.
Apologies if it's a dup.]

On Thu, Oct 19, 2017 at 10:52 AM, Ron Natalie <ron at ronnatalie.com> wrote:
> My favorite reduction to absurdity was /bin/true.   Someone decided we
> needed shell commands for true and false.   Easy enough to add a script that
> said "exit 0" or exit 1" as its only line.
> Then someone realized that the "exit 0" in /bin true was superfluous, the
> default return was 0.  /bin/true turned into an empty, yet executable, file.
>
> Then the lawyers got involved.    We got a version of a packaged UNIX (I
> think it was Interactive Systems).    Every shell script got twelve lines of
> copyright/license boilerplate.     Including /bin true.
> The file had nothing but useless comment in it.

Gerard Holzmann has something on this that I think is great:

http://spinroot.com/gerard/pdf/Code_Inflation.pdf

        - Dan C.

PS: A couple of thoughts.

The shell script hack on 7th Edition doesn't work if one tries to
'execl("/bin/true", "true", NULL);'.  This is because the behavior of
re-interpreting an execution failure as a request to run a script is
done by the shell, not exec in the kernel. This implies that one could
not directly exec a shell script, but rather must exec the shell and
give the path to the script as the first argument. I vaguely recall we
had a discussion about the origin of the '#!' syntax and how this was
addressed about a year or so ago.

I tried to write a teeny-tiny '/bin/true' on my Mac. Dynamically
linked, the obvious "int main() { return 0; }" is still a little over
4KB. Most of that is zeros; padding for section alignment and the
like. I managed to create a 'statically' linked `true` binary by
writing the program in assembler:

% cat true.s
# /bin/true in x86_64 assembler for Mac OS X
.text
.globl start
start:
mov $0x2000001, %rax # BSD system call #1
mov $0, %rdi # Exit status: 0 = 'true'
syscall

# OS X requires a non-empty data segment.
.data
zero: .word 0 As I recall,
%

macOS requires you to have a data section aligned to 4K, even if you
don't use it. The resulting binary is a little over 8K; again, mostly
zeros.

There are parlor tricks people play to get binary sizes down to
incredibly small values, but I found the results interesting. Building
the obvious C program on a PDP-11 running 7th Edition yields a 136
byte executable, stripped. Still infinitely greater than /bin/true in
the limit, but still svelte by modern standards.


  parent reply	other threads:[~2017-10-20  1:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-19 14:52 /bin/true (was [TUHS] " Ron Natalie
2017-10-19 15:01 ` Pete Wright
2017-10-19 15:17   ` Chet Ramey
2017-10-19 21:23 ` Steffen Nurpmeso
2017-10-19 21:43   ` Chet Ramey
2017-10-19 23:00     ` [TUHS] /bin/true (was " Dave Horsfall
2017-10-19 23:14       ` Grant Taylor
2017-10-19 23:23         ` Lyndon Nerenberg
2017-10-19 23:27         ` Kurt H Maier
2017-10-22  4:18           ` Dave Horsfall
2017-10-20 12:10       ` Chet Ramey
2017-10-19 21:43 ` /bin/true (was [TUHS] " Dave Horsfall
2017-10-19 22:04   ` Ronald Natalie
2017-10-19 23:25     ` [TUHS] /bin/true (was " Dave Horsfall
     [not found] ` <CAEoi9W7YZ7YXUip0JTMGip3Nd0czgdjqRCMRcK2GYmDJsckuDg@mail.gmail.com>
     [not found]   ` <CAEoi9W4zdJ3+RXjK5-5rAJ6rwx_0kx6N-bn1U61=txJGyLT_mw@mail.gmail.com>
2017-10-20  1:27     ` Dan Cross [this message]
2017-10-20  1:31       ` Lyndon Nerenberg
2017-10-20  2:05         ` Ronald Natalie
2017-11-28 16:21 ` Nemo
2017-11-28 17:56   ` Warner Losh
2017-11-28 18:26     ` Dan Cross
2017-11-28 18:41       ` Warner Losh
2017-11-28 19:09         ` Dan Cross
2017-11-28 20:34           ` Clem Cole
2017-11-28 22:42           ` Ralph Corderoy
2017-11-28 18:34     ` Bakul Shah
2017-11-28 23:25     ` Ralph Corderoy
2017-10-22 23:00 Doug McIlroy
2017-10-23  1:11 ` Dan Cross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEoi9W5Z6WDPtD9TuFz8W7KsSrsrLcrXmhhq4h6P2dG4vOAF7Q@mail.gmail.com \
    --to=crossd@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).