[lldb][COFF] Add note to forwarder export symbols in symtab

Forwarder exports do not point to a real function or variable. Instead
they point to a string describing which DLL and symbol to forward to.
Any imports which uses them will be redirected by the loader
transparently. These symbols do not have much use in LLDB, but keep them
just in case someone find it useful. Also set a synthesized name with
the forwarder string for informational purpose.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134518
This commit is contained in:
Alvin Wong
2022-09-28 12:45:38 +03:00
committed by Martin Storsjö
parent 7ebff6ab26
commit acf7d08119
2 changed files with 75 additions and 3 deletions

View File

@@ -869,6 +869,26 @@ ObjectFilePECOFF::AppendFromExportTable(SectionList *sect_list,
llvm::cantFail(entry.getOrdinal(ordinal));
symbol.SetID(ordinal);
bool is_forwarder;
llvm::cantFail(entry.isForwarder(is_forwarder));
if (is_forwarder) {
// Forwarder exports are redirected by the loader transparently, but keep
// it in symtab and make a note using the symbol name.
llvm::StringRef forwarder_name;
if (auto err = entry.getForwardTo(forwarder_name)) {
LLDB_LOG(log,
"ObjectFilePECOFF::AppendFromExportTable - failed to get "
"forwarder name of forwarder export '{0}': {1}",
sym_name, llvm::fmt_consume(std::move(err)));
continue;
}
llvm::SmallString<256> new_name = {symbol.GetDisplayName().GetStringRef(),
" (forwarded to ", forwarder_name,
")"};
symbol.GetMangled().SetDemangledName(ConstString(new_name.str()));
symbol.SetDemangledNameIsSynthesized(true);
}
uint32_t function_rva;
if (auto err = entry.getExportRVA(function_rva)) {
LLDB_LOG(log,
@@ -886,9 +906,10 @@ ObjectFilePECOFF::AppendFromExportTable(SectionList *sect_list,
// An exported symbol may be either code or data. Guess by checking whether
// the section containing the symbol is executable.
symbol.SetType(lldb::eSymbolTypeData);
if (auto section_sp = symbol.GetAddressRef().GetSection())
if (section_sp->GetPermissions() & ePermissionsExecutable)
symbol.SetType(lldb::eSymbolTypeCode);
if (!is_forwarder)
if (auto section_sp = symbol.GetAddressRef().GetSection())
if (section_sp->GetPermissions() & ePermissionsExecutable)
symbol.SetType(lldb::eSymbolTypeCode);
symbol.SetExternal(true);
uint32_t idx = symtab.AddSymbol(symbol);
export_list.push_back(std::make_pair(function_rva, idx));