discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: universal binaries


From: Frederico Muñoz
Subject: Re: universal binaries
Date: Sun, 16 Sep 2007 03:35:12 +0100

Hello all,

Sorry to revive such an old thread, but it's something that somewhat
interests me.

On 1/14/07, Markus Hitter <mah@jump-ing.de> wrote:
>
> Am 13.01.2007 um 19:04 schrieb Rogelio Serrano:
>
> > How does apple do it?
>
> Universal binaries are two or more ordinary binaries in a row,
> together with a header in front of it. All this is put into one file.
>
> To launch a Universal Binary (UB), the kernel's execve() recognizes
> the UB header in addition to ordinary binaries (and scripts). If
> execve() finds such a header, it sets a file offset to the binary
> matching the current architecture and starts over.
>

Indeed. The most simple and complete explanation I've found is at
http://hohle.net/scrap_post.php?post=197. Basically it doesn't seem
tied to Mach-O in the sense that the binary format doesn't seem to
offer any special support for it. In the end it seems as a "simple"
archive format that works by having a cooperating exec:

"(...)The first block contains the "Magic Number". This is how OS X
knows what kind of binary its going to try to run. CAFEBABE, is the
magic number used for fat binaries. The second number is for the
number of archives in the binary.(...)Next come the headers for each
of the binaries. The first block indicates the CPU Type, and the CPU
Subtype. From this example, it would seem that 0x12 is PowerPC, and
0x7 is x86. The next block is the CPU Subtype. Again, for this
example, the subtype for PowerPC is empty (0x0), and the Intel SubType
is 0x3.
Next comes different information about the addressing of the archive.
We see the offset, which tells us where the program starts in this
file, and how large that block is(...)"


> > With Mach-o?
>
> I don't think this is limited to some sort of ABI other than by
> patent issues. In principle, you should even be able to stitch
> together mach-o and ELF binaries. You'd have to modify the current
> Mac OS X kernel to get this working.

Indeed, I see no reason for not being possible to have ELF and Mach-O
mixed in the same MAB (which is not saying much since I know very
little on how these things are processed at this level). In GNU/Linux,
for example, I was thinking that a small, custom loader program could
be made to do the dirty work (i.e. find the offset of the appropriate
binary within the "archive", if any) and then use binfmt_misc
(http://en.wikipedia.org/wiki/Binfmt_misc) to make that loader the
responsible for the CAFEBABE magic number. The trick would be to
execute not the file, but the code that starts in that file at a
specified offset (and this is something that to my eyes sounds
"simple" but could be impossible or at least not trivial to
implement).
>
> > is it enough to compile and cross
> > compile and just put them all together in an application bundle?
>
> No.
>
> The stitching tool is named "lipo", to help your googling.
>
>

Something like "lipo" would be easier to do, even the output of "file"
in Darwin is simple (add the magic number and process the file header
to present a human-readable summary of the  archs in the binary).

Now, the actual benefict from this is somewhat more debatable, given
the miriad of distros, OS's and archs we are talking about. But still,
the idea is somewhat appealing, and along with the packaging format
I've been looking around in OSX for how this stuff works.

Cheers,

Frederico Muñoz




reply via email to

[Prev in Thread] Current Thread [Next in Thread]