Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upOverflowing the stack doesn't work, function optimized away #283
Comments
This comment has been minimized.
This comment has been minimized.
Hmm, that's strange. Are you compiling with optimizations? |
This comment has been minimized.
This comment has been minimized.
Yes. I'm compiling with BTW, I also had same issue with paging, because code has no side-effects, and some of it was getting optimized away. |
This comment has been minimized.
This comment has been minimized.
I don't use However, the code should also work with
That sounds really bad Thanks a lot for reporting these issues! I'm quite busy at the moment, but I'll try to investigate and fix them as soon as I have some time again. |
This comment has been minimized.
This comment has been minimized.
Does the following work? #[inline(never)]
fn stack_overflow(){
print!(".");
stack_overflow();
print!(".");
stack_overflow();
} Or
|
This comment has been minimized.
This comment has been minimized.
So there are two issues here:
|
This comment has been minimized.
This comment has been minimized.
My test for this works with #[allow(unconditional_recursion)]
fn stack_overflow(n: u64) -> u64 {
// We need to indicate to the compiler that it should disable optimisations by black_boxing `n`
stack_overflow(black_box(n + 1))
}
/// lifted from: https://doc.rust-lang.org/src/core/hint.rs.html#111
fn black_box<T>(dummy: T) -> T {
unsafe {
asm!("": : "r"(&dummy));
return dummy;
}
} |
This comment has been minimized.
This comment has been minimized.
woops, didn't see the original post date - ignore (although an answer would still be nice |
This comment has been minimized.
This comment has been minimized.
@64 Unfortunately, I never really solved the issues. I didn't know how to use bochs debugger then. My paging code was a huge mess anyways, so I have rewritten it twice since then. I'm now using let mut table: &mut PageTable = unsafe { &mut *virt_addr.as_mut_ptr() }; And I make sure the reference is dropped before I flush changes to TLB. |
From Double faults: Kernel Stack Overflow
I try to compile this, but
xargo build
just says:And then it (or llvm) apparently optimizes the recursion away, and to me it looks like the
stack_overflow
function wasn't even called, andIt did not crash!
is printed.My Rust version is
rustc 1.14.0-nightly
.I used this code to work around this:
Because
print!(".")
will cause a side-effect, the function must be called.