From 53ef00e68cc0620fa84ffa4e74305ec4f6df2f23 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 22 Feb 2020 15:57:53 +0100 Subject: [PATCH] Fix JIT on macOS Fixes #671 --- src/driver.rs | 9 ++++++++- test.sh | 16 ++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index cf3ad422171..056fc57989f 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -136,8 +136,15 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { if name.is_empty() || !symbol.is_global() || symbol.is_undefined() { return None; } + let dlsym_name = if cfg!(target_os = "macos") { + // On macOS `dlsym` expects the name without leading `_`. + assert!(name.starts_with("_"), "{:?}", name); + &name[1..] + } else { + &name + }; let symbol: libloading::Symbol<*const u8> = - unsafe { lib.get(name.as_bytes()) }.unwrap(); + unsafe { lib.get(dlsym_name.as_bytes()) }.unwrap(); Some((name, *symbol)) })); std::mem::forget(lib) diff --git a/test.sh b/test.sh index 72934e68958..e1cb1333649 100755 --- a/test.sh +++ b/test.sh @@ -12,16 +12,6 @@ fi source config.sh -jit() { - if [[ `uname` == 'Darwin' ]]; then - # FIXME(#671) `dlsym` returns "symbol not found" for existing symbols on macOS. - echo "[JIT] $1 (Ignored on macOS)" - else - echo "[JIT] $1" - SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic $2 - fi -} - rm -r target/out || true mkdir -p target/out/clif @@ -31,7 +21,8 @@ $RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib echo "[BUILD] example" $RUSTC example/example.rs --crate-type lib -#JIT_ARGS="abc bcd" jit mini_core_hello_world example/mini_core_hello_world.rs +echo "[JIT] mini_core_hello_world" +JIT_ARGS="abc bcd" SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic example/mini_core_hello_world.rs echo "[AOT] mini_core_hello_world" $RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g @@ -49,7 +40,8 @@ echo "[AOT] alloc_example" $RUSTC example/alloc_example.rs --crate-type bin ./target/out/alloc_example -jit std_example example/std_example.rs +echo "[JIT] std_example" +SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic example/std_example.rs echo "[AOT] dst_field_align" # FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed. -- 2.44.0