Skip to content

Commit

Permalink
librustc: Add #[link_args] to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Mar 8, 2013
1 parent d661711 commit 48b14f5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use lib::llvm::llvm;
use lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False};
use lib;
use metadata::common::LinkMeta;
use metadata::{encoder, cstore};
use metadata::{encoder, csearch, cstore};
use middle::trans::common::CrateContext;
use middle::ty;
use util::ppaux;
Expand Down Expand Up @@ -814,6 +814,14 @@ pub fn link_binary(sess: Session,
let ula = cstore::get_used_link_args(cstore);
for ula.each |arg| { cc_args.push(/*bad*/copy *arg); }

// 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);
do vec::consume(link_args) |_, link_arg| {
cc_args.push(link_arg);
}
}

// # Extern library linking

// User-supplied library search paths (-L on the cammand line) These are
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ pub const tag_item_unnamed_field: uint = 0x76;
pub const tag_items_data_item_struct_ctor: uint = 0x77;
pub const tag_items_data_item_visibility: uint = 0x78;

pub const tag_link_args: uint = 0x79;
pub const tag_link_args_arg: uint = 0x7a;

pub struct LinkMeta {
name: @str,
vers: @str,
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ pub fn get_method_visibility(cstore: @mut cstore::CStore,
decoder::get_method_visibility(cdata, def_id.node)
}

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

// Local Variables:
// mode: rust
// fill-column: 78;
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,15 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
}
}

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 = ~[];
for reader::tagged_docs(link_args, tag_link_args_arg) |arg_doc| {
result.push(reader::doc_as_str(arg_doc));
}
result
}

// Local Variables:
// mode: rust
// fill-column: 78;
Expand Down
22 changes: 22 additions & 0 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct Stats {
attr_bytes: uint,
dep_bytes: uint,
lang_item_bytes: uint,
link_args_bytes: uint,
item_bytes: uint,
index_bytes: uint,
zero_bytes: uint,
Expand Down Expand Up @@ -1255,6 +1256,20 @@ fn encode_lang_items(ecx: @EncodeContext, ebml_w: writer::Encoder) {
ebml_w.end_tag(); // tag_lang_items
}

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

let link_args = cstore::get_used_link_args(ecx.cstore);
for link_args.each |link_arg| {
ebml_w.start_tag(tag_link_args_arg);
ebml_w.writer.write_str(link_arg.to_str());
ebml_w.end_tag();
}

ebml_w.end_tag();
}

fn encode_crate_dep(ecx: @EncodeContext, ebml_w: writer::Encoder,
dep: decoder::crate_dep) {
ebml_w.start_tag(tag_crate_dep);
Expand Down Expand Up @@ -1291,6 +1306,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
attr_bytes: 0,
dep_bytes: 0,
lang_item_bytes: 0,
link_args_bytes: 0,
item_bytes: 0,
index_bytes: 0,
zero_bytes: 0,
Expand Down Expand Up @@ -1329,6 +1345,11 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
encode_lang_items(ecx, ebml_w);
ecx.stats.lang_item_bytes = wr.pos - i;

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

// Encode and index the items.
ebml_w.start_tag(tag_items);
i = wr.pos;
Expand Down Expand Up @@ -1359,6 +1380,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
io::println(fmt!(" attribute bytes: %u", ecx.stats.attr_bytes));
io::println(fmt!(" dep bytes: %u", ecx.stats.dep_bytes));
io::println(fmt!(" lang item bytes: %u", ecx.stats.lang_item_bytes));
io::println(fmt!(" link args bytes: %u", ecx.stats.link_args_bytes));
io::println(fmt!(" item bytes: %u", ecx.stats.item_bytes));
io::println(fmt!(" index bytes: %u", ecx.stats.index_bytes));
io::println(fmt!(" zero bytes: %u", ecx.stats.zero_bytes));
Expand Down

5 comments on commit 48b14f5

@bors
Copy link
Contributor

@bors bors commented on 48b14f5 Mar 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at pcwalton@48b14f5

@bors
Copy link
Contributor

@bors bors commented on 48b14f5 Mar 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/rust/assert = 48b14f5 into auto

@bors
Copy link
Contributor

@bors bors commented on 48b14f5 Mar 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcwalton/rust/assert = 48b14f5 merged ok, testing candidate = 647a94d

@bors
Copy link
Contributor

@bors bors commented on 48b14f5 Mar 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 48b14f5 Mar 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 647a94d

Please sign in to comment.