thneed: lookup dlsym offset at compile time (#20019)
old-commit-hash: 1744076514a9aa5bf9d7e7940ddbd9c431c551bf
This commit is contained in:
@@ -3,6 +3,15 @@ lenv = env.Clone()
|
||||
|
||||
libs = [cereal, messaging, common, 'OpenCL', 'SNPE', 'symphony-cpu', 'capnp', 'zmq', 'kj', 'yuv', gpucommon, visionipc]
|
||||
|
||||
def get_dlsym_offset():
|
||||
"""Returns the offset between dlopen and dlsym in libdl.so"""
|
||||
import ctypes
|
||||
libdl = ctypes.PyDLL('libdl.so')
|
||||
dlopen = ctypes.cast(libdl.dlopen, ctypes.c_void_p).value
|
||||
dlsym = ctypes.cast(libdl.dlsym, ctypes.c_void_p).value
|
||||
return dlsym - dlopen
|
||||
|
||||
|
||||
common_src = [
|
||||
"models/commonmodel.cc",
|
||||
"runners/snpemodel.cc",
|
||||
@@ -21,8 +30,9 @@ if arch == "aarch64" or arch == "larch64":
|
||||
libs += ['gnustl_shared'] if arch == "aarch64" else ['pthread', 'dl']
|
||||
|
||||
common_src += thneed_src
|
||||
lenv['CFLAGS'].append("-DUSE_THNEED")
|
||||
dlsym_offset = get_dlsym_offset()
|
||||
lenv['CXXFLAGS'].append("-DUSE_THNEED")
|
||||
lenv['CXXFLAGS'].append(f"-DDLSYM_OFFSET={dlsym_offset}")
|
||||
else:
|
||||
libs += ['pthread']
|
||||
|
||||
@@ -45,6 +55,7 @@ else:
|
||||
|
||||
common_model = lenv.Object(common_src)
|
||||
|
||||
|
||||
# build thneed model
|
||||
if arch == "aarch64" or arch == "larch64":
|
||||
compiler = lenv.Program('thneed/compile', ["thneed/compile.cc" ]+common_model, LIBS=libs)
|
||||
|
||||
@@ -433,11 +433,8 @@ cl_program thneed_clCreateProgramWithSource(cl_context context, cl_uint count, c
|
||||
}
|
||||
|
||||
void *dlsym(void *handle, const char *symbol) {
|
||||
// TODO: Find dlsym in a better way. Currently this is hand looked up in libdl.so
|
||||
#if defined QCOM
|
||||
void *(*my_dlsym)(void *handle, const char *symbol) = (void *(*)(void *handle, const char *symbol))((uintptr_t)dlopen-0x2d4);
|
||||
#elif defined QCOM2
|
||||
void *(*my_dlsym)(void *handle, const char *symbol) = (void *(*)(void *handle, const char *symbol))((uintptr_t)dlopen+0x138);
|
||||
#if defined(QCOM) || defined(QCOM2)
|
||||
void *(*my_dlsym)(void *handle, const char *symbol) = (void *(*)(void *handle, const char *symbol))((uintptr_t)dlopen + DLSYM_OFFSET);
|
||||
#else
|
||||
#error "Unsupported platform for thneed"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user