- raw_fd_ostream OS(FD, true);
- formatted_raw_ostream FOS(OS);
+ // Open a file descriptor for each backend thread. This is done in a block
+ // so that the output file descriptors are closed before gold opens them.
+ std::list<llvm::raw_fd_ostream> OSs;
+ std::vector<llvm::raw_pwrite_stream *> OSPtrs(options::Parallelism);
+ for (unsigned I = 0; I != options::Parallelism; ++I) {
+ int FD;
+ if (TempOutFile) {
+ std::error_code EC =
+ sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filenames[I]);
+ if (EC)
+ message(LDPL_FATAL, "Could not create temporary file: %s",
+ EC.message().c_str());
+ } else {
+ Filenames[I] = Filename;
+ if (options::Parallelism != 1)
+ Filenames[I] += utostr(I);
+ std::error_code EC =
+ sys::fs::openFileForWrite(Filenames[I], FD, sys::fs::F_None);
+ if (EC)
+ message(LDPL_FATAL, "Could not open file: %s", EC.message().c_str());
+ }
+ OSs.emplace_back(FD, true);
+ OSPtrs[I] = &OSs.back();
+ }