diff options
author | Petr Hosek <phosek@chromium.org> | 2019-03-09 01:26:55 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2019-03-09 01:26:55 +0000 |
commit | aac819b84442a57e573e2d87d8903e820e0bee1a (patch) | |
tree | 69f6c93087700f744fa7279754b237a5f05de4d5 | |
parent | 65e062655ed8591761f3d7b7ce31bd8f9dd553ef (diff) | |
download | bcm5719-llvm-aac819b84442a57e573e2d87d8903e820e0bee1a.tar.gz bcm5719-llvm-aac819b84442a57e573e2d87d8903e820e0bee1a.zip |
[CMake] Support stripping and linking output to .build-id directory
When installing runtimes with install-runtimes-stripped, we don't want
to just strip them, we also want to preserve the debugging information
for potential debugging. To make it possible to later find the stripped
debugging information, we want to use the .build-id layout:
https://fedoraproject.org/wiki/RolandMcGrath/BuildID#Find_files_by_build_ID
That is, for libfoo.so with build ID abcdef1234, the debugging information
will be installed into lib/debug/.build-id/ab/cdef1234. llvm-objcopy
already has support for stripping files and linking the debugging
stripped output into the right location. However, CMake doesn't support
customizing strip invocation for the *-stripped targets. So instead, we
replace CMAKE_STRIP with a custom script that invokes llvm-objcopy with
the right command line flags.
Differential Revision: https://reviews.llvm.org/D59127
llvm-svn: 355765
-rw-r--r-- | clang/cmake/caches/Fuchsia-stage2.cmake | 7 | ||||
-rw-r--r-- | llvm/cmake/modules/LLVMExternalProjectUtils.cmake | 10 | ||||
-rw-r--r-- | llvm/runtimes/CMakeLists.txt | 12 | ||||
-rwxr-xr-x | llvm/runtimes/llvm-strip-link.in | 27 |
4 files changed, 54 insertions, 2 deletions
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake index 51efb2ddb8d..fab7f0d9e5b 100644 --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -74,6 +74,9 @@ foreach(target aarch64-linux-gnu;armv7-linux-gnueabihf;i386-linux-gnu;x86_64-lin set(RUNTIMES_${target}_SANITIZER_CXX_ABI "libc++" CACHE STRING "") set(RUNTIMES_${target}_SANITIZER_CXX_ABI_INTREE ON CACHE BOOL "") set(RUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") + + # Use .build-id link. + list(APPEND RUNTIME_BUILD_ID_LINK "${target}") endif() endforeach() @@ -126,6 +129,9 @@ if(FUCHSIA_SDK) set(RUNTIMES_${target}-fuchsia_LIBCXX_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF CACHE BOOL "") set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "") + + # Use .build-id link. + list(APPEND RUNTIME_BUILD_ID_LINK "${target}-fuchsia") endforeach() set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "") @@ -134,6 +140,7 @@ endif() set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "") set(LLVM_RUNTIME_TARGETS "${RUNTIME_TARGETS}" CACHE STRING "") +set(LLVM_RUNTIME_BUILD_ID_LINK_TARGETS "${RUNTIME_BUILD_ID_LINK}" CACHE STRING "") # Setup toolchain. set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "") diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake index 4d26a30f97b..dab71820ade 100644 --- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake +++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake @@ -35,12 +35,14 @@ endfunction() # Extra targets in the subproject to generate targets for # PASSTHROUGH_PREFIXES prefix... # Extra variable prefixes (name is always included) to pass down +# STRIP_TOOL path +# Use provided strip tool instead of the default one. # ) function(llvm_ExternalProject_Add name source_dir) cmake_parse_arguments(ARG "USE_TOOLCHAIN;EXCLUDE_FROM_ALL;NO_INSTALL;ALWAYS_CLEAN" "SOURCE_DIR" - "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES" + "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES;STRIP_TOOL" ${ARGN}) canonicalize_tool_name(${name} nameCanon) if(NOT ARG_TOOLCHAIN_TOOLS) @@ -125,12 +127,16 @@ function(llvm_ExternalProject_Add name source_dir) if(llvm-objcopy IN_LIST TOOLCHAIN_TOOLS) list(APPEND compiler_args -DCMAKE_OBJCOPY=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-objcopy) endif() - if(llvm-strip IN_LIST TOOLCHAIN_TOOLS) + if(llvm-strip IN_LIST TOOLCHAIN_TOOLS AND NOT ARG_STRIP_TOOL) list(APPEND compiler_args -DCMAKE_STRIP=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-strip) endif() list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS}) endif() + if(ARG_STRIP_TOOL) + list(APPEND compiler_args -DCMAKE_STRIP=${ARG_STRIP_TOOL}) + endif() + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp DEPENDS ${ARG_DEPENDS} diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index 4cb3ed9db2b..1866b256b4f 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -318,6 +318,14 @@ else() # if this is included from LLVM's CMake list(APPEND runtime_names ${projName}) endforeach() + if(LLVM_RUNTIME_BUILD_ID_LINK_TARGETS) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/llvm-strip-link.in + ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link + @ONLY + ) + endif() + function(runtime_default_target) cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN}) @@ -426,6 +434,10 @@ else() # if this is included from LLVM's CMake endif() endforeach() + if(target IN_LIST LLVM_RUNTIME_BUILD_ID_LINK_TARGETS) + list(APPEND EXTRA_ARGS STRIP_TOOL ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link) + endif() + llvm_ExternalProject_Add(runtimes-${name} ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${${name}_deps} diff --git a/llvm/runtimes/llvm-strip-link.in b/llvm/runtimes/llvm-strip-link.in new file mode 100755 index 00000000000..f9f6a9883df --- /dev/null +++ b/llvm/runtimes/llvm-strip-link.in @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +import subprocess + + +ELF_MAGIC = '\x7fELF' + +with open(sys.argv[1], "rb") as f: + buf = f.read(len(ELF_MAGIC)) + if buf != ELF_MAGIC: + sys.exit(0) + +llvm_objcopy = os.path.join('@LLVM_RUNTIME_OUTPUT_INTDIR@', 'llvm-objcopy') +install_dir = os.path.join(os.getenv('DESTDIR', ''), '@CMAKE_INSTALL_PREFIX@') +link_dir = os.path.join(install_dir, 'lib', 'debug', '.build-id') + +sys.exit(subprocess.call([ + llvm_objcopy, + '--strip-sections', + '--build-id-link-dir=' + link_dir, + '--build-id-link-input=.debug', + '--build-id-link-output=', + sys.argv[1], +])) |