Repository: go
Issue: cmd/cgo: failed to run c-archive library built for iOS
Labels: NeedsInvestigation,mobile,compiler/runtime

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.15.1 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?

Yes

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/roger/Library/Caches/go-build"
GOENV="/Users/roger/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/roger/go/pkg/mod"
GONOPROXY="github.com/XXXXXX"
GONOSUMDB="github.com/XXXXXX"
GOOS="darwin"
GOPATH="/Users/roger/go"
GOPRIVATE="github.com/XXXXXXX"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/roger/Development/XXXXX/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y8/8fn4c6b54y38lyvqcmsxk9hc0000gn/T/go-build298028240=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->

Create a simple go program that has C export function:
```go
package main

import "C"

//export sayHello
func sayHello() string {
	return "Hello from Go\x00"
}

func main() {}
```
build the code with the following:

```zsh
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 CC=$(shell go env GOROOT)/misc/ios/clangwrap.sh CGO_CFLAGS="-fembed-bitcode" go build -buildmode=c-archive -tags ios -o arm64.a .
```

Build is successful.

Add the `arm64.a` and `arm64.h` to an iOS project in XCode, and add `#import "arm64.h"` to the bridging header file.

Call the `sayHello` function from Swift:

```swift
let hello = sayHello()
self.helloLabel = String.init(cString: hello.p, encoding: .utf8)!
```

### What did you expect to see?

XCode to build successfully, and the `helloLabel` to be updated with "Hello from Go".

### What did you see instead?

I get a very strange error from XCode that states `iOS-arm64 != iOS-arm64`!:

```
ignoring file /Users/roger/Development/XXXXX/arm64.a, building for iOS-arm64 but attempting to link with file built for iOS-arm64
```

```
$ lipo -info arm64.a
Non-fat file: arm64.a is architecture: arm64
```

Ps. I previously had this working successfully, but I can't see what changed other than upgrading to Go 1.15 (I tried downgrading to 1.14.6 but no change) and updating Catalina to 10.15.6