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 6 pull requests #41129

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
03949f5
issue #40793
GAJaloyan Mar 24, 2017
c80868e
correcting another mistake in an example
GAJaloyan Mar 27, 2017
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
60381cd
cstore: return an immutable borrow from `visible_parent_map`
arielb1 Apr 4, 2017
b970bc2
Enable appveyor cache, add more paranoia
aidanhs Apr 4, 2017
608e8fe
dist-powerpc-linux: use a pure 32-bit CPU profile
cuviper Apr 5, 2017
4c7e277
add an #[used] attribute
Feb 20, 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
7d25e76
add link to issue number, ignore snippet that requires custom linking
Apr 6, 2017
f4f79c3
ignore the .init_array doctest
Apr 6, 2017
fac4941
Rollup merge of #39987 - japaric:used, r=arielb1
frewsxcv Apr 7, 2017
c749a77
Rollup merge of #40797 - GAJaloyan:patch-1, r=arielb1
frewsxcv Apr 7, 2017
331151a
Rollup merge of #41047 - cuviper:src_is_git, r=alexcrichton
frewsxcv Apr 7, 2017
c2747b9
Rollup merge of #41061 - arielb1:parent-lock, r=eddyb
frewsxcv Apr 7, 2017
1565936
Rollup merge of #41075 - aidanhs:aphs-enable-appveyor-cache, r=alexcr…
frewsxcv Apr 7, 2017
9b8e7f0
Rollup merge of #41080 - cuviper:generic-powerpc, r=alexcrichton
frewsxcv Apr 7, 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
7 changes: 5 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,18 @@ install:
- set SCCACHE_ERROR_LOG=%CD%/sccache.log

test_script:
- appveyor-retry sh -c 'git submodule deinit -f . && git submodule update --init'
- if not exist C:\cache\rustsrc\NUL mkdir C:\cache\rustsrc
- sh src/ci/init_repo.sh . /c/cache/rustsrc
- set SRC=.
- set NO_CCACHE=1
- sh src/ci/run.sh

on_failure:
- cat %CD%/sccache.log
- cat %CD%\sccache.log
- cat C:\Users\appveyor\AppData\Local\Temp\1\build-cache-logs\*.log

cache:
- C:\cache\rustsrc
- "build/i686-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
- "build/x86_64-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
- "i686-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
Expand Down
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
7 changes: 1 addition & 6 deletions src/ci/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,13 @@ For targets: `powerpc-unknown-linux-gnu`
- Path and misc options > Patches origin = Bundled, then local
- Path and misc options > Local patch directory = /tmp/patches
- Target options > Target Architecture = powerpc
- Target options > Emit assembly for CPU = power4 -- (+)
- Target options > Tune for CPU = power6 -- (+)
- Target options > Emit assembly for CPU = powerpc -- pure 32-bit PowerPC
- Operating System > Target OS = linux
- Operating System > Linux kernel version = 2.6.32.68 -- ~RHEL6 kernel
- C-library > glibc version = 2.12.2 -- ~RHEL6 glibc
- C compiler > gcc version = 4.9.3
- C compiler > Core gcc extra config = --with-cpu-32=power4 --with-cpu=default32 -- (+)
- C compiler > gcc extra config = --with-cpu-32=power4 --with-cpu=default32 -- (+)
- C compiler > C++ = ENABLE -- to cross compile LLVM

(+) These CPU options match the configuration of the toolchains in RHEL6.

## `powerpc64-linux-gnu.config`

For targets: `powerpc64-unknown-linux-gnu`
Expand Down
8 changes: 4 additions & 4 deletions src/ci/docker/dist-powerpc-linux/powerpc-linux-gnu.config
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ CT_ARCH_SUPPORTS_WITH_FLOAT=y
CT_ARCH_DEFAULT_BE=y
CT_ARCH_DEFAULT_32=y
CT_ARCH_ABI=""
CT_ARCH_CPU="power4"
CT_ARCH_TUNE="power6"
CT_ARCH_CPU="powerpc"
CT_ARCH_TUNE=""
CT_ARCH_BE=y
# CT_ARCH_LE is not set
CT_ARCH_32=y
Expand Down Expand Up @@ -391,8 +391,8 @@ CT_CC_GCC_HAS_LIBSANITIZER=y
CT_CC_GCC_VERSION="4.9.3"
# CT_CC_LANG_FORTRAN is not set
CT_CC_GCC_ENABLE_CXX_FLAGS=""
CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY="--with-cpu-32=power4 --with-cpu=default32"
CT_CC_GCC_EXTRA_CONFIG_ARRAY="--with-cpu-32=power4 --with-cpu=default32"
CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
CT_CC_GCC_EXTRA_CONFIG_ARRAY=""
CT_CC_GCC_EXTRA_ENV_ARRAY=""
CT_CC_GCC_STATIC_LIBSTDCXX=y
# CT_CC_GCC_SYSTEM_ZLIB is not set
Expand Down
15 changes: 13 additions & 2 deletions src/ci/init_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ fi

# Wipe the cache if it's not valid, or mark it as invalid while we update it
if [ ! -f "$cache_valid_file" ]; then
rm -rf "$CACHE_DIR" && mkdir "$CACHE_DIR"
rm -rf "$CACHE_DIR"
mkdir "$CACHE_DIR"
else
rm "$cache_valid_file"
stat_lines=$(cd "$cache_src_dir" && git status --porcelain | wc -l)
stat_ec=$(cd "$cache_src_dir" && git status >/dev/null 2>&1 && echo $?)
if [ ! -d "$cache_src_dir/.git" -o $stat_lines != 0 -o $stat_ec != 0 ]; then
# Something is badly wrong - the cache valid file is here, but something
# about the git repo is fishy. Nuke it all, just in case
echo "WARNING: $cache_valid_file exists but bad repo: l:$stat_lines, ec:$stat_ec"
rm -rf "$CACHE_DIR"
mkdir "$CACHE_DIR"
else
rm "$cache_valid_file"
fi
fi

# Update the cache (a pristine copy of the rust source master)
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,ignore
#![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>
```
4 changes: 2 additions & 2 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub trait CrateStore {
fn stability(&self, def: DefId) -> Option<attr::Stability>;
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
fn visibility(&self, def: DefId) -> ty::Visibility;
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>>;
fn item_generics_cloned(&self, def: DefId) -> ty::Generics;
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name>;
Expand Down Expand Up @@ -302,7 +302,7 @@ impl CrateStore for DummyCrateStore {
fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>> {
bug!("visible_parent_map")
}
fn item_generics_cloned(&self, def: DefId) -> ty::Generics
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_borrowck/borrowck/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ ALIASABLE(*LV, MQ) // M-Deref-Unique
ALIASABLE(LV, MQ)
```

### Checking mutability of immutable pointer types
### Checking aliasability of immutable pointer types

Immutable pointer types like `&T` are aliasable, and hence can only be
borrowed immutably:
Expand All @@ -357,7 +357,7 @@ ALIASABLE(*LV, imm) // M-Deref-Borrowed-Imm
TYPE(LV) = &Ty
```

### Checking mutability of mutable pointer types
### Checking aliasability of mutable pointer types

`&mut T` can be frozen, so it is acceptable to borrow it as either imm or mut:

Expand Down Expand Up @@ -633,7 +633,7 @@ Here is a concrete example of a bug this rule prevents:

```rust
// Test region-reborrow-from-shorter-mut-ref.rs:
fn copy_pointer<'a,'b,T>(x: &'a mut &'b mut T) -> &'b mut T {
fn copy_borrowed_ptr<'a,'b,T>(x: &'a mut &'b mut T) -> &'b mut T {
&mut **p // ERROR due to clause (1)
}
fn main() {
Expand Down
Loading