作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

计算机工程

• •    

基于QEMU的龙架构平台插桩软件

  • 发布日期:2025-05-22

An Instrumentation Software for LoongArch Based on QEMU

  • Published:2025-05-22

摘要: 随着软件规模和复杂性指数级地增长,对程序运行时行为的监控和分析变得越来越困难,动态二进制插桩技术是解决这一问题的有效手段,现有成熟的二进制插桩软件有Pin和Valgrind等,主要支持x86、ARM等主流架构,但在新兴的自主指令集架构上缺乏支持。龙架构作为我国自主研制的指令集架构,具有较好的自主性、先进性与兼容性,但其发展时间较短,生态环境尚不完善,特别是在调试工具链方面存在明显短板。为了填补这一空白,推动龙架构生态的成熟,推出一款支持龙架构的动态二进制插桩软件具有重要意义。本研究旨在设计并实现一款基于QEMU框架的动态二进制插桩软件,以支持龙架构的程序监控与分析。该软件对标Pin,设计实现了五个基础插桩粒度及相关插桩API,并在此基础上开发了20多个插桩工具,供用户直接使用或学习插桩工具的编写。为了提升框架性能,研究通过优化条件跳转指令的翻译、基本块链接和插桩内联等方法对框架进行了改进。性能测试结果表明,优化后的框架在指令级插桩效率上提升了100多倍,基本块级插桩效率提高了近33倍。最后,本研究将源代码在GitHub上开源,以促进龙架构生态的进一步发展,并为相关领域的研究者提供参考和学习资源。

Abstract: As software scale and complexity grow exponentially, monitoring and analyzing program runtime behavior has become increasingly challenging. Dynamic binary instrumentation is an effective solution to this problem, with mature tools like Pin and Valgrind supporting mainstream architectures such as x86 and ARM. However, these tools lack support for emerging domestic instruction set architectures, such as LoongArch. LoongArch, a self-developed instruction set architecture in China, exhibits high levels of autonomy, advancement, and compatibility. Nevertheless, due to its relatively short development history, its ecosystem remains incomplete, particularly in the debugging toolchain. To address this gap and promote the maturation of the LoongArch ecosystem, developing a dynamic binary instrumentation tool for LoongArch is of significant importance. This study aims to design and implement a dynamic binary instrumentation tool based on the QEMU framework to support program monitoring and analysis on LoongArch. The tool, modeled after Pin, implements five fundamental instrumentation granularities and related APIs, along with over 20 instrumentation tools for direct use or as learning resources for tool development. To enhance performance, the framework was optimized through improvements in conditional jump instruction translation, basic block linking, and instrumentation inlining. Performance tests demonstrate that the optimized framework achieves over 100 times improvement in instruction-level instrumentation efficiency and nearly 33 times improvement in basic block-level instrumentation efficiency. Finally, the source code has been open-sourced on GitHub to facilitate the further development of the LoongArch ecosystem and provide a reference for researchers in related fields.