Converting libfoo.so for linux to freebsd

M. Warner Losh imp at bsdimp.com
Thu Aug 11 16:48:27 GMT 2005


In message: <ygevf2e4c42.wl%ume at mahoroba.org>
            Hajimu UMEMOTO <ume at FreeBSD.org> writes:
: Hi,
: 
: >>>>> On Tue, 9 Aug 2005 16:31:30 -0500
: >>>>> Dan Nelson <dnelson at allantgroup.com> said:
: 
: dnelson> In the last episode (Aug 09), M. Warner Losh said:
: > I have recently purcahsed a device that comes with a .so for linux,
: > but no sources.  Is there any way one can take an arbitrary linux .so
: > which appears to have no dependencies to a FreeBSD .so?  The binary
: > code is about 20k or so.
: 
: dnelson> As long as any structs that are passed back and forth have the same
: dnelson> members and alignment, it should work.  This includes struct FILE,
: dnelson> which means if the app tries to use stdio it'll likely crash.
: 
: dnelson> I just compiled a little "hello world" object file on SUSE and linked
: dnelson> it on FreeBSD and it ran (it just calls printf, which is safe since it
: dnelson> doesn't pass a FILE *).
: 
: As far as the Linux shlib uses the functions which ABI are compatible
: with FreeBSD's one, it should work.  However, if there are some ABI
: incompatibility, you may want to consider the approach of
: linuxpluginwrapper.
: The PIPS ports (print/pips*) link Linux shlib to FreeBSD binary.  To
: do this, the PIPS ports use www/linuxpluginwrapper to fixup some ABI
: incompatibility.

umemoto-san

This was exactly the hint that I needed to get things working.  My
brother MCP-5440CN scanner is now working (don't know about the
printing side of things, since I've not tried that at all).  Thank
you so very much!

Here's a breif outline of what I've learned:

	(1) To remove the symbol versioning goo from a shared library,
		objcopy -R .gnu.version linux.so freebsd.so
	(there's also a .gnu.version_r on some libraries, that can
	also be removed this way).  Doing this allows one to directly
	link the .so into your program, modulo ABI issues.

	(2) dlopen (and likely ld-elf.so in general) doesn't check the
	version information at all.  If all you are doing is linking
	dynamically at run time, you don't have to perform step #1.
	The compile time linker, however, whines about missing symbol
	versions.

	(3) Use libmap.conf to map libc.so.6 for the shared library
	that you are loading to overcome ABI issues.  See the man page
	for an example.

The linuxplugwrapper port can be used to generate shims for the ABI
issues, in general, and works well.  I'll likely not use it for the
brother scanner port I'm working on since all I need is stderr defined
in a linuxly correct, and I can do that in the source part of the
driver.  I'd love to get the network side of things working, but I
think that might be more effort than I care to go to at the moment.
I'd also like to get faxing and printing working, but again, time...
I bought it for the 35 sheet document feeder + scanner at $100.00
after rebate :-)

Warner


More information about the freebsd-hackers mailing list