Skip to content

Commit

Permalink
Allow BDWGC to be linked dynamically
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jacob-hughes committed Apr 23, 2024
1 parent ea73114 commit bb0c71a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/bdwgc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const BDWGC_BUILD_DIR: &str = "lib";
compile_error!("Requires x86_64 with 64 bit pointer width.");

fn main() {
if env::var("GC_LINK_DYNAMIC").map_or(false, |v| v == "true") {
println!("cargo:rustc-link-lib=dylib=gc");
return;
}

let out_dir = env::var("OUT_DIR").unwrap();
let bdwgc_src = PathBuf::from(BDWGC_REPO);

Expand Down

0 comments on commit bb0c71a

Please sign in to comment.