Fix bug where WinCOFFObjectWriter would assume starting from an empty output.
authorManuel Klimek <klimek@google.com>
Wed, 18 Nov 2015 15:24:17 +0000 (15:24 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 18 Nov 2015 15:24:17 +0000 (15:24 +0000)
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
lib/MC/WinCOFFObjectWriter.cpp
test/MC/COFF/stdin.s [new file with mode: 0644]

index ed1f493d74e79c2dcd56626e3c539dfc1f4471f9..63c833ac20d6d09543880af10238c7e37f2ad914 100644 (file)
@@ -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();
 
index 7eb470353b7c4c92956f310c2a2c51e95a7b08ac..875a61425f13733f5cdc88dd1db0465819d93f19 100644 (file)
@@ -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 (file)
index 0000000..9a22da5
--- /dev/null
@@ -0,0 +1,3 @@
+// REQUIRES: shell
+// RUN: ( echo "test"; llvm-mc -filetype=obj -triple i686-pc-win32 %s ) > %t
+