高级检索

    面向LoongArch边界检查访存指令的GCC优化实现

    GCC Optimization for LoongArch Memory Accessing Instructions with Bound-Checking

    • 摘要: 为了减少内存安全检查的开销,LoongArch指令集架构引入了边界检查访存类指令. 然而,作为一种新的内存访问指令,目前GCC(GNU compiler collection)编译器不支持该类指令,LoongArch硬件能力不能得到充分利用. 针对此LoongArch边界检查访存指令改进了GCC编译器,实现利用该类指令优化程序的内存安全检查. 具体而言,完成了3个方面的工作:1)设计实现了针对边界检查访存指令的内建函数;2)改进GCC RTL(register transfer language)阶段的优化器,使其能够识别无异常处理和带异常处理2种情况的边界检查访存语义,并自动优化;3)面向LoongArch边界检查访存指令触发的边界检查异常(bound check exception,BCE),设计了新的Linux内核异常信号SIGBCE和相应的运行时库glibc(GNU C library)的信号处理函数,实现了边界检查异常处理. 通过在GCC 12.2.0和龙芯3C5000L服务器进行实验,验证了改进后编译器不仅能正确使用新引入的边界检查访存指令,并在某些安全函数中带来接近20%的性能提升. 完善了LoongArch生态、推进了LoongArch指令集发展. 对此类特定指令编译器优化工作有一定的借鉴意义.

       

      Abstract: LoongArch ISA (instruction set architecture) introduces new memory accessing instructions with bound-checking to decrease the overhead of memory security check. However, as a new type of memory accessing instruction, the existing GCC (GNU compiler collection) compiler tools cannot support it and thus LoongArch based hardware remains underutilized. Therefore, in this paper, we revise the GCC compiler with the LoongArch memory accessing instructions to optimize the memory security check. Specifically, our work is divided into three parts: 1) designs built-in functions for the memory accessing instructions; 2) improves the RTL (register transfer language) optimizer of GCC to recognize two kinds of semantic patterns of memory accessing instructions with bound-checking, which are non-exception handling and exception handling; 3) implements a new exception signal SIGBCE for the bound check exception BCE that is raised by CPU in Linux kernel, and implements the corresponding signal handling function in glibc (GNU C library) to deal with the bound check exception. The experiments on GCC 12.2.0 and Loongson 3C5000L server show that the revised compiler is able to correctly employ the new memory accessing instructions and bring an acceleration of approximately 20% in some security routines. Our work improves the ecosystem of LoongArch and boost the development of LoongArch ISA. It will also be referential to GCC optimization for the specialized instructions.

       

    /

    返回文章
    返回