about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper
AgeCommit message (Collapse)AuthorLines
2022-01-24Use error-on-mismatch policy for PAuth module flags.Jacob Bramley-3/+6
This agrees with Clang, and avoids an error when using LTO with mixed C/Rust. LLVM considers different behaviour flags to be a mismatch, even when the flag value itself is the same. This also makes the flag setting explicit for all uses of LLVMRustAddModuleFlag.
2022-01-14Remove LLVMRustMarkAllFunctionsNounwindAmanieu d'Antras-19/+0
This was originally introduced in #10916 as a way to remove all landing pads when performing LTO. However this is no longer necessary today since rustc properly marks all functions and call-sites as nounwind where appropriate. In fact this is incorrect in the presence of `extern "C-unwind"` which must create a landing pad when compiled with `-C panic=abort` so that foreign exceptions are caught and properly turned into aborts.
2022-01-06Rollup merge of #92559 - durin42:llvm-14-attributemask, r=nikicMatthias Krüger-5/+3
RustWrapper: adapt to new AttributeMask API Upstream LLVM change 9290ccc3c1a1 migrated attribute removal to use AttributeMask instead of AttrBuilder, so we need to follow suit here. r? ``@nagisa`` cc ``@nikic``
2022-01-05RustWrapper: simplify removing attributesAugie Fackler-7/+3
Avoids some extra conversions. Spotted by nikic during review.
2022-01-04RustWrapper: adapt to new AttributeMask APIAugie Fackler-2/+4
Upstream LLVM change 9290ccc3c1a1 migrated attribute removal to use AttributeMask instead of AttrBuilder, so we need to follow suit here.
2022-01-03RustWrapper: adapt for an LLVM API changeKrasimir Georgiev-4/+4
No functional changes intended. The LLVM commit https://github.com/llvm/llvm-project/commit/ec501f15a8b8ace2b283732740d6d65d40d82e09 removed the signed version of `createExpression`. This adapts the Rust LLVM wrappers accordingly.
2022-01-01Auto merge of #92419 - erikdesjardins:coldland, r=nagisabors-0/+8
Mark drop calls in landing pads `cold` instead of `noinline` Now that deferred inlining has been disabled in LLVM (#92110), this shouldn't cause catastrophic size blowup. I confirmed that the test cases from https://github.com/rust-lang/rust/issues/41696#issuecomment-298696944 still compile quickly (<1s) after this change. ~Although note that I wasn't able to reproduce the original issue using a recent rustc/llvm with deferred inlining enabled, so those tests may no longer be representative. I was also unable to create a modified test case that reproduced the original issue.~ (edit: I reproduced it on CI by accident--the first commit timed out on the LLVM 12 builder, because I forgot to make it conditional on LLVM version) r? `@nagisa` cc `@arielb1` (this effectively reverts #42771 "mark calls in the unwind path as !noinline") cc `@RalfJung` (fixes #46515) edit: also fixes #87055
2021-12-30keep noinline for system llvm < 14Erik Desjardins-0/+8
2021-12-13Use the existing llvm-plugins option for both legacy and new pm registrationAxel Cohen-4/+4
2021-12-13Add a codegen option to allow loading LLVM pass pluginsAxel Cohen-1/+17
2021-12-03LLVM codgen support for unwinding inline assemblycynecx-0/+8
2021-12-03Adjust llvm wrapper for unwinding support for inlineasmcynecx-2/+3
2021-12-01Rollup merge of #91207 - richkadel:rk-bump-coverage-version, r=tmandryMatthias Krüger-2/+7
Add support for LLVM coverage mapping format versions 5 and 6 This PR cherry-pick's Swatinem's initial commit in unsubmitted PR #90047. My additional commit augments Swatinem's great starting point, but adds full support for LLVM Coverage Mapping Format version 6, conditionally, if compiling with LLVM 13. Version 6 requires adding the compilation directory when file paths are relative, and since Rustc coverage maps use relative paths, we should add the expected compilation directory entry. Note, however, that with the compilation directory, coverage reports from `llvm-cov show` can now report file names (when the report includes more than one file) with the full absolute path to the file. This would be a problem for test results, but the workaround (for the rust coverage tests) is to include an additional `llvm-cov show` parameter: `--compilation-dir=.`
2021-11-28Rollup merge of #90833 - tmiasko:optimization-remarks, r=nikicMatthias Krüger-0/+93
Emit LLVM optimization remarks when enabled with `-Cremark` The default diagnostic handler considers all remarks to be disabled by default unless configured otherwise through LLVM internal flags: `-pass-remarks`, `-pass-remarks-missed`, and `-pass-remarks-analysis`. This behaviour makes `-Cremark` ineffective on its own. Fix this by configuring a custom diagnostic handler that enables optimization remarks based on the value of `-Cremark` option. With `-Cremark=all` enabling all remarks. Fixes #90924. r? `@nikic`
2021-11-23Update CoverageMappingFormat Support to Version6Arpad Borsos-2/+7
Version 5 adds Branch Regions which are a prerequisite for branch coverage. Version 6 can use the zeroth filename as prefix for other relative files.
2021-11-22add rustc option for using LLVM stack smash protectionBenjamin A. Bjørnseth-0/+9
LLVM has built-in heuristics for adding stack canaries to functions. These heuristics can be selected with LLVM function attributes. This patch adds a rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use of these attributes. This gives rustc the same stack smash protection support as clang offers through options `-fno-stack-protector`, `-fstack-protector`, `-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the current list of rustc exploit mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html), originally discussed in #15179. Stack smash protection adds runtime overhead and is therefore still off by default, but now users have the option to trade performance for security as they see fit. An example use case is adding Rust code in an existing C/C++ code base compiled with stack smash protection. Without the ability to add stack smash protection to the Rust code, the code base artifacts could be exploitable in ways not possible if the code base remained pure C/C++. Stack smash protection support is present in LLVM for almost all the current tier 1/tier 2 targets: see test/assembly/stack-protector/stack-protector-target-support.rs. The one exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a warning message printed if stack smash protection is used with this target (see test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3 targets has not been checked. Since the heuristics are applied at the LLVM level, the heuristics are expected to add stack smash protection to a fraction of functions comparable to C/C++. Some experiments demonstrating how Rust code is affected by the different heuristics can be found in test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is potential for better heuristics using Rust-specific safety information. For example it might be reasonable to skip stack smash protection in functions which transitively only use safe Rust code, or which uses only a subset of functions the user declares safe (such as anything under `std.*`). Such alternative heuristics could be added at a later point. LLVM also offers a "safestack" sanitizer as an alternative way to guard against stack smashing (see #26612). This could possibly also be included as a stack-protection heuristic. An alternative is to add it as a sanitizer (#39699). This is what clang does: safestack is exposed with option `-fsanitize=safe-stack`. The options are only supported by the LLVM backend, but as with other codegen options it is visible in the main codegen option help menu. The heuristic names "basic", "strong", and "all" are hopefully sufficiently generic to be usable in other backends as well. Reviewed-by: Nikita Popov <nikic@php.net> Extra commits during review: - [address-review] make the stack-protector option unstable - [address-review] reduce detail level of stack-protector option help text - [address-review] correct grammar in comment - [address-review] use compiler flag to avoid merging functions in test - [address-review] specify min LLVM version in fortanix stack-protector test Only for Fortanix test, since this target specifically requests the `--x86-experimental-lvi-inline-asm-hardening` flag. - [address-review] specify required LLVM components in stack-protector tests - move stack protector option enum closer to other similar option enums - rustc_interface/tests: sort debug option list in tracking hash test - add an explicit `none` stack-protector option Revert "set LLVM requirements for all stack protector support test revisions" This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-11-19Make `LLVMRustGetOrInsertGlobal` always return a `GlobalVariable`Josh Stone-1/+11
`Module::getOrInsertGlobal` returns a `Constant*`, which is a super class of `GlobalVariable`, but if the given type doesn't match an existing declaration, it returns a bitcast of that global instead. This causes UB when we pass that to `LLVMGetVisibility` which unconditionally casts the opaque argument to a `GlobalValue*`. Instead, we can do our own get-or-insert without worrying whether existing types match exactly. It's not relevant when we're just trying to get/set the linkage and visibility, and if types are needed we can bitcast or error nicely from `rustc_codegen_llvm` instead.
2021-11-16Recognize machine optimization remarksTomasz Miąsko-0/+3
2021-11-16Emit LLVM optimization remarks when enabled with `-Cremark`Tomasz Miąsko-0/+90
The default diagnostic handler considers all remarks to be disabled by default unless configured otherwise through LLVM internal flags: `-pass-remarks`, `-pass-remarks-missed`, and `-pass-remarks-analysis`. This behaviour makes `-Cremark` ineffective on its own. Fix this by configuring a custom diagnostic handler that enables optimization remarks based on the value of `-Cremark` option. With `-Cremark=all` enabling all remarks.
2021-11-11PassWrapper: additional sanitizer update to match clangKrasimir Georgiev-1/+0
This happened later in the stream than the other changes, but the fix is overlapping. Fix taken from a55c4ec1cee7683d9095327d9d33e7137ec25292 in LLVM.
2021-11-09Didn't mean to invert this boolean.Augie Fackler-1/+1
2021-11-09rustc_llvm: update PassWrapper for recent LLVMAugie Fackler-6/+9
Now AddressSanitizerOptions is a struct, but at least the change was tiny. r? nikic
2021-11-05Initialize LLVM time trace profiler on each code generation threadTomasz Miąsko-0/+4
In https://reviews.llvm.org/D71059 LLVM 11, the time trace profiler was extended to support multiple threads. `timeTraceProfilerInitialize` creates a thread local profiler instance. When a thread finishes `timeTraceProfilerFinishThread` moves a thread local instance into a global collection of instances. Finally when all codegen work is complete `timeTraceProfilerWrite` writes data from the current thread local instance and the instances in global collection of instances. Previously, the profiler was intialized on a single thread only. Since this thread performs no code generation on its own, the resulting profile was empty. Update LLVM codegen to initialize & finish time trace profiler on each code generation thread.
2021-10-25Rollup merge of #89581 - jblazquez:master, r=Mark-SimulacrumMatthias Krüger-0/+2
Add -Z no-unique-section-names to reduce ELF header bloat. This change adds a new compiler flag that can help reduce the size of ELF binaries that contain many functions. By default, when enabling function sections (which is the default for most targets), the LLVM backend will generate different section names for each function. For example, a function `func` would generate a section called `.text.func`. Normally this is fine because the linker will merge all those sections into a single one in the binary. However, starting with [LLVM 12](https://github.com/llvm/llvm-project/commit/ee5d1a04), the backend will also generate unique section names for exception handling, resulting in thousands of `.gcc_except_table.*` sections ending up in the final binary because some linkers like LLD don't currently merge or strip these EH sections (see discussion [here](https://reviews.llvm.org/D83655)). This can bloat the ELF headers and string table significantly in binaries that contain many functions. The new option is analogous to Clang's `-fno-unique-section-names`, and instructs LLVM to generate the same `.text` and `.gcc_except_table` section for each function, resulting in a smaller final binary. The motivation to add this new option was because we have a binary that ended up with so many ELF sections (over 65,000) that it broke some existing ELF tools, which couldn't handle so many sections. Here's our old binary: ``` $ readelf --sections old.elf | head -1 There are 71746 section headers, starting at offset 0x2a246508: $ readelf --sections old.elf | grep shstrtab [71742] .shstrtab STRTAB 0000000000000000 2977204c ad44bb 00 0 0 1 ``` That's an 11MB+ string table. Here's the new binary using this option: ``` $ readelf --sections new.elf | head -1 There are 43 section headers, starting at offset 0x29143ca8: $ readelf --sections new.elf | grep shstrtab [40] .shstrtab STRTAB 0000000000000000 29143acc 0001db 00 0 0 1 ``` The whole binary size went down by over 20MB, which is quite significant.
2021-10-22Update the minimum external LLVM to 12Josh Stone-98/+2
2021-10-22Update the minimum external LLVM to 11Josh Stone-114/+0
2021-10-18RustWrapper: adapt for an LLVM API changeKrasimir Georgiev-1/+5
No functional changes intended. The LLVM commit https://github.com/llvm/llvm-project/commit/89b57061f7b769e9ea9bf6ed686e284f3e55affe moved TargetRegistry.(h|cpp) from Support to MC. This adapts RustWrapper accordingly.
2021-10-11Add -Z no-unique-section-names to reduce ELF header bloat.Javier Blazquez-0/+2
This change adds a new compiler flag that can help reduce the size of ELF binaries that contain many functions. By default, when enabling function sections (which is the default for most targets), the LLVM backend will generate different section names for each function. For example, a function "func" would generate a section called ".text.func". Normally this is fine because the linker will merge all those sections into a single one in the binary. However, starting with LLVM 12 (llvm/llvm-project@ee5d1a0), the backend will also generate unique section names for exception handling, resulting in thousands of ".gcc_except_table.*" sections ending up in the final binary because some linkers don't currently merge or strip these EH sections. This can bloat the ELF headers and string table significantly in binaries that contain many functions. The new option is analogous to Clang's -fno-unique-section-names, and instructs LLVM to generate the same ".text" and ".gcc_except_table" section for each function, resulting in smaller object files and potentially a smaller final binary.
2021-10-07Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoeristerJubilee-4/+7
Implement `#[link_ordinal(n)]` Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name. As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL. Part of #58713.
2021-10-07Rollup merge of #87918 - mikebenfield:pr-afdo, r=nikicJubilee-9/+21
Enable AutoFDO. This largely involves implementing the options debug-info-for-profiling and profile-sample-use and forwarding them on to LLVM. AutoFDO can be used on x86-64 Linux like this: rustc -O -Clink-arg='Wl,--no-rosegment' -Cdebug-info-for-profiling main.rs -o main perf record -b ./main create_llvm_prof --binary=main --out=code.prof rustc -O -Cprofile-sample-use=code.prof main.rs -o main2 Now `main2` will have feedback directed optimization applied to it. The create_llvm_prof tool can be obtained from this github repository: https://github.com/google/autofdo The option -Clink-arg='Wl,--no-rosegment' is necessary to avoid lld putting an extra RO segment before the executable code, which would make the binary silently incompatible with create_llvm_prof.
2021-10-06Enable AutoFDO.Michael Benfield-9/+21
This largely involves implementing the options debug-info-for-profiling and profile-sample-use and forwarding them on to LLVM. AutoFDO can be used on x86-64 Linux like this: rustc -O -Cdebug-info-for-profiling main.rs -o main perf record -b ./main create_llvm_prof --binary=main --out=code.prof rustc -O -Cprofile-sample-use=code.prof main.rs -o main2 Now `main2` will have feedback directed optimization applied to it. The create_llvm_prof tool can be obtained from this github repository: https://github.com/google/autofdo Fixes #64892.
2021-10-05RustWrapper: adapt for LLVM API change of fatal_error_handler_tKrasimir Georgiev-0/+4
No functional changes intended. The LLVM commit https://github.com/llvm/llvm-project/commit/e463b69736da8b0a950ecd937cf990401bdfcdeb changed an argument of fatal_error_handler_t from std::string to char*. This adapts RustWrapper accordingly.
2021-09-27PassWrapper: handle function rename from upstream D36850Augie Fackler-0/+4
thinLTOResolvePrevailingInModule became thinLTOFinalizeInModule and gained the ability to propagate noRecurse and noUnwind function attributes. I ran codegen tests with it both on and off, as the upstream patch uses it in both modes, and the tests pass both ways. Given that, it seemed reasonable to go ahead and let the propagation be enabled in rustc, and see what happens. See https://reviews.llvm.org/D36850 for more examples of how the new version of the function gets used.
2021-09-25Use correct pipeline for LTO at O0Nikita Popov-1/+4
Unlike the pre-link piplines, the LTO pipelines do support O0, and using them is required to avoid leaving behind undefined references for the linker.
2021-09-22Rollup merge of #89041 - sticnarf:sticnarf/fat-lto-dwarf, r=nagisathe8472-2/+2
Work around invalid DWARF bugs for fat LTO This PR applies the same workaround in #46772 to fat LTO. It seems to fix the bug reported in https://github.com/rust-lang/rust/issues/66118#issuecomment-917434036.
2021-09-20Implement #[link_ordinal] attribute in the context of #[link(kind = ↵Richard Cobbe-4/+7
"raw-dylib")].
2021-09-17Work around invalid DWARF bugs for fat LTOYilin Chen-2/+2
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-09-17compiler/rustc_llvm: Enable M68k LLVM targetJohn Paul Adrian Glaubitz-0/+7
2021-09-16PassWrapper: these two lines shouldn't have been ifdef'dAugie Fackler-2/+2
2021-09-16PassWrapper: handle separate Module*SanitizerPassAugie Fackler-0/+8
Change ab41eef9aca3 in LLVM split MemorySanitizerPass into MemorySanitizerPass for functions and ModuleMemorySanitizerPass for modules. There's a related change for ThreadSanitizerPass, and in here since we're using a ModulePassManager I only add the module flavor of the pass on LLVM 14. r? @nikic cc @nagisa
2021-09-08RustWrapper: remove some uses of AttrBuilderAugie Fackler-19/+6
Turns out we can also use Attribute::get*() methods here, and avoid the AttrBuilder and an extra helper method here.
2021-09-07RustWrapper: just use the *AtIndex funcs directlyAugie Fackler-36/+3
Otherwise we're kind of reimplementing the inverse of the well-named methods, and that's not a direction we want to go.
2021-09-07RustWrapper: avoid deleted unclear attribute methodsAugie Fackler-18/+70
These were deleted in https://reviews.llvm.org/D108614, and in C++ I definitely see the argument for their removal. I didn't try and propagate the changes up into higher layers of rustc in this change because my initial goal was to get rustc working against LLVM HEAD promptly, but I'm happy to follow up with some refactoring to make the API on the Rust side match the LLVM API more directly (though the way the enum works in Rust makes the API less scary IMO). r? @nagisa cc @nikic
2021-08-26RustWrapper: adapt to LLVM change 0f45c16f2caaAugie Fackler-14/+9
The above-mentioned commit (part of the LLVM 14 development cycle) removes a method that rustc uses somewhat extensively. We mostly switch to lower-level methods that exist in all versions of LLVM we use, so no new ifdef logic is required in most cases.
2021-08-22Rollup merge of #88164 - durin42:llvm-14-san-opts, r=nikicGuillaume Gomez-0/+15
PassWrapper: adapt for LLVM 14 changes These API changes appear to have all taken place in https://reviews.llvm.org/D105007, which moved HWAddressSanitizerPass and AddressSanitizerPass to only accept their options type as a ctor argument instead of the sequence of bools etc. This required a couple of parameter additions, which I made match the default prior to the mentioned upstream LLVM change. This patch restores rustc to building (though not quite passing all tests, I've mailed other patches for those issues) against LLVM HEAD.
2021-08-19PassWrapper: adapt for LLVM 14 changesAugie Fackler-0/+15
These API changes appear to have all taken place in https://reviews.llvm.org/D105007, which moved HWAddressSanitizerPass and AddressSanitizerPass to only accept their options type as a ctor argument instead of the sequence of bools etc. This required a couple of parameter additions, which I made match the default prior to the mentioned upstream LLVM change. This patch restores rustc to building (though not quite passing all tests, I've mailed other patches for those issues) against LLVM HEAD.
2021-08-16Handle SrcMgr diagnosticsNikita Popov-3/+17
This is how InlineAsm diagnostics with source information are reported now. Previously a separate InlineAsm diagnostic handler was used.
2021-08-08Auto merge of #87798 - durin42:llvm-14, r=nikicbors-27/+31
PassWrapper: handle move of OptimizationLevel class out of PassBuilder This is the first build break of the LLVM 14 cycle, and was caused by https://reviews.llvm.org/D107025. Mercifully an easy fix.
2021-08-06PassWrapper: handle move of OptimizationLevel class out of PassBuilderAugie Fackler-27/+31
This is the first build break of the LLVM 14 cycle, and was caused by https://reviews.llvm.org/D107025. Mercifully an easy fix.
2021-08-05Prepare call/invoke for opaque pointersJosh Stone-7/+7
Rather than relying on `getPointerElementType()` from LLVM function pointers, we now pass the function type explicitly when building `call` or `invoke` instructions.