Index: lib/MC/WasmObjectWriter.cpp =================================================================== --- lib/MC/WasmObjectWriter.cpp +++ lib/MC/WasmObjectWriter.cpp @@ -398,8 +398,14 @@ // 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; - if (uint32_t(Size) != Size) + 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 (Size && uint32_t(Size) != Size) report_fatal_error("section size does not fit in a uint32_t"); LLVM_DEBUG(dbgs() << "endSection size=" << Size << "\n"); Index: test/MC/WebAssembly/null-output.s =================================================================== --- /dev/null +++ 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