Skip to content

Commit

Permalink
Makefile support for link-time optimization (#7181)
Browse files Browse the repository at this point in the history
Summary:
`USE_LTO=1` in `make` commands now enables LTO. The archiver (`ar`) needed
to change in this PR to use a wrapper that enables the LTO plugin.

Pull Request resolved: #7181

Test Plan:
build a few ways
```
$ make clean && USE_LTO=1 make -j48 db_bench
$ make clean && USE_CLANG=1 USE_LTO=1 make -j48 db_bench
$ make clean && ROCKSDB_NO_FBCODE=1 USE_LTO=1 make -j48 db_bench
```

Reviewed By: cheng-chang

Differential Revision: D22784994

Pulled By: ajkr

fbshipit-source-id: 9c45333bd49bf4615aa04c85b7c6fd3925421152
  • Loading branch information
ajkr authored and facebook-github-bot committed Jul 28, 2020
1 parent 83ea266 commit c0c33a4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Makefile
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions build_tools/build_detect_platform
Expand Up @@ -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`
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions build_tools/fbcode_config.sh
Expand Up @@ -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"
Expand All @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions build_tools/fbcode_config4.8.1.sh
Expand Up @@ -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"
Expand All @@ -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/"

Expand Down
2 changes: 2 additions & 0 deletions build_tools/fbcode_config_platform007.sh
Expand Up @@ -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"
Expand All @@ -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"

Expand Down

0 comments on commit c0c33a4

Please sign in to comment.