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

📅 2026-08-04
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
This work addresses the challenge that embedded C functions often fail to reuse across platforms despite semantic similarity and passing static analysis, primarily due to hardware incompatibilities. To tackle this, the authors propose a domain-aware retrieval-augmented generation (RAG) approach that integrates function comments, call graphs, and project documentation, leveraging eight embedding models—including BGE, GraphCodeBERT, and LLaMA-3—for multi-perspective representation. Crucially, the method incorporates hardware abstraction layer dependencies, peripheral interfaces, and register constraints into reuse assessment for the first time. Four novel hardware compatibility verifiers are introduced: peripheral token overlap, parameter count consistency, call graph dependency overlap, and structural branching patterns. Experimental results demonstrate a verification accuracy of 97.5%, substantially outperforming SonarQube, which exhibits a false positive rate as high as 93.6%, thereby effectively identifying reuse failures caused by hardware mismatches.
📝 Abstract
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).
Problem

Research questions and friction points this paper is trying to address.

embedded software reuse
hardware compatibility
static analysis limitations
function reuse detection
microcontroller platforms
Innovation

Methods, ideas, or system contributions that make the work stand out.

hardware-compatibility validation
retrieval-augmented generation (RAG)
embedded C reuse detection
domain-aware embedding
static analysis limitation
🔎 Similar Papers
No similar papers found.