Skip to content

Commit

Permalink
Stop propagating link arguments across crates
Browse files Browse the repository at this point in the history
This is a fairly brittle modle that doesn't scale well across many crates. It's
unlikely that all of the downstream crates will have all of the original native
dependencies of all the upstream crates. In the case that FFI functions are
reachable, then it should be the responsibility of the downstream crate to link
against the correct library, or the upstream crate should prevent the functions
from being reachable.
  • Loading branch information
alexcrichton committed Nov 2, 2013
1 parent c15038d commit 2b9c774
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 47 deletions.
10 changes: 1 addition & 9 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use lib::llvm::llvm;
use lib::llvm::ModuleRef;
use lib;
use metadata::common::LinkMeta;
use metadata::{encoder, csearch, cstore, filesearch};
use metadata::{encoder, cstore, filesearch};
use middle::trans::context::CrateContext;
use middle::trans::common::gensym_name;
use middle::ty;
Expand Down Expand Up @@ -1043,14 +1043,6 @@ pub fn link_args(sess: Session,
let ula = cstore::get_used_link_args(cstore);
for arg in ula.iter() { args.push(arg.to_owned()); }

// Add all the link args for external crates.
do cstore::iter_crate_data(cstore) |crate_num, _| {
let link_args = csearch::get_link_args_for_crate(cstore, crate_num);
for link_arg in link_args.move_iter() {
args.push(link_arg);
}
}

// # Extern library linking

// User-supplied library search paths (-L on the cammand line) These are
Expand Down
7 changes: 0 additions & 7 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,6 @@ pub fn get_item_visibility(cstore: @mut cstore::CStore,
decoder::get_item_visibility(cdata, def_id.node)
}

pub fn get_link_args_for_crate(cstore: @mut cstore::CStore,
crate_num: ast::CrateNum)
-> ~[~str] {
let cdata = cstore::get_crate_data(cstore, crate_num);
decoder::get_link_args_for_crate(cdata)
}

pub fn each_impl(cstore: @mut cstore::CStore,
crate_num: ast::CrateNum,
callback: &fn(ast::DefId)) {
Expand Down
10 changes: 0 additions & 10 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,16 +1456,6 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
}
}

pub fn get_link_args_for_crate(cdata: Cmd) -> ~[~str] {
let link_args = reader::get_doc(reader::Doc(cdata.data), tag_link_args);
let mut result = ~[];
do reader::tagged_docs(link_args, tag_link_args_arg) |arg_doc| {
result.push(arg_doc.as_str());
true
};
result
}

pub fn each_impl(cdata: Cmd, callback: &fn(ast::DefId)) {
let impls_doc = reader::get_doc(reader::Doc(cdata.data), tag_impls);
let _ = do reader::tagged_docs(impls_doc, tag_impls_impl) |impl_doc| {
Expand Down
21 changes: 0 additions & 21 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct Stats {
attr_bytes: u64,
dep_bytes: u64,
lang_item_bytes: u64,
link_args_bytes: u64,
impl_bytes: u64,
misc_bytes: u64,
item_bytes: u64,
Expand Down Expand Up @@ -1610,19 +1609,6 @@ fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
ebml_w.end_tag(); // tag_lang_items
}

fn encode_link_args(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
ebml_w.start_tag(tag_link_args);

let link_args = cstore::get_used_link_args(ecx.cstore);
for link_arg in link_args.iter() {
ebml_w.start_tag(tag_link_args_arg);
ebml_w.writer.write(link_arg.as_bytes());
ebml_w.end_tag();
}

ebml_w.end_tag();
}

struct ImplVisitor<'self> {
ecx: &'self EncodeContext<'self>,
ebml_w: &'self mut writer::Encoder,
Expand Down Expand Up @@ -1740,7 +1726,6 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
attr_bytes: 0,
dep_bytes: 0,
lang_item_bytes: 0,
link_args_bytes: 0,
impl_bytes: 0,
misc_bytes: 0,
item_bytes: 0,
Expand Down Expand Up @@ -1797,11 +1782,6 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
encode_lang_items(&ecx, &mut ebml_w);
ecx.stats.lang_item_bytes = wr.tell() - i;

// Encode the link args.
i = wr.tell();
encode_link_args(&ecx, &mut ebml_w);
ecx.stats.link_args_bytes = wr.tell() - i;

// Encode the def IDs of impls, for coherence checking.
i = wr.tell();
encode_impls(&ecx, crate, &mut ebml_w);
Expand Down Expand Up @@ -1838,7 +1818,6 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
println!(" attribute bytes: {}", ecx.stats.attr_bytes);
println!(" dep bytes: {}", ecx.stats.dep_bytes);
println!(" lang item bytes: {}", ecx.stats.lang_item_bytes);
println!(" link args bytes: {}", ecx.stats.link_args_bytes);
println!(" impl bytes: {}", ecx.stats.impl_bytes);
println!(" misc bytes: {}", ecx.stats.misc_bytes);
println!(" item bytes: {}", ecx.stats.item_bytes);
Expand Down

0 comments on commit 2b9c774

Please sign in to comment.