diff --git a/Makefile b/Makefile index b36e0438f..847e7b47d 100644 --- a/Makefile +++ b/Makefile @@ -195,6 +195,17 @@ endif $(warning Warning: Compiling in debug mode. Don't use the resulting binary in production) endif +# `USE_LTO=1` enables link-time optimizations. Among other things, this enables +# more devirtualization opportunities and inlining across translation units. +# This can save significant overhead introduced by RocksDB's pluggable +# interfaces/internal abstractions, like in the iterator hierarchy. It works +# better when combined with profile-guided optimizations (not currently +# supported natively in Makefile). +ifeq ($(USE_LTO), 1) + CXXFLAGS += -flto + LDFLAGS += -flto -fuse-linker-plugin +endif + #----------------------------------------------- include src.mk diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index b93b029ea..66f83b2b0 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -89,6 +89,16 @@ if test -z "$CXX"; then fi fi +if test -z "$AR"; then + if [ -x "$(command -v gcc-ar)" ]; then + AR=gcc-ar + elif [ -x "$(command -v llvm-ar)" ]; then + AR=llvm-ar + else + AR=ar + fi +fi + # Detect OS if test -z "$TARGET_OS"; then TARGET_OS=`uname -s` @@ -756,6 +766,7 @@ ROCKSDB_PATCH=`build_tools/version.sh patch` echo "CC=$CC" >> "$OUTPUT" echo "CXX=$CXX" >> "$OUTPUT" +echo "AR=$AR" >> "$OUTPUT" echo "PLATFORM=$PLATFORM" >> "$OUTPUT" echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> "$OUTPUT" echo "JAVA_LDFLAGS=$JAVA_LDFLAGS" >> "$OUTPUT" diff --git a/build_tools/fbcode_config.sh b/build_tools/fbcode_config.sh index 4834be5f4..2f56daa08 100644 --- a/build_tools/fbcode_config.sh +++ b/build_tools/fbcode_config.sh @@ -109,6 +109,7 @@ if [ -z "$USE_CLANG" ]; then # gcc CC="$GCC_BASE/bin/gcc" CXX="$GCC_BASE/bin/g++" + AR="$GCC_BASE/bin/gcc-ar" CFLAGS+=" -B$BINUTILS/gold" CFLAGS+=" -isystem $GLIBC_INCLUDE" @@ -119,6 +120,7 @@ else CLANG_INCLUDE="$CLANG_LIB/clang/stable/include" CC="$CLANG_BIN/clang" CXX="$CLANG_BIN/clang++" + AR="$CLANG_BIN/llvm-ar" KERNEL_HEADERS_INCLUDE="$KERNEL_HEADERS_BASE/include" diff --git a/build_tools/fbcode_config4.8.1.sh b/build_tools/fbcode_config4.8.1.sh index 5f0813a04..c5ba8ddf4 100644 --- a/build_tools/fbcode_config4.8.1.sh +++ b/build_tools/fbcode_config4.8.1.sh @@ -69,6 +69,7 @@ if [ -z "$USE_CLANG" ]; then # gcc CC="$GCC_BASE/bin/gcc" CXX="$GCC_BASE/bin/g++" + CXX="$GCC_BASE/bin/gcc-ar" CFLAGS="-B$BINUTILS/gold -m64 -mtune=generic" CFLAGS+=" -isystem $GLIBC_INCLUDE" @@ -81,6 +82,7 @@ else CLANG_INCLUDE="$CLANG_LIB/clang/*/include" CC="$CLANG_BIN/clang" CXX="$CLANG_BIN/clang++" + AR="$CLANG_BIN/llvm-ar" KERNEL_HEADERS_INCLUDE="$KERNEL_HEADERS_BASE/include/" diff --git a/build_tools/fbcode_config_platform007.sh b/build_tools/fbcode_config_platform007.sh index 60b51800a..f7de7fcca 100644 --- a/build_tools/fbcode_config_platform007.sh +++ b/build_tools/fbcode_config_platform007.sh @@ -118,6 +118,7 @@ if [ -z "$USE_CLANG" ]; then # gcc CC="$GCC_BASE/bin/gcc" CXX="$GCC_BASE/bin/g++" + AR="$GCC_BASE/bin/gcc-ar" CFLAGS+=" -B$BINUTILS/gold" CFLAGS+=" -isystem $LIBGCC_INCLUDE" @@ -128,6 +129,7 @@ else CLANG_INCLUDE="$CLANG_LIB/clang/stable/include" CC="$CLANG_BIN/clang" CXX="$CLANG_BIN/clang++" + AR="$CLANG_BIN/llvm-ar" KERNEL_HEADERS_INCLUDE="$KERNEL_HEADERS_BASE/include"