2

I've used the gomobile bind tool to build my Go library for use in an iOS app. I've wrapped my library into a Cocoapods .podspec. It works nicely in the simulator (via a local development pod), but when I try to do pod lib lint (part step, part of releasing a cocoapod) I run into errors:

Error:

 ld: illegal text-relocation to 'runtime.rodata' in /Users/matti/src/foobar-sdk-ios/Frameworks/Client.framework/Client(go.o) from 'sync/atomic.(*Value).Store' in /Users/matti/src/foobar-sdk-ios/Frameworks/Client.framework/Client(go.o) for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Warning:

- NOTE  | [iOS] [FooBarSDK/Go] xcodebuild:  ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in sync/atomic.(*Value).Store from /Users/matti/src/foobar-sdk-ios/Frameworks/Client.framework/Client(go.o). To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie

It seems to link for other architectures. I couldnt figure out how to skip i386 - even though I override VALID_ARCHS - and I guess it wouldnt be the proper solution anyway.

So instead I'd like to know how to build a proper binary out of my Go code - I tried supplying -ldflags="-extldflags=-pie" to the gomobile bind command but I am assuming its more of a compilation issue. I know there is -buildmode=pie available for go build, but only for main packages and also not for gomobile bind.

Matti
  • 427
  • 1
  • 4
  • 13

1 Answers1

0

Apparently this fixes (suppresses) the error:

spec.pod_target_xcconfig = {
    "OTHER_LDFLAGS[arch=i386]" => "-Wl,-read_only_relocs,suppress"
}

I still get the PIE warning but the error is gone and the pod is pushed to the repository ok.

I wonder if Apple will have a beef with a binary missing PIE when pushing to App Store?

Matti
  • 427
  • 1
  • 4
  • 13