Change:
let file = path.filename_str().unwrap(); let file = file.slice(3, file.len() - 5); // chop off lib/.rlib debug!("reading {}", file); <del> let bc = time(sess.time_passes(), format!("read {}.bytecode.deflate", name).as_slice(), (), |_| { archive.read(format!("{}.bytecode.deflate", file).as_slice()) }); let bc = bc.expect("missing compressed bytecode in archive!"); let bc = time(sess.time_passes(), format!("inflate {}.bc", file).as_slice(), (), |_| { match flate::inflate_bytes(bc) { Some(bc) => bc, None => { sess.fatal(format!("failed to decompress  bc of `{}`", name).as_slice()) } } }); let ptr = bc.as_slice().as_ptr(); </del> <ins> let bc_encoded = time(sess.time_passes(), format!("read {}.bytecode.deflate", name).as_slice(), (), |_| { archive.read(format!("{}.bytecode.deflate", file).as_slice()) }); let bc_encoded = bc_encoded.expect("missing compressed bytecode in archive!"); let bc_extractor = if is_versioned_bytecode_format(bc_encoded) { |_| { // Read the version let version = extract_bytecode_format_version(bc_encoded); if version == 1 { // The only version existing so far let data_size = extract_compressed_bytecode_size_v1(bc_encoded); let compressed_data = bc_encoded.slice( link::RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET, link::RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET + data_size as uint); match flate::inflate_bytes(compressed_data) { Some(inflated) => inflated, None => { sess.fatal(format!("failed to decompress bc of `{}`", name).as_slice()) } } } else { sess.fatal(format!("Unsupported bytecode format version {}", version).as_slice()) } } } else { // the object must be in the old, pre-versioning format, so simply // inflate everything and let LLVM decide if it can make sense of it |_| { match flate::inflate_bytes(bc_encoded) { Some(bc) => bc, None => { sess.fatal(format!("failed to decompress bc of `{}`", name).as_slice()) } } } }; let bc_decoded = time(sess.time_passes(), format!("decode {}.bc", file).as_slice(), (), bc_extractor); let ptr = bc_decoded.as_slice().as_ptr(); </ins> debug!("linking {}", name); time(sess.time_passes(), format!("ll link {}", name).as_slice(),

Discussion:
There's another bug in LLDB that causes it to segfault when reading archive files. This one has already been fixed in May () but it still exists in a lot of LLDB binaries out there. As far as I can tell, the bug occurs when a number of object files are stored in an archive and the last one ends at an uneven byte offset. This often seems to be the case for compressed byte-code archives in rlibs (maybe regular object files are always padded to an even size?). I'm currently compiling a possible workaround (pad the bytecode objects to an even size). It would be good if we could allow for rust code to be debugged with older LLDB versions too.
Update: Padding all archives entries to an even size seems to prevent the crash in LLDB and I have not seen any detrimental side effects to this approach so far. Any idea if the additional padding byte at the end of the compressed LLVM IR object in an archive could potentially lead to a problem?
I'm not familiar enough with the format of object files or bytecode files to know whether an extra byte or two at the end would corrupt them, but if it's working ok currently then I'd just ship it!
I doubt that the containing archive will care about the padding byte, but either the decompression algorithm or the LLVM bitcode reader could trip over it. The safe way to do this would probably be to prepend the actual size of the compressed data, so we always know how much data to pass to . I guess, I'll implement this and make a pull request.
Thinking about it, changing the format here is not as so trivial since the compiler must handle libs with the old format differently from libs with the new format. I see two options: (1) Just add the padding byte and hope for the best (2) Introduce some kind of header (including a version byte) before the compressed bitcode, in order to future-proof this against other changes to the encoding. I think I'd favor option (2).
Is this only a problem for the bytecode in archives, or is it also a problem for object files?
So far it has only occurred for bytecode. All object files I came across had a size dividable by 2. I don't know if that's a coincidence...
Interesting!

I'm all for putting the bytecode in whatever format we want (it's already just a huge deflated stream)
I'll come up with something and then we can discuss the matter further when we have some code to look at in a PR, OK?
Sounds good to me!