Skip to content

Commit ee618e1

Browse files
committed
Don't always modify the symbol table in rlibs
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
1 parent 487e58c commit ee618e1

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
@@ -982,16 +982,21 @@ fn link_rlib(sess: Session,
982982
// contain the metadata in a separate file.
983983
let metadata = obj_filename.with_filename(METADATA_FILENAME);
984984
fs::File::create(&metadata).write(trans.metadata);
985-
a.add_file(&metadata);
985+
a.add_file(&metadata, false);
986986
fs::unlink(&metadata);
987987

988988
// For LTO purposes, the bytecode of this library is also inserted
989989
// into the archive.
990990
let bc = obj_filename.with_extension("bc");
991-
a.add_file(&bc);
991+
a.add_file(&bc, false);
992992
if !sess.opts.save_temps {
993993
fs::unlink(&bc);
994994
}
995+
996+
// Now that we've added files, some platforms need us to now update
997+
// the symbol table in the archive (because some platforms die when
998+
// adding files to the archive without symbols).
999+
a.update_symbols();
9951000
}
9961001

9971002
None => {}

0 commit comments

Comments
 (0)