Ar (Unix)
Originally developed for Unix, the command is widely available on Unix-based systems, and similar commands are available on other platforms. An implementation is included in GNU Binutils.[2] In the Linux Standard Base (LSB), the command has been deprecated and is expected to disappear in a future release of that standard. The rationale provided was that "the LSB does not include software development utilities nor does it specify .o and .a file formats."[4] File format![]() The format of a file that results from using StructureAn archive file begins with a header that identifies the file type and is followed with a section for each contained file. Each contained file section consists of a header followed by the file content. The headers consist solely of printable ASCII characters and line feeds. In fact, an archive containing only text files is also a text file. The content of a contained file begins on an even byte boundary. A newline is inserted between files as padding, if necessary. Nevertheless, the size stored reflects the size excluding padding.[9] Archive headerThe first header, a.k.a. file signature, is a magic number that encodes the ASCII string Contained file headerEach file is preceded by a header that contains information about the file. The common format is as follows. Numeric values are encoded in ASCII and all values are right-padded with spaces (0x20).
VariantsVariants of the command were developed to address issues including:
BSDThe BSD implementation stores file names right-padded with ASCII spaces. This causes issues with spaces inside file names.[clarification needed] The 4.4BSD implementation stores extended file names[clarification needed] by placing the string "#1/" followed by the file name length in the file name field, and storing the real file name in front of the data section.[8] The BSD implementation traditionally does not handle the building of a global symbol lookup table, and delegates this task to a separate utility, To conform to POSIX, newer BSD implementations support the System V (or GNU)[clarification needed]The System V implementation uses a slash ('/') to mark the end of the file name which allows for the use of spaces without the use of an extended file name. Then[clarification needed], it stores multiple extended file names in the data section of a file[clarification needed] with the name "//", this record is referred to by future headers[clarification needed]. A header references an extended file name by storing a "/" followed by a decimal offset to the start of the file name in the extended file name data section.[15] The format of this "//" file itself is simply a list of the long file names, each separated by one or more LF characters. This is usually the second entry of the file, after the symbol table which always is the first. The System V implementation uses the special file name "/" to denote that the following data entry contains a symbol lookup table, which is used in ar libraries[clarification needed] to speed up access. This symbol table is built in three parts which are recorded together as contiguous data.
Some System V systems do not use this format. For operating systems such as HP-UX 11.0, this information is stored in a data structure based on the SOM file format. The special file "/" is not terminated with a specific sequence; the end is assumed once the last symbol name has been read.[clarification needed] To overcome the 4 GiB file size limit[clarification needed] some operating system like Solaris 11.2 and GNU use a variant lookup table. Instead of 32-bit integers, 64-bit integers are used in the symbol lookup tables. The string "/SYM64/" instead "/" is used as identifier for this table[16] WindowsThe Windows (PE/COFF) variant is based on the SysV/GNU variant. The first entry "/" has the same layout as the SysV/GNU symbol table. The second entry is another "/", a Microsoft extension that stores an extended symbol cross-reference table. This one is sorted and uses little-endian integers.[5][17] The third entry is the optional "//" long name data as in SysV/GNU.[18] Thin archiveThe GNU binutils and Elfutils implementations have an additional "thin archive" format with the magic number ExamplesThe following command creates an archive libclass.a with object files class1.o, class2.o, class3.o: ar rcs libclass.a class1.o class2.o class3.o The linker ld main.o -lclass See alsoReferences
External linksThe Wikibook Guide to Unix has a page on the topic of: Commands
|