Static bins

Christopher James Coleman ug97cjc at cs.bham.ac.uk
Wed Jan 7 14:00:32 PST 2004



On Wed, 7 Jan 2004, Robert Connolly wrote:
> Gnu false supports --help and --version. Linus has commented on it saying its
> an example of taking guildlines too far. I don't know what I'm doing but this
> seems to work.
>
> cat > false.c << "EOF"
> int main () {exit (1);}
> EOF
> gcc -static -o false false.c
>
> In comparision I think Gnu's False.c is unsafe simply because it accepts
> arguments. When this is built dynamicly linked it's less then 1/3rd the size
> of gnu's false. Staticly its 20+ times bigger. So this would be defintly be
> best in assembly.

The GNU thing is, well, a GNU thing. I do not understand why they insist
on beefing up programs. It says that if you define POSIXLY_CORRECT in your
environment then it will not acknowledge any command-line arguments, but
that means it using the environment.

You should use _exit(), rather than exit(). I do not think that the
overhead of using exit() is worth it in this context.

Assembly to do `false' is fairly trivial, at least on i386. You only need
to set two registers, and then throw int 128. I do not know about other
architectures - but, that is besides the point. I do not get why all this
bloat is used.

> Another option is
> cat > false.sh << "EOF"
> #! /bin/sh exit 1
> EOF
>
> But I have no idea how safe this is.

That invokes the shell, and so is slightly less cool.

.chris



More information about the hlfs-dev mailing list