src.conf: Add WITH_LLVM_LINK_STATIC_LIBRARIES build knob
Some checks are pending
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (push) Waiting to run
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (push) Waiting to run
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (push) Waiting to run
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (push) Waiting to run
Cross-build Kernel / amd64 macos-latest (clang-18) (push) Waiting to run
Cross-build Kernel / aarch64 macos-latest (clang-18) (push) Waiting to run

In commit 2e47f35be5 libllvm, libclang and liblldb were converted into
private shared libraries. This allowed clang, lld, lldb, and other llvm
tools to be linked against these shared libraries, which makes them
smaller and avoids duplication.

However, this also comes at the cost of some performance, since the
dynamic libraries are quite large, and contain lots of long symbols
(mangled C++ identifiers).

Add a WITH_LLVM_LINK_STATIC_LIBRARIES build knob that can be used to go
back to the previous behavior: libllvm, libclang and liblldb are built
as internal static libraries, i.e. only available during buildworld, and
fully linked into the various executables such as clang, lld, etc.

PR:		287447
Reviewed by:	emaste
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D50956
This commit is contained in:
Dimitry Andric 2025-06-18 12:06:25 +02:00
parent 5819f8b285
commit 8d5a11cd01
13 changed files with 61 additions and 17 deletions

View file

@ -1,8 +1,8 @@
.include <bsd.init.mk>
.include <src.opts.mk>
.include "../clang.pre.mk"
.if defined(TOOLS_PREFIX)
# Build static library during cross-tools stage
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
# Build static library during cross-tools stage, or when explicitly requested.
LIB= clang
INTERNALLIB=
.else
@ -872,7 +872,7 @@ SRCS+= ${SRCS_ALL:O}
LIBDEPS+= llvm
.if defined(TOOLS_PREFIX)
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
LIBPRIV=
LIBEXT= a
.else

View file

@ -1,10 +1,16 @@
.include <bsd.init.mk>
.include <src.opts.mk>
.include "../lldb.pre.mk"
.if ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
# Build static library when explicitly requested.
LIB= lldb
INTERNALLIB=
.else
PACKAGE= lldb
SHLIB_CXX= lldb
SHLIB_MAJOR= 19
PRIVATELIB=
.endif
SHARED_CXXFLAGS+= -UPIC # To avoid compile errors
@ -753,8 +759,13 @@ SRCS+= Version/Version.cpp
LIBDEPS+= clang
LIBDEPS+= llvm
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
LIBPRIV=
LIBEXT= a
.else
LIBPRIV= private
LIBEXT= so
.endif
.for lib in ${LIBDEPS}
DPADD+= ${OBJTOP}/lib/clang/lib${lib}/lib${LIBPRIV}${lib}.${LIBEXT}

View file

@ -1,8 +1,8 @@
.include <bsd.init.mk>
.include <src.opts.mk>
.include "../llvm.pre.mk"
.if defined(TOOLS_PREFIX)
# Build static library during cross-tools stage
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
# Build static library during cross-tools stage, or when explicitly requested.
LIB= llvm
INTERNALLIB=
.else
@ -14,6 +14,7 @@ PRIVATELIB=
# Work around "relocation R_PPC_GOT16 out of range" errors
PICFLAG= -fPIC
.endif
CFLAGS+= -DLLVM_BUILD_LLVM_DYLIB
.endif
SHARED_CXXFLAGS+= -UPIC # To avoid compile errors
@ -48,8 +49,6 @@ CFLAGS+= -DBLAKE3_NO_AVX512 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_SSE41 \
CFLAGS+= -DBLAKE3_USE_NEON=0
.endif
CFLAGS+= -DLLVM_BUILD_LLVM_DYLIB
SRCDIR= llvm/lib
# Explanation of different SRCS variants below:

View file

@ -1,5 +1,5 @@
.\" DO NOT EDIT-- this file is @generated by tools/build/options/makeman.
.Dd December 15, 2025
.Dd December 21, 2025
.Dt SRC.CONF 5
.Os
.Sh NAME
@ -999,6 +999,13 @@ Install ELF Tool Chain's cxxfilt as c++filt, instead of LLVM's llvm-cxxfilt.
.It Va WITH_LLVM_FULL_DEBUGINFO
Generate full debug information for LLVM libraries and tools, which uses
more disk space and build resources, but allows for easier debugging.
.It Va WITH_LLVM_LINK_STATIC_LIBRARIES
Link LLVM libraries (libllvm, libclang, liblldb) statically into each of
the binaries that use them.
This means that binaries linked against these libraries, such as clang,
ld.lld and lldb will be much larger and position dependent, but will
start more quickly.
.It Va WITHOUT_LLVM_TARGET_AARCH64
Do not build LLVM target support for AArch64.
The

View file

@ -213,6 +213,7 @@ __DEFAULT_NO_OPTIONS = \
LOADER_VERBOSE \
LOADER_VERIEXEC_PASS_MANIFEST \
LLVM_FULL_DEBUGINFO \
LLVM_LINK_STATIC_LIBRARIES \
MALLOC_PRODUCTION \
OFED_EXTRA \
OPENLDAP \

View file

@ -892,12 +892,14 @@ OLD_FILES+=usr/share/man/man4/ccd.4.gz
OLD_FILES+=usr/share/man/man8/ccdconfig.8.gz
.endif
.if ${MK_CLANG} == no && ${MK_CLANG_FORMAT} == no && ${MK_LLDB} == no
.if ${MK_CLANG} == no && ${MK_CLANG_FORMAT} == no && ${MK_LLDB} == no && \
${MK_LLVM_LINK_STATIC_LIBRARIES} == no
OLD_LIBS+=usr/lib/libprivateclang.so.19
.endif
.if ${MK_CLANG_EXTRAS} == no && ${MK_CLANG} == no && ${MK_LLDB} == no && \
${MK_LLD} == no && ${MK_LLVM_BINUTILS} == no && ${MK_LLVM_COV} == no
${MK_LLD} == no && ${MK_LLVM_BINUTILS} == no && ${MK_LLVM_COV} == no && \
${MK_LLVM_LINK_STATIC_LIBRARIES} == no
OLD_LIBS+=usr/lib/libprivatellvm.so.19
.endif
@ -3868,10 +3870,13 @@ OLD_LIBS+=${DEBUG_LIB${LIBCOMPAT}_LIBS}
OLD_FILES+=usr/bin/ld.lld
.endif
.if ${MK_LLDB} == no && ${MK_LLVM_LINK_STATIC_LIBRARIES} == no
OLD_LIBS+=usr/lib/libprivatelldb.so.19
.endif
.if ${MK_LLDB} == no
OLD_FILES+=usr/bin/lldb
OLD_FILES+=usr/bin/lldb-server
OLD_LIBS+=usr/lib/libprivatelldb.so.19
OLD_FILES+=usr/share/man/man1/lldb-server.1.gz
OLD_FILES+=usr/share/man/man1/lldb.1.gz
.endif

View file

@ -0,0 +1,6 @@
Link LLVM libraries (libllvm, libclang, liblldb) statically into each of
the binaries that use them.
This means that binaries linked against these libraries, such as clang,
ld.lld and lldb will be much larger and position dependent, but will
start more quickly.

View file

@ -1,6 +1,6 @@
.include <src.opts.mk>
.if defined(TOOLS_PREFIX)
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
MK_PIE:= no # Explicit libXXX.a references
.endif

View file

@ -18,7 +18,7 @@ LIBADD+= z
LIBADD+= zstd
.endif
.if defined(TOOLS_PREFIX)
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
LIBPRIV=
LIBEXT= a
.else

View file

@ -81,7 +81,7 @@ SRCS+= tools/lld/lld.cpp
LIBDEPS+= llvm
.if defined(TOOLS_PREFIX)
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
LIBPRIV=
LIBEXT= a
.else

View file

@ -22,8 +22,13 @@ LIBDEPS+= lldb
LIBDEPS+= clang
LIBDEPS+= llvm
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
LIBPRIV=
LIBEXT= a
.else
LIBPRIV= private
LIBEXT= so
.endif
.for lib in ${LIBDEPS}
DPADD+= ${OBJTOP}/lib/clang/lib${lib}/lib${LIBPRIV}${lib}.${LIBEXT}

View file

@ -15,8 +15,13 @@ LIBDEPS+= lldb
LIBDEPS+= clang
LIBDEPS+= llvm
.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
LIBPRIV=
LIBEXT= a
.else
LIBPRIV= private
LIBEXT= so
.endif
.for lib in ${LIBDEPS}
DPADD+= ${OBJTOP}/lib/clang/lib${lib}/lib${LIBPRIV}${lib}.${LIBEXT}

View file

@ -14,8 +14,13 @@ LIBPRIV=
LIBEXT= a
.else
LIBDEPS+= llvm
.if ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes"
LIBPRIV=
LIBEXT= a
.else
LIBPRIV= private
LIBEXT= so
.endif
LIBADD+= z
LIBADD+= zstd
.endif