miri icon indicating copy to clipboard operation
miri copied to clipboard

Unsupported operation `sqlite3_open_v2`

Open weiznich opened this issue 3 years ago • 6 comments

Motivated by Ralf Jung's blog post about the last 2 years of miri development I've tried to run diesels test suit using miri. Especially the sqlite backend does a lot of nasty pointer things, so another layer of checks beside asan and friends would be helpful. I run into the following error message:

error: unsupported operation: can't call foreign function: sqlite3_open_v2
   --> diesel/src/sqlite/connection/raw.rs:47:13
    |
47  |             ffi::sqlite3_open_v2(database_url.as_ptr(), &mut conn_pointer, flags, ptr::null())
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't call foreign function: sqlite3_open_v2
    |
    = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support

    = note: inside `sqlite::connection::raw::RawConnection::establish` at diesel/src/sqlite/connection/raw.rs:47:13
note: inside `<sqlite::connection::SqliteConnection as connection::Connection>::establish` at diesel/src/sqlite/connection/mod.rs:92:30
   --> diesel/src/sqlite/connection/mod.rs:92:30
    |
92  |         let raw_connection = RawConnection::establish(database_url)?;
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `test_helpers::connection` at diesel/src/test_helpers.rs:10:13
   --> diesel/src/test_helpers.rs:10:13
    |
10  |             SqliteConnection::establish(":memory:").unwrap()
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `connection::transaction_manager::test::sqlite_transaction_is_rolled_back_upon_deferred_constraint_failure` at diesel/src/connection/transaction_manager.rs:896:25
   --> diesel/src/connection/transaction_manager.rs:896:25
    |
896 |         let conn = &mut crate::test_helpers::connection();
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure at diesel/src/connection/transaction_manager.rs:889:5
   --> diesel/src/connection/transaction_manager.rs:889:5
    |
887 |       #[test]
    |       ------- in this procedural macro expansion
888 |       #[cfg(feature = "sqlite")]
889 | /     fn sqlite_transaction_is_rolled_back_upon_deferred_constraint_failure() {
890 | |         use crate::connection::transaction_manager::AnsiTransactionManager;
891 | |         use crate::connection::transaction_manager::TransactionManager;
892 | |         use crate::result::Error;
...   |
923 | |         );
924 | |     }
    | |_____^
    = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

I should note that I kind of expected that. I mainly raise this issue as the blog post explicitly calls for opening issues for unsupported operations.

Environment information:

  • Ubuntu 22.04
  • rustc --version:
rustc 1.63.0-nightly (c06728704 2022-05-19)
binary: rustc
commit-hash: c0672870491e84362f76ddecd50fa229f9b06dff
commit-date: 2022-05-19
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.4

Steps to reproduce:

git clone https://github.com/diesel-rs/diesel
cd diesel
git checkout cbdfee30b206fff0aba62fa482fd837c0edd2cea
cd diesel
cargo miri test --features "sqlite" --no-default-features

weiznich avatar Jul 04 '22 12:07 weiznich

I think the only way forward for this would be to change libsqlite3-sys to use #[cfg(miri)] to do a pure-Rust in-memory implementation (beyond compiling the C library to Rust via that c2rust converter, I forget its name).

I mean, we do have https://github.com/rust-lang/miri/issues/11 which would allow these things directly, but considering it has been untouched for years, it may take more years.

oli-obk avatar Jul 04 '22 12:07 oli-obk

Yeah, I should probably have worded this a bit more carefully in the blog post... we're not going to be able to implement Python, PHP, or sqlite in Miri. :/

RalfJung avatar Jul 04 '22 13:07 RalfJung

That's totally understandable and that is what I've assumed anyway. I'm fine with closing this issue as out of scope :heart:

weiznich avatar Jul 05 '22 07:07 weiznich

I guess to resolve this issue properly we should add something to https://github.com/rust-lang/miri/blob/master/CONTRIBUTING.md that says what things are in scope of miri and what are out of scope

oli-obk avatar Jul 05 '22 07:07 oli-obk

👀 https://github.com/maurer/miri/pull/1

LegNeato avatar Jul 08 '22 06:07 LegNeato

Oh wow. oO

RalfJung avatar Jul 08 '22 20:07 RalfJung

Closing as we'll not implement this shim in Miri.

RalfJung avatar May 04 '24 11:05 RalfJung