Sefault in llvm-mc when emitting an object file

Hello,

I'm trying to use MC to assemble some code into a memory buffer.
Whilst trying this, I ran into a segfault that I was able to reproduce
using the llvm-mc tool (which makes me think it's not just me using
the library incorrectly.)

The bug looks like this (the binary is from a clean build of the 2.8 release):

$ cat test/asm1.s
movl %ebx, %eax

$ ~/root/bin/llvm-mc --filetype=obj test/asm1.s
0 libLLVM-2.8.so 0xb7374ce8
Stack dump:
0. Program arguments: /home/matt/root/bin/llvm-mc --filetype=obj test/asm1.s
Segmentation fault

$ gdb ~/root/bin/llvm-mc
Reading symbols from /home/matt/root/bin/llvm-mc...done.
(gdb) r --filetype=obj test/asm1.s
Starting program: /home/matt/root/bin/llvm-mc --filetype=obj test/asm1.s
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
__memmove_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:160
160 ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S: No such file or directory.
  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
(gdb) bt
#0 __memmove_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:160
#1 0xb785d086 in __copy_m<char> (this=0x806fae8, Asm=..., Layout=...)
    at /usr/include/c++/4.5/bits/stl_algobase.h:386
#2 __copy_move_a<false, char const*, char*> (this=0x806fae8, Asm=...,
Layout=...)
    at /usr/include/c++/4.5/bits/stl_algobase.h:404
#3 __copy_move_a2<false, char const*, char*> (this=0x806fae8,
Asm=..., Layout=...)
    at /usr/include/c++/4.5/bits/stl_algobase.h:442
#4 copy<char const*, char*> (this=0x806fae8, Asm=..., Layout=...)
    at /usr/include/c++/4.5/bits/stl_algobase.h:474
#5 uninitialized_copy<char const*, char*> (this=0x806fae8, Asm=..., Layout=...)
    at /usr/include/c++/4.5/bits/stl_uninitialized.h:92
#6 uninitialized_copy<char const*, char*> (this=0x806fae8, Asm=..., Layout=...)
    at /usr/include/c++/4.5/bits/stl_uninitialized.h:116
#7 append<char const*> (this=0x806fae8, Asm=..., Layout=...)
    at /home/matt/src/llvm-2.8/include/llvm/ADT/SmallVector.h:364
#8 operator+= (this=0x806fae8, Asm=..., Layout=...)
    at /home/matt/src/llvm-2.8/include/llvm/ADT/SmallString.h:57
#9 (anonymous namespace)::ELFObjectWriterImpl::CreateMetadataSections (
    this=0x806fae8, Asm=..., Layout=...) at ELFObjectWriter.cpp:821
#10 0xb785f09d in WriteObject (this=0x806fad0, Asm=..., Layout=...)
    at ELFObjectWriter.cpp:831
#11 llvm::ELFObjectWriter::WriteObject (this=0x806fad0, Asm=..., Layout=...)
---Type <return> to continue, or q <return> to quit---
    at ELFObjectWriter.cpp:972
#12 0xb786c71a in llvm::MCAssembler::Finish (this=0x80737f0, Writer=0x806fad0)
    at MCAssembler.cpp:816
#13 0xb786f586 in (anonymous namespace)::MCELFStreamer::Finish (this=0x8073aa8)
    at MCELFStreamer.cpp:398
#14 0xb789b072 in (anonymous namespace)::AsmParser::Run (this=0x8074888,
    NoInitialTextSection=false, NoFinalize=false) at AsmParser.cpp:395
#15 0x0804e09a in AssembleInput (ProgName=0xbffff5c7
"/home/matt/root/bin/llvm-mc")
    at llvm-mc.cpp:335
#16 0x0804ed27 in main (argc=Cannot access memory at address 0x5458
) at llvm-mc.cpp:401
(gdb)

Any ideas on how to fix this? Also, if anybody knows a better way to
do in-memory assembly than to create and MCObjectStreamer and use it
to assemble into raw_svector_ostream backed by a SmallVector<char>,
I'd be very happy to hear about it.

Cheers,
Matt

Please use a non-ancient version of LLVM. This works fine with ToT (and
most likely with 2.9 as well).

Joerg