Skip to content

[BUG] Llvm-plugins failed when build the same nightly rustc to stage2 rustc #137954

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

Closed
llooFlashooll opened this issue Mar 3, 2025 · 11 comments
Closed
Labels
-Zllvm-plugins Unstable option: LLVM plugins A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@llooFlashooll
Copy link

Hi guys, I try to use these commands to build the rustc compiler from the source and link its stage2. I just modified the nightly config in the config.toml, and found it cannot -Z llvm-plugins= load the passes. However, I can do it successfully in the same version of the rustup install nightly-x compiler.

cp config.example.toml config.toml
python3 x.py build --stage 2 -j 8

Here is the rustc --version --verbose message of both nightly and stage2 versions:

rustc 1.76.0-nightly (3f28fe133 2023-12-18)
binary: rustc
commit-hash: 3f28fe133475ec5faf3413b556bf3cfb0d51336c
commit-date: 2023-12-18
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.6

Here is the error message of the stage2 compiler. The nightly-installed one can successfully execute.

RUSTFLAGS="-Z unstable-options -Z llvm-plugins=../../afl-llvm-pass.so" cargo build

error: failed to run LLVM passes: Failed to load pass plugin../../afl-llvm-pass.so <- It can be any .so file.

What is the correct config.example.toml setting and the procedure?

@llooFlashooll llooFlashooll added the C-bug Category: This is a bug. label Mar 3, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 3, 2025
@llooFlashooll llooFlashooll changed the title Llvm-plugins failed when build the same nightly rustc to stage2 rustc [BUG] Llvm-plugins failed when build the same nightly rustc to stage2 rustc Mar 3, 2025
@jieyouxu jieyouxu added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 3, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 3, 2025

rustc 1.76.0-nightly (3f28fe1 2023-12-18)

Does this repro on a rustc built on latest master? And what rustc is the cargo build actually running?

@jieyouxu jieyouxu added S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. S-needs-info Status: The issue lacks details necessary to triage or act on it. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 3, 2025
@llooFlashooll
Copy link
Author

No. I build from scratch of the nightly (3f28fe1) compiler by git reset to the commit hash.
cargo build applies to any Rust program, when you try to -Z llvm-plugins=.

This bug can be reproduced I think, and looks strange. I don't know how to address it.

@jieyouxu
Copy link
Member

jieyouxu commented Mar 3, 2025

That commit is ancient. Like, more than a year ago. I ask what rustc cargo build is running because you could be running idk stable rustc and not whatever rustc you built. What does cargo -vV say?

@llooFlashooll
Copy link
Author

llooFlashooll commented Mar 3, 2025

cargo build -> I build the rust-url project. But actually this case applies to HelloWorld Rust program.
-Z llvm-plugins= -> I want to load my own afl-fuzz.so to fuzz the rust-url project.

I don't think the commit is old. Just close to a year. Besides, for example, a lot of projects rely on llvm. Usually we cannot update to too recent llvm version. This rustc supports llvm-17, which is already quite new. The rustc is also quite new. (We all know that a project undergoes one year is so common.)

Here is cargo -vV.

cargo 1.85.0-nightly (4c39aaff6 2024-11-25)
release: 1.85.0-nightly
commit-hash: 4c39aaff66862cc0da52fe529aa1990bb8bb9a22
commit-date: 2024-11-25
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 22.4.0 (jammy) [64-bit]

@llooFlashooll
Copy link
Author

llooFlashooll commented Mar 3, 2025

Another way is that maybe I want to know, how to build a rustc compiler from scratch as the same as nightly-installed compiler?
There are so many configurations in the config.toml.example.

@jieyouxu
Copy link
Member

jieyouxu commented Mar 3, 2025

You are not using the rustc you built. This cargo build invocation is using the nightly rustc shipped with the nightly 2024-11-25 toolchain. Did you link the stage2 rustc via https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html?highlight=rustup%20link#creating-a-rustup-toolchain? Then, I would've expected your cargo invocation to look sth like cargo +stage2 build.

@jieyouxu
Copy link
Member

jieyouxu commented Mar 3, 2025

cc @nikic @ZuseZ4 since you may have any ideas (I don't test this configuration at all)... Do you happen to know if this configuration is possible?

cc #127577.

@jieyouxu jieyouxu added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. -Zllvm-plugins Unstable option: LLVM plugins needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. S-needs-info Status: The issue lacks details necessary to triage or act on it. labels Mar 3, 2025
@ZuseZ4
Copy link
Member

ZuseZ4 commented Mar 3, 2025

I can cinfirm that I used -Z llvm-plugins just a month ago successfully with Enzyme on a self-build rustc. I can share more details later today.

I did use the configure command mentioned here:
https://enzyme.mit.edu/index.fcgi/rust/installation.html#build-instructions

I am pretty sure llvm.enable_plugins isn't set to true by default.

@jieyouxu
Copy link
Member

jieyouxu commented Mar 3, 2025

Oh right. You may need to explicitly build LLVM and also configure config.toml with

[llvm]
plugins = true

But I'm not 100% sure, because I've never used this myself.

@llooFlashooll
Copy link
Author

llooFlashooll commented Mar 4, 2025

Sorry, I tried the instructions you provided, and still triggered this bug. @jieyouxu. Let me try the instructions by @ZuseZ4.

@llooFlashooll
Copy link
Author

Hi @ZuseZ4 , the configuration setting works, and it fixes the issue. Thanks.

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zllvm-plugins Unstable option: LLVM plugins A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants