[llvm] r352806 - [WebAssembly] MC: Fix for outputing wasm object to /dev/null

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 31 14:38:23 PST 2019


Author: sbc
Date: Thu Jan 31 14:38:22 2019
New Revision: 352806

URL: http://llvm.org/viewvc/llvm-project?rev=352806&view=rev
Log:
[WebAssembly] MC: Fix for outputing wasm object to /dev/null

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

Differential Revision: https://reviews.llvm.org/D57479

Added:
    llvm/trunk/test/MC/WebAssembly/null-output.s
Modified:
    llvm/trunk/lib/MC/WasmObjectWriter.cpp

Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=352806&r1=352805&r2=352806&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Thu Jan 31 14:38:22 2019
@@ -398,7 +398,13 @@ void WasmObjectWriter::startCustomSectio
 // Now that the section is complete and we know how big it is, patch up the
 // section size field at the start of the section.
 void WasmObjectWriter::endSection(SectionBookkeeping &Section) {
-  uint64_t Size = W.OS.tell() - Section.PayloadOffset;
+  uint64_t Size = W.OS.tell();
+  // /dev/null doesn't support seek/tell and can report offset of 0.
+  // Simply skip this patching in that case.
+  if (!Size)
+    return;
+
+  Size -= Section.PayloadOffset;
   if (uint32_t(Size) != Size)
     report_fatal_error("section size does not fit in a uint32_t");
 

Added: llvm/trunk/test/MC/WebAssembly/null-output.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/null-output.s?rev=352806&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/null-output.s (added)
+++ llvm/trunk/test/MC/WebAssembly/null-output.s Thu Jan 31 14:38:22 2019
@@ -0,0 +1,10 @@
+# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -o /dev/null < %s
+
+    .text
+    .section .text.main,"",@
+    .type    main, at function
+main:
+    .functype   main (i32, i32) -> (i32)
+    end_function
+.Lfunc_end0:
+    .size main, .Lfunc_end0-main




More information about the llvm-commits mailing list