Compile libcore to llvm IR (bytecode)

guys,

We are building a symbolic executor for Rust, but got trouble building standard library into llvm IR(bytecode), e.g., libcore.

we tried everything found by google:

  • rustc --emit=llvm-bc src/libcore/lib.rs
  • xbuild etc

nothing worked so far, any idea ? thanks!

What are the problems?

As a workaround you could take libcore-.rlib from somewere in the sysroot (rustc --print sysroot) and use ar x to extract it. One of the files has bc as an extension. I believe it is compressed with flate2, so you will have to decompress it. This is an implementation detail, so it can change at any moment.

What exactly are you getting as an error? rustc --emit=llvm-ir kind of works for me (e.g. it is what cargo llvm-ir uses) and dumps llvm-ir, you could then compile that to bytecode manually.

below is the syntax error I got :

~/work/rust.git$ rustc --emit=llvm-bc src/libcore/lib.rs

error[E0642]: patterns aren't allowed in methods without bodies --> src/libcore/iter/traits/iterator.rs:1742:51 | 1742 | fn partition_in_place<'a, T: 'a, P>(mut self, ref mut predicate: P) -> usize | ^^^^^^^^^^^^^^^^^ | help: give this argument a name or use an underscore to ignore it | 1742 | fn partition_in_place<'a, T: 'a, P>(mut self, _: P) -> usize | ^

error[E0432]: unresolved import manually_drop --> src/libcore/mem/mod.rs:18:9 | 18 | pub use manually_drop::ManuallyDrop; | ^^^^^^^^^^^^^ help: a similar path exists: self::manually_drop

error[E0432]: unresolved import maybe_uninit --> src/libcore/mem/mod.rs:22:9 | 22 | pub use maybe_uninit::MaybeUninit; | ^^^^^^^^^^^^ help: a similar path exists: self::maybe_uninit

The latter two sounds like an edition import handling difference; make sure you compile the crates in the correct edition (I think all the stdlib crates are edition2018).

I am using top of rust.git tree with version info:

Merge: f8fd462 ae03e16 Author: bors bors@rust-lang.org Date: Fri Feb 7 06:24:55 2020 +0000

rustc is in-tree installed, with version info: rustc 1.43.0-dev

thanks bjorn3 for the reply.

once you ar x to extract the rlib file, the .bc.z file is not in flate2 format, it is flate2 with customized header, exact description is here: RUST_OBJECT format

the decompressing code is in same rs file.

I am not aware of any standalone utility to decode this format, but with link above, not hard to create one.

thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.