code: def relocate_elf_library(
      patchelf, output_dir, output_library, binary
  ):
      """
      Relocate an ELF shared library to be packaged on a wheel.
  
      Given a shared library, find the transitive closure of its dependencies,
      rename and copy them into the wheel while updating their respective rpaths.
      """
  
      print(f"Relocating {binary}")
      binary_path = osp.join(output_library, binary)
  
      ld_tree = lddtree(binary_path)
      tree_libs = ld_tree["libs"]
  
      binary_queue = [(n, binary) for n in ld_tree["needed"]]
      binary_paths = {binary: binary_path}
      binary_dependencies = {}
  
      while binary_queue != []:
          library, parent = binary_queue.pop(0)
          library_info = tree_libs[library]
          print(library)
  
          if library_info["path"] is None:
              print(f"Omitting {library}")
              continue
  
          if library in ALLOWLIST:
              # Omit glibc/gcc/system libraries
              print(f"Omitting {library}")
              continue
  
          parent_dependencies = binary_dependencies.get(parent, [])
          parent_dependencies.append(library)
          binary_dependencies[parent] = parent_dependencies
  
          if library in binary_paths:
              continue
  
          binary_paths[library] = library_info["path"]
          binary_queue += [(n, library) for n in library_info["needed"]]
  
      print("Copying dependencies to wheel directory")
      new_libraries_path = osp.join(output_dir, "torchvision.libs")
      os.makedirs(new_libraries_path, exist_ok=True)
  
      new_names = {binary: binary_path}
  
      for library in binary_paths:
          if library != binary:
              library_path = binary_paths[library]
              new_library_path = patch_new_path(
                  library_path, new_libraries_path
              )
              print(f"{library} -> {new_library_path}")
              shutil.copyfile(library_path, new_library_path)
              new_names[library] = new_library_path
  
      print("Updating dependency names by new files")
      for library in binary_paths:
          if library != binary:
              if library not in binary_dependencies:
                  continue
              library_dependencies = binary_dependencies[library]
              new_library_name = new_names[library]
              for dep in library_dependencies:
                  new_dep = osp.basename(new_names[dep])
                  print(f"{library}: {dep} -> {new_dep}")
                  subprocess.check_output(
                      [
                          patchelf,
                          "--replace-needed",
                          dep,
                          new_dep,
                          new_library_name,
                      ],
                      cwd=new_libraries_path,
                  )
  
              print("Updating library rpath")
              subprocess.check_output(
                  [
                      patchelf,
                      "--set-rpath",
                      "$ORIGIN",
                      new_library_name,
                  ],
                  cwd=new_libraries_path,
              )
  
              subprocess.check_output(
                  [patchelf, "--print-rpath", new_library_name],
                  cwd=new_libraries_path,
              )
  
      print("Update library dependencies")
      library_dependencies = binary_dependencies[binary]
      for dep in library_dependencies:
          new_dep = osp.basename(new_names[dep])
          print(f"{binary}: {dep} -> {new_dep}")
          subprocess.check_output(
              [patchelf, "--replace-needed", dep, new_dep, binary],
              cwd=output_library,
          )
  
      print("Update library rpath")
      subprocess.check_output(
          [
              patchelf,
              "--set-rpath",
              "$ORIGIN:$ORIGIN/../torchvision.libs",
              binary_path,
          ],
          cwd=output_library,
      )
  
imports: import glob
  import hashlib
  import os
  import os.path
  import platform
  import shutil
  import subprocess
  import sys
  import zipfile
  from base64 import urlsafe_b64encode
label_desc: Use image node_id 7 for calling a global function with example usage: relocate_elf_library(patchelf, output_dir, output_library, binary) without return types