LinuxCommandLibrary

llvm-ar

Create, modify, and extract from archives

TLDR

View documentation for the original command

$ tldr ar
copy

SYNOPSIS

llvm-ar <command> [<options>] <archive> [<member>...]

PARAMETERS

d
    Delete members from the archive. If no member is specified, nothing is deleted.

m
    Move members within the archive. Used with a, b, or i to specify placement relative to an existing member.

p
    Print the contents of the specified members to standard output. If no member is given, all members are printed.

q
    Quick append. Appends members to the end of the archive without checking for duplicates. This is faster than r but less robust.

r
    Replace or add members to the archive. If a member with the same name already exists, it is replaced; otherwise, it is added. Often used with u.

s
    Write an object file index (symbol table) into the archive. This is typically done by default for new or modified archives.

t
    Display a table of contents of the archive. Lists the names of the members. Often used with v for more detail.

x
    Extract members from the archive. If no member is specified, all members are extracted.

a <posname>
    Place new members after the existing member named posname when using r or m.

b <posname>
    Place new members before the existing member named posname when using r or m. (Same as i).

c
    Create the archive if it does not exist, without issuing a warning. Usually implied by operations like r or q.

i <posname>
    Synonym for b. Place new members before the existing member named posname.

N <count>
    Use the first count files with the specified name. Useful when duplicate names exist in the archive.

P
    Use the full pathnames when matching entries in the archive. By default, only base names are used.

S
    Do not write an object file index (symbol table) into the archive. This can save space but might impact linker performance.

T
    Create a 'thin' archive. A thin archive contains only references to the member files, not their actual contents. Original files must remain accessible.

u
    Update only. When used with r, only replace members if their modification date is newer than the corresponding member in the archive.

v
    Verbose mode. Display a more detailed output for the given operation, such as file sizes and modification times.

--help
    Display a summary of command-line options and exit.

--version
    Display version information and exit.

DESCRIPTION

llvm-ar is a command-line utility from the LLVM project used to create, modify, and extract from archives (static libraries). It provides functionality very similar to the standard ar command found on Unix-like systems, but with native support for LLVM bitcode files in addition to traditional native object files. This makes it an integral part of the LLVM toolchain, enabling the construction of static libraries from code compiled with clang or other LLVM frontends, including those containing intermediate LLVM bitcode.

It's especially valuable in cross-compilation scenarios or when building projects that require a pure LLVM-based build environment. llvm-ar ensures consistent archive management across different platforms and architectures supported by LLVM, providing a robust tool for linking and packaging compiled code.

CAVEATS

While llvm-ar aims to be a compatible drop-in replacement for GNU ar, minor behavioral differences or unsupported GNU extensions might exist. Its primary advantage is native support for LLVM bitcode, which traditional ar utilities do not handle.

Thin archives (created with -T) are powerful for reducing build times and archive sizes, but they introduce a dependency: the original member files must persist and be accessible at their original paths relative to the archive for linking to succeed. Moving a thin archive without its referenced files will break it.

ROLE IN BUILD SYSTEMS

llvm-ar is commonly integrated into modern build systems such as Make, CMake, Ninja, and Bazel. These systems invoke llvm-ar to assemble compiled object files (.o) and bitcode files (.bc) into static libraries (.a files). Its seamless operation with clang and lld simplifies toolchain configuration, ensuring that projects compiled with LLVM can utilize standard build practices without requiring a mixed GNU/LLVM toolset. This integration is crucial for maintaining efficient and reproducible build processes, especially in continuous integration environments.

HISTORY

llvm-ar is an integral part of the LLVM project, which was started at the University of Illinois in 2000. Its development was driven by the need for a modern, modular, and reusable compiler infrastructure. As part of this vision, llvm-ar was created to provide a complete, self-contained toolchain that could handle both traditional object files and LLVM's intermediate representation (bitcode). This allows for a consistent build experience across various platforms and architectures, making it a cornerstone for cross-compilation and advanced compiler research.

SEE ALSO

ar(1), ranlib(1), clang(1), lld(1)

Copied to clipboard