mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
Fix ASAN static initialization order fiasco
See here for more details https://github.com/google/sanitizers/wiki/AddressSanitizerInitializationOrderFiasco Use the "Construct On First Use" idiom from https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Construct_On_First_Use
This commit is contained in:
parent
6d6d0317e2
commit
1c2323cad3
2 changed files with 8 additions and 5 deletions
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
namespace ghidra {
|
namespace ghidra {
|
||||||
|
|
||||||
vector<UnitTest *> UnitTest::tests;
|
|
||||||
|
|
||||||
/// Run all the tests unless a non-empty set of names is passed in.
|
/// Run all the tests unless a non-empty set of names is passed in.
|
||||||
/// In which case, only the named tests in the set are run.
|
/// In which case, only the named tests in the set are run.
|
||||||
/// \param testNames is the set of names
|
/// \param testNames is the set of names
|
||||||
|
@ -30,7 +28,7 @@ int UnitTest::run(set<string> &testNames)
|
||||||
int total = 0;
|
int total = 0;
|
||||||
int passed = 0;
|
int passed = 0;
|
||||||
|
|
||||||
for(auto &t : UnitTest::tests) {
|
for(auto &t : UnitTest::tests()) {
|
||||||
if (testNames.size() > 0 && testNames.find(t->name) == testNames.end()) {
|
if (testNames.size() > 0 && testNames.find(t->name) == testNames.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ typedef void (*testfunc_t)(); ///< A unit-test function
|
||||||
/// The static run() method calls all the function pointers of all instantiated
|
/// The static run() method calls all the function pointers of all instantiated
|
||||||
/// objects.
|
/// objects.
|
||||||
struct UnitTest {
|
struct UnitTest {
|
||||||
static vector<UnitTest *> tests; ///< The collection of test objects
|
|
||||||
string name; ///< Name of the test
|
string name; ///< Name of the test
|
||||||
testfunc_t func; ///< Call-back function executing the test
|
testfunc_t func; ///< Call-back function executing the test
|
||||||
|
|
||||||
|
@ -64,7 +63,13 @@ struct UnitTest {
|
||||||
UnitTest(const string &name,testfunc_t func) :
|
UnitTest(const string &name,testfunc_t func) :
|
||||||
name(name), func(func)
|
name(name), func(func)
|
||||||
{
|
{
|
||||||
tests.push_back(this);
|
tests().push_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief The collection of test objects
|
||||||
|
static vector<UnitTest *> & tests() {
|
||||||
|
static vector<UnitTest *> tests;
|
||||||
|
return tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run(set<string> &testNames); ///< Run all the instantiated tests
|
static int run(set<string> &testNames); ///< Run all the instantiated tests
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue