File format · .sa
Unix Stub Library Files: How They Work and How to Repair Them
A clear guide to Unix stub libraries: what the linker stores in them, why they stop working, and what our engineers can recover from a damaged file.
A stub library is the smallest library file a Unix toolchain can produce: it holds the symbol information a linker needs and almost nothing else. Programs never run from it. Its whole job is to let a build succeed before the real shared object is present or convenient to use. This page explains what goes into one, why these files break, and what we can get back when they do.
What is a Unix stub library?
A stub library is a library file that holds symbol records instead of executable code. At build time the linker reads it to learn which functions and variables a shared object will provide. The finished program carries unresolved references to those names. When the program starts, the dynamic linker binds each reference to the real code. Linking uses the stub; running never does.
On Linux, the BSDs and macOS, a stub rarely exists as a separate file. Formats such as ELF and Mach-O describe executables and libraries alike, so one file serves both linking and loading. A distinct stub matters where that arrangement fails: when the shared object is awkward to link against, or when it cannot be present on the machine doing the build.
The idea travels under several names. Unix-like systems speak of shared objects, or dynamic shared objects, usually with .so names. Windows calls the same concept a dynamic-link library and pairs it with an import library, which is a stub in all but name. On AIX, the subject of much of this page, the stub library is an explicit artifact of the linker.
The systems that create stub libraries
IBM AIX is the classic source of stub libraries. There a shared library typically lives as a shared object inside an archive file, and the system linker records the exported symbols in a stub library kept with it. Later builds link against that stub rather than the shared object. IBM's own linker documentation is authoritative on the exact layout, so consult it before scripting around these files.
Cross-compilation toolchains and vendor SDKs produce stubs too. A kit may ship a small library exporting the same symbols as the real runtime component, so your build resolves cleanly on a machine that will never run the code. Licensing often drives this: the interface may be published while the implementation may not.
What is inside the file?
A stub library is almost always an archive, the same container format used for static libraries. The archive holds one or more members, each preceded by a header carrying its name, size and mode. An index lists the symbols those members export. On AIX the members are XCOFF objects; elsewhere ELF objects dominate. No machine code is present, so the files stay small, often a few kilobytes.
All of the file's value sits in that metadata. Symbol names, member names, type fields and version tags are what the linker consumes. Damage to the index or headers disables the whole file, even though there is no code to corrupt in the usual sense.
How do stub libraries become corrupt or unreadable?
Because the files are small and purely structural, the failures are structural too. These are the patterns we see most:
- Truncated transfers. An archive cut short mid-copy fails the first integrity check, and tools report it as not an archive at all.
- Interrupted writes. A build killed while the linker or archiver is writing leaves a partial member or a half-updated index.
- Stale symbol indexes. Editing an archive with a different archiver can leave the index pointing at members that moved or no longer exist. Linker errors then blame missing symbols.
- Format mismatches. Feeding a 32-bit stub to a 64-bit link, or an XCOFF stub to an ELF toolchain, produces errors that look like corruption but are not.
- Storage and backup damage. Failing disks, damaged archives inside backups, or a corrupt compressed wrapper all take their toll.
What can be recovered from a damaged stub library?
Recovery here is reconstruction more than repair, and the outlook is usually good. We can typically recover the full export list, the member inventory, and the header fields the linker needs. On AIX, where archives often hold the real shared object alongside the stub, that object's code and data are recoverable candidates too.
A destroyed stub is often less serious than it appears. If the shared object survives, its dynamic symbol table names every export, and a fresh stub can be generated from it. That path rescues builds even when the original stub file is unsalvageable. For the wider problem, see our Unix library and archive repair service.
How does our recovery process work?
Our engineers begin with the container, not the symbols. We read the archive headers, walk the members, and map exactly where the structure broke. Readable members are extracted and each object header is validated against the platform's object format.
We then rebuild what the linker needs. The symbol index is reconstructed from the surviving members, or regenerated from the shared object's export table when that is the sounder source. The archive is reassembled, and we verify the result by performing an actual link against it. A stub is only fixed when a toolchain accepts it.
FAQ
Does a damaged stub library affect a running program?
No. The stub is a build-time artifact; at run time the loader works from the shared object alone. The damage surfaces at the next compile or link, which is often the first sign anything is wrong.
Is a stub library the same thing as a static library?
Not quite, though both are archives and both usually carry the same .a extension. A static library holds complete compiled code that the linker copies into your executable. A stub holds names only. Confusing the two produces either unresolved symbols or unexpected code bloat.
Can a stub library be rebuilt rather than repaired?
Often, yes. When the shared object is intact, its exports define the stub completely, and the linker can regenerate one. We do this routinely when an archive index has been destroyed but the shared object is sound.
Why does the linker reject a file whose size looks correct?
Because linkers check structure, not size. A broken member header, a stale index or a wrong object format each produce rejection messages that read like corruption. Comparing the file against a known good archive from the same toolchain usually pinpoints the cause.
If a stub library is blocking your build, we can look at it. Send us the file, or the archive that contains it, and we will tell you what is recoverable before any charge. Start with our free evaluation and we will take it from there.
Send us your .sa file for a free evaluation
Our recovery engineers will tell you exactly what can be recovered — at no cost. There is no charge if we cannot recover your data.
Start a free evaluation