Search code examples
c++cgccfpic

c/c++ convert position dependent object to be position independent


I have some compiled object file with debug symbols, but no acces to the sources.

Is there any method to convert this file to be position independent?

As far as I understand the '-fPIC' flag it makes all jumps to be relative. I'm wondering if having debug symbols is enough to be able to fix this jumps and so create a PIC binary.

If not please tell me why this operation is impossible to be done.


Solution

  • I think this question is rather platform than compiler specific since different platforms implement PIC code differently.

    Nevertheless, I don't know of any platform where it would be possible with a simple tool to convert conventional code into position indepependant code. This is a decision that has to be made at compile/code generation time. Probably the only way to achieve your goal would be to disassemble the code and modify every absolute code/data reference into relative addressing.

    The short answer would be: no, (practically) impossible.