about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/consts.rs
AgeCommit message (Collapse)AuthorLines
2025-03-09Rollup merge of #122790 - Zoxc:dllimp-rev, r=ChrisDentonMatthias Krüger-6/+5
Apply dllimport in ThinLTO This partially reverts https://github.com/rust-lang/rust/pull/103353 by properly applying `dllimport` if `-Z dylib-lto` is passed. That PR should probably fully be reverted as it looks quite sketchy. We don't know locally if the entire crate graph would be statically linked. This should hopefully be sufficient to make ThinLTO work for rustc on Windows. r? ``@wesleywiser`` --- Edit: This PR is changed to just generally revert https://github.com/rust-lang/rust/pull/103353.
2025-03-03Apply dllimport in ThinLTOJohn Kåre Alsaker-6/+5
2025-02-24Use a safe wrapper around an LLVM FFI functionOli Scherer-1/+1
2025-02-20Merge two operations that were always performed togetherOli Scherer-9/+2
2025-02-20Create safe helper for LLVMSetDLLStorageClassOli Scherer-6/+2
2025-02-11Document some safety constraints and use more safe wrappersOli Scherer-3/+3
2025-02-02Rollup merge of #136426 - oli-obk:push-nkpuulwurykn, r=compiler-errorsMatthias Krüger-2/+8
Explain why we retroactively change a static initializer to have a different type I keep getting confused about it and in turn confused `@GuillaumeGomez` while trying to explain it badly
2025-02-01Explain why we retroactively change a static initializer to have a different ↵Oli Scherer-2/+8
type
2025-01-24Add comments about address spacesFlakebi-0/+13
2025-01-02Cast global variables to default address spaceFlakebi-17/+31
Pointers for variables all need to be in the same address space for correct compilation. Therefore ensure that even if a global variable is created in a different address space, it is casted to the default address space before its value is used. This is necessary for the amdgpu target and others where the default address space for global variables is not 0. For example `core` does not compile in debug mode when not casting the address space to the default one because it tries to emit the following (simplified) LLVM IR, containing a type mismatch: ```llvm @alloc_0 = addrspace(1) constant <{ [6 x i8] }> <{ [6 x i8] c"bit.rs" }>, align 1 @alloc_1 = addrspace(1) constant <{ ptr }> <{ ptr addrspace(1) @alloc_0 }>, align 8 ; ^ here a struct containing a `ptr` is needed, but it is created using a `ptr addrspace(1)` ``` For this to compile, we need to insert a constant `addrspacecast` before we use a global variable: ```llvm @alloc_0 = addrspace(1) constant <{ [6 x i8] }> <{ [6 x i8] c"bit.rs" }>, align 1 @alloc_1 = addrspace(1) constant <{ ptr }> <{ ptr addrspacecast (ptr addrspace(1) @alloc_0 to ptr) }>, align 8 ``` As vtables are global variables as well, they are also created with an `addrspacecast`. In the SSA backend, after a vtable global is created, metadata is added to it. To add metadata, we need the non-casted global variable. Therefore we strip away an addrspacecast if there is one, to get the underlying global.
2024-11-23Rollup merge of #127483 - BertalanD:no_sanitize-global-var, r=rcvalle许杰友 Jieyou Xu (Joe)-0/+2
Allow disabling ASan instrumentation for globals AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them. This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions. (cc https://github.com/rust-lang/rust/issues/39699)
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-3/+3
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-07Rollup merge of #130586 - dpaoliello:fixrawdylib, r=wesleywiserJubilee-8/+2
Set "symbol name" in raw-dylib import libraries to the decorated name `windows-rs` received a bug report that mixing raw-dylib generated and the Windows SDK import libraries was causing linker failures: <https://github.com/microsoft/windows-rs/issues/3285> The root cause turned out to be #124958, that is we are not including the decorated name in the import library and so the import name type is also not being correctly set. This change modifies the generation of import libraries to set the "symbol name" to the fully decorated name and correctly marks the import as being data vs function. Note that this also required some changes to how the symbol is named within Rust: for MSVC we now need to use the decorated name but for MinGW we still need to use partially decorated (or undecorated) name. Fixes #124958 Passing i686 MSVC and MinGW build: <https://github.com/rust-lang/rust/actions/runs/11000433888?pr=130586> r? `@ChrisDenton`
2024-11-03compiler: Directly use rustc_abi in codegenJubilee Young-3/+3
2024-11-02Allow disabling ASan instrumentation for globalsDaniel Bertalan-0/+2
AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them. This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions.
2024-10-28Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`Zalathar-4/+4
2024-10-26Use safe wrappers `get_visibility` and `set_visibility`Zalathar-6/+4
2024-10-26Use safe wrappers `get_linkage` and `set_linkage`Zalathar-42/+38
2024-09-24Test fixing raw-dylibDaniel Paoliello-8/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-09-20Rollup merge of #128209 - beetrees:no-macos-10.10, r=jieyouxuGuillaume Gomez-52/+0
Remove macOS 10.10 dynamic linker bug workaround Rust's current minimum macOS version is 10.12, so the hack can be removed. This PR also updates the `remove_dir_all` docs to reflect that all supported macOS versions are protected against TOCTOU race conditions (the fallback implementation was already removed in #127683). try-job: dist-x86_64-apple try-job: dist-aarch64-apple try-job: dist-apple-various try-job: aarch64-apple try-job: x86_64-apple-1
2024-09-19Reformat some comments.Nicholas Nethercote-10/+11
So they are less than 100 chars.
2024-09-19Reduce visibility.Nicholas Nethercote-1/+1
2024-09-17Rename supertraits of `CodegenMethods`.Nicholas Nethercote-1/+1
Supertraits of `BuilderMethods` are all called `XyzBuilderMethods`. Supertraits of `CodegenMethods` are all called `XyzMethods`. This commit changes the latter to `XyzCodegenMethods`, for consistency.
2024-09-05Rollup merge of #128820 - LYF1999:yf/dev, r=nikicMatthias Krüger-1/+1
fix: get llvm type of global val using `LLVMTypeOf` on a global var always return ptr. so create a new function to access the value type of a global
2024-09-04Remove macOS 10.10 dynamic linker bug workaroundbeetrees-52/+0
2024-08-27Rollup merge of #126013 - nnethercote:unreachable_pub, r=UrgauMatthias Krüger-1/+1
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal. There are plenty more crates to do but this seems like enough for a first PR. r? `@compiler-errors`
2024-08-20Avoid extra `cast()`s after `CStr::as_ptr()`Josh Stone-1/+1
These used to be `&str` literals that did need a pointer cast, but that became a no-op after switching to `c""` literals in #118566.
2024-08-16Add `warn(unreachable_pub)` to `rustc_codegen_llvm`.Nicholas Nethercote-1/+1
2024-08-09fix: get llvm type of global valyifei-1/+1
2024-07-30Move is_mingw_gnu_toolchain and i686_decorated_name to cg_ssabjorn3-2/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-11/+12
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-20compiler: Never debug_assert in codegenJubilee Young-1/+1
The gains in performance are not worth the costs in correctness. This is partly because the gains are zero and the costs are unknown.
2024-07-19Rollup merge of #121533 - ratmice:wasm_init_fini_array, r=nnethercoteTrevor Gross-2/+8
Handle .init_array link_section specially on wasm Given that wasm-ld now has support for [.init_array](https://github.com/llvm/llvm-project/blob/8f2bd8ae68883592a333f4bdbed9798d66e68630/llvm/lib/MC/WasmObjectWriter.cpp#L1852), it appears we can easily implement that section by falling through to the normal path rather than taking the typical custom_section path for wasm. The wasm-ld appears to have a bunch of limitations. Only one static with the `link_section` in a crate or else you hit the fatal error in the link above "only one .init_array section fragment supported". They do not get merged. You can still call multiple constructors by setting it to an array. ``` unsafe extern "C" fn ctor() { println!("foo"); } #[used] #[link_section = ".init_array"] static FOO: [unsafe extern "C" fn(); 2] = [ctor, ctor]; ``` Another issue appears to be that if crate *A* depends on crate *B*, but *A* doesn't call any symbols from *B* and *B* doesn't `#[export_name = ...]` any symbols, then crate *B*'s constructor will not be called. The workaround to this is to provide an exported symbol in crate *B*.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_codegen_llvm`.Nicholas Nethercote-0/+1
2024-04-22Rollup merge of #124178 - GuillaumeGomez:llvm-backend, r=oli-obkGuillaume Gomez-3/+4
[cleanup] [llvm backend] Prevent creating the same `Instance::mono` multiple times Just a little thing I came across while going through the code. r? ```@oli-obk```
2024-04-19Prevent creating the same `Instance::mono` multiple timesGuillaume Gomez-3/+4
2024-04-16Codegen ZSTs without an allocationMark Rousskov-2/+16
This makes sure that &[] is just as efficient as indirecting through unsafe code (from_raw_parts). No new stable guarantee is intended about whether or not we do this, this is just an optimization. Co-authored-by: Ralf Jung <post@ralfj.de>
2024-03-12Some comment nitsOli Scherer-3/+2
2024-03-12Ensure nested allocations in statics do not get deduplicatedOli Scherer-3/+18
2024-03-12Make some functions private that are only ever used in the same moduleOli Scherer-1/+1
2024-03-12Stop requiring a type when codegenning types. We can get all the type info ↵Oli Scherer-10/+3
we need from the `ConstAllocation`
2024-03-12Check whether a static is mutable instead of passing it downOli Scherer-5/+5
2024-03-12Swap the order of a piece of code to make follow up diffs simplerOli Scherer-2/+2
2024-03-12Use information from allocation instead of from the static's typeOli Scherer-2/+6
2024-03-12Move `codegen_static` function body to an inherent method in preparation of ↵Oli Scherer-23/+27
splitting it. This should make the diff easier to read, as this commit does no functional changes at all.
2024-03-12Reduce some duplicate work that is being done around staticsOli Scherer-8/+18
2024-03-12Share the llvm type computation between both arms of a conditionOli Scherer-5/+4
2024-02-23Handle .init_array link_section specially on wasmmatt rice-2/+8
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-3/+3
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.