Skip to content

rustc-LLVM ERROR of ControlFlowIntegrit #142284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zsdfbb opened this issue Jun 10, 2025 · 10 comments · May be fixed by #142323
Open

rustc-LLVM ERROR of ControlFlowIntegrit #142284

zsdfbb opened this issue Jun 10, 2025 · 10 comments · May be fixed by #142323
Labels
A-control-flow-integrity Area: Control Flow Integrity (CFI) security mitigation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. PG-exploit-mitigations Project group: Exploit mitigations S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zsdfbb
Copy link

zsdfbb commented Jun 10, 2025

Hello, I am a beginner. I am testing the CFI of Rust (The Rust Unstable Book ControlFlowIntegrit), but I encountered this error log.

The error message is as follows:

Code

// This example demonstrates redirecting control flow using an indirect
// branch/call to a function with a different number of parameters than
// arguments intended/passed in the call/branch site.

use std::mem;

fn add_one(x: i32) -> i32 {
    x + 1
}

fn add_two(x: i32, _y: i32) -> i32 {
    x + 2
}

fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
    f(arg) + f(arg)
}

fn main() {
    let answer = do_twice(add_one, 5);

    println!("The answer is: {}", answer);

    println!("With CFI enabled, you should not see the next answer");
    let f: fn(i32) -> i32 =
        unsafe { mem::transmute::<*const u8, fn(i32) -> i32>(add_two as *const u8) };
    let next_answer = do_twice(f, 5);

    println!("The next answer is: {}", next_answer);
}

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.89.0-nightly (d13a431a6 2025-06-09)
binary: rustc
commit-hash: d13a431a6cc69cd65efe7c3eb7808251d6fd7a46
commit-date: 2025-06-09
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

$ clang --version --verbose
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ uname -a
Linux ZSMSI 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Error output

$ RUSTFLAGS="-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld -Zsanitizer=cfi" cargo run -Zbuild-std -Zbuild-std-features --release --target x86_64-unknown-linux-gnu

   Compiling compiler_builtins v0.1.160 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/compiler-builtins/compiler-builtins)
   Compiling rustc-std-workspace-core v1.99.0 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling panic_abort v0.0.0 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
   Compiling cfg-if v1.0.0
   Compiling libc v0.2.172
   Compiling rustc-demangle v0.1.24
rustc-LLVM ERROR: Do not know how to promote this operator!
error: could not compile `compiler_builtins` (lib)

Caused by:
  process didn't exit successfully: `/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name compiler_builtins --edition=2024 /home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/compiler-builtins/compiler-builtins/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=80 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --warn=unexpected_cfgs --check-cfg 'cfg(bootstrap)' --check-cfg 'cfg(target_os, values("cygwin"))' --cfg 'feature="compiler-builtins"' --cfg 'feature="default"' --cfg 'feature="rustc-dep-of-std"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("c", "compiler-builtins", "default", "mangled-names", "mem", "no-asm", "no-f16-f128", "rustc-dep-of-std", "unstable-public-internals"))' -C metadata=dc0628facc0e0355 -C extra-filename=-6998363e595a805f --out-dir /home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -Z force-unstable-if-unmarked -L dependency=/home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/debug/deps --extern core=/home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/x86_64-unknown-linux-gnu/debug/deps/libcore-0f6e55509e6eb67a.rmeta --cap-lints allow -Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld -Zsanitizer=cfi --cfg f16_enabled --cfg f128_enabled --cfg intrinsics_enabled --cfg arch_enabled --cfg 'feature="unstable-intrinsics"' --cfg 'feature="mem-unaligned"' --check-cfg 'cfg(__ashldi3, values("optimized-c"))' --check-cfg 'cfg(__ashlsi3, values("optimized-c"))' --check-cfg 'cfg(__ashrdi3, values("optimized-c"))' --check-cfg 'cfg(__ashrsi3, values("optimized-c"))' --check-cfg 'cfg(__bswapsi2, values("optimized-c"))' --check-cfg 'cfg(__bswapdi2, values("optimized-c"))' --check-cfg 'cfg(__bswapti2, values("optimized-c"))' --check-cfg 'cfg(__divdi3, values("optimized-c"))' --check-cfg 'cfg(__divsi3, values("optimized-c"))' --check-cfg 'cfg(__divmoddi4, values("optimized-c"))' --check-cfg 'cfg(__divmodsi4, values("optimized-c"))' --check-cfg 'cfg(__divmodsi4, values("optimized-c"))' --check-cfg 'cfg(__divmodti4, values("optimized-c"))' --check-cfg 'cfg(__lshrdi3, values("optimized-c"))' --check-cfg 'cfg(__lshrsi3, values("optimized-c"))' --check-cfg 'cfg(__moddi3, values("optimized-c"))' --check-cfg 'cfg(__modsi3, values("optimized-c"))' --check-cfg 'cfg(__muldi3, values("optimized-c"))' --check-cfg 'cfg(__udivdi3, values("optimized-c"))' --check-cfg 'cfg(__udivmoddi4, values("optimized-c"))' --check-cfg 'cfg(__udivmodsi4, values("optimized-c"))' --check-cfg 'cfg(__udivsi3, values("optimized-c"))' --check-cfg 'cfg(__umoddi3, values("optimized-c"))' --check-cfg 'cfg(__umodsi3, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(target_feature, values("vis3"))' --check-cfg 'cfg(feature, values("checked"))' --check-cfg 'cfg(assert_no_panic)' --check-cfg 'cfg(f16_enabled)' --check-cfg 'cfg(f128_enabled)' --check-cfg 'cfg(thumb)' --check-cfg 'cfg(thumb_1)' --check-cfg 'cfg(intrinsics_enabled)' --check-cfg 'cfg(arch_enabled)' --check-cfg 'cfg(optimizations_enabled)' --check-cfg 'cfg(feature, values("unstable-public-internals"))' --check-cfg 'cfg(optimizations_enabled)' --check-cfg 'cfg(x86_no_sse)' --check-cfg 'cfg(kernel_user_helpers)' --check-cfg 'cfg(feature, values("mem-unaligned"))'` (exit status: 101)
warning: build failed, waiting for other jobs to finish...
Backtrace

$ RUST_BACKTRACE=1
$ RUSTFLAGS="-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld -Zsanitizer=cfi" cargo run -Zbuild-std -Zbuild-std-features --release --target x86_64-unknown-linux-gnu

   Compiling compiler_builtins v0.1.160 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/compiler-builtins/compiler-builtins)
   Compiling rustc-std-workspace-core v1.99.0 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling panic_abort v0.0.0 (/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
   Compiling cfg-if v1.0.0
   Compiling libc v0.2.172
   Compiling rustc-demangle v0.1.24
rustc-LLVM ERROR: Do not know how to promote this operator!
error: could not compile `compiler_builtins` (lib)

Caused by:
  process didn't exit successfully: `/home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name compiler_builtins --edition=2024 /home/zs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/compiler-builtins/compiler-builtins/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=82 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --warn=unexpected_cfgs --check-cfg 'cfg(bootstrap)' --check-cfg 'cfg(target_os, values("cygwin"))' --cfg 'feature="compiler-builtins"' --cfg 'feature="default"' --cfg 'feature="rustc-dep-of-std"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("c", "compiler-builtins", "default", "mangled-names", "mem", "no-asm", "no-f16-f128", "rustc-dep-of-std", "unstable-public-internals"))' -C metadata=f9ff92ee632bac5e -C extra-filename=-9c78bddfac14b282 --out-dir /home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C strip=debuginfo -Z force-unstable-if-unmarked -L dependency=/home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/release/deps --extern core=/home/zs/Develop/CfiTest/rust/rust-cfi-examples/rust-cfi-2/target/x86_64-unknown-linux-gnu/release/deps/libcore-f03378565b56c52d.rmeta --cap-lints allow -Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld -Zsanitizer=cfi --cfg f16_enabled --cfg f128_enabled --cfg intrinsics_enabled --cfg arch_enabled --cfg optimizations_enabled --cfg 'feature="unstable-intrinsics"' --cfg 'feature="mem-unaligned"' --check-cfg 'cfg(__ashldi3, values("optimized-c"))' --check-cfg 'cfg(__ashlsi3, values("optimized-c"))' --check-cfg 'cfg(__ashrdi3, values("optimized-c"))' --check-cfg 'cfg(__ashrsi3, values("optimized-c"))' --check-cfg 'cfg(__bswapsi2, values("optimized-c"))' --check-cfg 'cfg(__bswapdi2, values("optimized-c"))' --check-cfg 'cfg(__bswapti2, values("optimized-c"))' --check-cfg 'cfg(__divdi3, values("optimized-c"))' --check-cfg 'cfg(__divsi3, values("optimized-c"))' --check-cfg 'cfg(__divmoddi4, values("optimized-c"))' --check-cfg 'cfg(__divmodsi4, values("optimized-c"))' --check-cfg 'cfg(__divmodsi4, values("optimized-c"))' --check-cfg 'cfg(__divmodti4, values("optimized-c"))' --check-cfg 'cfg(__lshrdi3, values("optimized-c"))' --check-cfg 'cfg(__lshrsi3, values("optimized-c"))' --check-cfg 'cfg(__moddi3, values("optimized-c"))' --check-cfg 'cfg(__modsi3, values("optimized-c"))' --check-cfg 'cfg(__muldi3, values("optimized-c"))' --check-cfg 'cfg(__udivdi3, values("optimized-c"))' --check-cfg 'cfg(__udivmoddi4, values("optimized-c"))' --check-cfg 'cfg(__udivmodsi4, values("optimized-c"))' --check-cfg 'cfg(__udivsi3, values("optimized-c"))' --check-cfg 'cfg(__umoddi3, values("optimized-c"))' --check-cfg 'cfg(__umodsi3, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_cas16_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldadd8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldclr8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldeor8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_ldset8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp1_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp2_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp4_acq_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_relax, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_acq, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_rel, values("optimized-c"))' --check-cfg 'cfg(__aarch64_swp8_acq_rel, values("optimized-c"))' --check-cfg 'cfg(target_feature, values("vis3"))' --check-cfg 'cfg(feature, values("checked"))' --check-cfg 'cfg(assert_no_panic)' --check-cfg 'cfg(f16_enabled)' --check-cfg 'cfg(f128_enabled)' --check-cfg 'cfg(thumb)' --check-cfg 'cfg(thumb_1)' --check-cfg 'cfg(intrinsics_enabled)' --check-cfg 'cfg(arch_enabled)' --check-cfg 'cfg(optimizations_enabled)' --check-cfg 'cfg(feature, values("unstable-public-internals"))' --check-cfg 'cfg(optimizations_enabled)' --check-cfg 'cfg(x86_no_sse)' --check-cfg 'cfg(kernel_user_helpers)' --check-cfg 'cfg(feature, values("mem-unaligned"))'` (exit status: 101)
warning: build failed, waiting for other jobs to finish...

@zsdfbb zsdfbb added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jun 10, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 10, 2025
@cyrgani cyrgani added A-sanitizers Area: Sanitizers for correctness and code quality A-control-flow-integrity Area: Control Flow Integrity (CFI) security mitigation labels Jun 10, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Jun 10, 2025

This error can be caused just by RUSTFLAGS="-Clinker-plugin-lto -Zsanitizer=cfi" cargo b on an empty crate with the compiler_builtins = "=0.1.160" dependency. It is only caused by compiler_builtins v0.1.157 and above, 0.1.156 compiles sucessfully.

reduction of compiler_builtins:

#![no_builtins]
#![no_std]

static FUNC: fn() = initializer;

fn initializer() {
    call(fma_with_fma);
}

fn call(fn_ptr: fn()) {
    fn_ptr();
}

fn fma_with_fma() {}

@cyrgani

This comment has been minimized.

@cyrgani cyrgani added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Jun 10, 2025
@saethlin
Copy link
Member

Your second example looks smaller but it's actually bigger. Since it's a bin crate without no_std it pulls in our pre-main initialization code which does dispatch through a function pointer.

@saethlin saethlin added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 10, 2025
@workingjubilee workingjubilee added the PG-exploit-mitigations Project group: Exploit mitigations label Jun 10, 2025
@workingjubilee
Copy link
Member

huh.

cc @rcvalle @maurer

@maurer
Copy link
Contributor

maurer commented Jun 10, 2025

Interestingly, it only triggers for cfi, not kcfi (which is probably why I hadn't noticed it, my day-to-day usage of the feature only hits kcfi).

mmaurer@joyeuse:~/rustc-repro$ rustc +nightly -Clinker-plugin-lto -Zsanitizer=cfi scratch.rs --crate-type=rlib -C panic=abort --cap-lints=allow
rustc-LLVM ERROR: Do not know how to promote this operator!
mmaurer@joyeuse:~/rustc-repro$ rustc +nightly -Cpanic=abort -Zsanitizer=kcfi scratch.rs --crate-type=rlib --cap-lints=allow
mmaurer@joyeuse:~/rustc-repro$ 

@maurer
Copy link
Contributor

maurer commented Jun 10, 2025

Switching from -Clinker-plugin-lto to -Clto -Ccodegen-units=1 also suppresses the error.

@maurer
Copy link
Contributor

maurer commented Jun 10, 2025

mmaurer@joyeuse:~/rustc-repro$ cat check.sh 
#!/usr/bin/env bash
rustc -Clinker-plugin-lto -Zsanitizer=cfi scratch.rs --crate-type=rlib -C panic=abort --cap-lints=allow
mmaurer@joyeuse:~/rustc-repro$ cargo-bisect-rustc --script check.sh

SNIP

looking for regression commit between 2024-01-12 and 2024-01-13
fetching (via remote github) commits from max(62d7ed4a6775c4490e493093ca98ef7c215b835b, 2024-01-10) to 2319be8e265dd19973574eb581d28297baf44b11
ending github query because we found starting sha: 62d7ed4a6775c4490e493093ca98ef7c215b835b
get_commits_between returning commits, len: 8
  commit[0] 2024-01-11: Auto merge of #119864 - matthiaskrgr:rollup-mc2qz13, r=matthiaskrgr
  commit[1] 2024-01-12: Auto merge of #119430 - NCGThompson:int-pow-bench, r=cuviper
  commit[2] 2024-01-12: Auto merge of #118548 - Enselic:bench-padding, r=thomcc,ChrisDenton
  commit[3] 2024-01-12: Auto merge of #119735 - lcnr:provisional-cache-readd, r=compiler-errors
  commit[4] 2024-01-12: Auto merge of #119879 - matthiaskrgr:rollup-y710der, r=matthiaskrgr
  commit[5] 2024-01-12: Auto merge of #119396 - Nadrieril:intersection-tracking, r=WaffleLapkin
  commit[6] 2024-01-12: Auto merge of #119889 - GuillaumeGomez:rollup-ah3dhya, r=GuillaumeGomez
  commit[7] 2024-01-12: Auto merge of #119452 - AngelicosPhosphoros:make_nonzeroint_get_assume_nonzero, r=scottmcm
ERROR: no CI builds available between 62d7ed4a6775c4490e493093ca98ef7c215b835b and 2319be8e265dd19973574eb581d28297baf44b11 within last 167 days

Taking a quick glance through those, the one that seems most relevant is #119889 , as it contains #119885 which reverts #113923 . This basically suggests that the core problem is that #[no_builtins] crates are not participating in linker-plugin-LTO, which means that if they get a CFI bundle that is supposed to be lowered in LTO, the build fails.

This likely means that until compiler_builtins v0.1.57, there were no indirect jumps in compiler builtins, so this didn't trigger.

The fact that it doesn't trigger with -Clto makes me wonder if there's something funny going on with the suppression of one vs the other for builtins?

@maurer
Copy link
Contributor

maurer commented Jun 10, 2025

compiler_builtins triggers this by switching to a function pointer for run-time feature detection.

It appears that linker-plugin-lto selects bitcode emission differently than -Clto, which is why it breaks.

If -Clto is working, I think we may not need that particular adaptation, but given the fragility of compiler_builtins / #![no_builtins] in general, it's hard to be certain. I've sent up #142323 to try that approach out - it does fix this bug, but we probably need to poke at it to make sure it doesn't break other build configurations.

@dianqk
Copy link
Member

dianqk commented Jun 13, 2025

Interestingly, it only triggers for cfi, not kcfi (which is probably why I hadn't noticed it, my day-to-day usage of the feature only hits kcfi).

mmaurer@joyeuse:~/rustc-repro$ rustc +nightly -Clinker-plugin-lto -Zsanitizer=cfi scratch.rs --crate-type=rlib -C panic=abort --cap-lints=allow
rustc-LLVM ERROR: Do not know how to promote this operator!
mmaurer@joyeuse:~/rustc-repro$ rustc +nightly -Cpanic=abort -Zsanitizer=kcfi scratch.rs --crate-type=rlib --cap-lints=allow
mmaurer@joyeuse:~/rustc-repro$ 

It seems that kcfi doesn't require LTO:

To enable Clang’s available CFI schemes, use the flag -fsanitize=cfi. You can also enable a subset of available schemes. As currently implemented, all schemes except for kcfi rely on link-time optimization (LTO); so it is required to specify -flto or -flto=thin, and the linker used must support LTO, for example via the gold plugin. (https://clang.llvm.org/docs/ControlFlowIntegrity.html)

@maurer
Copy link
Contributor

maurer commented Jun 13, 2025

Yes, that was in my initial assessment - I didn't know it was LTO related at that point and thought it might have just been sanitizer related, so I tried with KCFI to see if that would trigger it in a more reduced sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-control-flow-integrity Area: Control Flow Integrity (CFI) security mitigation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. PG-exploit-mitigations Project group: Exploit mitigations S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants