Skip to content

Commit 0c55e28

Browse files
authored
fix(maitake): add no_mangle workaround for ICE (#190)
See rust-lang/rust#97708 for more details
1 parent bde8172 commit 0c55e28

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

maitake/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ categories = [
1616
edition = "2021"
1717
rust-version = "1.61.0"
1818

19+
# NOTE! As a workaround for https://github.com/rust-lang/rust/issues/97708,
20+
# maitake uses some `no_mangle` functions. This will cause linker errors if
21+
# you attempt to use two versions of maitake in the same binary. Until then,
22+
# we use the "links" key to prevent two versions of maitake in the same
23+
# dependency graph
24+
links = "maitake"
25+
1926
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2027

2128
[features]

maitake/build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Part of https://github.com/rust-lang/rust/issues/97708 workaround
2+
fn main() {}

maitake/src/task.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -437,26 +437,32 @@ unsafe impl Sync for TaskRef {}
437437

438438
// === impl Header ===
439439

440+
// See https://github.com/rust-lang/rust/issues/97708 for why
441+
// this is necessary
442+
#[no_mangle]
443+
unsafe fn _maitake_header_nop(_ptr: TaskRef) -> Poll<()> {
444+
#[cfg(debug_assertions)]
445+
unreachable!("stub task ({_ptr:?}) should never be polled!");
446+
#[cfg(not(debug_assertions))]
447+
Poll::Pending
448+
}
449+
450+
// See https://github.com/rust-lang/rust/issues/97708 for why
451+
// this is necessary
452+
#[no_mangle]
453+
unsafe fn _maitake_header_nop_deallocate(ptr: NonNull<Header>) {
454+
unreachable!("stub task ({ptr:p}) should never be deallocated!");
455+
}
456+
440457
impl Header {
441458
#[cfg(not(loom))]
442459
pub(crate) const fn new_stub() -> Self {
443-
unsafe fn nop(_ptr: TaskRef) -> Poll<()> {
444-
#[cfg(debug_assertions)]
445-
unreachable!("stub task ({_ptr:?}) should never be polled!");
446-
#[cfg(not(debug_assertions))]
447-
Poll::Pending
448-
}
449-
450-
unsafe fn nop_deallocate(ptr: NonNull<Header>) {
451-
unreachable!("stub task ({ptr:p}) should never be deallocated!");
452-
}
453-
454460
Self {
455461
run_queue: mpsc_queue::Links::new_stub(),
456462
state: StateCell::new(),
457463
vtable: &Vtable {
458-
poll: nop,
459-
deallocate: nop_deallocate,
464+
poll: _maitake_header_nop,
465+
deallocate: _maitake_header_nop_deallocate,
460466
},
461467
}
462468
}

maitake/tests/static_stub.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use maitake::scheduler::TaskStub;
2+
3+
/// This test reproduces an internal compiler error:
4+
/// https://github.com/rust-lang/rust/issues/97708
5+
#[test]
6+
fn compiles() {
7+
#[allow(dead_code)]
8+
static TASK_STUB: TaskStub = TaskStub::new();
9+
}

0 commit comments

Comments
 (0)