duction) * 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 --- lib/clang/libllvm/Makefile | 12 ++++++++++++ lib/clang/llvm.build.mk | 1 + 2 files changed, 13 insertions(+) diff --git a/lib/clang/libllvm/Makefile b/lib/clang/libllvm/Makefile index 810eac08d8d5..7c45375b8fbf 100644 --- a/lib/clang/libllvm/Makefile +++ b/lib/clang/libllvm/Makefile @@ -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} \ diff --git a/lib/clang/llvm.build.mk b/lib/clang/llvm.build.mk index a26e15679242..b8b4be7dfe28 100644 --- a/lib/clang/llvm.build.mk +++ b/lib/clang/llvm.build.mk @@ -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