From: Sam Clegg Date: Thu, 31 Jan 2019 22:38:22 +0000 (+0000) Subject: [WebAssembly] MC: Fix for outputing wasm object to /dev/null X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9edb74e0f28c21d102e489784db801f05f00d965;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352806 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/MC/WasmObjectWriter.cpp b/lib/MC/WasmObjectWriter.cpp index d0ffe7c4a40..83ac9a44dc4 100644 --- a/lib/MC/WasmObjectWriter.cpp +++ b/lib/MC/WasmObjectWriter.cpp @@ -398,7 +398,13 @@ void WasmObjectWriter::startCustomSection(SectionBookkeeping &Section, // 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"); diff --git a/test/MC/WebAssembly/null-output.s b/test/MC/WebAssembly/null-output.s new file mode 100644 index 00000000000..a25d095e0cb --- /dev/null +++ b/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,@function +main: + .functype main (i32, i32) -> (i32) + end_function +.Lfunc_end0: + .size main, .Lfunc_end0-main