diff --git a/src/mldebug/bin/llvm-objdump.elf b/src/mldebug/bin/llvm-objdump.elf index e1369be..61fd067 100755 --- a/src/mldebug/bin/llvm-objdump.elf +++ b/src/mldebug/bin/llvm-objdump.elf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:237de21054bfcaf78c63b7d965fc590592c5e872b24cec4ccd1536e032f1feff -size 47986232 +oid sha256:742951dc42c97fa9cd7629cc4c016b20dc39fa62ff954cfcb77ca56b2c51e269 +size 36754912 diff --git a/src/mldebug/work_dir.py b/src/mldebug/work_dir.py index 4c33121..8755d3c 100644 --- a/src/mldebug/work_dir.py +++ b/src/mldebug/work_dir.py @@ -16,6 +16,25 @@ from mldebug.utils import LOGGER, is_aarch64, is_windows +def run_bundled(cmd, **kwargs): + """ + Run a bundled executable (cmd[0]) so that shared libraries shipped next to + it are resolvable at runtime. Linux and Windows only. + + Any extra kwargs are forwarded to subprocess.check_output. + """ + exe_dir = str(Path(cmd[0]).resolve().parent) + env = dict(kwargs.pop("env", os.environ)) + if is_windows(): + # Prepend the exe's dir to PATH so co-located DLLs are found. + env["PATH"] = exe_dir + os.pathsep + env.get("PATH", "") + with os.add_dll_directory(exe_dir): + return subprocess.check_output(cmd, env=env, **kwargs) + # Linux: point the loader at co-located .so files. + env["LD_LIBRARY_PATH"] = exe_dir + os.pathsep + env.get("LD_LIBRARY_PATH", "") + return subprocess.check_output(cmd, env=env, **kwargs) + + @dataclass class AIEFunction: """ @@ -214,7 +233,7 @@ def _get_lst(self, elf_path, elf_name, arch_name, dump_lst): elif is_aarch64(): exe = "llvm-objdump.aarch64" with resources.as_file(resources.files("mldebug") / "bin" / exe) as objdump_path: - lst = subprocess.check_output( + lst = run_bundled( [ str(objdump_path), "-d",