In Rust We Trust - A Transpiler from Unsafe C to Safer Rust

被引:0
|
作者
Ling, Michael [1 ]
Yu, Yijun [1 ,2 ]
Wu, Haitao [1 ]
Wang, Yuan [1 ]
Cordy, James R. [3 ]
Hassan, Ahmed E. [3 ]
机构
[1] Huawei Technol, Toronto, ON, Canada
[2] Open Univ, Milton Keynes, Bucks, England
[3] Queens Univ, Kingston, ON, Canada
关键词
transpiler; safety; measurement; refactoring; code transformation;
D O I
10.1145/3510454.3528640
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Rust is a type-safe system programming language with a compiler checking memory and concurrency safety. For a smooth transition from existing C projects, a source-to-source transpiler can auto-transform C programs into Rust using program transformation. However, existing C-to-Rust transformation tools (e.g. the open-source C2Rust transpiler(1) project) have the drawback of preserving the unsafe semantics of C, while rewriting them in Rust's syntax. The work by Emre et el. [2] acknowledged these drawbacks, and used rustc compiler feedback to refactor one certain type of raw pointers to Rust references to improve overall safety and idiomaticness of C2Rust output. Focusing on improving API-safeness (i.e. lowering unsafe keyword usage in function signatures), we apply source-to-source transformation technique to auto-refactor C2Rust output using code structure pattern matching and transformation, which does not rely on rustc compiler feedback. And by relaxing the semantics-preserving constraints of transformations, we present CRustS(2) a fully-automated source-to-source transformation approach that increases the ratio of the transformed code passing the safety checks of the rustc compiler. Our method uses 220 new TXL [1] source-to-source transformation rules, of which 198 are strictly semantics-preserving and 22 are semantics-approximating, thus reducing the scope of unsafe expressions and exposing more opportunities for safe Rust refactoring. Our method has been evaluated on both open-source and commercial C projects, and demonstrates significantly higher safe code ratios after the transformations, with function-level safe code ratios comparable to the average level of idiomatic Rust projects.
引用
收藏
页码:354 / 355
页数:2
相关论文
共 50 条
  • [1] Translating C to Safer Rust
    Emre, Mehmet
    Schroeder, Ryan
    Dewey, Kyle
    Hardekopf, Ben
    [J]. PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2021, 5
  • [2] TOLERANT COATINGS IN RUST WE TRUST
    WINDSOR, B
    [J]. JOURNAL OF THE OIL & COLOUR CHEMISTS ASSOCIATION, 1988, 71 (04): : 103 - 105
  • [3] Securing UnSafe Rust Programs with XRust
    Liu, Peiming
    Zhao, Gang
    Huang, Jeff
    [J]. 2020 ACM/IEEE 42ND INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE 2020), 2020, : 234 - 245
  • [4] How Do Programmers Use Unsafe Rust?
    Astrauskas, Vytautas
    Matheja, Christoph
    Poli, Federico
    Muller, Peter
    Summers, Alexander J.
    [J]. PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2020, 4
  • [5] Fidelius Charm: Isolating Unsafe Rust Code
    Almohri, Hussain M. J.
    Evans, David
    [J]. PROCEEDINGS OF THE EIGHTH ACM CONFERENCE ON DATA AND APPLICATION SECURITY AND PRIVACY (CODASPY'18), 2018, : 248 - 255
  • [6] "In rust we trust". Hematite - the prospective inorganic backbone for artificial photosynthesis
    Bora, Debajeet K.
    Braun, Artur
    Constable, Edwin C.
    [J]. ENERGY & ENVIRONMENTAL SCIENCE, 2013, 6 (02) : 407 - 425
  • [7] CORROSIONEERING - OR - IN RUST THERE CAN BE NO TRUST
    GROVES, D
    [J]. NAVAL ENGINEERS JOURNAL, 1993, 105 (01) : 71 - 73
  • [8] On the Dual Nature of Necessity in Use of Rust Unsafe Code
    Zhang, Yuchen
    Kundu, Ashish
    Portokalidis, Georgios
    Xu, Jun
    [J]. PROCEEDINGS OF THE 31ST ACM JOINT MEETING EUROPEAN SOFTWARE ENGINEERING CONFERENCE AND SYMPOSIUM ON THE FOUNDATIONS OF SOFTWARE ENGINEERING, ESEC/FSE 2023, 2023, : 2032 - 2037
  • [9] Detecting Unsafe Raw Pointer Dereferencing Behavior in Rust
    Huang, Zhijian
    Wang, Yong Jun
    Liu, Jing
    [J]. IEICE TRANSACTIONS ON INFORMATION AND SYSTEMS, 2018, E101D (08): : 2150 - 2153
  • [10] WHY DONT WE RUST
    不详
    [J]. SCIENCE DIGEST, 1984, 92 (05) : 88 - 88