Android Go x86,runtime: android x86 support

博客讨论了Go语言在Android/386平台上遇到的TLS(线程局部存储)处理难题,由于Android链接器缺乏相应支持。目前的解决方案是模仿Darwin/386的处理方式,但这种方法存在不优雅和脆弱性。作者考虑了通过IEMode支持的可行性,但不清楚实现所需工作量。邮件线程中提及可能通过IEMode实现更清洁的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

One obvious missing feature is the TLS handling - linux/386 assumes availability of TLS store to hold g across cgo calls, and the linker's ability to handle TLS relocation for LE mode. But android linker lacks such support.

Android/arm overcomes it by emulating runtime.tlsg as a regular variable. The same trick doesn't seem to work for 386 where the offset is encoded in the instruction when using LE model.

Instead, @crawshaw and I think the approach darwin/386 is taking (runtime/cgo/gcc_darwin_386.c) may work for android/386 as well - basically we allocate a thread-local storage with a specific key and use a hard-coded offset (cmd/link/internal/ld/sym.go line 145). This is ugly and fragile, but seems promising. Should we take this path?

In this mail thread https://groups.google.com/forum/#!topic/golang-nuts/cZPdxDmnuUM @mwhudson mentioned it may be feasible through IE model support and I guess it may be cleaner. However, not being familiar with the concept yet, I cannot estimate how much work is necessary to implement IE model support (pointer to the cl that implements IE mode for amd64 would be appreciated) and not yet clear about where to hook into the tls offset info when the linker is not doing most of the magic for me.

package com.taixin.txallremote.jni; import com.taixin.txallremote.utils.ALog; public final class H6RemoteIO { private static final String TAG = "H6RemoteIO"; private static final String libSoName = "txporting-i2c"; static { ALog.i(TAG, "load library: lib" + libSoName + ".so"); System.loadLibrary(libSoName); } public static void remoteOpen() { ALog.i(TAG, "txallremote init"); TxAllRemote_Init(); } public static void remoteLearnStart() { TxAllRemote_LearnStart(); } public static byte remoteReadData(byte[] buf, int count) { byte ack; ack = TxAllRemote_ReadData(buf, count); ALog.i(TAG, "ack:" + ack); return ack; } public static byte remoteWriteData(byte[] buf, int count) { byte ack; ack = TxAllRemote_WriteData(buf, count); return ack; } private static native void TxAllRemote_Init(); private static native void TxAllRemote_LearnStart(); private static native byte TxAllRemote_ReadData(byte[] paramArrayOfByte, int paramInt); private static native byte TxAllRemote_WriteData(byte[] paramArrayOfByte, int paramInt); } 07-23 08:31:32.909 22259 22282 D libEGL : loaded /system/lib64/egl/libEGL_emulation.so 07-23 08:31:32.910 22259 22259 I txallremote-H6RemoteIO: load library: libtxporting-i2c.so 07-23 08:31:32.929 22259 22259 D AndroidRuntime: Shutting down VM 07-23 08:31:32.929 22259 22282 I nemucooker: cook file1: /etc/mumu-configs/renderer.config, last modify time: Thu Aug 29 11:22:45 2024 07-23 08:31:32.929 22259 22282 I nemucooker: cook file2: /data/system/etc/mumu-configs/renderer.config, last modify time: Thu Jul 17 21:45:34 2025 07-23 08:31:32.929 22259 22282 I nemucooker: cook select file: /data/system/etc/mumu-configs/renderer.config 07-23 08:31:32.940 22259 22259 E AndroidRuntime: FATAL EXCEPTION: main 07-23 08:31:32.940 22259 22259 E AndroidRuntime: Process: com.taixin.txallremote, PID: 22259 07-23 08:31:32.940 22259 22259 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: library "libtxporting-i2c.so" not found 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at java.lang.Runtime.loadLibrary0(Runtime.java:1086) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at java.lang.Runtime.loadLibrary0(Runtime.java:1006) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at java.lang.System.loadLibrary(System.java:1656) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at com.taixin.txallremote.jni.H6RemoteIO.<clinit>(H6RemoteIO.java:12) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at com.taixin.txallremote.jni.H6RemoteIO.remoteOpen(Unknown Source:0) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at com.taixin.txallremote.dataway.RemoteDirectIo.getInstance(RemoteDirectIo.java:27) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at com.taixin.txallremote.activity.TempHumiControlManagerActivity.onCreate(TempHumiControlManagerActivity.java:81) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8054) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8034) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1347) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3736) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3931) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2294) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8060) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 07-23 08:31:32.940 22259 22259 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1091) 07-23 08:31:32.945 22259 22282 D libEGL : loaded /system/lib64/egl/libGLESv1_CM_emulation.so 07-23 08:31:32.946 22259 22282 D libEGL : loaded /system/lib64/egl/libGLESv2_emulation.so 07-23 08:31:32.961 22259 22282 E GraphicsEnv: Failed to get gpu service 07-23 08:31:33.000 22259 22259 I Process : Sending signal. PID: 22259 SIG: 9 07-23 08:31:33.025 1251 10643 I ActivityManager: Process com.taixin.txallremote (pid 22259) has died: fg TOP 07-23 08:31:33.025 1054 1054 I Zygote : Process 22259 exited due to signal 9 (Killed) 07-23 08:31:33.025 1251 1291 I libprocessgroup: Successfully killed process cgroup uid 10111 pid 22259 in 0ms 07-23 08:31:40.589 1091 1091 D opengl-gc: Check pid 22259: running 0
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值