Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #41116

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3fb1a84
Add a common Build::src_is_git flag
cuviper Apr 3, 2017
e9cfc30
Only use cargo-vendor if building from git sources
cuviper Apr 3, 2017
4d32ff4
Loosen src_is_git to just check exists()
cuviper Apr 3, 2017
631f761
travis: Update musl for i686/x86_64
alexcrichton Apr 5, 2017
4c7e277
add an #[used] attribute
Feb 20, 2017
4e1147f
Add example to std::process::abort
rap2hpoutre Apr 5, 2017
bc1bd8a
add tracking issue and feature-gate and run-make tests
Mar 6, 2017
c759eea
fix location of the emitted object file
Mar 6, 2017
c1635d7
cast the #[used] static to *i8
Apr 6, 2017
ecddad6
don't test for the absence of BAR in the rmake test
Apr 6, 2017
bbe5411
document the implementation a bit more
Apr 6, 2017
763beff
add documentation to the unstable book
Apr 6, 2017
16c77d7
Update process.rs
rap2hpoutre Apr 6, 2017
b4be475
Fix Markdown issues in the docs
ollie27 Apr 6, 2017
f9fb381
rustdoc: Use pulldown-cmark for Markdown HTML rendering
ollie27 Apr 6, 2017
7d25e76
add link to issue number, ignore snippet that requires custom linking
Apr 6, 2017
1f93a78
.gitmodules: use the official Git URL w/o redirect
nodakai Apr 6, 2017
c47cdc0
Introduce HashStable trait and base ICH implementations on it.
michaelwoerister Mar 30, 2017
1220eca
Rollup merge of #39987 - japaric:used, r=arielb1
frewsxcv Apr 6, 2017
51650b4
Rollup merge of #40878 - michaelwoerister:dmh, r=nikomatsakis
frewsxcv Apr 6, 2017
3925445
Rollup merge of #41047 - cuviper:src_is_git, r=alexcrichton
frewsxcv Apr 6, 2017
f05abfe
Rollup merge of #41089 - alexcrichton:update-musl, r=brson
frewsxcv Apr 6, 2017
eba47aa
Rollup merge of #41090 - rap2hpoutre:patch-2, r=steveklabnik
frewsxcv Apr 6, 2017
5fbf6b2
Rollup merge of #41111 - ollie27:docs_markdown_fix, r=GuillaumeGomez
frewsxcv Apr 6, 2017
f66edec
Rollup merge of #41112 - ollie27:rustdoc_pull, r=GuillaumeGomez
frewsxcv Apr 6, 2017
ad59ff8
Rollup merge of #41114 - nodakai:patch-2, r=petrochenkov
frewsxcv Apr 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
url = https://github.com/rust-lang-nursery/reference.git
[submodule "book"]
path = src/doc/book
url = https://github.com/rust-lang/book
url = https://github.com/rust-lang/book.git
41 changes: 22 additions & 19 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,29 +433,32 @@ pub fn rust_src(build: &Build) {
copy(&build.src.join(item), &dst_src.join(item));
}

// Get cargo-vendor installed, if it isn't already.
let mut has_cargo_vendor = false;
let mut cmd = Command::new(&build.cargo);
for line in output(cmd.arg("install").arg("--list")).lines() {
has_cargo_vendor |= line.starts_with("cargo-vendor ");
}
if !has_cargo_vendor {
// If we're building from git sources, we need to vendor a complete distribution.
if build.src_is_git {
// Get cargo-vendor installed, if it isn't already.
let mut has_cargo_vendor = false;
let mut cmd = Command::new(&build.cargo);
for line in output(cmd.arg("install").arg("--list")).lines() {
has_cargo_vendor |= line.starts_with("cargo-vendor ");
}
if !has_cargo_vendor {
let mut cmd = Command::new(&build.cargo);
cmd.arg("install")
.arg("--force")
.arg("--debug")
.arg("--vers").arg(CARGO_VENDOR_VERSION)
.arg("cargo-vendor")
.env("RUSTC", &build.rustc);
build.run(&mut cmd);
}

// Vendor all Cargo dependencies
let mut cmd = Command::new(&build.cargo);
cmd.arg("install")
.arg("--force")
.arg("--debug")
.arg("--vers").arg(CARGO_VENDOR_VERSION)
.arg("cargo-vendor")
.env("RUSTC", &build.rustc);
cmd.arg("vendor")
.current_dir(&dst_src.join("src"));
build.run(&mut cmd);
}

// Vendor all Cargo dependencies
let mut cmd = Command::new(&build.cargo);
cmd.arg("vendor")
.current_dir(&dst_src.join("src"));
build.run(&mut cmd);

// Create source tarball in rust-installer format
let mut cmd = Command::new(SH_CMD);
cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub struct Build {
cxx: HashMap<String, gcc::Tool>,
crates: HashMap<String, Crate>,
is_sudo: bool,
src_is_git: bool,
}

#[derive(Debug)]
Expand Down Expand Up @@ -233,6 +234,7 @@ impl Build {
};
let rust_info = channel::GitInfo::new(&src);
let cargo_info = channel::GitInfo::new(&src.join("cargo"));
let src_is_git = src.join(".git").exists();

Build {
flags: flags,
Expand All @@ -251,6 +253,7 @@ impl Build {
lldb_version: None,
lldb_python_dir: None,
is_sudo: is_sudo,
src_is_git: src_is_git,
}
}

Expand Down Expand Up @@ -307,10 +310,7 @@ impl Build {
OutOfSync,
}

if !self.config.submodules {
return
}
if fs::metadata(self.src.join(".git")).is_err() {
if !self.src_is_git || !self.config.submodules {
return
}
let git = || {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn check(build: &mut Build) {

// If we've got a git directory we're gona need git to update
// submodules and learn about various other aspects.
if fs::metadata(build.src.join(".git")).is_ok() {
if build.src_is_git {
need_cmd("git".as_ref());
}

Expand Down
9 changes: 6 additions & 3 deletions src/ci/docker/dist-i586-gnu-i686-musl/build-musl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ set -ex
export CFLAGS="-fPIC -Wa,-mrelax-relocations=no"
export CXXFLAGS="-Wa,-mrelax-relocations=no"

MUSL=musl-1.1.14
MUSL=musl-1.1.16
curl https://www.musl-libc.org/releases/$MUSL.tar.gz | tar xzf -
cd $MUSL
CFLAGS="$CFLAGS -m32" ./configure --prefix=/musl-i686 --disable-shared --target=i686
make -j10
CC=gcc \
CFLAGS="$CFLAGS -m32" \
./configure --prefix=/musl-i686 --disable-shared \
--target=i686
make AR=ar RANLIB=ranlib -j10
make install
cd ..

Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/dist-x86_64-musl/build-musl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set -ex
export CFLAGS="-fPIC -Wa,-mrelax-relocations=no"
export CXXFLAGS="-Wa,-mrelax-relocations=no"

MUSL=musl-1.1.14
MUSL=musl-1.1.16
curl https://www.musl-libc.org/releases/$MUSL.tar.gz | tar xzf -
cd $MUSL
./configure --prefix=/musl-x86_64 --disable-shared
Expand Down
1 change: 1 addition & 0 deletions src/doc/unstable-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
- [unwind_attributes](unwind-attributes.md)
- [update_panic_count](update-panic-count.md)
- [use_extern_macros](use-extern-macros.md)
- [used](used.md)
- [utf8_error_error_len](utf8-error-error-len.md)
- [vec_remove_item](vec-remove-item.md)
- [windows_c](windows-c.md)
Expand Down
153 changes: 153 additions & 0 deletions src/doc/unstable-book/src/used.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# `used`

The tracking issue for this feature
is: [40289](https://github.com/rust-lang/rust/issues/40289).

------------------------

The `#[used]` attribute can be applied to `static` variables to prevent the Rust
compiler from optimizing them away even if they appear to be unused by the crate
(appear to be "dead code").

``` rust
#![feature(used)]

#[used]
static FOO: i32 = 1;

static BAR: i32 = 2;

fn main() {}
```

If you compile this program into an object file, you'll see that `FOO` makes it
to the object file but `BAR` doesn't. Neither static variable is used by the
program.

``` text
$ rustc -C opt-level=3 --emit=obj used.rs

$ nm -C used.o
0000000000000000 T main
U std::rt::lang_start
0000000000000000 r used::FOO
0000000000000000 t used::main
```

Note that the *linker* knows nothing about the `#[used]` attribute and will
remove `#[used]` symbols if they are not referenced by other parts of the
program:

``` text
$ rustc -C opt-level=3 used.rs

$ nm -C used | grep FOO
```

"This doesn't sound too useful then!" you may think but keep reading.

To preserve the symbols all the way to the final binary, you'll need the
cooperation of the linker. Here's one example:

The ELF standard defines two special sections, `.init_array` and
`.pre_init_array`, that may contain function pointers which will be executed
*before* the `main` function is invoked. The linker will preserve symbols placed
in these sections (at least when linking programs that target the `*-*-linux-*`
targets).

``` rust
#![feature(used)]

extern "C" fn before_main() {
println!("Hello, world!");
}

#[link_section = ".init_array"]
#[used]
static INIT_ARRAY: [extern "C" fn(); 1] = [before_main];

fn main() {}
```

So, `#[used]` and `#[link_section]` can be combined to obtain "life before
main".

``` text
$ rustc -C opt-level=3 before-main.rs

$ ./before-main
Hello, world!
```

Another example: ARM Cortex-M microcontrollers need their reset handler, a
pointer to the function that will executed right after the microcontroller is
turned on, to be placed near the start of their FLASH memory to boot properly.

This condition can be met using `#[used]` and `#[link_section]` plus a linker
script.

``` rust,ignore
#![feature(lang_items)]
#![feature(used)]
#![no_main]
#![no_std]

extern "C" fn reset_handler() -> ! {
loop {}
}

#[link_section = ".reset_handler"]
#[used]
static RESET_HANDLER: extern "C" fn() -> ! = reset_handler;

#[lang = "panic_fmt"]
fn panic_fmt() {}
```

``` text
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 128K
RAM : ORIGIN = 0x20000000, LENGTH = 20K
}

SECTIONS
{
.text ORIGIN(FLASH) :
{
/* Vector table */
LONG(ORIGIN(RAM) + LENGTH(RAM)); /* initial SP value */
KEEP(*(.reset_handler));

/* Omitted: The rest of the vector table */

*(.text.*);
} > FLASH

/DISCARD/ :
{
/* Unused unwinding stuff */
*(.ARM.exidx.*)
}
}
```

``` text
$ xargo rustc --target thumbv7m-none-eabi --release -- \
-C link-arg=-Tlink.x -C link-arg=-nostartfiles

$ arm-none-eabi-objdump -Cd target/thumbv7m-none-eabi/release/app
./target/thumbv7m-none-eabi/release/app: file format elf32-littlearm


Disassembly of section .text:

08000000 <app::RESET_HANDLER-0x4>:
8000000: 20005000 .word 0x20005000

08000004 <app::RESET_HANDLER>:
8000004: 08000009 ....

08000008 <app::reset_handler>:
8000008: e7fe b.n 8000008 <app::reset_handler>
```
2 changes: 1 addition & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ impl<T: PartialEq> Vec<T> {
/// # Examples
///
/// ```
///# #![feature(vec_remove_item)]
/// # #![feature(vec_remove_item)]
/// let mut vec = vec![1, 2, 3, 1];
///
/// vec.remove_item(&1);
Expand Down
5 changes: 3 additions & 2 deletions src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
/// Rust's memory orderings are [the same as
/// LLVM's](http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations).
///
/// For more information see the [nomicon][1].
/// [1]: ../../../nomicon/atomics.html
/// For more information see the [nomicon].
///
/// [nomicon]: ../../../nomicon/atomics.html
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy, Clone, Debug)]
pub enum Ordering {
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ impl Definitions {
}
}

pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
self.node_to_hir_id[node_id]
}

/// Add a definition with a parent definition.
pub fn create_def_with_parent(&mut self,
parent: Option<DefIndex>,
Expand Down
Loading