diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -477,6 +477,9 @@ option(LLVM_USE_SPLIT_DWARF "Use -gsplit-dwarf when compiling llvm." OFF) +option(LLVM_USE_GDB_INDEX + "Use -Wl,--gdb-index when compiling llvm." OFF) + # Define an option controlling whether we should build for 32-bit on 64-bit # platforms, where supported. if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")) diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -773,6 +773,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_compile_options(-gsplit-dwarf) + + # Turn on -Wl,--gdb-index if requested and supported + if (LLVM_USE_GDB_INDEX AND + (LLVM_USE_LINKER STREQUAL "gold" OR LLVM_USE_LINKER STREQUAL "lld")) + append("-Wl,--gdb-index" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) + endif() endif() endif() diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst --- a/llvm/docs/CMake.rst +++ b/llvm/docs/CMake.rst @@ -639,6 +639,15 @@ Rewrite absolute source paths in sources and debug info to relative ones. The source prefix can be adjusted via the LLVM_SOURCE_PREFIX variable. +**LLVM_USE_SPLIT_DWARF**:BOOL + If enabled, store DWARF debug information separately from object files. Enabling + this option can speed up build times in Debug configurations. + +**LLVM_USE_GDB_INDEX**:BOOL + If enabled, generate GDB index tables for locating split DWARF debug + information at link time. Enabling this option can speed up GDB debugging + startup times in Debug configurations with LLVM_USE_SPLIT_DWARF enabled. + CMake Caches ============