[PATCH] D57479: [WebAssembly] MC: Fix for outputing wasm object to /dev/null

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 31 14:38:16 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL352806: [WebAssembly] MC: Fix for outputing wasm object to /dev/null (authored by sbc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D57479?vs=184581&id=184613#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57479/new/

https://reviews.llvm.org/D57479

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


Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp
@@ -398,7 +398,13 @@
 // 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");
 
Index: llvm/trunk/test/MC/WebAssembly/null-output.s
===================================================================
--- llvm/trunk/test/MC/WebAssembly/null-output.s
+++ llvm/trunk/test/MC/WebAssembly/null-output.s
@@ -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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57479.184613.patch
Type: text/x-patch
Size: 1285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190131/e485253e/attachment.bin>


More information about the llvm-commits mailing list