Reland of 00bf4755.
This patches fixes the visibility and linkage information of symbols
referring to IR globals.
Emission of external declarations is now done in the first execution
of emitConstantPool rather than in emitLinkage (and a few other
places). This is the point where we have already gathered information
about used symbols (by running the MC Lower PrePass) and not yet
started emitting any functions so that any declarations that need to
be emitted are done so at the top of the file before any functions.
This changes the order of a few directives in the final asm file which
required an update to a few tests.
To be honest, we shouldn't be using Subtarget or TLI here at all since using these means we are inside a Function. But we aren't, what we do is set Subtarget from the last Function we saw. Which means that it will always be assigned to the Subtarget from the last seen Function. This might be ok in the Wasm backend but not in general and breaks when no function is defined. However, as far as I can tell from doing some checks whenever we call this _and_ Subtarget is null, we don't need to call computeLegalValueVTs therefore I added this check.