[all-commits] [llvm/llvm-project] 7e6df4: [NFC] Refactor symbol table parsing.

Greg Clayton via All-commits all-commits at lists.llvm.org
Tue Nov 30 13:54:48 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7e6df41f655e51c984b92bbd9c19a6fb851f35d4
      https://github.com/llvm/llvm-project/commit/7e6df41f655e51c984b92bbd9c19a6fb851f35d4
  Author: Greg Clayton <gclayton at fb.com>
  Date:   2021-11-30 (Tue, 30 Nov 2021)

  Changed paths:
    M lldb/include/lldb/Symbol/ObjectFile.h
    M lldb/include/lldb/Symbol/Symtab.h
    M lldb/source/Core/Module.cpp
    M lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
    M lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
    M lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    M lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
    M lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
    M lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
    M lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    M lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
    M lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
    M lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    M lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
    M lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
    M lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
    M lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
    M lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    M lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
    M lldb/source/Symbol/ObjectFile.cpp
    M lldb/source/Symbol/Symtab.cpp

  Log Message:
  -----------
  [NFC] Refactor symbol table parsing.

Symbol table parsing has evolved over the years and many plug-ins contained duplicate code in the ObjectFile::GetSymtab() that used to be pure virtual. With this change, the "Symbtab *ObjectFile::GetSymtab()" is no longer virtual and will end up calling a new "void ObjectFile::ParseSymtab(Symtab &symtab)" pure virtual function to actually do the parsing. This helps centralize the code for parsing the symbol table and allows the ObjectFile base class to do all of the common work, like taking the necessary locks and creating the symbol table object itself. Plug-ins now just need to parse when they are asked to parse as the ParseSymtab function will only get called once.

This is a retry of the original patch https://reviews.llvm.org/D113965 which was reverted. There was a deadlock in the Manual DWARF indexing code during symbol preloading where the module was asked on the main thread to preload its symbols, and this would in turn cause the DWARF manual indexing to use a thread pool to index all of the compile units, and if there were relocations on the debug information sections, these threads could ask the ObjectFile to load section contents, which could cause a call to ObjectFileELF::RelocateSection() which would ask for the symbol table from the module and it would deadlock. We can't lock the module in ObjectFile::GetSymtab(), so the solution I am using is to use a llvm::once_flag to create the symbol table object once and then lock the Symtab object. Since all APIs on the symbol table use this lock, this will prevent anyone from using the symbol table before it is parsed and finalized and will avoid the deadlock I mentioned. ObjectFileELF::GetSymtab() was never locking the module lock before and would put off creating the symbol table until somewhere inside ObjectFileELF::GetSymtab(). Now we create it one time inside of the ObjectFile::GetSymtab() and immediately lock it which should be safe enough. This avoids the deadlocks and still provides safety.

Differential Revision: https://reviews.llvm.org/D114288




More information about the All-commits mailing list