[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Wrapping code



Leopold Palomo-Avellaneda <lepalom@wol.es> writes:

> Hi,
>
> I have a question that maybe could be an off topic but I think that it could 
> be interesting for the amd64 users. 
>
> I have a library code with some executables of a device. This device uses the 
> parallel port and provides a library to use it with some more functionalities 
> (provides some .so and some .h to link with). 
>
> Of course I don't have the source code and worst the library is compiled for 
> RedHat 7.2 :-( (gcc-2.96 ...)
>
> I have though that maybe it could be possible to develop a wrapper to use the 
> library in the way that I can update compiler and distro and also arch amd64) 
> but really, I don't know if is this possible and how to begin.
>
> Is this possible or I'm asking something stupid?

It is possible. Nothing is impossible. But it is also quite stupid.

You would need a very god reason, like you get paid for it, to do this.

> If it's possible, how I can do that? rewriting the headers and a cpp code 
> calling the library functions? and the compiler, have I to make some special 
> flag? can I reuse a .so as a .a?
>
> This idea could help to the people that have devices that have libraries to 
> develop with them but not the source code and for example want to change of 
> distro or upgrade an a amd64. Of course that if the library is compiled in a 
> 32 bits it will be 32 bit, but it's possible to mix 64bit and 32bits code?

You need a library that mmaps the old library into a 32bit address
space, provides a wraper function for every function that uses 64bit
calling convention, translates those into 32bit variables, copies all
pointer targets into the 32bit address space and adjusts them, calls
the origianl function with the gcc-2.96 C calling conventions (which
differ miniscule from current gcc) and in 32bit mode, and reverses all
that with the results. Especialy for the pointer conversions you need
detailed knowledge of every function, so no automatic conversion
possible there.

On the other hand you might just be able to just use the library as is
in 32bit mode, unless some glibc symbols clash or they use one of the
very rare construct with abi changes. And thats why the wraper is stupid.

> well, thank's in advance,
>
> Best regards,
>
> Leo

MfG
        Goswin



Reply to: