Re:“Shared libraries are not a good thing in general”
by MereInterest on Saturday May 01, 2021 @07:02PM
(#27010705)
Yes, but LTO doesn't apply across shared object libraries. Suppose I write a video game that uses DirectX for graphics, but I don't use the DirectX Raytracing feature at all. Because of DLL hell, I'm going to be shipping my own version of the DirectX libraries, ones that I know my video game is compatible with. Those are going to be complete DirectX libraries, including the Raytracing component, even though I don't use it at all in my game. No amount of LTO can remove it, because theoretically that same library could be used by other programs.
On the other hand, if I am static linking, then there are no other programs that could use the static library. (Or, rather, if they do, they have their own embedded copy.) The LTO is free to remove any functions that I don't need, reducing the total amount that I need to ship.
Re:“Shared libraries are not a good thing in general”
by hdhrnnrkrkf on Saturday May 01, 2021 @09:21PM
(#27011522)
DirectX is a bad example, it's now a part of Windows and you don't ship it anymore.
Re:“Shared libraries are not a good thing in general”
by MereInterest on Saturday May 01, 2021 @10:46PM
(#27011959)
Good point (and shows that I am not a video game developer). I had tried to pick DirectX as something that would follow fao_'s example of game developers. The point still holds in the general case, though as you pointed out, not in the case of DirectX in particular.
Re:“Shared libraries are not a good thing in general”
by yakubin on Saturday May 01, 2021 @07:00PM
(#27010689)
Even without LTO, linker will discard object files that aren't used (on Linux a static library is just an AR archive of object files). It's just a different level of granularity.
Re:“Shared libraries are not a good thing in general”
by floatboth on Saturday May 01, 2021 @08:28PM
(#27011243)
You can get better granularity – build with -ffunction-sections, link with --gc-sections.
LTO is really a much bigger deal, the main reason to use it is not throwing unused stuff away, but inlining across all the things.
Link-time optimization is already a thing. It's sad it doesn't seem to be used more often.