[PATCH] D67696: [tools] Mark output of tools as text if it is really text

Kai Nacke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 01:15:22 PDT 2019


Kai created this revision.
Kai added reviewers: rnk, vivekvpandya, Bigcheese, andreadb.
Herald added subscribers: llvm-commits, dexonsmith, gbedwell, hiraditya, aprantl.
Herald added a project: LLVM.

Several LLVM tools write text files/streams without using OF_Text.
This can cause problems on platforms which distinguish between
text and binary output. This PR adds the OF_Text flag for the
following tools:

- llvm-dis
- llvm-dwarfdump
- llvm-mca
- llvm-mc (assembler files only)
- RemarkStreamer (used e.g. by opt)

Most notably, llc already makes the distinction between text and binary output.


Repository:
  rL LLVM

https://reviews.llvm.org/D67696

Files:
  llvm/lib/IR/RemarkStreamer.cpp
  llvm/tools/llvm-dis/llvm-dis.cpp
  llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-mca/llvm-mca.cpp


Index: llvm/tools/llvm-mca/llvm-mca.cpp
===================================================================
--- llvm/tools/llvm-mca/llvm-mca.cpp
+++ llvm/tools/llvm-mca/llvm-mca.cpp
@@ -233,7 +233,7 @@
     OutputFilename = "-";
   std::error_code EC;
   auto Out =
-      std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_None);
+      std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_Text);
   if (!EC)
     return std::move(Out);
   return EC;
Index: llvm/tools/llvm-mc/llvm-mc.cpp
===================================================================
--- llvm/tools/llvm-mc/llvm-mc.cpp
+++ llvm/tools/llvm-mc/llvm-mc.cpp
@@ -209,9 +209,10 @@
   return TheTarget;
 }
 
-static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path) {
+static std::unique_ptr<ToolOutputFile> GetOutputStream(
+    StringRef Path, sys::fs::OpenFlags Flags) {
   std::error_code EC;
-  auto Out = std::make_unique<ToolOutputFile>(Path, EC, sys::fs::OF_None);
+  auto Out = std::make_unique<ToolOutputFile>(Path, EC, Flags);
   if (EC) {
     WithColor::error() << EC.message() << '\n';
     return nullptr;
@@ -413,7 +414,9 @@
     FeaturesStr = Features.getString();
   }
 
-  std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename);
+  sys::fs::OpenFlags Flags = (FileType == OFT_AssemblyFile) ? sys::fs::OF_Text
+                                                            : sys::fs::F_None;
+  std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename, Flags);
   if (!Out)
     return 1;
 
@@ -423,7 +426,7 @@
       WithColor::error() << "dwo output only supported with object files\n";
       return 1;
     }
-    DwoOut = GetOutputStream(SplitDwarfFile);
+    DwoOut = GetOutputStream(SplitDwarfFile, sys::fs::F_None);
     if (!DwoOut)
       return 1;
   }
Index: llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
===================================================================
--- llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -584,7 +584,7 @@
   }
 
   std::error_code EC;
-  ToolOutputFile OutputFile(OutputFilename, EC, sys::fs::OF_None);
+  ToolOutputFile OutputFile(OutputFilename, EC, sys::fs::OF_Text);
   error("Unable to open output file" + OutputFilename, EC);
   // Don't remove output file if we exit with an error.
   OutputFile.keep();
Index: llvm/tools/llvm-dis/llvm-dis.cpp
===================================================================
--- llvm/tools/llvm-dis/llvm-dis.cpp
+++ llvm/tools/llvm-dis/llvm-dis.cpp
@@ -186,7 +186,7 @@
 
   std::error_code EC;
   std::unique_ptr<ToolOutputFile> Out(
-      new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
+      new ToolOutputFile(OutputFilename, EC, sys::fs::OF_Text));
   if (EC) {
     errs() << EC.message() << '\n';
     return 1;
Index: llvm/lib/IR/RemarkStreamer.cpp
===================================================================
--- llvm/lib/IR/RemarkStreamer.cpp
+++ llvm/lib/IR/RemarkStreamer.cpp
@@ -126,7 +126,7 @@
 
   std::error_code EC;
   auto RemarksFile =
-      std::make_unique<ToolOutputFile>(RemarksFilename, EC, sys::fs::OF_None);
+      std::make_unique<ToolOutputFile>(RemarksFilename, EC, sys::fs::OF_Text);
   // We don't use llvm::FileError here because some diagnostics want the file
   // name separately.
   if (EC)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67696.220618.patch
Type: text/x-patch
Size: 3338 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190918/59c61d63/attachment.bin>


More information about the llvm-commits mailing list