allow #[link_args] with #[nolink]. For now, fail if two modules link same lib, and second has link_args.

I think it should undefined to have multiple modules that link in the same
library, but provide different link arguments. Unfortunately we don't track
link_args by module -- they are just appended as discovered into the crate
store -- but for now, it should be an error to provide link_args on a module
that's already been included (with or without link_args).
This commit is contained in:
Graham Fawcett 2011-12-16 11:04:11 -05:00 committed by Brian Anderson
parent 7ddd353ef6
commit f14bc54b06
4 changed files with 48 additions and 15 deletions

View File

@ -60,23 +60,28 @@ fn visit_item(e: env, i: @ast::item) {
let cstore = e.sess.get_cstore();
let native_name = i.ident;
if vec::len(attr::find_attrs_by_name(i.attrs, "nolink")) > 0u {
ret;
let already_added = false;
if vec::len(attr::find_attrs_by_name(i.attrs, "nolink")) == 0u {
alt attr::get_meta_item_value_str_by_name(i.attrs, "link_name") {
some(nn) { native_name = nn; }
none. { }
}
if native_name == "" {
e.sess.span_fatal(i.span,
"empty #[link_name] not allowed; use #[nolink].");
}
already_added = !cstore::add_used_library(cstore, native_name);
}
alt attr::get_meta_item_value_str_by_name(i.attrs, "link_name") {
some(nn) { native_name = nn; }
none. { }
let link_args = attr::find_attrs_by_name(i.attrs, "link_args");
if vec::len(link_args) > 0u && already_added {
e.sess.span_fatal(i.span, "library '" + native_name +
"' already added: can't specify link_args.");
}
if native_name == "" {
e.sess.span_fatal(i.span,
"empty #[link_name] not allowed; use #[nolink].");
}
if !cstore::add_used_library(cstore, native_name) { ret; }
for a: ast::attribute in
attr::find_attrs_by_name(i.attrs, "link_args") {
for a: ast::attribute in link_args {
alt attr::get_meta_item_value_str(attr::attr_meta(a)) {
some(linkarg) { cstore::add_used_link_args(cstore, linkarg); }
some(linkarg) {
cstore::add_used_link_args(cstore, linkarg);
}
none. {/* fallthrough */ }
}
}

View File

@ -90,7 +90,7 @@ fn get_used_crate_files(cstore: cstore) -> [str] {
}
fn add_used_library(cstore: cstore, lib: str) -> bool {
if lib == "" { ret false; }
assert lib != "";
if vec::member(lib, p(cstore).used_libraries) { ret false; }
p(cstore).used_libraries += [lib];

View File

@ -0,0 +1,11 @@
// error-pattern:aFdEfSeVEE
/* We're testing that link_args are indeed passed when nolink is specified.
So we try to compile with junk link_args and make sure they are visible in
the compiler output. */
#[link_args = "aFdEfSeVEEE"]
#[nolink]
native mod m1 { }
fn main() { }

View File

@ -0,0 +1,17 @@
// error-pattern:library 'm' already added: can't specify link_args.
/* I think it should undefined to have multiple modules that link in the same
library, but provide different link arguments. Unfortunately we don't track
link_args by module -- they are just appended as discovered into the crate
store -- but for now, it should be an error to provide link_args on a module
that's already been included (with or without link_args). */
#[link_name= "m"]
#[link_args="-foo"] // this could have been elided.
native mod m1 {
}
#[link_name= "m"]
#[link_args="-bar"] // this is the actual error trigger.
native mod m2 {
}