COFF: Support import-by-ordinal DLL imports.

Symbols exported by DLLs can be imported not by name but by
small number or ordinal. Usually, symbols have both ordinals
and names, and in that case ordinals are called "hints" and
used by the loader as hints.

However, symbols can have only ordinals. They are called
import-by-ordinal symbols. You need to manage ordinals by hand
so that they will never change if you choose to use the feature.
But it's supposed to make dynamic linking faster because
it needs no string comparison. Not sure if that claim still
stands in year 2015, though. Anyways, the feature exists,
and this patch implements that.

llvm-svn: 238780
This commit is contained in:
Rui Ueyama
2015-06-01 21:05:27 +00:00
parent c2abdd9152
commit fd99e01b91
8 changed files with 53 additions and 19 deletions

View File

@@ -229,7 +229,11 @@ std::error_code ImportFile::parse() {
StringRef Name = StringAlloc.save(StringRef(Buf + sizeof(*Hdr)));
StringRef ImpName = StringAlloc.save(Twine("__imp_") + Name);
StringRef DLLName(Buf + sizeof(coff_import_header) + Name.size() + 1);
auto *ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, Name, Hdr);
StringRef ExternalName = Name;
if (Hdr->getNameType() == llvm::COFF::IMPORT_ORDINAL)
ExternalName = "";
auto *ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExternalName,
Hdr);
SymbolBodies.push_back(ImpSym);
// If type is function, we need to create a thunk which jump to an