[PATCH] D58628: [cmake] Add option to enable gdb-index.

Michael Liao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 25 08:06:31 PST 2019


hliao created this revision.
Herald added subscribers: llvm-commits, jdoerfert, arphaman, mgorny.
Herald added a project: LLVM.

- It's well-known that building gdb index could speed up the loading in gdb. However, simply adding '-DCMAKE_{EXE/SHARED/MODULE}_LINKER_FLAGS="-Wl,--gdb-index"' would cause linking error under certain enviroments. E.g., it's quite common that gold is not the default system linker but it's selected in LLVM build by specifying '-DLLVM_USE_LINKER=gold'. Under such case, `-Wl,--gdb-index` would cause linking issue when cmake needs to build executable for environment detection, says it needs to build a problem to check whether there a working C compiler as, following the default system linker, it still uses the linker without understanding of -Wl,--gdb-index. It's quite annoying if the default system linker cannot be easily switched to gold.

- LLVM_USE_GDBINDEX option is introduced to make life easier by only adding that option in LLVM build. So far, it only enables adding of that option when the linker to be used is gold.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58628

Files:
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -191,6 +191,10 @@
     set(LLVM_LINKER_DETECTED NO)
     message(STATUS "Linker detection: unknown")
   endif()
+  if(LLVM_LINKER_IS_GOLD AND LLVM_USE_GDBINDEX)
+    append("-Wl,--gdb-index" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
+      CMAKE_MODULE_LINKER_FLAGS)
+  endif()
 endif()
 
 function(add_link_opts target_name)
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -468,6 +468,8 @@
 
 option(LLVM_USE_SPLIT_DWARF
   "Use -gsplit-dwarf when compiling llvm." OFF)
+option(LLVM_USE_GDBINDEX
+  "Use -Wl,--gdb-index to index the debug info." OFF)
 
 option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ON)
 option(LLVM_POLLY_BUILD "Build LLVM with Polly" ON)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58628.188183.patch
Type: text/x-patch
Size: 986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190225/ff424902/attachment.bin>


More information about the llvm-commits mailing list