Skip to content

Commit c0affde

Browse files
committed
[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: 352806
1 parent d16ca2f commit c0affde

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/lib/MC/WasmObjectWriter.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,13 @@ void WasmObjectWriter::startCustomSection(SectionBookkeeping &Section,
398398
// Now that the section is complete and we know how big it is, patch up the
399399
// section size field at the start of the section.
400400
void WasmObjectWriter::endSection(SectionBookkeeping &Section) {
401-
uint64_t Size = W.OS.tell() - Section.PayloadOffset;
401+
uint64_t Size = W.OS.tell();
402+
// /dev/null doesn't support seek/tell and can report offset of 0.
403+
// Simply skip this patching in that case.
404+
if (!Size)
405+
return;
406+
407+
Size -= Section.PayloadOffset;
402408
if (uint32_t(Size) != Size)
403409
report_fatal_error("section size does not fit in a uint32_t");
404410

+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)