Could self-modifying code be used to speed up function calling in dynamically linked libraries?
As far as I understand it, ELF shared libraries use a kind of indirect jump table (the procedure linkage table, or PLT) to enable lazy binding of library functions. The purpose seems to be to avoid having to modify the table in the code segment while still enabling lazy resolution of function positions at the first call.
Wouldn't it be faster to dynamically create the code for that table at load time, or possibly even at the first function call?
Is it to enable sharing of the code segment between processes as much as possible (a dynamic table would be private to a process)? Is it for security reasons (writable code shouldn't be executable - but JITs do that all the time, and the write permission could be added and removed by the loader before actually starting the program)?
Or is it a combination of those, and the small performance gain per function call just wouldn't be worth the effort?