Skip to content

Commit 53ef00e

Browse files
committed
Fix JIT on macOS
Fixes #671
1 parent cc30c20 commit 53ef00e

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/driver.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,15 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
136136
if name.is_empty() || !symbol.is_global() || symbol.is_undefined() {
137137
return None;
138138
}
139+
let dlsym_name = if cfg!(target_os = "macos") {
140+
// On macOS `dlsym` expects the name without leading `_`.
141+
assert!(name.starts_with("_"), "{:?}", name);
142+
&name[1..]
143+
} else {
144+
&name
145+
};
139146
let symbol: libloading::Symbol<*const u8> =
140-
unsafe { lib.get(name.as_bytes()) }.unwrap();
147+
unsafe { lib.get(dlsym_name.as_bytes()) }.unwrap();
141148
Some((name, *symbol))
142149
}));
143150
std::mem::forget(lib)

test.sh

+4-12
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ fi
1212

1313
source config.sh
1414

15-
jit() {
16-
if [[ `uname` == 'Darwin' ]]; then
17-
# FIXME(#671) `dlsym` returns "symbol not found" for existing symbols on macOS.
18-
echo "[JIT] $1 (Ignored on macOS)"
19-
else
20-
echo "[JIT] $1"
21-
SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic $2
22-
fi
23-
}
24-
2515
rm -r target/out || true
2616
mkdir -p target/out/clif
2717

@@ -31,7 +21,8 @@ $RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib
3121
echo "[BUILD] example"
3222
$RUSTC example/example.rs --crate-type lib
3323

34-
#JIT_ARGS="abc bcd" jit mini_core_hello_world example/mini_core_hello_world.rs
24+
echo "[JIT] mini_core_hello_world"
25+
JIT_ARGS="abc bcd" SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic example/mini_core_hello_world.rs
3526

3627
echo "[AOT] mini_core_hello_world"
3728
$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"
4940
$RUSTC example/alloc_example.rs --crate-type bin
5041
./target/out/alloc_example
5142

52-
jit std_example example/std_example.rs
43+
echo "[JIT] std_example"
44+
SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic example/std_example.rs
5345

5446
echo "[AOT] dst_field_align"
5547
# FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed.

0 commit comments

Comments
 (0)