

Linking and loading: what's incidental? - chubot
http://www.cl.cam.ac.uk/~srk31/blog/2014/06/13/#linking-and-loading-complexity

======
eliben
"Few people care about all things simultaneously, so linking seems
overcomplicated to everyone. But all these concerns add to complexity
individually, and the tension between them also increases complexity."

This is true of all software, actually.

------
TheLoneWolfling
Personally?

I think that most compilers should not compile to machine code. They should
compile to an intermediate bytecode (only doing relatively generic
optimizations), something like LLVM but with precondition / postcondition
annotations. Call this phase 1. The operating system then takes that bytecode
and on first-run (or at any other time if a program explicitly asks for it)
compiles it to machine code, doing whole-program optimization, for the
specific machine. Call this phase 2.

The phase 1 compiler may split functions into a version with the original
semantics, and maybe versions that require preconditions / post-conditions.
Say, a hashmap constructor that requires the size to be a prime (that throws
an error otherwise) may get split into a version that checks if the size is a
prime that falls through into a function that just assumes the size is a
prime, with a precondition that the size is a prime. This can then be used by
the phase 2 compiler when appropriate.

For public functions, the phase 2 compiler _may_ decide to copy (a) functions
from the shared library to the program itself if there is enough incentive to
do so. Say, a function that does an expensive check that the compiler knows
isn't necessary, but the pass 1 compiler didn't split it out. The phase 2
compiler saves information regarding what optimizations were done / useful,
which can be passed back to the phase 1 compiler when appropriate.

(For cases where a compiler on the target device isn't really appropriate,
and/or the hardware of the target is fixed, you can cross-compile. Again:
"most".)

~~~
sillysaurus3
It might not be a good idea to push compile-time bugs to runtime.

EDIT: Whoops, I misread your comment. Sorry about that.

~~~
TheLoneWolfling
Can't you say the same about any interpreted / JITted language?

------
daurnimator
This article is the first I've heard of `dlvsym`. The idea of shared libraries
having more to their versions than just the name of the `.so`.

This was an informative post to read:
[http://www.trevorpounds.com/blog/?p=33;](http://www.trevorpounds.com/blog/?p=33;)
I just posted it to HN:
[https://news.ycombinator.com/item?id=8216999](https://news.ycombinator.com/item?id=8216999)

