面向嵌入式C软件的嵌入引导函数复用检测方法

An Approach for Embedding-Guided Function Reuse Detection in Embedded C Software

精选理由

复用嵌入式函数前,先看看这篇:RAG加硬件校验,SonarQube假阳性率93.6%,能帮你避免硬件不兼容的坑。

AI 摘要

论文提出一种面向嵌入式C软件的函数复用检测RAG流程,用注释、调用图和README增强函数表示,并集成8种嵌入模型与4个硬件兼容性验证器。在6个开源项目的184个函数、4815对候选上测试,SonarQube作为复用过滤器的假阳性率达93.6%,其中83.5%的失败源于静态分析无法发现的硬件环境不匹配。人工核验40对被拒的复用函数对后,验证器准确率为97.5%。诊断变体显示主要失败类别差异显著(McNemar卡方=294.0,p<0.001)。

原文 · arXiv: OpenAI

An Approach for Embedding-Guided Function Reuse Detection in Embedded C Software

Reusing embedded software functions across products is economically valuable but technically difficult: the same functionality implemented for two different microcontroller platforms can be entirely incompatible at the hardware level, even when the functions score above 0.90 cosine similarity and both pass SonarQube quality checks. Static analysis tools were designed to measure code quality, not hardware-domain compatibility, and have no model of peripheral interfaces, hardware abstraction layer (HAL) dependencies, or register-map constraints. This paper presents a domain-aware retrieval-augmented generation (RAG) pipeline for embedded C software reuse detection that addresses the hardware-compatibility gap directly. The pipeline enriches each function by extracting its existing inline comments, call-graph context, and a project README before embedding it with eight backbone models (MiniLM, MPNet, BGE, E5, GraphCodeBERT, OpenAI text-embedding-3-small, LLaMA 3 8B, StarCoder2 3B) acting as feature extractors. Four hardware-compatibility validators---covering peripheral token overlap, parameter count parity, call-graph dependency overlap, and structural branching pattern---filter candidates directly in the retrieval stack. Evaluated on six public embedded C software projects (184 functions, 4,815 above-plateau pairs), the pipeline reveals that SonarQube produces a 93.6% false-positive rate as a reuse filter, with 83.5% of failures caused by hardware-environment mismatches that static analysis cannot detect. Manual verification of 40 rejected pairs confirms 97.5% validator accuracy, and a diagnostic rule-injection variant identifies the dominant failure categories (McNemar chi-squared~=~294.0, p~$<$~0.001).