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

fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use #118709

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -316,6 +316,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 early_handler = EarlyErrorHandler::new(config.opts.error_format);
early_handler.initialize_checked_jobserver();

util::run_in_thread_pool_with_globals(
config.opts.edition,
config.opts.unstable_opts.threads,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use std::sync::Arc;

fn mk_session(matches: getopts::Matches) -> (Session, Cfg) {
let mut early_handler = EarlyErrorHandler::new(ErrorOutputType::default());
early_handler.initialize_checked_jobserver();

let registry = registry::Registry::new(&[]);
let sessopts = build_session_options(&mut early_handler, &matches);
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,17 +1474,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| {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
parse_sess
.span_diagnostic
.struct_warn(err)
.note("the build environment is likely misconfigured")
.emit()
});

let sess = Session {
target: target_cfg,
host,
Expand Down Expand Up @@ -1792,6 +1781,18 @@ impl EarlyErrorHandler {
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
self.handler.struct_warn(msg).emit()
}

pub fn initialize_checked_jobserver(&self) {
// initialize jobserver before getting `jobserver::client` and `build_session`.
jobserver::initialize_checked(|err| {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
self.handler
.struct_warn(err)
.note("the build environment is likely misconfigured")
.emit()
});
}
}

fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
Expand Down
2 changes: 0 additions & 2 deletions tests/run-make/jobserver-error/cannot_open_fd.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ warning: failed to connect to jobserver from environment variable `MAKEFLAGS="--

error: no input filename given

warning: 1 warning emitted

2 changes: 0 additions & 2 deletions tests/run-make/jobserver-error/not_a_pipe.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ warning: failed to connect to jobserver from environment variable `MAKEFLAGS="--
|
= note: the build environment is likely misconfigured

warning: 1 warning emitted

Loading