Page MenuHomePhabricator

[cmake] Add option to enable gdb-index.
Needs ReviewPublic

Authored by hliao on Feb 25 2019, 8:06 AM.

Details

Reviewers
chandlerc
Summary
  • 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.

Event Timeline

hliao created this revision.Feb 25 2019, 8:06 AM

Hi Chandler

Not sure whom should I ask for review. If you have candidates, please add them.

Thanks

hliao updated this revision to Diff 188186.Feb 25 2019, 8:12 AM

It seems phabricator understands certain markups.

Hmm, I don't seem to have had the troubles you've had - I use CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=-Wl,--gdb-index and... ah, I don't use (or even have in my CMakeCache.txt any mention of) LLVM_USE_LINKER. Not actually sure where/how my build is choosing to use gold. Perhaps it's just my system default once it's installed.

that's the case your system has gold as the default linker. For my case, my default system linker is bfd ld, which don't understand -Wl,--gdb-index.

Would it be simpler/effective to add "-fuse-ld=gold -Wl,--gdb-index" to your linker flags to enable both these things, rather than having specific CMake support for either/both?

LLD supports --gdb-index as well.

I think you also want to add -ggnu-pubnames to your compile flags if you're doing this. gold supports building a GDB index without that extra debug info being present, but in my experience it doesn't work as reliably and is way slower. LLD doesn't support building a GDB index without that debug info yet; D54497 adds some support for that, but that's pending a bunch of review discussion.

hliao added a comment.Feb 25 2019, 1:07 PM

Would it be simpler/effective to add "-fuse-ld=gold -Wl,--gdb-index" to your linker flags to enable both these things, rather than having specific CMake support for either/both?

The additional option could serve as the start point and option to use ld.bfd + objcopy to generate gdbindex on platforms without gold, says non x86 or arm processors.