Implemented a linkage attribute for functions and foreign statics.

Closes #7196 and obsoletes #9945 (I've reused the test from the latter, with the added `linkage(external)` attribute).
The subset of allowed linkages is left to be decided by the reviewers.