TL;DR
Software debloating optimizes performance and security by stripping away unused features, but current tools often overfit to basic test cases—accidentally breaking critical edge cases or removing vital security checks. To solve this, LEADER leverages Large Language Models (LLMs) to read program documentation, automatically augment test suites, and act as a secure decision-maker in a neuro-symbolic code-pruning pipeline. The framework achieves a 95.5% test pass rate while reducing program size by 42.5% and slashing newly introduced vulnerabilities by 79.1%.
What Problem Does This Paper Address?
As software evolves, it naturally bloats to accommodate diverse platforms and user needs. However, individual users typically only need a small fraction of a program's features. This extra code doesn't just waste memory; it expands the software's "attack surface," leaving behind unnecessary vectors for exploitation.
To combat this, developers use input-based software debloating, which runs a program against a set of user-provided tests, analyzes code coverage, and aggressively prunes any code that wasn't executed. This introduces two major challenges:
- Functionality Loss (Overfitting): User tests rarely cover every edge case of a desired feature. For example, if a test checks
mkdir -p foo/bar, a traditional debloater might strip out the loop required to handle deeper paths likefoo/bar/baz, breaking the feature for unseen inputs. - Compromised Security: Safety mechanisms like null-pointer checks or array boundary guards are rarely triggered during normal testing. Traditional debloaters greedily remove these unexecuted blocks, inadvertently introducing severe vulnerabilities (like undefined behaviors or arbitrary code execution) into the "optimized" program.
Methods
The authors introduce LEADER (LLM-aidEd progrAm DEbloateR), a framework that injects semantic understanding into the debloating process through two main modules:
1. Documentation-Guided Test Augmentation
Instead of relying solely on sparse user inputs, LEADER uses an LLM to read the program's documentation (such as Unix man pages or --help text).
- Step A: The LLM extracts all supported features and use cases.
- Step B: It cross-references these features with the user's initial tests to identify which core functionalities the user actually wants to keep.
- Step C: The LLM generates a highly diverse, augmented test suite specifically targeting those desired features, ensuring high code coverage before pruning even begins.
2. Multi-Advisor-Aided Program Debloating
LEADER sets up a neuro-symbolic pipeline where traditional static analysis tools and an LLM work together:
- Debloating Advisor (Symbolic): Uses code coverage tools (
llvm-cov/gcov) and Abstract Syntax Tree (AST) parsing via Clang to find truly unexecuted code and redundant syntax (e.g., unused variables). - Security Advisor (Symbolic): Uses static analysis engines (
CodeChecker,Cppcheck,Infer) to run differential analysis on the original vs. debloated code, flagging any security rules violated by code removal. - Decision-Maker (Neural/LLM): The suggestions from both advisors are injected directly into the source code as inline annotations and comments. The LLM then reviews this contextualized code to make the final decision on how to safely refactor and prune the code without introducing vulnerabilities.
Datasets
The framework was evaluated across 25 classic C programs split into two widely accepted benchmarks:
- Util Benchmark: 10 standard GNU utility programs (including
bzip2,chown,date,grep,gzip,mkdir,rm,sort,tar, anduniq), totaling nearly 124,000 lines of code. - SIR (Software-artifact Infrastructure Repository) Benchmark: 15 complex programs (including
bash,flex,make,sed, andvim), scaling up to over 136,000 lines of code for a single application.
Key Insights and Ideas
- Documentation as a Specification: Traditional test augmentation relies on fuzzing (like AFL), which generates random, irregular inputs that often fail basic lexical analysis. By reading documentation, LLMs generate semantically valid tests that preserve core feature logic.
- Contextualizing the LLM: LLMs notoriously struggle with tracking exact line numbers in large codebases. LEADER bypasses this by embedding the static analyzer's warnings directly into the code as comments (e.g.,
/* Uninitialized Value... */). This allows the LLM to use its local semantic window to make accurate security decisions. - Refactoring over Pruning: Traditional tools simply delete lines of code. LEADER uses the LLM's generative capabilities to actively refactor bloated structures (e.g., condensing a 21-statement conditional block into a single, clean return statement), maximizing size reduction safely.
Key Results
LEADER was compared against several state-of-the-art debloating tools, including CHISEL, DEBOP, RAZOR, and CovA:
- High Correctness: On the Util benchmark, LEADER achieved a 95.5% test pass rate on unseen test cases, vastly outperforming the premier baseline tool, CovA, which scored just 73%.
- Substantial Reduction: It successfully reduced overall program size by 42.5% (and up to 54% on standard utilities).
- Vulnerability Mitigation: LEADER reduced pre-existing vulnerabilities by 16.5% more than CovA. More importantly, it decreased the introduction of new vulnerabilities by 79.1% compared to the baselines, proving the efficacy of the Security Advisor loop.
- Efficiency Balance: While purely heuristic tools like RAZOR run in seconds, they suffer from low correctness. LEADER averaged 84.7 minutes per program, striking a practical middle ground compared to heavy optimization tools like DEBOP, which take over 5 hours.
Limitations and Future Work
- Language Constraints: The current implementation and evaluation of LEADER are strictly tailored to C programs. Its performance on object-oriented or memory-safe languages (like Java or Rust) remains untested.
- Documentation Dependency: The quality of the test augmentation relies heavily on the availability of clear, comprehensive documentation (
manpages). Legacy or proprietary codebases lacking documentation would limit LEADER's effectiveness. - LLM Overhead: Invoking commercial LLMs iteratively is time-consuming and introduces token costs. Exploring parallel processing or fine-tuning smaller, local open-source models is noted as a necessary next step.
Summary updated