Skip to content

Commit

Permalink
fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use
Browse files Browse the repository at this point in the history
  • Loading branch information
oksbsb committed Dec 7, 2023
1 parent 85a4bd8 commit 4f5355a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/jobserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn default_client() -> Client {

static GLOBAL_CLIENT_CHECKED: OnceLock<Client> = OnceLock::new();

pub fn check(report_warning: impl FnOnce(&'static str)) {
pub fn initialize_checked(report_warning: impl FnOnce(&'static str)) {
let client_checked = match &*GLOBAL_CLIENT {
Ok(client) => client.clone(),
Err(e) => {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
// Set parallel mode before thread pool creation, which will create `Lock`s.
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);

// Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread
let handler = EarlyErrorHandler::new(config.opts.error_format);
handler.initialize_checked_jobserver();

util::run_in_thread_pool_with_globals(
config.opts.edition,
config.opts.unstable_opts.threads,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Se
output_file: None,
temps_dir,
};

handler.initialize_checked_jobserver();

let sess = build_session(
handler,
sessopts,
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,11 +1469,6 @@ pub fn build_session(
let asm_arch =
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };

// Check jobserver before getting `jobserver::client`.
jobserver::check(|err| {
handler.early_warn_with_note(err, "the build environment is likely misconfigured")
});

let sess = Session {
target: target_cfg,
host,
Expand Down Expand Up @@ -1791,6 +1786,13 @@ impl EarlyErrorHandler {
) {
self.handler.struct_warn(msg).note(note).emit()
}

pub fn initialize_checked_jobserver(&self) {
// initialize jobserver before getting `jobserver::client` and `build_session`.
jobserver::initialize_checked(|err| {
self.early_warn_with_note(err, "the build environment is likely misconfigured")
});
}
}

fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
Expand Down

0 comments on commit 4f5355a

Please sign in to comment.