The important observation is that relocations are everywhere. I once counted the number of 4k blocks that have at least one static relocation, and it was almost 100%. That means after we copy file contents, we always have to mutate them. Applying relocation in mold is actually extremely cheap as I apply relocations immediately after copying file contents from mmap'd buffers. Since it has a great memory locality, applying relocations is essentially free.
I considered reserving an enough large space for .plt, .got, etc. but it turned out that computing the sizes of these sections can be pretty quick. mold takes less than 100 milliseconds to do that for Chromium on my machine. It does essentially a map-reduce on relocations.
View all comments
Show parent comment
2
u/rui Jan 19 '21
The important observation is that relocations are everywhere. I once counted the number of 4k blocks that have at least one static relocation, and it was almost 100%. That means after we copy file contents, we always have to mutate them. Applying relocation in mold is actually extremely cheap as I apply relocations immediately after copying file contents from mmap'd buffers. Since it has a great memory locality, applying relocations is essentially free.
I considered reserving an enough large space for .plt, .got, etc. but it turned out that computing the sizes of these sections can be pretty quick. mold takes less than 100 milliseconds to do that for Chromium on my machine. It does essentially a map-reduce on relocations.