Skip to content

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

Closed as not planned
@bayedieng

Description

@bayedieng

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-macosOperating system: macOST-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions