Skip to content
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

Move back::link and debuginfo::type_names to cg ssa #59564

Merged
merged 8 commits into from
Apr 20, 2019
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2634,6 +2634,7 @@ dependencies = [
"serialize 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
Expand Down
94 changes: 55 additions & 39 deletions src/librustc_codegen_llvm/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ use std::path::{Path, PathBuf};
use std::ptr;
use std::str;

use crate::back::bytecode::RLIB_BYTECODE_EXTENSION;
use crate::llvm::archive_ro::{ArchiveRO, Child};
use crate::llvm::{self, ArchiveKind};
use crate::metadata::METADATA_FILENAME;
use rustc_codegen_ssa::back::archive::find_library;
use rustc_codegen_ssa::{METADATA_FILENAME, RLIB_BYTECODE_EXTENSION};
use rustc_codegen_ssa::back::archive::{ArchiveBuilder, find_library};
use rustc::session::Session;

pub struct ArchiveConfig<'a> {
struct ArchiveConfig<'a> {
pub sess: &'a Session,
pub dst: PathBuf,
pub src: Option<PathBuf>,
Expand All @@ -23,7 +22,7 @@ pub struct ArchiveConfig<'a> {

/// Helper for adding many files to an archive.
#[must_use = "must call build() to finish building the archive"]
pub struct ArchiveBuilder<'a> {
pub struct LlvmArchiveBuilder<'a> {
config: ArchiveConfig<'a>,
removals: Vec<String>,
additions: Vec<Addition>,
Expand All @@ -49,11 +48,26 @@ fn is_relevant_child(c: &Child<'_>) -> bool {
}
}

impl<'a> ArchiveBuilder<'a> {
fn archive_config<'a>(sess: &'a Session,
output: &Path,
input: Option<&Path>) -> ArchiveConfig<'a> {
use rustc_codegen_ssa::back::link::archive_search_paths;
ArchiveConfig {
sess,
dst: output.to_path_buf(),
src: input.map(|p| p.to_path_buf()),
lib_search_paths: archive_search_paths(sess),
}
}

impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
/// Creates a new static archive, ready for modifying the archive specified
/// by `config`.
pub fn new(config: ArchiveConfig<'a>) -> ArchiveBuilder<'a> {
ArchiveBuilder {
fn new(sess: &'a Session,
output: &Path,
input: Option<&Path>) -> LlvmArchiveBuilder<'a> {
let config = archive_config(sess, output, input);
LlvmArchiveBuilder {
config,
removals: Vec::new(),
additions: Vec::new(),
Expand All @@ -63,12 +77,12 @@ impl<'a> ArchiveBuilder<'a> {
}

/// Removes a file from this archive
pub fn remove_file(&mut self, file: &str) {
fn remove_file(&mut self, file: &str) {
self.removals.push(file.to_string());
}

/// Lists all files in an archive
pub fn src_files(&mut self) -> Vec<String> {
fn src_files(&mut self) -> Vec<String> {
if self.src_archive().is_none() {
return Vec::new()
}
Expand All @@ -84,18 +98,9 @@ impl<'a> ArchiveBuilder<'a> {
.collect()
}

fn src_archive(&mut self) -> Option<&ArchiveRO> {
if let Some(ref a) = self.src_archive {
return a.as_ref()
}
let src = self.config.src.as_ref()?;
self.src_archive = Some(ArchiveRO::open(src).ok());
self.src_archive.as_ref().unwrap().as_ref()
}

/// Adds all of the contents of a native library to this archive. This will
/// search in the relevant locations for a library named `name`.
pub fn add_native_library(&mut self, name: &str) {
fn add_native_library(&mut self, name: &str) {
let location = find_library(name, &self.config.lib_search_paths,
self.config.sess);
self.add_archive(&location, |_| false).unwrap_or_else(|e| {
Expand All @@ -109,7 +114,7 @@ impl<'a> ArchiveBuilder<'a> {
///
/// This ignores adding the bytecode from the rlib, and if LTO is enabled
/// then the object file also isn't added.
pub fn add_rlib(&mut self,
fn add_rlib(&mut self,
rlib: &Path,
name: &str,
lto: bool,
Expand Down Expand Up @@ -141,23 +146,8 @@ impl<'a> ArchiveBuilder<'a> {
})
}

fn add_archive<F>(&mut self, archive: &Path, skip: F)
-> io::Result<()>
where F: FnMut(&str) -> bool + 'static
{
let archive = match ArchiveRO::open(archive) {
Ok(ar) => ar,
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
};
self.additions.push(Addition::Archive {
archive,
skip: Box::new(skip),
});
Ok(())
}

/// Adds an arbitrary file to this archive
pub fn add_file(&mut self, file: &Path) {
fn add_file(&mut self, file: &Path) {
let name = file.file_name().unwrap().to_str().unwrap();
self.additions.push(Addition::File {
path: file.to_path_buf(),
Expand All @@ -167,13 +157,13 @@ impl<'a> ArchiveBuilder<'a> {

/// Indicate that the next call to `build` should update all symbols in
/// the archive (equivalent to running 'ar s' over it).
pub fn update_symbols(&mut self) {
fn update_symbols(&mut self) {
self.should_update_symbols = true;
}

/// Combine the provided files, rlibs, and native libraries into a single
/// `Archive`.
pub fn build(&mut self) {
fn build(mut self) {
let kind = self.llvm_archive_kind().unwrap_or_else(|kind|
self.config.sess.fatal(&format!("Don't know how to build archive of type: {}", kind)));

Expand All @@ -182,6 +172,32 @@ impl<'a> ArchiveBuilder<'a> {
}

}
}

impl<'a> LlvmArchiveBuilder<'a> {
fn src_archive(&mut self) -> Option<&ArchiveRO> {
if let Some(ref a) = self.src_archive {
return a.as_ref()
}
let src = self.config.src.as_ref()?;
self.src_archive = Some(ArchiveRO::open(src).ok());
self.src_archive.as_ref().unwrap().as_ref()
}

fn add_archive<F>(&mut self, archive: &Path, skip: F)
-> io::Result<()>
where F: FnMut(&str) -> bool + 'static
{
let archive = match ArchiveRO::open(archive) {
Ok(ar) => ar,
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
};
self.additions.push(Addition::Archive {
archive,
skip: Box::new(skip),
});
Ok(())
}

fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
let kind = &*self.config.sess.target.target.options.archive_format;
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_codegen_llvm/back/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub const RLIB_BYTECODE_OBJECT_MAGIC: &[u8] = b"RUST_OBJECT";
// The version number this compiler will write to bytecode objects in rlibs
pub const RLIB_BYTECODE_OBJECT_VERSION: u8 = 2;

pub const RLIB_BYTECODE_EXTENSION: &str = "bc.z";

pub fn encode(identifier: &str, bytecode: &[u8]) -> Vec<u8> {
let mut encoded = Vec::new();

Expand Down
Loading