Dynamic linking enabling in edk2 - shijunjing/edk2 GitHub Wiki
Background:
Uefi firmware is very sensitive on code/image size. Millions of code have to be linked into only several MB ROM space. Every KB counts for us. But Uefi only support static linking for now and there are many common library function built into each module. We use the compression on multiple modules to mitigate the common library code size issue but it is not an ideal solution. The compressed module need memory to decompress in runtime but Uefi have modules need to run (XIP) before the memory is ready. So we have the requirement to support dynamic linking.
We once had one POC in edk2 staging to support the driver combination. Here is code https://github.com/tianocore/edk2-staging/tree/BaseToolsOpt. This can help with the duplication between non-hardware specific PEIM. But it will not help with our hardware specific PEIM. Our IP block libraries use build flags to include different register sets. So the functions all have the same names and cannot be built into a single PEIM without name collisions. Whereas a DLL capability will let us separate common functions in a more performance optimized way.
Differences between dynamic linking and static linking: https://docs.microsoft.com/en-us/cpp/build/dlls-in-visual-cpp?view=vs-2017
LLD community happen to discuss a proposal of automatically partitioning a program into multiple binaries, which looks quite fit for Uefi dynamic linking enabling: http://lists.llvm.org/pipermail/llvm-dev/2019-March/130744.html