Date: Thu, 11 Aug 2005 10:46:04 -0600 (MDT) From: "M. Warner Losh" <imp@bsdimp.com> To: ume@FreeBSD.org Cc: hackers@FreeBSD.org, dnelson@allantgroup.com Subject: Re: Converting libfoo.so for linux to freebsd Message-ID: <20050811.104604.61335403.imp@bsdimp.com> In-Reply-To: <ygevf2e4c42.wl%ume@mahoroba.org> References: <20050809.133734.08360256.imp@bsdimp.com> <20050809213130.GB71687@dan.emsphone.com> <ygevf2e4c42.wl%ume@mahoroba.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In message: <ygevf2e4c42.wl%ume@mahoroba.org> Hajimu UMEMOTO <ume@FreeBSD.org> writes: : Hi, : : >>>>> On Tue, 9 Aug 2005 16:31:30 -0500 : >>>>> Dan Nelson <dnelson@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050811.104604.61335403.imp>