Discussion:
relinking a program with shared library
Marcin Kasprzak
2008-12-29 12:17:20 UTC
Permalink
Hello,
I wonder to know if it is possible to somehow perform
a static (re)linking of already compiled binary that uses a shared libs?
For example I have a binary "bin" which depends on "libA.so" and "libB.so".
Would it be possible to relink it statically so that both libraries
would be included within "bin"?
[ I don't have access to source code of that program ]

It would be even better if such a command could work recursively,
in case for example "libA.so" depends on "libA1.so" and "libA2.so".

I would appreciate any help from your side, thanks.
--
Marcin
Tim Prince
2008-12-29 15:22:03 UTC
Permalink
Post by Marcin Kasprzak
I wonder to know if it is possible to somehow perform
a static (re)linking of already compiled binary that uses a shared libs?
For example I have a binary "bin" which depends on "libA.so" and "libB.so".
Would it be possible to relink it statically so that both libraries
would be included within "bin"?
If this were possible on some platform, it would be a function of the
linker system (binutils, for many gcc targets). It's certainly not
something gcc itself could do.
On all systems I am familiar with, if you have the objects made by gcc,
you can accomplish this by re-linking.
Marcin Kasprzak
2008-12-29 22:40:37 UTC
Permalink
Post by Tim Prince
If this were possible on some platform, it would be a function of the
linker system (binutils, for many gcc targets). It's certainly not
something gcc itself could do.
On all systems I am familiar with, if you have the objects made by gcc,
you can accomplish this by re-linking.
Hi Tim,
This is also my understanding, I sent this inquiry to this maillist s
ince I didn't know a better place to ask (sorry if that's a wrong place).

My platform is x86 machine, running linux with ELF executable.
I'm thinking about the way of doing a sort of conversion from
.so (PIC) to .a (static) lib and then (this part is more tricky) to
relink it against binary.
As I wrote previously I don't have access to source code or .o (object)
files (this is a sort of 3rd party software).

I believe that two separate actions are needed:
1. Conversion from .so to .a
2. decomposition of binary file back to .o files and
one again linkage(ld) process this time against static libs

Is it possible to do that?

Thanks,
--
Marcin
Ian Lance Taylor
2008-12-30 02:34:28 UTC
Permalink
Post by Marcin Kasprzak
My platform is x86 machine, running linux with ELF executable.
I'm thinking about the way of doing a sort of conversion from
.so (PIC) to .a (static) lib and then (this part is more tricky) to
relink it against binary.
As I wrote previously I don't have access to source code or .o (object)
files (this is a sort of 3rd party software).
1. Conversion from .so to .a
2. decomposition of binary file back to .o files and
one again linkage(ld) process this time against static libs
Is it possible to do that?
No. It is not possible to run a .so file into a .a file. The .so
file no longer has any record of the various places which call into
the PLT and GOT. It might be possible to do an approximation by
somehow introducing an initialization routine which set up the PLT and
GOT as required. I don't know of any tool which does that.

It is not possible to turn a linked executable back into .o files.
The relocation information has been irretrievably lost.

Ian
Marcin Kasprzak
2008-12-30 17:51:27 UTC
Permalink
Post by Ian Lance Taylor
No. It is not possible to run a .so file into a .a file. The .so
file no longer has any record of the various places which call into
the PLT and GOT. It might be possible to do an approximation by
somehow introducing an initialization routine which set up the PLT and
GOT as required. I don't know of any tool which does that.
It is not possible to turn a linked executable back into .o files.
The relocation information has been irretrievably lost.
Hi Ian,
Many thanks for yours and Tim's explanation.
I will have to somehow live without this feature;-)

Once again thanks,
--
Marcin
Loading...