Skip to content

Commit f363745

Browse files
committed
Auto merge of #67458 - pnkfelix:fix-66530-by-propagating-fatal-error-from-worker, r=matthewjasper
When a codegen worker has a FatalError, propagate it instead of ICE'ing. Fix #66530
2 parents 1389494 + 3193836 commit f363745

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

src/librustc_codegen_ssa/back/write.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ pub enum Message<B: WriteBackendMethods> {
902902
worker_id: usize,
903903
},
904904
Done {
905-
result: Result<CompiledModule, ()>,
905+
result: Result<CompiledModule, Option<WorkerFatalError>>,
906906
worker_id: usize,
907907
},
908908
CodegenDone {
@@ -1474,9 +1474,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
14741474
main_thread_worker_state = MainThreadWorkerState::Idle;
14751475
}
14761476
// If the thread failed that means it panicked, so we abort immediately.
1477-
Message::Done { result: Err(()), worker_id: _ } => {
1477+
Message::Done { result: Err(None), worker_id: _ } => {
14781478
bug!("worker thread panicked");
14791479
}
1480+
Message::Done { result: Err(Some(WorkerFatalError)), worker_id: _ } => {
1481+
return Err(());
1482+
}
14801483
Message::CodegenItem => bug!("the coordinator should not receive codegen requests"),
14811484
}
14821485
}
@@ -1520,29 +1523,36 @@ fn start_executing_work<B: ExtraBackendMethods>(
15201523

15211524
pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
15221525

1526+
/// `FatalError` is explicitly not `Send`.
1527+
#[must_use]
1528+
pub struct WorkerFatalError;
1529+
15231530
fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>) {
15241531
thread::spawn(move || {
15251532
// Set up a destructor which will fire off a message that we're done as
15261533
// we exit.
15271534
struct Bomb<B: ExtraBackendMethods> {
15281535
coordinator_send: Sender<Box<dyn Any + Send>>,
1529-
result: Option<WorkItemResult<B>>,
1536+
result: Option<Result<WorkItemResult<B>, FatalError>>,
15301537
worker_id: usize,
15311538
}
15321539
impl<B: ExtraBackendMethods> Drop for Bomb<B> {
15331540
fn drop(&mut self) {
15341541
let worker_id = self.worker_id;
15351542
let msg = match self.result.take() {
1536-
Some(WorkItemResult::Compiled(m)) => {
1543+
Some(Ok(WorkItemResult::Compiled(m))) => {
15371544
Message::Done::<B> { result: Ok(m), worker_id }
15381545
}
1539-
Some(WorkItemResult::NeedsFatLTO(m)) => {
1546+
Some(Ok(WorkItemResult::NeedsFatLTO(m))) => {
15401547
Message::NeedsFatLTO::<B> { result: m, worker_id }
15411548
}
1542-
Some(WorkItemResult::NeedsThinLTO(name, thin_buffer)) => {
1549+
Some(Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer))) => {
15431550
Message::NeedsThinLTO::<B> { name, thin_buffer, worker_id }
15441551
}
1545-
None => Message::Done::<B> { result: Err(()), worker_id },
1552+
Some(Err(FatalError)) => {
1553+
Message::Done::<B> { result: Err(Some(WorkerFatalError)), worker_id }
1554+
}
1555+
None => Message::Done::<B> { result: Err(None), worker_id },
15461556
};
15471557
drop(self.coordinator_send.send(Box::new(msg)));
15481558
}
@@ -1562,7 +1572,7 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15621572
// surface that there was an error in this worker.
15631573
bomb.result = {
15641574
let _prof_timer = cgcx.prof.generic_activity(work.profiling_event_id());
1565-
execute_work_item(&cgcx, work).ok()
1575+
Some(execute_work_item(&cgcx, work))
15661576
};
15671577
});
15681578
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Issue #66530: We would ICE if someone compiled with `-o /dev/null`,
2+
// because we would try to generate auxiliary files in `/dev/` (which
3+
// at least the OS X file system rejects).
4+
//
5+
// An attempt to `-o` into a directory we cannot write into should indeed
6+
// be an error; but not an ICE.
7+
8+
// compile-flags: -o /dev/null
9+
10+
// The error-pattern check occurs *before* normalization, and the error patterns
11+
// are wildly different between build environments. So this is a cop-out (and we
12+
// rely on the checking of the normalized stderr output as our actual
13+
// "verification" of the diagnostic).
14+
15+
// error-pattern: error
16+
17+
// On Mac OS X, we get an error like the below
18+
// normalize-stderr-test "failed to write bytecode to /dev/null.non_ice_error_on_worker_io_fail.*" -> "io error modifying /dev/"
19+
20+
// On Linux, we get an error like the below
21+
// normalize-stderr-test "couldn't create a temp dir.*" -> "io error modifying /dev/"
22+
23+
// ignore-tidy-linelength
24+
// ignore-windows - this is a unix-specific test
25+
// ignore-emscripten - the file-system issues do not replicate here
26+
// ignore-wasm - the file-system issues do not replicate here
27+
// ignore-arm - the file-system issues do not replicate here, at least on armhf-gnu
28+
29+
#![crate_type="lib"]
30+
31+
#![cfg_attr(not(feature = "std"), no_std)]
32+
pub mod task {
33+
pub mod __internal {
34+
use crate::task::Waker;
35+
}
36+
pub use core::task::Waker;
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: ignoring --out-dir flag due to -o flag
2+
3+
error: io error modifying /dev/
4+
5+
error: aborting due to previous error
6+

0 commit comments

Comments
 (0)