Skip to content

Commit fe30087

Browse files
committed
Add metadata from a tempdir instead of a build dir
Right now if you have concurrent builds of two libraries in the same directory (such as rustc's bootstrapping process), it's possible that two libraries will stomp over each others' metadata, producing corrupt rlibs. By placing the metadata file in a tempdir we're guranteed to not conflict with ay other builds happening concurrently. Normally this isn't a problem because output filenames are scoped to the name of the crate, but metadata is special in that it has the same name across all crates.
1 parent a4f30bf commit fe30087

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/librustc/back/link.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,11 @@ fn link_rlib(sess: Session,
890890
match trans {
891891
Some(trans) => {
892892
// Instead of putting the metadata in an object file section, rlibs
893-
// contain the metadata in a separate file.
894-
let metadata = obj_filename.with_filename(METADATA_FILENAME);
893+
// contain the metadata in a separate file. We use a temp directory
894+
// here so concurrent builds in the same directory don't try to use
895+
// the same filename for metadata (stomping over one another)
896+
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
897+
let metadata = tmpdir.path().join(METADATA_FILENAME);
895898
fs::File::create(&metadata).write(trans.metadata);
896899
a.add_file(&metadata, false);
897900
fs::unlink(&metadata);

0 commit comments

Comments
 (0)