Skip to content

Commit fd2f8a4

Browse files
committed
Auto merge of #39677 - frewsxcv:rollup, r=frewsxcv
Rollup of 9 pull requests - Successful merges: #37928, #38699, #39589, #39598, #39599, #39641, #39649, #39653, #39671 - Failed merges:
2 parents 29dece1 + 1e3e904 commit fd2f8a4

File tree

60 files changed

+928
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+928
-46
lines changed

configure

+1
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ opt codegen-tests 1 "run the src/test/codegen tests"
649649
opt option-checking 1 "complain about unrecognized options in this configure script"
650650
opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
651651
opt vendor 0 "enable usage of vendored Rust crates"
652+
opt sanitizers 0 "build the sanitizer runtimes (asan, lsan, msan, tsan)"
652653

653654
# Optimization and debugging options. These may be overridden by the release channel, etc.
654655
opt_nosave optimize 1 "build optimized rust code"

mk/cfg/aarch64-unknown-freebsd.mk

-1
This file was deleted.

mk/cfg/i686-unknown-netbsd.mk

-1
This file was deleted.

src/Cargo.lock

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/check.rs

+4
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ pub fn compiletest(build: &Build,
242242
cmd.env("RUSTC_BOOTSTRAP", "1");
243243
build.add_rust_test_threads(&mut cmd);
244244

245+
if build.config.sanitizers {
246+
cmd.env("SANITIZER_SUPPORT", "1");
247+
}
248+
245249
cmd.arg("--adb-path").arg("adb");
246250
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
247251
if target.contains("android") {

src/bootstrap/compile.rs

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ pub fn std(build: &Build, target: &str, compiler: &Compiler) {
5151
if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc {
5252
features.push_str(" force_alloc_system");
5353
}
54+
55+
if compiler.stage != 0 && build.config.sanitizers {
56+
// This variable is used by the sanitizer runtime crates, e.g.
57+
// rustc_lsan, to build the sanitizer runtime from C code
58+
// When this variable is missing, those crates won't compile the C code,
59+
// so we don't set this variable during stage0 where llvm-config is
60+
// missing
61+
// We also only build the runtimes when --enable-sanitizers (or its
62+
// config.toml equivalent) is used
63+
cargo.env("LLVM_CONFIG", build.llvm_config(target));
64+
}
5465
cargo.arg("--features").arg(features)
5566
.arg("--manifest-path")
5667
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"));

src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct Config {
4848
pub target_config: HashMap<String, Target>,
4949
pub full_bootstrap: bool,
5050
pub extended: bool,
51+
pub sanitizers: bool,
5152

5253
// llvm codegen options
5354
pub llvm_assertions: bool,
@@ -149,6 +150,7 @@ struct Build {
149150
python: Option<String>,
150151
full_bootstrap: Option<bool>,
151152
extended: Option<bool>,
153+
sanitizers: Option<bool>,
152154
}
153155

154156
/// TOML representation of various global install decisions.
@@ -294,6 +296,7 @@ impl Config {
294296
set(&mut config.vendor, build.vendor);
295297
set(&mut config.full_bootstrap, build.full_bootstrap);
296298
set(&mut config.extended, build.extended);
299+
set(&mut config.sanitizers, build.sanitizers);
297300

298301
if let Some(ref install) = toml.install {
299302
config.prefix = install.prefix.clone().map(PathBuf::from);
@@ -438,6 +441,7 @@ impl Config {
438441
("VENDOR", self.vendor),
439442
("FULL_BOOTSTRAP", self.full_bootstrap),
440443
("EXTENDED", self.extended),
444+
("SANITIZERS", self.sanitizers),
441445
}
442446

443447
match key {

src/bootstrap/config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
# disabled by default.
125125
#extended = false
126126

127+
# Build the sanitizer runtimes
128+
#sanitizers = false
129+
127130
# =============================================================================
128131
# General install configuration options
129132
# =============================================================================

src/bootstrap/dist.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,7 @@ pub fn cargo(build: &Build, stage: u32, target: &str) {
515515

516516
let branch = match &build.config.channel[..] {
517517
"stable" |
518-
"beta" => {
519-
build.release.split(".").take(2).collect::<Vec<_>>().join(".")
520-
}
518+
"beta" => format!("rust-{}", build.release_num),
521519
_ => "master".to_string(),
522520
};
523521

src/bootstrap/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ impl Build {
599599
/// Get the space-separated set of activated features for the standard
600600
/// library.
601601
fn std_features(&self) -> String {
602-
let mut features = "panic-unwind".to_string();
602+
let mut features = "panic-unwind asan lsan msan tsan".to_string();
603+
603604
if self.config.debug_jemalloc {
604605
features.push_str(" debug-jemalloc");
605606
}

src/ci/docker/dist-x86-linux/Dockerfile

+16-11
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,7 @@ RUN yum upgrade -y && yum install -y \
2121
ENV PATH=/rustroot/bin:$PATH
2222
ENV LD_LIBRARY_PATH=/rustroot/lib64:/rustroot/lib
2323
WORKDIR /tmp
24-
25-
# binutils < 2.22 has a bug where the 32-bit executables it generates
26-
# immediately segfault in Rust, so we need to install our own binutils.
27-
#
28-
# See https://github.com/rust-lang/rust/issues/20440 for more info
2924
COPY shared.sh build-binutils.sh /tmp/
30-
RUN ./build-binutils.sh
31-
32-
# Need a newer version of gcc than centos has to compile LLVM nowadays
33-
COPY build-gcc.sh /tmp/
34-
RUN ./build-gcc.sh
3525

3626
# We need a build of openssl which supports SNI to download artifacts from
3727
# static.rust-lang.org. This'll be used to link into libcurl below (and used
@@ -49,6 +39,16 @@ RUN ./build-openssl.sh
4939
COPY build-curl.sh /tmp/
5040
RUN ./build-curl.sh
5141

42+
# binutils < 2.22 has a bug where the 32-bit executables it generates
43+
# immediately segfault in Rust, so we need to install our own binutils.
44+
#
45+
# See https://github.com/rust-lang/rust/issues/20440 for more info
46+
RUN ./build-binutils.sh
47+
48+
# Need a newer version of gcc than centos has to compile LLVM nowadays
49+
COPY build-gcc.sh /tmp/
50+
RUN ./build-gcc.sh
51+
5252
# CentOS 5.5 has Python 2.4 by default, but LLVM needs 2.7+
5353
COPY build-python.sh /tmp/
5454
RUN ./build-python.sh
@@ -63,6 +63,11 @@ RUN ./build-git.sh
6363
COPY build-cmake.sh /tmp/
6464
RUN ./build-cmake.sh
6565

66+
# for sanitizers, we need kernel headers files newer than the ones CentOS ships
67+
# with so we install newer ones here
68+
COPY build-headers.sh /tmp/
69+
RUN ./build-headers.sh
70+
6671
RUN curl -Lo /rustroot/dumb-init \
6772
https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 && \
6873
chmod +x /rustroot/dumb-init
@@ -76,5 +81,5 @@ RUN curl -L https://api.pub.build.mozilla.org/tooltool/sha512/$SCCACHE_DIGEST |
7681
ENV HOSTS=i686-unknown-linux-gnu
7782
ENV HOSTS=$HOSTS,x86_64-unknown-linux-gnu
7883

79-
ENV RUST_CONFIGURE_ARGS --host=$HOSTS --enable-extended
84+
ENV RUST_CONFIGURE_ARGS --host=$HOSTS --enable-extended --enable-sanitizers
8085
ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
3+
# file at the top-level directory of this distribution and at
4+
# http://rust-lang.org/COPYRIGHT.
5+
#
6+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9+
# option. This file may not be copied, modified, or distributed
10+
# except according to those terms.
11+
12+
set -ex
13+
source shared.sh
14+
15+
curl https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.2.84.tar.xz | unxz | tar x
16+
17+
cd linux-3.2.84
18+
hide_output make mrproper
19+
hide_output make INSTALL_HDR_PATH=dest headers_install
20+
21+
find dest/include \( -name .install -o -name ..install.cmd \) -delete
22+
yes | cp -fr dest/include/* /usr/include
23+
24+
cd ..
25+
rm -rf linux-3.2.84

src/ci/docker/x86_64-gnu/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-ini
2222
rm dumb-init_*.deb
2323
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
2424

25-
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu
25+
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --enable-sanitizers
2626
ENV SCRIPT python2.7 ../x.py test && python2.7 ../x.py dist

src/doc/reference.md

+60-9
Original file line numberDiff line numberDiff line change
@@ -1291,15 +1291,18 @@ guaranteed to refer to the same memory address.
12911291

12921292
Constant values must not have destructors, and otherwise permit most forms of
12931293
data. Constants may refer to the address of other constants, in which case the
1294-
address will have the `static` lifetime. The compiler is, however, still at
1295-
liberty to translate the constant many times, so the address referred to may not
1296-
be stable.
1294+
address will have elided lifetimes where applicable, otherwise – in most cases –
1295+
defaulting to the `static` lifetime. (See below on [static lifetime elision].)
1296+
The compiler is, however, still at liberty to translate the constant many times,
1297+
so the address referred to may not be stable.
1298+
1299+
[static lifetime elision]: #static-lifetime-elision
12971300

12981301
Constants must be explicitly typed. The type may be `bool`, `char`, a number, or
12991302
a type derived from those primitive types. The derived types are references with
13001303
the `static` lifetime, fixed-size arrays, tuples, enum variants, and structs.
13011304

1302-
```
1305+
```rust
13031306
const BIT1: u32 = 1 << 0;
13041307
const BIT2: u32 = 1 << 1;
13051308

@@ -1317,6 +1320,8 @@ const BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings {
13171320
};
13181321
```
13191322

1323+
1324+
13201325
### Static items
13211326

13221327
A *static item* is similar to a *constant*, except that it represents a precise
@@ -1351,7 +1356,7 @@ running in the same process.
13511356
Mutable statics are still very useful, however. They can be used with C
13521357
libraries and can also be bound from C libraries (in an `extern` block).
13531358

1354-
```
1359+
```rust
13551360
# fn atomic_add(_: &mut u32, _: u32) -> u32 { 2 }
13561361

13571362
static mut LEVELS: u32 = 0;
@@ -1375,6 +1380,53 @@ unsafe fn bump_levels_unsafe2() -> u32 {
13751380
Mutable statics have the same restrictions as normal statics, except that the
13761381
type of the value is not required to ascribe to `Sync`.
13771382

1383+
#### `'static` lifetime elision
1384+
1385+
[Unstable] Both constant and static declarations of reference types have
1386+
*implicit* `'static` lifetimes unless an explicit lifetime is specified. As
1387+
such, the constant declarations involving `'static` above may be written
1388+
without the lifetimes. Returning to our previous example:
1389+
1390+
```rust
1391+
# #![feature(static_in_const)]
1392+
const BIT1: u32 = 1 << 0;
1393+
const BIT2: u32 = 1 << 1;
1394+
1395+
const BITS: [u32; 2] = [BIT1, BIT2];
1396+
const STRING: &str = "bitstring";
1397+
1398+
struct BitsNStrings<'a> {
1399+
mybits: [u32; 2],
1400+
mystring: &'a str,
1401+
}
1402+
1403+
const BITS_N_STRINGS: BitsNStrings = BitsNStrings {
1404+
mybits: BITS,
1405+
mystring: STRING,
1406+
};
1407+
```
1408+
1409+
Note that if the `static` or `const` items include function or closure
1410+
references, which themselves include references, the compiler will first try the
1411+
standard elision rules ([see discussion in the nomicon][elision-nomicon]). If it
1412+
is unable to resolve the lifetimes by its usual rules, it will default to using
1413+
the `'static` lifetime. By way of example:
1414+
1415+
[elision-nomicon]: https://doc.rust-lang.org/nomicon/lifetime-elision.html
1416+
1417+
```rust,ignore
1418+
// Resolved as `fn<'a>(&'a str) -> &'a str`.
1419+
const RESOLVED_SINGLE: fn(&str) -> &str = ..
1420+
1421+
// Resolved as `Fn<'a, 'b, 'c>(&'a Foo, &'b Bar, &'c Baz) -> usize`.
1422+
const RESOLVED_MULTIPLE: Fn(&Foo, &Bar, &Baz) -> usize = ..
1423+
1424+
// There is insufficient information to bound the return reference lifetime
1425+
// relative to the argument lifetimes, so the signature is resolved as
1426+
// `Fn(&'static Foo, &'static Bar) -> &'static Baz`.
1427+
const RESOLVED_STATIC: Fn(&Foo, &Bar) -> &Baz = ..
1428+
```
1429+
13781430
### Traits
13791431

13801432
A _trait_ describes an abstract interface that types can
@@ -2072,7 +2124,9 @@ macro scope.
20722124

20732125
### Miscellaneous attributes
20742126

2075-
- `deprecated` - mark the item as deprecated; the full attribute is `#[deprecated(since = "crate version", note = "...")`, where both arguments are optional.
2127+
- `deprecated` - mark the item as deprecated; the full attribute is
2128+
`#[deprecated(since = "crate version", note = "...")`, where both arguments
2129+
are optional.
20762130
- `export_name` - on statics and functions, this determines the name of the
20772131
exported symbol.
20782132
- `link_section` - on statics and functions, this specifies the section of the
@@ -2489,9 +2543,6 @@ The currently implemented features of the reference compiler are:
24892543
into a Rust program. This capability, especially the signature for the
24902544
annotated function, is subject to change.
24912545

2492-
* `static_in_const` - Enables lifetime elision with a `'static` default for
2493-
`const` and `static` item declarations.
2494-
24952546
* `thread_local` - The usage of the `#[thread_local]` attribute is experimental
24962547
and should be seen as unstable. This attribute is used to
24972548
declare a `static` as being unique per-thread leveraging

0 commit comments

Comments
 (0)