]> git.lizzy.rs Git - rust.git/commitdiff
Don't always modify the symbol table in rlibs
authorAlex Crichton <alex@alexcrichton.com>
Tue, 10 Dec 2013 17:28:20 +0000 (09:28 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 12 Dec 2013 03:37:26 +0000 (19:37 -0800)
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

src/librustc/back/archive.rs
src/librustc/back/link.rs

index eec15f798278d195e048932c1cf0ac5f4fd83016..c1916714bf28366126e81e7899fa67fe03e920b7 100644 (file)
@@ -103,8 +103,9 @@ pub fn add_rlib(&mut self, rlib: &Path, name: &str, lto: bool) {
     }
 
     /// 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 @@ pub fn remove_file(&mut self, file: &str) {
         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()
index 451213ab694f712d32212b0bb53f2d7d19b8c024..43a08d1c998c3c09fb6b5903b70e9e3e7c530afa 100644 (file)
@@ -982,16 +982,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 => {}