diff options
-rw-r--r-- | lld/ELF/Driver.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/DriverUtils.cpp | 33 | ||||
-rw-r--r-- | lld/ELF/Error.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Error.h | 2 |
4 files changed, 18 insertions, 21 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 9bfb1219d26..a1c82954d1c 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -493,8 +493,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { for (auto *Arg : Args.filtered(OPT_wrap)) Symtab.wrap(Arg->getValue()); - maybeCloseReproArchive(); - // Write the result to the file. if (Config->GcSections) markLive<ELFT>(); diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index 621dfb934ec..179b8b79caf 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -117,14 +117,8 @@ static std::string getDestPath(StringRef Path) { 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(StringRef Path, StringRef Data) { 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) diff --git a/lld/ELF/Error.cpp b/lld/ELF/Error.cpp index 9823082ad6f..991ec97d056 100644 --- a/lld/ELF/Error.cpp +++ b/lld/ELF/Error.cpp @@ -29,7 +29,6 @@ void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; } 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 Twine &Prefix) { void fatal(const Twine &Msg) { llvm::errs() << Msg << "\n"; - maybeCloseReproArchive(); exit(1); } diff --git a/lld/ELF/Error.h b/lld/ELF/Error.h index bf7e5e7d8ae..45d9113cbd8 100644 --- a/lld/ELF/Error.h +++ b/lld/ELF/Error.h @@ -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); |