Bootstrapping Rust with GCC: A Debugging Odyssey

2025-07-07

This article details the author's journey bootstrapping the Rust compiler using GCC instead of LLVM. The process was fraught with challenges, encountering three major bugs: the `#[inline(always)]` attribute on recursive functions, an incorrect implementation of the 128-bit SwitchInt terminator, and a misaligned memory access. Employing a 'lobotomy' debugging approach, the author progressively identified and fixed these issues, successfully achieving a Stage 2 build and progressing towards Stage 3. The article shares debugging techniques like using core dumps to analyze segfaults and explores the complexities of compiler optimizations.

Read more
Development

Rust to C Compiler Update: 96% Core Test Coverage!

2025-04-12

Significant progress has been made on a Rust to C compiler project, achieving a 95.9% core test pass rate and culminating in a presentation at Rust Week. The post details fixes for 128-bit integer intrinsics, checked arithmetic, and subslicing bugs. Improvements in C compiler compatibility are also discussed, along with a move towards a more memory-efficient internal IR. Challenges such as difficulties obtaining compilers for certain platforms are acknowledged, but the author remains committed to increasing C99 compliance and broader platform support. Future plans include completing a deep dive into Rust panics and developing a memory profiler.

Read more
Development C Compiler

Rust Reflection: The Tug-of-War Between Safety and Access Rules

2025-01-03

Rust lacks reflection, a feature many developers desire. This article delves into the safety challenges of implementing reflection in Rust. Due to Rust's memory safety guarantees, a reflection API must adhere to strict access rules, preventing arbitrary access to private fields to avoid memory safety vulnerabilities. The author explores how these limitations impact reflection API design, such as handling reflection failures and expressing complex reflection bounds. The trade-offs between safe and unsafe reflection APIs are also discussed, along with balancing functionality and security. Ultimately, creating a safe reflection mechanism in Rust is a complex and challenging problem requiring careful consideration of various factors.

Read more
Development Reflection