Subject: Fat binaries
To: None <current-users@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: current-users
Date: 04/11/1995 12:35:16
> How about an architectural independent format for multi-platform
> distrubution.  It won't give you the speed of native binaries, but at
> least it will give portablity.

> Two candiates that come to mind are: RTL (this is abit of a problem,
> if two versons of NetBSD differ significantly, although it could be
> argued that if an application is platform specific then it should be
> native anyway), and the Java virtual machine.

> The Java virtual machine (start at http://java.sun.com - I think), of
> which I am currently reading, seems to be a better platform, although
> I wonder if it is workable.

I would be inclined to doubt it.  I know little about Java, only what
I've seen when I spent a few hours browsing their web pages...but the
Java machine seems to have too much security cruft to be usable as a
general-purpose machine language.  I suppose you could add lots of new
primitives (corresponding to C-coded stuff in a traditional Java
implementation), but then what's the difference between just inventing
a new p-code language from scratch?

Of course, this p-code would not be usable for things like the kernel
and init; it would be useful only for distributing application-level
software.  And we already have a good application-level language for
the purpose; it's called C.

> Another idea that was muted many moons ago was to get the exec call
> to recognise the AR format files.  It would look in the archive for a
> file that was named like the CPU. Ie. "ix86", "m68k-nfpu", etc. and
> then load that file.  This fits the classical idea of a fat file.

Yes.  Unless the archive is very carefully constructed, though, it
would have to treat the file like an OMAGIC (or is it NMAGIC?) file,
since page boundaries in the executable won't in general be aligned on
page boundaries on disk.  Perhaps such a situation should just impose a
performance penalty; perhaps it should produce ENOEXEC.

Or perhaps something else should be done.  Maybe an attempt to exec() a
directory that's mode 4000 (ie, --S------) should search it for a file
named after the machine architecture and attempt to execute that
instead.  Or is there some present use for mode 4000 directories?
Overloading directory mode bits like that is _really_ ugly, tho....

How about the following as a fat binary?  (Obviously the btoa data
sections are not for real. :-)

#! /bin/sh
fn=/tmp/$$.exec
case `arch` in
	sun4)	atob << \EOF
xbtoa Begin
B\#CQ5ecXN;^@DA[Basc'Hcrl'gfa%M,Mg.86AgYiT#,\*c;J(4"'0B%q`_G#?Q%"[#T*^.`!)`1R@
3X3Or7.r3]^XruUgqC&`a]Vm,CA-j78Dotk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fn
	case $# in
		0)	exec $fn ;;
		*)	exec $fn "$@" ;;
	esac
fi
exit 1

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu