Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is a patched in-place binary identical to the binary that would be generated from a clean compilation?


No, some parts of the binary file will be unused in the final executable if you keep updating it incrementally.

The linkers will do what they can to reuse all previously freed blocks of the file, but you can imagine a scenario where a function is updated but does not fit in the block that was previously allocated for it. In this case, a new block of the file will be allocated for this function.

If you then add a smaller function, it will occupy some portion of the old block. You can keep adding things into this block until some minimum amount of memory is reached (and as long as the declarations fit in there, obviously).

Repeating this process for all new declarations and for all the modifications of declarations, you can imagine some parts of the files will remain unused.

I hope this makes sense :)


Doesn't sound like it. Seems like it appends the new versions of the functions and updates the global offset table.


Not quite, the linkers (at least ELF and PE which I am familiar with) will "free" parts of the file (when a block needs to be reallocated because the decl code gets too big, or when a decl is removed) and reuse them when they can.

But in general, the final executable will not be the same, this is correct.


Thanks for clarifying!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: