google / google/uVkCompute

Stack corruption caused by registered benchmark parameter going out of scope

Open
#52 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
262
Forks
45
PR merge metrics
No merged PRs in 30d

Description

A pointer to this variable is used in a call to `memory::RegisterCopyStorageBufferBenchmark()`.

https://github.com/google/uVkCompute/blob/2e4c8e4c7f871aa5496518fd0ec746f5d80f6051/benchmarks/memory/copy_storage_buffer_main.cc#L41-L44

Since this is a local automatic variable, it goes out of scope and the pointer used to register the benchmark points to some place on the stack that will later be used for subsequent stack frames. Later, when the benchmark actually runs, this code:

https://github.com/google/uVkCompute/blob/2e4c8e4c7f871aa5496518fd0ec746f5d80f6051/benchmarks/memory/copy_storage_buffer.cc#L221

writes a double to some unwanted place on the stack, causing corruption.

I only saw this problem on LLVM/Clang and didn't see it with MSVC or GCC compilers. The failures are somewhat random as is the case with these stack corruption problems. In my case with LLVM, I got a seg fault as the code returned from running the benchmark.

The easiest fix is to just change the storage class of `avg_latency_seconds` to static. It doesn't look like this variable is actually used or reported anywhere, so it could be removed from the benchmark parameter list (and registration) entirely, or perhaps make a space for it in a benchmark-related data structure that has a lifetime that spans the execution of the test.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.