Commit Graph

427 Commits

Author SHA1 Message Date
bors a84bb95a1f Auto merge of #121036 - matthiaskrgr:rollup-ul05q8e, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #114877 (unstable-book: add quick-edit link)
 - #120548 (rustdoc: Fix handling of doc_auto_cfg feature for cfg attributes on glob reexport)
 - #120549 (modify alias-relate to also normalize ambiguous opaques)
 - #120959 (Remove good path delayed bugs)
 - #120978 (match lowering: simplify block creation)
 - #121019 (coverage: Simplify some parts of the coverage span refiner)
 - #121021 (Extend intra-doc link chapter in the rustdoc book)
 - #121031 (RustWrapper: adapt for coverage mapping API changes)

Failed merges:

 - #121014 (Remove `force_print_diagnostic`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-13 17:27:25 +00:00
bors eaff1af8fd Auto merge of #120055 - nikic:llvm-18, r=cuviper
Update to LLVM 18

LLVM 18 final is planned to be released on Mar 5th. Rust 1.78 is planned to be released on May 2nd.

Tested images: dist-x86_64-linux, dist-s390x-linux, dist-aarch64-linux, dist-riscv64-linux, dist-loongarch64-linux, dist-x86_64-freebsd, dist-x86_64-illumos, dist-x86_64-musl, x86_64-linux-integration, test-various, armhf-gnu, i686-msvc, x86_64-msvc, i686-mingw, x86_64-mingw, x86_64-apple-1, x86_64-apple-2, dist-aarch64-apple

r? `@ghost`
2024-02-13 15:07:28 +00:00
Tim Neumann 14ec3b6c91 RustWrapper: adapt for coverage mapping API changes 2024-02-13 15:15:14 +01:00
Nikita Popov a911c8ce23 Use MCSubtargetInfo::getAllProcessorFeatures()
This method is now available in upstream LLVM \o/
2024-02-13 10:33:40 +01:00
Matthias Krüger 70ea26d349
Rollup merge of #120995 - durin42:llvm-19-pgo-coldfuncopt, r=cuviper
PassWrapper: adapt for llvm/llvm-project@93cdd1b5cf

Should be no functional change.

`@rustbot` label: +llvm-main
2024-02-13 06:27:41 +01:00
Augie Fackler 9d1bd2e067 PassWrapper: adapt for llvm/llvm-project@93cdd1b5cf
Should be no functional change.

@rustbot label: +llvm-main
2024-02-12 19:13:09 -05:00
Hans Wennborg 718b304d82 llvm-wrapper: adapt for LLVM API change: Add support for EXPORTAS name types
Adapt for llvm/llvm-project@8f23464.
2024-02-12 15:23:50 +01:00
Matthias Krüger 46a0448405
Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco
Invert diagnostic lints.

That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.

r? ````@davidtwco````
2024-02-09 14:41:50 +01:00
Matthias Krüger 59ba8024af
Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compiler-errors
Remove `ffi_returns_twice` feature

The [tracking issue](https://github.com/rust-lang/rust/issues/58314) and [RFC](https://github.com/rust-lang/rfcs/pull/2633) have been closed for a couple of years.

There is also an attribute gate in R-A which should be removed if this lands.
2024-02-06 22:45:42 +01:00
klensy ca35cfb6de review 2024-02-06 12:44:40 +03:00
klensy 2a06b69ba2 llvm-wrapper: remove llvm 12 hack
effectively reverts 9a8acea783
2024-02-06 12:24:30 +03:00
Nicholas Nethercote 0ac1195ee0 Invert diagnostic lints.
That is, change `diagnostic_outside_of_impl` and
`untranslatable_diagnostic` from `allow` to `deny`, because more than
half of the compiler has be converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow`
attributes, which proves that this change is warranted.
2024-02-06 13:12:33 +11:00
clubby789 7331315898 Remove `ffi_returns_twice` feature 2024-01-30 22:09:09 +00:00
DianQK aa874c5513
Revert "Auto merge of #113923 - DianQK:restore-no-builtins-lto, r=pnkfelix"
This reverts commit 8c2b577217, reversing
changes made to 9cf18e98f8.
2024-01-12 18:23:04 +08:00
Ao Li c9276ea042 Pass LLVM error message back to pass wrapper. 2024-01-05 15:59:11 -05:00
Matthias Krüger b053a9c2ea
Rollup merge of #118941 - krasimirgg:llvm-cov, r=nikic
llvm-wrapper: adapt for LLVM API changes

Adapt for 8ecbb0404d.

r? `@nikic`
`@rustbot` label: +llvm-main
2023-12-18 17:03:11 +01:00
Krasimir Georgiev 0a285e8de7 llvm-wrapper: adapt for LLVM API changes
Adapt for 8ecbb0404d.
2023-12-18 11:25:31 +00:00
bors 02ad6676dd Auto merge of #110494 - majaha:noTrapAfterNoreturn, r=nikic
Use the LLVM option NoTrapAfterNoreturn

Use this LLVM option: https://llvm.org/doxygen/classllvm_1_1TargetOptions.html#acd83fce25de1ac9f6c975135a8235c22 when TrapUnreachable is enabled. This prevents codegenning unnecessary double-traps in some situations.

See further discussion here: https://github.com/rust-lang/compiler-team/issues/618
2023-12-16 18:55:01 +00:00
Krasimir Georgiev 46a8015591 llvm-wrapper: adapt for LLVM API change
LLVM commit f09cf34d00 moved some functions to a different header:

https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/24416#018c5de6-b9c9-4b22-9473-6070d99dcfa7/233-537
2023-12-12 12:29:30 +00:00
bors e2a3c9b3f0 Auto merge of #117962 - weihanglo:debug-name-table, r=wesleywiser
fix: stop emitting `.debug_pubnames` and `.debug_pubtypes`

A continuation of #94181.
Fixes #48762
MCP can be found in <https://github.com/rust-lang/compiler-team/issues/688>.

`.debug_pubnames` and `.debug_pubtypes` are poorly designed and people
seldom use them. However, they take a considerable portion of size in
the final binary. This tells LLVM stop emitting those sections on
DWARFv4 or lower. DWARFv5 use `.debug_names` which is more concise
in size and performant for name lookup.

Some other no-really-useful personal notes:

<details><summary>Details</summary>
<p>

## Pepole saying they are not useful

* https://github.com/rust-lang/rust/issues/48762
* https://rust-lang.zulipchat.com/#narrow/stream/317568-t-compiler.2Fwg-debugging/topic/investigating.20debuginfo.20size/near/342713604
* `DwarfCompileUnit::hasDwarfPubSections()` — f633f325a1/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (L1477-L1494)
* clang default to no debug name table when no option provided — f633f325a1/clang/lib/Frontend/CompilerInvocation.cpp (L1819-L1824)
* GCC explicitly says GDB doesn't use pub sections (`TARGET_WANT_DEBUG_PUB_SECTIONS` only be true on Darwin) — 5d2a360f0a/gcc/target.def (L6985-L6990) and 319b460545/gold/dwarf_reader.h (L424-L427)
* Probably the only place that makes use of pub section in lldb — 725115d7bb/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (L2117-L2135)

* "The -gsplit-dwarf option requires -ggnu-pubnames." — 5d2a360f0a/gcc/opts.cc (L1205)

* LLVM: Always emit `.debug_names` with dwarf 5 for Apple platforms — https://reviews.llvm.org/D118754

</p>
</details>
2023-12-11 22:32:08 +00:00
Weihang Lo 1667f3d2cc
fix: stop emitting `.debug_pubnames` and `.debug_pubtypes`
`.debug_pubnames` and `.debug_pubtypes` are poorly designed and people
seldom use them. However, they take a considerable portion of size in
the final binary. This tells LLVM stop emitting those sections on
DWARFv4 or lower. DWARFv5 use `.debug_names` which is more concise
in size and performant for name lookup.
2023-12-11 14:58:02 -05:00
Krasimir Georgiev a0c5079889 llvm-wrapper: adapt for LLVM API change
LLVM commit 1d608fc755
renamed the pass.
2023-12-11 09:27:09 +00:00
bors 608f32435a Auto merge of #117873 - quininer:android-emutls, r=Amanieu
Add emulated TLS support

This is a reopen of https://github.com/rust-lang/rust/pull/96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful.

Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false.

This commit has some changes to allow users to enable emutls:

1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key.
2. when using emutls, decorate symbol names to find thread local symbol correctly.
3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls.

r? `@Amanieu`
2023-12-09 05:32:35 +00:00
Matthias Krüger 78d2061390
Rollup merge of #118177 - sivadeilra:suppress-llvm-warnings, r=cuviper
Suppress warnings in LLVM wrapper when targeting MSVC

The LLVM header files generate many warnings when compiled using MSVC. This makes it difficult to work on the LLVM wrapper code, because the warnings and errors that are relevant to local edits are obscured by the hundreds of lines of warnings from the LLVM Headers.
2023-12-06 21:52:31 +01:00
quininer e5b76892cc Add emulated TLS support
Currently LLVM uses emutls by default
for some targets (such as android, openbsd),
but rust does not use it, because `has_thread_local` is false.

This commit has some changes to allow users to enable emutls:

1. add `-Zhas-thread-local` flag to specify
    that std uses `#[thread_local]` instead of pthread key.
2. when using emutls, decorate symbol names
    to find thread local symbol correctly.
3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated`
    to explicitly specify whether to generate emutls.
2023-12-07 00:21:32 +08:00
Urgau 9b4fe38903 Use new check-cfg syntax in rustc_llvm build script 2023-12-05 13:25:11 +01:00
bors 8c2b577217 Auto merge of #113923 - DianQK:restore-no-builtins-lto, r=pnkfelix
Restore `#![no_builtins]` crates participation in LTO.

After #113716, we can make `#![no_builtins]` crates participate in LTO again.

`#![no_builtins]` with LTO does not result in undefined references to the error. I believe this type of issue won't happen again.

Fixes #72140.  Fixes #112245. Fixes #110606.  Fixes #105734. Fixes #96486. Fixes #108853. Fixes #108893. Fixes #78744. Fixes #91158. Fixes https://github.com/rust-lang/cargo/issues/10118. Fixes https://github.com/rust-lang/compiler-builtins/issues/347.

 The `nightly-2023-07-20` version does not always reproduce problems due to changes in compiler-builtins, core, and user code. That's why this issue recurs and disappears.
Some issues were not tested due to the difficulty of reproducing them.

r? pnkfelix

cc `@bjorn3` `@japaric` `@alexcrichton` `@Amanieu`
2023-12-01 21:45:18 +00:00
Miguel Ojeda 2d476222e8 Add `-Zfunction-return={keep,thunk-extern}` option
This is intended to be used for Linux kernel RETHUNK builds.

With this commit (optionally backported to Rust 1.73.0), plus a
patched Linux kernel to pass the flag, I get a RETHUNK build with
Rust enabled that is `objtool`-warning-free and is able to boot in
QEMU and load a sample Rust kernel module.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-11-30 20:21:31 +01:00
bors 49b3924bd4 Auto merge of #117947 - Dirbaio:drop-llvm-15, r=cuviper
Update the minimum external LLVM to 16.

With this change, we'll have stable support for LLVM 16 and 17.
For reference, the previous increase to LLVM 15 was #114148

[Relevant zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/riscv.20forced-atomics)
2023-11-27 21:54:03 +00:00
klensy aff6c741d4 remove unused pub fn 2023-11-23 14:11:02 +03:00
Arlie Davis 84bc8f037a fix long lines 2023-11-22 10:17:50 -08:00
Arlie Davis 6773fd1a9a suppress warnings on msvc 2023-11-22 09:10:53 -08:00
Dario Nieuwenhuis 7de6d04bc8 Update the minimum external LLVM to 16. 2023-11-21 22:40:16 +01:00
Ben Kimock e6f8edff37 Tighten up linkage settings for LLVM bindings 2023-11-21 13:43:11 -05:00
bors 1be1e84872 Auto merge of #117875 - Mark-Simulacrum:bootstrap-bump, r=clubby789
Bootstrap bump

Bumps bootstrap compiler to just-released beta.

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2023-11-16 12:45:27 +00:00
bors 6faa181015 Auto merge of #117948 - aeubanks:dibuilder, r=durin42
llvm-wrapper: Pass newly added param to DIBuilder::createStaticMemberType()

This was added in https://github.com/llvm/llvm-project/pull/72234.
DW_TAG_member was the implicit default before.

The LLVM change is quite sinister since due to weakly typed ints and default params, this was still successfully compiling against LLVM but was passing the wrong parameters.
2023-11-16 03:14:51 +00:00
Mark Rousskov db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
Arthur Eubanks 7cde2cee35 llvm-wrapper: Pass newly added param to DIBuilder::createEnumerationType()
Added in LLVM in https://github.com/llvm/llvm-project/pull/72011.
2023-11-15 14:42:53 -08:00
Arthur Eubanks e2c3e94be9 17 -> 18 2023-11-15 13:15:55 -08:00
Arthur Eubanks 984898da17 [llvm-wrapper] Pass newly added param to DIBuilder::createStaticMemberType()
This was added in https://github.com/llvm/llvm-project/pull/72234.
DW_TAG_member was the implicit default before.
2023-11-15 11:29:35 -08:00
Matthias Krüger 03d6e7ade0
Rollup merge of #114224 - inferiorhumanorgans:solaris-llvm-wrapper, r=cuviper
rustc_llvm: Link to libkstat on Solaris/SPARC

getHostCPUName calls into libkstat but as of
LLVM 16.0.6 libLLVMTargetParser is not explicitly
linked against libkstat causing builds to fail
due to undefined symbols.

See also: llvm/llvm-project#64186
2023-11-13 21:28:54 +01:00
Josh Stone 855388e9a2
Mention LLVM 64186 in a comment 2023-11-13 11:04:53 -08:00
Hans Wennborg 752a6132e5 llvm-wrapper: Remove include of non-existant Vectorize.h 2023-11-07 16:40:35 +01:00
Matt Harding 4a8c5cbe7a Use the LLVM option NoTrapAfterNoreturn
Use the LLVM option NoTrapAfterNoreturn: https://llvm.org/doxygen/classllvm_1_1TargetOptions.html#acd83fce25de1ac9f6c975135a8235c22
when TrapUnreachable is enabled. This prevents codegenning unnecessary
double-traps in some situations.
Also, ensure NoTrapAfterNoreturn is set to false when targeting WebAssembly,
as it is known to cause bugs.
2023-11-03 02:36:49 +00:00
Nicholas Nethercote 8ff624a9f2 Clean up `rustc_*/Cargo.toml`.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Havard Eidnes 0f04e2dd8f For i586/NetBSD: fix another formatting insistence. 2023-10-27 09:37:25 +00:00
Havard Eidnes 391b472a37 rustc_llvm/build.rs: improve comment for NetBSD/i386 targets
...explaining why we need -latomic (gcc & g++ built for i486,
and LLVM insisting on use of 64-bit atomics).
2023-10-26 17:10:16 +00:00
Havard Eidnes 6642b4b1e2 Add support for i586-unknown-netbsd as target.
This restricts instructions to those offered by Pentium,
to support e.g. AMD Geode.

There is already an entry for this target in the NetBSD
platform support page at

  src/doc/rustc/src/platform-support/netbsd.md

...so this should forestall its removal.

Additional fixes are needed for some vendored modules, this
is the changes in the rust compiler core itself.
2023-10-25 15:23:34 +00:00
DianQK b592f29a8e
Treat extern in compiler-builtins as `used`
We have to preserve the symbols of the built-in functions during LTO.
2023-10-21 19:14:01 +08:00
DianQK a6f7596fb9
Add `PreservedSymbols` from LLVM to LTO.
When building with LTO, builtin functions that are defined but whose calls have not been inserted yet, get internalized.
We need to prevent these symbols from being internalized at LTO time.

Refer to https://reviews.llvm.org/D49434.
2023-10-16 18:17:04 +08:00
DianQK 6762d64063
Removes the useless DisableSimplifyLibCalls parameter.
After applying no_builtins to the function attributes, we can remove the
DisableSimplifyLibCalls parameter.
2023-10-15 21:12:05 +08:00
Michael Howell c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Emanuele Vannacci 5048f81313 fix to register analysis pass from llvm plugin 2023-10-06 12:04:28 +00:00
Nicholas Nethercote c3127d161a Remove unused features from `rustc_llvm`. 2023-10-03 15:54:44 +11:00
Florian Schmiderer 91544e6a93 Pass name of object file to LLVM so it can correctly emit S_OBJNAME 2023-09-25 19:31:58 +02:00
Krasimir Georgiev af401b0ca3 llvm-wrapper: adapt for LLVM API changes
No functional changes intended.

Adapts the wrapper for 0a1aa6cda2.

Found by our experimental rust + llvm @ head CI: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/22301#018a9926-a810-4e56-8ac2-e6f30b78f433/253-551
2023-09-15 14:31:43 +00:00
Matthias Krüger aa78b4c368
Rollup merge of #115358 - durin42:compress-debuginfo, r=oli-obk
debuginfo: add compiler option to allow compressed debuginfo sections

LLVM already supports emitting compressed debuginfo. In debuginfo=full builds, the debug section is often a large amount of data, and it typically compresses very well (3x is not unreasonable.) We add a new knob to allow debuginfo to be compressed when the matching LLVM functionality is present. Like clang, if a known-but-disabled compression mechanism is requested, we disable compression and emit uncompressed debuginfo sections.

The API is different enough on older LLVMs we just pretend the support
is missing on LLVM older than 16.
2023-09-09 00:28:19 +02:00
bors ffc48e3eda Auto merge of #115641 - durin42:llvm-18-fatlto-take-2, r=nikic
lto: load bitcode sections by name

Upstream change
llvm/llvm-project@6b539f5eb8 changed `isSectionBitcode` works and it now only respects `.llvm.lto` sections instead of also `.llvmbc`, which it says was never intended to be used for LTO. We instead load sections by name, and sniff for raw bitcode by hand.

This is an alternative approach to #115136, where we tried the same thing using the `object` crate, but it got too fraught to continue.

r? `@nikic`
`@rustbot` label: +llvm-main
2023-09-08 19:07:17 +00:00
Augie Fackler af9e55068c debuginfo: add compiler option to allow compressed debuginfo sections
LLVM already supports emitting compressed debuginfo. In debuginfo=full
builds, the debug section is often a large amount of data, and it
typically compresses very well (3x is not unreasonable.) We add a new
knob to allow debuginfo to be compressed when the matching LLVM
functionality is present. Like clang, if a known-but-disabled
compression mechanism is requested, we disable compression and emit
uncompressed debuginfo sections.

The API is different enough on older LLVMs we just pretend the support
is missing on LLVM older than 16.
2023-09-08 10:45:29 -04:00
Augie Fackler 942bdf910c lto: load bitcode sections by name
Upstream change
llvm/llvm-project@6b539f5eb8 changed
`isSectionBitcode` works and it now only respects `.llvm.lto` sections
instead of also `.llvmbc`, which it says was never intended to be used
for LTO. We instead load sections by name, and sniff for raw bitcode by
hand.

r? @nikic
@rustbot label: +llvm-main
2023-09-08 10:45:22 -04:00
Guillaume Gomez 575c3633f8
Rollup merge of #115638 - ldm0:ldm/llvm-args-fix, r=nikic
`-Cllvm-args` usability improvement

fixes: #26338
fixes: #115564

Two problems were found during playing with `-Cllvm-args`

1. When `llvm.link-shared` is set to `false` in `config.toml`, output of `rustc -C llvm-args='--help-list-hidden'` doesn't contain `--emit-dwarf-unwind` and `--emulated-tls`. When it is set to `true`, `rustc -C llvm-args='--help-list-hidden'` emits `--emit-dwarf-unwind`, but `--emulated-tls` is still missing.
2. Setting `-Cllvm-args=--emit-dwarf-unwind=always` doesn't take any effect, but `-Cllvm-args=-machine-outliner-reruns=3` does work.

### 1

Adding `RegisterCodeGenFlags` to register codegen flags fixed the first problem. `rustc -C llvm-args='--help-list-hidden'` emits full codegen flags including `--emit-dwarf-unwind` and `--emulated-tls`.

### 2

Constructing `TargetOptions` from `InitTargetOptionsFromCodeGenFlags` in `LLVMRustCreateTargetMachine` fixed the second problem. The `LLVMRustSetLLVMOptions` calls `ParseCommandLineOptions` which parses given `llvm-args`. For options like `machine-outliner-reruns`, it just works, since the codegen logic directly consumes the parsing result:

[machine-outliner-reruns register](0537f6354c/llvm/lib/CodeGen/MachineOutliner.cpp (L114))
[machine-outliner-reruns consumption](0537f6354c/llvm/lib/CodeGen/MachineOutliner.cpp (L1138))

But for flags defined in `TargetOptions` and `MCTargetOptions` to take effect, constructing them with `InitTargetOptionsFromCodeGenFlags` is essential, or the parsing result is just not consumed. Similar patterns can be observed in [lli](0537f6354c/llvm/tools/llc/llc.cpp (L494)), [llc](0537f6354c/llvm/tools/lli/lli.cpp (L517)), etc.
2023-09-08 14:10:52 +02:00
bors 9be4eac264 Auto merge of #113492 - nebulark:pr_96475, r=petrochenkov
Add CL and CMD into to pdb debug info

Partial fix for https://github.com/rust-lang/rust/issues/96475

The Arg0 and CommandLineArgs of the MCTargetOptions cpp class are not set within bb548f9645/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp (L378)

This causes LLVM to not  neither output any compiler path (cl) nor the arguments that were used when invoking it (cmd) in the PDB file.

This fix adds the missing information to the target machine so LLVM can use it.
2023-09-08 10:06:40 +00:00
Florian Schmiderer 4cdc633301 Add missing Debuginfo to PDB debug file on windows.
Set Arg0 and CommandLineArgs in MCTargetoptions so LLVM outputs correct CL and CMD in LF_DEBUGINFO instead of empty/invalid values.
2023-09-08 00:28:40 +02:00
Augie Fackler 6e5566cf03 lto: load bitcode sections by name
Upstream change
llvm/llvm-project@6b539f5eb8 changed
`isSectionBitcode` works and it now only respects `.llvm.lto` sections
instead of also `.llvmbc`, which it says was never intended to be used
for LTO. We instead load sections by name, and sniff for raw bitcode by
hand.

r? @nikic
@rustbot label: +llvm-main
2023-09-07 09:48:50 -04:00
Liu Dingming 487766cef0 Using parsed codegen flags 2023-09-07 17:37:12 +08:00
Liu Dingming bb6dcf5f74 Add `RegisterCodeGenFlags` to get full codegen flags list 2023-09-07 17:37:12 +08:00
bors e3abbd4994 Auto merge of #114946 - anforowicz:generic-fix-for-asan-lto, r=tmiasko
Preserve ASAN-related symbols during LTO.

Fixes https://github.com/rust-lang/rust/issues/113404
2023-09-06 20:04:03 +00:00
Krasimir Georgiev bdfa08a345 llvm-wrapper: adapt for LLVM API change
No functional changes intended.

Adapts the wrapper for bbe8cd1333.

Found by our experimental rust + llvm @ HEAD CI: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/22055#018a6495-8dd9-41df-9381-5e7b0009ce0a/274-575
2023-09-05 10:04:25 +00:00
Matthias Krüger 4e2231803b
Rollup merge of #114349 - inferiorhumanorgans:dragonfly-link-libz, r=cuviper
rustc_llvm: Link to `zlib` on dragonfly and solaris

On native builds `llvm-config` picks up `zlib` and this gets pased into
the rust build tools, but on cross builds `llvm-config` is explicitly
ignored as it contains information for the host system and cannot be
trusted to be accurate for the target system.

Both DragonFly and Solaris contain `zlib` in the base system, so this is
both a safe assumption and required for a successful cross build unless
`zlib` support is disabled in LLVM.

This is more or less in the same vein as rust-lang#75713 and rust-lang#75655.
2023-09-02 07:48:21 +02:00
Lukasz Anforowicz e6dddbda35 Preserve `___asan_globals_registered` symbol during LTO.
Fixes https://github.com/rust-lang/rust/issues/113404
2023-08-29 19:02:33 +00:00
bors d1fb1755aa Auto merge of #115079 - cuviper:unused-mcinfo, r=Mark-Simulacrum
Move a local to the `#if` block where it is used

For other cases (LLVM < 17), this was complaining under `-Wall`:

```
warning: llvm-wrapper/PassWrapper.cpp: In function ‘void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef, const char*)’:
warning: llvm-wrapper/PassWrapper.cpp:311:26: warning: unused variable ‘MCInfo’ [-Wunused-variable]
warning:   311 |   const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
warning:       |                          ^~~~~~
```
2023-08-27 10:32:24 +00:00
Augie Fackler 3977ed1e69 ArchiveWrapper: handle LLVM API update
In llvm/llvm-project@f740bcb370 a boolean
parameter changed to an enum.

r? @nikic
@rustbot label: +llvm-main
2023-08-22 12:26:35 -04:00
Josh Stone ef0651972f Move a local to the `#if` block where it is used
For other cases (LLVM < 17), this was complaining under `-Wall`:

```
warning: llvm-wrapper/PassWrapper.cpp: In function ‘void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef, const char*)’:
warning: llvm-wrapper/PassWrapper.cpp:311:26: warning: unused variable ‘MCInfo’ [-Wunused-variable]
warning:   311 |   const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
warning:       |                          ^~~~~~
```
2023-08-21 15:27:08 -07:00
Dirreke d16409fe22 add a csky-unknown-linux-gnuabiv2 target 2023-08-14 23:02:36 +08:00
bors a9b2c6a0ce Auto merge of #114005 - Zalathar:no-cstr, r=jackh726
coverage: Don't convert filename/symbol strings to `CString` for FFI

LLVM APIs are usually perfectly happy to accept pointer/length strings, as long as we supply a suitable length value when creating a `StringRef` or `std::string`.

This lets us avoid quite a few intermediate `CString` copies during coverage codegen. It also lets us use an `IndexSet<Symbol>` (instead of an `IndexSet<CString>`) when building the deduplicated filename table.
2023-08-10 23:06:10 +00:00
Matthias Krüger 54a9c2cb2a
Rollup merge of #114612 - lqd:east-17-warning, r=nikic
update llvm-wrapper include to silence deprecation warning

Includes of `include/llvm/Support/Host.h` now emit a deprecated warning: `warning: This header is deprecated, please use llvm/TargetParser/Host.h`.

I don't believe we are using this include.

I don't believe we need to bump the `download-ci-llvm` stamp since these warnings are emitted while building the `llvm-wrapper`.

r? ```@nikic```
2023-08-08 21:44:44 +02:00
Matthias Krüger c097e48082
Rollup merge of #113593 - rcvalle:rust-cfi-fix-90546, r=wesleywiser
CFI: Fix error compiling core with LLVM CFI enabled

Fix #90546 by filtering out global value function pointer types from the type tests, and adding the LowerTypeTests pass to the rustc LTO optimization pipelines.
2023-08-08 21:44:43 +02:00
bors f525bb4e2a Auto merge of #114439 - Kobzol:remark-pgo-hotness, r=tmiasko
Add hotness data to LLVM remarks

Slight improvement of https://github.com/rust-lang/rust/pull/113040. This makes sure that if PGO is used, remarks generated using `-Zremark-dir` will include the `Hotness` attribute.

r? `@tmiasko`
2023-08-08 15:41:44 +00:00
Jakub Beránek 9d417d7c86
Only enable hotness information when PGO is available 2023-08-08 15:36:55 +02:00
Rémy Rakic bcf7bfc9f4 remove llvm-wrapper include to silence deprecation warning
Includes of `include/llvm/Support/Host.h` now emit a deprecated warning:
`warning: This header is deprecated, please use llvm/TargetParser/Host.h`.
2023-08-08 10:48:20 +00:00
Alex Zepeda 6ef7813cf0 rustc_llvm: Link `zlib` on cross Solaris builds
On native builds `llvm-config` picks up `zlib` and this gets pased into
the rust build tools, but on cross builds `llvm-config` is explicitly
ignored as it contains information for the host system and cannot be
trusted to be accurate for the target system.

Both DragonFly and Solaris contain `zlib` in the base system, so this is
both a safe assumption and required for a successful cross build unless
`zlib` support is disabled in LLVM.

This is more or less in the same vein as #75713 and #75655.
2023-08-07 17:19:30 -07:00
Ramon de C Valle f837c48f0d CFI: Fix error compiling core with LLVM CFI enabled
Fix #90546 by filtering out global value function pointer types from the
type tests, and adding the LowerTypeTests pass to the rustc LTO
optimization pipelines.
2023-08-07 15:59:15 -07:00
Nikita Popov 7867833652 Fix LLVM version check for ThinLTO import/export lists
These types changed in LLVM 18, not LLVM 17.
2023-08-07 20:36:14 +02:00
Nikita Popov 055dd282c5 Remove no longer needed LLVM_RUSTLLVM check
The bundled version now uses the LLVM 17 code path.
2023-08-07 20:35:55 +02:00
Krasimir Georgiev 9941db4512 llvm-wrapper: adapt for LLVM API changes
No functional changes intended.

Adapts llvm-wrapper for 65e57bbed0.

Found by our experimental rust + llvm @ HEAD CI:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/21304#0189c526-86cd-4db9-bdbc-dd0132dfc22b/197-500
2023-08-05 10:54:30 +00:00
Jakub Beránek 93bdc01adf
Add hotness data to LLVM remarks
This makes sure that if PGO is used, remarks generated using `-Zremark-dir` will include the `Hotness` attribute.
2023-08-04 10:31:00 +02:00
Zalathar 4b154bc8e2 coverage: Don't convert symbol names to `CString` for FFI 2023-08-04 10:48:05 +10:00
Zalathar e184118683 coverage: Don't convert filenames to `CString` for FFI 2023-08-04 10:48:05 +10:00
bors f77c624c03 Auto merge of #113339 - lqd:respect-filters, r=tmiasko
Filter out short-lived LLVM diagnostics before they reach the rustc handler

During profiling I saw remark passes being unconditionally enabled: for example `Machine Optimization Remark Emitter`.

The diagnostic remarks enabled by default are [from missed optimizations and opt analyses](https://github.com/rust-lang/rust/pull/113339#discussion_r1259480303). They are created by LLVM, passed to the diagnostic handler on the C++ side, emitted to rust, where they are unpacked, C++ strings are converted to rust, etc.

Then they are discarded in the vast majority of the time (i.e. unless some kind of `-Cremark` has enabled some of these passes' output to be printed).

These unneeded allocations are very short-lived, basically only lasting between the LLVM pass emitting them and the rust handler where they are discarded. So it doesn't hugely impact max-rss, and is only a slight reduction in instruction count (cachegrind reports a reduction between 0.3% and 0.5%) _on linux_. It's possible that targets without `jemalloc` or with a worse allocator, may optimize these less.

It is however significant in the aggregate, looking at the total number of allocated bytes:
- it's the biggest source of allocations according to dhat, on the benchmarks I've tried e.g. `syn` or `cargo`
- allocations on `syn` are reduced by 440MB, 17% (from 2440722647 bytes total, to 2030461328 bytes)
- allocations on `cargo` are reduced by 6.6GB, 19% (from 35371886402 bytes total, to 28723987743 bytes)

Some of these diagnostics objects [are allocated in LLVM](https://github.com/rust-lang/rust/pull/113339#discussion_r1252387484) *before* they're emitted to our diagnostic handler, where they'll be filtered out. So we could remove those in the future, but that will require changing a few LLVM call-sites upstream, so I left a FIXME.
2023-08-01 23:15:20 +00:00
Alex Zepeda 14dd4e97a8 rustc_llvm: Link to `zlib` on dragonfly 2023-08-01 15:54:30 -07:00
Rémy Rakic 77d01103a3 filter LLVM diagnostics before crossing the rust bridge
this will eliminate many short-lived allocations (e.g. 20% of the memory used
building cargo) when unpacking the diagnostic and converting its various
C++ strings into rust strings, just to be filtered out most of the time.
2023-08-01 21:01:20 +00:00
Alex Zepeda 103b2df63b rustc_llvm: Link to libkstat on Solaris/SPARC
getHostCPUName calls into libkstat but as of
LLVM 16.0.6 libLLVMTargetParser is not explicitly
linked against libkstat causing builds to fail
due to undefined symbols.

See also: llvm/llvm-project#64186
2023-07-29 14:37:46 -07:00
Josh Stone 190ded8443 Update the minimum external LLVM to 15 2023-07-27 14:07:08 -07:00
Miguel Ojeda 74b8d324eb Support `.comment` section like GCC/Clang (`!llvm.ident`)
Both GCC and Clang write by default a `.comment` section with compiler
information:

```txt
$ gcc -c -xc /dev/null && readelf -p '.comment' null.o

String dump of section '.comment':
  [     1]  GCC: (GNU) 11.2.0

$ clang -c -xc /dev/null && readelf -p '.comment' null.o

String dump of section '.comment':
  [     1]  clang version 14.0.1 (https://github.com/llvm/llvm-project.git c62053979489ccb002efe411c3af059addcb5d7d)
```

They also implement the `-Qn` flag to avoid doing so:

```txt
$ gcc -Qn -c -xc /dev/null && readelf -p '.comment' null.o
readelf: Warning: Section '.comment' was not dumped because it does not exist!

$ clang -Qn -c -xc /dev/null && readelf -p '.comment' null.o
readelf: Warning: Section '.comment' was not dumped because it does not exist!
```

So far, `rustc` only does it for WebAssembly targets and only
when debug info is enabled:

```txt
$ echo 'fn main(){}' | rustc --target=wasm32-unknown-unknown --emit=llvm-ir -Cdebuginfo=2 - && grep llvm.ident rust_out.ll
!llvm.ident = !{!27}
```

In the RFC part of this PR it was decided to always add
the information, which gets us closer to other popular compilers.
An opt-out flag like GCC and Clang may be added later on if deemed
necessary.

Implementation-wise, this covers both `ModuleLlvm::new()` and
`ModuleLlvm::new_metadata()` cases by moving the addition to
`context::create_module` and adds a few test cases.

ThinLTO also sees the `llvm.ident` named metadata duplicated (in
temporary outputs), so this deduplicates it like it is done for
`wasm.custom_sections`. The tests also check this duplication does
not take place.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-07-21 22:01:50 +02:00
Matthias Krüger b1d1e99c22
Rollup merge of #113780 - dtolnay:printkindpath, r=b-naber
Support `--print KIND=PATH` command line syntax

As is already done for `--emit KIND=PATH` and `-L KIND=PATH`.

In the discussion of #110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o` path to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`.

I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](d43cf3a51a/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system.

From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse". 31eda6f7c3/src/cargo/core/compiler/build_context/target_info.rs (L242) (FYI `@weihanglo` as you dealt with this recently in https://github.com/rust-lang/cargo/pull/11633.)

Mentioning reviewers active in #110785: `@fee1-dead` `@jyn514` `@bjorn3`
2023-07-21 06:52:28 +02:00
Matthias Krüger 2734b5ada9
Rollup merge of #113723 - khei4:khei4/llvm-stats, r=oli-obk,nikic
Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics.

This resurrects PR https://github.com/rust-lang/rust/pull/104000, which has sat idle for a while. And I want to see the effect of stack-move optimizations on LLVM (like https://reviews.llvm.org/D153453) :).

I have applied the changes requested by `@oli-obk` and `@nagisa`  https://github.com/rust-lang/rust/pull/104000#discussion_r1014625377 and https://github.com/rust-lang/rust/pull/104000#discussion_r1014642482 in the latest commits.

r? `@oli-obk`

-----

LLVM has a neat [statistics](https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option) feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too.

-----
(Edit: fix broken link
(Edit2: fix segmentation fault and use malloc

If `rustc` is built with
```toml
[llvm]
assertions = true
```
Then you can see like
```
rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
         3 aa                           - Number of MayAlias results
       193 aa                           - Number of MustAlias results
       531 aa                           - Number of NoAlias results
...
```

And the current default build emits only
```
$ rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
$
```
This might be better to emit the message to tell assertion flag necessity, but now I can't find how to do that...
2023-07-21 06:52:27 +02:00
David Tolnay 815a114974
Implement printing to file in PassWrapper 2023-07-20 11:04:31 -07:00
khei4 c7bf20dfdc address feedback from nikic and oli-obk https://github.com/rust-lang/rust/pull/113723/files
use slice memcpy rather than strcpy and write it on stdout

use println on failure

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2023-07-20 16:53:06 +09:00
bors c4e6fe9240 Auto merge of #113714 - Kobzol:ci-cmake, r=nikic
CI: build CMake 3.20 to support LLVM 17

LLVM 17 will require CMake at least 3.20, so we have to go back to building our own CMake on the Linux x64 dist builder.

r? `@nikic`
2023-07-17 15:46:43 +00:00
Jakub Beránek e95caa7b72 Link to `execinfo` on NetBSD 2023-07-17 08:30:54 +02:00