Index: lld/ELF/MapFile.cpp =================================================================== --- lld/ELF/MapFile.cpp +++ lld/ELF/MapFile.cpp @@ -25,7 +25,7 @@ #include "InputFiles.h" #include "Strings.h" -#include "llvm/Support/FileUtilities.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace llvm::object; @@ -33,28 +33,28 @@ using namespace lld; using namespace lld::elf; -static void writeOutSecLine(raw_fd_ostream &OS, int Width, uint64_t Address, +static void writeOutSecLine(raw_ostream &OS, int Width, uint64_t Address, uint64_t Size, uint64_t Align, StringRef Name) { OS << format_hex_no_prefix(Address, Width) << ' ' << format_hex_no_prefix(Size, Width) << ' ' << format("%5x ", Align) << left_justify(Name, 7); } -static void writeInSecLine(raw_fd_ostream &OS, int Width, uint64_t Address, +static void writeInSecLine(raw_ostream &OS, int Width, uint64_t Address, uint64_t Size, uint64_t Align, StringRef Name) { // Pass an empty name to align the text to the correct column. writeOutSecLine(OS, Width, Address, Size, Align, ""); OS << ' ' << left_justify(Name, 7); } -static void writeFileLine(raw_fd_ostream &OS, int Width, uint64_t Address, +static void writeFileLine(raw_ostream &OS, int Width, uint64_t Address, uint64_t Size, uint64_t Align, StringRef Name) { // Pass an empty name to align the text to the correct column. writeInSecLine(OS, Width, Address, Size, Align, ""); OS << ' ' << left_justify(Name, 7); } -static void writeSymbolLine(raw_fd_ostream &OS, int Width, uint64_t Address, +static void writeSymbolLine(raw_ostream &OS, int Width, uint64_t Address, uint64_t Size, StringRef Name) { // Pass an empty name to align the text to the correct column. writeFileLine(OS, Width, Address, Size, 0, ""); @@ -62,7 +62,7 @@ } template -static void writeInputSection(raw_fd_ostream &OS, const InputSection *IS, +static void writeInputSection(raw_ostream &OS, const InputSection *IS, StringRef &PrevName) { int Width = ELFT::Is64Bits ? 16 : 8; StringRef Name = IS->Name; @@ -95,9 +95,8 @@ } template -static void writeMapFile2(int FD, +static void writeMapFile2(raw_ostream &OS, ArrayRef OutputSections) { - raw_fd_ostream OS(FD, true); int Width = ELFT::Is64Bits ? 16 : 8; OS << left_justify("Address", Width) << ' ' << left_justify("Size", Width) @@ -119,22 +118,14 @@ template void elf::writeMapFile(ArrayRef OutputSections) { - StringRef MapFile = Config->MapFile; - if (MapFile.empty()) + if (Config->MapFile.empty()) return; - // Create new file in same directory but with random name. - SmallString<128> TempPath; - int FD; - std::error_code EC = - sys::fs::createUniqueFile(Twine(MapFile) + ".tmp%%%%%%%", FD, TempPath); + std::error_code EC; + raw_fd_ostream OS(Config->MapFile, EC, sys::fs::F_None); if (EC) - fatal(EC.message()); - FileRemover RAII(TempPath); - writeMapFile2(FD, OutputSections); - EC = sys::fs::rename(TempPath, MapFile); - if (EC) - fatal(EC.message()); + fatal("cannot open " + Config->MapFile + ": " + EC.message()); + writeMapFile2(OS, OutputSections); } template void elf::writeMapFile(ArrayRef);