Commit Graph

986 Commits

Author SHA1 Message Date
Dylan DPC 9b16c7a712
Rollup merge of #83132 - Aaron1011:fix/incr-cache-dummy, r=estebank
Don't encode file information for span with a dummy location

Fixes #83112

The location information for a dummy span isn't real, so don't encode
it. This brings the incr comp cache code into line with the Span
`StableHash` impl, which doesn't hash the location information for dummy
spans.

Previously, we would attempt to load the 'original' file from a dummy
span - if the file id changed (e.g. due to being moved on disk), we would get an
ICE, since the Span was still valid due to its hash being unchanged.
2021-03-15 16:22:58 +01:00
Aaron Hill 7429c688a5
Don't encode file information for span with a dummy location
Fixes #83112

The location information for a dummy span isn't real, so don't encode
it. This brings the incr comp cache code into line with the Span
`StableHash` impl, which doesn't hash the location information for dummy
spans.

Previously, we would attempt to load the 'original' file from a dummy
span - if the file id changed (e.g. due to being moved on disk), we would get an
ICE, since the Span was still valid due to its hash being unchanged.
2021-03-14 20:22:13 -04:00
Simon Vandel Sillesen 35566bfd7d Do not emit alloca for ZST local even if it is uninitialized 2021-03-13 18:01:14 -05:00
Tomasz Miąsko 8b184ff1b8 Remove storage markers if they won't be used during code generation
The storage markers constitute a substantial portion of all MIR
statements. At the same time, for builds without any optimizations,
the storage markers have no further use during and after MIR
optimization phase.

If storage markers are not necessary for code generation, remove them.
2021-02-28 20:10:44 +01:00
hyd-dev 43aed7441e
[libtest] Run the test synchronously when hitting thread limit 2021-02-17 21:38:25 +08:00
Mark Rousskov 8a3edb1d66 Update tests for extern block linting 2021-01-13 07:49:16 -05:00
oli e90b521a15 --emit=mir now emits both `mir_for_ctfe` and `optimized_mir` for `const fn` 2021-01-11 17:24:41 +00:00
bors cf9bfdb872 Auto merge of #78122 - fusion-engineering-forks:fmt-write-bounds-check, r=Mark-Simulacrum
Avoid panic_bounds_check in fmt::write.

Writing any fmt::Arguments would trigger the inclusion of usize formatting and padding code in the resulting binary, because indexing used in fmt::write would generate code using panic_bounds_check, which prints the index and length.

These bounds checks are not necessary, as fmt::Arguments never contains any out-of-bounds indexes.

This change replaces them with unsafe get_unchecked, to reduce the amount of generated code, which is especially important for embedded targets.

---

Demonstration of the size of and the symbols in a 'hello world' no_std binary:

<details>
<summary>Source code</summary>

```rust
#![feature(lang_items)]
#![feature(start)]
#![no_std]

use core::fmt;
use core::fmt::Write;

#[link(name = "c")]
extern "C" {
    #[allow(improper_ctypes)]
    fn write(fd: i32, s: &str) -> isize;
    fn exit(code: i32) -> !;
}

struct Stdout;

impl fmt::Write for Stdout {
    fn write_str(&mut self, s: &str) -> fmt::Result {
        unsafe { write(1, s) };
        Ok(())
    }
}

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
    let _ = writeln!(Stdout, "Hello World");
    0
}

#[lang = "eh_personality"]
fn eh_personality() {}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    unsafe { exit(1) };
}
```
</details>

Before:
```
   text	   data	    bss	    dec	    hex	filename
   6059	    736	      8	   6803	   1a93	before
```
```
0000000000001e00 T <T as core::any::Any>::type_id
0000000000003dd0 D core::fmt::num::DEC_DIGITS_LUT
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for u64>::fmt
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for usize>::fmt
0000000000001370 T core::fmt::write
0000000000001b30 t core::fmt::Formatter::pad_integral::write_prefix
0000000000001660 T core::fmt::Formatter::pad_integral
0000000000001350 T core::ops::function::FnOnce::call_once
0000000000001b80 t core::ptr::drop_in_place
0000000000001120 t core::ptr::drop_in_place
0000000000001c50 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001c90 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001b90 T core::panicking::panic_bounds_check
0000000000001c10 T core::panicking::panic_fmt
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```

After:
```
   text	   data	    bss	    dec	    hex	filename
   3068	    600	      8	   3676	    e5c	after
```
```
0000000000001360 T core::fmt::write
0000000000001340 T core::ops::function::FnOnce::call_once
0000000000001120 t core::ptr::drop_in_place
0000000000001620 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001660 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```
2020-11-29 23:14:40 +00:00
Mara Bos 1da5780303 Add test to check for fmt::write bloat.
It checks that fmt::write by itself doesn't pull in any panicking or
or display code.
2020-11-29 11:38:51 +01:00
bors 9722952f0b Auto merge of #76256 - tgnottingham:issue-74890, r=nikomatsakis
incr-comp: hash and serialize span end line/column

Hash both the length and the end location (line/column) of a span. If we
hash only the length, for example, then two otherwise equal spans with
different end locations will have the same hash. This can cause a
problem during incremental compilation wherein a previous result for a
query that depends on the end location of a span will be incorrectly
reused when the end location of the span it depends on has changed. A
similar analysis applies if some query depends specifically on the
length of the span, but we only hash the end location. So hash both.

Fix #46744, fix #59954, fix #63161, fix #73640, fix #73967, fix #74890, fix #75900

---

See #74890 for a more in-depth analysis.

I haven't thought about what other problems this root cause could be responsible for. Please let me know if anything springs to mind. I believe the issue has existed since the inception of incremental compilation.
2020-11-12 15:34:09 +00:00
Tyson Nottingham dac57e67d6 incr-comp: add ignore-32bit directive to incr-prev-body-beyond-eof test
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-11-09 14:08:52 -08:00
Tyson Nottingham 73351109f5 incr-comp: add clarifying comments to incr-prev-body-beyond-eof test 2020-11-08 20:28:03 -08:00
Daiki Ihara f197da655f fix shellcheck error of SC2148 2020-11-06 20:33:12 +09:00
Tyson Nottingham b71e627b26 incr-comp: hash span end line/column
Hash both the length and the end location (line/column) of a span. If we
hash only the length, for example, then two otherwise equal spans with
different end locations will have the same hash. This can cause a
problem during incremental compilation wherein a previous result for a
query that depends on the end location of a span will be incorrectly
reused when the end location of the span it depends on has changed. A
similar analysis applies if some query depends specifically on the
length of the span, but we only hash the end location. So hash both.

Fix #46744, fix #59954, fix #63161, fix #73640, fix #73967, fix #74890, fix #75900
2020-11-04 01:37:18 -08:00
Jonas Schievink 60594b1f0f Ignore on 32-bit targets 2020-10-19 16:41:36 +02:00
Jonas Schievink d7c7649f5b ignore-thumb 2020-10-19 16:37:05 +02:00
Jonas Schievink a67160494c Ignore test on WASM 2020-10-19 16:37:04 +02:00
Jonas Schievink e36de6b2a1 Move issue-36710 test to run-make
Somewhat hacky to reuse `tools.mk` like this, we should probably migrate
most of them now
2020-10-19 16:37:04 +02:00
Raoul Strackx 7d3c3fdc1d cleaning up code 2020-09-25 15:13:55 +02:00
Raoul Strackx 8ca26cca29 Building libunwind with new CMakeLists.
The old CMakeLists file of libunwind used the C compiler to compile assembly files. This caused such code not to be hardened.
2020-09-25 15:09:57 +02:00
Raoul Strackx 72a8e6b193 Adding checks for module level assembly 2020-09-25 15:09:16 +02:00
Raoul Strackx d8a7904e06 LVI hardening tests for cmake 2020-09-25 15:08:32 +02:00
Raoul Strackx 64811ed5a5 testing c++ code (cc crate) 2020-09-25 15:06:40 +02:00
Raoul Strackx bdf81f508d test hardening C inline assembly code (cc crate) 2020-09-25 15:02:15 +02:00
Raoul Strackx 0526e750cd started using cc crate 2020-09-25 15:02:15 +02:00
Raoul Strackx 6db05904f6 LVI test std lib 2020-09-25 15:02:14 +02:00
Raoul Strackx 947d7238e0 Adding checks for assembly files in libunwind 2020-09-25 15:02:14 +02:00
Mark Rousskov 1aac99de25 Provide bootstrap tools with RUSTC in environment 2020-09-20 16:39:13 -04:00
Vadim Petrochenkov 62c9fa939d proc_macro: Add API for tracked access to environment variables 2020-07-26 13:37:37 +03:00
Harald Hoyer 6b9b2d99ca Fix src/test/run-make/static-pie/test-aslr.rs
Might be subject to the birthday paradox occasionally, causing spurious failures.

Addresses: https://github.com/rust-lang/rust/pull/70740#pullrequestreview-430981320
2020-07-13 11:33:03 +02:00
Vadim Petrochenkov a5764de00b expand: Stop using nonterminals for passing tokens to attribute and derive macros 2020-07-01 13:13:21 +03:00
bors 1033351a51 Auto merge of #71858 - petrochenkov:env, r=Mark-Simulacrum
Print environment variables accessed by rustc as special comments into depinfo files

So cargo (and perhaps others tools) can use them for linting (at least) or for actually rebuilding crates on env var changes.

---
I've recently observed one more forgotten environment variable in a build script 8a77d1ca3f and thought it would be nice to provide the list of accessed variables to cargo automatically as a part of depinfo.

Unsurprisingly, I wasn't the first who had this idea - cc https://github.com/rust-lang/rust/issues/70517 https://github.com/rust-lang/rust/issues/40364 https://github.com/rust-lang/rust/issues/44074.

Also, there are dozens of uses of `(option_)env!` in rustc repo and, like, half of them are not registered in build scripts.

---
Description:
- depinfo files are extended with special comments containing info about environment variables accessed during compilation.
- Comment format for environment variables with successfully retrieved value: `# env-dep:KEY=VALUE`.
- Comment format for environment variables without successfully retrieved value: `# env-dep:KEY` (can happen with `option_env!`).
- `KEY` and `VALUE` are minimally escaped (`\n`, `\r`, `\\`) so they don't break makefile comments and can be unescaped by anything that can unescape standard `escape_default` and friends.

FCP report: https://github.com/rust-lang/rust/pull/71858#issuecomment-633071488

Closes https://github.com/rust-lang/rust/issues/70517
Closes https://github.com/rust-lang/rust/issues/40364
Closes https://github.com/rust-lang/rust/issues/44074
A new issue in the cargo repo will be needed to track the cargo side of this feature.

r? @ehuss
2020-06-25 22:52:59 +00:00
Harald Hoyer d3ca6fd71e Enable static-pie for the x86_64-unknown-linux-musl target
Fixes: https://github.com/rust-lang/rust/issues/70693
2020-06-15 14:04:48 +02:00
Vadim Petrochenkov 69b2179afe Print accessed env vars as special comments into depinfo files 2020-05-31 12:00:46 +03:00
ThinkChaos 4ea83bfb3d Use Cell::take in a couple places 2020-04-26 11:50:53 +02:00
bors 138c50f0af Auto merge of #67878 - Others:opt-3, r=Mark-Simulacrum
Change opt-level from 2 back to 3

In Cargo.toml, the opt-level for `release` and `bench` was overridden to be 2. This was to work around a problem with LLVM 7. However, rust no longer uses LLVM 7, so this is hopefully no longer needed?

I tried a little bit to replicate the original problem, and could not. I think running this through CI is the best way to smoke test this :) Even if things break dramatically, the comment should be updated to reflect that things are still broken with LLVM 9.

I'm just getting started playing with the compiler, so apologies if I've missed an obvious problem here.

fixes #52378

(possibly relevant is the [current update to LLVM 10](https://github.com/rust-lang/rust/pull/67759))
2020-01-31 00:03:55 +00:00
Gregor Peach 0d52c562db Change opt-level from 2 back to 3
In Cargo.toml, the opt-level for `release` and `bench` was
overridden to be 2. This was to work around a problem with LLVM
7. However, rust no longer uses LLVM 7, so this is no longer
needed.

This creates a small compile time regression in MIR constant eval,
so I've added a #[inline(always)] on the `step` function used in
const eval

Also creates a binary size increase in wasm-stringify-ints-small,
so I've bumped the limit there.
2020-01-30 15:40:14 -05:00
Jonas Schievink d022e01caa Do not use Cortex-M0 since Qemu is too old 2020-01-21 19:01:56 +01:00
Jonas Schievink 6175f447b5 Check in lockfile 2020-01-21 19:01:56 +01:00
Jonas Schievink 36e230fe22 Update dependencies
This fixes a linkage issue that was fixed a while ago, and adds thumbv8
support.
2020-01-21 19:01:56 +01:00
Jonas Schievink ce36c98e5b Use the right runners for all thumb targets 2020-01-21 19:01:56 +01:00
Jonas Schievink ce7172da51 Fix thumb target CI 2020-01-21 19:01:56 +01:00
maik f1fb384cd6 Check for the entry kind 2020-01-08 10:05:44 +01:00
maik b81ab44a8f Remove unnecessary global counting 2020-01-08 09:53:33 +01:00
Maik Klein eddb3f0668 Fix indentation 2020-01-07 19:42:35 +01:00
Maik Klein a526c8d7fd Add tests for static variables 2020-01-07 19:37:24 +01:00
Alex Crichton aa0ef5a01f Fix handling of wasm import modules and names
The WebAssembly targets of rustc have weird issues around name mangling
and import the same name from different modules. This all largely stems
from the fact that we're using literal symbol names in LLVM IR to
represent what a function is called when it's imported, and we're not
using the wasm-specific `wasm-import-name` attribute. This in turn leads
to two issues:

* If, in the same codegen unit, the same FFI symbol is referenced twice
  then rustc, when translating to LLVM IR, will only reference one
  symbol from the first wasm module referenced.

* There's also a bug in LLD [1] where even if two codegen units
  reference different modules, having the same symbol names means that
  LLD coalesces the symbols and only refers to one wasm module.

Put another way, all our imported wasm symbols from the environment are
keyed off their LLVM IR symbol name, which has lots of collisions today.
This commit fixes the issue by implementing two changes:

1. All wasm symbols with `#[link(wasm_import_module = "...")]` are
   mangled by default in LLVM IR. This means they're all given unique names.

2. Symbols then use the `wasm-import-name` attribute to ensure that the
   WebAssembly file uses the correct import name.

When put together this should ensure we don't trip over the LLD bug [1]
and we also codegen IR correctly always referencing the right symbols
with the right import module/name pairs.

Closes #50021
Closes #56309
Closes #63562

[1]: https://bugs.llvm.org/show_bug.cgi?id=44316
2019-12-16 14:43:46 -08:00
Thomas Lively 2bf59bea48 Upgrade Emscripten targets to use upstream LLVM backend
- Compatible with Emscripten 1.38.46-upstream or later upstream.
 - Refactors the Emscripten target spec to share code with other wasm
   targets.
 - Replaces the old incorrect wasm32 C call ABI with the correct one,
   preserving the old one as wasm32_bindgen_compat for wasm-bindgen
   compatibility.
 - Updates the varargs ABI used by Emscripten and deletes the old one.
 - Removes the obsolete wasm32-experimental-emscripten target.
 - Uses EMCC_CFLAGS on CI to avoid the timeout problems with #63649.
2019-10-16 17:06:48 -07:00
Tyler Mandry d16b7f705b Revert "Auto merge of #63649 - tlively:emscripten-upstream-upgrade, r=alexcrichton"
This reverts commit 7870050796, reversing
changes made to 2e7244807a.
2019-10-05 21:38:45 -07:00
Thomas Lively 5b56c660c9 Fix ABI, run and fix more tests, re-enable CI for PRs 2019-10-04 00:47:21 -07:00