cmd/compile,cmd/link: resolve cgo symbols to the correct Go ABI
Currently, Go functions exported to cgo have some confusion around
ABIs that leads to crashes. The cmd/cgo-generated C code references an
exported Go wrapper function (which calls the underlying exported user
function). The linker resolves this reference to the ABI0 entry-point
to that Go wrapper function because all host object references are
currently assumed to be to version 0 of a symbol. This gets passed via
crosscall2 and winds its way to cgocallbackg1, which puts this ABI0
entry-point into a function value and calls it. Unfortunately,
function values always use the ABIInternal calling convention, so
calling this ABI0 entry-point goes poorly.
Fix this by threading definition ABIs through the cgo export mechanism
so the linker can resolve host object references (which have no
concept of multiple ABIs) to the correct Go symbol. This involves a
few pieces:
- The compiler extends the cgo_export_{static,dynamic} directives that
get passed on to the linker with symbol definition ABIs.
- The linker parses the ABIs in the cgo_export_{static,dynamic}
directives to look up the right symbol to apply export attributes to
and put in the dynexp list.
- For internal linking, the linker's Loader structure tracks the right
symbol (in particular the right ABI) to resolve host object
references to, and we use this in all of the host object loaders.
- For external linking, we mangle only the non-ABIInternal symbols
now, so the external linker is able to resolve the correct reference
from host objects to Go symbols.