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

Failed to get bitcode from object file for LTO #32

Open
jiayihu opened this issue Nov 21, 2020 · 8 comments
Open

Failed to get bitcode from object file for LTO #32

jiayihu opened this issue Nov 21, 2020 · 8 comments

Comments

@jiayihu
Copy link

jiayihu commented Nov 21, 2020

When trying to use the tool I get the following error:

cargo +nightly call-stack --bin fedra --verbose

"cargo" "rustc" "--bin" "fedra" "--release" "--" "--emit=llvm-ir,obj" "-C" "embed-bitcode=yes" "-C" "lto=fat" "-Z" "emit-stack-sizes"
   Compiling fedra v0.1.0 (/Users/jiayihu/Desktop/Repo/fedra-clone)
error: failed to get bitcode from object file for LTO (Bitcode section not found in object file)
rustc --version
rustc 1.50.0-nightly (593fe977a 2020-11-20)

Same error even with the previous nightly rustc 1.49.0-nightly (b1496c6e6 2020-10-18)

@jiayihu
Copy link
Author

jiayihu commented Nov 21, 2020

Ironically if I try RUSTFLAGS="-C embed-bitcode" as said in #25 , it gives a different error:

error: BUG: failed to parse .ll file; please submit a bug report with Rust source code. Details (include the _first_ LLVM item, e.g. `define .. { .. }`, in the report):
Failure(("%0 = type { [0 x i32], { {}*, [3 x i32]* }, [0 x i32], i8*, [0 x i32] }\n%1 = type { [0 x i32], %2, [0 x i32], i8*, [0 x i8], i8, [3 x i8] }\n%2 = type { [0 x i32], %\"rtt_target::rtt::RttChannel\"*, [0 x i32], i32, [0 x i32], i32, [0 x i8], i8, [3 x i8] }\n%3 = type { [0 x i32], %\"alloc::string::String\", [0 x i32] }\n%4 = type { [0 x i32], %\"core::fmt::Formatter\"*, [0 x i32], i32, [0 x i8], i8, [0 x i8], i8, [2 x i8] }\n%5 = type { [0 x i32], %\"core::fmt::Formatter\"*, [0 x i8], i8, [0 x i8], i8, [2 x i8] }\n%6 = type { [0 x i8], i8, [11 x i8] }\n%7 = type { [0 x i32], %8, [0 x i32], i32, [0 x i32] }\n%8 = type { [0 x i32], %9, [0 x i32], %9, [0 x i32] }\n%9 = type { [1 x i32], {}*, [1 x i32] }\n%10 = type { [0 x i8], {}, [0 x i8], i32*, [0 x i32], i32*, [0 x i32], i32, [0 x i32] }\n%11 = type { [0 x i32], %\"smoltcp::wire::Icmpv4Repr\", [0 x i32] }\n%12 = type { [0 x i32], i32, [0 x i32], i32, [0 x i32], %13, [0 x i32] }\n%13 = type { [0 x i32], %\"parity_wasm::el
[...]

@CedMaire
Copy link

Any update on fixing this issue?

@ysun
Copy link

ysun commented Apr 5, 2021

I got the same issue. May I know the progress of this issue ? I got exactly the same issue with @jiayihu. Hi @jiayihu do you get the solution ?

@jiayihu
Copy link
Author

jiayihu commented Apr 5, 2021

Sorry @ysun, no luck

@ysun
Copy link

ysun commented Apr 6, 2021

@jiayihu Then did you get any other solution to get rust call-graph ?

@taqtiqa-mark
Copy link

We have also observed this error:

BUG: failed to parse .ll file: Failure(("define internal fastcc void @_Z....

The following is a MRE.

Run this command:

RUSTFLAGS = "-C embed-bitcode" cargo +nightly call-stack --example rme > mre.dot

With this code as examples/mre.rs:

use lazy_static::lazy_static;
use rand::distributions::{Distribution, Uniform};
use std::time::Duration;
use tokio::time::{sleep, Instant};

lazy_static! { static ref START_TIME: Instant = Instant::now(); }

#[tokio::main]
async fn main() {
    let page = get_page(42).await;
    println!("Page #42: {:?}", page);
}

async fn get_page(i: usize) -> Vec<usize> {
    let millis = Uniform::from(5_000..6_000).sample(&mut rand::thread_rng());
    println!( "[{}] # get_page({}) will complete in {} ms on {:?}",
        START_TIME.elapsed().as_millis(),
        i,
        millis,
        std::thread::current().id()
    );

    sleep(Duration::from_millis(millis)).await;
    println!("[{}] # get_page({}) completed",
        START_TIME.elapsed().as_millis(),
        i
    );
    (10 * i..10 * (i + 1)).collect()
}

@savchenko
Copy link

Observing the same on the "hello world" created via cargo new.

cargo +nightly call-stack --bin hello --target x86_64-unknown-linux-gnu > hello.dot
  1. Exporting RUSTFLAGS="-C embed-bitcode" results in:

    error: failed to parse application's LLVM IR from `/tst/helloworld/target/x86_64-unknown-linux-gnu/release/deps/hello-f16df3c84b67da29.ll`: BUG: failed to parse LLVM IR; please submit a cargo-call-stack bug report and attach the `.ll` file: Failure("Eof in line 970")
    

    .ll file is attached to this message: hello-ll.zip

  2. Using LTO leads to the same problem.

  3. Not using either yields the error:

    error: failed to get bitcode from object file for LTO (Bitcode section not found in object file)
    

@jiayihu , looks suspiciously similar to what @taqtiqa-mark is experiencing in #33

@thvdveld thvdveld mentioned this issue Apr 28, 2022
bors bot added a commit that referenced this issue Jun 15, 2022
56: Fix parsing r=japaric a=thvdveld

This commit fixes some parsing errors I had.
Maybe this fixes #22, #28, #32 and #33.

Parsing is fixed for my own project, though I still have logged errors (at least the dot file is generated):
```
[2022-04-28T15:23:33Z ERROR cargo_call_stack] BUG? no callees for `void ({}*)`
[2022-04-28T15:23:33Z ERROR cargo_call_stack] BUG? no callees for `void ({}*, void ({}*)*)`
```

Co-authored-by: Thibaut Vandervelden <[email protected]>
@japaric
Copy link
Owner

japaric commented Jun 15, 2022

This issue seems to only affect Cargo project using the default release profile. To get pass the "Bitcode section not found in object file" error enable fat LTO in Cargo.toml -- this is a workaround

[profile.release]
lto = 'fat'

A fix may be adding -C embed-bitcode=yes to each rustc invocation; either that or remove the -C embed-bitcode=no that gets passed to rustc by default (when lto = 'thin').

after enabling fat LTO I get a LLVM IR parser error when running cargo-call-stack on a "Hello, world" project but that's a separate issue from this.

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

6 participants