Skip to content

Commit 48b14f5

Browse files
committed
librustc: Add #[link_args] to metadata
1 parent d661711 commit 48b14f5

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

src/librustc/back/link.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use lib::llvm::llvm;
1717
use lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False};
1818
use lib;
1919
use metadata::common::LinkMeta;
20-
use metadata::{encoder, cstore};
20+
use metadata::{encoder, csearch, cstore};
2121
use middle::trans::common::CrateContext;
2222
use middle::ty;
2323
use util::ppaux;
@@ -814,6 +814,14 @@ pub fn link_binary(sess: Session,
814814
let ula = cstore::get_used_link_args(cstore);
815815
for ula.each |arg| { cc_args.push(/*bad*/copy *arg); }
816816

817+
// Add all the link args for external crates.
818+
do cstore::iter_crate_data(cstore) |crate_num, _| {
819+
let link_args = csearch::get_link_args_for_crate(cstore, crate_num);
820+
do vec::consume(link_args) |_, link_arg| {
821+
cc_args.push(link_arg);
822+
}
823+
}
824+
817825
// # Extern library linking
818826

819827
// User-supplied library search paths (-L on the cammand line) These are

src/librustc/metadata/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ pub const tag_item_unnamed_field: uint = 0x76;
156156
pub const tag_items_data_item_struct_ctor: uint = 0x77;
157157
pub const tag_items_data_item_visibility: uint = 0x78;
158158

159+
pub const tag_link_args: uint = 0x79;
160+
pub const tag_link_args_arg: uint = 0x7a;
161+
159162
pub struct LinkMeta {
160163
name: @str,
161164
vers: @str,

src/librustc/metadata/csearch.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ pub fn get_method_visibility(cstore: @mut cstore::CStore,
237237
decoder::get_method_visibility(cdata, def_id.node)
238238
}
239239

240+
pub fn get_link_args_for_crate(cstore: @mut cstore::CStore,
241+
crate_num: ast::crate_num)
242+
-> ~[~str] {
243+
let cdata = cstore::get_crate_data(cstore, crate_num);
244+
decoder::get_link_args_for_crate(cdata)
245+
}
246+
240247
// Local Variables:
241248
// mode: rust
242249
// fill-column: 78;

src/librustc/metadata/decoder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,15 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
11311131
}
11321132
}
11331133

1134+
pub fn get_link_args_for_crate(cdata: cmd) -> ~[~str] {
1135+
let link_args = reader::get_doc(reader::Doc(cdata.data), tag_link_args);
1136+
let mut result = ~[];
1137+
for reader::tagged_docs(link_args, tag_link_args_arg) |arg_doc| {
1138+
result.push(reader::doc_as_str(arg_doc));
1139+
}
1140+
result
1141+
}
1142+
11341143
// Local Variables:
11351144
// mode: rust
11361145
// fill-column: 78;

src/librustc/metadata/encoder.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct Stats {
7474
attr_bytes: uint,
7575
dep_bytes: uint,
7676
lang_item_bytes: uint,
77+
link_args_bytes: uint,
7778
item_bytes: uint,
7879
index_bytes: uint,
7980
zero_bytes: uint,
@@ -1255,6 +1256,20 @@ fn encode_lang_items(ecx: @EncodeContext, ebml_w: writer::Encoder) {
12551256
ebml_w.end_tag(); // tag_lang_items
12561257
}
12571258
1259+
fn encode_link_args(ecx: @EncodeContext,
1260+
ebml_w: writer::Encoder) {
1261+
ebml_w.start_tag(tag_link_args);
1262+
1263+
let link_args = cstore::get_used_link_args(ecx.cstore);
1264+
for link_args.each |link_arg| {
1265+
ebml_w.start_tag(tag_link_args_arg);
1266+
ebml_w.writer.write_str(link_arg.to_str());
1267+
ebml_w.end_tag();
1268+
}
1269+
1270+
ebml_w.end_tag();
1271+
}
1272+
12581273
fn encode_crate_dep(ecx: @EncodeContext, ebml_w: writer::Encoder,
12591274
dep: decoder::crate_dep) {
12601275
ebml_w.start_tag(tag_crate_dep);
@@ -1291,6 +1306,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
12911306
attr_bytes: 0,
12921307
dep_bytes: 0,
12931308
lang_item_bytes: 0,
1309+
link_args_bytes: 0,
12941310
item_bytes: 0,
12951311
index_bytes: 0,
12961312
zero_bytes: 0,
@@ -1329,6 +1345,11 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
13291345
encode_lang_items(ecx, ebml_w);
13301346
ecx.stats.lang_item_bytes = wr.pos - i;
13311347
1348+
// Encode the link args.
1349+
i = wr.pos;
1350+
encode_link_args(ecx, ebml_w);
1351+
ecx.stats.link_args_bytes = wr.pos - i;
1352+
13321353
// Encode and index the items.
13331354
ebml_w.start_tag(tag_items);
13341355
i = wr.pos;
@@ -1359,6 +1380,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
13591380
io::println(fmt!(" attribute bytes: %u", ecx.stats.attr_bytes));
13601381
io::println(fmt!(" dep bytes: %u", ecx.stats.dep_bytes));
13611382
io::println(fmt!(" lang item bytes: %u", ecx.stats.lang_item_bytes));
1383+
io::println(fmt!(" link args bytes: %u", ecx.stats.link_args_bytes));
13621384
io::println(fmt!(" item bytes: %u", ecx.stats.item_bytes));
13631385
io::println(fmt!(" index bytes: %u", ecx.stats.index_bytes));
13641386
io::println(fmt!(" zero bytes: %u", ecx.stats.zero_bytes));

0 commit comments

Comments
 (0)