Page MenuHomePhabricator

[CMake] Enable the use of -ffile-prefix-map
ClosedPublic

Authored by phosek on Mar 11 2020, 11:37 AM.

Details

Summary

This handles not paths embedded in debug info, but also in sources.
Since the use of this flag is controlled by an option, rather than
replacing the new option, we add a new option.

Diff Detail

Event Timeline

phosek created this revision.Mar 11 2020, 11:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2020, 11:37 AM
phosek updated this revision to Diff 249705.Mar 11 2020, 11:38 AM
leonardchan accepted this revision.Mar 11 2020, 12:03 PM

I also tried this but am still finding some paths embedded in libunwind and libclang_rt for some reason.

leonardchan@cp-snakewater:~/llvm-monorepo/llvm-build-1-master-fuchsia-toolchain$ strings ./install/lib/aarch64-unknown-fuchsia/c++/asan/libunwind.so.1.0 |& less
...
3 32 624 9 cursor:93 784 528 5 uc:94 1440 72 7 info:95
/usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-1/libunwind/src/libunwind.cpp
libunwind: %s - %s
_Unwind_Resume
_Unwind_Resume() can't return
unwind_phase2
during phase1 personality function said it would stop here, but now in phase2 it did not stop here
/usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-1/libunwind/src/UnwindLevel1.c
libunwind: %s - %s
_Unwind_Resume_or_Rethrow
...

I can assert from comparing an unstripped to the stripped binary that the __FILE__ path that we see in _LIBUNWIND_ABORT is stripped and resolved to just libunwind/src/UnwindLevel1.c, but there seems to be a separate instance of this absolute path (/usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-1/libunwind/src/UnwindLevel1.c) that I can see in the stripped binary that includes the full path.

I suppose it would be ok to submit this still since it saves space from some trimmed paths. I was hesitant to submit it yet since I haven't found a complete solution yet or figured out where this absolute path I'm finding came from.

llvm/cmake/modules/HandleLLVMOptions.cmake
1024

nit: update the name + description since it doesn't just affect debug info only now (perhaps just LLVM_USE_RELATIVE_PATHS)

I also think it would be good to add a section for this flag in llvm/docs/CMake.rst.

This revision is now accepted and ready to land.Mar 11 2020, 12:03 PM

This change only covers LLVM, not the runtimes. I'll make a follow up change to do the same for runtimes which should cover the cases you mentioned.

phosek updated this revision to Diff 249747.Mar 11 2020, 2:02 PM
phosek marked an inline comment as done.
phosek retitled this revision from [CMake] Use -ffile-prefix-map instead of -fdebug-prefix-map to [CMake] Enable the use of -ffile-prefix-map.
phosek edited the summary of this revision. (Show Details)
phosek updated this revision to Diff 249748.Mar 11 2020, 2:06 PM
phosek added a reviewer: smeenai.
phosek added a subscriber: smeenai.

@smeenai does this look reasonable to you?

Oh, I think you'll need to add it to llvm/cmake/modules/LLVMExternalProjectUtils.cmake also:

--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -221,6 +221,9 @@ function(llvm_ExternalProject_Add name source_dir)
     set(cmake_args ${ARG_CMAKE_ARGS})
   endif()

   ExternalProject_Add(${name}
     DEPENDS ${ARG_DEPENDS} llvm-config
     ${name}-clobber
@@ -239,6 +242,7 @@ function(llvm_ExternalProject_Add name source_dir)
                -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_USE_RELATIVE_PATHS_IN_FILES=${LLVM_USE_RELATIVE_PATHS_IN_FILES}
                -DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX}
                -DPACKAGE_VERSION=${PACKAGE_VERSION}
                -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}

Oh, I think you'll need to add it to llvm/cmake/modules/LLVMExternalProjectUtils.cmake also:

--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -221,6 +221,9 @@ function(llvm_ExternalProject_Add name source_dir)
     set(cmake_args ${ARG_CMAKE_ARGS})
   endif()

   ExternalProject_Add(${name}
     DEPENDS ${ARG_DEPENDS} llvm-config
     ${name}-clobber
@@ -239,6 +242,7 @@ function(llvm_ExternalProject_Add name source_dir)
                -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_USE_RELATIVE_PATHS_IN_FILES=${LLVM_USE_RELATIVE_PATHS_IN_FILES}
                -DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX}
                -DPACKAGE_VERSION=${PACKAGE_VERSION}
                -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}

Good catch, done.

This revision was automatically updated to reflect the committed changes.