Agner`s CPU blog

Software optimization resources | E-mail subscription to this blog | www.agner.org

New idea: Re-linkable libraries in ForwardCom
Author: Agner Date: 2017-04-27 00:03
I am working on the binary utilities for ForwardCom, and I have got an idea of a new concept for function libraries.

The well-known method for static linking is used. An option to the linker specifies that certain object files or library files should be re-linkable. The necessary symbol and relocation records are then preserved in the executable file so that the library functions can later be replaced by repeating the link process.

This concept has many advantages:


  • The executable file is ready to run without any external dependencies. You will never have problems with a missing DLL or a wrong version of a shared object.

  • An important advantage of static linking is that you don't have to load a large dynamic library containing hundreds of functions when you only need a few of these functions. The re-linking feature combines this advantage with the ability to update or replace a library later or to use a third-party library, which traditionally requires dynamic linking.

  • If you update a DLL in Windows, you are affecting all programs that use this DLL, even if some programs work better with the old version. With re-linkable libraries, you can update a library in each program separately.

  • You can update or modify a program without access to the original source code.

  • The rarely used symbol interposition feature in shared objects is very inefficient because all accesses to public symbols go through global offset tables (GOT) and procedure linkage tables (PLT). These inefficient table lookups are not needed with the relink method

  • You can have different versions of your functions for different platforms. For example, the same program can have different graphical user interfaces for different environments. The appropriate version can conveniently be linked to the executable program as part of the installation procedure.

  • You can have specific versions of a critical piece of code optimized for different microprocessor models.

  • You can reconfigure a program at any time if you update the hardware or operating system.

  • You are not wasting time on loading and linking dynamic libraries every time a program is loaded.

  • Modifying or updating an executable program requires administrator privileges, for security reasons.

  • While this concept is intended for ForwardCom, it can also be implemented in existing systems. The only thing this requires is a new linker. Run-time loading of this kind of library is only possible in ForwardCom, though.

I have previously proposed a feature to link in libraries when a program is loaded, where the choice of library can depend on environment variables, or whatever. Do we still need this feature if we have relinking at install time? I think it is safer to relink when a program is installed than when it is loaded, because a hacker might insert a tampered-with library to be linked at load time.
If relinking requires administrator privileges then it is more convenient to do it when the program is installed. In the rare cases where a choice between different versions needs to be done at load time, it would be safer (and faster) to store different ready-made versions of the executable file.

Any comments?

 
thread New idea: Re-linkable libraries in ForwardCom - Agner - 2017-04-27
last replythread New idea: Re-linkable libraries in ForwardCom new - Hubert Lamontagne - 2017-04-27
last replythread New idea: Re-linkable libraries in ForwardCom new - Agner - 2017-04-27
last replythread New idea: Re-linkable libraries in ForwardCom new - Hubert Lamontagne - 2017-05-10
last replythread New idea: Re-linkable libraries in ForwardCom new - Agner - 2017-05-11
last replythread New idea: Re-linkable libraries in ForwardCom new - Hubert Lamontagne - 2017-05-12
last reply New idea: Re-linkable libraries in ForwardCom new - Agner - 2017-05-13