<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 4, 2016 at 5:47 AM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Author: rafael<br>
Date: Wed May  4 07:47:56 2016<br>
New Revision: 268495<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=268495&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=268495&view=rev</a><br>
Log:<br>
Print the cpio trailer after every member.<br>
<br>
This is both simpler and safer. If we crash at any point, there is a<br>
valid cpio file to reproduce the crash.<br>
<br>
Thanks to Rui for the suggestion.<br>
<br>
Modified:<br>
    lld/trunk/ELF/Driver.cpp<br>
    lld/trunk/ELF/DriverUtils.cpp<br>
    lld/trunk/ELF/Error.cpp<br>
    lld/trunk/ELF/Error.h<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=268495&r1=268494&r2=268495&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=268495&r1=268494&r2=268495&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Wed May  4 07:47:56 2016<br>
@@ -493,8 +493,6 @@ template <class ELFT> void LinkerDriver:<br>
   for (auto *Arg : Args.filtered(OPT_wrap))<br>
     Symtab.wrap(Arg->getValue());<br>
<br>
-  maybeCloseReproArchive();<br>
-<br>
   // Write the result to the file.<br>
   if (Config->GcSections)<br>
     markLive<ELFT>();<br>
<br>
Modified: lld/trunk/ELF/DriverUtils.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=268495&r1=268494&r2=268495&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=268495&r1=268494&r2=268495&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/DriverUtils.cpp (original)<br>
+++ lld/trunk/ELF/DriverUtils.cpp Wed May  4 07:47:56 2016<br>
@@ -117,14 +117,8 @@ static std::string getDestPath(StringRef<br>
   return Dest.str();<br>
 }<br>
<br>
-static void maybePrintCpioMember(StringRef Path, StringRef Data) {<br>
-  if (Config->Reproduce.empty())<br>
-    return;<br>
-<br>
-  if (!Driver->IncludedFiles.insert(Path).second)<br>
-    return;<br>
-<br>
-  raw_fd_ostream &OS = *Driver->ReproduceArchive;<br>
+static void maybePrintCpioMemberAux(raw_fd_ostream &OS, StringRef Path,<br>
+                                    StringRef Data) {<br>
   OS << "070707"; // c_magic<br>
<br>
   // The c_dev/c_ino pair should be unique according to the spec, but no one<br>
@@ -144,19 +138,28 @@ static void maybePrintCpioMember(StringR<br>
   OS << Data;                            // c_filedata<br>
 }<br>
<br>
+static void maybePrintCpioMember(StringRef Path, StringRef Data) {<br>
+  if (Config->Reproduce.empty())<br>
+    return;<br>
+<br>
+  if (!Driver->IncludedFiles.insert(Path).second)<br>
+    return;<br>
+  raw_fd_ostream &OS = *Driver->ReproduceArchive;<br>
+  maybePrintCpioMemberAux(OS, Path, Data);<br>
+<br>
+  // Print the trailer and seek back. This way we have a valid archive if we<br>
+  // crash.<br>
+  uint64_t Pos = OS.tell();<br>
+  maybePrintCpioMemberAux(OS, "TRAILER!!!", "");<br></blockquote><div><br></div><div>Is it 2 or 3 exclamation points? The first source I find <a href="https://www.mkssoftware.com/docs/man4/cpio.4.asp">https://www.mkssoftware.com/docs/man4/cpio.4.asp</a> claims the trailer has two exclamation points. Do you have a specific CPIO spec that you used and could link?</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
+  OS.seek(Pos);<br>
+}<br>
+<br>
 // Write file Src with content Data to the archive.<br>
 void elf::maybeCopyInputFile(StringRef Src, StringRef Data) {<br>
   std::string Dest = getDestPath(Src);<br>
   maybePrintCpioMember(Dest, Data);<br>
 }<br>
<br>
-void elf::maybeCloseReproArchive() {<br>
-  if (!Driver->ReproduceArchive)<br>
-    return;<br>
-  maybePrintCpioMember("TRAILER!!!", "");<br>
-  Driver->ReproduceArchive.reset();<br>
-}<br>
-<br>
 // Quote a given string if it contains a space character.<br>
 static std::string quote(StringRef S) {<br>
   if (S.find(' ') == StringRef::npos)<br>
<br>
Modified: lld/trunk/ELF/Error.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=268495&r1=268494&r2=268495&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=268495&r1=268494&r2=268495&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Error.cpp (original)<br>
+++ lld/trunk/ELF/Error.cpp Wed May  4 07:47:56 2016<br>
@@ -29,7 +29,6 @@ void warning(const Twine &Msg) { llvm::e<br>
 void error(const Twine &Msg) {<br>
   *ErrorOS << Msg << "\n";<br>
   HasError = true;<br>
-  maybeCloseReproArchive();<br>
 }<br>
<br>
 void error(std::error_code EC, const Twine &Prefix) {<br>
@@ -39,7 +38,6 @@ void error(std::error_code EC, const Twi<br>
<br>
 void fatal(const Twine &Msg) {<br>
   llvm::errs() << Msg << "\n";<br>
-  maybeCloseReproArchive();<br>
   exit(1);<br>
 }<br>
<br>
<br>
Modified: lld/trunk/ELF/Error.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=268495&r1=268494&r2=268495&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=268495&r1=268494&r2=268495&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Error.h (original)<br>
+++ lld/trunk/ELF/Error.h Wed May  4 07:47:56 2016<br>
@@ -18,8 +18,6 @@ namespace elf {<br>
 extern bool HasError;<br>
 extern llvm::raw_ostream *ErrorOS;<br>
<br>
-void maybeCloseReproArchive();<br>
-<br>
 void log(const Twine &Msg);<br>
 void warning(const Twine &Msg);<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>