Skip to content

Commit 02bc46f

Browse files
authored
Add a test that dynamically loaded libraries symbolicate (#332)
1 parent 1ca764e commit 02bc46f

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ features = ['read_core', 'elf', 'macho', 'pe']
4848
[target.'cfg(windows)'.dependencies]
4949
winapi = { version = "0.3.3", optional = true }
5050

51+
[dev-dependencies]
52+
dylib-dep = { path = "crates/dylib-dep" }
53+
libloading = "0.6"
54+
5155
[features]
5256
# By default libstd support and gimli-symbolize is used to symbolize addresses.
5357
default = ["std", "gimli-symbolize"]
@@ -131,7 +135,7 @@ edition = '2018'
131135

132136
[[test]]
133137
name = "accuracy"
134-
required-features = ["std", "libbacktrace"]
138+
required-features = ["std", "gimli-symbolize"]
135139
edition = '2018'
136140

137141
[[test]]

crates/dylib-dep/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "dylib-dep"
3+
version = "0.1.0"
4+
edition = "2018"
5+
authors = []
6+
publish = false
7+
8+
[lib]
9+
name = "dylib_dep"
10+
crate-type = ["cdylib", "rlib"]

crates/dylib-dep/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type Pos = (&'static str, u32);
2+
3+
macro_rules! pos {
4+
() => {
5+
(file!(), line!())
6+
};
7+
}
8+
9+
#[no_mangle]
10+
pub extern "C" fn foo(outer: Pos, inner: fn(Pos, Pos)) {
11+
inner(outer, pos!());
12+
}

tests/accuracy/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ type Pos = (&'static str, u32);
1616

1717
#[test]
1818
fn doit() {
19+
// Skip musl which is by default statically linked and doesn't support
20+
// dynamic libraries.
21+
//
22+
// FIXME(#333) doesn't work on MinGW yet
23+
if !cfg!(target_env = "musl") && !(cfg!(windows) && cfg!(target_env = "gnu")) {
24+
// TODO(#238) this shouldn't have to happen first in this function, but
25+
// currently it does.
26+
let mut dir = std::env::current_exe().unwrap();
27+
dir.pop();
28+
if cfg!(windows) {
29+
dir.push("dylib_dep.dll");
30+
} else if cfg!(target_os = "macos") {
31+
dir.push("libdylib_dep.dylib");
32+
} else {
33+
dir.push("libdylib_dep.so");
34+
}
35+
let lib = libloading::Library::new(&dir).unwrap();
36+
let api = unsafe { lib.get::<extern "C" fn(Pos, fn(Pos, Pos))>(b"foo").unwrap() };
37+
api(pos!(), |a, b| {
38+
check!(a, b);
39+
});
40+
}
41+
1942
outer(pos!());
2043
}
2144

0 commit comments

Comments
 (0)