public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Extract static object from dynamic one
@ 2007-12-03 23:22 Thomas Köppe
  2007-12-04 11:58 ` Tom Browder
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Köppe @ 2007-12-03 23:22 UTC (permalink / raw)
  To: gcc-help

Hello,

I've been wondering about a relatively simple question for which there 
seems to be no obvious answer - am I overlooking something?

Suppose I have a dynamic C library libfoo.so (or foo.dll) along with 
headers in foo.h. Is it possible to build from the binary a static 
library libfoo.a?

I'm thinking that this should be easy, since I know all the function 
signatures and entry points in the binary; is there some way (maybe with 
objcopy or objdump?) in which I can extract the binary code for a 
specific function?

Thank you very much,

Thomas K.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: Extract static object from dynamic one
@ 2007-12-04 14:47 Duft Markus
  2007-12-04 15:06 ` Thomas Köppe
  0 siblings, 1 reply; 8+ messages in thread
From: Duft Markus @ 2007-12-04 14:47 UTC (permalink / raw)
  To: Thomas Köppe, gcc-help; +Cc: Tom Browder

Hi!

At least on windows some information that would have been included in a static library is processed and after that discarded by the linker. For example, in a release link of a DLL there are no more symbol names (except for those that are exported - and that only when not importing by ordinal numbers), so it would be impossible to come up again with the signature for a particular (internal) function.

I believe ELF keeps symbol names somewhere, but i'm not sure. Anyway i don't think, that a shared library contains all information a static library has. (for example at least the names of the objects containing the various functions are discarded.)

Cheers, Markus

Thomas Köppe <> wrote:
> Brian Dessent wrote:
>  >
>  > Tom Browder wrote:
>  >
>  >> On Dec 3, 2007 5:21 PM, Thomas Köppe <t.koeppe@ed.ac.uk> wrote:
>  >>
>  >>> [...]
>  >>>
>  >>> Suppose I have a dynamic C library libfoo.so (or foo.dll) along
>  with >>> headers in foo.h. Is it possible to build from the binary a
>  static >>> library libfoo.a?
>  >>
>  >> I believe GNU libtool can be used to do that.
>  >> [...]
>  >
>  > Libtool is useful for creating both shared and static at the same
>  > (build) time, but it won't let you create a static library from an
>  > already linked shared library.  There is no way to do that, as far
>  as I > know.  You need to recompile from source.
>  >
>  > Brian
> 
> I agree that libtool does not deal with binary files in that way;
> that's why I was thinking about something from binutils.
> 
> But is there a reason that it should be impossible in principle to
> reconstruct a statically linkable object from a shared library? After
> all, the code is there, I know the function signatures, and
> relocatable addresses can be resolved to fixed addresses at link time.
> 
> Is there an obstruction in principle (that some vital information is
> lost in the shared library), or is it simply that no such tool has
> been written?
> 
> Many thanks,
> 
> Thomas


-- 
5. Dezember 2007
Salomon Automation am  Schweizer Forum für Logistik, Lausanne, CH




Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht für Zivilrechtssachen Graz

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-12-04 16:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-03 23:22 Extract static object from dynamic one Thomas Köppe
2007-12-04 11:58 ` Tom Browder
2007-12-04 13:05   ` Brian Dessent
2007-12-04 14:08     ` Thomas Köppe
2007-12-04 14:19       ` Brian Dessent
2007-12-04 16:13         ` Ian Lance Taylor
2007-12-04 14:47 Duft Markus
2007-12-04 15:06 ` Thomas Köppe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).