From: Petr Hosek Date: Fri, 31 May 2019 01:34:51 +0000 (+0000) Subject: [CMake] Provide an option to use relative paths in debug info X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a3f589fca384b16a35d5fd1c4ec38e752aa8fef;p=llvm [CMake] Provide an option to use relative paths in debug info CMake always uses absolute file paths in the generated compiler invocation which results in absolute file paths being embedded in debug info. This is undesirable when building a toolchain e.g. on bots as the debug info may embed the bot source checkout path which is meaningless anywhere else. This change introduces the LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO which uses -fdebug-prefix-map (where supported) options to rewrite paths embedded into debug info with relative ones. Additionally, LLVM_SOURCE_PREFIX can be used to override the path to source directory with a different one. Differential Revision: https://reviews.llvm.org/D62622 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362185 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index cb9a01e1d39..1aa0804a3c0 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -977,3 +977,19 @@ if(macos_signposts_available) endif() endif() endif() + +option(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO "Use relative paths in debug info" OFF) +set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources in debug info") + +if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO) + check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP) + if(LLVM_ENABLE_PROJECTS_USED) + get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE) + else() + set(source_root "${LLVM_MAIN_SRC_DIR}") + endif() + file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}") + append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES) +endif() diff --git a/cmake/modules/LLVMExternalProjectUtils.cmake b/cmake/modules/LLVMExternalProjectUtils.cmake index 8190896737f..9a6adab1656 100644 --- a/cmake/modules/LLVMExternalProjectUtils.cmake +++ b/cmake/modules/LLVMExternalProjectUtils.cmake @@ -231,6 +231,8 @@ function(llvm_ExternalProject_Add name source_dir) -DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR} -DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE} -DLLVM_HAVE_LINK_VERSION_SCRIPT=${LLVM_HAVE_LINK_VERSION_SCRIPT} + -DLLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO=${LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO} + -DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX} -DPACKAGE_VERSION=${PACKAGE_VERSION} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt index e91003b5b19..6ac92cc6703 100644 --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -375,6 +375,7 @@ else() # if this is included from LLVM's CMake CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE} + -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED} -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE} -DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE} @@ -464,6 +465,7 @@ else() # if this is included from LLVM's CMake CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} -DLLVM_DEFAULT_TARGET_TRIPLE=${target} + -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED} -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DCMAKE_C_COMPILER_TARGET=${target} -DCMAKE_CXX_COMPILER_TARGET=${target}