Skip to content

Commit b669430

Browse files
committed
Use metadata to avoid always passing -Lrustllvm to the linker.
1 parent 6b1da80 commit b669430

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

src/comp/driver/rustc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn build_session(@session::options sopts) -> session::session {
299299
auto target_crate_num = 0;
300300
auto sess =
301301
session::session(target_crate_num, target_cfg, sopts, crate_cache, [],
302-
[], front::codemap::new_codemap(), 0u);
302+
[], [], front::codemap::new_codemap(), 0u);
303303
ret sess;
304304
}
305305

@@ -460,7 +460,7 @@ fn main(vec[str] args) {
460460
case (_) { rmext(filename) }
461461
};
462462
}
463-
463+
464464
for (str cratepath in sess.get_used_crate_files()) {
465465
auto dir = fs::dirname(cratepath);
466466
if (dir != "") {
@@ -470,6 +470,7 @@ fn main(vec[str] args) {
470470
gcc_args += ["-l" + libarg];
471471
}
472472

473+
gcc_args += sess.get_used_link_args();
473474
auto used_libs = sess.get_used_libraries();
474475
for (str l in used_libs) {
475476
gcc_args += ["-l" + l];
@@ -478,9 +479,8 @@ fn main(vec[str] args) {
478479
if (sopts.shared) {
479480
gcc_args += [shared_cmd];
480481
} else {
481-
// FIXME: having -Lrustllvm hardcoded in here is hack
482-
// FIXME: same for -lm
483-
gcc_args += ["-Lrustllvm", "-lm", main];
482+
// FIXME: why do we hardcode -lm?
483+
gcc_args += ["-lm", main];
484484
}
485485
// We run 'gcc' here
486486

src/comp/driver/session.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import std::map;
1010
import std::option;
1111
import std::option::some;
1212
import std::option::none;
13+
import std::str;
1314

1415
tag os { os_win32; os_macos; os_linux; }
1516

@@ -71,6 +72,7 @@ obj session(ast::crate_num cnum,
7172
map::hashmap[int, crate_metadata] crates,
7273
mutable vec[str] used_crate_files,
7374
mutable vec[str] used_libraries,
75+
mutable vec[str] used_link_args,
7476
codemap::codemap cm,
7577
mutable uint err_count) {
7678
fn get_targ_cfg() -> @config { ret targ_cfg; }
@@ -130,18 +132,25 @@ obj session(ast::crate_num cnum,
130132
crates.insert(num, metadata);
131133
}
132134
fn has_external_crate(int num) -> bool { ret crates.contains_key(num); }
133-
fn add_used_library(&str lib) {
135+
fn add_used_link_args(&str args) {
136+
used_link_args += str::split(args, ' ' as u8);
137+
}
138+
fn get_used_link_args() -> vec[str] {
139+
ret used_link_args;
140+
}
141+
fn add_used_library(&str lib) -> bool {
134142
if (lib == "") {
135-
ret;
143+
ret false;
136144
}
137145
// A program has a small number of libraries, so a vector is probably
138146
// a good data structure in here.
139147
for (str l in used_libraries) {
140148
if (l == lib) {
141-
ret;
149+
ret false;
142150
}
143151
}
144152
used_libraries += [lib];
153+
ret true;
145154
}
146155
fn get_used_libraries() -> vec[str] {
147156
ret used_libraries;

src/comp/lib/llvm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const uint LLVMRealULT = 12u;
125125
const uint LLVMRealULE = 13u;
126126
const uint LLVMRealUNE = 14u;
127127

128+
#[link_args = "-Lrustllvm"]
128129
native mod llvm = "rustllvm" {
129130

130131
type ModuleRef;

src/comp/metadata/creader.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,25 @@ fn visit_view_item(env e, &@ast::view_item i) {
170170
fn visit_item(env e, &@ast::item i) {
171171
alt (i.node) {
172172
case (ast::item_native_mod(?m)) {
173-
if (m.abi == ast::native_abi_rust ||
174-
m.abi == ast::native_abi_cdecl) {
175-
e.sess.add_used_library(m.native_name);
173+
if (m.abi != ast::native_abi_rust &&
174+
m.abi != ast::native_abi_cdecl) {
175+
ret;
176+
}
177+
if (!e.sess.add_used_library(m.native_name)) {
178+
ret;
179+
}
180+
for (ast::attribute a in i.attrs) {
181+
auto v = a.node.value.node;
182+
alt (v) {
183+
case (ast::meta_name_value(?i, ?s)) {
184+
if (i != "link_args") {
185+
cont;
186+
}
187+
e.sess.add_used_link_args(s);
188+
}
189+
case (_) {
190+
}
191+
}
176192
}
177193
}
178194
case (_) {

0 commit comments

Comments
 (0)