[lld] r268495 - Print the cpio trailer after every member.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 05:47:57 PDT 2016


Author: rafael
Date: Wed May  4 07:47:56 2016
New Revision: 268495

URL: http://llvm.org/viewvc/llvm-project?rev=268495&view=rev
Log:
Print the cpio trailer after every member.

This is both simpler and safer. If we crash at any point, there is a
valid cpio file to reproduce the crash.

Thanks to Rui for the suggestion.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/DriverUtils.cpp
    lld/trunk/ELF/Error.cpp
    lld/trunk/ELF/Error.h

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=268495&r1=268494&r2=268495&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed May  4 07:47:56 2016
@@ -493,8 +493,6 @@ template <class ELFT> void LinkerDriver:
   for (auto *Arg : Args.filtered(OPT_wrap))
     Symtab.wrap(Arg->getValue());
 
-  maybeCloseReproArchive();
-
   // Write the result to the file.
   if (Config->GcSections)
     markLive<ELFT>();

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=268495&r1=268494&r2=268495&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Wed May  4 07:47:56 2016
@@ -117,14 +117,8 @@ static std::string getDestPath(StringRef
   return Dest.str();
 }
 
-static void maybePrintCpioMember(StringRef Path, StringRef Data) {
-  if (Config->Reproduce.empty())
-    return;
-
-  if (!Driver->IncludedFiles.insert(Path).second)
-    return;
-
-  raw_fd_ostream &OS = *Driver->ReproduceArchive;
+static void maybePrintCpioMemberAux(raw_fd_ostream &OS, StringRef Path,
+                                    StringRef Data) {
   OS << "070707"; // c_magic
 
   // The c_dev/c_ino pair should be unique according to the spec, but no one
@@ -144,19 +138,28 @@ static void maybePrintCpioMember(StringR
   OS << Data;                            // c_filedata
 }
 
+static void maybePrintCpioMember(StringRef Path, StringRef Data) {
+  if (Config->Reproduce.empty())
+    return;
+
+  if (!Driver->IncludedFiles.insert(Path).second)
+    return;
+  raw_fd_ostream &OS = *Driver->ReproduceArchive;
+  maybePrintCpioMemberAux(OS, Path, Data);
+
+  // Print the trailer and seek back. This way we have a valid archive if we
+  // crash.
+  uint64_t Pos = OS.tell();
+  maybePrintCpioMemberAux(OS, "TRAILER!!!", "");
+  OS.seek(Pos);
+}
+
 // Write file Src with content Data to the archive.
 void elf::maybeCopyInputFile(StringRef Src, StringRef Data) {
   std::string Dest = getDestPath(Src);
   maybePrintCpioMember(Dest, Data);
 }
 
-void elf::maybeCloseReproArchive() {
-  if (!Driver->ReproduceArchive)
-    return;
-  maybePrintCpioMember("TRAILER!!!", "");
-  Driver->ReproduceArchive.reset();
-}
-
 // Quote a given string if it contains a space character.
 static std::string quote(StringRef S) {
   if (S.find(' ') == StringRef::npos)

Modified: lld/trunk/ELF/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=268495&r1=268494&r2=268495&view=diff
==============================================================================
--- lld/trunk/ELF/Error.cpp (original)
+++ lld/trunk/ELF/Error.cpp Wed May  4 07:47:56 2016
@@ -29,7 +29,6 @@ void warning(const Twine &Msg) { llvm::e
 void error(const Twine &Msg) {
   *ErrorOS << Msg << "\n";
   HasError = true;
-  maybeCloseReproArchive();
 }
 
 void error(std::error_code EC, const Twine &Prefix) {
@@ -39,7 +38,6 @@ void error(std::error_code EC, const Twi
 
 void fatal(const Twine &Msg) {
   llvm::errs() << Msg << "\n";
-  maybeCloseReproArchive();
   exit(1);
 }
 

Modified: lld/trunk/ELF/Error.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=268495&r1=268494&r2=268495&view=diff
==============================================================================
--- lld/trunk/ELF/Error.h (original)
+++ lld/trunk/ELF/Error.h Wed May  4 07:47:56 2016
@@ -18,8 +18,6 @@ namespace elf {
 extern bool HasError;
 extern llvm::raw_ostream *ErrorOS;
 
-void maybeCloseReproArchive();
-
 void log(const Twine &Msg);
 void warning(const Twine &Msg);
 




More information about the llvm-commits mailing list