Commit graph

89 commits

Author SHA1 Message Date
Anthony Ramine
6febaf2419 Implement -Z relax-elf-relocations=yes|no
This lets rustc users tweak whether the linker should relax ELF relocations,
namely whether it should emit R_X86_64_GOTPCRELX relocations instead of
R_X86_64_GOTPCREL, as the former is allowed by the ABI to be further
optimised. The default value is whatever the target defines.
2020-10-31 17:16:56 +01:00
Joshua Nelson
57c6ed0c07 Fix even more clippy warnings 2020-10-30 10:13:39 -04:00
bors
3dddf6ac1e Auto merge of #78414 - nox:function-sections, r=nagisa,bjorn3
Implement -Z function-sections=yes|no

This lets rustc users tweak whether all functions should be put in their own TEXT section, using whatever default value the target defines if the flag is missing.

I'm having fun experimenting with musl libc and trying to implement the start symbol in Rust, that means avoiding code that requires relocations, and AFAIK putting everything in its own section makes the toolchain generate `GOTPCREL` relocations for symbols that could use plain old PC-relative addressing (at least on `x86_64`) if they were all in the same section.
2020-10-28 17:47:36 +00:00
Anthony Ramine
056942215c Implement -Z function-sections=yes|no
This lets rustc users tweak whether all functions should be put in their own
TEXT section, using whatever default value the target defines if the flag
is missing.
2020-10-26 23:26:43 +01:00
bors
0da6d42f29 Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obk
rustc_mir: track inlined callees in SourceScopeData.

We now record which MIR scopes are the roots of *other* (inlined) functions's scope trees, which allows us to generate the correct debuginfo in codegen, similar to what LLVM inlining generates.
This PR makes the `ui` test `backtrace-debuginfo` pass, if the MIR inliner is turned on by default.

Also, `#[track_caller]` is now correct in the face of MIR inlining (cc `@anp).`

Fixes #76997.

r? `@rust-lang/wg-mir-opt`
2020-10-26 18:50:22 +00:00
Dylan DPC
147a001fd3
Rollup merge of #78126 - shepmaster:aarch64-apple-darwin-valist, r=nagisa
Properly define va_arg and va_list for aarch64-apple-darwin

From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-26 03:09:00 +01:00
Jake Goulding
0a91755ff4 Properly define va_arg and va_list for aarch64-apple-darwin
From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-25 21:37:01 -04:00
Jake Goulding
c6ab758e54 Switch from tuple matching to match guards 2020-10-24 12:58:38 -04:00
Jonas Schievink
1ac137be93
Rollup merge of #78307 - rust-lang:revert-77961-embed-bitcode, r=tmandry
Revert "Set .llvmbc and .llvmcmd sections as allocatable"

Reverts rust-lang/rust#77961, see discussion starting from https://github.com/rust-lang/rust/pull/77961#issuecomment-712313902
2020-10-24 14:12:20 +02:00
Rich Kadel
f75a236fe0
Update compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2020-10-23 14:58:08 -07:00
Tyler Mandry
6640a62e0e
Revert "Set .llvmbc and .llvmcmd sections as allocatable" 2020-10-23 12:54:00 -07:00
Rich Kadel
a7bc1a2edf Make codegen coverage_context optional, and check
Addresses Issue #78286

Libraries compiled with coverage and linked with out enabling coverage
would fail when attempting to add the library's coverage statements to
the codegen coverage context (None).

Now, if coverage statements are encountered while compiling / linking
with `-Z instrument-coverage` disabled, codegen will *not* attempt to
add code regions to a coverage map, and it will not inject the LLVM
instrprof_increment intrinsic calls.
2020-10-23 12:00:30 -07:00
Eduard-Mihai Burtescu
0ce4452fce rustc_codegen_llvm: add support for inlined function debuginfo. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
737499593d rustc_codegen_llvm: expose DILocation to rustc_codegen_ssa. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
88d874de63 rustc_codegen_llvm: avoid converting between DILocation and Value. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
fa2b381ec8 rustc_codegen_llvm: move DISubprogram creation to a dbg_scope_fn method. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
9d57c417fc rustc_codegen_llvm: create DIFiles from just SourceFiles. 2020-10-21 04:43:56 +03:00
bors
94332bbe10 Auto merge of #78047 - khyperia:set_span_mut, r=bjorn3
Make set_span take mut self

This was a mistake in https://github.com/rust-lang/rust/pull/77614

It's not a _huge_ deal, because backends can always implement this with interior mutability, but it's nice to avoid interior mutability when possible. For context, the `set_source_location` method, called alongside `set_span`, also takes `&mut self`.

r? `@eddyb`
2020-10-18 05:36:23 +00:00
khyperia
3d484481c7 Make set_span take mut self 2020-10-17 13:28:58 +02:00
bors
6f0ea299cf Auto merge of #77685 - jackh726:binder-map, r=lcnr
Use rebind instead of Binder::bind when possible

These are really only the easy places. I just searched for `Binder::bind` and replaced where it straightforward.

r? `@lcnr`
cc. `@nikomatsakis`
2020-10-17 10:28:52 +00:00
Dylan DPC
55f9676c47
Rollup merge of #77961 - glandium:embed-bitcode, r=nagisa
Set .llvmbc and .llvmcmd sections as allocatable

This marks both sections as allocatable rather than excluded, which matches what
clang does with the equivalent `-fembed-bitcode` flag.
2020-10-17 03:27:20 +02:00
Jack Huey
11d62aa284 Review comments 2020-10-16 12:58:50 -04:00
Jack Huey
dd5c9bf139 Use map_bound(_ref) instead of Binder::bind when possible 2020-10-16 12:58:50 -04:00
bors
a78a62fc99 Auto merge of #77972 - Mark-Simulacrum:side-effect-loop, r=nagisa
Prevent miscompilation in trivial loop {}

Ideally, we would want to handle a broader set of cases to fully fix the
underlying bug here. That is currently relatively expensive at compile and
runtime, so we don't do that for now.

Performance results indicate this is not a major regression, if at all, so it should be safe to land.

cc #28728
2020-10-16 14:06:37 +00:00
Mark Rousskov
e2efec8976 Prevent miscompilation in trivial loop {}
Ideally, we would want to handle a broader set of cases to fully fix the
underlying bug here. That is currently relatively expensive at compile and
runtime, so we don't do that for now.
2020-10-15 09:42:06 -04:00
est31
d683e3ac23 Remove rustc_session::config::Config
The wrapper type led to tons of target.target
across the compiler. Its ptr_width field isn't
required any more, as target_pointer_width
is already present in parsed form.
2020-10-15 12:02:24 +02:00
est31
4fa5578774 Replace target.target with target and target.ptr_width with target.pointer_width
Preparation for a subsequent change that replaces
rustc_target::config::Config with its wrapped Target.

On its own, this commit breaks the build. I don't like making
build-breaking commits, but in this instance I believe that it
makes review easier, as the "real" changes of this PR can be
seen much more easily.

Result of running:

find compiler/ -type f -exec sed -i -e 's/target\.target\([)\.,; ]\)/target\1/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target\.target$/target/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target.ptr_width/target.pointer_width/g' {} \;
./x.py fmt
2020-10-15 12:02:24 +02:00
est31
0d1aa1e034 Rename target_pointer_width to pointer_width and turn it into an u32
Rename target_pointer_width to pointer_width because it is already
member of the Target struct.

The compiler supports only three valid values for target_pointer_width:
16, 32, 64. Thus it can safely be turned into an int.
This means less allocations and clones as well as easier handling of the type.
2020-10-15 12:02:23 +02:00
Mike Hommey
684d142e70 Set .llvmbc and .llvmcmd sections as allocatable 2020-10-15 14:04:57 +09:00
Yuki Okushi
022d20759b
Rollup merge of #77739 - est31:remove_unused_code, r=petrochenkov,varkor
Remove unused code

Rustc has a builtin lint for detecting unused code inside a crate, but when an item is marked `pub`, the code, even if unused inside the entire workspace, is never marked as such. Therefore, I've built [warnalyzer](https://github.com/est31/warnalyzer) to detect unused items in a cross-crate setting.

Closes https://github.com/est31/warnalyzer/issues/2
2020-10-15 07:32:29 +09:00
est31
feaac592a3 Remove unused code from rustc_codegen_* 2020-10-14 04:14:32 +02:00
Dylan DPC
17ee28b71f
Rollup merge of #77795 - bjorn3:codegen_backend_interface_refactor, r=oli-obk
Codegen backend interface refactor

This moves several things away from the codegen backend to rustc_interface. There are a few behavioral changes where previously the incremental cache (incorrectly) wouldn't get finalized, but now it does. See the individual commit messages.
2020-10-14 02:30:38 +02:00
Dylan DPC
596235281c
Rollup merge of #77765 - amshafer:master, r=petrochenkov
Add LLVM flags to limit DWARF version to 2 on BSD

This has been a thorn in my side for a while, I can finally generate flamegraphs of rust programs on bsd again. This fixes dtrace profiling on freebsd, I think it might help with lldb as well but I can't test that because my current rust-lldb setup is messed up.

I'm limiting the dwarf version to 2 on all bsd's (netbsd/openbsd/freebsd) since it looks like this applies to all of them, but I have only tested on freebsd.

Let me know if there's anything I can improve!

---
Currently on FreeBSD dtrace profiling does not work and shows jumbled/incorrect
symbols in the backtraces. FreeBSD does not support the latest versions of DWARF
in dtrace (and lldb?) yet, and needs to be limited to DWARF2 in the same way as macos.

This adds an is_like_bsd flag since it was missing. NetBSD/OpenBSD/FreeBSD all
match this.

This effectively copies #11864 but targets FreeBSD instead of macos.
2020-10-14 02:30:34 +02:00
Austin Shafer
4511f8b9f3 Add a target option for selecting a DWARF version
Certain platforms need to limit the DWARF version emitted (oxs, *bsd). This
change adds a dwarf_version entry to the options that allows a platform to
specify the dwarf version to use. By default this option is none and the default
DWARF version is selected.

Also adds an option for printing Option<u32> json keys
2020-10-13 15:56:30 -04:00
est31
a0fc455d30 Replace absolute paths with relative ones
Modern compilers allow reaching external crates
like std or core via relative paths in modules
outside of lib.rs and main.rs.
2020-10-13 14:16:45 +02:00
bors
f54072bb81 Auto merge of #76830 - Artoria2e5:tune, r=nagisa
Pass tune-cpu to LLVM

I think this is how it should work...

See https://internals.rust-lang.org/t/expose-tune-cpu-from-llvm/13088 for the background. Or the documentation diff.
2020-10-13 02:49:00 +00:00
bjorn3
b620e49cca Remove dump_incremental_data 2020-10-12 10:34:30 +02:00
bors
c71248b708 Auto merge of #76859 - Aaron1011:fix/llvm-cgu-reuse, r=davidtwco,nikic
Use llvm::computeLTOCacheKey to determine post-ThinLTO CGU reuse

During incremental ThinLTO compilation, we attempt to re-use the
optimized (post-ThinLTO) bitcode file for a module if it is 'safe' to do
so.

Up until now, 'safe' has meant that the set of modules that our current
modules imports from/exports to is unchanged from the previous
compilation session. See PR #67020 and PR #71131 for more details.

However, this turns out be insufficient to guarantee that it's safe
to reuse the post-LTO module (i.e. that optimizing the pre-LTO module
would produce the same result). When LLVM optimizes a module during
ThinLTO, it may look at other information from the 'module index', such
as whether a (non-imported!) global variable is used. If this
information changes between compilation runs, we may end up re-using an
optimized module that (for example) had dead-code elimination run on a
function that is now used by another module.

Fortunately, LLVM implements its own ThinLTO module cache, which is used
when ThinLTO is performed by a linker plugin (e.g. when clang is used to
compile a C proect). Using this cache directly would require extensive
refactoring of our code - but fortunately for us, LLVM provides a
function that does exactly what we need.

The function `llvm::computeLTOCacheKey` is used to compute a SHA-1 hash
from all data that might influence the result of ThinLTO on a module.
In addition to the module imports/exports that we manually track, it
also hashes information about global variables (e.g. their liveness)
which might be used during optimization. By using this function, we
shouldn't have to worry about new LLVM passes breaking our module re-use
behavior.

In LLVM, the output of this function forms part of the filename used to
store the post-ThinLTO module. To keep our current filename structure
intact, this PR just writes out the mapping 'CGU name -> Hash' to a
file. To determine if a post-LTO module should be reused, we compare
hashes from the previous session.

This should unblock PR #75199 - by sheer chance, it seems to have hit
this issue due to the particular CGU partitioning and optimization
decisions that end up getting made.
2020-10-11 20:50:02 +00:00
bors
7bc5839e99 Auto merge of #77337 - lzutao:asm-mips64, r=Amanieu
Add asm! support for mips64

- [x] Updated `src/doc/unstable-book/src/library-features/asm.md`.
- [ ] No vector type support. I don't know much about those types.

cc #76839
2020-10-10 17:32:28 +00:00
bjorn3
12a2941214 Move llvm_util::time_trace_profiler_finish call to join_codegen
This makes it also run when compilation has failed, neither --emit exe
nor --emit metadata is passed, or -Zno-link is used.
2020-10-10 16:20:42 +02:00
bjorn3
69f26b7761 Use fixed type for CodegenResults
This also moves the -Zno-link implementation to rustc_interface
2020-10-10 16:18:36 +02:00
bjorn3
f141acf067 Move finalize_session_directory call out of cg_llvm
This causes it to be called even when passing `-Zno-link`, when linking
fails or when neither `--emit link` nor `--emit metadata` is used.
2020-10-10 15:20:35 +02:00
bjorn3
69f45cd965 Move save_work_product_index call out of cg_llvm 2020-10-10 15:14:58 +02:00
bjorn3
46f2f023b0 Move supported_target_features query provider to cg_ssa 2020-10-09 19:35:17 +02:00
xd009642
a6e2b636e6 Implement the instruction_set attribute 2020-10-08 23:32:20 +01:00
khyperia
c5bc95676b Let backends access span information
Sometimes, a backend may need to emit warnings, errors, or otherwise
need to know the span of the current item in a basic block. So, add a
set_span method to give the backend that information.
2020-10-06 15:39:12 +02:00
Rich Kadel
f5aebad28f Updates to experimental coverage counter injection
This is a combination of 18 commits.

Commit #2:

Additional examples and some small improvements.

Commit #3:

fixed mir-opt non-mir extensions and spanview title elements

Corrected a fairly recent assumption in runtest.rs that all MIR dump
files end in .mir. (It was appending .mir to the graphviz .dot and
spanview .html file names when generating blessed output files. That
also left outdated files in the baseline alongside the files with the
incorrect names, which I've now removed.)

Updated spanview HTML title elements to match their content, replacing a
hardcoded and incorrect name that was left in accidentally when
originally submitted.

Commit #4:

added more test examples

also improved Makefiles with support for non-zero exit status and to
force validation of tests unless a specific test overrides it with a
specific comment.

Commit #5:

Fixed rare issues after testing on real-world crate

Commit #6:

Addressed PR feedback, and removed temporary -Zexperimental-coverage

-Zinstrument-coverage once again supports the latest capabilities of
LLVM instrprof coverage instrumentation.

Also fixed a bug in spanview.

Commit #7:

Fix closure handling, add tests for closures and inner items

And cleaned up other tests for consistency, and to make it more clear
where spans start/end by breaking up lines.

Commit #8:

renamed "typical" test results "expected"

Now that the `llvm-cov show` tests are improved to normally expect
matching actuals, and to allow individual tests to override that
expectation.

Commit #9:

test coverage of inline generic struct function

Commit #10:

Addressed review feedback

* Removed unnecessary Unreachable filter.
* Replaced a match wildcard with remining variants.
* Added more comments to help clarify the role of successors() in the
CFG traversal

Commit #11:

refactoring based on feedback

* refactored `fn coverage_spans()`.
* changed the way I expand an empty coverage span to improve performance
* fixed a typo that I had accidently left in, in visit.rs

Commit #12:

Optimized use of SourceMap and SourceFile

Commit #13:

Fixed a regression, and synched with upstream

Some generated test file names changed due to some new change upstream.

Commit #14:

Stripping out crate disambiguators from demangled names

These can vary depending on the test platform.

Commit #15:

Ignore llvm-cov show diff on test with generics, expand IO error message

Tests with generics produce llvm-cov show results with demangled names
that can include an unstable "crate disambiguator" (hex value). The
value changes when run in the Rust CI Windows environment. I added a sed
filter to strip them out (in a prior commit), but sed also appears to
fail in the same environment. Until I can figure out a workaround, I'm
just going to ignore this specific test result. I added a FIXME to
follow up later, but it's not that critical.

I also saw an error with Windows GNU, but the IO error did not
specify a path for the directory or file that triggered the error. I
updated the error messages to provide more info for next, time but also
noticed some other tests with similar steps did not fail. Looks
spurious.

Commit #16:

Modify rust-demangler to strip disambiguators by default

Commit #17:

Remove std::process::exit from coverage tests

Due to Issue #77553, programs that call std::process::exit() do not
generate coverage results on Windows MSVC.

Commit #18:

fix: test file paths exceeding Windows max path len
2020-10-05 08:02:58 -07:00
Mingye Wang
a35a93f09c Pass tune-cpu to LLVM
I think this is how it should work...
2020-10-05 07:50:44 +08:00
Jonas Schievink
5889cf3146
Rollup merge of #77521 - bjorn3:target_feature_whitelist, r=lcnr
Move target feature whitelist from cg_llvm to cg_ssa

These target features have to be supported or at least emulated by alternative codegen backends anyway as they are used by common crates. By moving this list to cg_ssa, other codegen backends don't have to copy
this code.
2020-10-04 15:45:48 +02:00
Jonas Schievink
5bd9ce5cd4
Rollup merge of #77504 - Amanieu:select_simd_bitmask, r=ecstatic-morse
Support vectors with fewer than 8 elements for simd_select_bitmask

Resolves the issue raised here: https://github.com/rust-lang/stdarch/issues/310#issuecomment-693730094
2020-10-04 15:45:43 +02:00