cleanup of linkage processing code, part 1

This batch of changes reorganizes how linkage processing is performed. Additional steps and optimizations are yet to come; for now, te code compiles, runs and does not leak memory.

The code is a little simpler now, avoiding several stages of copying.