Skip to content

Commit 4b1712f

Browse files
committed
Merging r352806:
------------------------------------------------------------------------ r352806 | sbc | 2019-01-31 14:38:22 -0800 (Thu, 31 Jan 2019) | 5 lines [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 ------------------------------------------------------------------------ llvm-svn: 360949
1 parent 05288f5 commit 4b1712f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: llvm/lib/MC/WasmObjectWriter.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,13 @@ void WasmObjectWriter::startCustomSection(SectionBookkeeping &Section,
368368
// Now that the section is complete and we know how big it is, patch up the
369369
// section size field at the start of the section.
370370
void WasmObjectWriter::endSection(SectionBookkeeping &Section) {
371-
uint64_t Size = W.OS.tell() - Section.PayloadOffset;
371+
uint64_t Size = W.OS.tell();
372+
// /dev/null doesn't support seek/tell and can report offset of 0.
373+
// Simply skip this patching in that case.
374+
if (!Size)
375+
return;
376+
377+
Size -= Section.PayloadOffset;
372378
if (uint32_t(Size) != Size)
373379
report_fatal_error("section size does not fit in a uint32_t");
374380

Diff for: llvm/test/MC/WebAssembly/null-output.s

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -o /dev/null < %s
2+
3+
.text
4+
.section .text.main,"",@
5+
.type main,@function
6+
main:
7+
.functype main (i32, i32) -> (i32)
8+
end_function
9+
.Lfunc_end0:
10+
.size main, .Lfunc_end0-main

0 commit comments

Comments
 (0)