Reduce number of external symbols in libllvm, libclang and liblldb

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, upstream builds the shared libraries using several visibility
options, which reduces the number of external symbols, and makes the
libraries a bit smaller.

On my test machine:
* libprivatellvm.so goes from 75643 to 34706 symbols (~54% reduction)
* libprivateclang.so goes from 53250 to 33531 symbols (~37% reduction)
* libprivatelldb.so goes from 27242 to 18798 symbols (~31% reduction)

Note: to get the full benefit, a clean build is required. Incremental
builds should still work, but I didn't want to force a full rebuild on
everybody.

MFC after:	1 week
This commit is contained in:
Dimitry Andric
2025-12-21 22:37:57 +01:00
parent 88b04633c2
commit cf1eaaf41c
2 changed files with 13 additions and 0 deletions
+12
View File
@@ -48,6 +48,8 @@ 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:
@@ -2050,6 +2052,16 @@ SRCS_ALL+= ${SRCS_COV}
SRCS+= ${GENSRCS}
SRCS+= ${SRCS_ALL:O}
# Optimization: for all source files under Target/*/*, use -fvisibility=hidden,
# which reduces the number of external symbols in the resulting shared library.
# This is also what upstream does.
.for src in ${SRCS}
. if "${src:MTarget/*/*}"
CFLAGS.${src:T}+= -fvisibility=hidden
.info ${src}: CFLAGS.${src:T}
. endif
.endfor
llvm/CodeGen/GenVT.inc: ${LLVM_SRCS}/include/llvm/CodeGen/ValueTypes.td
${LLVM_MIN_TBLGEN} -gen-vt \
-I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
+1
View File
@@ -122,6 +122,7 @@ LDFLAGS+= -Wl,-m,elf64lriscv_fbsd
CXXSTD= c++17
CXXFLAGS+= -fno-exceptions
CXXFLAGS+= -fno-rtti
CXXFLAGS+= -fvisibility-inlines-hidden
.if ${.MAKE.OS} == "FreeBSD" || !defined(BOOTSTRAPPING)
CXXFLAGS.clang+= -stdlib=libc++
.else