dsegw3424 2019-04-12 00:38
浏览 221

高山ctypes loadlibrary()上的python失败,并出现OSError:重定位./cc.so:时出错::initial-exec TLS解析为./cc.so中的动态定义

I working on using golang builded shared library in python script(ctypes loadlibrary) on alpine based container.

But it is failed as follows,

/usr/src/app # go build -o cc.so -buildmode=c-shared main.go

/usr/src/app # readelf -d cc.so

Dynamic section at offset 0x10cd10 contains 22 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libc.musl-x86_64.so.1] 0x0000000000000010 (SYMBOLIC) 0x0 0x000000000000000c (INIT) 0x42000 0x000000000000000d (FINI) 0x92ed9 0x0000000000000019 (INIT_ARRAY) 0xa2078 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x270 0x0000000000000005 (STRTAB) 0xa50 0x0000000000000006 (SYMTAB) 0x378 0x000000000000000a (STRSZ) 1026 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x10deb0 0x0000000000000002 (PLTRELSZ) 720 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x41a00 0x0000000000000007 (RELA) 0xe58 0x0000000000000008 (RELASZ) 265128 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000000000001e (FLAGS) SYMBOLIC BIND_NOW STATIC_TLS 0x000000006ffffffb (FLAGS_1) Flags: NOW NODELETE 0x000000006ffffff9 (RELACOUNT) 11040 0x0000000000000000 (NULL) 0x0

/usr/src/app # python test.py Traceback (most recent call last): File "test.py", line 2, in lib = ctypes.cdll.LoadLibrary('./cc.so') File "/usr/lib/python2.7/ctypes/init.py", line 444, in LoadLibrary return self._dlltype(name) File "/usr/lib/python2.7/ctypes/init.py", line 366, in init self._handle = _dlopen(self._name, mode) OSError: Error relocating ./cc.so: : initial-exec TLS resolves to dynamic definition in ./cc.so

I have tried the following docker images

  1. Alpine 3.9 install go and python 2.7 on it

  2. go1.12:alpine and python2.7:alpine run go build to create shared library(go build -o cc.so -buildmode=c-shared main.go) then copy cc.so to python2.7:alpine container, run python test.py

The same problem.

But if I use ubuntu16.04 image and install go and python to do the same test, it works.

The main.go and test.py are as follows,

//main.go
package main

import "C"

//export add
func add(left, right int) int {
return left + right
}

//export minus
func minus(left, right int) int {
return left - right
}

//export multiply
func multiply(left, right int) int {
return left * right
}

//export divide
func divide(left, right int) int {
return left / right
}

//export testPrint
func testPrint(){
print("test")
}

func main() {
}

// test.py
import ctypes
lib = ctypes.cdll.LoadLibrary('./cc.so')
if lib is not None:
print ("can load so")
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建