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

Panic at program execution end with tfhe::generate_keys before rust 1.83 #1687

Open
amaury1093 opened this issue Oct 15, 2024 · 31 comments
Open
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@amaury1093
Copy link

Describe the bug

Followed docs. When calling tfhe::generate_keys, I get a panic at the end of the program execution (not during the function call). The panic is:

thread '<unnamed>' panicked at library/core/src/panicking.rs:220:5:
unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
[1]    26769 abort      cargo run

To Reproduce

Add the correct tfhe-rs version:

tfhe = { version = "0.8.3", features = [
    "boolean",
    "shortint",
    "integer",
    "aarch64-unix",
] }

Then in src/main.rs:

use tfhe::{generate_keys, ConfigBuilder};

fn main() {
    let config = ConfigBuilder::default().build();
    let _ = generate_keys(config);

    println!("Done.");
}

Expected behaviour

No error.

Actual behavior

The program ends, the keys are generated, but there's a panic at the end, after the call to generate_keys. See that the "Done." line is correctly printed.

➜  tfhe-rs-panic git:(main) ✗ cargo run
   Compiling tfhe-rs-panic v0.1.0 (/Users/amaury/Workspace/inco/tfhe-rs-panic)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.37s
     Running `target/debug/tfhe-rs-panic`
Done.
thread '<unnamed>' panicked at library/core/src/panicking.rs:220:5:
unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
[1]    26769 abort      cargo run
➜  tfhe-rs-panic git:(main) ✗ echo $?
134

Configuration(please complete the following information):

  • OS: macOS M1
  • Rust: 1.79

Additional context
Add any other context about the problem here.

@IceTDrinker
Copy link
Member

IceTDrinker commented Oct 15, 2024

That is very very weird to say the least.

do you have any non standard configuration ?

which hardware/OS (model and version) are you using ?

could you try updating your rust version with rustup update ?

also cargo clean and cargo update if you have the chance and try again

@IceTDrinker
Copy link
Member

Also if you have a full backtrace, it’s not clear what code is triggering the panic

@IceTDrinker
Copy link
Member

I think there may have been a faulty linker packaged with xcode tools on Apple mac at some point, could be worth to check if there is a way to update the dev tools coming from Apple

@amaury1093
Copy link
Author

No non-standard hardware or config. Running macOS 14.1.2 on Apple M1. Here's a repro: https://github.com/amaury1093/tfhe-rs-panic.

Backtrace (tried after cargo clean and cargo update):

➜  tfhe-rs-panic git:(main) RUST_BACKTRACE=1 cargo run               
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/tfhe-rs-panic`
Done.
thread '<unnamed>' panicked at library/core/src/panicking.rs:220:5:
unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:120:5
   3: core::panicking::panic_nounwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:220:5
   4: core::ptr::replace::precondition_check
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:66:21
   5: core::ptr::replace
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:73:17
   6: core::ptr::mut_ptr::<impl *mut T>::replace
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ptr/mut_ptr.rs:1560:18
   7: std::sys::thread_local::lazy::LazyKeyInner<T>::take
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/mod.rs:102:30
   8: std::sys::thread_local::fast_local::destroy_value::{{closure}}
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/fast_local.rs:241:21
   9: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
  10: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panic/unwind_safe.rs:272:9
  11: std::panicking::try::do_call
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:559:40
  12: ___rust_try
  13: std::panicking::try
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:523:19
  14: std::panic::catch_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panic.rs:149:14
  15: std::sys::thread_local::fast_local::destroy_value
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/fast_local.rs:239:21
  16: std::sys::pal::unix::thread_local_dtor::register_dtor::run_dtors
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/pal/unix/thread_local_dtor.rs:114:17
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.
[1]    33013 abort      RUST_BACKTRACE=1 cargo run

Also happens after:

➜  tfhe-rs-panic git:(main) rustup update stable
info: syncing channel updates for 'stable-aarch64-apple-darwin'

  stable-aarch64-apple-darwin unchanged - rustc 1.81.0 (eeb90cda1 2024-09-04)

info: checking for self-update

I'm updating Apple dev tools to see. I'll also ask other macOS users around me to try, and report back.

@IceTDrinker
Copy link
Member

IceTDrinker commented Oct 16, 2024

Looks like the crash is during the server key drop that’s stored in an Arc, or some of our thread local « engines »

@IceTDrinker
Copy link
Member

We’ll try to repro

@IceTDrinker
Copy link
Member

Running in release works fine I assume ?

@amaury1093
Copy link
Author

Running in release works fine I assume ?

Correct.

I also updated to macOS to 15.0.1 along with the Apple command line tools. Panic is still here.

@IceTDrinker
Copy link
Member

someone tried to run this on an M1 mac in debug and could not repro the crash :/

how did you install rustup ?

@amaury1093
Copy link
Author

how did you install rustup ?

It was a long time ago, but I'm sure it was following https://www.rust-lang.org/tools/install.

@IceTDrinker I know it can be hard to debug without repro. Let me know what info I can give you. However, it seems like it's only reproducible on my M1, so I'm happy to leave this issue in the background or even close it for now, until someone else confirms too. For now I'll simply run in release mode.

@IceTDrinker
Copy link
Member

IceTDrinker commented Oct 16, 2024

from where I'm standing it looks like a potential issue with your machine only, so maybe some peculiar setup having an issue, I would maybe try resintalling rust if for whatever reason a binary for the std is corrupted

@IceTDrinker
Copy link
Member

hey @amaury1093 unless you manage to have a repro on another machine I think we'll close that issue as it seems related to your particular setup (maybe some corrupted binary somewhere, really can't say)

@amaury1093
Copy link
Author

Sounds good, go ahead and close it.

@peitalin
Copy link

peitalin commented Oct 22, 2024

Running into the same issue with MacOs 13.5.1 on the latest rustc 1.82.0.

The quickstart example fails with the same error messages as @amaury1093's repo.

Likewise, running cargo run --release works.

@IceTDrinker IceTDrinker reopened this Oct 22, 2024
@IceTDrinker
Copy link
Member

hello @peitalin thanks for sharing, could you both share the version of the linker you are using ?

see e.g. https://stackoverflow.com/q/50246770/18088947

@peitalin
Copy link

Sure:

$ clang++ -v

Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ ld -v

@(#)PROGRAM:ld  PROJECT:dyld-1015.6
BUILD 20:37:42 Aug 14 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3)
Library search paths:
Framework search paths:

$ sw_vers

ProductName:		macOS
ProductVersion:		13.5.1
BuildVersion:		22G90

@IceTDrinker
Copy link
Member

could you try running the minimal repro with RUST_BACKTRACE=full ?

@peitalin
Copy link

peitalin commented Oct 22, 2024

Running @amaury1093's repo:

$  RUST_BACKTRACE=full cargo run 
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.22s
     Running `target/debug/tfhe-rs-panic`
thread 'main' panicked at core/src/panicking.rs:221:5:
unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null
stack backtrace:
   0:        0x1048e2448 - std::backtrace_rs::backtrace::libunwind::trace::h1c3451b342542f10
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:        0x1048e2448 - std::backtrace_rs::backtrace::trace_unsynchronized::h3743cad8cc2d54de
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1048e2448 - std::sys::backtrace::_print_fmt::h31ad576fee12d4ee
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:66:9
   3:        0x1048e2448 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::habbf9c4f641febb1
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:39:26
   4:        0x1048f741c - core::fmt::rt::Argument::fmt::h54965d9b1ee82264
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/fmt/rt.rs:177:76
   5:        0x1048f741c - core::fmt::write::ha36a8060c13608ea
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/fmt/mod.rs:1178:21
   6:        0x1048e0594 - std::io::Write::write_fmt::h431832c8ebcc85c9
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/io/mod.rs:1823:15
   7:        0x1048e35c4 - std::sys::backtrace::BacktraceLock::print::hd085ca0c3911e184
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:42:9
   8:        0x1048e35c4 - std::panicking::default_hook::{{closure}}::h4aa1f60327dfff6a
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:266:22
   9:        0x1048e3174 - std::panicking::default_hook::h4ebc6eb4ae179807
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:293:9
  10:        0x1048e3f90 - std::panicking::rust_panic_with_hook::h6a84efe4dcab239c
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:797:13
  11:        0x1048e3a44 - std::panicking::begin_panic_handler::{{closure}}::h5eef292190467fef
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:664:13
  12:        0x1048e290c - std::sys::backtrace::__rust_end_short_backtrace::hd7e7925203f20af9
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:170:18
  13:        0x1048e3734 - rust_begin_unwind
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:662:5
  14:        0x1049016b4 - core::panicking::panic_nounwind_fmt::runtime::hed7cc75ebcf8d970
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:112:18
  15:        0x1049016b4 - core::panicking::panic_nounwind_fmt::hb2df5b6c3d6ab15b
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:122:5
  16:        0x10490172c - core::panicking::panic_nounwind::h6b53a509f430e184
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:221:5
  17:        0x1047a6320 - core::ptr::replace::precondition_check::h1bd35d259ed51a2b
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ub_checks.rs:70:21
  18:        0x1048fcb74 - core::ptr::replace::h5b3649167c19b0f3
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ub_checks.rs:77:17
  19:        0x1048fcb74 - core::ptr::mut_ptr::<impl *mut T>::replace::hf06eb7f019c3e148
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ptr/mut_ptr.rs:1462:18
  20:        0x1048fcb74 - std::sys::thread_local::native::lazy::Storage<T,D>::initialize::hc0fccca2ed668ade
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/thread_local/native/lazy.rs:66:45
  21:        0x10476f440 - std::sys::thread_local::native::lazy::Storage<T,D>::get_or_init::h4f915c22fb65e1a5
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/thread_local/native/lazy.rs:56:40
  22:        0x1047950b4 - tfhe::shortint::engine::LOCAL_ENGINE::{{constant}}::{{closure}}::hccbcfa60c4426273
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/thread_local/native/mod.rs:93:25
  23:        0x10477051c - core::ops::function::FnOnce::call_once::hf38e54a44dbe3ccb
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
  24:        0x104757a14 - std::thread::local::LocalKey<T>::try_with::h792ef6ee3f51bce3
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/local.rs:282:37
  25:        0x104756d04 - std::thread::local::LocalKey<T>::with::h133aea6667b2688c
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/local.rs:260:9
  26:        0x104792290 - tfhe::shortint::engine::ShortintEngine::with_thread_local_mut::h4f79fd93d65b80ef
                               at /Users/peita/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tfhe-0.8.3/src/shortint/engine/mod.rs:300:9
  27:        0x104791554 - tfhe::shortint::client_key::ClientKey::new::h616c6b3a1f53d9de
                               at /Users/peita/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tfhe-0.8.3/src/shortint/client_key/mod.rs:67:9
  28:        0x1047913cc - tfhe::integer::client_key::ClientKey::new::ha3bbfe9138206075
                               at /Users/peita/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tfhe-0.8.3/src/integer/client_key/mod.rs:148:18
  29:        0x104798240 - <tfhe::high_level_api::keys::inner::IntegerClientKey as core::convert::From<tfhe::high_level_api::keys::inner::IntegerConfig>>::from::h3e9e2c535bdea7fe
                               at /Users/peita/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tfhe-0.8.3/src/high_level_api/keys/inner.rs:193:19
  30:        0x104751758 - tfhe::high_level_api::keys::client::ClientKey::generate::hcd9836800ab95d0f
                               at /Users/peita/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tfhe-0.8.3/src/high_level_api/keys/client.rs:35:18
  31:        0x1047513e8 - tfhe::high_level_api::keys::generate_keys::hcd7d7dd005cd0dda
                               at /Users/peita/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tfhe-0.8.3/src/high_level_api/keys/mod.rs:34:21
  32:        0x1047514cc - tfhe_rs_panic::main::h514cc79dfde30c55
                               at /Users/peita/Dev/eth/tfhe-rs-panic/src/main.rs:5:13
  33:        0x10475165c - core::ops::function::FnOnce::call_once::h77f60ce656fafc7f
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
  34:        0x1047517dc - std::sys::backtrace::__rust_begin_short_backtrace::h962fdbc46d670274
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:154:18
  35:        0x1047515b4 - std::rt::lang_start::{{closure}}::h7ef39edc085c8328
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:164:18
  36:        0x1048dd8dc - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hf77a1752ba39c45f
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:284:13
  37:        0x1048dd8dc - std::panicking::try::do_call::hf02556a6b145ecfc
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  38:        0x1048dd8dc - std::panicking::try::h2bb23dba91be7e3b
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  39:        0x1048dd8dc - std::panic::catch_unwind::h1844bc6507215052
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  40:        0x1048dd8dc - std::rt::lang_start_internal::{{closure}}::ha90e2c319598814e
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:143:48
  41:        0x1048dd8dc - std::panicking::try::do_call::h7de69f625a47132a
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  42:        0x1048dd8dc - std::panicking::try::h2198f44c68c232f7
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  43:        0x1048dd8dc - std::panic::catch_unwind::h40a34eeb64f44ac6
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  44:        0x1048dd8dc - std::rt::lang_start_internal::h9e88109c8deb8787
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:143:20
  45:        0x104751580 - std::rt::lang_start::h172685bf2879c1a3
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:163:17
  46:        0x104751524 - _main
thread caused non-unwinding panic. aborting.
[1]    55179 abort      RUST_BACKTRACE=full cargo run

@IceTDrinker
Copy link
Member

ok looks like something goes wrong when the engine gets populated 🧐

@IceTDrinker
Copy link
Member

@amaury1093 could you run the same please with the full backtrace ?

@IceTDrinker
Copy link
Member

@peitalin do you have the Done. print in your terminal ?

@amaury1093
Copy link
Author

➜  tfhe-rs-panic git:(main) RUST_BACKTRACE=full cargo run 
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/tfhe-rs-panic`
Done.
thread '<unnamed>' panicked at library/core/src/panicking.rs:220:5:
unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null
stack backtrace:
   0:        0x1041e300c - std::backtrace_rs::backtrace::libunwind::trace::he4f0a5f56afe8e37
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:        0x1041e300c - std::backtrace_rs::backtrace::trace_unsynchronized::habb302958e80f800
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1041e300c - std::sys_common::backtrace::_print_fmt::h9819d35e2a5cda77
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:68:5
   3:        0x1041e300c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1f3776e0b5c7517d
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x1041f92b8 - core::fmt::rt::Argument::fmt::h626862aa6242248a
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/fmt/rt.rs:165:63
   5:        0x1041f92b8 - core::fmt::write::heedef092c8c0962e
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/fmt/mod.rs:1157:21
   6:        0x1041e1130 - std::io::Write::write_fmt::h7178e8e2ea928914
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/io/mod.rs:1832:15
   7:        0x1041e2e64 - std::sys_common::backtrace::_print::ha0f584bc7bfb9d2b
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:47:5
   8:        0x1041e2e64 - std::sys_common::backtrace::print::h417292deb95532ed
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:34:9
   9:        0x1041e3fc0 - std::panicking::default_hook::{{closure}}::h0cb68f1228c4613a
  10:        0x1041e3cb4 - std::panicking::default_hook::h24535936bc1f51de
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:298:9
  11:        0x1041e4878 - std::panicking::rust_panic_with_hook::h5db4d2345b297bed
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:795:13
  12:        0x1041e427c - std::panicking::begin_panic_handler::{{closure}}::h3fd558f09a0d5492
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:656:13
  13:        0x1041e3494 - std::sys_common::backtrace::__rust_end_short_backtrace::hfc76eebe1ce501b2
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:171:18
  14:        0x1041e4018 - rust_begin_unwind
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
  15:        0x104203dd8 - core::panicking::panic_nounwind_fmt::runtime::h6aaba2885d9c2d14
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:110:18
  16:        0x104203dd8 - core::panicking::panic_nounwind_fmt::hcce2987b0dd42723
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:120:5
  17:        0x104203e50 - core::panicking::panic_nounwind::h355f878b46c24ec3
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:220:5
  18:        0x104091760 - core::ptr::replace::precondition_check::h07c4fab5673693ef
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:66:21
  19:        0x10406542c - core::ptr::replace::h927ff1f60d283a7b
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:73:17
  20:        0x10406542c - core::ptr::mut_ptr::<impl *mut T>::replace::hf01dccd12e24412b
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ptr/mut_ptr.rs:1560:18
  21:        0x10406542c - std::sys::thread_local::lazy::LazyKeyInner<T>::take::h7641a298d7d406fe
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/mod.rs:102:30
  22:        0x1040798d8 - std::sys::thread_local::fast_local::destroy_value::{{closure}}::hf2b5445c2cedce5d
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/fast_local.rs:241:21
  23:        0x104093ca0 - core::ops::function::FnOnce::call_once::ha895a6b3b661311a
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
  24:        0x1040911d4 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::ha531ccb0b9808345
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panic/unwind_safe.rs:272:9
  25:        0x104041034 - std::panicking::try::do_call::h4c4497f29c71fb06
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:559:40
  26:        0x1040424a8 - ___rust_try
  27:        0x10403fe44 - std::panicking::try::h0061f1a7fa70363f
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:523:19
  28:        0x104079784 - std::panic::catch_unwind::h81342db0e71db322
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panic.rs:149:14
  29:        0x104079784 - std::sys::thread_local::fast_local::destroy_value::h18eacd8b6b2bb2b5
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/fast_local.rs:239:21
  30:        0x1041e6cdc - std::sys::pal::unix::thread_local_dtor::register_dtor::run_dtors::h1fa3585f7318df66
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/pal/unix/thread_local_dtor.rs:114:17
thread caused non-unwinding panic. aborting.
[1]    21629 abort      RUST_BACKTRACE=full cargo run

@IceTDrinker
Copy link
Member

interesting you both have issues with thread locals, but not at the same point in the code

@IceTDrinker IceTDrinker added bug Something isn't working dependencies Pull requests that update a dependency file and removed triage_required labels Oct 22, 2024
@IceTDrinker
Copy link
Member

IceTDrinker commented Oct 22, 2024

for now triaging as a bug in a dep/build tool, asked on Zulip to see if some rust experts may know what's going on here

https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/Weird.20crash.20using.20thread.20locals.20Apple.20Silicon.20debug

@saethlin
Copy link

Can anyone who is able to provoke a crash run the program in gdb and show the backtrace in lldb? I think that will print the arguments to core::ptr::replace::precondition_check which should be enlightening. (I've tried to make this happen automatically but doing so without a lot of compile-time overhead to debug builds is tricky)

Something like lldb target/debug/tfhe-rs-panic then the lldb command run then the program should crash (hopefully) then run thread backtrace. If that doesn't contain the arguments, switching to the frame for replace::precondition_check and printing the arguments should work. I use https://lldb.llvm.org/use/map.html any time I have to use lldb, it might be a good reference for you.

@peitalin
Copy link

peitalin commented Oct 22, 2024

Hello, I've run rust-lldb target/debug/tfhe-rs-panic then run which produces the output:

> $ rust-lldb ./target/debug/tfhe-rs-panic
(lldb) command script import "/Users/peita/.rustup/toolchains/1.82-aarch64-apple-darwin/lib/rustlib/etc/lldb_lookup.py"
(lldb) command source -s 0 '/Users/peita/.rustup/toolchains/1.82-aarch64-apple-darwin/lib/rustlib/etc/lldb_commands'
Executing commands in '/Users/peita/.rustup/toolchains/1.82-aarch64-apple-darwin/lib/rustlib/etc/lldb_commands'.
(lldb) type synthetic add -l lldb_lookup.synthetic_lookup -x ".*" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^&(mut )?str$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^&(mut )?\\[.+\\]$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)NonZero<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::([a-z_]+::)+)PathBuf$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^&(mut )?(std::([a-z_]+::)+)Path$" --category Rust
(lldb) type category enable Rust
(lldb) target create "./target/debug/tfhe-rs-panic"
Current executable set to '/Users/peita/Dev/eth/tfhe-rs-panic/target/debug/tfhe-rs-panic' (arm64).
(lldb) run
Process 66387 launched: '/Users/peita/Dev/eth/tfhe-rs-panic/target/debug/tfhe-rs-panic' (arm64)
thread 'main' panicked at core/src/panicking.rs:221:5:
unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Process 66387 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x000000019d244764 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
->  0x19d244764 <+8>:  b.lo   0x19d244784               ; <+40>
    0x19d244768 <+12>: pacibsp
    0x19d24476c <+16>: stp    x29, x30, [sp, #-0x10]!
    0x19d244770 <+20>: mov    x29, sp
Target 0: (tfhe-rs-panic) stopped.
(lldb)

Then running thread backtrace command gives me this output:

(lldb) thread backtrace
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x000000019d244764 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x000000019d27bc28 libsystem_pthread.dylib`pthread_kill + 288
    frame #2: 0x000000019d189ae8 libsystem_c.dylib`abort + 180
    frame #3: 0x0000000100196110 tfhe-rs-panic`std::sys::pal::unix::abort_internal::h6d5bab7b9bc17708 at mod.rs:372:14 [opt]
    frame #4: 0x0000000100194138 tfhe-rs-panic`std::panicking::rust_panic_with_hook::h6a84efe4dcab239c at panicking.rs:819:9 [opt]
    frame #5: 0x0000000100193a44 tfhe-rs-panic`std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::h5eef292190467fef at panicking.rs:664:13 [opt]
    frame #6: 0x000000010019290c tfhe-rs-panic`std::sys::backtrace::__rust_end_short_backtrace::hd7e7925203f20af9 at backtrace.rs:170:18 [opt]
    frame #7: 0x0000000100193734 tfhe-rs-panic`rust_begin_unwind at panicking.rs:662:5 [opt]
    frame #8: 0x00000001001b16b4 tfhe-rs-panic`core::panicking::panic_nounwind_fmt::hb2df5b6c3d6ab15b [inlined] core::panicking::panic_nounwind_fmt::runtime::hed7cc75ebcf8d970 at panicking.rs:112:18 [opt]
    frame #9: 0x00000001001b1690 tfhe-rs-panic`core::panicking::panic_nounwind_fmt::hb2df5b6c3d6ab15b at panicking.rs:122:5 [opt]
    frame #10: 0x00000001001b172c tfhe-rs-panic`core::panicking::panic_nounwind::h6b53a509f430e184 at panicking.rs:221:5 [opt]
    frame #11: 0x0000000100056320 tfhe-rs-panic`core::ptr::replace::precondition_check::h1bd35d259ed51a2b(addr=0x000000010080aa28, align=16) at ub_checks.rs:70:21
    frame #12: 0x00000001001acb74 tfhe-rs-panic`std::sys::thread_local::native::lazy::Storage$LT$T$C$D$GT$::initialize::hc0fccca2ed668ade [inlined] core::ptr::replace::h5b3649167c19b0f3(dst=0x000000010080aa28, src=State<core::cell::RefCell<tfhe::shortint::engine::ShortintEngine>, ()> @ 0x000000016fdfabd0) at ub_checks.rs:77:17
    frame #13: 0x00000001001acb60 tfhe-rs-panic`std::sys::thread_local::native::lazy::Storage$LT$T$C$D$GT$::initialize::hc0fccca2ed668ade [inlined] core::ptr::mut_ptr::_$LT$impl$u20$$BP$mut$u20$T$GT$::replace::hf06eb7f019c3e148(self=0x000000010080aa28, src=State<core::cell::RefCell<tfhe::shortint::engine::ShortintEngine>, ()> @ 0x000000016fdfabd0) at mut_ptr.rs:1462:18
    frame #14: 0x00000001001acb60 tfhe-rs-panic`std::sys::thread_local::native::lazy::Storage$LT$T$C$D$GT$::initialize::hc0fccca2ed668ade(self=0x000000010080aa28, i=Option<&mut core::option::Option<core::cell::RefCell<tfhe::shortint::engine::ShortintEngine>>> @ 0x000000016fdfa060, f=0xffff000000000000) at lazy.rs:66:45
    frame #15: 0x000000010001f440 tfhe-rs-panic`std::sys::thread_local::native::lazy::Storage$LT$T$C$D$GT$::get_or_init::h4f915c22fb65e1a5(self=0x000000010080aa28, i=Option<&mut core::option::Option<core::cell::RefCell<tfhe::shortint::engine::ShortintEngine>>> @ 0x000000016fdfbf98, f=0x0000010080aa283f) at lazy.rs:56:40
    frame #16: 0x00000001000450b4 tfhe-rs-panic`tfhe::shortint::engine::LOCAL_ENGINE::_$u7b$$u7b$constant$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hccbcfa60c4426273((null)=0x000000016fdfc017, init=Option<&mut core::option::Option<core::cell::RefCell<tfhe::shortint::engine::ShortintEngine>>> @ 0x000000016fdfbfe8) at mod.rs:93:25
    frame #17: 0x000000010002051c tfhe-rs-panic`core::ops::function::FnOnce::call_once::hf38e54a44dbe3ccb((null)={closure_env#0} @ 0x000000016fdfc017, (null)=(core::option::Option<&mut core::option::Option<core::cell::RefCell<tfhe::shortint::engine::ShortintEngine>>>) @ 0x000000016fdfc018) at function.rs:250:5
    frame #18: 0x0000000100007a14 tfhe-rs-panic`std::thread::local::LocalKey$LT$T$GT$::try_with::h792ef6ee3f51bce3(self=0x0000000100233508, f=<unavailable>) at local.rs:282:37
    frame #19: 0x0000000100006d04 tfhe-rs-panic`std::thread::local::LocalKey$LT$T$GT$::with::h133aea6667b2688c(self=0x0000000100233508, f=<unavailable>) at local.rs:260:9
    frame #20: 0x0000000100042290 tfhe-rs-panic`tfhe::shortint::engine::ShortintEngine::with_thread_local_mut::h4f79fd93d65b80ef(func=<unavailable>) at mod.rs:300:9
    frame #21: 0x0000000100041554 tfhe-rs-panic`tfhe::shortint::client_key::ClientKey::new::h616c6b3a1f53d9de(parameters=<unavailable>) at mod.rs:67:9
    frame #22: 0x00000001000413cc tfhe-rs-panic`tfhe::integer::client_key::ClientKey::new::ha3bbfe9138206075(parameter_set=<unavailable>) at mod.rs:148:18
    frame #23: 0x0000000100048240 tfhe-rs-panic`_$LT$tfhe..high_level_api..keys..inner..IntegerClientKey$u20$as$u20$core..convert..From$LT$tfhe..high_level_api..keys..inner..IntegerConfig$GT$$GT$::from::h3e9e2c535bdea7fe(config=IntegerConfig @ 0x000000016fdfd560) at inner.rs:193:19
    frame #24: 0x0000000100001758 tfhe-rs-panic`tfhe::high_level_api::keys::client::ClientKey::generate::hcd9836800ab95d0f(config=<unavailable>) at client.rs:35:18
    frame #25: 0x00000001000013e8 tfhe-rs-panic`tfhe::high_level_api::keys::generate_keys::hcd7d7dd005cd0dda(config=<unavailable>) at mod.rs:34:21
    frame #26: 0x00000001000014cc tfhe-rs-panic`tfhe_rs_panic::main::h514cc79dfde30c55 at main.rs:5:13
    frame #27: 0x000000010000165c tfhe-rs-panic`core::ops::function::FnOnce::call_once::h77f60ce656fafc7f((null)=(tfhe-rs-panic`tfhe_rs_panic::main::h514cc79dfde30c55 at main.rs:3), (null)=<unavailable>) at function.rs:250:5
    frame #28: 0x00000001000017dc tfhe-rs-panic`std::sys::backtrace::__rust_begin_short_backtrace::h962fdbc46d670274(f=(tfhe-rs-panic`tfhe_rs_panic::main::h514cc79dfde30c55 at main.rs:3)) at backtrace.rs:154:18
    frame #29: 0x00000001000015b4 tfhe-rs-panic`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h7ef39edc085c8328 at rt.rs:164:18
    frame #30: 0x000000010018d8dc tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] core::ops::function::impls::_$LT$impl$u20$core..ops..function..FnOnce$LT$A$GT$$u20$for$u20$$RF$F$GT$::call_once::hf77a1752ba39c45f at function.rs:284:13 [opt]
    frame #31: 0x000000010018d8d4 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] std::panicking::try::do_call::hf02556a6b145ecfc at panicking.rs:554:40 [opt]
    frame #32: 0x000000010018d8d0 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] std::panicking::try::h2bb23dba91be7e3b at panicking.rs:518:19 [opt]
    frame #33: 0x000000010018d8d0 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] std::panic::catch_unwind::h1844bc6507215052 at panic.rs:345:14 [opt]
    frame #34: 0x000000010018d8d0 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] std::rt::lang_start_internal::_$u7b$$u7b$closure$u7d$$u7d$::ha90e2c319598814e at rt.rs:143:48 [opt]
    frame #35: 0x000000010018d8d0 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] std::panicking::try::do_call::h7de69f625a47132a at panicking.rs:554:40 [opt]
    frame #36: 0x000000010018d8d0 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] std::panicking::try::h2198f44c68c232f7 at panicking.rs:518:19 [opt]
    frame #37: 0x000000010018d8d0 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 [inlined] std::panic::catch_unwind::h40a34eeb64f44ac6 at panic.rs:345:14 [opt]
    frame #38: 0x000000010018d8d0 tfhe-rs-panic`std::rt::lang_start_internal::h9e88109c8deb8787 at rt.rs:143:20 [opt]
    frame #39: 0x0000000100001580 tfhe-rs-panic`std::rt::lang_start::h172685bf2879c1a3(main=(tfhe-rs-panic`tfhe_rs_panic::main::h514cc79dfde30c55 at main.rs:3), argc=1, argv=0x000000016fdfea38, sigpipe='\0') at rt.rs:163:17
    frame #40: 0x0000000100001524 tfhe-rs-panic`main + 36
    frame #41: 0x000000019cf23f28 dyld`start + 2236
(lldb)

@IceTDrinker
Copy link
Member

Looks like the check expects a 16 bytes alignement but gets a pointer with insufficient alignment with only an alignment of 8 bytes

@saethlin
Copy link

Can someone who is running into the crash try running this program?

#[repr(align(16))]
struct VeryAligned {
    _data: [u8; 16],
}
thread_local! {
    static LOCAL: VeryAligned = VeryAligned { _data: [0u8; 16] };
}
fn main() {
    LOCAL.with(|local| println!("{:?}", local as *const VeryAligned));
}

If the problem is just insufficiently-aligned thread-locals, this should make it clear that's what is happening.

In addition, can someone who is seeing the crash try to reproduce the crash on beta (1.83.0) and nightly?

@peitalin
Copy link

peitalin commented Oct 23, 2024

Running the above program @saethlin posted on rustc 1.82.0 produces:

$ rustc -V; RUST_BACKTRACE=full cargo run
rustc 1.82.0 (f6e511eec 2024-10-15)
   Compiling tfhe-rs-panic v0.1.0 (/Users/peita/Dev/eth/tfhe-rs-panic)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.40s
     Running `target/debug/tfhe-rs-panic`
thread 'main' panicked at core/src/panicking.rs:221:5:
unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null
stack backtrace:
   0:        0x1026113fc - std::backtrace_rs::backtrace::libunwind::trace::h1c3451b342542f10
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:        0x1026113fc - std::backtrace_rs::backtrace::trace_unsynchronized::h3743cad8cc2d54de
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1026113fc - std::sys::backtrace::_print_fmt::h31ad576fee12d4ee
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:66:9
   3:        0x1026113fc - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::habbf9c4f641febb1
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:39:26
   4:        0x102624f54 - core::fmt::rt::Argument::fmt::h54965d9b1ee82264
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/fmt/rt.rs:177:76
   5:        0x102624f54 - core::fmt::write::ha36a8060c13608ea
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/fmt/mod.rs:1178:21
   6:        0x10260f6dc - std::io::Write::write_fmt::h431832c8ebcc85c9
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/io/mod.rs:1823:15
   7:        0x1026124e8 - std::sys::backtrace::BacktraceLock::print::hd085ca0c3911e184
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:42:9
   8:        0x1026124e8 - std::panicking::default_hook::{{closure}}::h4aa1f60327dfff6a
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:266:22
   9:        0x102612098 - std::panicking::default_hook::h4ebc6eb4ae179807
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:293:9
  10:        0x102612eb4 - std::panicking::rust_panic_with_hook::h6a84efe4dcab239c
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:797:13
  11:        0x102612968 - std::panicking::begin_panic_handler::{{closure}}::h5eef292190467fef
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:664:13
  12:        0x1026118c0 - std::sys::backtrace::__rust_end_short_backtrace::hd7e7925203f20af9
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:170:18
  13:        0x102612658 - rust_begin_unwind
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:662:5
  14:        0x102629fa0 - core::panicking::panic_nounwind_fmt::runtime::hed7cc75ebcf8d970
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:112:18
  15:        0x102629fa0 - core::panicking::panic_nounwind_fmt::hb2df5b6c3d6ab15b
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:122:5
  16:        0x10262a018 - core::panicking::panic_nounwind::h6b53a509f430e184
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:221:5
  17:        0x1025f4cbc - core::ptr::replace::precondition_check::hfe05ec4e5341b076
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ub_checks.rs:70:21
  18:        0x102629008 - core::ptr::replace::hb08ce27f312ab429
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ub_checks.rs:77:17
  19:        0x102629008 - core::ptr::mut_ptr::<impl *mut T>::replace::h01c1601a0fbc59fe
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ptr/mut_ptr.rs:1462:18
  20:        0x102629008 - std::sys::thread_local::native::lazy::Storage<T,D>::initialize::he936653a2a4c02ab
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/thread_local/native/lazy.rs:66:45
  21:        0x1025f4b94 - std::sys::thread_local::native::lazy::Storage<T,D>::get_or_init::h9b976f0eb37b332f
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/thread_local/native/lazy.rs:56:40
  22:        0x1025f486c - tfhe_rs_panic::LOCAL::{{constant}}::{{closure}}::he9110d99c68aafe6
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/thread_local/native/mod.rs:99:25
  23:        0x1025f4a90 - core::ops::function::FnOnce::call_once::hd267988f5cf8c322
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
  24:        0x1025f46e0 - std::thread::local::LocalKey<T>::try_with::ha3985e6791eb3b67
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/local.rs:282:37
  25:        0x1025f4690 - std::thread::local::LocalKey<T>::with::h07b610e6f338a4de
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/local.rs:260:9
  26:        0x1025f48a8 - tfhe_rs_panic::main::h514cc79dfde30c55
                               at /Users/peita/Dev/eth/tfhe-rs-panic/src/main.rs:18:5
  27:        0x1025f4a68 - core::ops::function::FnOnce::call_once::h77f60ce656fafc7f
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
  28:        0x1025f4d50 - std::sys::backtrace::__rust_begin_short_backtrace::h962fdbc46d670274
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:154:18
  29:        0x1025f4980 - std::rt::lang_start::{{closure}}::h7ef39edc085c8328
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:164:18
  30:        0x10260d228 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hf77a1752ba39c45f
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:284:13
  31:        0x10260d228 - std::panicking::try::do_call::hf02556a6b145ecfc
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  32:        0x10260d228 - std::panicking::try::h2bb23dba91be7e3b
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  33:        0x10260d228 - std::panic::catch_unwind::h1844bc6507215052
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  34:        0x10260d228 - std::rt::lang_start_internal::{{closure}}::ha90e2c319598814e
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:143:48
  35:        0x10260d228 - std::panicking::try::do_call::h7de69f625a47132a
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  36:        0x10260d228 - std::panicking::try::h2198f44c68c232f7
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  37:        0x10260d228 - std::panic::catch_unwind::h40a34eeb64f44ac6
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  38:        0x10260d228 - std::rt::lang_start_internal::h9e88109c8deb8787
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:143:20
  39:        0x1025f494c - std::rt::lang_start::h172685bf2879c1a3
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:163:17
  40:        0x1025f48f0 - _main
thread caused non-unwinding panic. aborting.
[1]    88539 abort      RUST_BACKTRACE=full cargo run

Running the program on 1.83.0-beta.2 and 1.84.0-nightly prints the pointers without error:

$ rustc -V; cargo run
rustc 1.83.0-beta.2 (88c1c3c11 2024-10-18)
   Compiling tfhe-rs-panic v0.1.0 (/Users/peita/Dev/eth/tfhe-rs-panic)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.44s
     Running `target/debug/tfhe-rs-panic`
0x600000070030
$ rustc -V; cargo run
rustc 1.84.0-nightly (86d69c705 2024-10-22)
    Blocking waiting for file lock on build directory
   Compiling tfhe-rs-panic v0.1.0 (/Users/peita/Dev/eth/tfhe-rs-panic)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.98s
     Running `target/debug/tfhe-rs-panic`
0x6000035c8030

@IceTDrinker
Copy link
Member

Alright, then I guess it’s a matter of the patch hitting stable which should be in 1.83 at the latest, will keep this open until it’s released and update the title of the issue

@IceTDrinker IceTDrinker changed the title Panic at program execution end with tfhe::generate_keys Panic at program execution end with tfhe::generate_keys before rust 1.83 Oct 23, 2024
@IceTDrinker
Copy link
Member

@amaury1093 and @peitalin could you try to repro with rust 1.83 ?

Normally this has been fixed on the rustc side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

4 participants