Skip to content

Commit bb0c71a

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 ea73114 commit bb0c71a

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
@@ -9,6 +9,11 @@ const BDWGC_BUILD_DIR: &str = "lib";
99
compile_error!("Requires x86_64 with 64 bit pointer width.");
1010

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

0 commit comments

Comments
 (0)