Skip to content

Commit 2b17e85

Browse files
committed
Allow BDWGC to be linked dynamically
This is useful for debugging, where profilers intercept and override dynamically linked symbols (e.g. `malloc` and `free`). As of this commit, there is no way to build a custom BDWGC fork and have that dynamically link to a program compiled with Alloy automatically. This is because `cargo` does not support bubbling up linker args to the final linked binary, so there is no way to programmatically set the rpath for BDWGC to the OUT directory in `library/bdwgc` [1]. Alloy programs must therefore set the `LD_PRELOAD` environment variable to prevent it from linking against the system libgc. [1]: rust-lang/cargo#9554
1 parent d8b6c63 commit 2b17e85

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/bdwgc/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const BDWGC_BUILD_DIR: &str = "lib";
1010
compile_error!("Requires x86_64 with 64 bit pointer width.");
1111

1212
fn main() {
13+
if env::var("GC_LINK_DYNAMIC").map_or(false, |v| v == "true") {
14+
println!("cargo:rustc-link-lib=dylib=gc");
15+
return;
16+
}
17+
1318
let out_dir = env::var("OUT_DIR").unwrap();
1419
let bdwgc_src = PathBuf::from(BDWGC_REPO);
1520

0 commit comments

Comments
 (0)