Question Details

No question body available.

Tags

linux clang llvm

Answers (1)

Accepted Answer Available
Accepted Answer
July 10, 2026 Score: 0 Rep: 24 Quality: High Completeness: 80%

There is no universal directory list that is safe for every LLVM binary release. It depends on:

  • whether clang is dynamically linked against bundled LLVM libraries;

  • whether you use the system linker or lld;

  • whether C++ uses the system libstdc++ or bundled libc++;

  • whether you need sanitizers, profiling, OpenMP, or cross-compilation.

For ordinary native C and C++ compilation using the Linux system’s GCC runtime and libstdc++, the practical minimum is usually:

clang-minimal/ ├── bin/ │ ├── clang │ ├── clang++ -> clang │ └── clang- # when clang is a symlink to this file ├── lib/ │ ├── libLLVM.so # only if required by ldd │ ├── libclang-cpp.so # only if required by ldd │ └── clang/ │ └── / │ ├── include/ # Clang builtin headers │ └── lib/ │ └── linux/ # compiler-rt libraries, when used └── libexec/ # generally unnecessary

What must normally be kept

bin/clang and bin/clang++

Keep the real executable and all symlinks needed to reach it:

readlink -f bin/clang readlink -f bin/clang++

Frequently the layout is:

bin/clang -> clang-22 bin/clang++ -> clang bin/clang-22

Deleting clang-22 while preserving only the symlink breaks the compiler.

Clang’s resource directory

Run:

./bin/clang -print-resource-dir

It will normally print something such as:

/path/to/llvm/lib/clang/22

At minimum, preserve:

lib/clang/22/include/

This contains compiler-provided headers such as:

stddef.h stdarg.h stdint.h limits.h immintrin.h

These are not the same as the top-level include/ directory.

Preserving the entire:

lib/clang//

is the safest approach. Its lib/linux/ directory may contain compiler runtime, sanitizer, profiling, and builtins libraries.

Shared libraries required by the executable

Check the actual binary:

ldd "$(readlink -f ./bin/clang)"

Keep any dependency resolved from inside the extracted LLVM directory, typically files such as:

lib/libLLVM.so. lib/libclang-cpp.so.

System libraries such as libc.so.6, libstdc++.so.6, libz.so, and libtinfo.so do not need to be copied from LLVM.

Also preserve symlink chains. For example:

libLLVM.so -> libLLVM.so.22.1 libLLVM.so.22.1

Official packages differ: some Clang executables contain most LLVM components directly, while others depend on shared LLVM libraries. Therefore ldd is more reliable than a fixed filename list.

Usually removable

For normal compilation, these can generally be deleted:

include/ LLVM and Clang development API headers share/doc/ share/man/ share/clang/ helper scripts and editor integrations share/scan-build/ share/scan-view/ lib/cmake/ CMake package metadata for LLVM development lib/pkgconfig/ libexec/ analyzer/helper programs, unless explicitly used examples/ tests/ docs/ python/

The top-level include/ directory is mainly needed when compiling software that uses LLVM or Clang as libraries. It is not where Clang’s builtin C headers reside.

Most executables in bin/ can also be removed, including tools such as:

llvm-ar llvm-nm llvm-objdump llvm-config clangd clang-format clang-tidy lldb opt llc

Keep a tool only when your build system invokes it.

Linker requirements

Clang is a compiler driver: it invokes other programs for preprocessing, compilation, assembly, and linking.

On normal Linux installations, Clang can use the system GNU linker:

/usr/bin/ld

In that case, bundled ld.lld is unnecessary.

To use LLVM’s linker with:

clang -fuse-ld=lld main.c

preserve:

bin/ld.lld

and any symlink it uses.

See what Clang invokes with:

./bin/clang -### main.c -o main ./bin/clang++ -### main.cpp -o main

-### prints commands without executing them.

C++ standard-library requirements

Clang does not, by itself, provide the complete C++ standard library. A normal Linux configuration commonly uses GCC’s libstdc++ headers and runtime. Clang searches known GCC installations for items such as libstdc++, its headers, and startup objects.

Therefore, with a normal distro GCC installation, you do not need bundled libc++ files. Verify using:

echo | ./bin/clang++ -E -x c++ - -v

The output shows the selected C++ header search paths.

When compiling explicitly with libc++:

clang++ -stdlib=libc++ main.cpp

you must retain its components, commonly:

include/c++/v1/ lib/libc++.so lib/libc++abi.so lib/libunwind.so # depending on its configuration

This is a different case from using the system libstdc++.

Sanitizers and profiling

If you need options such as:

-fsanitize=address -fsanitize=undefined -fprofile-instr-generate --coverage

keep the relevant runtime archives under:

lib/clang//lib/linux/

Sanitizers require runtime libraries in addition to compiler instrumentation.

If saving a few additional megabytes is not important, preserve the entire resource directory instead of selecting individual runtime files.

Recommended way to create the reduced installation

Do not delete files from the only extracted copy. Build a separate reduced tree:

src=/opt/llvm-full dst=/opt/clang-minimal

version="$("$src/bin/clang" -dumpversion)" resource="$("$src/bin/clang" -print-resource-dir)"

mkdir -p "$dst/bin" "$dst/lib"

Preserve compiler executable and symlink structure.

cp -a "$src/bin/clang"
"$dst/bin/"

Preserve the complete Clang resource directory.

mkdir -p "$dst/$(dirname "${resource#"$src/"}")" cp -a "$resource" "$dst/${resource#"$src/"}"

Inspect and copy bundled shared-library dependencies separately.

ldd "$(readlink -f "$src/bin/clang")"

After copying the libraries reported by ldd, test both compilation and linking:

cat >/tmp/test.c