Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
from pathlib import Path
import yaml

sys.path.append(str(Path(__file__).resolve().parent.parent))
from amdgpu_family_matrix import is_asan
from configure_asan_env import get_asan_runtime_path

logging.basicConfig(level=logging.INFO, format="%(message)s")

# Map job name -> install location, relative to the ROCm prefix (THEROCK_BIN_DIR
Expand Down Expand Up @@ -242,6 +246,16 @@ def build_environment(rocm_path, component_name):
env = os.environ.copy()
component_root = resolve_component_path(component_name, rocm_path)

# Initialize ASan before Python allocates objects that instrumented imports
# may later free. Merely exposing the runtime on LD_LIBRARY_PATH loads it
# too late when rocisa imports instrumented ROCm libraries.
if is_asan():
runtime = str(get_asan_runtime_path(rocm_path))
existing_preload = env.get("LD_PRELOAD", "")
env["LD_PRELOAD"] = (
f"{runtime}:{existing_preload}" if existing_preload else runtime
)

existing_pythonpath = env.get("PYTHONPATH")
env["PYTHONPATH"] = (
f"{component_root}{os.pathsep}{existing_pythonpath}"
Expand Down
11 changes: 10 additions & 1 deletion build_tools/github_actions/tests/pytest_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,21 @@ def test_paths_and_ld_library_path(self):
def test_prepends_to_existing_values(self):
os.environ["PYTHONPATH"] = "/pre/existing"
os.environ["LD_LIBRARY_PATH"] = "/pre/ld"
os.environ["LD_PRELOAD"] = "/pre/preload"
rocm = Path("/opt/rocm")

env = pytest_runner.build_environment(rocm, "tensilelite")
with (
mock.patch.object(pytest_runner, "is_asan", return_value=True),
mock.patch.object(
pytest_runner, "get_asan_runtime_path", return_value=Path("/asan.so")
),
):
env = pytest_runner.build_environment(rocm, "tensilelite")

self.assertTrue(env["PYTHONPATH"].endswith("/pre/existing"))
self.assertIn("/pre/ld", env["LD_LIBRARY_PATH"].split(os.pathsep))
self.assertEqual(env["LD_PRELOAD"], f"{Path('/asan.so')}:/pre/preload")
self.assertEqual(os.environ["LD_PRELOAD"], "/pre/preload")

def test_ld_library_path_includes_all_llvm_triple_dirs(self):
# All triple subdirs must be on LD_LIBRARY_PATH in a deterministic order —
Expand Down