Subject: port-i386/2835: man page for compat_freebsd
To: None <gnats-bugs@gnats.netbsd.org>
From: None <jim.spath@stripey.spath.ba.md.us>
List: netbsd-bugs
Date: 10/11/1996 18:18:32
>Number:         2835
>Category:       port-i386
>Synopsis:       man page for compat_freebsd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 11 15:35:01 1996
>Last-Modified:
>Originator:     jim
>Organization:
hardly
>Release:        1.2
>Environment:
System: NetBSD stripey.spath.ba.md.us 1.2 NetBSD 1.2 (STRIPEY) #3: Sat Oct 5 10:06:09 EDT 1996 jim@stripey.spath.ba.md.us:/j/NetBSD/src/sys/arch/i386/compile/STRIPEY i386


>Description:
  man page attached.
>How-To-Repeat:
 n/a
>Fix:
.\" compat_freebsd.8
.\" Copyright (c) 1996 James E. Spath <spath@jhunix.hcf.jhu.edu>
.\" Adapted from:
.\"	$NetBSD: compat_linux.8,v 1.2 1995/10/16 20:17:59 fvdl Exp $
.\"
.\" Copyright (c) 1995 Frank van der Linden
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"      This product includes software developed for the NetBSD Project
.\"      by Frank van der Linden
.\" 4. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd October 11, 1996
.Os NetBSD 1.2
.Dt COMPAT_FREEBSD 8
.Sh NAME
.Nm COMPAT_FREEBSD
.Nd setup procedure for running FreeBSD binaries
.Sh DESCRIPTION
NetBSD supports running FreeBSD binaries. 
This only applies to i386 systems for now. 
Most programs should work.

The FreeBSD compatibility feature is active
for kernels compiled with the
.Nm COMPAT_FREEBSD
option enabled.

Many programs are dynamically linked.  This means you will also
need the FreeBSD shared libraries that the program depends on, and
the runtime linker.  You will need to create a "shadow root"
directory for FreeBSD binaries on your NetBSD system.  This directory
is named /emul/freebsd.  Any file operations done by FreeBSD programs
run under NetBSD will look in this directory first.  So, if a
FreeBSD program opens, for example, /etc/passwd, NetBSD will first
try to open /emul/freebsd/etc/passwd, and if that does not exist
open the 'real' /etc/passwd file.  We recommend that you install
FreeBSD packages that include configuration files, etc., under
/emul/freebsd, to avoid naming conflicts with possible NetBSD
counterparts.  Shared libraries should also be installed in the
shadow tree.
.Pp
Generally, you will need to look for the shared libraries that
FreeBSD binaries depend on only the first few times that you install
a FreeBSD program on your NetBSD system.  After a while, you will
have a sufficient set of FreeBSD shared libraries on your system
to be able to run newly imported FreeBSD binaries without any extra
work.

.Ss Setting up shared libraries
How to get to know which shared libraries FreeBSD binaries need,
and where to get them? Basically, there are 3 possibilities (when
following these instructions you will need to be root on your NetBSD
system).

.Bl -tag -width 123 -compact
.It 1.
You have access to a FreeBSD system.  In this case you can temporarily
install the binary there, see what shared libraries it needs, and
copy them to your NetBSD system.  Example: you have just ftp-ed
the FreeBSD binary of XPaint.  Put it on the FreeBSD system you
have access to, and check which shared libraries it needs by running
`ldd xpaint':
.Pp
.Bl -tag -width 123 -compact -offset indent
.It (me@freebsd) ldd xpaint
.nf
libXt.so.3 => /usr/X11/lib/libXt.so.3.1.0
.fi
.El
.Pp
You would need to get all the files from the last column, and put
them under /emul/freebsd, with the names in the first column as
symbolic links pointing to them.  This means you eventually have
these files on your NetBSD system:
.Pp
.nf
/emul/freebsd/usr/X11/lib/libXt.so.3.1.0
/emul/freebsd/usr/X11/lib/libXt.so.3 (symbolic link to the above)
.fi
.Pp
Note that if you already have a FreeBSD shared library with a
matching major revision number to the first column of the 'ldd'
output, you won't need to copy the file named in the last column
to your system (the one you already have should work).  We advise
copying the shared library if it is a newer version.  You can remove
the old one as long as you make the symbolic link point to the new
one.  So, if you have these libraries on your system:
.Pp
.nf
/emul/freebsd/lib/libc.so.4.6.27 
/emul/freebsd/lib/libc.so.4 -> /emul/freebsd/lib/libc.so.4.6.27
.fi
.Pp
and you find that the ldd output for a new binary you want to
install is:
.nf
.Pp
libc.so.4 => /lib/libc.so.4.6.29
.fi
.Pp
you won't need to worry about copying /lib/libc.so.4.6.29 too,
because the program should work fine with the slightly older version.
You can decide to replace the libc.so anyway, and that should leave
you with:
.Pp
.nf
/emul/freebsd/lib/libc.so.4.6.29
/emul/freebsd/lib/libc.so.4 -> /emul/freebsd/lib/libc.so.4.6.29
.fi
.Pp
Please note that the symbolic link mechanism is
.Nm only
needed for FreeBSD binaries; the NetBSD runtime linker takes care
of looking for matching major revision numbers itself.
.Pp
Finally, you must make sure that you have the FreeBSD runtime linker
and its config files on your system.  You should copy these files
from the FreeBSD system to their appropriate place on your NetBSD
system (in the /emul/freebsd tree):
.Pp
.nf
/usr/libexec/ld.so 
/sbin/ldconfig
.fi
.Pp
.It 2.
You don't have access to a FreeBSD system.  In that case, you should
get the extra files you need from various web sites.  Information
on where to look for the various files is appended below.  For now,
let's assume you know where to get the files.
.Pp
Retrieve the following files (from _one_ ftp site to avoid any
version mismatches), and install them under /emul/freebsd (i.e.
/foo/bar is installed as /emul/freebsd/foo/bar):
.Pp
.nf
/sbin/ldconfig 
/usr/bin/ldd 
/lib/libc.so.x.y.z 
/usr/libexec/ld.so
.fi
.Pp
ldconfig and ldd don't necessarily need to be under /emul/freebsd,
you can install them elsewhere in the system too.  Just make sure
they don't conflict with their NetBSD counterparts.  A good idea
would be to install them in /usr/local/bin as ldconfig-freebsd and
ldd-freebsd.
.Pp
Create the file /emul/freebsd/var/run/ld.so.hints, containing the
directories in which the FreeBSD runtime linker should look for
shared libs.  It is a plain text file, containing a directory name
on each line. /lib and /usr/lib are standard, you could add the
following:
.Pp
.nf
/usr/X11/lib 
/usr/local/lib
.fi
.Pp
Note that these are mapped to /emul/freebsd/XXXX by NetBSD's compat
code, and should exist as such on your system.

Run the FreeBSD ldconfig program.  It should be statically linked,
so it doesn't need any shared libraries by itself.  It will create
the file /emul/freebsd/var/run/ld.so.hionts.  You should rerun the FreeBSD
version of the ldconfig program each time you add a new shared
library.
.Pp
You should now be set up for FreeBSD binaries which only need a
shared libc.  You can test this by running the FreeBSD ldd on itself.
Suppose that you have it installed as ldd-freebsd, it should produce
something like:
.Pp
.Bl -tag -width 123 -compact -offset indent
.It (me@netbsd) ldd-freebsd `which ldd-freebsd`
libc.so.4 => /lib/libc.so.4.6.29
.El
.Pp
You are now ready to install new FreeBSD binaries.  Whenever you
install a new FreeBSD program, check if it needs shared libraries,
and if you have them installed in the /emul/freebsd tree.  To do
this, run the FreeBSD version of ldd on the new program, and watch
its output.  ldd (see also the manual page for ldd(1)) will print
a list of shared libraries that the program depends on, in the form
<majorname> => <fullname>.
.Pp
If it prints "not found" instead of <fullname> it means that you
need an extra library.  <majorname> shows the library name, in the
form libXXXX.so.<N> You will need to find a libXXXX.so.<N>.<mm> on
a FreeBSD ftp site, and install it on your system.  The XXXX (name)
and <N> (major revision number) should match; the minor number(s)
<mm> are less important, though it is advised to take the most
recent version.
.Pp
.It 3.
You have a FreeBSD "live file system" CD-ROM.  In this case you
can run binaries directly from the CD.  You could mount the CD
volume at the /emul/freebsd directory, and the emulator will find
all the correct binaries and shared libraries beneath this point.
Programs that look for /etc/passwd entries will find the CD-ROM
version, however, so the following can be used to overlay the
read-only files with writable ones:
.Pp
.nf
mount -v -t cd9660 -o ro /dev/cd0a /emul/freebsd 
mount -v -t union /usr/emul/freebsd /emul/freebsd
.fi
.Pp
The /emul/freebsd and /usr/emul/freebsd directories need to be
created first.  Specific files such as passwd and group can be
placed there after the union mount is made.
.El
.Ss Finding the necessary files.
.Nm Note:
the information below is valid as of the time this
document was written 
(October, 1996), 
but certain details such as names of web sites, 
directories and distribution names
may have changed by the time you read this.
.Pp
http://www.freebsd.org, or one of the mirror sites.
.Pp
.Sh FILES
.nf
/emul/freebsd/  mount point or directory.
/emul/freebsd/usr/libexec/ld.so 
/emul/freebsd/lib/libc.so.x.y.z 
/emul/freebsd/sbin/ldconfig 
/emul/freebsd/usr/bin/ldd 
.fi
.Sh SEE ALSO
compat_linux(8), mount_union(8)
.Sh BUGS
The information about FreeBSD distributions may become outdated.
We need a list of programs that will not work here.
>Audit-Trail:
>Unformatted: