thneed: lookup dlsym offset at compile time (#20019)

old-commit-hash: 1744076514
This commit is contained in:
Willem Melching
2021-02-04 16:41:46 +01:00
committed by GitHub
parent d295eb68f9
commit dadeec50dd
2 changed files with 14 additions and 6 deletions

View File

@@ -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)