rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.59k stars 12.62k forks source link

Error compiling `core` with LLVM CFI enabled #90546

Closed rcvalle closed 1 year ago

rcvalle commented 2 years ago

Code

fn main() {
    println!("Hello, world!");
}

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (db062de72 2021-11-01)
binary: rustc
commit-hash: db062de72b0a064f45b6f86894cbdc7c0ec68844
commit-date: 2021-11-01
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

~/hello-rust$ RUSTFLAGS="-Cembed-bitcode -Clto -Zsanitizer=cfi" RUSTDOCFLAGS="-Cembed-bitcode -Clto -Zsanitizer=cfi" cargo run -Zbuild-std --target x86_64-unknown-linux-gnu

    Updating crates.io index
  Downloaded addr2line v0.16.0
  Downloaded cc v1.0.69
  Downloaded cfg-if v0.1.10
  Downloaded unicode-width v0.1.8
  Downloaded adler v0.2.3
  Downloaded compiler_builtins v0.1.49
  Downloaded getopts v0.2.21
  Downloaded rustc-demangle v0.1.21
  Downloaded hashbrown v0.11.0
  Downloaded miniz_oxide v0.4.0
  Downloaded object v0.26.2
  Downloaded memchr v2.4.1
  Downloaded libc v0.2.103
  Downloaded gimli v0.25.0
  Downloaded 14 crates (2.0 MB) in 0.68s
   Compiling compiler_builtins v0.1.49
   Compiling core v0.0.0 (/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.103
   Compiling cc v1.0.69
   Compiling memchr v2.4.1
   Compiling std v0.0.0 (/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
   Compiling unwind v0.0.0 (/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x4c9083)[0x7fb24e347083]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x138e0)[0x7fb24dae68e0]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x3520633)[0x7fb24c11b633]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x351a701)[0x7fb24c115701]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x275552f)[0x7fb24b35052f]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x274d4b4)[0x7fb24b3484b4]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm12SelectionDAG13LegalizeTypesEv+0x33c)[0x7fb24b3422bc]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm16SelectionDAGISel17CodeGenAndEmitDAGEv+0x80)[0x7fb24b340610]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x271c)[0x7fb24b32477c]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0x4f2)[0x7fb24b31c3e2]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x2720ed8)[0x7fb24b31bed8]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE+0xaa)[0x7fb24b8f6e1a]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x6c7)[0x7fb24b7adf27]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x7fb24b7ad83f]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x289)[0x7fb24bb91219]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23f5004)[0x7fb250273004]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23efd5f)[0x7fb25026dd5f]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23f2960)[0x7fb250270960]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x238526b)[0x7fb25020326b]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x237f8ab)[0x7fb2501fd8ab]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23c469c)[0x7fb25024269c]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23d899c)[0x7fb25025699c]
/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/libstd-8adcca4f1427867b.so(rust_metadata_std_fcea40badc263c8f+0xa9513)[0x7fb24dbb8513]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8eae)[0x7fb24dadbeae]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7fb24d9f8a5f]
error: could not compile `core`

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2018 /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=46c7ed8bd3462e72 -C extra-filename=-46c7ed8bd3462e72 --out-dir /home/rcvalle/hello-rust/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -Z force-unstable-if-unmarked -L dependency=/home/rcvalle/hello-rust/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/home/rcvalle/hello-rust/target/debug/deps --cap-lints allow -Cembed-bitcode -Clto -Zsanitizer=cfi` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
error: build failed
Backtrace

`RUSTFLAGS="-Cembed-bitcode -Clto -Zsanitizer=cfi" RUSTDOCFLAGS="-Cembed-bitcode -Clto -Zsanitizer=cfi" RUST_BACKTRACE="1" cargo run -Zbuild-std --target x86_64-unknown-linux-gnu` ``` Compiling core v0.0.0 (/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core) Compiling rustc-std-workspace-core v1.99.0 (/home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core) Compiling compiler_builtins v0.1.49 Compiling libc v0.2.103 /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x4c9083)[0x7fa21a33b083] /lib/x86_64-linux-gnu/libpthread.so.0(+0x138e0)[0x7fa219ada8e0] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x3520633)[0x7fa21810f633] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x351a701)[0x7fa218109701] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x275552f)[0x7fa21734452f] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x274d4b4)[0x7fa21733c4b4] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm12SelectionDAG13LegalizeTypesEv+0x33c)[0x7fa2173362bc] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm16SelectionDAGISel17CodeGenAndEmitDAGEv+0x80)[0x7fa217334610] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x271c)[0x7fa21731877c] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0x4f2)[0x7fa2173103e2] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(+0x2720ed8)[0x7fa21730fed8] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE+0xaa)[0x7fa2178eae1a] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x6c7)[0x7fa2177a1f27] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x7fa2177a183f] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.58.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x289)[0x7fa217b85219] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23f5004)[0x7fa21c267004] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23efd5f)[0x7fa21c261d5f] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23f2960)[0x7fa21c264960] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x238526b)[0x7fa21c1f726b] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x237f8ab)[0x7fa21c1f18ab] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23c469c)[0x7fa21c23669c] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-5edcf0e336ae6d33.so(+0x23d899c)[0x7fa21c24a99c] /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/libstd-8adcca4f1427867b.so(rust_metadata_std_fcea40badc263c8f+0xa9513)[0x7fa219bac513] /lib/x86_64-linux-gnu/libpthread.so.0(+0x8eae)[0x7fa219acfeae] /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7fa2199eca5f] error: could not compile `core` Caused by: process didn't exit successfully: `rustc --crate-name core --edition=2018 /home/rcvalle/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=46c7ed8bd3462e72 -C extra-filename=-46c7ed8bd3462e72 --out-dir /home/rcvalle/hello-rust/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -Z force-unstable-if-unmarked -L dependency=/home/rcvalle/hello-rust/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/home/rcvalle/hello-rust/target/debug/deps --cap-lints allow -Cembed-bitcode -Clto -Zsanitizer=cfi` (signal: 11, SIGSEGV: invalid memory reference) warning: build failed, waiting for other jobs to finish... error: build failed ```

rcvalle commented 2 years ago

@rustbot claim

rcvalle commented 1 year ago

The issue seems to be with LLVM trying to generate the type tests for functions marked to be inlined---which if they're going to be inlined, there shouldn't be a branch, and a type test in the first place:

rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ RUSTFLAGS="-Zsanitizer=cfi -Cembed-bitcode=yes -Clto" cargo +stage1 build -Z build-std -Z build-std-features --target x86_64-unknown-linux-gnu
   Compiling core v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.146
   Compiling cc v1.0.79
   Compiling std v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std)
   Compiling unwind v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling compiler_builtins v0.1.93
   Compiling alloc v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling rustc-demangle v0.1.21
PromoteIntegerResult #0: t5: i1 = llvm.type.test TargetConstant:i64<298>, t3, MDNode:ch<0x7f6c763481f0>, /usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2268:62

Do not know how to promote this operator!
UNREACHABLE executed at /usr/local/google/home/rcvalle/rust/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:57!
error: could not compile `core` (lib)

Caused by:
  process didn't exit successfully: `/usr/local/google/home/rcvalle/.rustup/toolchains/stage1/bin/rustc --crate-name core --edition=2021 /usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=302 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=2c7763240bf392e4 -C extra-filename=-2c7763240bf392e4 --out-dir /usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -Z force-unstable-if-unmarked -L dependency=/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/debug/deps --cap-lints allow -Zsanitizer=cfi -Cembed-bitcode=yes -Clto` (signal: 6, SIGABRT: process abort signal)
warning: build failed, waiting for other jobs to finish...
PromoteIntegerResult #0: t5: i1 = llvm.type.test TargetConstant:i64<298>, t3, MDNode:ch<0x7fd347158668>, /usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc/src/str.rs:656:27

Do not know how to promote this operator!
UNREACHABLE executed at /usr/local/google/home/rcvalle/rust/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:57!
error: could not compile `alloc` (lib)

Caused by:
  process didn't exit successfully: `/usr/local/google/home/rcvalle/.rustup/toolchains/stage1/bin/rustc --crate-name alloc --edition=2021 /usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=302 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=77ada0965256b59c -C extra-filename=-77ada0965256b59c --out-dir /usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -Z force-unstable-if-unmarked -L dependency=/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/debug/deps --extern compiler_builtins=/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/x86_64-unknown-linux-gnu/debug/deps/libcompiler_builtins-37fdf83998d05d4b.rmeta --extern core=/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1/target/x86_64-unknown-linux-gnu/debug/deps/libcore-2c7763240bf392e4.rmeta --cap-lints allow -Zsanitizer=cfi -Cembed-bitcode=yes -Clto` (signal: 6, SIGABRT: process abort signal)
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ 
rcvalle commented 1 year ago

This was actually a combination of issues:

rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ RUSTFLAGS="-Zsanitizer=cfi -Ccodegen-units=1 -Cembed-bitcode=yes -Clto" cargo  +stage1 build -Z build-std=core,alloc -Z build-std-features --target x86_64-unknown-linux-gnu
   Compiling compiler_builtins v0.1.93
   Compiling core v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc)
   Compiling rust-cfi-1 v0.1.0 (/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 52s
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ ./target/x86_64-unknown-linux-gnu/debug/rust-cfi-1 
The answer is: 12
With CFI enabled, you should not see the next answer
Illegal instruction
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ RUSTFLAGS="-Zsanitizer=cfi -Ccodegen-units=1 -Cembed-bitcode=yes -Clto" cargo  +stage1 build -Z build-std=core,alloc -Z build-std-features --target x86_64-unknown-linux-gnu --release
   Compiling compiler_builtins v0.1.93
   Compiling core v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc)
   Compiling rust-cfi-1 v0.1.0 (/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1)
    Finished release [optimized] target(s) in 4m 07s
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ ./target/x86_64-unknown-linux-gnu/release/rust-cfi-1 
The answer is: 12
With CFI enabled, you should not see the next answer
Illegal instruction
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ cargo clean
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ RUSTFLAGS="-Clinker-plugin-lto -Clinker=/usr/local/google/home/rcvalle/llvm-project/build/bin/clang -Clink-arg=-fuse-ld=lld -Zsanitizer=cfi" cargo +stage1 build -Z build-std=core,alloc -Z build-std-features --target x86_64-unknown-linux-gnu
   Compiling compiler_builtins v0.1.93
   Compiling core v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc)
   Compiling rust-cfi-1 v0.1.0 (/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1)
    Finished dev [unoptimized + debuginfo] target(s) in 39.13s
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ ./target/x86_64-unknown-linux-gnu/debug/rust-cfi-1 
The answer is: 12
With CFI enabled, you should not see the next answer
Illegal instruction
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ RUSTFLAGS="-Clinker-plugin-lto -Clinker=/usr/local/google/home/rcvalle/llvm-project/build/bin/clang -Clink-arg=-fuse-ld=lld -Zsanitizer=cfi" cargo +stage1 build -Z build-std=core,alloc -Z build-std-features --target x86_64-unknown-linux-gnu --release
   Compiling core v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.93
   Compiling rustc-std-workspace-core v1.99.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/usr/local/google/home/rcvalle/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc)
   Compiling rust-cfi-1 v0.1.0 (/usr/local/google/home/rcvalle/rust-cfi-examples/rust-cfi-1)
    Finished release [optimized] target(s) in 43.93s
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ ./target/x86_64-unknown-linux-gnu/release/rust-cfi-1 
The answer is: 12
With CFI enabled, you should not see the next answer
Illegal instruction
rcvalle@rcvalle-desktop:~/rust-cfi-examples/rust-cfi-1$ 

I'll send a PR with these fixes soon. Rebuilding std and all its dependencies (not just core and alloc) now bumps into #100778, which I'll fix next.