Skip to content

Commit d52e1bf

Browse files
committed
auto merge of #10908 : alexcrichton/rust/issue-10907, r=cmr
Turns out that one some platforms the ar/ranlib tool will die with an assertion if the file being added doesn't actually have any symbols (or if it's just not an object file presumably). This functionality is already all exercised on the bots, it just turns out that the bots don't have an ar tool which dies in this situation, so it's difficult for me to add a test. Closes #10907
2 parents 2ec4712 + ee618e1 commit d52e1bf

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/librustc/back/archive.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,22 @@ impl Archive {
103103
}
104104

105105
/// Adds an arbitrary file to this archive
106-
pub fn add_file(&mut self, file: &Path) {
107-
run_ar(self.sess, "r", None, [&self.dst, file]);
106+
pub fn add_file(&mut self, file: &Path, has_symbols: bool) {
107+
let cmd = if has_symbols {"r"} else {"rS"};
108+
run_ar(self.sess, cmd, None, [&self.dst, file]);
108109
}
109110

110111
/// Removes a file from this archive
111112
pub fn remove_file(&mut self, file: &str) {
112113
run_ar(self.sess, "d", None, [&self.dst, &Path::new(file)]);
113114
}
114115

116+
/// Update all symbols in the archive (runs 'ar s' over it)
117+
pub fn update_symbols(&mut self) {
118+
run_ar(self.sess, "s", None, [&self.dst]);
119+
}
120+
121+
/// List all files in an archive
115122
pub fn files(&self) -> ~[~str] {
116123
let output = run_ar(self.sess, "t", None, [&self.dst]);
117124
str::from_utf8(output.output).lines().map(|s| s.to_owned()).collect()

src/librustc/back/link.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,16 +868,21 @@ fn link_rlib(sess: Session,
868868
// contain the metadata in a separate file.
869869
let metadata = obj_filename.with_filename(METADATA_FILENAME);
870870
fs::File::create(&metadata).write(trans.metadata);
871-
a.add_file(&metadata);
871+
a.add_file(&metadata, false);
872872
fs::unlink(&metadata);
873873

874874
// For LTO purposes, the bytecode of this library is also inserted
875875
// into the archive.
876876
let bc = obj_filename.with_extension("bc");
877-
a.add_file(&bc);
877+
a.add_file(&bc, false);
878878
if !sess.opts.save_temps {
879879
fs::unlink(&bc);
880880
}
881+
882+
// Now that we've added files, some platforms need us to now update
883+
// the symbol table in the archive (because some platforms die when
884+
// adding files to the archive without symbols).
885+
a.update_symbols();
881886
}
882887

883888
None => {}

0 commit comments

Comments
 (0)