Skip to content

CFI: segfault with debuginfo=2 since llvm18 #123062

Open
@matthiaskrgr

Description

@matthiaskrgr

Code

//@ run-pass
// Ensure that both `Box<dyn Error + Send + Sync>` and `Box<dyn Error>` can be
// obtained from `String`.

use std::error::Error;

fn main() {
    let _err1: Box<dyn Error + Send + Sync> = From::from("test".to_string());
    let _err2: Box<dyn Error> = From::from("test".to_string());
    let _err3: Box<dyn Error + Send + Sync + 'static> = From::from("test");
    let _err4: Box<dyn Error> = From::from("test");
}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (0824b300e 2024-03-24)
binary: rustc
commit-hash: 0824b300eb0dae5d9ed59719d3f2732016683d66
commit-date: 2024-03-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Error output

rustc file.rs -Copt-level=3 -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Zsanitizer-cfi-generalize-pointers=yes -Cdebuginfo=2

<output>
Backtrace

!dbg attachment points at wrong subprogram for function
!625 = distinct !DISubprogram(name: "main", linkageName: "_ZN5crash4main17h4641422eb1201da3E", scope: !627, file: !626, line: 7, type: !176, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized | DISPFlagMainSubprogram, unit: !75, templateParams: !55, retainedNodes: !628)
ptr @_ZN5crash4main17h4641422eb1201da3E.cfi
  tail call void @free(ptr noundef %23) #54, !dbg !1506, !noalias !1515
!1506 = !DILocation(line: 42, column: 9, scope: !394, inlinedAt: !1507)
!1242 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1179, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
!1242 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1179, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
!dbg attachment points at wrong subprogram for function
!625 = distinct !DISubprogram(name: "main", linkageName: "_ZN5crash4main17h4641422eb1201da3E", scope: !627, file: !626, line: 7, type: !176, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized | DISPFlagMainSubprogram, unit: !75, templateParams: !55, retainedNodes: !628)
ptr @_ZN5crash4main17h4641422eb1201da3E.cfi
  tail call void @free(ptr noundef %24) #54, !dbg !1505, !noalias !1514
!1505 = !DILocation(line: 42, column: 9, scope: !394, inlinedAt: !1506)
!1241 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1178, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
!1241 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1178, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
error: rustc interrupted by SIGSEGV, printing backtrace

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x2fee106)[0x70f5dcdee106]
/usr/lib/libc.so.6(+0x40770)[0x70f5d9c5a770]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm10DwarfDebug18finalizeModuleInfoEv+0x3ce)[0x70f5d7ef5f8e]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm10DwarfDebug9endModuleEv+0x142)[0x70f5d8494842]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(+0x65b2094)[0x70f5d87b2094]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm13FPPassManager14doFinalizationERNS_6ModuleE+0x4a)[0x70f5d84d1bd2]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x378)[0x70f5d84896b8]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(LLVMRustWriteOutputFile+0x190)[0x70f5dee89290]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x5088ea4)[0x70f5dee88ea4]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x5086d52)[0x70f5dee86d52]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x5086a42)[0x70f5dee86a42]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x508b5dc)[0x70f5dee8b5dc]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x508aba3)[0x70f5dee8aba3]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libstd-eb900a948ffb2e3b.so(rust_metadata_std_aca912f18be40d2b+0xc2a49)[0x70f5e0417a49]
/usr/lib/libc.so.6(+0x8f55a)[0x70f5d9ca955a]
/usr/lib/libc.so.6(+0x10ca3c)[0x70f5d9d26a3c]

note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
[1]    1450268 segmentation fault  rustc /tmp/crash.rs -Copt-level=3 -Zsanitizer=cfi -Ccodegen-units=1 -Clto

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-control-flow-integrityArea: Control Flow Integrity (CFI) security mitigationA-sanitizersArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.PG-exploit-mitigationsProject group: Exploit mitigationsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions