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

Enable leak checker on Windows #1302

Closed
RalfJung opened this issue Apr 4, 2020 · 3 comments · Fixed by #1485
Closed

Enable leak checker on Windows #1302

RalfJung opened this issue Apr 4, 2020 · 3 comments · Fixed by #1485
Labels
A-leaks Area: affects the memory leak checker A-windows Area: affects only Windows targets C-bug Category: This is a bug.

Comments

@RalfJung
Copy link
Member

RalfJung commented Apr 4, 2020

Currently, the leak checker is disabled on Windows. This is because even a NOP program reports a leak:

The following memory was leaked:
alloc1821 (Rust heap, size: 40, align: 8) {
    0x00 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x10 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x20 │ __ __ __ __ __ __ __ __                         │ ░░░░░░░░
}
alloc1965 (Rust heap, size: 40, align: 8) {
    0x00 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x10 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x20 │ __ __ __ __ __ __ __ __                         │ ░░░░░░░░
}
alloc1997 (Rust heap, size: 24, align: 8) {
    0x00 │ ╾─────alloc1949+0─────╼ 00 00 00 00 00 00 00 00 │ ╾──────╼........
    0x10 │ 01 00 00 00 __ __ __ __                         │ ....░░░░
}
alloc2395 (Rust heap, size: 40, align: 8) {
    0x00 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x10 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x20 │ __ __ __ __ __ __ __ __                         │ ░░░░░░░░
}
alloc2445 (Rust heap, size: 40, align: 8) {
    0x00 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x10 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
    0x20 │ __ __ __ __ __ __ __ __                         │ ░░░░░░░░
}
alloc1949 (fn: std::sys_common::thread_local::register_dtor_fallback::run_dtors)

This leak is caused by static sys:common::mutex::Mutex, which store a pointer to some Rust heap allocation, cast to an integer (so even with #940 resolved, we do not "see" the pointer).

Even on a Windows host, you can avoid this problem by cross-running your program with --target x86_64-unknown-linux-gnu.

@RalfJung RalfJung added C-bug Category: This is a bug. A-windows Area: affects only Windows targets labels Apr 4, 2020
@RalfJung
Copy link
Member Author

RalfJung commented Apr 4, 2020

rust-lang/rust#70765 should fix this.

@RalfJung RalfJung changed the title Enable leak checker on Windows Leak checker misses pointers cast to integer Apr 10, 2020
@RalfJung RalfJung added A-intptrcast Area: affects int2ptr and ptr2int casts A-leaks Area: affects the memory leak checker and removed A-windows Area: affects only Windows targets labels Apr 10, 2020
@RalfJung RalfJung changed the title Leak checker misses pointers cast to integer Enable leak checker on Windows Apr 10, 2020
@RalfJung RalfJung added A-windows Area: affects only Windows targets and removed A-intptrcast Area: affects int2ptr and ptr2int casts labels Apr 10, 2020
@RalfJung
Copy link
Member Author

See #1318 for the general issue with the leak checker and ptr-int casts (but just to get basic Windows support in the leak checker, a more targeted solution could suffice).

@RalfJung
Copy link
Member Author

RalfJung commented Jun 28, 2020

I thought implementing SRWLock would fix this, but there are unfortunately still some leaks left:

alloc10490 (Rust heap, size: 12, align: 4) {
    ╾a10426[<24213>] (4 ptr bytes)╼ 01 00 00 00 00 00 00 00             │ ╾──╼........
}
alloc11048 (Rust heap, size: 12, align: 4) {
    ╾a10989[<25532>] (4 ptr bytes)╼ 02 00 00 00 24 05 02 00             │ ╾──╼....$...
}

Both of these are allocated in std::sys::windows::thread_local::register_dtor, which manages a lock-free concurrent linked list of destructors, thus running into #1318.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jul 24, 2020
 Miri: use extern fn to expose interpreter operations to program; fix leak checker on Windows

This PR realizes an idea that @oli-obk has been suggesting for a while: to use Miri-specific `extern` functions to provide some extra capabilities to the program. Initially, we have two of these methods, which libstd itself needs:
* `miri_start_panic`, which replaces the intrinsic of the same name (mostly for consistency, to avoid having multiple mechanisms for Miri-specific functionality).
* `miri_static_root`, which adds an allocation to a list of static "roots" that Miri considers as not having leaked (including all memory reachable through them). This is needed for rust-lang/miri#1302.

We use `extern` functions instead of intrinsics for this so that user code can more easily call these Miri hoolks -- e.g. `miri_static_root` should be useful for rust-lang/miri#1318.

The Miri side of this is at rust-lang/miri#1485.

r? @oli-obk
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 24, 2020
 Miri: use extern fn to expose interpreter operations to program; fix leak checker on Windows

This PR realizes an idea that @oli-obk has been suggesting for a while: to use Miri-specific `extern` functions to provide some extra capabilities to the program. Initially, we have two of these methods, which libstd itself needs:
* `miri_start_panic`, which replaces the intrinsic of the same name (mostly for consistency, to avoid having multiple mechanisms for Miri-specific functionality).
* `miri_static_root`, which adds an allocation to a list of static "roots" that Miri considers as not having leaked (including all memory reachable through them). This is needed for rust-lang/miri#1302.

We use `extern` functions instead of intrinsics for this so that user code can more easily call these Miri hoolks -- e.g. `miri_static_root` should be useful for rust-lang/miri#1318.

The Miri side of this is at rust-lang/miri#1485.

r? @oli-obk
@bors bors closed this as completed in 91b58c9 Jul 25, 2020
lygstate added a commit to lygstate/miri that referenced this issue Oct 9, 2020
 Note however that
[leak checking is currently disabled on Windows targets](rust-lang#1302).

Windows issue are fixed
bors added a commit that referenced this issue Oct 9, 2020
Update README.md

 Note however that
[leak checking is currently disabled on Windows targets](#1302).

Windows issue are fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-leaks Area: affects the memory leak checker A-windows Area: affects only Windows targets C-bug Category: This is a bug.
Projects
None yet
1 participant