计算机科学 ›› 2024, Vol. 51 ›› Issue (11A): 240200115-9.doi: 10.11896/jsjkx.240200115

• 计算机软件&体系架构 • 上一篇    下一篇

面向龙芯处理器的一种CompCert可信编译器重定向实现

胡少儒, 王隽伟, 王生原   

  1. 清华大学计算机系 北京 100084
  • 出版日期:2024-11-16 发布日期:2024-11-13
  • 通讯作者: 王生原(wwssyy@tsinghua.edu.cn)
  • 作者简介:(cn.hushaoru@gmail.com)
  • 基金资助:
    国家重点研发计划(2022YFB3305204)

Implementation of Retargeting CompCert Trusted Compiler for Loongson Processors

HU Shaoru, WANG Juanwei, WANG Shengyuan   

  1. Department of Computer Science and Technology,Tsinghua University,Beijing 100084,China
  • Online:2024-11-16 Published:2024-11-13
  • About author:HU Shaoru,born in 1999,B.S.His main research interests include formal verification and compiler,and so on.
    WANG Shengyuan,born in 1964,Ph.D,associate professor.His main research interests include programming languages and systems,compilers and formal methods.
  • Supported by:
    National Key R&D Program of China(2022YFB3305204).

摘要: CompCert是著名的C语言可信编译器,它借助于交互式定理证明工具Coq实现,能够确保生成的目标汇编代码保持源代码的语义,具有极高的可信度,近年来被广泛应用于学术界和工业界的许多安全攸关任务的研发工作中。CompCert编译器的当前版本支持多种目标机结构,然而目前尚缺乏针对国内自主研发处理器的版本,如龙芯(Loongson)处理器体系结构(LoongArch)。将CompCert重定向到龙芯等国产处理器,对我国安全攸关软件领域的发展大有裨益。本文对 CompCert 编译器的设计理念、框架结构和龙芯架构的特点进行分析,改造 CompCert 编译器的后端,使其可以生成能在龙芯处理器上运行的汇编代码,并细致阐述不同模块的工作内容。重定向到龙芯处理器的 CompCert 编译器具有接近 GCC-O1 的性能,可满足许多场景的使用。

关键词: CompCert, 编译器, 编译器重定向, 龙芯架构, 形式化验证的编译器, Coq

Abstract: CompCert is a well-known trustworthy C-language compiler,which is highly credible and has been widely used in many research and development work in academia and industry in recent years.CompCert proves the property that the target assembly code it produces can keep the semantics of the source code,with Coq,an interactive proof assistant.The CompCert compiler now supports multiple target machine architectures,but there is currently a lack of versions specifically designed for domestically developed processors,such as the Loongson processor architecture(LoongArch).Retargetting CompCert to domestic processors such as Loongson is of great benefit to the development of safety-critical software in China.This paper analyzes the design and the structure of the CompCert compiler backend and the characteristics of Loongarch,revises the backend of the CompCert compiler to make it available to generate the assembly code suitable to run on the Loongson processor,and presents the work of the different modules.The revised CompCert compiler,which retargets to Loongson processors,has performance competitive with GCC at optimization level 1,and can meet the needs of various scenarios.

Key words: CompCert, Compiler, Compiler retargeting, Loongarch, Formally verified compilers, Coq

中图分类号: 

  • TP314
[1]YANG X J,CHEN Y,ERIC E,et al.Finding and understanding bugs in C compilers[C]//Proceedings of the 2011 ACM SIGPLAN Conference on Programming Language Design and Implementation(PLDI 2011).2011:283-294.
[2]ZHANG Q R,SUN C N,SU Z D.Skeletal Program Enume-ration for Rigorous Compiler Testing[C]//Proceedings of the 2017 ACM SIGPLAN Conference on Programming Language Design and Implementation(PLDI 2017).2017.
[3]MCCARTHY JPAINTER J.Correctness of a compiler for arithmetical expressions[C]//Mathematical Aspects of Computer Science,volume 19 of Proceedings of Symposia in Applied Ma-thematics.1967:33-41.
[4]MILNER R,WEYHRAUCH R.Proving compiler correctness in a mechanized logic[C]//Proceedings of 7th Annual Machine Intelligence Workshop,volume 7 of Machine Intelligence.1972:51-72.
[5]DAVE M A.Compiler verification:a bibliography[J].ACMSIGSOFT Software Engineering Notes,2003,28(6):2-2.
[6]LEROY X.Formal verification of a realistic compiler[C]//Communications of The ACM.2009:107-115.
[7]LEROY X.Formal certification of a compiler back-end or:pro-gramming a compiler with a proof assistant[C]//Proceedings of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.2006:42-54.
[8]PNUELI A,SIEGEL M,SINGERMAN E.Translation Valida-
tion[C]//Proceedings of TACAS'98,Lecture Notes in Compu-ter Science.1998:151-166.
[9]KÄSTNER D,LEROY X,BLAZY S,et al.Closing the gap-the formally verified optimizing compiler CompCert[C]//Developments in System Safety Engineering:Proceedings of the Twenty-fifth Safety-critical Systems Symposium(SSS'17).2017:163-180.
[10]LEROY X,BLAZY S.Formal verification of a C-like memory model and its uses for verifying program transformations[J].Journal of Automated Reasoning,2008,41(1):1-31.
[11]YANG P,WANG S Y.Analysis of Target Code GenerationMechanism of CompCert Compiler[J].Computer Science,2020,47(9):17-23.
[12]LEROY X.A formally verified compiler back-end[J].Journal of Automated Reasoning,2009,43(4):363-446.
[13]GEORGE L,APPEL A W.Iterated register coalescing[J].ACM Trans.Prog.Lang.Syst.,1996,18(3):300-324.
[14]RIDEAU S,LEROY X.Validating register allocation and spilling[C]//CC 2010.2010:224-243.
[15]BLAZY S,ROBILLARD B,APPEL A W.Formal verification of coalescing graph-coloring register allocation[C]//ESOP 2010.2010:145-164.
[16]龙芯中科.从必然王国到自由王国,龙芯重磅推出自主指令系统架构 LoongArch [EB/OL].[2021-05-10].https://www.loongson.cn/newsDetails/1913.
[17]龙芯中科.重磅发布|基于龙芯架构的新一代处理器龙芯 3A5000 正式发布[EB/OL].[2021-09-03].https://www.loongson.cn/newsDetails/22.
[18]龙芯中科技术股份有限公司.龙芯架构参考手册[M].2021.
[19]胡伟武等.计算机体系结构基础[M].机械工业出版社,2021.
[20]Loongson Technology Corporation Limited.Loongarch elf abispecification[OL].https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html.
[21]LEROY X,BLAZY S,KÄSTNER D,et al.CompCert-A Formally Verified Optimizing Compiler [C]//ERTS 2016.2016..
[22]胡少儒.CompCert 编译器的龙芯处理器重定向[D].Beijing:Tsinghua University,2022.
[23]王隽伟.机器证明的CompCert编译器龙芯处理器后端[D].Beijing:Tsinghua University,2023.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!