diff --git a/codegenerator.cpp b/codegenerator.cpp index 40d660ba7..368131b43 100644 --- a/codegenerator.cpp +++ b/codegenerator.cpp @@ -762,6 +762,8 @@ void CodeGenerator::translate(uint64_t VirtualAddress, Linker::LinkOnlyNeeded); assert(!Result && "Linking failed"); + Variables.setDataLayout(&TheModule->getDataLayout()); + legacy::PassManager PM; PM.add(createSROAPass()); PM.add(new CpuLoopExitPass(&Variables)); diff --git a/variablemanager.cpp b/variablemanager.cpp index 33e233992..3a7a81a07 100644 --- a/variablemanager.cpp +++ b/variablemanager.cpp @@ -272,7 +272,7 @@ VariableManager::VariableManager(Module& TheModule, TheModule(TheModule), Builder(TheModule.getContext()), CPUStateType(nullptr), - HelpersModuleLayout(&HelpersModule.getDataLayout()), + ModuleLayout(&HelpersModule.getDataLayout()), EnvOffset(0), Env(nullptr) { @@ -345,7 +345,7 @@ VariableManager::VariableManager(Module& TheModule, if (Found != End) { unsigned Index = Found - Begin; const StructLayout *Layout = nullptr; - Layout = HelpersModuleLayout->getStructLayout(TheStruct); + Layout = ModuleLayout->getStructLayout(TheStruct); EnvOffset += Layout->getElementOffset(Index); CPUStateType = TheStruct; Visited.insert(CPUStateType); @@ -422,7 +422,7 @@ GlobalVariable* VariableManager::getByCPUStateOffset(intptr_t Offset, GlobalsMap::iterator it = CPUStateGlobals.find(Offset); if (it == CPUStateGlobals.end() || (Name.size() != 0 && !it->second->getName().equals_lower(Name))) { - Type *VariableType = getTypeAtOffset(HelpersModuleLayout, + Type *VariableType = getTypeAtOffset(ModuleLayout, CPUStateType, Offset); diff --git a/variablemanager.h b/variablemanager.h index f80eca7fa..364ae045d 100644 --- a/variablemanager.h +++ b/variablemanager.h @@ -98,6 +98,10 @@ public: llvm::Instruction *InsertBefore, unsigned Offset = 0); + void setDataLayout(const llvm::DataLayout *NewLayout) { + ModuleLayout = NewLayout; + } + private: llvm::GlobalVariable *getByCPUStateOffset(intptr_t Offset, std::string Name=""); @@ -113,7 +117,7 @@ private: PTCInstructionList *Instructions; llvm::StructType *CPUStateType; - const llvm::DataLayout *HelpersModuleLayout; + const llvm::DataLayout *ModuleLayout; unsigned EnvOffset; llvm::Value *Env;