How nasa-sw-vnv/ikos works
Project Overview & Main Purpose
• IKOS serves as a static analyzer that processes source files (.c, .cpp, LLVM bitcode) and reports issues like buffer overflows.
• It provides a command-line “ikos” tool that orchestrates analysis, converts LLVM bitcode into an abstract representation (AR), executes a series of analyses, and finally generates reports.
• It also includes a Python interface for report generation (ikos-report, ikos-view) and has integration with LLVM/Clang for preprocessing and bitcode generation.
Core Components
• Frontend (frontend/llvm): This part wraps the LLVM integration. It handles parsing and converting the source code (via Clang) into LLVM bitcode. It implements modules for importing LLVM IR, applying various passes (such as lowering constant expressions, marking inlines, etc.).
• Analyzer (analyzer): The heart of the static analysis engine. This component implements the fixpoint iterators, various numerical and abstract domains, interprocedural and intraprocedural analyses, and checkers (e.g., for buffer overflow, division by zero, etc.). Notice how its file tree is divided into subdirectories for analysis, checkers, JSON handling, database (for storing results), and utilities.
• Core (core): This library forms the foundation of the abstract interpretation framework. It provides generic data structures (like control-flow graphs, abstract domains for numerical, memory, pointer, etc.) and algorithms (fixpoint computation, domain operations, etc.).
• AR Module (ar): This module translates LLVM bitcode into an Abstract Representation (AR) that is used by IKOS during subsequent analysis phases. It also contains transformation passes (like adding loop counters, simplifying the control-flow graph, and so on).
• Python Interfaces (analyzer/python): These modules help interface the underlying C++ analysis engine with reporting and configuration tools. Components such as ikos-view and ikos-report utilize these interfaces to generate web-based or CLI reports.
• Build/CI and Test Infrastructure: Directories like “cmake”, “script”, “test”, and GitHub workflows (in .github/workflows) show that the project uses CMake for building, has scripts to enforce quality (clang-format, clang-tidy), and automated tests for regression.
Diagramming Relationships & Data Flow
• The flow starts in the Frontend:
◦ Source code → Clang/LLVM → LLVM bitcode.
• Then pass this bitcode to the Analyzer:
◦ Analyzer leverages the Core libraries for abstract interpretation, which include various domains (numerical, memory, pointer, etc.) as well as fixpoint iterators.
• Concurrently, the AR module transforms intermediate LLVM representations into a more abstract form (AR) used in later analysis stages.
• In parallel, the Python modules provide capabilities for outputting the analysis results (either directly via the terminal or through a web-based view).
• The Build and Test system ensures correctness of these interactions, along with continuous integration (GitHub workflows).
Highlighting Architectural Patterns & Design Principles
• Modular design: IKOS is clearly segmented into well-defined components (frontend, analyzer, core, AR) that interact via clean interfaces.
• Layered Architecture: Lower-level libraries (core) support higher-level analysis (analyzer), and the frontend acts as the entry point.
• Separation of Concerns: Parsing, abstract domain computation, IR translation, and reporting are handled in different modules.
• Reusability/extensibility: The project structure (with its separate “analyzer”, “core” and “ar” modules) makes it easier to swap or extend parts of the system, such as adding new abstract domains or checkers.
Technologies and Frameworks
• Programming Language & Standards: C++14 is used for the core libraries and analysis engine.
• Build System: CMake is the central build scripting tool.
• Static Analysis & Compilation: LLVM/Clang play a pivotal role in converting source code into an analyzable form.
• Scripting & Reporting: Python scripts support pre- and post-analysis workflows.
• Database & Reporting: SQLite (and JSON libraries) are used to store and format the analysis results.