alvinhochun created this revision.
alvinhochun added reviewers: labath, DavidSpickett, mstorsjo.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.
This reimplements `ObjectFilePECOFF::ParseSymtab` with the following
changes:
- When the image has both an export table and a COFF symbol table, the symbols
obtained from the symbol table no longer get erased.
- Remove manual data extraction in favour of using what `COFFObjectFile`
provides.
- Mark symbols from the export table as "External" instead of "Debug".
- Support DLL forwarder exports (marked as re-exported).
- Handle absolute symbols in the symbol table.
- Heuristically set some symbol types. Symbols in the symbol table starting in
`__imp_` (dllimport IAT reference) or `.refptr.` (mingw stub) are marked as
"Data", because their locations store a pointer address.
- When a symbol in the symbol table is a duplicate of an exported symbol, its
info will be synchronized with the exported symbol, then it will be marked as
"Additional" type to avoid unwanted repetition when used in commands like
`disassemble`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134133
Files:
lldb/include/lldb/Symbol/Symtab.h
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
lldb/source/Symbol/Symtab.cpp
llvm/include/llvm/Object/COFF.h
Index: llvm/include/llvm/Object/COFF.h
===
--- llvm/include/llvm/Object/COFF.h
+++ llvm/include/llvm/Object/COFF.h
@@ -914,6 +914,10 @@
uint32_t getStringTableSize() const { return StringTableSize; }
+ const export_directory_table_entry *getExportTable() const {
+return ExportDirectory;
+ }
+
const coff_load_configuration32 *getLoadConfig32() const {
assert(!is64());
return reinterpret_cast(LoadConfig);
Index: lldb/source/Symbol/Symtab.cpp
===
--- lldb/source/Symbol/Symtab.cpp
+++ lldb/source/Symbol/Symtab.cpp
@@ -61,6 +61,14 @@
return m_symbols.empty() ? nullptr : &m_symbols[0];
}
+Symbol *Symtab::Extend(size_t count) {
+ // Clients should grab the mutex from this symbol table and lock it manually
+ // when calling this function to avoid performance issues.
+ auto old_size = m_symbols.size();
+ m_symbols.resize(old_size + count);
+ return m_symbols.empty() ? nullptr : &m_symbols[old_size];
+}
+
uint32_t Symtab::AddSymbol(const Symbol &symbol) {
// Clients should grab the mutex from this symbol table and lock it manually
// when calling this function to avoid performance issues.
@@ -809,6 +817,22 @@
return nullptr;
}
+bool Symtab::HasSymbolWithType(SymbolType symbol_type, Debug symbol_debug_type,
+ Visibility symbol_visibility) const {
+ std::lock_guard guard(m_mutex);
+
+ const size_t count = m_symbols.size();
+ for (size_t idx = 0; idx < count; ++idx) {
+if (symbol_type == eSymbolTypeAny ||
+m_symbols[idx].GetType() == symbol_type) {
+ if (CheckSymbolAtIndex(idx, symbol_debug_type, symbol_visibility)) {
+return true;
+ }
+}
+ }
+ return false;
+}
+
void
Symtab::FindAllSymbolsWithNameAndType(ConstString name,
SymbolType symbol_type,
Index: lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
===
--- lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
+++ lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
@@ -81,6 +81,11 @@
abilities |= Functions;
}
+ if (symtab->HasSymbolWithType(eSymbolTypeReExported, Symtab::eDebugAny,
+Symtab::eVisibilityAny)) {
+abilities |= Functions;
+ }
+
if (symtab->AppendSymbolIndexesWithType(eSymbolTypeData,
m_data_indexes)) {
symtab->SortSymbolIndexesByValue(m_data_indexes, true);
Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
===
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -225,12 +225,6 @@
data_dirs; // will contain num_data_dir_entries entries
} coff_opt_header_t;
- enum coff_data_dir_type {
-coff_data_dir_export_table = 0,
-coff_data_dir_import_table = 1,
-coff_data_dir_exception_table = 3
- };
-
typedef struct section_header {
char name[8] = {};
uint32_t vmsize = 0; // Virtual Size
@@ -244,29 +238,6 @@
uint32_t flags = 0;
} section_header_t;
- typedef struct coff_symbol {
-char name