Introduction
A .a file is a static library on Linux, macOS and other Unix-like
systems: a bundle of object files (.o, in
ELF or Mach-O
format) packed with the ar archiver. When a program is linked against it,
the linker copies in only the object files that define something the program uses.
Library names follow the pattern libname.a, which the option
-lname finds. A .a file can also be assembly source text, and
a universal library on macOS is a Mach-O universal file holding one archive per
processor.
The ar archive format is older than static libraries and is used for other things
too: a Debian package is an ar archive, and Windows
static libraries (.lib) use a variant of
it.
Variations
| Format | Variation | About | Open |
|---|---|---|---|
.A | System V and GNU static library | The ar archive format of Linux and most Unix systems. | Open |
.A | BSD and macOS static library | The ar archive format of macOS and the BSDs. | Open |
.A | GNU thin archive | An archive that lists its members but leaves their data in other files. | Open |
.A | AIX big archive | IBM AIX’s archive with linked members and 32-bit and 64-bit symbol tables. | Open |
.A | AIX small archive | The older AIX archive: linked members and one symbol table, in narrower fields. | Open |
System V and GNU static library
Used on Linux and most Unix systems. A symbol index is a member named
/, and a member named // holds long names.
BSD and macOS static library
Used on macOS and the BSDs. The symbol index is a member named
__.SYMDEF, and a long name sits right after the member’s header, marked
by #1/ and its length in the name field.
GNU thin archive
Starts with !<thin>\n instead of !<arch>\n. It
records the members but leaves their contents in the original files.
AIX big archive
Used by IBM AIX for archives of 32-bit and 64-bit objects. Starts with
<bigaf>\n and holds its offsets as decimal text: the members are a doubly linked list,
followed by a member table and 32-bit and 64-bit global symbol tables.
AIX small archive
The older AIX form, starting with <aiaff>\n: the same design with 12-byte fields and a
single symbol table.
Not described
The explorer reads the GNU, BSD and thin archive forms and their members. Member names, sizes and the symbol
index were compared with LLVM 22’s llvm-ar t, llvm-ar tv and
llvm-nm --print-armap on 9,161 distinct archives (6,595 GNU, 1,705 BSD, 861 COFF) with no
difference. ELF, Mach-O, WebAssembly, LLVM bitcode and nested-archive members open in the explorer’s own
viewers. A damaged archive is reported, not guessed at: a long name that points past the end of
// or has no // member, a name field such as /1x, a symbol index whose
count does not fit its member, and symbol offsets or member numbers that point at no member each give a problem
message, and the built damaged files were compared with llvm-ar t and
llvm-nm --print-armap. The statements about the GNU layout (the 60-byte header and its field sizes,
!<arch> and !<thin>, even offsets padded with a newline, // for
long names, / as the symbol index with big-endian numbers, /SYM64/ for archives past
4 GB, #1/N names in the BSD form) were checked against GNU Binutils 2.47
bfd/archive.c and include/aout/ar.h, and the BSD form against the macOS
ar(5) page.
Known, not yet covered
- Viewer: the members of a thin archive are separate files, so only their headers are
shown. The comparison covered one home-made thin archive, and the 64-bit
/SYM64/index was checked only on a built file, because no real one was found on this Mac. - Viewer: the AIX big and
small archives have pages and a reader of their own.
Their members are XCOFF objects, which have no viewer here and show as bytes; the big archive was checked
against
llvm-aroutput only, and the small one against a hand-made file only. - Viewer: the layout of the Windows
/<XFGHASHMAP>/member (a Windows SDK control-flow-guard table) is not known; it is labelled and its bytes are shown. The viewer does not count it as a member, butllvm-ar tstill lists it, because LLVM only accepts its name. - Viewer: GNU Binutils also reads the older
ARFILENAMES/long-name member and takes a name such as/1xas offset 1; the viewer follows LLVM, which does neither. - Viewer: the symbol-index and ARM64EC problem messages were checked against LLVM only on built files, not on damaged real libraries.
- Viewer: every long-name problem is listed, however many there are: the problems list shows the first 500 and pages through the rest, with the true count. Every member whose name has a problem is marked “bad long name” in the Members table.
Unknown
- Reference: why 11 of 340 real OMF libraries do not place names in the dictionary where the hash rule says they should; the viewer shows the dictionary as a field, not an error.
Also used for
- Assembly language source – Machine instructions as text; the syntax varies by assembler and processor.
Links
Software
- GNU Binutils – GNU’s binary tools, with
ar,ranlibandnm(Linux, macOS, Windows) - LLVM – compiler toolkit with
llvm-arandllvm-nm(Linux, macOS, Windows) - Xcode – Apple’s development environment, with
arandlibtool(macOS) - 7-Zip – free archiver that can list and extract the members (Windows)
Developers
- object – crate that reads ar archives and the object files inside (Rust)
Reference
- ar(5) – the FreeBSD manual page for the archive format and its variants