Introduce the notion of "Relocatable" precompiled headers, which are built
with a particular system root directory and can be used with a different
system root directory when the headers it depends on have been installed.
Relocatable precompiled headers rewrite the file names of the headers used
when generating the PCH file into the corresponding file names of the 
headers available when using the PCH file.

Addresses <rdar://problem/7001604>.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74885 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/GeneratePCH.cpp b/lib/Frontend/GeneratePCH.cpp
index 8be88ce..3b7715a 100644
--- a/lib/Frontend/GeneratePCH.cpp
+++ b/lib/Frontend/GeneratePCH.cpp
@@ -32,19 +32,24 @@
 namespace {
   class VISIBILITY_HIDDEN PCHGenerator : public SemaConsumer {
     const Preprocessor &PP;
+    const char *isysroot;
     llvm::raw_ostream *Out;
     Sema *SemaPtr;
     MemorizeStatCalls *StatCalls; // owned by the FileManager
-
+    
   public:
-    explicit PCHGenerator(const Preprocessor &PP, llvm::raw_ostream *Out);
+    explicit PCHGenerator(const Preprocessor &PP, 
+                          const char *isysroot,
+                          llvm::raw_ostream *Out);
     virtual void InitializeSema(Sema &S) { SemaPtr = &S; }
     virtual void HandleTranslationUnit(ASTContext &Ctx);
   };
 }
 
-PCHGenerator::PCHGenerator(const Preprocessor &PP, llvm::raw_ostream *OS)
-  : PP(PP), Out(OS), SemaPtr(0), StatCalls(0) { 
+PCHGenerator::PCHGenerator(const Preprocessor &PP, 
+                           const char *isysroot,
+                           llvm::raw_ostream *OS)
+  : PP(PP), isysroot(isysroot), Out(OS), SemaPtr(0), StatCalls(0) { 
 
   // Install a stat() listener to keep track of all of the stat()
   // calls.
@@ -56,14 +61,14 @@
   if (PP.getDiagnostics().hasErrorOccurred())
     return;
 
- // Write the PCH contents into a buffer
+  // Write the PCH contents into a buffer
   std::vector<unsigned char> Buffer;
   BitstreamWriter Stream(Buffer);
   PCHWriter Writer(Stream);
 
   // Emit the PCH file
   assert(SemaPtr && "No Sema?");
-  Writer.WritePCH(*SemaPtr, StatCalls);
+  Writer.WritePCH(*SemaPtr, StatCalls, isysroot);
 
   // Write the generated bitstream to "Out".
   Out->write((char *)&Buffer.front(), Buffer.size());
@@ -73,6 +78,7 @@
 }
 
 ASTConsumer *clang::CreatePCHGenerator(const Preprocessor &PP,
-                                       llvm::raw_ostream *OS) {
-  return new PCHGenerator(PP, OS);
+                                       llvm::raw_ostream *OS,
+                                       const char *isysroot) {
+  return new PCHGenerator(PP, isysroot, OS);
 }