[wireguard-apple] [iOS] Running WireGuard on a simulator

Jeffrey Walton noloader at gmail.com
Thu Sep 2 02:10:12 UTC 2021


On Wed, Sep 1, 2021 at 9:00 PM Neutron <dotneutron at protonmail.ch> wrote:
> ...
>
> The Go version is "go1.16 darwin/arm64". The build process fails at
> # runtime/cgo
> Undefined symbols for architecture arm64:
>   "_darwin_arm_init_mach_exception_handler", referenced from:
>       _x_cgo_init in _x004.o
>   "_darwin_arm_init_thread_exception_port", referenced from:
>       _threadentry in _x004.o
>       _x_cgo_init in _x004.o
> ld: symbol(s) not found for architecture arm64
>
> This issue was reported a few times in Go's issues section, e.g.,
> https://github.com/golang/go/issues/45772#issuecomment-874616905
>
> Further head banging lead me to the discovery that
>
> xcodebuild -target WireGuardiOS -sdk iphoneos14.5
>
> actually builds successfully. I looked through the Makefile and applied some
> monkey see, monkey do. It turns out I could get it to link by adding
> GOOS_iphonesimulator := ios.

This looks a little odd to me. You should not need ios there because
the M1 is its own first class platform. About all you should need is,
ensure '-arch arm64' is used. But I probably do not understand how Go
does things.

Apple uses simulators, which means your high level C code is compiled
to the host's native instruction set. The host is where the simulator
runs. On an M1, that means code is compiled to the host's arm64
instruction set, hence the reason for '-arch arm64'. You still need to
be aware of a target SDK, but that is a particular detail. The broad
stroke is '-arch arm64' for the M1.

Android uses emulators, which means the high level C code is compiled
to the target ISA, like x86_64, arm, aarch64 or mips. Then, the ISA
instructions are interpreted on the host machine. The high level C
code is not compiled to the emulator's native instruction set.

Jeff


More information about the WireGuard mailing list