From 21d2134dbd4ffe9f4252becf575969b78a43e1b8 Mon Sep 17 00:00:00 2001 From: Julian Büning Date: Sun, 9 Feb 2020 15:51:28 +0100 Subject: Executor: consolidate initialization of global objects --- lib/Core/Executor.cpp | 56 +++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'lib/Core') diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index 438fb0e3..9209be8a 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -750,35 +750,9 @@ void Executor::allocateGlobalObjects(ExecutionState &state) { /*alignment=*/globalObjectAlignment); if (!mo) klee_error("out of memory"); - ObjectState *os = bindObjectInState(state, mo, false); globalObjects.emplace(&v, mo); globalAddresses.emplace(&v, mo->getBaseExpr()); - - if (v.isDeclaration() && size) { - // Program already running -> object already initialized. - // Read concrete value and write it to our copy. - void *addr; - if (v.getName() == "__dso_handle") { - addr = &__dso_handle; // wtf ? - } else { - addr = externalDispatcher->resolveSymbol(v.getName()); - } - if (!addr) { - klee_error("Unable to load symbol(%.*s) while initializing globals", - static_cast(v.getName().size()), - v.getName().data() - ); - } - - for (unsigned offset = 0; offset < mo->size; offset++) { - os->write8(offset, static_cast(addr)[offset]); - } - } else { - if (!v.hasInitializer()) - os->initializeToRandom(); - } } - } void Executor::initializeGlobalAliases() { @@ -808,15 +782,31 @@ void Executor::initializeGlobalObjects(ExecutionState &state) { // calls std::vector constantObjects; for (const GlobalVariable &v : m->globals()) { - if (v.hasInitializer()) { - MemoryObject *mo = globalObjects.find(&v)->second; - const ObjectState *os = state.addressSpace.findObject(mo); - assert(os); - ObjectState *wos = state.addressSpace.getWriteable(mo, os); + MemoryObject *mo = globalObjects.find(&v)->second; + ObjectState *os = bindObjectInState(state, mo, false); - initializeGlobalObject(state, wos, v.getInitializer(), 0); + if (v.isDeclaration() && mo->size) { + // Program already running -> object already initialized. + // Read concrete value and write it to our copy. + void *addr; + if (v.getName() == "__dso_handle") { + addr = &__dso_handle; // wtf ? + } else { + addr = externalDispatcher->resolveSymbol(v.getName()); + } + if (!addr) { + klee_error("Unable to load symbol(%.*s) while initializing globals", + static_cast(v.getName().size()), v.getName().data()); + } + for (unsigned offset = 0; offset < mo->size; offset++) { + os->write8(offset, static_cast(addr)[offset]); + } + } else if (v.hasInitializer()) { + initializeGlobalObject(state, os, v.getInitializer(), 0); if (v.isConstant()) - constantObjects.emplace_back(wos); + constantObjects.emplace_back(os); + } else { + os->initializeToRandom(); } } -- cgit 1.4.1