From fc0981ecbc83809ca8f2157fb7408150f63fa978 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Wed, 18 Nov 2015 15:24:17 +0000 Subject: [PATCH] Fix bug where WinCOFFObjectWriter would assume starting from an empty output. Starting on an input stream that is not at offset 0 would trigger the assert in WinCOFFObjectWriter.cpp:1065: assert(getStream().tell() <= (*i)->Header.PointerToRawData && "Section::PointerToRawData is insane!"); git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253464 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCObjectWriter.h | 4 ++++ lib/MC/WinCOFFObjectWriter.cpp | 2 +- test/MC/COFF/stdin.s | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/MC/COFF/stdin.s diff --git a/include/llvm/MC/MCObjectWriter.h b/include/llvm/MC/MCObjectWriter.h index ed1f493d74e..63c833ac20d 100644 --- a/include/llvm/MC/MCObjectWriter.h +++ b/include/llvm/MC/MCObjectWriter.h @@ -49,6 +49,10 @@ protected: // Can only create subclasses. MCObjectWriter(raw_pwrite_stream &OS, bool IsLittleEndian) : OS(&OS), IsLittleEndian(IsLittleEndian) {} + unsigned getInitialOffset() { + return OS->tell(); + } + public: virtual ~MCObjectWriter(); diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index 7eb470353b7..875a61425f1 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -962,7 +962,7 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm, // Assign file offsets to COFF object file structures. - unsigned offset = 0; + unsigned offset = getInitialOffset(); if (UseBigObj) offset += COFF::Header32Size; diff --git a/test/MC/COFF/stdin.s b/test/MC/COFF/stdin.s new file mode 100644 index 00000000000..9a22da5488e --- /dev/null +++ b/test/MC/COFF/stdin.s @@ -0,0 +1,3 @@ +// REQUIRES: shell +// RUN: ( echo "test"; llvm-mc -filetype=obj -triple i686-pc-win32 %s ) > %t + -- 2.34.1