[Feature] support abi_check, Identify potential ABI incompatibility issues #17886
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ABI Check Tool
Overview
abi_check.pyis a Python tool designed for checking binary compatibility between different versions of ELF files and static libraries. It helps ensure that Application Binary Interface (ABI) compatibility is maintained when updating firmware components, preventing runtime errors caused by incompatible changes.What is ABI Compatibility?
Application Binary Interface (ABI) compatibility refers to the binary compatibility between compiled code and libraries. When you have static libraries (
.afiles) that were compiled against one version of a kernel/ELF, they must continue to work correctly when linked against a new version. ABI compatibility ensures that:Why ABI Check is Needed
Problem Scenario
In embedded systems, it's common to have:
If the kernel/ELF changes its internal structures or function signatures without proper versioning, previously compiled static libraries may:
Example Issue
Consider this structure change in a semaphore implementation:
Old Version:
New Version:
A static library compiled against the old version would try to access
waitlistat offset 4, but in the new version, accessing that memory would be undefined behavior. This is exactly the kind of issueabi_checkhelps detect.Features
1. API Signature Extraction
Extract external API function signatures used by static libraries from an ELF file.
What it does:
2. Version Comparison
Compare function signatures between two different ELF versions.
What it detects:
3. Structure Consistency Check
Check if structures with the same name have different member definitions within a single ELF file.
What it detects:
Installation
Prerequisites
The tool requires:
Usage
Command-Line Options
Use Case 1: Extract API Signatures
Extract all external APIs used by static libraries and find their signatures in the ELF file.
Output:
[ [ [ "sem_wait", { "return": { "type": "int", "size": 4, "field": [] }, "parameters": [ { "type": "FAR sem_t *", "size": 4, "field": [] } ] } ], [ "open", { "return": { "type": "int", "size": 4, "field": [] }, "parameters": [ { "type": "FAR const char *", "size": 4, "field": [] }, { "type": "int", "size": 4, "field": [] } ] } ] ], [ "undefined_function_1", "undefined_function_2" ] ]The JSON output contains:
With dump option:
Output to console:
Use Case 2: Compare Two Versions
Compare API signatures between old and new firmware versions.
Example output showing incompatibilities:
Use Case 3: Structure Consistency Check
Check for structure definition inconsistencies within a single ELF file.
Example output showing structure mismatch:
This output shows that
struct sem_shas two different definitions at different source locations, which is a potential ABI issue.Use Case 4: Verify Static Library Compatibility
When static libraries contain debug information, you can verify if they match the ELF file.
This generates two files:
api_signatures.json- API signatures from ELFlib_api_signatures.json- API signatures from static librariesYou can then compare these to ensure compatibility.
Workflow Examples
Firmware Update Validation
When updating firmware while keeping static libraries unchanged:
CI/CD Integration
Integrate ABI checking into your build pipeline:
Troubleshooting
Error: "elf and lib must be provided"
You must provide both an ELF file and at least one static library:
Error: "Error: elf must be provided"
When using
--struct_check, you must provide an ELF file:Warning: "File already exists, will be overwritten"
The tool warns before overwriting existing JSON files:
# Specify different output file to avoid overwriting abi_check.py -e nuttx.elf -a libapp.a -j new_signatures.jsonMissing pahole
If you get an error about
pahole, install the dwarves package:Function not found in ELF
If you see warnings about functions not found in the ELF file:
Function some_function not found in elf fileThis means:
Technical Details
How It Works
Symbol Collection:
.objfiles from static libraries usingar xSignature Extraction:
Structure Analysis:
paholeto dump structure layoutsComparison:
Output Format
The JSON output structure:
Best Practices
Limitations
-gflag