r/cpp • • Oct 10 '19

10 differences between static and dynamic libraries every C++ developer should know

https://www.acodersjourney.com/cplusplus-static-vs-dynamic-libraries/
5 Upvotes

25 comments sorted by

View all comments

13

u/mcmcc #pragma once Oct 10 '19

Surprisingly, no mention of Position Independent Code.

3

u/zvrba Oct 11 '19

That is not a thing on Windows. Each DLL has a preferred address and if that's already occupied at load-time, the DLL is relocated to another. Upside: no call redirection through PLT, so better performance. Downside: code page sharing across processes is potentially reduced, esp on 32-bit systems where it happens easier that two DLLs have clashing base addresses.

1

u/evaned Oct 11 '19

Downside: code page sharing across processes is potentially reduced, esp on 32-bit systems where it happens easier that two DLLs have clashing base addresses.

Another downside: it makes ASLR either far more expensive or less effective, or both. (If two processes share a library, either it will have to be at the same location, meaning less effective, or at least one will have been relocated, meaning extra load time costs plus extra memory use.)