From owner-freebsd-questions@FreeBSD.ORG Thu Aug 7 20:13:26 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 78889106567A for ; Thu, 7 Aug 2008 20:13:26 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from mail-out3.apple.com (mail-out3.apple.com [17.254.13.22]) by mx1.freebsd.org (Postfix) with ESMTP id 5C6798FC15 for ; Thu, 7 Aug 2008 20:13:26 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from relay12.apple.com (relay12.apple.com [17.128.113.53]) by mail-out3.apple.com (Postfix) with ESMTP id 484FE35B5A3E; Thu, 7 Aug 2008 13:13:26 -0700 (PDT) Received: from relay12.apple.com (unknown [127.0.0.1]) by relay12.apple.com (Symantec Mail Security) with ESMTP id 2FED246400B; Thu, 7 Aug 2008 13:13:26 -0700 (PDT) X-AuditID: 11807135-a75f4bb000001321-42-489b5765bf9e Received: from cswiger1.apple.com (cswiger1.apple.com [17.227.140.124]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by relay12.apple.com (Apple SCV relay) with ESMTP id 5BDD5420002; Thu, 7 Aug 2008 13:13:25 -0700 (PDT) Message-Id: From: Chuck Swiger To: Andrea Venturoli In-Reply-To: <489B4D7F.1040406@netfence.it> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v928.1) Date: Thu, 7 Aug 2008 13:13:25 -0700 References: <26ddd1750808071055i2b9976b3i4f347407d94a0813@mail.gmail.com> <489B3909.6080702@FreeBSD.org> <489B4D7F.1040406@netfence.it> X-Mailer: Apple Mail (2.928.1) X-Brightmail-Tracker: AAAAAA== Cc: FreeBSD Questions Subject: Re: Mixing 64 and 32-bit code (was: Linking amd64 binary with a 32-bit linux library) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Aug 2008 20:13:26 -0000 On Aug 7, 2008, at 12:31 PM, Andrea Venturoli wrote: >> You can't mix and match Linux and FreeBSD code in the same binary. > > Sorry for stepping in, but I have a similar question I asked in the > past and didn't get any answer: > is it possible to mix and match 32-bit and 64-bit FreeBSD code? > > I have a closed source 32-bit library which I'd like to link to on a > 64-bit system... The simplest answer is that it won't work-- the syscall interface and function argument/return-value sizes are going to be different between 32-bit and 64-bit code. If you have 32-bit code compiled with -fPIC which doesn't make any system calls, and is using all C99 datatypes (rather than native datatypes like "int" or "long" which are going to change in size under an ILP64 environment), well, that might be linkable into a 64-bit binary, but even so I wouldn't count on it to work without a translation shim. [1] Regards, -- -Chuck [1]: You can look up how thunking between Win16 and Win32 code worked here: http://en.wikipedia.org/wiki/Thunk#Thunk_as_compatibility_mapping ...but the same idea could be applied to generic 32-bit & 64-bit ELF code. (It's really an evil thing to try to do, however.)