This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 32-bit libraries in 64-bit build.


On Wed, May 20, 2009 at 09:03:53AM -0700, Bob Plantz wrote:
> On Wed, 2009-05-20 at 07:47 -0700, Ian Lance Taylor wrote:
> > Brian McGrew <brian@visionpro.com> writes:
> > 
> > > Is there any way of using a 32-bit library in a 64-bit build environment???
> > > Our entire software build is 64-bit but I need to use a vendors library that
> > > is only 32-bit and never will be 64-bit.  Any such way of accomplishing this
> > > task?
> > 
> > No.  If an x86 processor is running in 64-bit mode, then it can not
> > execute code compiled in 32-bit mode.  The two modes are not compatible.
> > 
> > The closest you can come is to write a 32-bit wrapper program around the
> > library, run it in a separate process, and use some sort of RPC to
> > communicate with it.
> > 
> > Ian
> 
> Wouldn't this depend on whether it is statically linked or dynamic? I
> could certainly use 32-bit mode calling conventions in my 64-bit code
> and call a function that uses only 32-bit instructions.
> 
> (I'm probably revealing my ignorance of libraries here.)

In theory it might be possible, but in practice it is not supported.  You would
have to make sure that the dynamic linker loads the 32-bit library in the first
32-bit part of the address space.  The 32-bit library would not be able to call
any functions in the standard library, since those use the 64-bit ABI.  You
would have to make sure that all addresses passed to the 32-bit library are
located in the 32-bit memory area, and that all structures used were 32-bit
structures as well.  64 and 32-bit programs use a completely different ABI, and
the stack is set up differently.  Finally, some 32-bit instruction encodings
are not available when the computer is in 64-bit mode, and others behave
differently when the 64-bit registers are enabled.

-- 
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
meissner@linux.vnet.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]