[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-30 Thread Sergey Dmitriev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc53cb2bdc78e: [Clang][Bundler] Reduce fat object size 
(authored by sdmitriev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
@@ -365,6 +364,41 @@
   }
 };
 
+namespace {
+
+// This class implements a list of temporary files that are removed upon
+// object destruction.
+class TempFileHandlerRAII {
+public:
+  ~TempFileHandlerRAII() {
+for (const auto &File : Files)
+  sys::fs::remove(File);
+  }
+
+  // Creates temporary file with given contents.
+  Expected Create(Optional> Contents) {
+SmallString<128u> File;
+if (std::error_code EC =
+sys::fs::createTemporaryFile("clang-offload-bundler", "tmp", File))
+  return createFileError(File, EC);
+Files.push_back(File);
+
+if (Contents) {
+  std::error_code EC;
+  raw_fd_ostream OS(File, EC);
+  if (EC)
+return createFileError(File, EC);
+  OS.write(Contents->data(), Contents->size());
+}
+return Files.back();
+  }
+
+private:
+  SmallVector, 4u> Files;
+};
+
+} // end anonymous namespace
+
 /// Handler for object files. The bundles are organized by sections with a
 /// designated name.
 ///
@@ -433,11 +467,16 @@
   Error ReadBundleEnd(MemoryBuffer &Input) final { return Error::success(); }
 
   Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
-Expected Content = CurrentSection->getContents();
-if (!Content)
-  return Content.takeError();
+Expected ContentOrErr = CurrentSection->getContents();
+if (!ContentOrErr)
+  return ContentOrErr.takeError();
+StringRef Content = *ContentOrErr;
+
+// Copy fat object contents to the output when extracting host bundle.
+if (Content.size() == 1u && Content.front() == 0)
+  Content = StringRef(Input.getBufferStart(), Input.getBufferSize());
 
-OS.write(Content->data(), Content->size());
+OS.write(Content.data(), Content.size());
 return Error::success();
   }
 
@@ -486,22 +525,37 @@
 // to pass down to llvm-objcopy.
 OS.close();
 
+// Temporary files that need to be removed.
+TempFileHandlerRAII TempFiles;
+
 // Create an intermediate temporary file to save object after the first
 // llvm-objcopy run.
-SmallString<128u> IntermediateObj;
-if (std::error_code EC = sys::fs::createTemporaryFile(
-"clang-offload-bundler", "tmp", IntermediateObj))
-  return createFileError(IntermediateObj, EC);
-FileRemover IntermediateObjRemover(IntermediateObj);
+Expected> IntermediateObjOrErr = TempFiles.Create(None);
+if (!IntermediateObjOrErr)
+  return IntermediateObjOrErr.takeError();
+const SmallString<128u> &IntermediateObj = *IntermediateObjOrErr;
 
 // Compose llvm-objcopy command line for add target objects' sections.
 BumpPtrAllocator Alloc;
 StringSaver SS{Alloc};
 SmallVector ObjcopyArgs{"llvm-objcopy"};
-for (unsigned I = 0; I < NumberOfInputs; ++I)
+for (unsigned I = 0; I < NumberOfInputs; ++I) {
+  StringRef InputFile = InputFileNames[I];
+  if (I == HostInputIndex) {
+// Special handling for the host bundle. We do not need to add a
+// standard bundle for the host object since we are going to use fat
+// object as a host object. Therefore use dummy contents (one zero byte)
+// when creating section for the host bundle.
+Expected TempFileOrErr = TempFiles.Create(ArrayRef(0));
+if (!TempFileOrErr)
+  return TempFileOrErr.takeError();
+InputFile = *TempFileOrErr;
+  }
+
   ObjcopyArgs.push_back(SS.save(Twine("--add-section=") +
 OFFLOAD_BUNDLER_MAGIC_STR + TargetNames[I] +
-"=" + InputFileNames[I]));
+"=" + InputFile));
+}
 ObjcopyArgs.push_back(InputFileNames[HostInputIndex]);
 ObjcopyArgs.push_back(IntermediateObj);
 
Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -253,16 +253,16 @@
 
 // RUN: clang-offload-bundler -type=o -targets=h

[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-30 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev added a comment.

@ABataev, do you have any additional comments?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-29 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev marked an inline comment as done.
sdmitriev added inline comments.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:378
+  // Creates temporary file with given contents.
+  Expected Create(Optional> Contents) {
+SmallString<128u> File;

ABataev wrote:
> I see that Contents is either `None` or just one byte `0`. Maybe, better to 
> use bool flag here instead of `Contents`?
Well, maybe we will need some other contents besides one zero byte in future, 
so I think having optional contents is probably better.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-29 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev updated this revision to Diff 241278.
sdmitriev added a comment.

Addressed review comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
@@ -365,6 +364,41 @@
   }
 };
 
+namespace {
+
+// This class implements a list of temporary files that are removed upon
+// object destruction.
+class TempFileHandlerRAII {
+public:
+  ~TempFileHandlerRAII() {
+for (const auto &File : Files)
+  sys::fs::remove(File);
+  }
+
+  // Creates temporary file with given contents.
+  Expected Create(Optional> Contents) {
+SmallString<128u> File;
+if (std::error_code EC =
+sys::fs::createTemporaryFile("clang-offload-bundler", "tmp", File))
+  return createFileError(File, EC);
+Files.push_back(File);
+
+if (Contents) {
+  std::error_code EC;
+  raw_fd_ostream OS(File, EC);
+  if (EC)
+return createFileError(File, EC);
+  OS.write(Contents->data(), Contents->size());
+}
+return Files.back();
+  }
+
+private:
+  SmallVector, 4u> Files;
+};
+
+} // end anonymous namespace
+
 /// Handler for object files. The bundles are organized by sections with a
 /// designated name.
 ///
@@ -433,11 +467,16 @@
   Error ReadBundleEnd(MemoryBuffer &Input) final { return Error::success(); }
 
   Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
-Expected Content = CurrentSection->getContents();
-if (!Content)
-  return Content.takeError();
+Expected ContentOrErr = CurrentSection->getContents();
+if (!ContentOrErr)
+  return ContentOrErr.takeError();
+StringRef Content = *ContentOrErr;
+
+// Copy fat object contents to the output when extracting host bundle.
+if (Content.size() == 1u && Content.front() == 0)
+  Content = StringRef(Input.getBufferStart(), Input.getBufferSize());
 
-OS.write(Content->data(), Content->size());
+OS.write(Content.data(), Content.size());
 return Error::success();
   }
 
@@ -486,22 +525,37 @@
 // to pass down to llvm-objcopy.
 OS.close();
 
+// Temporary files that need to be removed.
+TempFileHandlerRAII TempFiles;
+
 // Create an intermediate temporary file to save object after the first
 // llvm-objcopy run.
-SmallString<128u> IntermediateObj;
-if (std::error_code EC = sys::fs::createTemporaryFile(
-"clang-offload-bundler", "tmp", IntermediateObj))
-  return createFileError(IntermediateObj, EC);
-FileRemover IntermediateObjRemover(IntermediateObj);
+Expected> IntermediateObjOrErr = TempFiles.Create(None);
+if (!IntermediateObjOrErr)
+  return IntermediateObjOrErr.takeError();
+const SmallString<128u> &IntermediateObj = *IntermediateObjOrErr;
 
 // Compose llvm-objcopy command line for add target objects' sections.
 BumpPtrAllocator Alloc;
 StringSaver SS{Alloc};
 SmallVector ObjcopyArgs{"llvm-objcopy"};
-for (unsigned I = 0; I < NumberOfInputs; ++I)
+for (unsigned I = 0; I < NumberOfInputs; ++I) {
+  StringRef InputFile = InputFileNames[I];
+  if (I == HostInputIndex) {
+// Special handling for the host bundle. We do not need to add a
+// standard bundle for the host object since we are going to use fat
+// object as a host object. Therefore use dummy contents (one zero byte)
+// when creating section for the host bundle.
+Expected TempFileOrErr = TempFiles.Create(ArrayRef(0));
+if (!TempFileOrErr)
+  return TempFileOrErr.takeError();
+InputFile = *TempFileOrErr;
+  }
+
   ObjcopyArgs.push_back(SS.save(Twine("--add-section=") +
 OFFLOAD_BUNDLER_MAGIC_STR + TargetNames[I] +
-"=" + InputFileNames[I]));
+"=" + InputFile));
+}
 ObjcopyArgs.push_back(InputFileNames[HostInputIndex]);
 ObjcopyArgs.push_back(IntermediateObj);
 
Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -253,16 +253,16 @@
 
 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.

[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-29 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:371
+// object destruction.
+struct TempFileList {
+  ~TempFileList() {

If you have `private` members, it should be a class. Also, seems to me it is a 
RAII class. Better to name it something like `TempFileHandlerRAII` or something 
like this.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:378
+  // Creates temporary file with given contents.
+  Expected Create(Optional> Contents) {
+SmallString<128u> File;

I see that Contents is either `None` or just one byte `0`. Maybe, better to use 
bool flag here instead of `Contents`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-29 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev updated this revision to Diff 241269.
sdmitriev added a comment.

Addressed review comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
@@ -365,6 +364,40 @@
   }
 };
 
+namespace {
+
+// This structure implements a list of temporary files that are removed upon
+// object destruction.
+struct TempFileList {
+  ~TempFileList() {
+for (const auto &File : Files)
+  sys::fs::remove(File);
+  }
+
+  // Creates temporary file with given contents.
+  Expected Create(Optional> Contents) {
+SmallString<128u> File;
+if (std::error_code EC =
+sys::fs::createTemporaryFile("clang-offload-bundler", "tmp", File))
+  return createFileError(File, EC);
+Files.push_back(File);
+
+if (Contents) {
+  std::error_code EC;
+  raw_fd_ostream OS(File, EC);
+  if (EC)
+return createFileError(File, EC);
+  OS.write(Contents->data(), Contents->size());
+}
+return Files.back();
+  }
+
+private:
+  SmallVector, 4u> Files;
+};
+
+} // end anonymous namespace
+
 /// Handler for object files. The bundles are organized by sections with a
 /// designated name.
 ///
@@ -433,11 +466,16 @@
   Error ReadBundleEnd(MemoryBuffer &Input) final { return Error::success(); }
 
   Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
-Expected Content = CurrentSection->getContents();
-if (!Content)
-  return Content.takeError();
+Expected ContentOrErr = CurrentSection->getContents();
+if (!ContentOrErr)
+  return ContentOrErr.takeError();
+StringRef Content = *ContentOrErr;
+
+// Copy fat object contents to the output when extracting host bundle.
+if (Content.size() == 1u && Content.front() == 0)
+  Content = StringRef(Input.getBufferStart(), Input.getBufferSize());
 
-OS.write(Content->data(), Content->size());
+OS.write(Content.data(), Content.size());
 return Error::success();
   }
 
@@ -486,22 +524,37 @@
 // to pass down to llvm-objcopy.
 OS.close();
 
+// Temporary files that need to be removed.
+TempFileList TempFiles;
+
 // Create an intermediate temporary file to save object after the first
 // llvm-objcopy run.
-SmallString<128u> IntermediateObj;
-if (std::error_code EC = sys::fs::createTemporaryFile(
-"clang-offload-bundler", "tmp", IntermediateObj))
-  return createFileError(IntermediateObj, EC);
-FileRemover IntermediateObjRemover(IntermediateObj);
+Expected> IntermediateObjOrErr = TempFiles.Create(None);
+if (!IntermediateObjOrErr)
+  return IntermediateObjOrErr.takeError();
+const SmallString<128u> &IntermediateObj = *IntermediateObjOrErr;
 
 // Compose llvm-objcopy command line for add target objects' sections.
 BumpPtrAllocator Alloc;
 StringSaver SS{Alloc};
 SmallVector ObjcopyArgs{"llvm-objcopy"};
-for (unsigned I = 0; I < NumberOfInputs; ++I)
+for (unsigned I = 0; I < NumberOfInputs; ++I) {
+  StringRef InputFile = InputFileNames[I];
+  if (I == HostInputIndex) {
+// Special handling for the host bundle. We do not need to add a
+// standard bundle for the host object since we are going to use fat
+// object as a host object. Therefore use dummy contents (one zero byte)
+// when creating section for the host bundle.
+Expected TempFileOrErr = TempFiles.Create(ArrayRef(0));
+if (!TempFileOrErr)
+  return TempFileOrErr.takeError();
+InputFile = *TempFileOrErr;
+  }
+
   ObjcopyArgs.push_back(SS.save(Twine("--add-section=") +
 OFFLOAD_BUNDLER_MAGIC_STR + TargetNames[I] +
-"=" + InputFileNames[I]));
+"=" + InputFile));
+}
 ObjcopyArgs.push_back(InputFileNames[HostInputIndex]);
 ObjcopyArgs.push_back(IntermediateObj);
 
Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -253,16 +253,16 @@
 
 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.

[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-29 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:493-518
+// Temporary files that need to be removed.
+struct TempFileList : public SmallVector, 2u> {
+  ~TempFileList() {
+for (const auto &File : *this)
+  sys::fs::remove(File);
+clear();
+  }

We usually don't do this. New types must be declared outside in anonymous 
namespaces. Also, better to use `part-of` inheritance rather than `is-a` here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73642/new/

https://reviews.llvm.org/D73642



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73642: [Clang][Bundler] Reduce fat object size

2020-01-29 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev created this revision.
sdmitriev added a reviewer: ABataev.
Herald added a reviewer: alexshap.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fat object size has significantly increased after D65819 
 which changed bundler tool to add host object 
as a normal bundle to the fat output which almost doubled its size. That patch 
was fixing the following issues

1. Problems associated with the partial linking - global constructors were not 
called for partially linking objects which clearly resulted in incorrect 
behavior.
2. Eliminating "junk" target object sections from the linked binary on the host 
side.

The first problem is no longer relevant because we do not use partial linking 
for creating fat objects anymore. Target objects sections are now inserted into 
the resulting fat object with a help of llvm-objcopy tool.

The second issue, "junk" sections in the linked host binary, has been fixed in 
D73408  by adding "exclude" flag to the fat 
object's sections which contain target objects. This flag tells linker to drop 
section from the inputs when linking executable or shared library, therefore 
these sections will not be propagated in the linked binary.

Since both problems have been solved, we can revert D65819 
 changes to reduce fat object size and this 
patch essentially is doing that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73642

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
@@ -433,11 +432,16 @@
   Error ReadBundleEnd(MemoryBuffer &Input) final { return Error::success(); }
 
   Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
-Expected Content = CurrentSection->getContents();
-if (!Content)
-  return Content.takeError();
+Expected ContentOrErr = CurrentSection->getContents();
+if (!ContentOrErr)
+  return ContentOrErr.takeError();
+StringRef Content = *ContentOrErr;
 
-OS.write(Content->data(), Content->size());
+// Copy fat object contents to the output when extracting host bundle.
+if (Content.size() == 1u && Content.front() == 0)
+  Content = StringRef(Input.getBufferStart(), Input.getBufferSize());
+
+OS.write(Content.data(), Content.size());
 return Error::success();
   }
 
@@ -486,22 +490,60 @@
 // to pass down to llvm-objcopy.
 OS.close();
 
+// Temporary files that need to be removed.
+struct TempFileList : public SmallVector, 2u> {
+  ~TempFileList() {
+for (const auto &File : *this)
+  sys::fs::remove(File);
+clear();
+  }
+
+  Expected Create(Optional> Contents) {
+SmallString<128u> FileName;
+if (std::error_code EC = sys::fs::createTemporaryFile(
+"clang-offload-bundler", "tmp", FileName))
+  return createFileError(FileName, EC);
+push_back(FileName);
+
+if (Contents) {
+  std::error_code EC;
+  raw_fd_ostream HostFile(FileName, EC);
+  if (EC)
+return createFileError(FileName, EC);
+  HostFile.write(Contents->data(), Contents->size());
+}
+return back();
+  }
+} TempFiles;
+
 // Create an intermediate temporary file to save object after the first
 // llvm-objcopy run.
-SmallString<128u> IntermediateObj;
-if (std::error_code EC = sys::fs::createTemporaryFile(
-"clang-offload-bundler", "tmp", IntermediateObj))
-  return createFileError(IntermediateObj, EC);
-FileRemover IntermediateObjRemover(IntermediateObj);
+Expected> IntermediateObjOrErr = TempFiles.Create(None);
+if (!IntermediateObjOrErr)
+  return IntermediateObjOrErr.takeError();
+const SmallString<128u> &IntermediateObj = *IntermediateObjOrErr;
 
 // Compose llvm-objcopy command line for add target objects' sections.
 BumpPtrAllocator Alloc;
 StringSaver SS{Alloc};
 SmallVector ObjcopyArgs{"llvm-objcopy"};
-for (unsigned I = 0; I < NumberOfInputs; ++I)
+for (unsigned I = 0; I < NumberOfInputs; ++I) {
+  StringRef InputFile = InputFileNames[I];
+  if (I == HostInputIndex) {
+// Special handling for the host bundle. We do not need to add a
+// standard bundle for the host object since we are going to use fat
+