Skip to content

Commit

Permalink
Merge pull request #54 from firedancer-io/ll/LD_PRELOAD-for-asan-exec…
Browse files Browse the repository at this point in the history
…-insrt

ASAN - if we fail to load a library with the subcommand exec-instr try again
  • Loading branch information
llamb-jump authored Jun 25, 2024
2 parents b240c2c + e074b74 commit b9228ed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
branch = agave-v2.0
[submodule "impl/solfuzz"]
path = impl/solfuzz
url = https://github.com/firedancer-io/solfuzz
url = git@github.com:firedancer-io/solfuzz.git
branch = main
6 changes: 5 additions & 1 deletion src/test_suite/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
import test_suite.globals as globals
from test_suite.debugger import debug_host
from test_suite.util import set_ld_preload_asan
import resource
import tqdm
from test_suite.fuzz_context import ElfHarness, InstrHarness, SyscallHarness
Expand Down Expand Up @@ -58,7 +59,10 @@ def exec_instr(

# Initialize output buffers and shared library
initialize_process_output_buffers(randomize_output_buffer=randomize_output_buffer)
lib = ctypes.CDLL(shared_library)
try:
lib = ctypes.CDLL(shared_library)
except:
set_ld_preload_asan()
lib.sol_compat_init()

# Execute and cleanup
Expand Down
23 changes: 23 additions & 0 deletions src/test_suite/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import subprocess
import os
import sys


def set_ld_preload_asan():
# Run ldconfig -p and capture output
ldconfig_output = subprocess.check_output(["ldconfig", "-p"], text=True)

# Filter lines containing "asan"
asan_libs = [line for line in ldconfig_output.split("\n") if "asan" in line]

# Extract the first library path if available
if asan_libs:
first_asan_lib = asan_libs[0].split()[-1]
else:
print("No ASAN library found.")
return

# Set LD_PRELOAD environment variable
os.environ["LD_PRELOAD"] = first_asan_lib
print(f"LD_PRELOAD set to {first_asan_lib}")
os.execvp(sys.argv[0], sys.argv)

0 comments on commit b9228ed

Please sign in to comment.