golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cmd/link: PIC support for darwin/arm

KennyAtBaidu opened this issue · comments

When including the generated gomobile iOS framework into another iOS framework, calling gomobile generated method from the wrapper framework causes linker failure with message "ld: illegal text-relocation to 'type..eq.[0]string'"

Duplicate of #9210.

The only workaround before #9210 is fixed is to keep targeting SDK version 22.

<uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="22" />

@rakyll Sorry if I wasn't clear. This is for iOS framework. When code of custom iOS framework calling methods that are generated by gomobile cause illegal text-relocation.

Sorry, it was not clear from the text.

/cc @crawshaw

updated the original report.

Hi @KennyAtBaidu. Can you tell if this is coming from the ARMv7 or ARMv8 (arm64) binary? (You can extract the individual .a files by running gomobile with the -work.)

For ARMv7 it looks like we are not compiling as PIC for iOS, which is easy to fix. For ARMv8 I was under the impression the compiler was generating PC-relative code by default, but I tried to confirm with a quick inspection of the compiler and it's not clear to me.

Hi @crawshaw
It seems like

gomobile bind -work

gives me x86_64, armv7, and arm64 architecture.

I tried to toggle around with the Xcode build setting, if I build with simulator, I got the same error.

if I build with armv7, it'll first complain there's no bitcode, then I have the error

illegal text-relocation to 'main.initdone.'

If I build with arm64, it still complains there's no bitcode but once I disable bitcode, it built successfully. :D

Ok great, then this might be easy to fix. I'll try to attach a cl later today.

do we have any updates? I also hit into this.
can I know how to workaround this if we cann't fix it immediately.

same here. And thank you for your great effort.

I can see the individual statics with -work, can you briefly explain how I can get them back into xcode?

Otherwise is there another quick way of getting the embedded framework to function?

I just tested this and it works fine (except for a warning) with armv7+arm64. It stops working when I add amd64 to the fat binary.

UPDATE: I talked too soon, it still doesn't work.

@crawshaw hi, is there anything we can help with to help you fix this issue?

CL https://golang.org/cl/22461 mentions this issue.

@crawshaw @cherrymui thanks for your hard work on this issue.

I tested this on tip but I'm getting the following error:

gomobile bind -target=ios
gomobile: reading export data: /var/folders/y_/ws09jpg90_b5y710wmd7kvj5sbl416/T/gomobile-work-499035079/fakegopath/pkg/darwin_arm/path/to/my/sdk.a: unknown version:
make: *** [ios] Error 1

so I backported the commit to go 1.6 but when compiling I'm getting a similar error to the previous one:

ld: illegal text-relocation to 'go.string.*' in /test/sdk.framework/sdk(go.o) from 'runtime.interhash' in /test/sdk.framework/sdk(go.o) for architecture armv7

Let me know if we can provide more information.

@dcu is the first error in your comment, about "reading export data", fixed? I believe I saw the CL go by updating the gcimporter, and have no been able to replicate that error message.

@crawshaw no, sorry I forgot to update here.

This got fixed after #15519 and updating gomobile. it works on both 1.6 and 1.7.
Now we are getting errors when trying to install on a armv7 device because of a signature (according to the error message). Some of the issues are reported here: #15657
The other issue is that enabling armv7 requires the 386 sim I'm not sure why.