mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 11:44:14 +01:00
bench: Fix initialization order in registration
The initialization order of global data structures in different implementation units is undefined. Making use of this is essentially gambling on what the linker does, the so-called [Static initialization order fiasco](https://isocpp.org/wiki/faq/ctors#static-init-order). In this case it apparently worked on Linux but failed on OpenBSD and FreeBSD. To create it on first use, make the registration structure local to a function. Fixes #8910.
This commit is contained in:
@@ -63,7 +63,8 @@ namespace benchmark {
|
||||
|
||||
class BenchRunner
|
||||
{
|
||||
static std::map<std::string, BenchFunction> benchmarks;
|
||||
typedef std::map<std::string, BenchFunction> BenchmarkMap;
|
||||
static BenchmarkMap &benchmarks();
|
||||
|
||||
public:
|
||||
BenchRunner(std::string name, BenchFunction func);
|
||||
|
||||
Reference in New Issue
Block a user