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

SIGSEGV when std::time::Instant::now() called #125290

Open
sunny0531 opened this issue May 19, 2024 · 7 comments
Open

SIGSEGV when std::time::Instant::now() called #125290

sunny0531 opened this issue May 19, 2024 · 7 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. O-NixOS Operating system: NixOS, https://nixos.org/

Comments

@sunny0531
Copy link

sunny0531 commented May 19, 2024

I tried this code:

fn main() {
    let now=std::time::Instant::now();
    println!("{:#?}",now);
}

Then it crashed with signal SIGSEGV
signal SIGSEGV: address not mapped to object (fault address: 0x680)

Meta

Unstable channel Nix
rustc --version --verbose:

rustc 1.77.2 (25ef9e3d8 2024-04-09) (built from a source tarball)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6
@sunny0531 sunny0531 added the C-bug Category: This is a bug. label May 19, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 19, 2024
@tbu-
Copy link
Contributor

tbu- commented May 19, 2024

Do you have a stack trace?

@Nilstrieb
Copy link
Member

I have no problems with my nixos-unstable. Have you built this executable before doing an update and it segfaults now after the update? That happens sometimes with nix and isn't a bug in rust

@workingjubilee
Copy link
Contributor

workingjubilee commented May 20, 2024

Please retry with RUST_BACKTRACE=1? Or maybe try using gdb on the core dump...

@jieyouxu jieyouxu added the S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. label May 22, 2024
@saethlin saethlin added O-NixOS Operating system: NixOS, https://nixos.org/ C-discussion Category: Discussion or questions that doesn't represent real issues. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-bug Category: This is a bug. S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. labels May 24, 2024
@sunny0531
Copy link
Author

My apologies for the late reply, but I ran the code with lldb, here's the trace:

Process 985 launched: '/home/user/test/target/debug/app' (x86_64)
Process 985 stopped
* thread #1, name = 'app', stop reason = signal SIGSEGV: address not mapped to object (fault address: 0x680)
    frame #0: 0x0000000000000680
error: memory read failed for 0x600

@sunny0531 sunny0531 reopened this Jun 4, 2024
@sunny0531
Copy link
Author

Here's the stack trace with GDB

Temporary breakpoint 1 at 0x8d37: file src/main.rs, line 2.
Starting program: /home/user/test/target/debug/app 
warning: File "/nix/store/p9ysh5rk109gyjj3cn6jr54znvvlahfl-glibc-2.38-66/lib/libthread_db.so.1" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load:/nix/store/xvzz97yk73hw03v5dhhz3j47ggwf1yq1-gcc-13.2.0-lib".
To enable execution of this file add
        add-auto-load-safe-path /nix/store/p9ysh5rk109gyjj3cn6jr54znvvlahfl-glibc-2.38-66/lib/libthread_db.so.1
line to your configuration file "/home/user/.config/gdb/gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "/home/user/.config/gdb/gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.

Temporary breakpoint 1, app::main () at src/main.rs:2
2           let now=std::time::Instant::now();

@Nilstrieb I've never build rust from scratch, so I don't think that is the cause of the issue. I do suppose it might be glibc bug.
When I run the code with VSCode debugger
Debugger report crash at 7FFFF7E88A6D

; Symbol: clock_gettime@@GLIBC_2.17
; Source: unknown
7FFFF7E88A50: F3 0F 1E FA                endbr64 
7FFFF7E88A54: 48 8B 05 6D 74 10 00       movq   0x10746d(%rip), %rax
7FFFF7E88A5B: 48 8B 80 E8 02 00 00       movq   0x2e8(%rax), %rax
7FFFF7E88A62: 48 85 C0                   testq  %rax, %rax
7FFFF7E88A65: 74 19                      je     0x7ffff7e88a80  ; <+48>
7FFFF7E88A67: 48 83 EC 08                subq   $0x8, %rsp
7FFFF7E88A6B: FF D0                      callq  *%rax
7FFFF7E88A6D: 85 C0                      testl  %eax, %eax
7FFFF7E88A6F: 75 1F                      jne    0x7ffff7e88a90  ; <+64>
7FFFF7E88A71: 31 C0                      xorl   %eax, %eax
7FFFF7E88A73: 48 83 C4 08                addq   $0x8, %rsp
7FFFF7E88A77: C3                         retq   
7FFFF7E88A78: 0F 1F 84 00 00 00 00 00    nopl   (%rax,%rax)
7FFFF7E88A80: B8 E4 00 00 00             movl   $0xe4, %eax
7FFFF7E88A85: 0F 05                      syscall 
7FFFF7E88A87: 85 C0                      testl  %eax, %eax
7FFFF7E88A89: 75 1D                      jne    0x7ffff7e88aa8  ; <+88>
7FFFF7E88A8B: 31 C0                      xorl   %eax, %eax
7FFFF7E88A8D: C3                         retq   
7FFFF7E88A8E: 66 90                      nop    
7FFFF7E88A90: 48 8B 15 79 73 10 00       movq   0x107379(%rip), %rdx
7FFFF7E88A97: F7 D8                      negl   %eax
7FFFF7E88A99: 64 89 02                   movl   %eax, %fs:(%rdx)
7FFFF7E88A9C: B8 FF FF FF FF             movl   $0xffffffff, %eax  ; imm = 0xFFFFFFFF 
7FFFF7E88AA1: EB D0                      jmp    0x7ffff7e88a73  ; <+35>
7FFFF7E88AA3: 0F 1F 44 00 00             nopl   (%rax,%rax)
7FFFF7E88AA8: 48 8B 15 61 73 10 00       movq   0x107361(%rip), %rdx
7FFFF7E88AAF: F7 D8                      negl   %eax
7FFFF7E88AB1: 64 89 02                   movl   %eax, %fs:(%rdx)
7FFFF7E88AB4: B8 FF FF FF FF             movl   $0xffffffff, %eax  ; imm = 0xFFFFFFFF 
7FFFF7E88AB9: C3                         retq   

@tbu-
Copy link
Contributor

tbu- commented Jun 4, 2024

You can get a stack trace by typing bt into the lldb shell.

@sunny0531
Copy link
Author

Here's the lldb stack trace

(lldb) bt
* thread #1, name = 'app', stop reason = signal SIGSEGV: address not mapped to object (fault address: 0x680)
  * frame #0: 0x0000000000000680
    frame #1: 0x00007ffff7e88a6d libc.so.6`clock_gettime@@GLIBC_2.17 + 29
    frame #2: 0x000055555556ef10 app`std::sys::pal::unix::time::Timespec::now::h838169f1ec536b22 + 16
    frame #3: 0x000055555555cd40 app`app::main::h2a93287a77889921 at main.rs:2:13
    frame #4: 0x000055555555cf7b app`core::ops::function::FnOnce::call_once::h4353ad6d8b831443((null)=(app`app::main::h2a93287a77889921 at main.rs:1), (null)=<unavailable>) at function.rs:250:5
    frame #5: 0x000055555555d06e app`std::sys_common::backtrace::__rust_begin_short_backtrace::h8861549560295d41(f=(app`app::main::h2a93287a77889921 at main.rs:1)) at backtrace.rs:155:18
    frame #6: 0x000055555555d041 app`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h182da1a740b462df at rt.rs:166:18
    frame #7: 0x000055555556df04 app`std::panicking::try::ha86251cf5daa9bea + 20
    frame #8: 0x0000555555563d1b app`std::rt::lang_start_internal::ha6a51778162f8d22 + 43
    frame #9: 0x000055555555d01a app`std::rt::lang_start::h6f376ca7566268e6(main=(app`app::main::h2a93287a77889921 at main.rs:1), argc=1, argv=0x00007fffffffdb98, sigpipe='\0') at rt.rs:165:17
    frame #10: 0x000055555555ceee app`main + 30
    frame #11: 0x00007ffff7dddfce libc.so.6`__libc_start_call_main + 126
    frame #12: 0x00007ffff7dde089 libc.so.6`__libc_start_main@@GLIBC_2.34 + 137
    frame #13: 0x000055555555cc65 app`_start + 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. O-NixOS Operating system: NixOS, https://nixos.org/
Projects
None yet
Development

No branches or pull requests

7 participants