about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-12-13 05:01:58 -0800
committerbors <bors@rust-lang.org>2013-12-13 05:01:58 -0800
commitd52e1bffe5e0f8c5183df07583b666457d2059c0 (patch)
tree061ea74e044915c5d558612611e149130a8fc066
parent2ec471228958590f2ccf2c268f42daa53fc979d4 (diff)
parentee618e1e7590bf2cfd6431dafa0b6a9565bc91d3 (diff)
downloadrust-d52e1bffe5e0f8c5183df07583b666457d2059c0.tar.gz
rust-d52e1bffe5e0f8c5183df07583b666457d2059c0.zip
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
-rw-r--r--src/librustc/back/archive.rs11
-rw-r--r--src/librustc/back/link.rs9
2 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs
index eec15f79827..c1916714bf2 100644
--- a/src/librustc/back/archive.rs
+++ b/src/librustc/back/archive.rs
@@ -103,8 +103,9 @@ impl Archive {
     }
 
     /// Adds an arbitrary file to this archive
-    pub fn add_file(&mut self, file: &Path) {
-        run_ar(self.sess, "r", None, [&self.dst, file]);
+    pub fn add_file(&mut self, file: &Path, has_symbols: bool) {
+        let cmd = if has_symbols {"r"} else {"rS"};
+        run_ar(self.sess, cmd, None, [&self.dst, file]);
     }
 
     /// Removes a file from this archive
@@ -112,6 +113,12 @@ impl Archive {
         run_ar(self.sess, "d", None, [&self.dst, &Path::new(file)]);
     }
 
+    /// Update all symbols in the archive (runs 'ar s' over it)
+    pub fn update_symbols(&mut self) {
+        run_ar(self.sess, "s", None, [&self.dst]);
+    }
+
+    /// List all files in an archive
     pub fn files(&self) -> ~[~str] {
         let output = run_ar(self.sess, "t", None, [&self.dst]);
         str::from_utf8(output.output).lines().map(|s| s.to_owned()).collect()
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 838a5aa8943..91680f5c2e5 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -868,16 +868,21 @@ fn link_rlib(sess: Session,
             // contain the metadata in a separate file.
             let metadata = obj_filename.with_filename(METADATA_FILENAME);
             fs::File::create(&metadata).write(trans.metadata);
-            a.add_file(&metadata);
+            a.add_file(&metadata, false);
             fs::unlink(&metadata);
 
             // For LTO purposes, the bytecode of this library is also inserted
             // into the archive.
             let bc = obj_filename.with_extension("bc");
-            a.add_file(&bc);
+            a.add_file(&bc, false);
             if !sess.opts.save_temps {
                 fs::unlink(&bc);
             }
+
+            // Now that we've added files, some platforms need us to now update
+            // the symbol table in the archive (because some platforms die when
+            // adding files to the archive without symbols).
+            a.update_symbols();
         }
 
         None => {}