selfrando
selfrando copied to clipboard
Possible performance regression due to the new relocation de-duplication implementation
In commit https://github.com/immunant/selfrando/commit/7e550c6f651a748adbac215988cfeff95fc2202b, I added a list of "arch relocs" (basically, architecture-specific dynamic relocations), which we use to patch the GOT, .got.plt
and whatever else gets dynamic relocations. To prevent duplicate relocations between TRaP relocations and the "arch relocs", we keep track for each arch reloc whether it's already been applied (either by a TRaP relocation or the arch one itself). We keep track and update the markings in AdjustRelocation
, which requires us to do a binary search through the list of arch relocs twice for every call to AdjustRelocation
. This may have introduced a performance regression.
We can fix this by filtering out duplicate relocations earlier using a linear pass over all 3 kinds of relocations (TRaP record relocations, TRaP non-exec relocations and arch relocs) and merging the 3 sets into one, but that is a bit tricky to implement.
Another solution would be to use a bitmap to mark applied relocations, with one bitmap bit per byte in the binary, which would require 12.5% extra memory during randomization.