Commit Graph

304 Commits

Author SHA1 Message Date
whitequark 42754ce710 Add profiling support, through the rustc -Z profile flag.
When -Z profile is passed, the GCDAProfiling LLVM pass is added
to the pipeline, which uses debug information to instrument the IR.
After compiling with -Z profile, the $(OUT_DIR)/$(CRATE_NAME).gcno
file is created, containing initial profiling information.
After running the program built, the $(OUT_DIR)/$(CRATE_NAME).gcda
file is created, containing branch counters.

The created *.gcno and *.gcda files can be processed using
the "llvm-cov gcov" and "lcov" tools. The profiling data LLVM
generates does not faithfully follow the GCC's format for *.gcno
and *.gcda files, and so it will probably not work with other tools
(such as gcov itself) that consume these files.
2017-05-01 09:16:20 +00:00
bors 2971d491b9 Auto merge of #41508 - michaelwoerister:generic-path-remapping, r=alexcrichton
Implement a file-path remapping feature in support of debuginfo and reproducible builds

This PR adds the `-Zremap-path-prefix-from`/`-Zremap-path-prefix-to` commandline option pair and is a more general implementation of #41419. As opposed to the previous attempt, this implementation should enable reproducible builds regardless of the working directory of the compiler.

This implementation of the feature is more general in the sense that the re-mapping will affect *all* paths the compiler emits, including the ones in error messages.

r? @alexcrichton
2017-04-28 12:09:37 +00:00
Michael Woerister eb6308fc34 remap-path-prefix: Validate number of commandline arguments passed. 2017-04-26 15:44:02 +02:00
Michael Woerister 39ffea31df Implement a file-path remapping feature in support of debuginfo and reproducible builds. 2017-04-26 15:44:02 +02:00
kennytm 00dff0aa59
Support AddressSanitizer and ThreadSanitizer on x86_64-apple-darwin.
ASan and TSan are supported on macOS, and this commit enables their
support.

The sanitizers are always built as *.dylib on Apple platforms, so they
cannot be statically linked into the corresponding `rustc_?san.rlib`. The
dylibs are directly copied to `lib/rustlib/x86_64-apple-darwin/lib/`
instead.

Note, although Xcode also ships with their own copies of ASan/TSan dylibs,
we cannot use them due to version mismatch.

There is a caveat: the sanitizer libraries are linked as @rpath, so the
user needs to additionally pass `-C rpath`:

    rustc -Z sanitizer=address -C rpath file.rs
                               ^~~~~~~~

Otherwise there will be a runtime error:

    dyld: Library not loaded: @rpath/libclang_rt.asan_osx_dynamic.dylib
      Referenced from: /path/to/executable
      Reason: image not found
    Abort trap: 6

The next commit includes a temporary change in compiler to force the linker
to emit a usable @rpath.
2017-04-25 10:31:01 +08:00
nate 63ed7843bb add 'mir' as part of the --emit flag list in rustc --help menu and man doc.
This is added because 'rustc' can now generate MIR (referencing to
"Teach rustc --emit=mir #39891").
2017-04-14 15:33:48 -07:00
Austin Hicks 63ebf08be5 Initial attempt at implementing optimization fuel and re-enabling struct field reordering. 2017-04-11 14:36:05 +03:00
Jorge Aparicio 9d11b089ad -Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.

For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)

With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.

`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.

This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.

Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.

``` diff
-    "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+    "pre-link-args": {
+        "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+        "ld": ["--as-needed", "-z,-noexecstack"],
+    },
```

[breaking-change]  for users of custom targets specifications
2017-04-07 10:52:42 -05:00
Jake Goulding 9218f9772a Teach rustc --emit=mir 2017-03-21 20:19:02 -04:00
Corey Farwell 97a1b6a055 Update usages of 'OSX' (and other old names) to 'macOS'.
As of last year with version 'Sierra', the Mac operating system is now
called 'macOS'.
2017-03-12 14:59:04 -04:00
Eduard-Mihai Burtescu 582d5d9793 Rollup merge of #40037 - froydnj:overflow-checks, r=alexcrichton
add `-C overflow-checks` option

In addition to defining and handling the new option, we also add a method on librustc::Session for determining the necessity of overflow checks.  This method provides a single point to sort out the three (!) different ways for turning on overflow checks: -C debug-assertions, -C overflow-checks, and -Z force-overflow-checks.

I was seeing a [run-pass/issue-28950.rs](b1363a73ed/src/test/run-pass/issue-28950.rs) failure on my machine with these patches, but I was also seeing the failure without the changes to the core compiler.  We'll see what travis says.

Fixes #33134.  r? @alexcrichton
2017-02-25 14:13:38 +02:00
Eduard-Mihai Burtescu ebde617c7d Rollup merge of #40022 - wagenet:lib-defaults, r=alexcrichton
Better handling of lib defaults

r? @alexcrichton
2017-02-25 14:13:31 +02:00
Peter Wagenet ae32b6eafd Better handling of lib defaults 2017-02-23 09:36:33 -08:00
Nathan Froyd ffc6ddd51b add `-C overflow-checks` option
In addition to defining and handling the new option, we also add a
method on librustc::Session for determining the necessity of overflow
checks.  This method provides a single point to sort out the three (!)
different ways for turning on overflow checks: -C debug-assertions, -C
overflow-checks, and -Z force-overflow-checks.

Fixes #33134.
2017-02-22 10:08:57 -05:00
Jorge Aparicio 0b06db57d1 incr-comp: track the -Z sanitizer flag
closes #39611
2017-02-20 22:34:42 -05:00
Jorge Aparicio 9af6aa3889 sanitizer support 2017-02-08 18:51:43 -05:00
bors ea7a6486a2 Auto merge of #38426 - vadimcn:nobundle, r=alexcrichton
Implement kind="static-nobundle" (RFC 1717)

This implements the "static-nobundle" library kind (last item from #37403).

Rustc handles "static-nobundle" libs very similarly to dylibs, except that on Windows, uses of their symbols do not get marked with "dllimport".  Which is the whole point of this feature.
2017-02-04 21:13:07 +00:00
Michael Woerister 197f037652 incr.comp.: Make cross-crate tracking for incr. comp. opt-in. 2017-01-24 17:56:29 -05:00
Vadim Chugunov 3ae2174fc5 Feature gate 2017-01-19 13:53:33 -08:00
Vadim Chugunov 91f8144906 Implement the "static-nobundle" library kind (RFC 1717).
These are static libraries that are not bundled (as the name implies) into rlibs and staticlibs that rustc generates,
and must be present when the final binary artifact is being linked.
2017-01-19 13:52:38 -08:00
Jeffrey Seyfried debcbf0b8e Refactor the parser to consume token trees. 2017-01-17 08:17:26 +00:00
Seo Sanghyeon 833d6938e9 Rollup merge of #38841 - F001:Fix, r=steveklabnik
Update usage of rustc

Add proc_macro crate type
2017-01-10 20:27:46 +09:00
F001 943c53bc77 Update usage of rustc
Add proc_macro crate type
2017-01-05 12:25:26 +08:00
Doug Goldstein 031dd81cc8
fix help for the --print option
Since 8285ab5c99, which was merged in with #38061, the help for the
--print option is missing the surrounding [ ] around the possible
options.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2017-01-03 23:44:10 -06:00
Nick Cameron b059a80d4c Support --emit=foo,metadata 2016-12-29 18:17:07 +13:00
Nick Cameron 9c89166611 Restore --crate-type=metadata as an alias for --crate-type=rlib,--emit=metadata + a warning 2016-12-29 13:24:46 +13:00
Nick Cameron 7720cf02e3 Change --crate-type metadata to --emit=metadata 2016-12-29 13:24:45 +13:00
whitequark 5b0700ef31 Add a min_atomic_width target option, like max_atomic_width.
Rationale: some ISAs, e.g. OR1K, do not have atomic instructions
for byte and halfword access, and at the same time do not have
a fixed endianness, which makes it unreasonable to implement these
through word-sized atomic accesses.
2016-12-24 02:17:45 +00:00
bors 99913c5ead Auto merge of #38401 - redox-os:redox_cross, r=brson
Redox Cross Compilation

I will admit - there are things here that I wish I did not have to do. This completes the ability to create a cross compiler from the rust repository for `x86_64-unknown-redox`. I will document this PR with inline comments explaining some things.

[View this gist to see how a cross compiler is built](https://gist.github.com/jackpot51/6680ad973986e84d69c79854249f2b7e)

Prior discussion of a smaller change is here: https://github.com/rust-lang/rust/pull/38366
2016-12-23 09:09:26 +00:00
Jeremy Soller 4dcb867671 Convert fam to Symbol 2016-12-22 22:29:33 -07:00
Jeremy Soller c59bb4979c Correct target_family mess 2016-12-22 22:20:47 -07:00
Alex Crichton 1b8e6c152c rustbuild: Fix LC_ID_DYLIB directives on OSX
Currently libraries installed by rustbuild on OSX have an incorrect
`LC_ID_DYLIB` directive located in the dynamic libraries that are
installed. The directive we expect looks like:

    @rpath/libstd.dylib

Which means that if you want to find that dynamic library you should
look at the dylib's other `@rpath` directives. Typically our `@rpath`
directives look like `@loader_path/../lib` for the compiler as that's
where the installed libraries will be located. Currently, though,
rustbuild produces dylibs with the directive that looks like:

    /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps/libstd-713ad88203512705.dylib

In other words, the build directory is encoded erroneously. The compiler
already [knows how] to change this directive, but it only passes that
argument when `-C rpath` is also passed. The rustbuild system, however,
explicitly [does not pass] this option explicitly and instead bakes its
own. This logic then also erroneously didn't pass `-Wl,-install_name`
like the compiler.

[knows how]: 4a008cccaa/src/librustc_trans/back/linker.rs (L210-L214)
[does not pass]: 4a008cccaa/src/bootstrap/bin/rustc.rs (L133-L158)

To fix this regression this patch introduces a new `-Z` flag, `-Z
osx-rpath-install-name` which basically just forces the compiler to take
the previous `-install_name` branch when creating a dynamic library.
Hopefully we can sort out a better rpath story in the future, but for
now this "hack" should suffice in getting our nightly builds back to the
same state as before.

Closes #38430
2016-12-17 16:14:11 -08:00
Ulrik Sverdrup 6d46a21cb3 Simplify use of mir_opt_level
Remove the unused top level option by the same name, and retain the
debug option.

Use -Zmir-opt-level=1 as default.

One pass is enabled by default but wants to be optional:

- Instcombine requires mir_opt_level > 0

Copy propagation is not used by default, but used to be activated by
explicit -Zmir-opt-level=1. It must move one higher to be off by
default:

- CopyPropagation requires mir_opt_level > 1

Deaggregate is not used by default, and used to be on a different level
than CopyPropagation:

- Deaggreate requires mir_opt_level > 2
2016-12-11 21:23:59 +01:00
Oliver Schneider 87a9ae224d
add a -Z flag to guarantee that MIR is generated for all functions 2016-12-07 13:22:21 +01:00
bors 1692c0b587 Auto merge of #37973 - vadimcn:dllimport, r=alexcrichton
Implement RFC 1717

Implement the first two points from #37403.

r? @alexcrichton
2016-12-06 10:54:45 +00:00
bors ebeee0e27e Auto merge of #38092 - pnkfelix:mir-stats, r=nikomatsakis
Adds `-Z mir-stats`, which is similar to `-Z hir-stats`.

Adds `-Z mir-stats`, which is similar to `-Z hir-stats`.

Some notes:

* This code attempts to present the breakdown of each variant for
  every enum in the MIR. This is meant to guide decisions about how to
  revise representations e.g. when to box payloads for rare variants
  to shrink the size of the enum overall.

* I left out the "Total:" line that hir-stats presents, because this
  implementation uses the MIR Visitor infrastructure, and the memory
  usage of structures directly embedded in other structures (e.g. the
  `func: Operand` in a `TerminatorKind:Call`) is not distinguished
  from similar structures allocated in a `Vec` (e.g. the `args:
  Vec<Operand>` in a `TerminatorKind::Call`). This means that a naive
  summation of all the accumulated sizes is misleading, because it
  will double-count the contribution of the `Operand` of the `func` as
  well as the size of the whole `TerminatorKind`.

  * I did consider abandoning the MIR Visitor and instead hand-coding
    a traversal that distinguished embedded storage from indirect
    storage. But such code would be fragile; better to just require
    people to take care when interpreting the presented results.

* This traverses the `mir.promoted` rvalues to capture stats for MIR
  stored there, even though the MIR visitor super_mir method does not
  do so. (I did not observe any promoted mir being newly traversed when
  compiling the rustc crate, however.)

* It might be nice to try to unify this code with hir-stats.  Then
  again, the reporting portion is the only common code (I think), and
  it is small compared to the visitors in hir-stats and mir-stats.
2016-12-04 23:36:50 +00:00
Corey Farwell d6281faf7e Rollup merge of #38113 - nikomatsakis:incremental-dump-hash, r=michaelwoerister
add a `-Z incremental-dump-hash` flag

This causes us to dump a bunch of has information to stdout that can be
useful in tracking down incremental compilation invalidations,
particularly across crates.
2016-12-03 15:39:53 -05:00
Doug Goldstein ff112644de
rustc: add --print target-spec option
This option provides the user the ability to dump the configuration that
is in use by rustc for the target they are building for.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2016-12-02 10:07:38 -06:00
Vadim Chugunov 13477c77bf Implement native library kind and name overrides from the command line. 2016-12-01 16:22:04 -08:00
Doug Goldstein 8285ab5c99
convert --print options to a vector
To allow manipulation of the options that appear in --print, convert it
to a vector.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2016-12-01 16:59:09 -06:00
Niko Matsakis 57ffda6158 add a `-Z incremental-dump-hash` flag
This causes us to dump a bunch of has information to stdout that can be
useful in tracking down incremental compilation invalidations,
particularly across crates.
2016-12-01 12:29:28 -05:00
Felix S. Klock II ff1ba6a505 Adds `-Z mir-stats`, which is similar to `-Z hir-stats`.
Some notes:

* This code attempts to present the breakdown of each variant for
  every enum in the MIR. This is meant to guide decisions about how to
  revise representations e.g. when to box payloads for rare variants
  to shrink the size of the enum overall.

* I left out the "Total:" line that hir-stats presents, because this
  implementation uses the MIR Visitor infrastructure, and the memory
  usage of structures directly embedded in other structures (e.g. the
  `func: Operand` in a `TerminatorKind:Call`) is not distinguished
  from similar structures allocated in a `Vec` (e.g. the `args:
  Vec<Operand>` in a `TerminatorKind::Call`). This means that a naive
  summation of all the accumulated sizes is misleading, because it
  will double-count the contribution of the `Operand` of the `func` as
  well as the size of the whole `TerminatorKind`.

  * I did consider abandoning the MIR Visitor and instead hand-coding
    a traversal that distinguished embedded storage from indirect
    storage. But such code would be fragile; better to just require
    people to take care when interpreting the presented results.

* This traverses the `mir.promoted` rvalues to capture stats for MIR
  stored there, even though the MIR visitor super_mir method does not
  do so. (I did not observe any new mir being traversed when compiling
  the rustc crate, however.)

* It might be nice to try to unify this code with hir-stats.  Then
  again, the reporting portion is the only common code (I think), and
  it is small compared to the visitors in hir-stats and mir-stats.
2016-11-30 21:33:18 +01:00
Felix S. Klock II 9383fcf07f Add `-Z print-type-sizes`, a tool for digging into how variants are laid out. 2016-11-24 10:30:18 +01:00
bors 5196ca8518 Auto merge of #37681 - nrc:crate-metadata, r=@alexcrichton
add --crate-type metadata

r? @alexcrichton
2016-11-22 21:54:10 -06:00
Nick Cameron af1b19555c Rebasing and review changes 2016-11-23 12:50:39 +13:00
Jeffrey Seyfried a8e86f0f81 Fix fallout in `rustdoc` and tests. 2016-11-21 12:16:46 +00:00
Jeffrey Seyfried e85a0d70b8 Use `Symbol` instead of `InternedString` in the AST, HIR, and various other places. 2016-11-21 09:00:55 +00:00
Jeffrey Seyfried d2f8fb0a0a Move `syntax::util::interner` -> `syntax::symbol`, cleanup. 2016-11-20 23:40:20 +00:00
Nick Cameron b286a2f081 Add --crate-type metadata
With the same semantics as -Zno-trans
2016-11-21 07:08:35 +13:00
Jeffrey Seyfried 4b9b0d3474 Refactor `CrateConfig`. 2016-11-20 12:35:57 +00:00