Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose library name in OrcJIT tracker #967

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions llvmlite/binding/orcjit.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def link(self, lljit, library_name):
however, the name of the library cannot be reused.
"""
assert not lljit.closed, "Cannot add to closed JIT"
library_name = str(library_name).encode('utf-8')
assert len(library_name) > 0, "Library cannot be empty"
encoded_library_name = str(library_name).encode('utf-8')
assert len(encoded_library_name) > 0, "Library cannot be empty"
elements = (_LinkElement * len(self.__entries))()
for idx, (kind, value) in enumerate(self.__entries):
elements[idx].element_kind = c_uint8(kind)
Expand All @@ -163,7 +163,7 @@ def link(self, lljit, library_name):
with ffi.OutputString() as outerr:
tracker = lljit._capi.LLVMPY_LLJIT_Link(
lljit._ptr,
library_name,
encoded_library_name,
elements,
len(self.__entries),
imports,
Expand All @@ -173,9 +173,10 @@ def link(self, lljit, library_name):
outerr)
if not tracker:
raise RuntimeError(str(outerr))
return ResourceTracker(tracker, {name: exports[idx].address
for idx, name in
enumerate(self.__exports)})
return ResourceTracker(tracker,
library_name,
{name: exports[idx].address
for idx, name in enumerate(self.__exports)})


class ResourceTracker(ffi.ObjectRef):
Expand All @@ -195,8 +196,9 @@ class ResourceTracker(ffi.ObjectRef):
LLVM internally tracks references between different libraries, so only
"leaf" libraries need to be tracked.
"""
def __init__(self, ptr, addresses):
def __init__(self, ptr, name, addresses):
self.__addresses = addresses
self.__name = name
ffi.ObjectRef.__init__(self, ptr)

def __getitem__(self, item):
Expand All @@ -205,6 +207,10 @@ def __getitem__(self, item):
"""
return self.__addresses[item]

@property
def name(self):
return self.__name

def _dispose(self):
with ffi.OutputString() as outerr:
if self._capi.LLVMPY_LLJIT_Dylib_Tracker_Dispose(self, outerr):
Expand Down Expand Up @@ -252,7 +258,7 @@ def lookup(self, dylib, fn):
if not tracker:
raise RuntimeError(str(outerr))

return ResourceTracker(tracker, {fn: address.value})
return ResourceTracker(tracker, dylib, {fn: address.value})

@property
def target_data(self):
Expand Down
1 change: 1 addition & 0 deletions llvmlite/tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ def jit(self, asm=asm_sum, func_name="sum", target_machine=None,
.link(lljit, func_name)
cfptr = rt[func_name]
self.assertTrue(cfptr)
self.assertEqual(func_name, rt.name)
return lljit, rt, func_type(cfptr)

# From test_dylib_symbols
Expand Down