Skip to content

Commit 3d8a5cb

Browse files
committed
Remember the library files we used in rustc and pass them to the "linker".
This avoid the hardcoded -lstd, allows programs to use other crates and avoids any differences that may exist in the rustc and ld search logic.
1 parent a2dcd08 commit 3d8a5cb

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/comp/driver/rustc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn build_session(@session::options sopts) -> session::session {
271271
auto crate_cache = common::new_int_hash[session::crate_metadata]();
272272
auto target_crate_num = 0;
273273
auto sess =
274-
session::session(target_crate_num, target_cfg, sopts, crate_cache,
274+
session::session(target_crate_num, target_cfg, sopts, crate_cache, [],
275275
front::codemap::new_codemap(), 0u);
276276
ret sess;
277277
}
@@ -417,10 +417,13 @@ fn main(vec[str] args) {
417417
gcc_args = common_args;
418418
}
419419
}
420+
421+
gcc_args += sess.get_used_libraries();
422+
420423
if (sopts.shared) {
421424
gcc_args += [shared_cmd];
422425
} else {
423-
gcc_args += ["-Lrustllvm", "-lrustllvm", "-lstd", "-lm", main];
426+
gcc_args += ["-Lrustllvm", "-lrustllvm", "-lm", main];
424427
}
425428
// We run 'gcc' here
426429

src/comp/driver/session.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ obj session(ast::crate_num cnum,
6666
@config targ_cfg,
6767
@options opts,
6868
map::hashmap[int, crate_metadata] crates,
69+
mutable vec[str] used_libraries,
6970
codemap::codemap cm,
7071
mutable uint err_count) {
7172
fn get_targ_cfg() -> @config { ret targ_cfg; }
@@ -122,6 +123,19 @@ obj session(ast::crate_num cnum,
122123
crates.insert(num, metadata);
123124
}
124125
fn has_external_crate(int num) -> bool { ret crates.contains_key(num); }
126+
fn add_used_library(&str lib) {
127+
// A program has a small number of libraries, so a vector is probably a
128+
// good data structure in here.
129+
for (str l in used_libraries) {
130+
if (l == lib) {
131+
ret;
132+
}
133+
}
134+
used_libraries += [lib];
135+
}
136+
fn get_used_libraries() -> vec[str] {
137+
ret used_libraries;
138+
}
125139
fn get_codemap() -> codemap::codemap { ret cm; }
126140
fn lookup_pos(uint pos) -> codemap::loc {
127141
ret codemap::lookup_pos(cm, pos);

src/comp/front/creader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,13 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
582582
ret none;
583583
}
584584

585-
fn load_library_crate(&session::session sess, &int cnum, &ast::ident ident,
585+
fn load_library_crate(&session::session sess, int cnum, &ast::ident ident,
586586
&vec[@ast::meta_item] metas,
587587
&vec[str] library_search_paths) {
588588
alt (find_library_crate(sess, ident, metas, library_search_paths)) {
589589
case (some(?t)) {
590590
sess.set_external_crate(cnum, rec(name=ident, data=t._1));
591+
sess.add_used_library(t._0);
591592
ret;
592593
}
593594
case (_) { }

0 commit comments

Comments
 (0)