hev-task-system icon indicating copy to clipboard operation
hev-task-system copied to clipboard

[Bug] Android 平台下 System.loadLibrary 出现 TLS 符号加载失败

Open ReRokutosei opened this issue 1 month ago • 1 comments

Description

在 commit 8869fd2 中,项目引入了 initial-exec TLS 属性

该改动在 Android 运行时,通过 JNI(System.loadLibrary / dlopen)动态加载 libhev-socks5-tunnel.so 会抛出 UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError: dlopen failed: TLS symbol "(null)" in dlopened ".../libhev-socks5-tunnel.so" referenced from ".../libhev-socks5-tunnel.so" using IE access model

通过 readelf -r 检查 .so,可以确认存在由 initial-exec 引入的 R_AARCH64_TLS_TPREL64 重定位符号

Env

  • hev-socks5-tunnel:2.19.2 (bd6f919)
  • hev-task-system:5.11.0 (8869fd2)
  • Android(API 37 / arm64-v8a )

Proposed

Android 平台排除使用 initial-exec,让 Clang 回退使用标准的动态 TLS 模型,或者允许从外部编译选项覆盖 HEV_TLS_MODEL?

--- a/src/lib/misc/hev-compiler.h
+++ b/src/lib/misc/hev-compiler.h
@@ -30,7 +30,7 @@ extern "C" {
 #define barrier() __asm__ __volatile__ ("" : : : "memory")
 
-#if defined(__ELF__)
+#if defined(__ELF__) && !defined(__ANDROID__)
 #define HEV_TLS_MODEL __attribute__ ((tls_model ("initial-exec")))
 #else
 #define HEV_TLS_MODEL

Temporary

目前可以通过给 hev-task-system 追加编译参数临时绕过,无需修改子模块源码

target_compile_options(hev-task-system PRIVATE -U__ELF__ -fvisibility=hidden)

ReRokutosei avatar Oct 24 '26 19:10 ReRokutosei

感谢反馈,撤销了TLS Model的显式指定:https://github.com/heiher/hev-task-system/commit/d0365c370aadd39129924b563b80751cb63332d7

heiher avatar Oct 25 '26 01:10 heiher