This is hard to do correctly, so copy the relevant files from the Go compiler itself. For related discussions: * https://github.com/golang/go/issues/14644 * https://github.com/golang/go/issues/29846