Skip to content

Commit 6a43af3

Browse files
michaelwoeristeralexcrichton
authored andcommitted
Add workaround for archive reading bug in LLDB.
LLDB contains a bug that makes it crash if an archive it reads contains a file the name of which is exactly 16 bytes long. This bug recently has made it impossible to debug Rust applications with LLDB because some standard libraries triggered it indirectly: For rlibs, rustc includes the LLVM bytecode in the archive, giving it the extension ".bc.deflate". For liballoc (for example) this results in the 16 character filename "alloc.bc.deflate", which is bad. This commit replaces the ".bc.deflate" suffix with ".bytecode.deflate" which itself is already longer than 16 bytes, thus making sure that the bug won't be run into anymore. The bug could still be run into with 14 character filenames because then the .o files will trigger it. However, this is much more rare and working around it would introduce more complexity than necessary at the moment. It can always be done later on, if the need arises. Fixes #14356.
1 parent 735e518 commit 6a43af3

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/librustc/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'a> Archive<'a> {
109109
pub fn add_rlib(&mut self, rlib: &Path, name: &str,
110110
lto: bool) -> io::IoResult<()> {
111111
let object = format!("{}.o", name);
112-
let bytecode = format!("{}.bc.deflate", name);
112+
let bytecode = format!("{}.bytecode.deflate", name);
113113
let mut ignore = vec!(bytecode.as_slice(), METADATA_FILENAME);
114114
if lto {
115115
ignore.push(object.as_slice());

src/librustc/back/link.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,12 @@ fn link_rlib<'a>(sess: &'a Session,
958958

959959
// For LTO purposes, the bytecode of this library is also inserted
960960
// into the archive.
961+
// Note that we make sure that the bytecode filename in the archive is always at least
962+
// 16 bytes long by adding a 16 byte extension to it. This is to work around a bug in
963+
// LLDB that would cause it to crash if the name of a file in an archive was exactly
964+
// 16 bytes.
961965
let bc = obj_filename.with_extension("bc");
962-
let bc_deflated = obj_filename.with_extension("bc.deflate");
966+
let bc_deflated = obj_filename.with_extension("bytecode.deflate");
963967
match fs::File::open(&bc).read_to_end().and_then(|data| {
964968
fs::File::create(&bc_deflated)
965969
.write(match flate::deflate_bytes(data.as_slice()) {

src/librustc/back/lto.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
5555
let archive = ArchiveRO::open(&path).expect("wanted an rlib");
5656
debug!("reading {}", name);
5757
let bc = time(sess.time_passes(),
58-
format!("read {}.bc.deflate", name).as_slice(),
58+
format!("read {}.bytecode.deflate", name).as_slice(),
5959
(),
6060
|_| {
61-
archive.read(format!("{}.bc.deflate",
61+
archive.read(format!("{}.bytecode.deflate",
6262
name).as_slice())
6363
});
6464
let bc = bc.expect("missing compressed bytecode in archive!");

0 commit comments

Comments
 (0)