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

How to use mold without clang #168

Open
sebastian-de opened this issue Sep 19, 2022 · 5 comments
Open

How to use mold without clang #168

sebastian-de opened this issue Sep 19, 2022 · 5 comments

Comments

@sebastian-de
Copy link

gcc 12.1 is included in freedesktop-SDK 22.08, so it should be possible to use mold without clang.
I'm not able to figure this out however. I have append-path: /usr/lib/sdk/rust-stable/bin in my manifest, so mold is in $PATH.
If I set RUSTFLAGS: -C link-arg=-fuse-ld=mold the build fails:

  = note: collect2: fatal error: cannot find 'ld'
          compilation terminated.
          

error: could not compile `serde` due to previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name build_script_build /run/build/lapce/cargo/vendor/serde-1.0.143/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="serde_derive"' --cfg 'feature="std"' -C metadata=defc46304c21cac7 -C extra-filename=-defc46304c21cac7 --out-dir /run/build/lapce/target/release/build/serde-defc46304c21cac7 -L dependency=/run/build/lapce/target/release/deps --cap-lints allow -C link-arg=-fuse-ld=mold` (exit status: 1)
@sebastian-de
Copy link
Author

I also tried to use mold -run cargo --offline build --release, but that resulted in mold: fatal: mold-wrapper.so is missing.
Does any of the maintainers know how to achieve this? @Hofer-Julian maybe?

@Hofer-Julian
Copy link
Contributor

No sorry, I never tried that and just followed the instructions on mold's README.

@teohhanhui
Copy link

It seems like fuse-ld=mold only works if mold is in one of gcc's search dirs:

[📦 org.freedesktop.Sdk ~]$ gcc --print-search-dirs | grep ^programs:
programs: =/usr/libexec/gcc/x86_64-unknown-linux-gnu/12.1.0/:/usr/libexec/gcc/x86_64-unknown-linux-gnu/12.1.0/:/usr/libexec/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/12.1.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/12.1.0/../../../../x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu/12.1.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/12.1.0/../../../../x86_64-unknown-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/12.1.0/../../../../x86_64-unknown-linux-gnu/bin/

Perhaps this needs to be fixed in org.freedesktop.Sdk?

@sonnyp
Copy link

sonnyp commented Mar 24, 2024

@teohhanhui is correct

To expand a bit on that, gcc does not support path for -fuse-ld so what works for llvm doesn't for gcc : -fuse-ld=/usr/lib/sdk/rust-stable/bin/mold

-fuse-ld=mold would be the way to go but mold needs to be in the search dirs of gcc.

There is an option -B to add a path to search dirs of gcc but I couldn't make it work

-C link-arg=-fuse-ld=mold -C link-arg=-B=/usr/lib/sdk/rust-stable/ results in note: collect2: fatal error: cannot find 'ld'

There is a whole thread on the gcc mailing list https://gcc.gnu.org/pipermail/gcc-patches/2021-June/thread.html#573768

Regardless I agree that's something that should be fixed in the sdk extension but I don't know if it's possible to add a search dir to gcc from there.

@teohhanhui
Copy link

There's also the option of just replacing /usr/bin/ld with lld like what Fedora offers:

https://fedoraproject.org/wiki/Changes/Add_LLD_As_Update_Alternatives_Option_For_LD

(/usr/bin/ld is a symlimk managed by update-alternatives in Fedora)

I don't know how feasible this option is for Flatpak though. Could there be an SDK extension that overrides files from another SDK extension?

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

4 participants