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

Process Being Killed in Release Mode in MacOS Sequoia 15.0.1 on my M2 Mac #132068

Closed
bayedieng opened this issue Oct 23, 2024 · 5 comments
Closed
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bayedieng
Copy link

When attempting to run the very simple program in release mode below. I get the following error:
error: failed to run custom build command for `libc v0.2.161

use std::env;
use std::io::Write;

fn get_hostname() -> String {
    let mut hostname_buffer: [u8; 256] = [0; 256];
    unsafe {
        libc::gethostname(
            hostname_buffer.as_mut_ptr() as *mut i8,
            hostname_buffer.len(),
        )
    };
    String::from_utf8(hostname_buffer.to_vec()).unwrap()
}

fn main() {
    let mut input_string = String::with_capacity(1024);
    let computer_username = env!("USER");
    let computer_name = get_hostname();
    let (actual_name, _) = computer_name.split_once(".").unwrap();

    loop {
        print!("{computer_username}@{actual_name} > ");
        std::io::stdout().flush().unwrap();
        std::io::stdin().read_line(&mut input_string).unwrap();
        // removes new line character
        input_string.pop();
        println!("{input_string}");
        input_string.clear();
    }
}

When omitting libc from the dependency and run it just using the standard library I get the process being killed upon running in release mode:

zsh: killed cargo run --release

use std::env;
use std::io::Write;

//fn get_hostname() -> String {
//    let mut hostname_buffer: [u8; 256] = [0; 256];
//    unsafe {
//        libc::gethostname(
//            hostname_buffer.as_mut_ptr() as *mut i8,
//            hostname_buffer.len(),
//        )
//    };
//    String::from_utf8(hostname_buffer.to_vec()).unwrap()
//}

fn main() {
    let mut input_string = String::with_capacity(1024);
    let computer_username = env!("USER");
    //let computer_name = get_hostname();
    let (actual_name, _) = computer_name.split_once(".").unwrap();

    loop {
        //print!("{computer_username}@{actual_name} > ");
        std::io::stdout().flush().unwrap();
        std::io::stdin().read_line(&mut input_string).unwrap();
        // removes new line character
        input_string.pop();
        println!("{input_string}");
        input_string.clear();
    }
}

Note that both these programs work as intented in debug mode and even on release mode in nightly (tested on 2024-10-07).

Finally as a last example I'm getting a killed process from this program in release mode as well:

use std::collections::{BTreeMap, BTreeSet};

#[derive(Debug)]
struct Graph {
    pub adjacency_list: BTreeMap<char, BTreeSet<char>>,
}

impl Graph {
    pub fn new() -> Self {
        Self {
            adjacency_list: BTreeMap::new(),
        }
    }

    pub fn add_edge(&mut self, a: char, b: char) {
        self.adjacency_list
            .entry(a)
            .or_insert(BTreeSet::new())
            .insert(b);

        self.adjacency_list
            .entry(b)
            .or_insert(BTreeSet::new())
            .insert(a);
    }
}
fn main() {
    let mut graph = Graph::new();
    graph.add_edge('A', 'B');
    graph.add_edge('C', 'D');
    graph.add_edge('A', 'E');
    graph.add_edge('A', 'F');
    println!("{graph:?}");
}

This is occurring on rustc stable version 1.82 and also on the previous 1.81 version. I am using a base 16 inch m2 macbook pro running on MacOS Sequoia 15.0.1. I have tried reproducing the bug on my linux machine but the process being killed only occurs on my mac.

@bayedieng bayedieng added the C-bug Category: This is a bug. label Oct 23, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 23, 2024
@saethlin
Copy link
Member

I get the following error:
error: failed to run custom build command for `libc v0.2.161

That's not the error, the error is what comes after that, which might be a lot of text. Can you share all of it? You can upload text files to GitHub issues, which is probably useful for such errors.

@bayedieng
Copy link
Author

bayedieng commented Oct 23, 2024

Sorry for not being clear here:

  process didn't exit successfully: `/Users/bdieng/src/bdsh/target/release/build/libc-0ef8d401971a71b6/build-script-build` (signal: 9, SIGKILL: kill)

It does a sigkill which is essentially what is happening to all the code I've shown above when running in release mode.

@lqd
Copy link
Member

lqd commented Oct 23, 2024

Can you try on 1.83 beta? This looks like an issue with strip (e.g. from homebrew). #130781 should have mitigated this and is on beta.

@saethlin saethlin added O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 23, 2024
@bayedieng
Copy link
Author

Can you try on 1.83 beta? This looks like an issue with strip (e.g. from homebrew). #130781 should have mitigated this and is on beta.

All examples above work using rustc 1.83.0-beta.2 (88c1c3c11 2024-10-18)

@lqd
Copy link
Member

lqd commented Oct 23, 2024

So it seems you have a buggy strip in your PATH, likely from homebrew's binutils or similar. Removing it will fix the issue so that the regular /usr/bin/strip is used instead.

#130781 would also fix it when 1.83 is released at the end of next month, as shown by the issue not being present on nightly or beta.

(Even setting strip = false in a global cargo config file should work around this.)

In the mean time, I'll close this as a duplicate of #110536 that's already fixed. Feel free to reopen if that's not the case.

Thanks for opening an issue!

@lqd lqd closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants