Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with mold linker #337

Closed
brson opened this issue May 30, 2022 · 5 comments
Closed

Incompatibility with mold linker #337

brson opened this issue May 30, 2022 · 5 comments

Comments

@brson
Copy link

brson commented May 30, 2022

I recently tried to cargo install a crate (cargo-contract) that relies on dylint-link and it failed due to interactions with the recommended configuration for using the mold linker.

Mold is configured by putting this in ~/.cargo/config.toml:

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"]

This is a global configuration saying to use clang as the linker, and clang understands the -fuse-ld argument.

dylint-link though invokes cc, which on my system is gcc and I see the following error:

     Compiling memchr v2.4.1
  error: linking with `dylint-link` failed: exit status: 1
  ...
    = note: cc: error: unrecognized command line option '-fuse-ld=/usr/local/bin/mold'

It's not immediately obvious to me how to change dylint-link to handle this situation.

@smoelius
Copy link
Collaborator

I think dylint-link could check for the existence of ~/.cargo/config.toml, and whether there is an applicable setting in there.

I.e., if something like this appears, then invoke clang instead of cc:

[target.x86_64-unknown-linux-gnu]
linker = "clang"

Does that sound reasonable?

@brson
Copy link
Author

brson commented May 31, 2022

That sounds like it would work for my use case at least, and a good start. It may not be foolproof - there may for example be other locations where cargo might be looking for .cargo/config, or otherways to communicate to rustc/cargo which linker to use.

Thanks for the quick response.

@smoelius
Copy link
Collaborator

smoelius commented Jun 3, 2022

@brson I just published a new version that I think should address the problem.

Could I impose upon you to test the new version before we close this issue?

@brson
Copy link
Author

brson commented Jun 4, 2022

@smoelius yes, the new version works for me. Here is what I ran

cargo install dylint-link cargo-dylint
cargo install cargo-contract

Thanks!

@brson brson closed this as completed Jun 4, 2022
@smoelius
Copy link
Collaborator

smoelius commented Jun 4, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants