Problem
First I found this problem when run gtest for compiled with debug_assertions wasm tests - some of them failed on execution.
$ sh scripts/test.sh async
Fixture async-await (step: 1): Ok
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 2): Messages check [expected: 1, actual: 2]
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 3): Messages check [expected: 1, actual: 2]
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 4): Messages check [expected: 1, actual: 2]
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 5): Messages check [expected: 1, actual: 2]
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 6): Messages check [expected: 1, actual: 2]
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 7): Messages check [expected: 1, actual: 2]
DEBUG: 1 total message(s) stored:
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 8): Messages check [expected: 1, actual: 3]
DEBUG: 1 total message(s) stored:
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 9): Messages check [expected: 1, actual: 3]
DEBUG: 1 total message(s) stored:
DEBUG: 1 total message(s) stored:
Fixture async-await (step: 10): Log check [expected: 1, actual: 0]
Error: 9 tests failed
Investigating problem I found that debug_assertion is not a reason and something fails tests in checks code.
So I tried to localize problem - remove all unneeded checks and unneeded code.
Only one check function is left and inside only one small loop is left:
check_malloc_state(&mut self) {
if !DL_CHECKS { return; }
for i in 0..11 {
let head_chunk : *mut Chunk = self.smallbin_at(i as u32);
}
}
#[inline(never)]
unsafe fn smallbin_at(&mut self, idx: u32) -> *mut Chunk {
let idx = (idx * 2) as usize;
dlassert!(idx < self.smallbins.len());
let smallbins_ptr = &self.smallbins as *const *mut Chunk;
let idx_ptr = smallbins_ptr.offset(idx as isize ) as *mut Chunk;
return idx_ptr;
}
Here we just take few times mutable pointer and do nothing else. This function is called sometimes in allocator.
So, if DL_CHECKS is true then gtest is failed, else all goes right.
We can also tries to make function smallbin_at as inline - in that case tests goes well.
If we change iterations number in loop, for example 0..10, then tests also goes well.
I noticed that if iterations number >= 11 then we fails in other case goes well: 20..25 and 20..30 - goes well; 20..31 - fails
Steps
Linux kernel: 5.4.0-86-generic OS: 20.04.3 LTS (Focal Fossa) Proc: x86_64
- git fetch && git checkout gsobol_alloc_fail
- sh scripts/test.sh async // this must fail
- remove in galloc/Cargo.toml feature "gsobol_check" which is for dlallocator
- sh scripts/test.sh async // this runs well
Possible Solution
I think that problem may be in wasmtime compiler or when we compile from rust to wasm code.
No other ideas.
Notes
No response
Relevant Log Output
No response
C0-bug