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

--include-ffi cargo:warning=clang: error: unknown argument: '-fprofile-update=atomic' #377

Closed
zaq7434 opened this issue Jul 18, 2024 · 5 comments
Labels
C-question Category: A question

Comments

@zaq7434
Copy link

zaq7434 commented Jul 18, 2024

I have imported environment variables as required, but an error is reported after the '''cargo llvm-cov--lcov--include-ffi '''command is executed. Is it necessary to upgrade the clang version?
Thank you for your help!

build.rs

fn main() {
    cc::Build::new()
        .file("./src/hello.c")
        .compile("libhello.so");
}

llvm-cov 、clang++ and clang version :

llvm-cov --version
LLVM (http://llvm.org/):
  LLVM version 10.0.0
  
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: skylake-avx512

clang++ --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

clang --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

error info:

 --- stdout
  TARGET = Some("x86_64-unknown-linux-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = Some("/usr/bin/clang")
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = Some(" -fprofile-instr-generate -fcoverage-mapping -fprofile-update=atomic")
  cargo:warning=clang: error: unknown argument: '-fprofile-update=atomic'

  --- stderr


  error occurred: Command "/usr/bin/clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "--target=x86_64-unknown-linux-gnu" "-fprofile-instr-generate" "-fcoverage-mapping" "-fprofile-update=atomic" "-o" "/xxxx/target/llvm-cov-target/debug/build/xxx-3da963f442cec0dd/out/341629401c88030c-xxxx.o" "-c" "./src/xxx.c" with args clang did not execute successfully (status code exit status: 1).
@taiki-e
Copy link
Owner

taiki-e commented Jul 18, 2024

Is it necessary to upgrade the clang version?

Yes.

https://github.com/taiki-e/cargo-llvm-cov#get-coverage-of-cc-code-linked-to-rust-librarybinary

Set CC, CXX, LLVM_COV, and LLVM_PROFDATA environment variables to Clang/LLVM compatible with the LLVM version used in rustc, and run cargo-llvm-cov with --include-ffi flag.

The exact version required depends on the version of LLVM used in rustc, but usually the same version will work, and slightly older versions may or may not work.
(I would like to test it in CI and document it if possible... #241)

@taiki-e taiki-e added the C-question Category: A question label Jul 18, 2024
@zaq7434
Copy link
Author

zaq7434 commented Jul 18, 2024

clang 19 may support ' -fprofile-update=atomic'
How can I disable this option in earlier versions?

@taiki-e
Copy link
Owner

taiki-e commented Jul 18, 2024

How can I disable this option in earlier versions?

Unless you pass --include-ffi it is never passed to clang.

@taiki-e
Copy link
Owner

taiki-e commented Jul 18, 2024

clang 19 may support ' -fprofile-update=atomic'

In fact, that flag is supported by at least clang 13.
However, clang 13 is not even compatible with the coverage output of Rust 1.60, so you actually need at least clang 14.

https://github.com/taiki-e/cargo-llvm-cov/actions/runs/9992831084/job/27618778896

warning: /home/runner/work/cargo-llvm-cov/cargo-llvm-cov/tests/fixtures/crates/ffi/target/llvm-cov-target/ffi-2588-12781922132114531458_0.profraw: unsupported instrumentation profile format version
warning: /home/runner/work/cargo-llvm-cov/cargo-llvm-cov/tests/fixtures/crates/ffi/target/llvm-cov-target/ffi-2690-4839793181851534479_0.profraw: unsupported instrumentation profile format version
warning: /home/runner/work/cargo-llvm-cov/cargo-llvm-cov/tests/fixtures/crates/ffi/target/llvm-cov-target/ffi-2660-6024429800373142552_0.profraw: unsupported instrumentation profile format version
error: no profile can be merged
error: failed to merge profile data: process didn't exit successfully: `llvm-profdata-13 merge -sparse -f /home/runner/work/cargo-llvm-cov/cargo-llvm-cov/tests/fixtures/crates/ffi/target/llvm-cov-target/ffi-profraw-list -o /home/runner/work/cargo-llvm-cov/cargo-llvm-cov/tests/fixtures/crates/ffi/target/llvm-cov-target/ffi.profdata` (exit status: 1)

The exact version required depends on the version of LLVM used in rustc, but usually the same version will work, and slightly older versions may or may not work. (I would like to test it in CI and document it if possible... #241)

From the test on CI and local:

  • rustc 1.60-1.77 (builtin LLVM is 14-17) are at least compatible with all of clang 14-17
  • rustc 1.78- (builtin LLVM is 18) seem not compatible with clang 14-17 and compatible with clang 18

@taiki-e
Copy link
Owner

taiki-e commented Jul 18, 2024

Compatible Rust and LLVM versions are now documented in readme.
https://github.com/taiki-e/cargo-llvm-cov#get-coverage-of-cc-code-linked-to-rust-librarybinary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: A question
Projects
None yet
Development

No branches or pull requests

2 participants