Hacker News new | ask | show | jobs
by Animats 4219 days ago
Linkers don't get as much attention as they should. The linker has the last chance to look at the entire program before it runs. It's a good place for final checks and optimizations.

In Modula, each module had an "init" section. The Modula linker traced the dependencies of the "init" sections and arranged for them to be executed in a valid order. If there was a dependency loop, that was an error. That's way ahead of the C/C++ rules on order of initialization.

Elimination of duplicate code at link time is possible. For template and generic instantiations, this can be a big win, especially for C++.

Some linkers support "weak links" - if A has a weak link to B, and there are no strong links to B, B is not loaded and the link is null. This is useful for optional components which need some kind of startup.

1 comments

Vegedor, it looks like an early negative comment got your account auto-killed.

Quoting dead comment:

vegedor 17 hours ago |  link [dead]

GCC with --flto, literally link-time-optimizations, is new to me and seems to be good. It turns everything it can into constants, even inlines functions from pointer calls and resolves them if the arguments are also constant. That didn't work for me without it. Dunno if that's std compliant.