Skip to content

Commit d22944d

Browse files
authored
[cmake] Fix relative paths in prefix map (#74132)
When building debug version of LLVM with `LLVM_USE_RELATIVE_PATHS_IN_FILES=On` would cause source paths to be incorrect, and be prefixed by the build directory. This lead to source locations like the following: `../build/llvm/...`. Such paths do not exist, and existing debuggers can't adjust their search location because of the incorrect prefix. Ultimately, this happened because the relative path creation goes in the wrong direction, from source-dir to build-dir instead of from build-dir to source-dir. This patch swaps the directionality of the relative paths so that they get a proper prefix from the build directory. Given a build dir at `/build` and a project directory at `/llvm-project`, we get source locations like: `../llvm-project/llvm/lib/Transforms/...`, which a debugger can resolve once pointed to the correct project directory.
1 parent 5fe741f commit d22944d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
13411341
else()
13421342
set(source_root "${LLVM_MAIN_SRC_DIR}")
13431343
endif()
1344-
file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
1344+
file(RELATIVE_PATH relative_root "${CMAKE_BINARY_DIR}" "${source_root}")
13451345
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
13461346
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
13471347
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
@@ -1356,7 +1356,7 @@ if(LLVM_USE_RELATIVE_PATHS_IN_FILES)
13561356
else()
13571357
set(source_root "${LLVM_MAIN_SRC_DIR}")
13581358
endif()
1359-
file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
1359+
file(RELATIVE_PATH relative_root "${CMAKE_BINARY_DIR}" "${source_root}")
13601360
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
13611361
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
13621362
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)

0 commit comments

Comments
 (0)