// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use super::archive::{Archive, ArchiveConfig, METADATA_FILENAME};
+use super::archive::{Archive, ArchiveBuilder, ArchiveConfig, METADATA_FILENAME};
use super::rpath;
use super::rpath::RPathConfig;
use super::svh::Svh;
abi::OsLinux => (loader::LINUX_DLL_PREFIX, loader::LINUX_DLL_SUFFIX),
abi::OsAndroid => (loader::ANDROID_DLL_PREFIX, loader::ANDROID_DLL_SUFFIX),
abi::OsFreebsd => (loader::FREEBSD_DLL_PREFIX, loader::FREEBSD_DLL_SUFFIX),
+ abi::OsDragonfly => (loader::DRAGONFLY_DLL_PREFIX, loader::DRAGONFLY_DLL_SUFFIX),
abi::OsiOS => unreachable!(),
};
out_filename.with_filename(format!("{}{}{}",
abi::OsLinux |
abi::OsAndroid |
abi::OsFreebsd |
+ abi::OsDragonfly |
abi::OsiOS => out_filename.clone(),
}
}
match crate_type {
config::CrateTypeRlib => {
- link_rlib(sess, Some(trans), &obj_filename, &out_filename);
+ link_rlib(sess, Some(trans), &obj_filename, &out_filename).build();
}
config::CrateTypeStaticlib => {
link_staticlib(sess, &obj_filename, &out_filename);
fn link_rlib<'a>(sess: &'a Session,
trans: Option<&CrateTranslation>, // None == no metadata/bytecode
obj_filename: &Path,
- out_filename: &Path) -> Archive<'a> {
+ out_filename: &Path) -> ArchiveBuilder<'a> {
let handler = &sess.diagnostic().handler;
let config = ArchiveConfig {
handler: handler,
os: sess.targ_cfg.os,
maybe_ar_prog: sess.opts.cg.ar.clone()
};
- let mut a = Archive::create(config, obj_filename);
+ let mut ab = ArchiveBuilder::create(config);
+ ab.add_file(obj_filename).unwrap();
for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
match kind {
cstore::NativeStatic => {
- a.add_native_library(l.as_slice()).unwrap();
+ ab.add_native_library(l.as_slice()).unwrap();
}
cstore::NativeFramework | cstore::NativeUnknown => {}
}
}
+ // After adding all files to the archive, we need to update the
+ // symbol table of the archive.
+ ab.update_symbols();
+
+ let mut ab = match sess.targ_cfg.os {
+ // For OSX/iOS, we must be careful to update symbols only when adding
+ // object files. We're about to start adding non-object files, so run
+ // `ar` now to process the object files.
+ abi::OsMacos | abi::OsiOS => ab.build().extend(),
+ _ => ab,
+ };
+
// Note that it is important that we add all of our non-object "magical
// files" *after* all of the object files in the archive. The reason for
// this is as follows:
sess.abort_if_errors();
}
}
- a.add_file(&metadata, false);
+ ab.add_file(&metadata).unwrap();
remove(sess, &metadata);
// For LTO purposes, the bytecode of this library is also inserted
sess.abort_if_errors()
}
}
- a.add_file(&bc_deflated, false);
+ ab.add_file(&bc_deflated).unwrap();
remove(sess, &bc_deflated);
if !sess.opts.cg.save_temps &&
!sess.opts.output_types.contains(&OutputTypeBitcode) {
remove(sess, &bc);
}
-
- // After adding all files to the archive, we need to update the
- // symbol table of the archive. This currently dies on OSX (see
- // #11162), and isn't necessary there anyway
- match sess.targ_cfg.os {
- abi::OsMacos | abi::OsiOS => {}
- _ => { a.update_symbols(); }
- }
}
None => {}
}
- return a;
+
+ ab
}
// Create a static archive
// link in the metadata object file (and also don't prepare the archive with a
// metadata file).
fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
- let mut a = link_rlib(sess, None, obj_filename, out_filename);
- a.add_native_library("morestack").unwrap();
- a.add_native_library("compiler-rt").unwrap();
+ let ab = link_rlib(sess, None, obj_filename, out_filename);
+ let mut ab = match sess.targ_cfg.os {
+ abi::OsMacos | abi::OsiOS => ab.build().extend(),
+ _ => ab,
+ };
+ ab.add_native_library("morestack").unwrap();
+ ab.add_native_library("compiler-rt").unwrap();
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
let mut all_native_libs = vec![];
continue
}
};
- a.add_rlib(&p, name.as_slice(), sess.lto()).unwrap();
+ ab.add_rlib(&p, name.as_slice(), sess.lto()).unwrap();
let native_libs = csearch::get_native_libraries(&sess.cstore, cnum);
all_native_libs.extend(native_libs.move_iter());
}
+ ab.update_symbols();
+ let _ = ab.build();
+
if !all_native_libs.is_empty() {
sess.warn("link against the following native artifacts when linking against \
this static library");
// the symbols
if (sess.targ_cfg.os == abi::OsMacos || sess.targ_cfg.os == abi::OsiOS)
&& (sess.opts.debuginfo != NoDebugInfo) {
- match Command::new("dsymutil").arg(out_filename).status() {
+ match Command::new("dsymutil").arg(out_filename).output() {
Ok(..) => {}
Err(e) => {
sess.err(format!("failed to run dsymutil: {}", e).as_slice());
cmd.arg("-Wl,--gc-sections");
}
- if sess.targ_cfg.os == abi::OsLinux {
+ if sess.targ_cfg.os == abi::OsLinux || sess.targ_cfg.os == abi::OsDragonfly {
// GNU-style linkers will use this to omit linking to libraries which
// don't actually fulfill any relocations, but only for libraries which
// follow this flag. Thus, use it before specifying libraries to link to.
"-L/usr/local/lib/gcc46",
"-L/usr/local/lib/gcc44"]);
}
+ else if sess.targ_cfg.os == abi::OsDragonfly {
+ cmd.args(["-L/usr/local/lib",
+ "-L/usr/lib/gcc47",
+ "-L/usr/lib/gcc44"]);
+ }
+
// FIXME (#2397): At some point we want to rpath our guesses as to
// where extern libraries might live, based on the