7

I have an application, say gedit, which is dynamically linked and I don't have the source code. So I can not compile it as I like. what I want to do is to make it statically linked and move it to the system which doesn't have the necessary libraries to run that application. So is it possible to do it and how?

1 Answer 1

1

It is theoretically possible. You basically have to do the same job that the dynamic linker does, with some modifications, i.e.

  • dump all sections from the original file
  • resolve symbols
  • locate libraries
  • instead of loading them into memory, assemble them into a "virtual image"
  • resolve internal links
  • dump the whole thing in a independent file.

So objdump, readelf, and objcopy will be some of your friends.

The task is not easy and the result will be neither automatic, nor (probably) stable.

You may want to check out this code by someone else that tried the same, by actually intercepting the dynamic linker (i.e. all steps above, except the last) and dumping the results to disk.

It is based on this tool, so it's anyone's bet whether it works on the newest kernels.

(It probably doesn't - and you need at least to patch it to reflect the new structures. This is my attempt at doing so. Caveat emptor).

Sign up to request clarification or add additional context in comments.

3 Comments

I see. So it is not possible just to dump the objects from the elf file and then to statically link them.
The link to 'this tool' is broken and the last link is a patch to it.
@DavidJ the binary file is still available through the Wayback Machine (for the binary, the URL is web.archive.org/web/20130114222319if_/http://dagobah.ucc.asn.au/… )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.