Cargo Seg Fault Mac M1

Hi - Looking for pointers on how to debug or RCA a problem getting started with Rust.

All cargo sub commands apart from help result in a segmentation fault message

zsh: segmentation fault cargo search

On Mac M1, and have installed rust using rustup, homebrew (and homebrew build-from-source). I've also tried with beta and nightlies.

I tried running under lldb to see more detail and get the following:

Process 83013 launched: '/opt/homebrew/bin/cargo' (arm64)
Process 83013 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000100581b00 cargo`git__prefixcmp + 8
cargo`git__prefixcmp:
->  0x100581b00 <+8>:  ldrb   w9, [x0], #0x1
    0x100581b04 <+12>: add    x1, x1, #0x1              ; =0x1
    0x100581b08 <+16>: subs   w8, w9, w8
    0x100581b0c <+20>: b.eq   0x100581af8               ; <+0>
Target 0: (cargo) stopped.

thread backtrace gives me

(lldb) thread backtrace
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000100581b00 cargo`git__prefixcmp + 8
    frame #1: 0x0000000100530324 cargo`read_on_variable + 480
    frame #2: 0x0000000100531d7c cargo`git_config_parse + 1672
    frame #3: 0x0000000100530138 cargo`config_file_read + 324
    frame #4: 0x000000010052f888 cargo`config_file_open + 112
    frame #5: 0x000000010052c004 cargo`git_config_add_backend + 84
    frame #6: 0x000000010052bf2c cargo`git_config_add_file_ondisk + 144
    frame #7: 0x000000010057365c cargo`git_repository_config__weakptr + 352
    frame #8: 0x0000000100572a48 cargo`git_repository_open_ext + 1684
    frame #9: 0x000000010029c458 cargo`git2::repo::Repository::open::hbdc179d879d1961e + 120
    frame #10: 0x00000001001b4680 cargo`lazycell::LazyCell$LT$T$GT$::try_borrow_with::h063147125107e4be + 136
    frame #11: 0x000000010036fa70 cargo`_$LT$cargo..sources..registry..remote..RemoteRegistry$u20$as$u20$cargo..sources..registry..RegistryData$GT$::config::h42cc70d185dfeb46 + 116
    frame #12: 0x00000001003f10d0 cargo`cargo::ops::registry::registry::hf7d3d22240a32d17 + 1764
    frame #13: 0x00000001003f502c cargo`cargo::ops::registry::search::hae839b58d1729923 + 120
    frame #14: 0x00000001000229c8 cargo`cargo::commands::search::exec::h422d0b12d881581a + 628
    frame #15: 0x000000010003e0fc cargo`cargo::cli::main::h5df27e9a7c692d67 + 7796
    frame #16: 0x0000000100063c14 cargo`cargo::main::h2fdd93a263f932be + 536
    frame #17: 0x0000000100032a24 cargo`std::sys_common::backtrace::__rust_begin_short_backtrace::hea7c66efbfa0f355 + 12
    frame #18: 0x000000010005c2b0 cargo`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hfcb1279ca91e0e16 + 16
    frame #19: 0x0000000100659ad4 cargo`std::rt::lang_start_internal::ha631af460ec1a0f3 + 52
    frame #20: 0x000000010006588c cargo`main + 48
    frame #21: 0x0000000100b890f4 dyld`start + 520

What else can I try to try to identify the problem? Other components like rustc seem to be fine.

  • cargo 1.56.0
  • rustc 1.56.1
  • macOS Monterey 12.1 Apple M1

Thanks

Seems like the problem is related to git somehow. Does it only happen in a particular git repository?

2 Likes

Thanks @alice

Rechecking the include syntax in .gitconfig I needed to provide a specific path match for the includeif.

from >>

[include]
    path = ~/git-a.conf

[includeif]
    path = ~/git-b.conf

to:

[include]
    path = ~/git-a.conf

[includeif "gitdir:~/b/"]
    path = ~/git-b.conf

Does cargo output to stderr or similar - where I would have seen a more human readable error?

Thanks

I mean, cargo is certainly not supposed to segfault. It would make sense to report it as a bug, especially if you're figured out what caused it.

1 Like

Thanks. Reported #10247.

2 Likes