Skip to content

Commit 60a4f0d

Browse files
committed
---
yaml --- r: 12954 b: refs/heads/master c: 98b93b6 h: refs/heads/master v: v3
1 parent 5ac1699 commit 60a4f0d

File tree

7 files changed

+86
-57
lines changed

7 files changed

+86
-57
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c90a04701602353f410aad7073abffe758a01586
2+
refs/heads/master: 98b93b6c86d6dc3db7e057866bb8a29a38cc7a3a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/back/x86.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import driver::session;
2+
import session::sess_os_to_meta_os;
3+
import metadata::loader::meta_section_name;
24

35
fn get_target_strs(target_os: session::os) -> target_strs::t {
46
ret {
57
module_asm: "",
68

7-
meta_sect_name: alt target_os {
8-
session::os_macos { "__DATA,__note.rustc" }
9-
session::os_win32 { ".note.rustc" }
10-
session::os_linux { ".note.rustc" }
11-
session::os_freebsd { ".note.rustc" }
12-
},
9+
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
1310

1411
data_layout: alt target_os {
1512
session::os_macos {

trunk/src/rustc/back/x86_64.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import driver::session;
2+
import session::sess_os_to_meta_os;
3+
import metadata::loader::meta_section_name;
24

35
fn get_target_strs(target_os: session::os) -> target_strs::t {
46
ret {
57
module_asm: "",
68

7-
meta_sect_name: alt target_os {
8-
session::os_macos { "__DATA,__note.rustc" }
9-
session::os_win32 { ".note.rustc" }
10-
session::os_linux { ".note.rustc" }
11-
session::os_freebsd { ".note.rustc" }
12-
},
9+
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
1310

1411
data_layout: alt target_os {
1512
session::os_macos {

trunk/src/rustc/driver/driver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ fn early_error(emitter: diagnostic::emitter, msg: str) -> ! {
676676
}
677677

678678
fn list_metadata(sess: session, path: str, out: io::writer) {
679-
metadata::loader::list_file_metadata(sess, path, out);
679+
metadata::loader::list_file_metadata(
680+
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out);
680681
}
681682

682683
#[cfg(test)]

trunk/src/rustc/driver/session.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ fn building_library(req_crate_type: crate_type, crate: @ast::crate,
194194
}
195195
}
196196

197+
fn sess_os_to_meta_os(os: os) -> metadata::loader::os {
198+
import metadata::loader;
199+
200+
alt os {
201+
os_win32 { loader::os_win32 }
202+
os_linux { loader::os_linux }
203+
os_macos { loader::os_macos }
204+
os_freebsd { loader::os_freebsd }
205+
}
206+
}
207+
197208
#[cfg(test)]
198209
mod test {
199210
import syntax::ast_util;

trunk/src/rustc/metadata/creader.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,16 @@ fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
179179

180180
alt existing_match(e, metas, hash) {
181181
none {
182-
let cinfo =
183-
loader::load_library_crate(e.sess, ident, span, metas, hash);
182+
let load_ctxt: loader::ctxt = {
183+
sess: e.sess,
184+
span: span,
185+
ident: ident,
186+
metas: metas,
187+
hash: hash,
188+
os: session::sess_os_to_meta_os(e.sess.targ_cfg.os),
189+
static: e.sess.opts.static
190+
};
191+
let cinfo = loader::load_library_crate(load_ctxt);
184192

185193
let cfilename = cinfo.ident;
186194
let cdata = cinfo.data;

trunk/src/rustc/metadata/loader.rs

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,62 @@ import lib::llvm::{False, llvm, mk_object_file, mk_section_iter};
1313
import util::{filesearch};
1414
import io::writer_util;
1515

16+
export os;
17+
export ctxt;
1618
export load_library_crate;
1719
export list_file_metadata;
1820
export note_linkage_attrs;
1921
export crate_name_from_metas;
2022
export metadata_matches;
23+
export meta_section_name;
2124

22-
fn load_library_crate(sess: session::session, ident: ast::ident, span: span,
23-
metas: [@ast::meta_item], hash: str)
24-
-> {ident: str, data: @[u8]} {
25-
25+
enum os {
26+
os_macos,
27+
os_win32,
28+
os_linux,
29+
os_freebsd
30+
}
2631

27-
alt find_library_crate(sess, span, metas, hash) {
32+
type ctxt = {
33+
sess: session,
34+
span: span,
35+
ident: ast::ident,
36+
metas: [@ast::meta_item],
37+
hash: str,
38+
os: os,
39+
static: bool
40+
};
41+
42+
fn load_library_crate(cx: ctxt) -> {ident: str, data: @[u8]} {
43+
alt find_library_crate(cx) {
2844
some(t) { ret t; }
2945
none {
30-
sess.span_fatal(span, #fmt["can't find crate for '%s'", ident]);
46+
cx.sess.span_fatal(
47+
cx.span, #fmt["can't find crate for '%s'", cx.ident]);
3148
}
3249
}
3350
}
3451

35-
fn find_library_crate(sess: session::session, span: span,
36-
metas: [@ast::meta_item], hash: str)
37-
-> option<{ident: str, data: @[u8]}> {
38-
39-
attr::require_unique_names(sess.diagnostic(), metas);
40-
let metas = metas;
41-
42-
let nn = default_native_lib_naming(sess, sess.opts.static);
43-
find_library_crate_aux(sess, span, nn,
44-
metas, hash, sess.filesearch)
52+
fn find_library_crate(cx: ctxt) -> option<{ident: str, data: @[u8]}> {
53+
attr::require_unique_names(cx.sess.diagnostic(), cx.metas);
54+
find_library_crate_aux(cx, libname(cx), cx.sess.filesearch)
4555
}
4656

47-
fn default_native_lib_naming(sess: session::session, static: bool) ->
48-
{prefix: str, suffix: str} {
49-
if static { ret {prefix: "lib", suffix: ".rlib"}; }
50-
alt sess.targ_cfg.os {
51-
session::os_win32 { ret {prefix: "", suffix: ".dll"}; }
52-
session::os_macos { ret {prefix: "lib", suffix: ".dylib"}; }
53-
session::os_linux { ret {prefix: "lib", suffix: ".so"}; }
54-
session::os_freebsd { ret {prefix: "lib", suffix: ".so"}; }
57+
fn libname(cx: ctxt) -> {prefix: str, suffix: str} {
58+
if cx.static { ret {prefix: "lib", suffix: ".rlib"}; }
59+
alt cx.os {
60+
os_win32 { ret {prefix: "", suffix: ".dll"}; }
61+
os_macos { ret {prefix: "lib", suffix: ".dylib"}; }
62+
os_linux { ret {prefix: "lib", suffix: ".so"}; }
63+
os_freebsd { ret {prefix: "lib", suffix: ".so"}; }
5564
}
5665
}
5766

58-
fn find_library_crate_aux(sess: session::session,
59-
span: span,
67+
fn find_library_crate_aux(cx: ctxt,
6068
nn: {prefix: str, suffix: str},
61-
metas: [@ast::meta_item],
62-
hash: str,
6369
filesearch: filesearch::filesearch) ->
6470
option<{ident: str, data: @[u8]}> {
65-
let crate_name = crate_name_from_metas(metas);
71+
let crate_name = crate_name_from_metas(cx.metas);
6672
let prefix: str = nn.prefix + crate_name + "-";
6773
let suffix: str = nn.suffix;
6874

@@ -76,9 +82,9 @@ fn find_library_crate_aux(sess: session::session,
7682
option::none::<()>
7783
} else {
7884
#debug("%s is a candidate", path);
79-
alt get_metadata_section(sess, path) {
85+
alt get_metadata_section(cx.os, path) {
8086
option::some(cvec) {
81-
if !crate_matches(cvec, metas, hash) {
87+
if !crate_matches(cvec, cx.metas, cx.hash) {
8288
#debug("skipping %s, metadata doesn't match", path);
8389
option::none::<()>
8490
} else {
@@ -100,15 +106,15 @@ fn find_library_crate_aux(sess: session::session,
100106
} else if matches.len() == 1u {
101107
some(matches[0])
102108
} else {
103-
sess.span_err(
104-
span, #fmt("multiple matching crates for `%s`", crate_name));
105-
sess.note("candidates:");
109+
cx.sess.span_err(
110+
cx.span, #fmt("multiple matching crates for `%s`", crate_name));
111+
cx.sess.note("candidates:");
106112
for matches.each {|match|
107-
sess.note(#fmt("path: %s", match.ident));
113+
cx.sess.note(#fmt("path: %s", match.ident));
108114
let attrs = decoder::get_crate_attributes(match.data);
109-
note_linkage_attrs(sess, attrs);
115+
note_linkage_attrs(cx.sess, attrs);
110116
}
111-
sess.abort_if_errors();
117+
cx.sess.abort_if_errors();
112118
none
113119
}
114120
}
@@ -166,7 +172,7 @@ fn metadata_matches(extern_metas: [@ast::meta_item],
166172
ret true;
167173
}
168174

169-
fn get_metadata_section(sess: session::session,
175+
fn get_metadata_section(os: os,
170176
filename: str) -> option<@[u8]> unsafe {
171177
let mb = str::as_c_str(filename, {|buf|
172178
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
@@ -180,7 +186,7 @@ fn get_metadata_section(sess: session::session,
180186
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
181187
let name_buf = llvm::LLVMGetSectionName(si.llsi);
182188
let name = unsafe { str::unsafe::from_c_str(name_buf) };
183-
if str::eq(name, sess.targ_cfg.target_strs.meta_sect_name) {
189+
if str::eq(name, meta_section_name(os)) {
184190
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
185191
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
186192
unsafe {
@@ -193,9 +199,18 @@ fn get_metadata_section(sess: session::session,
193199
ret option::none::<@[u8]>;
194200
}
195201

202+
fn meta_section_name(os: os) -> str {
203+
alt os {
204+
os_macos { "__DATA,__note.rustc" }
205+
os_win32 { ".note.rustc" }
206+
os_linux { ".note.rustc" }
207+
os_freebsd { ".note.rustc" }
208+
}
209+
}
210+
196211
// A diagnostic function for dumping crate metadata to an output stream
197-
fn list_file_metadata(sess: session::session, path: str, out: io::writer) {
198-
alt get_metadata_section(sess, path) {
212+
fn list_file_metadata(os: os, path: str, out: io::writer) {
213+
alt get_metadata_section(os, path) {
199214
option::some(bytes) { decoder::list_crate_metadata(bytes, out); }
200215
option::none {
201216
out.write_str("could not find metadata in " + path + ".\n");

0 commit comments

Comments
 (0)