3 ms·
As always, static and dynamic linking both have their advantages and drawbacks. The usual arguments for dynamic linking around brought up in the article, and as
by saagarjha 6y ago
As always, static and dynamic linking both have their advantages and drawbacks. The usual arguments for dynamic linking around brought up in the article, and as others have mentioned here, the analysis is a bit lacking so the conclusions aren't generally true. Static linking has its own, fairly straightforwards benefits as well. It's no surprise that those who push one or the other usually do so because of their specific needs. Sometimes we even see some interesting hybrid solutions: one recent one is Apple introducing dyld shared caches on macOS, which (while being a pain to reverse engineer) are basically all the system (dynamic) libraries all statically linked together and presented dynamically, with some linker tricks to make it appear seamless. Likewise, a lot of statically linked binaries are only partially statically linked, still using things like libc or graphics libraries. The moral really is to try both and pick whichever one is the one that's better for your use case, and perhaps even consider a mix of both to give you the most flexibility in which tradeoffs you'd like to make.
- cryptonector 6y agoSpecifically for C, static linking is a trap due to its poor semantics. Don't do it. Or fix the C link-editors, then static linking C will be fine.
- sigjuice 6y agoWhat would be examples of poor static linking semantics? Thanks!
- cryptonector 6y agohttps://news.ycombinator.com/item?id=23656173 https://news.ycombinator.com/item?id=23656173
- comex 6y agoNitpick: macOS has used dyld shared caches for over a decade. The recent change is just to remove the original copies of the libraries on disk.
- saagarjha 6y agoAh, you're right. Forgot that they were being used already :) I'm curious what would happen though if you modified a system library and didn't update the cache, though…
- comex 6y agodyld would check the modification time and inode and avoid using the shared cache version if there’s a mismatch. (So I gleaned from the documentation of the DYLD_SHARED_CACHE_DONT_VALIDATE environment variable, which tells it not to do that.)