cassemblygcc

gcc command for keeping addresses as they were?


Is there a way to keep the offsets of all functions and variables as they were, everytime I'm compiling the program?


Solution

  • No. This is not a limitation of the compiler per se, but a "logical" limitation. Imagine you have a box that is full of stuff. Now you want to add stuff on box A but you don't want a new box. Well, you can't, it's a physical limitation.

    Or talking more "computerish":

    Function a() occupies from address 0 to 0xA00 (size 0xA00)

    Function b() occupies from address 0xA01 to 0xB00 (size 0x100)

    Now you modify a() so that's it's bigger, let's say its size is now 0xB00. How would you keep both a() and b() in the same address? You can't unless you do some nasty tricks like splitting the function a() into 2 parts, but I think this is not what you want.

    This without considering that modern OS have ASLR and other security methods.