rust-lang / rust-lang/rust

CFI: segfault with debuginfo=2 since llvm18

Open
#123,062 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-control-flow-integrity A-debuginfo A-LLVM A-sanitizers C-bug I-crash PG-exploit-mitigations T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the provided Rust snippet with the exact rustc flags and confirm the SIGSEGV. Trace the output path through LLVM's DwarfDebug::finalizeModuleInfo and rustc's LLVMRustWriteOutputFile, using the duplicated debug-info attachments as the reported symptom. Done means the command completes without a segmentation fault and emits valid debuginfo.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.