在 Yocto 中为 armv7ahf 交叉编译 Coqui + TFLite:R_ARM_TLS_LE32 共享对象中不允许重定位

Cross-compiling Coqui + TFLite for armv7ahf in Yocto: R_ARM_TLS_LE32 relocation not permitted in shared object

我正在尝试从 Coqui 项目构建 libstt.so 的 Yocto,以 TFLite 作为后端,用于具有 armv7ahf 处理器的 Snapdragon 210。我一直在使用 meta-tensorflow OpenEmbedded 层作为起点。

编译 Bazel 并使用 Yocto 交叉编译工具链非常复杂,但现在我很高兴,我的层已经进展到构建 libstt.so 本身。

然而,在链接阶段构建即将结束时,我得到了这个 R_ARM_TLS_LE32 relocation not permitted in shared object 错误:

ld: bazel-out/arm-opt/bin/tensorflow/lite/kernels/libeigen_support.pic.a(eigen_support.pic.o)(.text._ZNK6tflite13eigen_support12_GLOBAL__N_122EigenThreadPoolWrapper15CurrentThreadIdEv+0x2c): R_ARM_TLS_LE32 relocation not permitted in shared object
bazel-out/arm-opt/bin/tensorflow/lite/kernels/libeigen_support.pic.a(eigen_support.pic.o): In function `tflite::eigen_support::(anonymous namespace)::EigenThreadPoolWrapper::CurrentThreadId() const':
eigen_support.cc:(.text._ZNK6tflite13eigen_support12_GLOBAL__N_122EigenThreadPoolWrapper15CurrentThreadIdEv+0x2c): dangerous relocation: unsupported relocation

我了解到 R_ARM_TLS_LE32 是一个 ELF 静态线程本地存储重定位代码,并且 eigen_support 被错误地编译为链接器不接受的静态代码?但我在这里肯定超出了我的深度。

正在启动构建:

bazel build \
        --config=monolithic \
        --verbose_explanations --verbose_failures \ 
        --action_env ANDROID_NDK_API_LEVEL=21 \     
        --config=android  \
        --config=android_arm \
        --define runtime=tflite \
        --cxxopt="-fpermissive" \
        --cxxopt="-std=c++14"  \
        --cpu="${BAZEL_TARGET_CPU}" \
        -c opt \
        --copt="-D_GLIBCXX_USE_CXX11_ABI=0" \
        --copt=-fvisibility=hidden \
        --copt=-O3 \
        --copt=-D_GLIBCXX_USE_C99 \
        --crosstool_top=@local_config_yocto_compiler//:toolchain \
        --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
        --subcommands --explain=${T}/explain.log \
        //native_client:libstt.so
}

eigen_support.pic.o 本身是使用以下命令构建的(来自错误日志,经过格式化以便于阅读)。你能帮我找出编译错误的原因吗?

arm-oe-linux-gnueabi-gcc 
-fstack-protector 
-g0 
-O2 
-DNDEBUG 
-ffunction-sections 
-fdata-sections 
-D_PYTHON_INCLUDE_TARGET 
-MD 
-MF bazel-out/arm-opt/bin/tensorflow/lite/kernels/_objs/eigen_support/eigen_support.pic.d 
'-frandom-seed=bazel-out/arm-opt/bin/tensorflow/lite/kernels/_objs/eigen_support/eigen_support.pic.o' 
-fPIC 
-DEIGEN_MPL2_ONLY 
'-DEIGEN_MAX_ALIGN_BYTES=64' 
'-DEIGEN_HAS_TYPE_TRAITS=0' 
-iquote . 
-iquote bazel-out/arm-opt/bin 
-iquote external/gemmlowp 
-iquote bazel-out/arm-opt/bin/external/gemmlowp 
-iquote external/eigen_archive 
-iquote bazel-out/arm-opt/bin/external/eigen_archive 
-iquote external/local_config_sycl 
-iquote bazel-out/arm-opt/bin/external/local_config_sycl 
-iquote external/ruy 
-iquote bazel-out/arm-opt/bin/external/ruy 
-iquote external/cpuinfo 
-iquote bazel-out/arm-opt/bin/external/cpuinfo 
-iquote external/clog 
-iquote bazel-out/arm-opt/bin/external/clog 
-Ibazel-out/arm-opt/bin/external/clog/_virtual_includes/clog 
-isystem external/eigen_archive 
-isystem bazel-out/arm-opt/bin/external/eigen_archive 
-DTFLITE_WITH_RUY_GEMV 
-w 
-w 
-fPIC 
-D_GLIBCXX_USE_C99 
-D_PYTHON_INCLUDE_TARGET 
'-march=armv7-a' 
'-mfpu=neon' 
'-mfloat-abi=hard' 
-Wl,-O1 
'-Wl,--hash-style=gnu' 
-Wl,--as-needed 
-Wl,-z,relro,-z,now,-z,noexecstack 
-fstack-protector-strong 
-pie -fPIE '-D_FORTIFY_SOURCE=2' 
-Wa,--noexecstack 
-Wformat -Wformat-security '-Werror=format-security' 
'--sysroot=/home/gbw/sc20_linux/poky/build/tmp-glibc/work/armv7ahf-neon-oe-linux-gnueabi/coqui/v0.10.0-alpha.9-r0/bazel/output_base/external/yocto_compiler/recipe-sysroot' 
-O2 
-Wa,--noexecstack 
-fexpensive-optimizations 
-frename-registers 
-fomit-frame-pointer 
-ftree-vectorize 
-finline-functions 
'-finline-limit=64' 
'-Wno-error=maybe-uninitialized' 
'-Wno-error=unused-result' 
-fvisibility-inlines-hidden 
'-std=c++14' 
'-std=c++14' -fpermissive 
'-std=c++14' 
-DFARMHASH_NO_CXX_STRING 
-Wno-sign-compare 
-O3 
-fno-exceptions 
'-Wno-error=reorder' 
-Wno-builtin-macro-redefined 
'-D__DATE__="redacted"' 
'-D__TIMESTAMP__="redacted"' 
'-D__TIME__="redacted"' 
-no-canonical-prefixes 
-fno-canonical-system-headers 
-c tensorflow/lite/kernels/eigen_support.cc 
-o bazel-out/arm-opt/bin/tensorflow/lite/kernels/_objs/eigen_support/eigen_support.pic.o)

问题是由于我没有注意到的 bazelrc 文件添加了 -fPIE 编译器标志。删除 -fPIE 修复了错误。