Skip to content

rustc from homebrew produces SIGBUS: access to undefined memory when -v is provided #125350

@DrGo

Description

@DrGo

I tried this code:

use std::path::{Path,PathBuf};
use std::{env,fs}; 

//TODO
// read src folder into a vec
// convert to typst
// compile to pdf

fn main() ->Result<(), AppError>{
   println!("Hello, world!");
    Ok(())
}

cargo build -v

I expected to see this happen: explanation
code checked and compiled

Instead, this happened: explanation
crash only when -v is provided

Caused by:
  process didn't exit successfully: `CARGO=/opt/homebrew/Cellar/rust/1.78.0/bin/cargo CARGO_BIN_NAME=rst CARGO_CRATE_NAME=rst CARGO_MANIFEST_DIR=/Users/drgo/local/code/booker/rs CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=rst CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 DYLD_FALLBACK_LIBRARY_PATH='/Users/drgo/local/code/booker/rs/target/debug/deps:/Users/drgo/lib:/usr/local/lib:/usr/lib' rustc --crate-name rst --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=98 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=a4aaf64bcde3c91c -C extra-filename=-a4aaf64bcde3c91c --out-dir /Users/drgo/local/code/booker/rs/target/debug/deps -C incremental=/Users/drgo/local/code/booker/rs/target/debug/incremental -L dependency=/Users/drgo/local/code/booker/rs/target/debug/deps` (exit status: 1)

Meta

rustc --version --verbose:

ustc 1.78.0 (9b00956e5 2024-04-29) (Homebrew)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.4
Backtrace

backtrace is not produced probably because of the crash

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 21, 2024
DrGo

DrGo commented on May 21, 2024

@DrGo
Author

Actually the compiler now crashes even when the -v is not provided with the following code

use std::path::{Path,PathBuf};
use std::{env,fs}; 

//TODO
// read src folder into a vec
// convert to typst
// compile to pdf

fn main() ->Result<(), AppError>{
    println!("Hello, world!");
    Ok(())
}

#[derive(Debug, Clone, PartialEq)]
struct File {
    path: PathBuf,
    content: String,
}

#[derive(Debug, Clone, PartialEq)]
struct Book {
    files: Vec<File>,
}

impl Book {
    fn load_book(Self, dir : AsRef<Path>) -> Result<(), Error> {
   }
}

the crashing stops and errors are reported as expected when I add `dyn' in the function definition

  fn load_book(Self, dir : dyn AsRef<Path>) -> Result<(), Error> {
workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

How... odd. If you are using rustc via Homebrew, please try installing the Rust toolchain via https://rustup.rs instead and letting us know if this replicates?

DrGo

DrGo commented on May 21, 2024

@DrGo
Author

Yes.. very odd,
I removed the Homebrew version and reinstalled using the rustup script.
Now the compiler crashes only if I add the -v option but does not report the cause of the crash

Caused by:
  process didn't exit successfully: `/Users/drgo/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name rst --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=98 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=972ad4c1b6c71082 -C extra-filename=-972ad4c1b6c71082 --out-dir /Users/drgo/local/code/booker/rs/target/debug/deps -C incremental=/Users/drgo/local/code/booker/rs/target/debug/incremental -L dependency=/Users/drgo/local/code/booker/rs/target/debug/deps` (exit status: 1)
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2
workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

...that is incredibly fucky.

workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

And this reproduces with the nightly compiler too, right?

workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

Ah, I mean the one you can get by trying rustup default nightly.

DrGo

DrGo commented on May 21, 2024

@DrGo
Author

forgot to enable nightly..
yes, it occurs with nightly too. only with the -v option

rustc 1.80.0-nightly (b92758a9a 2024-05-20)
binary: rustc
commit-hash: b92758a9aef1cef7b79e2b72c3d8ba113e547f89
commit-date: 2024-05-20
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
added
O-macosOperating system: macOS
O-AArch64Armv8-A or later processors in AArch64 mode
and removed
O-macosOperating system: macOS
O-AArch64Armv8-A or later processors in AArch64 mode
on May 21, 2024
workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

Huuuh, I can't get the "crash without -v" sample to repro.

For the other cases, I think this is just what Cargo does when you pass it -v. Normally it silences rustc failures which exit with 1, i.e. a "normal failure", but you asked it for verbose output, I guess?

workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

@DrGo As for why the code doesn't compile: you haven't defined the AppError type.

workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

The other errors you get on the later sample also have explanations. Have you acted on the error messages?

DrGo

DrGo commented on May 21, 2024

@DrGo
Author

I used -v when I noticed stable rustc crashing with the SIGBUS message.
What I shared was just an example code to trigger the crash.

workingjubilee

workingjubilee commented on May 21, 2024

@workingjubilee
Member

Hmm, a SIGBUS is indeed worrying...

DrGo

DrGo commented on May 21, 2024

@DrGo
Author

that was the Homebrew stable rustc.. I will just use the rustup version

saethlin

saethlin commented on May 21, 2024

@saethlin
Member

This whole issue is incredibly confused. I can't even tell what's being reported here.

I'm guessing that what we have is an example program which will cause the Rust toolchain distributed by homebrew to SIGBUS, but which does not cause the toolchain distributed by rustup to SIGBUS. Is that correct?

DrGo

DrGo commented on May 21, 2024

@DrGo
Author

Otherwise, I am happy with your explanation to the behaviour of cargo
Thanks

DrGo

DrGo commented on May 21, 2024

@DrGo
Author

yes... the error when the compiler crashed with the SIGBUS message was very similar to what cargo -v reports with when rustc can't compile code. The only difference was the brief SIGBUS part. That is very confusing for newbies like me.

removed
C-bugCategory: This is a bug.
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 21, 2024
saethlin

saethlin commented on May 21, 2024

@saethlin
Member

So there's not necessarily any bug here. The toolchain we distribute works correctly.

There have been problems in the past with strip implementations mangling librustc.so, it would not surprise me if something like that is happening in whatever process homebrew is using to deliver artifacts.

If I'm correct, this is a bug in homebrew.

added
C-discussionCategory: Discussion or questions that doesn't represent real issues.
on May 21, 2024
crescentrose

crescentrose commented on Jun 23, 2024

@crescentrose

I had this happen intermittently as well when running doc-tests, and indeed removing the Homebrew version and installing rustc directly via Rustup as @workingjubilee suggested fixed the issue. I'm not sure exactly what's going on in the Homebrew version but so far I am satisfied by just accepting they messed up somewhere.

changed the title [-]compiler SIGBUS: access to undefined memory when -v is provided[/-] [+]rustc from homebrew produces SIGBUS: access to undefined memory when -v is provided[/+] on Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @crescentrose@saethlin@DrGo@jieyouxu@workingjubilee

        Issue actions

          rustc from homebrew produces SIGBUS: access to undefined memory when -v is provided · Issue #125350 · rust-lang/rust