librustc: Remove all uses of ~str from librustc.

This commit is contained in:
Patrick Walton 2014-05-09 18:45:36 -07:00
parent e8053b9a7f
commit 6559a3675e
83 changed files with 2014 additions and 1439 deletions

View file

@ -129,12 +129,12 @@ impl<'a> Archive<'a> {
}
/// Lists all files in an archive
pub fn files(&self) -> Vec<~str> {
pub fn files(&self) -> Vec<StrBuf> {
let output = run_ar(self.sess, "t", None, [&self.dst]);
let output = str::from_utf8(output.output.as_slice()).unwrap();
// use lines_any because windows delimits output with `\r\n` instead of
// just `\n`
output.lines_any().map(|s| s.to_owned()).collect()
output.lines_any().map(|s| s.to_strbuf()).collect()
}
fn add_archive(&mut self, archive: &Path, name: &str,

View file

@ -13,56 +13,57 @@ use driver::config::cfg_os_to_meta_os;
use metadata::loader::meta_section_name;
use syntax::abi;
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
let cc_args = if target_triple.contains("thumb") {
vec!("-mthumb".to_owned())
pub fn get_target_strs(target_triple: StrBuf, target_os: abi::Os) -> target_strs::t {
let cc_args = if target_triple.as_slice().contains("thumb") {
vec!("-mthumb".to_strbuf())
} else {
vec!("-marm".to_owned())
vec!("-marm".to_strbuf())
};
return target_strs::t {
module_asm: "".to_owned(),
module_asm: "".to_strbuf(),
meta_sect_name: meta_section_name(cfg_os_to_meta_os(target_os)).to_owned(),
meta_sect_name:
meta_section_name(cfg_os_to_meta_os(target_os)).to_strbuf(),
data_layout: match target_os {
abi::OsMacos => {
"e-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"e-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsWin32 => {
"e-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"e-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsLinux => {
"e-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"e-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsAndroid => {
"e-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"e-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsFreebsd => {
"e-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"e-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
},

View file

@ -54,15 +54,15 @@ pub enum OutputType {
OutputTypeExe,
}
pub fn llvm_err(sess: &Session, msg: ~str) -> ! {
pub fn llvm_err(sess: &Session, msg: StrBuf) -> ! {
unsafe {
let cstr = llvm::LLVMRustGetLastError();
if cstr == ptr::null() {
sess.fatal(msg);
sess.fatal(msg.as_slice());
} else {
let err = CString::new(cstr, true);
let err = str::from_utf8_lossy(err.as_bytes());
sess.fatal(msg + ": " + err.as_slice());
sess.fatal((msg.as_slice() + ": " + err.as_slice()));
}
}
}
@ -79,7 +79,7 @@ pub fn WriteOutputFile(
let result = llvm::LLVMRustWriteOutputFile(
target, pm, m, output, file_type);
if !result {
llvm_err(sess, "could not write output".to_owned());
llvm_err(sess, "could not write output".to_strbuf());
}
})
}
@ -115,7 +115,7 @@ pub mod write {
fn target_feature<'a>(sess: &'a Session) -> &'a str {
match sess.targ_cfg.os {
abi::OsAndroid => {
if "" == sess.opts.cg.target_feature {
if "" == sess.opts.cg.target_feature.as_slice() {
"+v7"
} else {
sess.opts.cg.target_feature.as_slice()
@ -173,8 +173,12 @@ pub mod write {
}
};
let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|t| {
sess.opts.cg.target_cpu.with_c_str(|cpu| {
let tm = sess.targ_cfg
.target_strs
.target_triple
.as_slice()
.with_c_str(|t| {
sess.opts.cg.target_cpu.as_slice().with_c_str(|cpu| {
target_feature(sess).with_c_str(|features| {
llvm::LLVMRustCreateTargetMachine(
t, cpu, features,
@ -201,7 +205,7 @@ pub mod write {
// If we're verifying or linting, add them to the function pass
// manager.
let addpass = |pass: &str| {
pass.with_c_str(|s| llvm::LLVMRustAddPass(fpm, s))
pass.as_slice().with_c_str(|s| llvm::LLVMRustAddPass(fpm, s))
};
if !sess.no_verify() { assert!(addpass("verify")); }
@ -212,7 +216,7 @@ pub mod write {
}
for pass in sess.opts.cg.passes.iter() {
pass.with_c_str(|s| {
pass.as_slice().with_c_str(|s| {
if !llvm::LLVMRustAddPass(mpm, s) {
sess.warn(format!("unknown pass {}, ignoring", *pass));
}
@ -355,7 +359,7 @@ pub mod write {
assembly.as_str().unwrap().to_owned()];
debug!("{} '{}'", cc, args.connect("' '"));
match Process::output(cc, args) {
match Process::output(cc.as_slice(), args) {
Ok(prog) => {
if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
@ -400,7 +404,7 @@ pub mod write {
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
for arg in sess.opts.cg.llvm_args.iter() {
add(*arg);
add((*arg).as_slice());
}
}
@ -527,19 +531,20 @@ pub fn find_crate_id(attrs: &[ast::Attribute], out_filestem: &str) -> CrateId {
match attr::find_crateid(attrs) {
None => from_str(out_filestem).unwrap_or_else(|| {
let mut s = out_filestem.chars().filter(|c| c.is_XID_continue());
from_str(s.collect::<~str>()).or(from_str("rust-out")).unwrap()
from_str(s.collect::<StrBuf>()
.to_owned()).or(from_str("rust-out")).unwrap()
}),
Some(s) => s,
}
}
pub fn crate_id_hash(crate_id: &CrateId) -> ~str {
pub fn crate_id_hash(crate_id: &CrateId) -> StrBuf {
// This calculates CMH as defined above. Note that we don't use the path of
// the crate id in the hash because lookups are only done by (name/vers),
// not by path.
let mut s = Sha256::new();
s.input_str(crate_id.short_name_with_version().as_slice());
truncated_hash_result(&mut s).slice_to(8).to_owned()
truncated_hash_result(&mut s).as_slice().slice_to(8).to_strbuf()
}
pub fn build_link_meta(krate: &ast::Crate, out_filestem: &str) -> LinkMeta {
@ -551,10 +556,10 @@ pub fn build_link_meta(krate: &ast::Crate, out_filestem: &str) -> LinkMeta {
return r;
}
fn truncated_hash_result(symbol_hasher: &mut Sha256) -> ~str {
fn truncated_hash_result(symbol_hasher: &mut Sha256) -> StrBuf {
let output = symbol_hasher.result_bytes();
// 64 bits should be enough to avoid collisions.
output.slice_to(8).to_hex()
output.slice_to(8).to_hex().to_strbuf()
}
@ -563,7 +568,7 @@ fn symbol_hash(tcx: &ty::ctxt,
symbol_hasher: &mut Sha256,
t: ty::t,
link_meta: &LinkMeta)
-> ~str {
-> StrBuf {
// NB: do *not* use abbrevs here as we want the symbol names
// to be independent of one another in the crate.
@ -572,16 +577,16 @@ fn symbol_hash(tcx: &ty::ctxt,
symbol_hasher.input_str("-");
symbol_hasher.input_str(link_meta.crate_hash.as_str());
symbol_hasher.input_str("-");
symbol_hasher.input_str(encoder::encoded_ty(tcx, t));
symbol_hasher.input_str(encoder::encoded_ty(tcx, t).as_slice());
// Prefix with 'h' so that it never blends into adjacent digits
let mut hash = StrBuf::from_str("h");
hash.push_str(truncated_hash_result(symbol_hasher));
hash.into_owned()
hash.push_str(truncated_hash_result(symbol_hasher).as_slice());
hash
}
fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> StrBuf {
match ccx.type_hashcodes.borrow().find(&t) {
Some(h) => return h.to_str(),
Some(h) => return h.to_strbuf(),
None => {}
}
@ -595,7 +600,7 @@ fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
// Name sanitation. LLVM will happily accept identifiers with weird names, but
// gas doesn't!
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
pub fn sanitize(s: &str) -> ~str {
pub fn sanitize(s: &str) -> StrBuf {
let mut result = StrBuf::new();
for c in s.chars() {
match c {
@ -630,11 +635,10 @@ pub fn sanitize(s: &str) -> ~str {
}
// Underscore-qualify anything that didn't start as an ident.
let result = result.into_owned();
if result.len() > 0u &&
result[0] != '_' as u8 &&
! char::is_XID_start(result[0] as char) {
return "_".to_owned() + result;
result.as_slice()[0] != '_' as u8 &&
! char::is_XID_start(result.as_slice()[0] as char) {
return ("_" + result.as_slice()).to_strbuf();
}
return result;
@ -642,7 +646,7 @@ pub fn sanitize(s: &str) -> ~str {
pub fn mangle<PI: Iterator<PathElem>>(mut path: PI,
hash: Option<&str>,
vers: Option<&str>) -> ~str {
vers: Option<&str>) -> StrBuf {
// Follow C++ namespace-mangling style, see
// http://en.wikipedia.org/wiki/Name_mangling for more info.
//
@ -679,10 +683,10 @@ pub fn mangle<PI: Iterator<PathElem>>(mut path: PI,
}
n.push_char('E'); // End name-sequence.
n.into_owned()
n
}
pub fn exported_name(path: PathElems, hash: &str, vers: &str) -> ~str {
pub fn exported_name(path: PathElems, hash: &str, vers: &str) -> StrBuf {
// The version will get mangled to have a leading '_', but it makes more
// sense to lead with a 'v' b/c this is a version...
let vers = if vers.len() > 0 && !char::is_XID_start(vers.char_at(0)) {
@ -695,8 +699,8 @@ pub fn exported_name(path: PathElems, hash: &str, vers: &str) -> ~str {
}
pub fn mangle_exported_name(ccx: &CrateContext, path: PathElems,
t: ty::t, id: ast::NodeId) -> ~str {
let mut hash = StrBuf::from_owned_str(get_symbol_hash(ccx, t));
t: ty::t, id: ast::NodeId) -> StrBuf {
let mut hash = get_symbol_hash(ccx, t);
// Paths can be completely identical for different nodes,
// e.g. `fn foo() { { fn a() {} } { fn a() {} } }`, so we
@ -723,25 +727,28 @@ pub fn mangle_exported_name(ccx: &CrateContext, path: PathElems,
pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext,
t: ty::t,
name: &str) -> ~str {
name: &str) -> StrBuf {
let s = ppaux::ty_to_str(ccx.tcx(), t);
let path = [PathName(token::intern(s)),
let path = [PathName(token::intern(s.as_slice())),
gensym_name(name)];
let hash = get_symbol_hash(ccx, t);
mangle(ast_map::Values(path.iter()), Some(hash.as_slice()), None)
}
pub fn mangle_internal_name_by_path_and_seq(path: PathElems, flav: &str) -> ~str {
pub fn mangle_internal_name_by_path_and_seq(path: PathElems, flav: &str) -> StrBuf {
mangle(path.chain(Some(gensym_name(flav)).move_iter()), None, None)
}
pub fn output_lib_filename(id: &CrateId) -> ~str {
format!("{}-{}-{}", id.name, crate_id_hash(id), id.version_or_default())
pub fn output_lib_filename(id: &CrateId) -> StrBuf {
format_strbuf!("{}-{}-{}",
id.name,
crate_id_hash(id),
id.version_or_default())
}
pub fn get_cc_prog(sess: &Session) -> ~str {
pub fn get_cc_prog(sess: &Session) -> StrBuf {
match sess.opts.cg.linker {
Some(ref linker) => return linker.to_owned(),
Some(ref linker) => return linker.to_strbuf(),
None => {}
}
@ -750,23 +757,23 @@ pub fn get_cc_prog(sess: &Session) -> ~str {
// instead of hard-coded gcc.
// For win32, there is no cc command, so we add a condition to make it use gcc.
match sess.targ_cfg.os {
abi::OsWin32 => return "gcc".to_owned(),
abi::OsWin32 => return "gcc".to_strbuf(),
_ => {},
}
get_system_tool(sess, "cc")
}
pub fn get_ar_prog(sess: &Session) -> ~str {
pub fn get_ar_prog(sess: &Session) -> StrBuf {
match sess.opts.cg.ar {
Some(ref ar) => return ar.to_owned(),
Some(ref ar) => return (*ar).clone(),
None => {}
}
get_system_tool(sess, "ar")
}
fn get_system_tool(sess: &Session, tool: &str) -> ~str {
fn get_system_tool(sess: &Session, tool: &str) -> StrBuf {
match sess.targ_cfg.os {
abi::OsAndroid => match sess.opts.cg.android_cross_path {
Some(ref path) => {
@ -774,14 +781,16 @@ fn get_system_tool(sess: &Session, tool: &str) -> ~str {
"cc" => "gcc",
_ => tool
};
format!("{}/bin/arm-linux-androideabi-{}", *path, tool_str)
format_strbuf!("{}/bin/arm-linux-androideabi-{}",
*path,
tool_str)
}
None => {
sess.fatal(format!("need Android NDK path for the '{}' tool \
(-C android-cross-path)", tool))
}
},
_ => tool.to_owned(),
_ => tool.to_strbuf(),
}
}
@ -1022,7 +1031,7 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
continue
}
};
a.add_rlib(&p, name, sess.lto()).unwrap();
a.add_rlib(&p, name.as_slice(), sess.lto()).unwrap();
let native_libs = csearch::get_native_libraries(&sess.cstore, cnum);
for &(kind, ref lib) in native_libs.iter() {
let name = match kind {
@ -1057,7 +1066,11 @@ fn link_natively(sess: &Session, trans: &CrateTranslation, dylib: bool,
// Invoke the system linker
debug!("{} {}", cc_prog, cc_args.connect(" "));
let prog = time(sess.time_passes(), "running linker", (), |()|
Process::output(cc_prog, cc_args.as_slice()));
Process::output(cc_prog.as_slice(),
cc_args.iter()
.map(|x| (*x).to_owned())
.collect::<Vec<_>>()
.as_slice()));
match prog {
Ok(prog) => {
if !prog.status.success() {
@ -1096,20 +1109,20 @@ fn link_args(sess: &Session,
tmpdir: &Path,
trans: &CrateTranslation,
obj_filename: &Path,
out_filename: &Path) -> Vec<~str> {
out_filename: &Path) -> Vec<StrBuf> {
// The default library location, we need this to find the runtime.
// The location of crates will be determined as needed.
// FIXME (#9639): This needs to handle non-utf8 paths
let lib_path = sess.target_filesearch().get_lib_path();
let stage: ~str = "-L".to_owned() + lib_path.as_str().unwrap();
let stage = ("-L".to_owned() + lib_path.as_str().unwrap()).to_strbuf();
let mut args = vec!(stage);
// FIXME (#9639): This needs to handle non-utf8 paths
args.push_all([
"-o".to_owned(), out_filename.as_str().unwrap().to_owned(),
obj_filename.as_str().unwrap().to_owned()]);
"-o".to_strbuf(), out_filename.as_str().unwrap().to_strbuf(),
obj_filename.as_str().unwrap().to_strbuf()]);
// Stack growth requires statically linking a __morestack function. Note
// that this is listed *before* all other libraries, even though it may be
@ -1126,14 +1139,14 @@ fn link_args(sess: &Session,
// line, but inserting this farther to the left makes the
// "rust_stack_exhausted" symbol an outstanding undefined symbol, which
// flags libstd as a required library (or whatever provides the symbol).
args.push("-lmorestack".to_owned());
args.push("-lmorestack".to_strbuf());
// When linking a dynamic library, we put the metadata into a section of the
// executable. This metadata is in a separate object file from the main
// object file, so we link that in here.
if dylib {
let metadata = obj_filename.with_extension("metadata.o");
args.push(metadata.as_str().unwrap().to_owned());
args.push(metadata.as_str().unwrap().to_strbuf());
}
// We want to prevent the compiler from accidentally leaking in any system
@ -1144,7 +1157,7 @@ fn link_args(sess: &Session,
//
// FIXME(#11937) we should invoke the system linker directly
if sess.targ_cfg.os != abi::OsWin32 {
args.push("-nodefaultlibs".to_owned());
args.push("-nodefaultlibs".to_strbuf());
}
// If we're building a dylib, we don't use --gc-sections because LLVM has
@ -1152,20 +1165,20 @@ fn link_args(sess: &Session,
// metadata. If we're building an executable, however, --gc-sections drops
// the size of hello world from 1.8MB to 597K, a 67% reduction.
if !dylib && sess.targ_cfg.os != abi::OsMacos {
args.push("-Wl,--gc-sections".to_owned());
args.push("-Wl,--gc-sections".to_strbuf());
}
if sess.targ_cfg.os == abi::OsLinux {
// 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.
args.push("-Wl,--as-needed".to_owned());
args.push("-Wl,--as-needed".to_strbuf());
// GNU-style linkers support optimization with -O. GNU ld doesn't need a
// numeric argument, but other linkers do.
if sess.opts.optimize == config::Default ||
sess.opts.optimize == config::Aggressive {
args.push("-Wl,-O1".to_owned());
args.push("-Wl,-O1".to_strbuf());
}
} else if sess.targ_cfg.os == abi::OsMacos {
// The dead_strip option to the linker specifies that functions and data
@ -1178,14 +1191,14 @@ fn link_args(sess: &Session,
// won't get much benefit from dylibs because LLVM will have already
// stripped away as much as it could. This has not been seen to impact
// link times negatively.
args.push("-Wl,-dead_strip".to_owned());
args.push("-Wl,-dead_strip".to_strbuf());
}
if sess.targ_cfg.os == abi::OsWin32 {
// Make sure that we link to the dynamic libgcc, otherwise cross-module
// DWARF stack unwinding will not work.
// This behavior may be overridden by --link-args "-static-libgcc"
args.push("-shared-libgcc".to_owned());
args.push("-shared-libgcc".to_strbuf());
// And here, we see obscure linker flags #45. On windows, it has been
// found to be necessary to have this flag to compile liblibc.
@ -1212,13 +1225,13 @@ fn link_args(sess: &Session,
//
// [1] - https://sourceware.org/bugzilla/show_bug.cgi?id=13130
// [2] - https://code.google.com/p/go/issues/detail?id=2139
args.push("-Wl,--enable-long-section-names".to_owned());
args.push("-Wl,--enable-long-section-names".to_strbuf());
}
if sess.targ_cfg.os == abi::OsAndroid {
// Many of the symbols defined in compiler-rt are also defined in libgcc.
// Android linker doesn't like that by default.
args.push("-Wl,--allow-multiple-definition".to_owned());
args.push("-Wl,--allow-multiple-definition".to_strbuf());
}
// Take careful note of the ordering of the arguments we pass to the linker
@ -1263,22 +1276,23 @@ fn link_args(sess: &Session,
if dylib {
// On mac we need to tell the linker to let this library be rpathed
if sess.targ_cfg.os == abi::OsMacos {
args.push("-dynamiclib".to_owned());
args.push("-Wl,-dylib".to_owned());
args.push("-dynamiclib".to_strbuf());
args.push("-Wl,-dylib".to_strbuf());
// FIXME (#9639): This needs to handle non-utf8 paths
if !sess.opts.cg.no_rpath {
args.push("-Wl,-install_name,@rpath/".to_owned() +
out_filename.filename_str().unwrap());
args.push(format_strbuf!("-Wl,-install_name,@rpath/{}",
out_filename.filename_str()
.unwrap()));
}
} else {
args.push("-shared".to_owned())
args.push("-shared".to_strbuf())
}
}
if sess.targ_cfg.os == abi::OsFreebsd {
args.push_all(["-L/usr/local/lib".to_owned(),
"-L/usr/local/lib/gcc46".to_owned(),
"-L/usr/local/lib/gcc44".to_owned()]);
args.push_all(["-L/usr/local/lib".to_strbuf(),
"-L/usr/local/lib/gcc46".to_strbuf(),
"-L/usr/local/lib/gcc44".to_strbuf()]);
}
// FIXME (#2397): At some point we want to rpath our guesses as to
@ -1295,7 +1309,7 @@ fn link_args(sess: &Session,
//
// This is the end of the command line, so this library is used to resolve
// *all* undefined symbols in all other libraries, and this is intentional.
args.push("-lcompiler-rt".to_owned());
args.push("-lcompiler-rt".to_strbuf());
// Finally add all the linker arguments provided on the command line along
// with any #[link_args] attributes found inside the crate
@ -1317,16 +1331,16 @@ fn link_args(sess: &Session,
// Also note that the native libraries linked here are only the ones located
// in the current crate. Upstream crates with native library dependencies
// may have their native library pulled in above.
fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
fn add_local_native_libraries(args: &mut Vec<StrBuf>, sess: &Session) {
for path in sess.opts.addl_lib_search_paths.borrow().iter() {
// FIXME (#9639): This needs to handle non-utf8 paths
args.push("-L" + path.as_str().unwrap().to_owned());
args.push(("-L" + path.as_str().unwrap().to_owned()).to_strbuf());
}
let rustpath = filesearch::rust_path();
for path in rustpath.iter() {
// FIXME (#9639): This needs to handle non-utf8 paths
args.push("-L" + path.as_str().unwrap().to_owned());
args.push(("-L" + path.as_str().unwrap().to_owned()).to_strbuf());
}
// Some platforms take hints about whether a library is static or dynamic.
@ -1340,21 +1354,21 @@ fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
cstore::NativeUnknown | cstore::NativeStatic => {
if takes_hints {
if kind == cstore::NativeStatic {
args.push("-Wl,-Bstatic".to_owned());
args.push("-Wl,-Bstatic".to_strbuf());
} else {
args.push("-Wl,-Bdynamic".to_owned());
args.push("-Wl,-Bdynamic".to_strbuf());
}
}
args.push("-l" + *l);
args.push(format_strbuf!("-l{}", *l));
}
cstore::NativeFramework => {
args.push("-framework".to_owned());
args.push(l.to_owned());
args.push("-framework".to_strbuf());
args.push(l.to_strbuf());
}
}
}
if takes_hints {
args.push("-Wl,-Bdynamic".to_owned());
args.push("-Wl,-Bdynamic".to_strbuf());
}
}
@ -1363,7 +1377,7 @@ fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
// Rust crates are not considered at all when creating an rlib output. All
// dependencies will be linked when producing the final output (instead of
// the intermediate rlib version)
fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
fn add_upstream_rust_crates(args: &mut Vec<StrBuf>, sess: &Session,
dylib: bool, tmpdir: &Path,
trans: &CrateTranslation) {
// All of the heavy lifting has previously been accomplished by the
@ -1405,16 +1419,16 @@ fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
}
// Converts a library file-stem into a cc -l argument
fn unlib(config: &config::Config, stem: &str) -> ~str {
fn unlib(config: &config::Config, stem: &str) -> StrBuf {
if stem.starts_with("lib") && config.os != abi::OsWin32 {
stem.slice(3, stem.len()).to_owned()
stem.slice(3, stem.len()).to_strbuf()
} else {
stem.to_owned()
stem.to_strbuf()
}
}
// Adds the static "rlib" versions of all crates to the command line.
fn add_static_crate(args: &mut Vec<~str>, sess: &Session, tmpdir: &Path,
fn add_static_crate(args: &mut Vec<StrBuf>, sess: &Session, tmpdir: &Path,
cnum: ast::CrateNum, cratepath: Path) {
// When performing LTO on an executable output, all of the
// bytecode from the upstream libraries has already been
@ -1445,21 +1459,21 @@ fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
sess.abort_if_errors();
}
}
let dst_str = dst.as_str().unwrap().to_owned();
let dst_str = dst.as_str().unwrap().to_strbuf();
let mut archive = Archive::open(sess, dst);
archive.remove_file(format!("{}.o", name));
let files = archive.files();
if files.iter().any(|s| s.ends_with(".o")) {
if files.iter().any(|s| s.as_slice().ends_with(".o")) {
args.push(dst_str);
}
});
} else {
args.push(cratepath.as_str().unwrap().to_owned());
args.push(cratepath.as_str().unwrap().to_strbuf());
}
}
// Same thing as above, but for dynamic crates instead of static crates.
fn add_dynamic_crate(args: &mut Vec<~str>, sess: &Session,
fn add_dynamic_crate(args: &mut Vec<StrBuf>, sess: &Session,
cratepath: Path) {
// If we're performing LTO, then it should have been previously required
// that all upstream rust dependencies were available in an rlib format.
@ -1468,9 +1482,11 @@ fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
// Just need to tell the linker about where the library lives and
// what its name is
let dir = cratepath.dirname_str().unwrap();
if !dir.is_empty() { args.push("-L" + dir); }
if !dir.is_empty() {
args.push(format_strbuf!("-L{}", dir));
}
let libarg = unlib(&sess.targ_cfg, cratepath.filestem_str().unwrap());
args.push("-l" + libarg);
args.push(format_strbuf!("-l{}", libarg));
}
}
@ -1492,7 +1508,7 @@ fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
// generic function calls a native function, then the generic function must
// be instantiated in the target crate, meaning that the native symbol must
// also be resolved in the target crate.
fn add_upstream_native_libraries(args: &mut Vec<~str>, sess: &Session) {
fn add_upstream_native_libraries(args: &mut Vec<StrBuf>, sess: &Session) {
// Be sure to use a topological sorting of crates because there may be
// interdependencies between native libraries. When passing -nodefaultlibs,
// for example, almost all native libraries depend on libc, so we have to
@ -1507,10 +1523,12 @@ fn add_upstream_native_libraries(args: &mut Vec<~str>, sess: &Session) {
let libs = csearch::get_native_libraries(&sess.cstore, cnum);
for &(kind, ref lib) in libs.iter() {
match kind {
cstore::NativeUnknown => args.push("-l" + *lib),
cstore::NativeUnknown => {
args.push(format_strbuf!("-l{}", *lib))
}
cstore::NativeFramework => {
args.push("-framework".to_owned());
args.push(lib.to_owned());
args.push("-framework".to_strbuf());
args.push(lib.to_strbuf());
}
cstore::NativeStatic => {
sess.bug("statics shouldn't be propagated");

View file

@ -20,7 +20,7 @@ use libc;
use flate;
pub fn run(sess: &session::Session, llmod: ModuleRef,
tm: TargetMachineRef, reachable: &[~str]) {
tm: TargetMachineRef, reachable: &[StrBuf]) {
if sess.opts.cg.prefer_dynamic {
sess.err("cannot prefer dynamic linking when performing LTO");
sess.note("only 'staticlib' and 'bin' outputs are supported with LTO");
@ -67,13 +67,16 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
if !llvm::LLVMRustLinkInExternalBitcode(llmod,
ptr as *libc::c_char,
bc.len() as libc::size_t) {
link::llvm_err(sess, format!("failed to load bc of `{}`", name));
link::llvm_err(sess,
(format_strbuf!("failed to load bc of `{}`",
name)));
}
});
}
// Internalize everything but the reachable symbols of the current module
let cstrs: Vec<::std::c_str::CString> = reachable.iter().map(|s| s.to_c_str()).collect();
let cstrs: Vec<::std::c_str::CString> =
reachable.iter().map(|s| s.as_slice().to_c_str()).collect();
let arr: Vec<*i8> = cstrs.iter().map(|c| c.with_ref(|p| p)).collect();
let ptr = arr.as_ptr();
unsafe {

View file

@ -13,51 +13,52 @@ use driver::config::cfg_os_to_meta_os;
use metadata::loader::meta_section_name;
use syntax::abi;
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
pub fn get_target_strs(target_triple: StrBuf, target_os: abi::Os) -> target_strs::t {
return target_strs::t {
module_asm: "".to_owned(),
module_asm: "".to_strbuf(),
meta_sect_name: meta_section_name(cfg_os_to_meta_os(target_os)).to_owned(),
meta_sect_name:
meta_section_name(cfg_os_to_meta_os(target_os)).to_strbuf(),
data_layout: match target_os {
abi::OsMacos => {
"E-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"E-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsWin32 => {
"E-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"E-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsLinux => {
"E-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"E-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsAndroid => {
"E-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"E-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
abi::OsFreebsd => {
"E-p:32:32:32".to_owned() +
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
"-f32:32:32-f64:64:64" +
"-v64:64:64-v128:64:128" +
"-a0:0:64-n32"
"E-p:32:32:32\
-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-f32:32:32-f64:64:64\
-v64:64:64-v128:64:128\
-a0:0:64-n32".to_strbuf()
}
},

View file

@ -22,7 +22,7 @@ fn not_win32(os: abi::Os) -> bool {
os != abi::OsWin32
}
pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<StrBuf> {
let os = sess.targ_cfg.os;
// No rpath on windows
@ -33,9 +33,9 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
let mut flags = Vec::new();
if sess.targ_cfg.os == abi::OsFreebsd {
flags.push_all(["-Wl,-rpath,/usr/local/lib/gcc46".to_owned(),
"-Wl,-rpath,/usr/local/lib/gcc44".to_owned(),
"-Wl,-z,origin".to_owned()]);
flags.push_all(["-Wl,-rpath,/usr/local/lib/gcc46".to_strbuf(),
"-Wl,-rpath,/usr/local/lib/gcc44".to_strbuf(),
"-Wl,-z,origin".to_strbuf()]);
}
debug!("preparing the RPATH!");
@ -47,16 +47,19 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
l.map(|p| p.clone())
}).collect::<Vec<_>>();
let rpaths = get_rpaths(os, sysroot, output, libs.as_slice(),
sess.opts.target_triple);
let rpaths = get_rpaths(os,
sysroot,
output,
libs.as_slice(),
sess.opts.target_triple.as_slice());
flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice());
flags
}
pub fn rpaths_to_flags(rpaths: &[~str]) -> Vec<~str> {
pub fn rpaths_to_flags(rpaths: &[StrBuf]) -> Vec<StrBuf> {
let mut ret = Vec::new();
for rpath in rpaths.iter() {
ret.push("-Wl,-rpath," + *rpath);
ret.push(("-Wl,-rpath," + (*rpath).as_slice()).to_strbuf());
}
return ret;
}
@ -65,7 +68,7 @@ fn get_rpaths(os: abi::Os,
sysroot: &Path,
output: &Path,
libs: &[Path],
target_triple: &str) -> Vec<~str> {
target_triple: &str) -> Vec<StrBuf> {
debug!("sysroot: {}", sysroot.display());
debug!("output: {}", output.display());
debug!("libs:");
@ -82,7 +85,7 @@ fn get_rpaths(os: abi::Os,
// And a final backup rpath to the global library location.
let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple));
fn log_rpaths(desc: &str, rpaths: &[~str]) {
fn log_rpaths(desc: &str, rpaths: &[StrBuf]) {
debug!("{} rpaths:", desc);
for rpath in rpaths.iter() {
debug!(" {}", *rpath);
@ -102,14 +105,14 @@ fn get_rpaths(os: abi::Os,
fn get_rpaths_relative_to_output(os: abi::Os,
output: &Path,
libs: &[Path]) -> Vec<~str> {
libs: &[Path]) -> Vec<StrBuf> {
libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect()
}
pub fn get_rpath_relative_to_output(os: abi::Os,
output: &Path,
lib: &Path)
-> ~str {
-> StrBuf {
use std::os;
assert!(not_win32(os));
@ -129,10 +132,11 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
let relative = lib.path_relative_from(&output);
let relative = relative.expect("could not create rpath relative to output");
// FIXME (#9639): This needs to handle non-utf8 paths
prefix+"/"+relative.as_str().expect("non-utf8 component in path")
(prefix + "/" + relative.as_str()
.expect("non-utf8 component in path")).to_strbuf()
}
pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str {
pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> StrBuf {
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
@ -140,10 +144,10 @@ pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str {
path.push(&tlib);
let path = os::make_absolute(&path);
// FIXME (#9639): This needs to handle non-utf8 paths
path.as_str().expect("non-utf8 component in rpath").to_owned()
path.as_str().expect("non-utf8 component in rpath").to_strbuf()
}
pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> {
pub fn minimize_rpaths(rpaths: &[StrBuf]) -> Vec<StrBuf> {
let mut set = HashSet::new();
let mut minimized = Vec::new();
for rpath in rpaths.iter() {
@ -163,8 +167,13 @@ mod test {
#[test]
fn test_rpaths_to_flags() {
let flags = rpaths_to_flags(["path1".to_owned(), "path2".to_owned()]);
assert_eq!(flags, vec!("-Wl,-rpath,path1".to_owned(), "-Wl,-rpath,path2".to_owned()));
let flags = rpaths_to_flags([
"path1".to_strbuf(),
"path2".to_strbuf()
]);
assert_eq!(flags,
vec!("-Wl,-rpath,path1".to_strbuf(),
"-Wl,-rpath,path2".to_strbuf()));
}
#[test]
@ -190,18 +199,37 @@ mod test {
#[test]
fn test_minimize1() {
let res = minimize_rpaths(["rpath1".to_owned(), "rpath2".to_owned(), "rpath1".to_owned()]);
assert!(res.as_slice() == ["rpath1".to_owned(), "rpath2".to_owned()]);
let res = minimize_rpaths([
"rpath1".to_strbuf(),
"rpath2".to_strbuf(),
"rpath1".to_strbuf()
]);
assert!(res.as_slice() == [
"rpath1".to_strbuf(),
"rpath2".to_strbuf()
]);
}
#[test]
fn test_minimize2() {
let res = minimize_rpaths(["1a".to_owned(), "2".to_owned(), "2".to_owned(),
"1a".to_owned(), "4a".to_owned(), "1a".to_owned(),
"2".to_owned(), "3".to_owned(), "4a".to_owned(),
"3".to_owned()]);
assert!(res.as_slice() == ["1a".to_owned(), "2".to_owned(), "4a".to_owned(),
"3".to_owned()]);
let res = minimize_rpaths([
"1a".to_strbuf(),
"2".to_strbuf(),
"2".to_strbuf(),
"1a".to_strbuf(),
"4a".to_strbuf(),
"1a".to_strbuf(),
"2".to_strbuf(),
"3".to_strbuf(),
"4a".to_strbuf(),
"3".to_strbuf()
]);
assert!(res.as_slice() == [
"1a".to_strbuf(),
"2".to_strbuf(),
"4a".to_strbuf(),
"3".to_strbuf()
]);
}
#[test]

View file

@ -54,13 +54,13 @@ use syntax::ast;
#[deriving(Clone, Eq)]
pub struct Svh {
hash: ~str,
hash: StrBuf,
}
impl Svh {
pub fn new(hash: &str) -> Svh {
assert!(hash.len() == 16);
Svh { hash: hash.to_owned() }
Svh { hash: hash.to_strbuf() }
}
pub fn as_str<'a>(&'a self) -> &'a str {

View file

@ -11,9 +11,9 @@
#![allow(non_camel_case_types)]
pub struct t {
pub module_asm: ~str,
pub meta_sect_name: ~str,
pub data_layout: ~str,
pub target_triple: ~str,
pub cc_args: Vec<~str> ,
pub module_asm: StrBuf,
pub meta_sect_name: StrBuf,
pub data_layout: StrBuf,
pub target_triple: StrBuf,
pub cc_args: Vec<StrBuf> ,
}

View file

@ -14,38 +14,41 @@ use driver::config::cfg_os_to_meta_os;
use metadata::loader::meta_section_name;
use syntax::abi;
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
pub fn get_target_strs(target_triple: StrBuf, target_os: abi::Os)
-> target_strs::t {
return target_strs::t {
module_asm: "".to_owned(),
module_asm: "".to_strbuf(),
meta_sect_name: meta_section_name(cfg_os_to_meta_os(target_os)).to_owned(),
meta_sect_name:
meta_section_name(cfg_os_to_meta_os(target_os)).to_strbuf(),
data_layout: match target_os {
abi::OsMacos => {
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16".to_owned() +
"-i32:32:32-i64:32:64" +
"-f32:32:32-f64:32:64-v64:64:64" +
"-v128:128:128-a0:0:64-f80:128:128" + "-n8:16:32"
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16\
-i32:32:32-i64:32:64\
-f32:32:32-f64:32:64-v64:64:64\
-v128:128:128-a0:0:64-f80:128:128\
-n8:16:32".to_strbuf()
}
abi::OsWin32 => {
"e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32".to_owned()
"e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32".to_strbuf()
}
abi::OsLinux => {
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_owned()
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_strbuf()
}
abi::OsAndroid => {
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_owned()
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_strbuf()
}
abi::OsFreebsd => {
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_owned()
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_strbuf()
}
},
target_triple: target_triple,
cc_args: vec!("-m32".to_owned()),
cc_args: vec!("-m32".to_strbuf()),
};
}

View file

@ -14,46 +14,47 @@ use driver::config::cfg_os_to_meta_os;
use metadata::loader::meta_section_name;
use syntax::abi;
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
pub fn get_target_strs(target_triple: StrBuf, target_os: abi::Os) -> target_strs::t {
return target_strs::t {
module_asm: "".to_owned(),
module_asm: "".to_strbuf(),
meta_sect_name: meta_section_name(cfg_os_to_meta_os(target_os)).to_owned(),
meta_sect_name:
meta_section_name(cfg_os_to_meta_os(target_os)).to_strbuf(),
data_layout: match target_os {
abi::OsMacos => {
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
"s0:64:64-f80:128:128-n8:16:32:64"
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
s0:64:64-f80:128:128-n8:16:32:64".to_strbuf()
}
abi::OsWin32 => {
// FIXME: Test this. Copied from linux (#2398)
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
"s0:64:64-f80:128:128-n8:16:32:64-S128"
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
s0:64:64-f80:128:128-n8:16:32:64-S128".to_strbuf()
}
abi::OsLinux => {
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
"s0:64:64-f80:128:128-n8:16:32:64-S128"
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
s0:64:64-f80:128:128-n8:16:32:64-S128".to_strbuf()
}
abi::OsAndroid => {
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
"s0:64:64-f80:128:128-n8:16:32:64-S128"
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
s0:64:64-f80:128:128-n8:16:32:64-S128".to_strbuf()
}
abi::OsFreebsd => {
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
"s0:64:64-f80:128:128-n8:16:32:64-S128"
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
s0:64:64-f80:128:128-n8:16:32:64-S128".to_strbuf()
}
},
target_triple: target_triple,
cc_args: vec!("-m64".to_owned()),
cc_args: vec!("-m64".to_strbuf()),
};
}