Skip to content

Commit

Permalink
Better Clang LTO: install LLVMgold to bfd-plugins.
Browse files Browse the repository at this point in the history
ar will automatically load any plugins that are installed to
../lib/bfd-plugins. Rather than needing to fix all of our build
systems, we can make LTO Just Work if we copy the gold plugin (and
its dependencies) into the binutils directory.

I've also added a test for cmake LTO.

Test: ./validate.py --filter flto
Bug: android/ndk#108
Change-Id: I1db61b8ef3405474c64ff20478daa86ca41ab3b3
  • Loading branch information
DanAlbert committed Jan 5, 2017
1 parent eefa0e2 commit ec60de8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
6 changes: 0 additions & 6 deletions build/core/build-binary.mk
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,6 @@ ifeq (true,$(thin_archive))
ar_flags := $(ar_flags)T
endif

ifeq (clang,$(NDK_TOOLCHAIN_VERSION))
ifneq ($(HOST_OS),windows)
ar_flags += --plugin $(TARGET_AR_PLUGIN)
endif
endif

$(LOCAL_BUILT_MODULE): PRIVATE_ABI := $(TARGET_ARCH_ABI)
$(LOCAL_BUILT_MODULE): PRIVATE_AR := $(TARGET_AR) $(ar_flags) $(TARGET_AR_FLAGS)
$(LOCAL_BUILT_MODULE): PRIVATE_AR_OBJECTS := $(ar_objects)
Expand Down
1 change: 0 additions & 1 deletion build/core/default-build-commands.mk
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ ifneq (clang,$(NDK_TOOLCHAIN_VERSION))
TARGET_AR = $(TOOLCHAIN_PREFIX)gcc-ar
else
TARGET_AR = $(TOOLCHAIN_PREFIX)ar
TARGET_AR_PLUGIN = $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/lib64/LLVMgold.so
endif

TARGET_ARFLAGS := crsD
Expand Down
22 changes: 22 additions & 0 deletions checkbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,28 @@ def install_arch(self, out_dir, host, arch):

ndk.builds.install_directory(toolchain_path, install_path)

if not host.startswith('windows'):
so = '.so'
if host == 'darwin':
so = '.dylib'

clang_libs = build_support.android_path(
'prebuilts/ndk/current/toolchains', host_tag, 'llvm/lib64')
llvmgold = os.path.join(clang_libs, 'LLVMgold.so')
libcxx = os.path.join(clang_libs, 'libc++' + so)
libllvm = os.path.join(clang_libs, 'libLLVM' + so)

bfd_plugins = os.path.join(install_path, 'lib/bfd-plugins')
os.makedirs(bfd_plugins)
shutil.copy2(llvmgold, bfd_plugins)

# The rpath on LLVMgold.so is ../lib64, so we have to install to
# lib/lib64 to have it be in the right place :(
lib_dir = os.path.join(install_path, 'lib/lib64')
os.makedirs(lib_dir)
shutil.copy2(libcxx, lib_dir)
shutil.copy2(libllvm, lib_dir)


class ShaderTools(ndk.builds.InvokeBuildModule):
name = 'shader-tools'
Expand Down
10 changes: 10 additions & 0 deletions tests/build/flto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.6.0)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")

add_library(bar STATIC jni/bar.c)

add_executable(flto jni/flto.c)
target_link_libraries(flto bar)

0 comments on commit ec60de8

Please sign in to comment.