Skip to content

Commit 4d50b40

Browse files
authored
[libc++] Remap headers in the debug info when building the library (#143004)
The libc++ build includes a step where headers are generated. This is required in order to preprocess some files such as the assertion handler and the __config_site header. As a result, the library is built against headers located inside the build directory, and the path to those headers is what's included in the debug information of the library. However, these headers in the build directory are usually not persistent, which means that the debug information might end up referring to headers that don't exist anymore. To solve this problem, this patch uses the -fdebug-prefix-map flag supported by Clang and GCC to remap the generated headers to the original headers in the source directory. This provides the illusion that the library was truly built against the in-source version of the headers.
1 parent 9f82ac5 commit 4d50b40

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,11 @@ add_dependencies(cxx-headers generate-cxx-headers)
17061706
target_include_directories(cxx-headers INTERFACE ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}
17071707
${LIBCXX_GENERATED_INCLUDE_DIR})
17081708

1709+
# Make sure to map the generated include directory back to libc++'s actual source directory when generating
1710+
# debug information. Otherwise, the debug information will refer to generated headers which are created during
1711+
# the build and generally not persistent.
1712+
target_add_compile_flags_if_supported(cxx-headers INTERFACE "-fdebug-prefix-map=${LIBCXX_GENERATED_INCLUDE_DIR}=${LIBCXX_SOURCE_DIR}/include")
1713+
17091714
if (LIBCXX_INSTALL_HEADERS)
17101715
foreach(file ${files})
17111716
get_filename_component(dir ${file} DIRECTORY)

0 commit comments

Comments
 (0)