Skip to content

Commit bee1bb4

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 774a4bd + 18750e0 commit bee1bb4

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

src/librustc_codegen_ssa/back/write.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ pub enum Message<B: WriteBackendMethods> {
903903
worker_id: usize,
904904
},
905905
Done {
906-
result: Result<CompiledModule, ()>,
906+
result: Result<CompiledModule, Option<WorkerFatalError>>,
907907
worker_id: usize,
908908
},
909909
CodegenDone {
@@ -1476,9 +1476,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
14761476
main_thread_worker_state = MainThreadWorkerState::Idle;
14771477
}
14781478
// If the thread failed that means it panicked, so we abort immediately.
1479-
Message::Done { result: Err(()), worker_id: _ } => {
1479+
Message::Done { result: Err(None), worker_id: _ } => {
14801480
bug!("worker thread panicked");
14811481
}
1482+
Message::Done { result: Err(Some(WorkerFatalError)), worker_id: _ } => {
1483+
return Err(());
1484+
}
14821485
Message::CodegenItem => bug!("the coordinator should not receive codegen requests"),
14831486
}
14841487
}
@@ -1527,6 +1530,10 @@ fn start_executing_work<B: ExtraBackendMethods>(
15271530

15281531
pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
15291532

1533+
/// `FatalError` is explicitly not `Send`.
1534+
#[must_use]
1535+
pub struct WorkerFatalError;
1536+
15301537
fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>) {
15311538
let depth = time_depth();
15321539

@@ -1537,23 +1544,26 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15371544
// we exit.
15381545
struct Bomb<B: ExtraBackendMethods> {
15391546
coordinator_send: Sender<Box<dyn Any + Send>>,
1540-
result: Option<WorkItemResult<B>>,
1547+
result: Option<Result<WorkItemResult<B>, FatalError>>,
15411548
worker_id: usize,
15421549
}
15431550
impl<B: ExtraBackendMethods> Drop for Bomb<B> {
15441551
fn drop(&mut self) {
15451552
let worker_id = self.worker_id;
15461553
let msg = match self.result.take() {
1547-
Some(WorkItemResult::Compiled(m)) => {
1554+
Some(Ok(WorkItemResult::Compiled(m))) => {
15481555
Message::Done::<B> { result: Ok(m), worker_id }
15491556
}
1550-
Some(WorkItemResult::NeedsFatLTO(m)) => {
1557+
Some(Ok(WorkItemResult::NeedsFatLTO(m))) => {
15511558
Message::NeedsFatLTO::<B> { result: m, worker_id }
15521559
}
1553-
Some(WorkItemResult::NeedsThinLTO(name, thin_buffer)) => {
1560+
Some(Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer))) => {
15541561
Message::NeedsThinLTO::<B> { name, thin_buffer, worker_id }
15551562
}
1556-
None => Message::Done::<B> { result: Err(()), worker_id },
1563+
Some(Err(FatalError)) => {
1564+
Message::Done::<B> { result: Err(Some(WorkerFatalError)), worker_id }
1565+
}
1566+
None => Message::Done::<B> { result: Err(None), worker_id },
15571567
};
15581568
drop(self.coordinator_send.send(Box::new(msg)));
15591569
}
@@ -1573,7 +1583,7 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15731583
// surface that there was an error in this worker.
15741584
bomb.result = {
15751585
let _prof_timer = cgcx.prof.generic_activity(work.profiling_event_id());
1576-
execute_work_item(&cgcx, work).ok()
1586+
Some(execute_work_item(&cgcx, work))
15771587
};
15781588
});
15791589
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
26+
#![crate_type="lib"]
27+
28+
#![cfg_attr(not(feature = "std"), no_std)]
29+
pub mod task {
30+
pub mod __internal {
31+
use crate::task::Waker;
32+
}
33+
pub use core::task::Waker;
34+
}
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)