diff -u'rF^function' llvm/include/llvm/Function.h llvm/include/llvm/Function.h
--- llvm/include/llvm/Function.h	2005-10-25 19:58:00.000000000 +0200
+++ llvm/include/llvm/Function.h	2006-09-25 12:58:49.000000000 +0200
@@ -66,6 +66,8 @@
   SymbolTable *SymTab;
   unsigned CallingConvention;
 
+  std::string nameOfPreviousModule;//empty if parent==originalModule
+
   friend class SymbolTableListTraits<Function, Module, Module>;
 
   void setParent(Module *parent);
@@ -230,6 +232,9 @@
   /// including any contained basic blocks.
   ///
   void dropAllReferences();
+
+  const std::string getNameOfPreviousModule() const;
+  void setNameOfPreviousModule(const std::string& oldModuleName);
 };
 
 } // End llvm namespace
diff -u'rF^function' llvm/include/llvm/Linker.h llvm/include/llvm/Linker.h
--- llvm/include/llvm/Linker.h	2006-02-22 17:23:42.000000000 +0100
+++ llvm/include/llvm/Linker.h	2006-09-25 13:20:43.000000000 +0200
@@ -239,8 +239,9 @@
     /// @returns True if an error occurs, false otherwise.
     /// @brief Link in a module.
     bool LinkInModule(
-      Module* Src     ///< Module linked into \p Dest
-    ) { return LinkModules(Composite, Src, &Error); }
+      Module* Src,     ///< Module linked into \p Dest
+      const std::string& originalModuleName=""
+    ) { return LinkModules(Composite, Src, &Error,originalModuleName); }
 
     /// This is the heart of the linker. This method will take unconditional
     /// control of the \p Src module and link it into the \p Dest module. The
@@ -253,7 +254,7 @@
     /// error.
     /// @returns True if an error occurs, false otherwise.
     /// @brief Generically link two modules together.
-    static bool LinkModules(Module* Dest, Module* Src, std::string* ErrorMsg);
+    static bool LinkModules(Module* Dest, Module* Src, std::string* ErrorMsg,const std::string& originalModuleName="");
 
     /// This function looks through the Linker's LibPaths to find a library with
     /// the name \p Filename. If the library cannot be found, the returned path
diff -u'rF^function' llvm/lib/Linker/LinkItems.cpp llvm/lib/Linker/LinkItems.cpp
--- llvm/lib/Linker/LinkItems.cpp	2006-01-10 04:14:40.000000000 +0100
+++ llvm/lib/Linker/LinkItems.cpp	2006-09-25 13:17:10.000000000 +0200
@@ -150,7 +150,7 @@
     std::auto_ptr<Module> M(LoadObject(File));
     if (M.get() == 0)
       return error("Cannot load file '" + File.toString() + "'" + Error);
-    if (LinkInModule(M.get()))
+    if (LinkInModule(M.get(),File.toString()))
       return error("Cannot link file '" + File.toString() + "'" + Error);
 
     verbose("Linked in file '" + File.toString() + "'");
diff -u'rF^function' llvm/lib/Linker/LinkModules.cpp llvm/lib/Linker/LinkModules.cpp
--- llvm/lib/Linker/LinkModules.cpp	2006-07-15 00:21:31.000000000 +0200
+++ llvm/lib/Linker/LinkModules.cpp	2006-09-25 13:20:42.000000000 +0200
@@ -644,9 +644,12 @@
 // function, and that Src is not.
 static bool LinkFunctionBody(Function *Dest, Function *Src,
                              std::map<const Value*, Value*> &GlobalMap,
-                             std::string *Err) {
+                             std::string *Err, const std::string& originalModuleName="") {
   assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
 
+  // Set name of original Module
+  Dest->setNameOfPreviousModule(originalModuleName);
+
   // Go through and convert function arguments over, remembering the mapping.
   Function::arg_iterator DI = Dest->arg_begin();
   for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();
@@ -686,7 +689,7 @@
 // function over and fixing up references to values.
 static bool LinkFunctionBodies(Module *Dest, Module *Src,
                                std::map<const Value*, Value*> &ValueMap,
-                               std::string *Err) {
+                               std::string *Err,const std::string& originalModuleName="") {
 
   // Loop over all of the functions in the src module, mapping them over as we
   // go
@@ -697,7 +700,7 @@
       // DF not external SF external?
       if (DF->isExternal()) {
         // Only provide the function body if there isn't one already.
-        if (LinkFunctionBody(DF, SF, ValueMap, Err))
+        if (LinkFunctionBody(DF, SF, ValueMap, Err, originalModuleName))
           return true;
       }
     }
@@ -799,7 +802,7 @@
 // the problem.  Upon failure, the Dest module could be in a modified state, and
 // shouldn't be relied on to be consistent.
 bool
-Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) {
+Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg,const std::string& originalModuleName) {
   assert(Dest != 0 && "Invalid Destination module");
   assert(Src  != 0 && "Invalid Source Module");
 
@@ -894,7 +897,7 @@
   // Link in the function bodies that are defined in the source module into the
   // DestModule.  This consists basically of copying the function over and
   // fixing up references to values.
-  if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true;
+  if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg, originalModuleName)) return true;
 
   // If there were any appending global variables, link them together now.
   if (LinkAppendingVars(Dest, AppendingVars, ErrorMsg)) return true;
diff -u'rF^function' llvm/lib/VMCore/Function.cpp llvm/lib/VMCore/Function.cpp
--- llvm/lib/VMCore/Function.cpp	2006-03-25 07:32:47.000000000 +0100
+++ llvm/lib/VMCore/Function.cpp	2006-09-25 12:58:49.000000000 +0200
@@ -76,7 +76,7 @@
 
 Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
                    const std::string &name, Module *ParentModule)
-  : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name) {
+  : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name),nameOfPreviousModule("") {
   CallingConvention = 0;
   BasicBlocks.setItemParent(this);
   BasicBlocks.setParent(this);
@@ -111,8 +111,10 @@
 }
 
 void Function::setParent(Module *parent) {
-  if (getParent())
+  if (getParent()){
     LeakDetector::addGarbageObject(this);
+    setNameOfPreviousModule(Parent->getModuleIdentifier());
+  }
   Parent = parent;
   if (getParent())
     LeakDetector::removeGarbageObject(this);
@@ -192,6 +194,14 @@
   BasicBlocks.clear();    // Delete all basic blocks...
 }
 
+const std::string Function::getNameOfPreviousModule() const{
+  return nameOfPreviousModule;
+}
+
+void Function::setNameOfPreviousModule(const std::string& oldModuleName){
+  nameOfPreviousModule=oldModuleName;
+}
+
 /// getIntrinsicID - This method returns the ID number of the specified
 /// function, or Intrinsic::not_intrinsic if the function is not an
 /// intrinsic, or if the pointer is null.  This value is always defined to be
