- Module *SafeModule = CloneModule(BD.Program);
-
- // Make sure functions & globals are all external so that linkage
- // between the two modules will work.
- for (Module::iterator I = SafeModule->begin(), E = SafeModule->end();I!=E;++I)
- I->setLinkage(GlobalValue::ExternalLinkage);
- for (Module::giterator I=SafeModule->gbegin(),E = SafeModule->gend();I!=E;++I)
- I->setLinkage(GlobalValue::ExternalLinkage);
-
- DisambiguateGlobalSymbols(SafeModule);
- Module *TestModule = CloneModule(SafeModule);
-
- // Make sure global initializers exist only in the safe module (CBE->.so)
- for (Module::giterator I=TestModule->gbegin(),E = TestModule->gend();I!=E;++I)
- I->setInitializer(0); // Delete the initializer to make it external
-
- // Remove the Test functions from the Safe module
- for (unsigned i = 0, e = Funcs.size(); i != e; ++i) {
- Function *TNOF = SafeModule->getFunction(Funcs[i]->getName(),
- Funcs[i]->getFunctionType());
- assert(TNOF && "Function doesn't exist in module!");
- DeleteFunctionBody(TNOF); // Function is now external in this module!
- }
-
- // Remove the Safe functions from the Test module
- for (Module::iterator I=TestModule->begin(),E=TestModule->end(); I!=E; ++I) {
- bool funcFound = false;
- for (std::vector<Function*>::const_iterator F=Funcs.begin(),Fe=Funcs.end();
- F != Fe; ++F)
- if (I->getName() == (*F)->getName()) funcFound = true;