// 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;
};
// Look in attributes 100% of the time to make sure the attribute is marked
- // as used. After doing this, however, favor crate names from the command
- // line.
+ // as used. After doing this, however, we still prioritize a crate name from
+ // the command line over one found in the #[crate_name] attribute. If we
+ // find both we ensure that they're the same later on as well.
let attr_crate_name = attrs.iter().find(|at| at.check_name("crate_name"))
.and_then(|at| at.value_str().map(|s| (at, s)));
match sess {
Some(sess) => {
match sess.opts.crate_name {
- Some(ref s) => return validate(s.clone(), None),
+ Some(ref s) => {
+ match attr_crate_name {
+ Some((attr, ref name)) if s.as_slice() != name.get() => {
+ let msg = format!("--crate-name and #[crate_name] \
+ are required to match, but `{}` \
+ != `{}`", s, name);
+ sess.span_err(attr.span, msg.as_slice());
+ }
+ _ => {},
+ }
+ return validate(s.clone(), None);
+ }
None => {}
}
}
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!("{}{}{}",
config::CrateTypeStaticlib => {
out_filename.with_filename(format!("lib{}.a", libname))
}
- config::CrateTypeExecutable => out_filename.clone(),
+ config::CrateTypeExecutable => {
+ match sess.targ_cfg.os {
+ abi::OsWin32 => out_filename.with_extension("exe"),
+ abi::OsMacos |
+ 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());
abi::OsMacos | abi::OsiOS => {
let morestack = lib_path.join("libmorestack.a");
- let mut v = "-Wl,-force_load,".as_bytes().to_owned();
+ let mut v = b"-Wl,-force_load,".to_vec();
v.push_all(morestack.as_vec());
cmd.arg(v.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
add_dynamic_crate(cmd, sess, src.dylib.unwrap())
}
cstore::RequireStatic => {
- add_static_crate(cmd, sess, tmpdir, cnum, src.rlib.unwrap())
+ add_static_crate(cmd, sess, tmpdir, src.rlib.unwrap())
}
}
// Adds the static "rlib" versions of all crates to the command line.
fn add_static_crate(cmd: &mut Command, sess: &Session, tmpdir: &Path,
- cnum: ast::CrateNum, cratepath: Path) {
+ cratepath: Path) {
// When performing LTO on an executable output, all of the
// bytecode from the upstream libraries has already been
// included in our object file output. We need to modify all of
// If we're not doing LTO, then our job is simply to just link
// against the archive.
if sess.lto() {
- let name = sess.cstore.get_crate_data(cnum).name.clone();
+ let name = cratepath.filename_str().unwrap();
+ let name = name.slice(3, name.len() - 5); // chop off lib/.rlib
time(sess.time_passes(),
format!("altering {}.rlib", name).as_slice(),
(), |()| {