Skip to content

Commit fa880ae

Browse files
committed
---
yaml --- r: 104540 b: refs/heads/try c: fc1c06d h: refs/heads/master v: v3
1 parent 69e8018 commit fa880ae

File tree

6 files changed

+102
-9
lines changed

6 files changed

+102
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
5-
refs/heads/try: 9cc26cfdf43adffe51acdc5ef9886cb5e1844d46
5+
refs/heads/try: fc1c06d7b1202a0cc7c09bcfeca88ada3fbfb091
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/doc/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ li {list-style-type: none; }
4343
* [The `sync` library for concurrency-enabled mechanisms and primitives](sync/index.html)
4444
* [The `syntax` library, the Rust parser](syntax/index.html)
4545
* [The `term` terminal-handling library](term/index.html)
46+
* [The `test` library](test/index.html)
4647
* [The `uuid` 128-bit universally unique identifier library](uuid/index.html)
4748

4849
# Tooling

branches/try/src/libstd/rt/crate_map.rs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use cast;
1112
use cmp::TotalOrd;
1213
use container::MutableSet;
1314
use iter::Iterator;
@@ -35,27 +36,61 @@ pub struct CrateMap<'a> {
3536
event_loop_factory: Option<fn() -> ~EventLoop>,
3637
}
3738

39+
// When working on android, apparently weak symbols don't work so well for
40+
// finding the crate map, and neither does dlopen + dlsym. This is mainly a
41+
// problem when integrating a shared library with an existing application.
42+
// Standalone binaries do not appear to have this problem. The reasons are a
43+
// little mysterious, and more information can be found in #11731.
44+
//
45+
// For now we provide a way to tell libstd about the crate map manually that's
46+
// checked before the normal weak symbol/dlopen paths. In theory this is useful
47+
// on other platforms where our dlopen/weak linkage strategy mysteriously fails
48+
// but the crate map can be specified manually.
49+
static mut MANUALLY_PROVIDED_CRATE_MAP: *CrateMap<'static> =
50+
0 as *CrateMap<'static>;
51+
#[no_mangle]
52+
#[cfg(not(test))]
53+
pub extern fn rust_set_crate_map(map: *CrateMap<'static>) {
54+
unsafe { MANUALLY_PROVIDED_CRATE_MAP = map; }
55+
}
56+
57+
fn manual_crate_map() -> Option<&'static CrateMap<'static>> {
58+
unsafe {
59+
if MANUALLY_PROVIDED_CRATE_MAP.is_null() {
60+
None
61+
} else {
62+
Some(cast::transmute(MANUALLY_PROVIDED_CRATE_MAP))
63+
}
64+
}
65+
}
66+
3867
#[cfg(not(windows))]
3968
pub fn get_crate_map() -> Option<&'static CrateMap<'static>> {
4069
extern {
4170
#[crate_map]
4271
static CRATE_MAP: CrateMap<'static>;
4372
}
4473

45-
let ptr: (*CrateMap) = &'static CRATE_MAP;
46-
if ptr.is_null() {
47-
return None;
48-
} else {
49-
return Some(&'static CRATE_MAP);
50-
}
74+
manual_crate_map().or_else(|| {
75+
let ptr: (*CrateMap) = &'static CRATE_MAP;
76+
if ptr.is_null() {
77+
None
78+
} else {
79+
Some(&'static CRATE_MAP)
80+
}
81+
})
5182
}
5283

5384
#[cfg(windows)]
5485
pub fn get_crate_map() -> Option<&'static CrateMap<'static>> {
55-
use cast::transmute;
5686
use c_str::ToCStr;
5787
use unstable::dynamic_lib::dl;
5888

89+
match manual_crate_map() {
90+
Some(cm) => return Some(cm),
91+
None => {}
92+
}
93+
5994
let sym = unsafe {
6095
let module = dl::open_internal();
6196
let rust_crate_map_toplevel = if cfg!(target_arch = "x86") {
@@ -74,7 +109,7 @@ pub fn get_crate_map() -> Option<&'static CrateMap<'static>> {
74109
return None;
75110
} else {
76111
unsafe {
77-
return Some(transmute(sym));
112+
return Some(cast::transmute(sym));
78113
}
79114
}
80115
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) lib.rs -C gen-crate-map
5+
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
6+
$(CC) main.c -o $(call RUN,main) -lboot -Wl,-rpath,$(TMPDIR)
7+
RUST_LOG=boot $(call RUN,main)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[crate_id="boot#0.1"];
12+
#[crate_type="dylib"];
13+
#[no_uv];
14+
15+
extern crate rustuv;
16+
extern crate green;
17+
18+
use std::rt::crate_map::{CrateMap, rust_set_crate_map};
19+
20+
// pull in this symbol from libstd into this crate (for convenience)
21+
#[no_mangle]
22+
pub static set_crate_map: extern "C" fn(*CrateMap<'static>) = rust_set_crate_map;
23+
24+
#[no_mangle] // this needs to get called from C
25+
pub extern "C" fn foo(argc: int, argv: **u8) -> int {
26+
green::start(argc, argv, proc() {
27+
if log_enabled!(std::logging::DEBUG) { return }
28+
fail!()
29+
})
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// this is the rust entry point that we're going to call.
12+
int foo(int argc, char *argv[]);
13+
14+
extern void (*set_crate_map)(void *map);
15+
extern int _rust_crate_map_toplevel;
16+
17+
int main(int argc, char *argv[]) {
18+
set_crate_map(&_rust_crate_map_toplevel);
19+
return foo(argc, argv);
20+
}

0 commit comments

Comments
 (0)