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

Could not compile libafl_cc #1234

Closed
NeXX451 opened this issue Apr 27, 2023 · 8 comments
Closed

Could not compile libafl_cc #1234

NeXX451 opened this issue Apr 27, 2023 · 8 comments

Comments

@NeXX451
Copy link
Contributor

NeXX451 commented Apr 27, 2023

Hi,
I'm trying to build the library using cargo build --release. However, the process terminates with the error:

warning: Failed to find clang frontend.
   Compiling libafl_cc v0.10.0 (D:\C\rust\fuzzing\LibAFL\libafl_cc)
error[E0425]: cannot find value `LIBAFL_CC_LLVM_VERSION` in this scope
   --> libafl_cc\src\clang.rs:309:36
    |
309 |                 if let Some(ver) = LIBAFL_CC_LLVM_VERSION {
    |                                    ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `CLANG_PATH` in this scope
   --> libafl_cc\src\clang.rs:398:25
    |
398 |             wrapped_cc: CLANG_PATH.into(),
    |                         ^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `CLANGXX_PATH` in this scope
   --> libafl_cc\src\clang.rs:399:26
    |
399 |             wrapped_cxx: CLANGXX_PATH.into(),
    |                          ^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
The following warnings were emitted during compilation:

warning: Failed to find clang frontend.

error: could not compile `libafl_cc` due to 3 previous errors

Now, I have installed LLVM-14.06 and I have also compiled the llvm-project (same version) to get the llvm-config executable. I have also set the path variable LLVM_CONFIG. The strange thing is that I have set the path to clang and I can compile with clang without problem.. here is the version:

PS D:\C\rust\fuzzing> clang --version
clang version 14.0.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

PS D:\C\rust\fuzzing> llvm-config --version
14.0.6

Any suggestions appreciated.

@tokatoka
Copy link
Member

tokatoka commented Apr 27, 2023

do you have ./target/release/build/libafl_cc-<random number>/out/clang_constants.rs in your directory?
https://github.com/AFLplusplus/LibAFL/blob/main/libafl_cc/build.rs#L271
This is an auto-generated file needed to compile libafl_cc

@NeXX451
Copy link
Contributor Author

NeXX451 commented Apr 27, 2023

Yup, I have libafl_cc-12ae2230e3679ae0 which contains some build scripts and libafl_cc-85d22745fcb8a4f6 which contains the mentioned /out/clang_constants.rs, however, it is an empty file.

@tokatoka
Copy link
Member

ok, then
https://github.com/AFLplusplus/LibAFL/blob/main/libafl_cc/src/clang.rs#L26
this line is where it includes the aforementioned clang_constants.rs.

Can you check if this is the right file, that has all the CLANG, LLVM_CC_LLVM_VERSION, definitions?

@NeXX451
Copy link
Contributor Author

NeXX451 commented Apr 27, 2023

Sure I can, except I don't know how. If it includes the aforementioned file, then it includes an empty file.

@NeXX451
Copy link
Contributor Author

NeXX451 commented Apr 27, 2023

Ok, after a bit of digging, I have verified that yes it is indeed the correct file. However, in in here

write!(
it should populate the clang_constants.rs file, but only if it can't find llvm-config??

    if find_llvm_config().is_err() {  <-------- true if llvm-config not found
        println!(
            "cargo:warning=Failed to find llvm-config, we will not build LLVM passes. If you need them, set the LLVM_CONFIG environment variable to a recent llvm-config."
        );

        write!(
            clang_constants_file,
            "// These constants are autogenerated by build.rs
/// The path to the `clang` executable
pub const CLANG_PATH: &str = \"clang\";
/// The path to the `clang++` executable
pub const CLANGXX_PATH: &str = \"clang++\";
/// The llvm version used to build llvm passes
pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = None;
    "
        )

so the file is populated only if it doesn't find llvm-config? I'm confused. If I negate the if clause, I get the warning that llvm-config wasn't found but the file is populated. Namely with:

// These constants are autogenerated by build.rs
/// The path to the `clang` executable
pub const CLANG_PATH: &str = "clang";
/// The path to the `clang++` executable
pub const CLANGXX_PATH: &str = "clang++";
/// The llvm version used to build llvm passes
pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = None;

@tokatoka
Copy link
Member

if llvm-config is installed. then it'll get populated here

write!(

@NeXX451
Copy link
Contributor Author

NeXX451 commented Apr 27, 2023

ok I found the issue, why it can't find clang. It's because of this

    let llvm_bindir = exec_llvm_config(&["--bindir"]);
    let bindir_path = Path::new(&llvm_bindir);

    let clang = bindir_path.join("clang");

If one installs the LLVM-tools on windows, it doesn't come with llvm-config, for that you have to compile the llvm-project yourself. Long story short, llvm-config and the clang executable are in two different locations. You can close this now :D
However it wouldn't be a bad idea to include another env variable just for clang.

@tokatoka
Copy link
Member

tokatoka commented Apr 27, 2023

However it wouldn't be a bad idea to include another env variable just for clang.

Yes, if you can submit a pr that'll be helpful. We don't have anybody with access to windows now.

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