<div dir="ltr"><div>Today, there're two different locations for runtimes files within Clang's installation:</div><div><br></div><div>compiler-rt:</div><div>  headers: $prefix/lib/clang/$version/include(/sanitizer)</div><div>  libraries: $prefix/lib/clang/$version/lib/$os/libclang_rt.$name-$arch.$ext</div><div><br></div><div>libc++, libc++abi, libunwind:</div><div>  headers: $prefix/include/c++/v1</div><div>  libraries: $prefix/lib/$name.$ext</div><div><br></div><div>The scheme used by libc++, libc++abi, libunwind doesn't support targets other than the host which is a problem when cross-compiling. In our toolchain, we would like to build runtimes for all host and target platforms we support, e.g. a single toolchain will have runtimes for x86_64 and aarch64 Linux, Fuchsia and Windows. All you need to provide is the target triple and the sysroot. While this is possible with builtins, sanitizers and other compiler-rt runtimes, it's not possible with libc++, libc++abi, libunwind.</div><div><br></div><div>Our proposal is to move both compiler-rt and libc++, libc++abi, libunwind into a new location that would support cross-compilation and unify the layout:</div><div><br></div><div>headers: $prefix/lib/clang/$version/include(/$triple)(/c++/v1)</div><div>libraries: $prefix/lib/clang/$version/$triple/lib/$name.$ext</div><div><br></div><div>This means that for compiler-rt, the main difference would be moving the runtime libraries to an target specific subdirectory rather than including the architecture in the library name; for libc++, libc++abi, libunwind, both headers and libraries will be moved to a new, target specific location.</div><div><br></div><div>In terms of implementation, we'll need to modify the Clang driver to use this location when looking for runtimes and C++ libraries and headers. This should be a non-intrusive change: we'll modify the driver to look into the new location in addition to the existing ones, so if the new path doesn't exist, the driver will simply fallback to the existing behavior. When this is done, we need to modify the CMake build to install files into the new location.</div><div><br></div><div>This layout would be only used when runtimes are built as part of the llvm/runtimes tree or using LLVM_ENABLE_RUNTIMES in the monorepo layout (because this setup supports cross-compiling runtimes). When built as part of LLVM or standalone, libc++, libc++abi, libunwind would still install their files to $prefix/include and $prefix/lib as today.<br></div><div><br></div><div>Once the overall scheme is agreed upon, we could also consider de-duplicating C++ headers across targets, by moving shared headers into a common directory, with only varying subset in include/$triple.</div><div><br></div><div><div>To give an example, for x86_64 and aarch64 Linux, this would look like:</div><div><br></div><div>$prefix/lib/clang/6.0.0/include/sanitizer<br></div><div>$prefix/lib/clang/6.0.0/include/c++/v1</div><div>$prefix/lib/clang/6.0.0/include/x86_64-linux-gnu/c++/v1/__config<br></div><div>...</div><div>$prefix/lib/clang/6.0.0/x86_64-linux-gnu/lib/<a href="http://libclang_rt.asan.so">libclang_rt.asan.so</a><br></div><div>$prefix/lib/clang/6.0.0/x86_64-linux-gnu/lib/libc++.so</div><div>...</div><div><div>$prefix/lib/clang/6.0.0/aarch64-linux-gnu/lib/<a href="http://libclang_rt.asan.so">libclang_rt.asan.so</a><br></div><div>$prefix/lib/clang/6.0.0/aarch64-linux-gnu/lib/libc++.so</div></div><div>...</div></div></div>