mold icon indicating copy to clipboard operation
mold copied to clipboard

Directly relocate PLT entries?

Open rui314 opened this issue 3 years ago • 0 comments

If -z now is passed to the linker, the linker sets a flag to its output so that the dynamic loader resolves all relocations for PLT on process startup (i.e. disabling lazy name resolution for PLT). If this is the case, each PLT entry always read the same value from its corresponding .got.plt entry. So the runtime cost of a PLT entry is one memory load (which is likely to be cached though) and an indirect jump (which may be predictable but may not be as cheap as a direct jump that doesn't need any branch prediction).

So here is an optimization idea: What if we let the dynamic loader to directly relocate PLT entries instead of .got.plt? This could improve program's runtime performance because we can emit direct call instructions instead of indirect ones for PLT.

Directly relocating PLT entries means that we relocate a text section, but it may not be as bad as believed. At least in this case, we only relocate PLT entries, so there wouldn't be too many places to relocate.

rui314 avatar Apr 25 '22 03:04 rui314