Page 28 - 《软件学报》2026年第6期
P. 28
屈晟 等: 面向 RISC-V 指令集多样性的兼容性感知多层级构建方法 2347
3
(State Key Laboratory for Novel Software Technology (Nanjing University), Nanjing 210023, China)
Abstract: The RISC-V instruction set architecture, characterized by its openness and modular design, promotes innovation and
customization in processor architecture, while simultaneously introducing severe software ecosystem fragmentation. Traditional cross-
platform software build mechanisms, such as on-site compilation, IFUNC, and Multilib, encounter significant challenges in the RISC-V
ecosystem, including limited compatibility, high maintenance overhead, and insufficient optimization granularity, which highlights the need
for new solutions. To address these issues, this study proposes a compatibility-aware multi-level compilation method for the RISC-V
platform—RuyiBuild toolchain. By adopting LLVM IR as the intermediate representation and integrating a non-intrusive compilation
interception mechanism, transparent adaptation to existing software build systems is achieved. As a result, the generated operating system
software packages simultaneously support compatibility across heterogeneous combinations of RISC-V extension instruction sets and
adaptive, extension-aware optimizations tailored to target execution platforms. This approach systematically resolves the dual-objective
challenge of achieving both high-performance binary optimization and broad compatibility under diverse instruction set extensions and
platform variations inherent in the RISC-V ecosystem. Centered on the extraction, deployment, transformation, and optimization of LLVM
IR, RuyiBuild establishes a comprehensive framework for cross-platform software distribution and fine-grained optimization. The
framework consists of four core mechanisms: a transparent dual-path compilation and LLVM IR extraction mechanism; a dynamic library
LLVM IR aggregation and link-time transformation mechanism; an LLVM IR deployment and automated RPM integration mechanism; a
client-cloud collaborative LLVM IR dynamic transformation and resource-adaptive scheduling mechanism. From an implementation
perspective, the RuyiBuild toolchain encapsulates compilation tools and system commands, enabling full-path LLVM IR extraction and
distribution without modifying source code or existing build systems. During deployment, synchronized distribution of LLVM IR and
traditional binaries is supported. Furthermore, to facilitate performance optimization across various target devices and microarchitectures,
client-side resource-aware deferred transformation and cloud-side multi-architecture adaptation with dynamic LLVM IR transformation are
provided. Experimental results show that RuyiBuild supports deployment across a wide range of RISC-V instruction set extensions and
microarchitecture combinations, while achieving a favorable balance among performance, compatibility, build overhead, and deployment
complexity. Consequently, this study provides a novel and effective solution for software build, deployment, and adaptation in the RISC-V
ecosystem, offering both academic value and practical potential.
Key words: RISC-V; LLVM IR; cross-platform compilation; software ecosystem fragmentation; multi-architecture adaptation; build system
transparency
1 引 言
近年来, 随着计算领域多样化应用需求的不断涌现, 传统的指令集架构 (如 x86 架构与 ARM 架构) 逐渐暴露
出其封闭性、扩展性不足、授权费用高昂等局限性问题 [1,2] . 作为应对这一挑战的全新方案, RISC-V 指令集架构
以其开放性、精简性和可扩展性的独特优势, 迅速获得学术界与产业界的广泛关注与认可 [3] . RISC-V 允许芯片
厂商根据特定性能需求和应用场景需求, 自由定制指令集扩展与微架构, 从而推动了芯片设计的灵活性与创新性 [4,5] .
同时为了满足标准化、大规模部署以及用户快速使用的需要, 如 openEuler、Debian、Ubuntu 等预编译二进
制 Linux 操作系统得到了广泛的使用, 为与纯理论含义上的操作系统内核进行区分, 一般称之为操作系统发行版
或直接简称为发行版. 这些操作系统均是以软件包为单位进行组织. 如何方便、快速、标准化地构建软件包, 并且
充分发挥硬件的性能就成为一个主要的研究课题. 如果使用贴近特定硬件特性的方式构建软件包, 那么将会带来
兼容性的巨大挑战; 反之, 如果使用通用硬件的特性, 那么又会导致无法发挥硬件最强性能, 这一般被称为碎片化.
当前各主流发行版普遍选择优先保障兼容性.
然而, 指令集扩展的高度自由化与微架构的多样化, 也给 RISC-V 生态系统带来更加严重的软件生态碎片化
问题 [6] . 不同厂商实施差异化的指令集扩展与微架构优化, 使得软件跨平台的兼容性与性能优化问题变得尤为突
出. 传统的软件分发模式 (如预编译二进制文件) 在 RISC-V 生态中面临难以逾越的困难, 若需覆盖所有可能的指
令集扩展组合与微架构, 软件包数量将呈现指数级增长, 严重提高了软件分发与维护成本; 而源码级的现场编译
(on-device compilation) 则受限于终端设备资源不足与用户体验要求, 难以推广实施 [7] .
针对上述问题, 目前学术界与产业界给出的解决方案主要基于两种思想: 一种是通过修改动态库的源代码, 从
函数或动态库级别提供面向不同指令集优化的版本, 在软件运行时, 可以根据当前硬件的特性选择适合的版本; 另

