Skip to content

Don't always modify the symbol table in rlibs #10908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/librustc/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,22 @@ 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
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()
Expand Down
9 changes: 7 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
Expand Down