Skip to content

Commit 4353860

Browse files
committed
---
yaml --- r: 277852 b: refs/heads/auto c: 8da2bca h: refs/heads/master
1 parent c43a52c commit 4353860

File tree

8 files changed

+173
-47
lines changed

8 files changed

+173
-47
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 0fc9f9a20080753426772eac77d4d135ccd01ab7
11+
refs/heads/auto: 8da2bcac5db1e091b90cceb19d0496f0f7501c88
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc/session/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ pub fn build_session(sopts: config::Options,
408408
registry: diagnostics::registry::Registry,
409409
cstore: Rc<for<'a> CrateStore<'a>>)
410410
-> Session {
411+
build_session_with_codemap(sopts,
412+
local_crate_source_file,
413+
registry,
414+
cstore,
415+
Rc::new(codemap::CodeMap::new()))
416+
}
417+
418+
pub fn build_session_with_codemap(sopts: config::Options,
419+
local_crate_source_file: Option<PathBuf>,
420+
registry: diagnostics::registry::Registry,
421+
cstore: Rc<for<'a> CrateStore<'a>>,
422+
codemap: Rc<codemap::CodeMap>)
423+
-> Session {
411424
// FIXME: This is not general enough to make the warning lint completely override
412425
// normal diagnostic warnings, since the warning lint can also be denied and changed
413426
// later via the source code.
@@ -419,7 +432,6 @@ pub fn build_session(sopts: config::Options,
419432
.unwrap_or(true);
420433
let treat_err_as_bug = sopts.treat_err_as_bug;
421434

422-
let codemap = Rc::new(codemap::CodeMap::new());
423435
let emitter: Box<Emitter> = match sopts.error_format {
424436
config::ErrorOutputType::HumanReadable(color_config) => {
425437
Box::new(EmitterWriter::stderr(color_config, Some(registry), codemap.clone()))

branches/auto/src/librustc_driver/lib.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use pretty::{PpMode, UserIdentifiedItem};
6666
use rustc_resolve as resolve;
6767
use rustc_save_analysis as save;
6868
use rustc_trans::back::link;
69-
use rustc::session::{config, Session, build_session, CompileResult};
69+
use rustc::session::{self, config, Session, build_session, CompileResult};
7070
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
7171
use rustc::session::config::{get_unstable_features_setting, nightly_options};
7272
use rustc::middle::cstore::CrateStore;
@@ -91,13 +91,11 @@ use std::thread;
9191

9292
use rustc::session::early_error;
9393

94-
use syntax::ast;
95-
use syntax::parse::{self, PResult};
96-
use syntax::errors;
94+
use syntax::{ast, errors, diagnostics};
95+
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
9796
use syntax::errors::emitter::Emitter;
98-
use syntax::diagnostics;
99-
use syntax::parse::token;
10097
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
98+
use syntax::parse::{self, PResult, token};
10199

102100
#[cfg(test)]
103101
pub mod test;
@@ -148,11 +146,20 @@ pub fn run(args: Vec<String>) -> isize {
148146
0
149147
}
150148

151-
// Parse args and run the compiler. This is the primary entry point for rustc.
152-
// See comments on CompilerCalls below for details about the callbacks argument.
153149
pub fn run_compiler<'a>(args: &[String],
154150
callbacks: &mut CompilerCalls<'a>)
155151
-> (CompileResult, Option<Session>) {
152+
run_compiler_with_file_loader(args, callbacks, box RealFileLoader)
153+
}
154+
155+
// Parse args and run the compiler. This is the primary entry point for rustc.
156+
// See comments on CompilerCalls below for details about the callbacks argument.
157+
// The FileLoader provides a way to load files from sources other than the file system.
158+
pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
159+
callbacks: &mut CompilerCalls<'a>,
160+
loader: Box<L>)
161+
-> (CompileResult, Option<Session>)
162+
where L: FileLoader + 'static {
156163
macro_rules! do_or_return {($expr: expr, $sess: expr) => {
157164
match $expr {
158165
Compilation::Stop => return (Ok(()), $sess),
@@ -189,7 +196,12 @@ pub fn run_compiler<'a>(args: &[String],
189196
};
190197

191198
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
192-
let sess = build_session(sopts, input_file_path, descriptions, cstore.clone());
199+
let codemap = Rc::new(CodeMap::with_file_loader(loader));
200+
let sess = session::build_session_with_codemap(sopts,
201+
input_file_path,
202+
descriptions,
203+
cstore.clone(),
204+
codemap);
193205
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
194206
let mut cfg = config::build_configuration(&sess);
195207
target_features::add_configuration(&mut cfg, &sess);

branches/auto/src/libstd/num/f32.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,10 @@ impl f32 {
646646
#[stable(feature = "rust1", since = "1.0.0")]
647647
#[inline]
648648
pub fn log2(self) -> f32 {
649-
unsafe { intrinsics::log2f32(self) }
649+
#[cfg(target_os = "android")]
650+
return ::sys::android::log2f32(self);
651+
#[cfg(not(target_os = "android"))]
652+
return unsafe { intrinsics::log2f32(self) };
650653
}
651654

652655
/// Returns the base 10 logarithm of the number.

branches/auto/src/libstd/num/f64.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,12 @@ impl f64 {
546546
#[stable(feature = "rust1", since = "1.0.0")]
547547
#[inline]
548548
pub fn log2(self) -> f64 {
549-
self.log_wrapper(|n| { unsafe { intrinsics::log2f64(n) } })
549+
self.log_wrapper(|n| {
550+
#[cfg(target_os = "android")]
551+
return ::sys::android::log2f64(n);
552+
#[cfg(not(target_os = "android"))]
553+
return unsafe { intrinsics::log2f64(n) };
554+
})
550555
}
551556

552557
/// Returns the base 10 logarithm of the number.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2016 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+
//! Android ABI-compatibility module
12+
//!
13+
//! The ABI of Android has changed quite a bit over time, and libstd attempts to
14+
//! be both forwards and backwards compatible as much as possible. We want to
15+
//! always work with the most recent version of Android, but we also want to
16+
//! work with older versions of Android for whenever projects need to.
17+
//!
18+
//! Our current minimum supported Android version is `android-9`, e.g. Android
19+
//! with API level 9. We then in theory want to work on that and all future
20+
//! versions of Android!
21+
//!
22+
//! Some of the detection here is done at runtime via `dlopen` and
23+
//! introspection. Other times no detection is performed at all and we just
24+
//! provide a fallback implementation as some versions of Android we support
25+
//! don't have the function.
26+
//!
27+
//! You'll find more details below about why each compatibility shim is needed.
28+
29+
#![cfg(target_os = "android")]
30+
31+
use libc::{c_int, sighandler_t};
32+
33+
use io;
34+
use sys::cvt_r;
35+
36+
// The `log2` and `log2f` functions apparently appeared in android-18, or at
37+
// least you can see they're not present in the android-17 header [1] and they
38+
// are present in android-18 [2].
39+
//
40+
// [1]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms
41+
// /android-17/arch-arm/usr/include/math.h
42+
// [2]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms
43+
// /android-18/arch-arm/usr/include/math.h
44+
//
45+
// Note that these shims are likely less precise than directly calling `log2`,
46+
// but hopefully that should be enough for now...
47+
//
48+
// Note that mathematically, for any arbitrary `y`:
49+
//
50+
// log_2(x) = log_y(x) / log_y(2)
51+
// = log_y(x) / (1 / log_2(y))
52+
// = log_y(x) * log_2(y)
53+
//
54+
// Hence because `ln` (log_e) is available on all Android we just choose `y = e`
55+
// and get:
56+
//
57+
// log_2(x) = ln(x) * log_2(e)
58+
59+
#[cfg(not(test))]
60+
pub fn log2f32(f: f32) -> f32 {
61+
f.ln() * ::f32::consts::LOG2_E
62+
}
63+
64+
#[cfg(not(test))]
65+
pub fn log2f64(f: f64) -> f64 {
66+
f.ln() * ::f64::consts::LOG2_E
67+
}
68+
69+
// Back in the day [1] the `signal` function was just an inline wrapper
70+
// around `bsd_signal`, but starting in API level android-20 the `signal`
71+
// symbols was introduced [2]. Finally, in android-21 the API `bsd_signal` was
72+
// removed [3].
73+
//
74+
// Basically this means that if we want to be binary compatible with multiple
75+
// Android releases (oldest being 9 and newest being 21) then we need to check
76+
// for both symbols and not actually link against either.
77+
//
78+
// [1]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms
79+
// /android-18/arch-arm/usr/include/signal.h
80+
// [2]: https://chromium.googlesource.com/android_tools/+/fbd420/ndk_experimental
81+
// /platforms/android-20/arch-arm
82+
// /usr/include/signal.h
83+
// [3]: https://chromium.googlesource.com/android_tools/+/20ee6d/ndk/platforms
84+
// /android-21/arch-arm/usr/include/signal.h
85+
pub unsafe fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t {
86+
weak!(fn signal(c_int, sighandler_t) -> sighandler_t);
87+
weak!(fn bsd_signal(c_int, sighandler_t) -> sighandler_t);
88+
89+
let f = signal.get().or_else(|| bsd_signal.get());
90+
let f = f.expect("neither `signal` nor `bsd_signal` symbols found");
91+
f(signum, handler)
92+
}
93+
94+
// The `ftruncate64` symbol apparently appeared in android-12, so we do some
95+
// dynamic detection to see if we can figure out whether `ftruncate64` exists.
96+
//
97+
// If it doesn't we just fall back to `ftruncate`, generating an error for
98+
// too-large values.
99+
pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
100+
weak!(fn ftruncate64(c_int, i64) -> c_int);
101+
102+
extern {
103+
fn ftruncate(fd: c_int, off: i32) -> c_int;
104+
}
105+
106+
unsafe {
107+
match ftruncate64.get() {
108+
Some(f) => cvt_r(|| f(fd, size as i64)).map(|_| ()),
109+
None => {
110+
if size > i32::max_value() as u64 {
111+
Err(io::Error::new(io::ErrorKind::InvalidInput,
112+
"cannot truncate >2GB"))
113+
} else {
114+
cvt_r(|| ftruncate(fd, size as i32)).map(|_| ())
115+
}
116+
}
117+
}
118+
}
119+
}

branches/auto/src/libstd/sys/unix/fs.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use sys_common::{AsInner, FromInner};
2727
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
2828
use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64};
2929
#[cfg(target_os = "android")]
30-
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off64_t, ftruncate64, lseek64,
30+
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off64_t, lseek64,
3131
dirent as dirent64, open as open64};
3232
#[cfg(not(any(target_os = "linux",
3333
target_os = "emscripten",
@@ -475,10 +475,13 @@ impl File {
475475
}
476476

477477
pub fn truncate(&self, size: u64) -> io::Result<()> {
478-
cvt_r(|| unsafe {
478+
#[cfg(target_os = "android")]
479+
return ::sys::android::ftruncate64(self.0.raw(), size);
480+
481+
#[cfg(not(target_os = "android"))]
482+
return cvt_r(|| unsafe {
479483
ftruncate64(self.0.raw(), size as off64_t)
480-
})?;
481-
Ok(())
484+
}).map(|_| ());
482485
}
483486

484487
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {

branches/auto/src/libstd/sys/unix/mod.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use ops::Neg;
3131
#[macro_use]
3232
pub mod weak;
3333

34+
pub mod android;
3435
pub mod backtrace;
3536
pub mod condvar;
3637
pub mod ext;
@@ -91,37 +92,8 @@ pub fn init() {
9192
unsafe fn reset_sigpipe() {}
9293
}
9394

94-
// Currently the minimum supported Android version of the standard library is
95-
// API level 18 (android-18). Back in those days [1] the `signal` function was
96-
// just an inline wrapper around `bsd_signal`, but starting in API level
97-
// android-20 the `signal` symbols was introduced [2]. Finally, in android-21
98-
// the API `bsd_signal` was removed [3].
99-
//
100-
// Basically this means that if we want to be binary compatible with multiple
101-
// Android releases (oldest being 18 and newest being 21) then we need to check
102-
// for both symbols and not actually link against either.
103-
//
104-
// Note that if we're not on android we just link against the `android` symbol
105-
// itself.
106-
//
107-
// [1]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms
108-
// /android-18/arch-arm/usr/include/signal.h
109-
// [2]: https://chromium.googlesource.com/android_tools/+/fbd420/ndk_experimental
110-
// /platforms/android-20/arch-arm
111-
// /usr/include/signal.h
112-
// [3]: https://chromium.googlesource.com/android_tools/+/20ee6d/ndk/platforms
113-
// /android-21/arch-arm/usr/include/signal.h
11495
#[cfg(target_os = "android")]
115-
unsafe fn signal(signum: libc::c_int,
116-
handler: libc::sighandler_t) -> libc::sighandler_t {
117-
weak!(fn signal(libc::c_int, libc::sighandler_t) -> libc::sighandler_t);
118-
weak!(fn bsd_signal(libc::c_int, libc::sighandler_t) -> libc::sighandler_t);
119-
120-
let f = signal.get().or_else(|| bsd_signal.get());
121-
let f = f.expect("neither `signal` nor `bsd_signal` symbols found");
122-
f(signum, handler)
123-
}
124-
96+
pub use sys::android::signal;
12597
#[cfg(not(target_os = "android"))]
12698
pub use libc::signal;
12799

0 commit comments

Comments
 (0)