Hasty Briefsbeta

Bilingual

Building the Rust Compiler with GCC

10 months ago
  • #Rust
  • #Compiler
  • #GCC
  • The author loves working on the Rust compiler and is tackling the challenge of bootstrapping it using `cg_gcc` (GCC-based codegen) instead of LLVM.
  • Bootstrapping the Rust compiler involves a complex three-stage process to ensure the GCC-based compiler behaves identically to the LLVM-based one.
  • A major milestone is achieving a stage 3 build, which confirms the GCC-based Rust compiler is equivalent to the LLVM version.
  • Debugging techniques like 'Giving the compiler a lobotomy' involve patching out problematic code to identify and fix bugs.
  • One significant bug involves the `#[inline(always)]` attribute on recursive functions, which GCC cannot handle, unlike LLVM.
  • A workaround treats `#[inline(always)]` as a hint rather than a strict directive, avoiding recursion issues but potentially causing performance regressions.
  • Another bug involves incorrect handling of 128-bit integers in `SwitchInt` terminators, requiring a workaround using nested `if` statements instead of switches.
  • A misalignment issue in the Rust compiler's interner, particularly with `ScalarInt` types, was fixed by ensuring proper alignment for 128-bit integers.
  • The project has made progress, including fixes for stack overflows and memory usage issues, but challenges remain.
  • Future work includes fuzzing with `rustlantis`, bootstrapping on ARM, and addressing ABI and GCC bugs.