llvm.org GIT mirror llvm / 308cadd
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355765 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 4 months ago
3 changed file(s) with 47 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
3434 # Extra targets in the subproject to generate targets for
3535 # PASSTHROUGH_PREFIXES prefix...
3636 # Extra variable prefixes (name is always included) to pass down
37 # STRIP_TOOL path
38 # Use provided strip tool instead of the default one.
3739 # )
3840 function(llvm_ExternalProject_Add name source_dir)
3941 cmake_parse_arguments(ARG
4042 "USE_TOOLCHAIN;EXCLUDE_FROM_ALL;NO_INSTALL;ALWAYS_CLEAN"
4143 "SOURCE_DIR"
42 "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES"
44 "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES;STRIP_TOOL"
4345 ${ARGN})
4446 canonicalize_tool_name(${name} nameCanon)
4547 if(NOT ARG_TOOLCHAIN_TOOLS)
124126 if(llvm-objcopy IN_LIST TOOLCHAIN_TOOLS)
125127 list(APPEND compiler_args -DCMAKE_OBJCOPY=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-objcopy)
126128 endif()
127 if(llvm-strip IN_LIST TOOLCHAIN_TOOLS)
129 if(llvm-strip IN_LIST TOOLCHAIN_TOOLS AND NOT ARG_STRIP_TOOL)
128130 list(APPEND compiler_args -DCMAKE_STRIP=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-strip)
129131 endif()
130132 list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS})
133 endif()
134
135 if(ARG_STRIP_TOOL)
136 list(APPEND compiler_args -DCMAKE_STRIP=${ARG_STRIP_TOOL})
131137 endif()
132138
133139 add_custom_command(
316316 endif()
317317 list(APPEND runtime_names ${projName})
318318 endforeach()
319
320 if(LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
321 configure_file(
322 ${CMAKE_CURRENT_SOURCE_DIR}/llvm-strip-link.in
323 ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link
324 @ONLY
325 )
326 endif()
319327
320328 function(runtime_default_target)
321329 cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
424432 list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
425433 endif()
426434 endforeach()
435
436 if(target IN_LIST LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
437 list(APPEND EXTRA_ARGS STRIP_TOOL ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link)
438 endif()
427439
428440 llvm_ExternalProject_Add(runtimes-${name}
429441 ${CMAKE_CURRENT_SOURCE_DIR}
0 #!/usr/bin/env python
1 # -*- coding: utf-8 -*-
2
3 import os
4 import sys
5 import subprocess
6
7
8 ELF_MAGIC = '\x7fELF'
9
10 with open(sys.argv[1], "rb") as f:
11 buf = f.read(len(ELF_MAGIC))
12 if buf != ELF_MAGIC:
13 sys.exit(0)
14
15 llvm_objcopy = os.path.join('@LLVM_RUNTIME_OUTPUT_INTDIR@', 'llvm-objcopy')
16 install_dir = os.path.join(os.getenv('DESTDIR', ''), '@CMAKE_INSTALL_PREFIX@')
17 link_dir = os.path.join(install_dir, 'lib', 'debug', '.build-id')
18
19 sys.exit(subprocess.call([
20 llvm_objcopy,
21 '--strip-sections',
22 '--build-id-link-dir=' + link_dir,
23 '--build-id-link-input=.debug',
24 '--build-id-link-output=',
25 sys.argv[1],
26 ]))