It is theoretically possible. You basically have to do the same job as the dynamic linker, with some changes, i.e.
- delete all sections from the source file
- Allow characters
- find libraries
- instead of loading them into memory, assemble them into a “virtual image”
- allow internal links
- flushes everything in an independent file.
So objdump , objcopy and objcopy will be some of your friends.
The task is not easy, and the result will be neither automatic nor (possibly) stable.
You can check this code to others who have tried the same thing, actually intercepting the dynamic linker (i.e. all the steps above except the last one) and flushing the results to disk.
It is based on this tool , so any of them makes a bet whether it works on the latest kernels.
(This is probably not the case, and you should at least plan it to reflect new structures. This is my attempt at the same time. Caution emptor).
source share