codegen_llvm_back: improve common patterns
This commit is contained in:
parent
4286c3c1b0
commit
3dbb2cc864
6 changed files with 30 additions and 57 deletions
|
@ -185,13 +185,8 @@ impl<'a> ArchiveBuilder<'a> {
|
||||||
/// Combine the provided files, rlibs, and native libraries into a single
|
/// Combine the provided files, rlibs, and native libraries into a single
|
||||||
/// `Archive`.
|
/// `Archive`.
|
||||||
pub fn build(&mut self) {
|
pub fn build(&mut self) {
|
||||||
let kind = match self.llvm_archive_kind() {
|
let kind = self.llvm_archive_kind().unwrap_or_else(|kind|
|
||||||
Ok(kind) => kind,
|
self.config.sess.fatal(&format!("Don't know how to build archive of type: {}", kind)));
|
||||||
Err(kind) => {
|
|
||||||
self.config.sess.fatal(&format!("Don't know how to build archive of type: {}",
|
|
||||||
kind));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(e) = self.build_with_llvm(kind) {
|
if let Err(e) = self.build_with_llvm(kind) {
|
||||||
self.config.sess.fatal(&format!("failed to build archive: {}", e));
|
self.config.sess.fatal(&format!("failed to build archive: {}", e));
|
||||||
|
|
|
@ -107,13 +107,10 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(sess: &Session, path: &Path) {
|
pub fn remove(sess: &Session, path: &Path) {
|
||||||
match fs::remove_file(path) {
|
if let Err(e) = fs::remove_file(path) {
|
||||||
Ok(..) => {}
|
sess.err(&format!("failed to remove {}: {}",
|
||||||
Err(e) => {
|
path.display(),
|
||||||
sess.err(&format!("failed to remove {}: {}",
|
e));
|
||||||
path.display(),
|
|
||||||
e));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +181,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
|
||||||
// the objects as they're losslessly contained inside the archives.
|
// the objects as they're losslessly contained inside the archives.
|
||||||
let output_linked = sess.crate_types.borrow()
|
let output_linked = sess.crate_types.borrow()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|x| *x != config::CrateType::Rlib && *x != config::CrateType::Staticlib);
|
.any(|&x| x != config::CrateType::Rlib && x != config::CrateType::Staticlib);
|
||||||
if !output_linked {
|
if !output_linked {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -289,13 +286,10 @@ fn link_binary_output(sess: &Session,
|
||||||
// final destination, with a `fs::rename` call. In order for the rename to
|
// final destination, with a `fs::rename` call. In order for the rename to
|
||||||
// always succeed, the temporary file needs to be on the same filesystem,
|
// always succeed, the temporary file needs to be on the same filesystem,
|
||||||
// which is why we create it inside the output directory specifically.
|
// which is why we create it inside the output directory specifically.
|
||||||
let metadata_tmpdir = match TempFileBuilder::new()
|
let metadata_tmpdir = TempFileBuilder::new()
|
||||||
.prefix("rmeta")
|
.prefix("rmeta")
|
||||||
.tempdir_in(out_filename.parent().unwrap())
|
.tempdir_in(out_filename.parent().unwrap())
|
||||||
{
|
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));
|
||||||
Ok(tmpdir) => tmpdir,
|
|
||||||
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
|
|
||||||
};
|
|
||||||
let metadata = emit_metadata(sess, codegen_results, &metadata_tmpdir);
|
let metadata = emit_metadata(sess, codegen_results, &metadata_tmpdir);
|
||||||
if let Err(e) = fs::rename(metadata, &out_filename) {
|
if let Err(e) = fs::rename(metadata, &out_filename) {
|
||||||
sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
||||||
|
@ -303,10 +297,8 @@ fn link_binary_output(sess: &Session,
|
||||||
out_filenames.push(out_filename);
|
out_filenames.push(out_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tmpdir = match TempFileBuilder::new().prefix("rustc").tempdir() {
|
let tmpdir = TempFileBuilder::new().prefix("rustc").tempdir().unwrap_or_else(|err|
|
||||||
Ok(tmpdir) => tmpdir,
|
sess.fatal(&format!("couldn't create a temp dir: {}", err)));
|
||||||
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
|
|
||||||
};
|
|
||||||
|
|
||||||
if outputs.outputs.should_codegen() {
|
if outputs.outputs.should_codegen() {
|
||||||
let out_filename = out_filename(sess, crate_type, outputs, crate_name);
|
let out_filename = out_filename(sess, crate_type, outputs, crate_name);
|
||||||
|
@ -869,9 +861,8 @@ fn link_natively(sess: &Session,
|
||||||
sess.opts.debuginfo != DebugInfo::None &&
|
sess.opts.debuginfo != DebugInfo::None &&
|
||||||
!preserve_objects_for_their_debuginfo(sess)
|
!preserve_objects_for_their_debuginfo(sess)
|
||||||
{
|
{
|
||||||
match Command::new("dsymutil").arg(out_filename).output() {
|
if let Err(e) = Command::new("dsymutil").arg(out_filename).output() {
|
||||||
Ok(..) => {}
|
sess.fatal(&format!("failed to run dsymutil: {}", e))
|
||||||
Err(e) => sess.fatal(&format!("failed to run dsymutil: {}", e)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -919,12 +919,6 @@ impl ThinLTOImports {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module_name_to_str(c_str: &CStr) -> &str {
|
fn module_name_to_str(c_str: &CStr) -> &str {
|
||||||
match c_str.to_str() {
|
c_str.to_str().unwrap_or_else(|e|
|
||||||
Ok(s) => s,
|
bug!("Encountered non-utf8 LLVM module name `{}`: {}", c_str.to_string_lossy(), e))
|
||||||
Err(e) => {
|
|
||||||
bug!("Encountered non-utf8 LLVM module name `{}`: {}",
|
|
||||||
c_str.to_string_lossy(),
|
|
||||||
e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ const WASM_EXTERNAL_KIND_GLOBAL: u8 = 3;
|
||||||
/// https://github.com/llvm-mirror/llvm/commit/0f32e1365, although support still
|
/// https://github.com/llvm-mirror/llvm/commit/0f32e1365, although support still
|
||||||
/// needs to be added, tracked at https://bugs.llvm.org/show_bug.cgi?id=37168
|
/// needs to be added, tracked at https://bugs.llvm.org/show_bug.cgi?id=37168
|
||||||
pub fn rewrite_imports(path: &Path, import_map: &FxHashMap<String, String>) {
|
pub fn rewrite_imports(path: &Path, import_map: &FxHashMap<String, String>) {
|
||||||
if import_map.len() == 0 {
|
if import_map.is_empty() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ impl<'a> Iterator for WasmSections<'a> {
|
||||||
type Item = (u8, &'a [u8]);
|
type Item = (u8, &'a [u8]);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<(u8, &'a [u8])> {
|
fn next(&mut self) -> Option<(u8, &'a [u8])> {
|
||||||
if self.0.data.len() == 0 {
|
if self.0.data.is_empty() {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1440,15 +1440,12 @@ fn execute_copy_from_cache_work_item(cgcx: &CodegenContext,
|
||||||
module.name,
|
module.name,
|
||||||
source_file,
|
source_file,
|
||||||
obj_out.display());
|
obj_out.display());
|
||||||
match link_or_copy(&source_file, &obj_out) {
|
if let Err(err) = link_or_copy(&source_file, &obj_out) {
|
||||||
Ok(_) => { }
|
let diag_handler = cgcx.create_diag_handler();
|
||||||
Err(err) => {
|
diag_handler.err(&format!("unable to copy {} to {}: {}",
|
||||||
let diag_handler = cgcx.create_diag_handler();
|
source_file.display(),
|
||||||
diag_handler.err(&format!("unable to copy {} to {}: {}",
|
obj_out.display(),
|
||||||
source_file.display(),
|
err));
|
||||||
obj_out.display(),
|
|
||||||
err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -343,17 +343,13 @@ impl<'a> Linker for GccLinker<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debuginfo(&mut self) {
|
fn debuginfo(&mut self) {
|
||||||
match self.sess.opts.debuginfo {
|
if let DebugInfo::None = self.sess.opts.debuginfo {
|
||||||
DebugInfo::None => {
|
// If we are building without debuginfo enabled and we were called with
|
||||||
// If we are building without debuginfo enabled and we were called with
|
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
|
||||||
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
|
// found when linking to get rid of symbols from libstd.
|
||||||
// found when linking to get rid of symbols from libstd.
|
if let Some(true) = self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
|
||||||
match self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
|
self.linker_arg("-S");
|
||||||
Some(true) => { self.linker_arg("-S"); },
|
}
|
||||||
_ => {},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue