about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/errors.rs
diff options
context:
space:
mode:
authorBastian Kersting <bkersting@google.com>2025-03-11 11:00:42 +0000
committerBastian Kersting <bkersting@google.com>2025-03-17 08:27:53 +0000
commitb30cf11b9672cf9d938654a75aded1a2084b9980 (patch)
treee0964e18d5130042be0a7c5cc5699c48c2a74e66 /compiler/rustc_codegen_llvm/src/errors.rs
parent705421b52239d7393b4738764b192179d5c139c2 (diff)
downloadrust-b30cf11b9672cf9d938654a75aded1a2084b9980.tar.gz
rust-b30cf11b9672cf9d938654a75aded1a2084b9980.zip
Emit function declarations for functions with #[linkage="extern_weak"]
Currently, when declaring an extern weak function in Rust, we use the
following syntax:
```rust
unsafe extern "C" {
   #[linkage = "extern_weak"]
   static FOO: Option<unsafe extern "C" fn() -> ()>;
}
```
This allows runtime-checking the extern weak symbol through the Option.

When emitting LLVM-IR, the Rust compiler currently emits this static
as an i8, and a pointer that is initialized with the value of the global
i8 and represents the nullabilty e.g.
```
@FOO = extern_weak global i8
@_rust_extern_with_linkage_FOO = internal global ptr @FOO
```

This approach does not work well with CFI, where we need to attach CFI
metadata to a concrete function declaration, which was pointed out in
https://github.com/rust-lang/rust/issues/115199.

This change switches to emitting a proper function declaration instead
of a global i8. This allows CFI to work for extern_weak functions.

We keep initializing the Rust internal symbol with the function
declaration, which preserves the correct behavior for runtime checking
the Option.

Co-authored-by: Jakob Koschel <jakobkoschel@google.com>
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/errors.rs')
0 files changed, 0 insertions, 0 deletions