rustanlys / rupta

A Pointer Analysis Framework for Rust
https://rustanlys.github.io/rupta/
GNU General Public License v3.0
42 stars 8 forks source link

Rupta crashed after generating the call graph #4

Open Endericedragon opened 5 months ago

Endericedragon commented 5 months ago

Thanks for your rapid fixing work! Eventually I could get the full call graph of Substrate Node Template. However, not only the compiling and analysing cost a lot of time (near 4 hours), but I also received delayed bugs messages after rupta had generated the .dot file and pts information. Here is the bug message I received:

##########################################################
Call Graph Statistics:
#Reachable functions (CS): 156806
#Reachable functions (CI): 58415
#Reachable unmonomorphized functions (CI): 17629
#Call graph edges (CS): 373326
#Call graph edges (CI): 156805
#Statically resolved calls: 155235
#Dynamically resolved calls: 533, #call graph edges: 1570
        #Dynamic dispatch calls: 446, #call graph edges: 884
        #Fnptr calls: 66, #call graph edges: 72
        #Dynamic Fn* trait calls: 21, #call graph edges: 614
----------------------------------------------------------
CS Points-to Statistics:
#Pointers: 2349972
#Points-to relations: 91999763
#Avg points-to size: 39.14930177891481
CI Points-to Statistics:
#Pointers: 893837
#Points-to relations: 14818231
#Avg points-to size: 16.578225112632392
##########################################################
Used Memory Before Analysis: 340 MB
Max Memory in Analysis: 23166 MB
note: no errors encountered even though `span_delayed_bug` issued

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: cannot relate consts of different types (a=1_usize, b=?0c: bool)
  |
  = note: delayed at compiler/rustc_infer/src/infer/relate/combine.rs:183:32 - disabled backtrace

thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:1462:9:
Box<dyn Any>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: could not compile `node-template` (bin "node-template")

Caused by:
  process didn't exit successfully: `/home/endericedragon/.cargo/bin/cargo-pta /home/endericedragon/.rustup/toolchains/nightly-2024-02-03-x86_64-unknown-linux-gnu/bin/rustc --crate-name node_template --edition=2021 node/src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=114 --crate-type bin --emit=dep-info,metadata -C opt-level=3 -C embed-bitcode=no --cfg 'feature="default"' -C metadata=4682dc25484d0090 -C extra-filename=-4682dc25484d0090 --out-dir /home/endericedragon/repos/substrate-node-template-copy/target/release/deps -C strip=debuginfo -L dependency=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps --extern clap=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libclap-b93f4a5060d339df.rmeta --extern frame_benchmarking=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libframe_benchmarking-526d8e14c4d88e2e.rmeta --extern frame_benchmarking_cli=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libframe_benchmarking_cli-b0942ae1ec54d3e8.rmeta --extern frame_system=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libframe_system-9a97457edb5aa3a4.rmeta --extern futures=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libfutures-0657d23efe7ddbc7.rmeta --extern jsonrpsee=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libjsonrpsee-df2a08305033a2fb.rmeta --extern node_template=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libnode_template-e97827ef26b660bc.rmeta --extern node_template_runtime=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libnode_template_runtime-1258c3169e5d4206.rmeta --extern pallet_transaction_payment=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libpallet_transaction_payment-7f9d93bc4da80d0e.rmeta --extern pallet_transaction_payment_rpc=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libpallet_transaction_payment_rpc-7ba4d8a483987661.rmeta --extern sc_basic_authorship=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_basic_authorship-9acc44af58916c60.rmeta --extern sc_cli=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_cli-a02aee59ed8d3eeb.rmeta --extern sc_client_api=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_client_api-bf33d32df8d1e8f3.rmeta --extern sc_consensus=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_consensus-d8944f75789afe34.rmeta --extern sc_consensus_aura=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_consensus_aura-ddfd4fffd11bb188.rmeta --extern sc_consensus_grandpa=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_consensus_grandpa-9c1a2d7e3fcf2dce.rmeta --extern sc_executor=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_executor-8bdd6a66c1006da3.rmeta --extern sc_network=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_network-dd7c50b678478a0d.rmeta --extern sc_offchain=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_offchain-f0331688b1853944.rmeta --extern sc_rpc_api=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_rpc_api-c5f1dbb7fabbd3bf.rmeta --extern sc_service=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_service-12918ea595ec50e0.rmeta --extern sc_statement_store=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_statement_store-fa15dcd2ee60dec3.rmeta --extern sc_telemetry=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_telemetry-5b3143f9679b5e09.rmeta --extern sc_transaction_pool=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_transaction_pool-af929fc47f0abafb.rmeta --extern sc_transaction_pool_api=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsc_transaction_pool_api-b42c7e527965c80a.rmeta --extern sp_api=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_api-66e2497628ee7c57.rmeta --extern sp_block_builder=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_block_builder-27cafc9a59eb8b9b.rmeta --extern sp_blockchain=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_blockchain-923b376467cd4bd1.rmeta --extern sp_consensus_aura=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_consensus_aura-4dd36008b93c10bc.rmeta --extern sp_consensus_grandpa=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_consensus_grandpa-ee34c37acd541271.rmeta --extern sp_core=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_core-ea394a10482b4e47.rmeta --extern sp_inherents=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_inherents-84c21e0aa3dfc415.rmeta --extern sp_io=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_io-bbf8b7d8262ef267.rmeta --extern sp_keyring=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_keyring-6d9a9853bbc131bd.rmeta --extern sp_runtime=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_runtime-9f88f8738fec0221.rmeta --extern sp_timestamp=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsp_timestamp-8c1e40de05adcba1.rmeta --extern substrate_frame_rpc_system=/home/endericedragon/repos/substrate-node-template-copy/target/release/deps/libsubstrate_frame_rpc_system-61941b511c4ecee6.rmeta -Z always_encode_mir -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/secp256k1-sys-30adedace81f3255/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/psm-797561feeccef94d/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/zstd-sys-182dad89d171d540/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/wasmtime-runtime-0dbad21a8f6087dc/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/blake3-b69f35ae3c08cdba/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/blake3-b69f35ae3c08cdba/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/librocksdb-sys-23bebd4cf1e1856b/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/librocksdb-sys-23bebd4cf1e1856b/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/tikv-jemalloc-sys-02b951e3579e8d7c/out/build/lib -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/lz4-sys-8a4a456edb69adf8/out -L native=/home/endericedragon/repos/substrate-node-template-copy/target/release/build/ring-9b05b8e8b9375404/out` (exit status: 101)
Error: <stdin>: syntax error in line 398 scanning a quoted string (missing endquote? longer than 16384?)
String starting:"tokio::runtime::scheduler::current_thread::{impl#8}::block_on::{closure#0}<std::

After going through the paper about rupta and the manual, I still do not know what delayed bugs are. Are there code smells in the analyzed crate? Or it is just another bug of rupta?

rustanlys commented 5 months ago

We have also encountered this issue. However, it seems to have little impact on our analysis.

We think this issue is caused by subtle and undocumented invariants not being satisfied when using the Rust compiler's query system, leading to an internal compiler error.

It is not easy to pinpoint the problem, but we will work on fixing it in the future.

rustanlys commented 5 months ago

We tested Rupta on analyzing the substrate-node-template. Although the project itself is not very large, it has many dependencies, resulting in a large number of reachable functions. Consequently, it requires some time and memory to analyze.

Our analysis results differed from yours, which may be due to analyzing different versions of the substrate-node-template. Our test showed more reachable functions than your results, but our analysis took much less time.

I think the long analysis time might be due to insufficient available memory during the analysis. As indicated in your results, it took about 23GB to analyze this project. It is necessary to ensure enough running memory during analysis.

Endericedragon commented 5 months ago

We tested Rupta on analyzing the substrate-node-template. Although the project itself is not very large, it has many dependencies, resulting in a large number of reachable functions. Consequently, it requires some time and memory to analyze.

Our analysis results differed from yours, which may be due to analyzing different versions of the substrate-node-template. Our test showed more reachable functions than your results, but our analysis took much less time.

I think the long analysis time might be due to insufficient available memory during the analysis. As indicated in your results, it took about 23GB to analyze this project. It is necessary to ensure enough running memory during analysis.

Indeed, I am analyzing an older version of substrate node template(which is a fork created in last year). I think I would install more memory on my PC to accelerate that process. Thanks for your reply!

workingjubilee commented 4 months ago

We have also encountered this issue. However, it seems to have little impact on our analysis.

We think this issue is caused by subtle and undocumented invariants not being satisfied when using the Rust compiler's query system, leading to an internal compiler error.

Undocumented, yes. Subtle... not very?

In general, the Rust compiler is designed to issue a "bug" on any question that, during a normal compilation session, you should probably not even be asking. This is a fairly standard "fail fast" stance.

However, there are some questions that are okay to ask, but the answer implies the program should be rejected. When you ask a question, "are these consts equal types?", it is expecting you are using the answer to typecheck and thus reject the program. Then the compiler creates a delayed bug. The compiler asking such a question is deemed "non-buggy" if an error is later issued.

Most of the compiler is not designed to support general analysis of it. It is designed to actually compile programs, and thus to reject incorrect programs. The stable_mir project is designed to create something that does support general analysis.