[PATCH] D62622: [CMake] Provide an option to use relative paths in debug info
Petr Hosek via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 29 13:00:34 PDT 2019
phosek created this revision.
phosek added reviewers: beanz, smeenai.
Herald added subscribers: llvm-commits, cfe-commits, aprantl, mgorny.
Herald added projects: clang, LLVM.
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 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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D62622
Files:
clang/cmake/caches/Fuchsia-stage2.cmake
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Index: llvm/cmake/modules/LLVMExternalProjectUtils.cmake
===================================================================
--- llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -231,6 +231,8 @@
-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=${LLVM_USE_RELATIVE_PATHS}
+ -DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX}
-DPACKAGE_VERSION=${PACKAGE_VERSION}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -977,3 +977,19 @@
endif()
endif()
endif()
+
+option(LLVM_USE_RELATIVE_PATHS "Make builds independent of absolute file paths." OFF)
+set(LLVM_SOURCE_PREFIX "" CACHE STRING "LLVM source directory prefix")
+
+if(LLVM_USE_RELATIVE_PATHS)
+ check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP)
+ set(source_root "${CMAKE_CURRENT_SOURCE_DIR}/../..")
+ if(LLVM_ENABLE_PROJECTS_USED)
+ string(APPEND source_root "/..")
+ endif()
+ get_filename_component(source_root "${source_root}" ABSOLUTE)
+ 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()
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===================================================================
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -15,6 +15,7 @@
set(LLVM_EXTERNALIZE_DEBUGINFO ON CACHE BOOL "")
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
+set(LLVM_USE_RELATIVE_PATHS ON CACHE BOOL "")
set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
if(NOT APPLE)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62622.202029.patch
Type: text/x-patch
Size: 2380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190529/3102085d/attachment.bin>
More information about the cfe-commits
mailing list