一句话:提出 Forcrat,用来源/能力与错误源静态分析将 C2Rust 生成代码中的 libc I/O 调用自动替换为 Rust std 调用。
将 C 遗留系统迁移到 Rust 可提升可靠性,但 C2Rust 仍保留 libc 调用而非替换为 Rust 标准库。本文聚焦 I/O API 替换,其难点在于两边 API 的类型设计不同:libc 与 Rust std 用不同类型表示流的来源(标准输入、文件)与能力(读、写),且错误检查机制不同(libc 内部指示器 vs Rust std 返回值)。为此提出两种静态分析:来源与能力分析、错误源分析,并据此自动替换 I/O API。评估显示方法正确(32 个带测试套件程序变换后全部通过)、高效(14 秒分析并变换 422k LOC)、适用性广(替换 82% I/O API 调用)。
Translating C to Rust is a promising way to enhance the reliability of legacy system programs. Although the industry has developed an automatic C-to-Rust translator, C2Rust, its translation remains unsatisfactory. One major reason is that C2Rust retains C standard library (libc) function calls instead of replacing them with functions from the Rust standard library (Rust std). However, little work has been done on replacing library functions in C2Rust-generated code. In this work, we focus on replacing the I/O API, an important subset of library functions. This poses challenges due to the semantically different designs of I/O APIs in libc and Rust std. First, the two APIs offer different sets of types that represent the origins (e.g., standard input, files) and capabilities (e.g., read, write) of streams used for I/O. Second, they use different error-checking mechanisms: libc uses internal indicators, while Rust std uses return values. To address these challenges, we propose two static analysis techniques, origin and capability analysis and error source analysis, and use their results to replace the I/O API. Our evaluation shows that the proposed approach is (1) correct, with all 32 programs that have test suites passing the tests after transformation, (2) efficient, analyzing and transforming 422k LOC in 14 seconds, and (3) widely applicable, replacing 82% of I/O API calls.
DOI 原文 ·
@inproceedings{paperbot9497,
title = {Forcrat: Automatic I/O API Translation from C to Rust via Origin and Capability Analysis},
author = {Jaemin Hong and Sukyoung Ryu},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00130}
}