COFF: Simplify Writer::createImportTables.
A short import library has up to two symbols, so we don't have to do a for-loop and type dispatch in createImportTables. llvm-svn: 245200
This commit is contained in:
parent
e75ee0f0c8
commit
e73e418bb4
|
@ -298,16 +298,16 @@ void ImportFile::parse() {
|
|||
ExtName = ExtName.substr(0, ExtName.find('@'));
|
||||
break;
|
||||
}
|
||||
auto *ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExtName, Hdr);
|
||||
ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExtName, Hdr);
|
||||
SymbolBodies.push_back(ImpSym);
|
||||
|
||||
// If type is function, we need to create a thunk which jump to an
|
||||
// address pointed by the __imp_ symbol. (This allows you to call
|
||||
// DLL functions just like regular non-DLL functions.)
|
||||
if (Hdr->getType() == llvm::COFF::IMPORT_CODE) {
|
||||
auto *B = new (Alloc) DefinedImportThunk(Name, ImpSym, Hdr->Machine);
|
||||
SymbolBodies.push_back(B);
|
||||
}
|
||||
if (Hdr->getType() != llvm::COFF::IMPORT_CODE)
|
||||
return;
|
||||
ThunkSym = new (Alloc) DefinedImportThunk(Name, ImpSym, Hdr->Machine);
|
||||
SymbolBodies.push_back(ThunkSym);
|
||||
}
|
||||
|
||||
void BitcodeFile::parse() {
|
||||
|
|
|
@ -33,6 +33,8 @@ using llvm::object::coff_section;
|
|||
|
||||
class Chunk;
|
||||
class Defined;
|
||||
class DefinedImportData;
|
||||
class DefinedImportThunk;
|
||||
class Lazy;
|
||||
class SymbolBody;
|
||||
class Undefined;
|
||||
|
@ -182,6 +184,9 @@ public:
|
|||
static bool classof(const InputFile *F) { return F->kind() == ImportKind; }
|
||||
std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }
|
||||
|
||||
DefinedImportData *ImpSym = nullptr;
|
||||
DefinedImportThunk *ThunkSym = nullptr;
|
||||
|
||||
private:
|
||||
void parse() override;
|
||||
|
||||
|
|
|
@ -367,19 +367,13 @@ void Writer::createImportTables() {
|
|||
return;
|
||||
OutputSection *Text = createSection(".text");
|
||||
for (ImportFile *File : Symtab->ImportFiles) {
|
||||
for (SymbolBody *B : File->getSymbols()) {
|
||||
auto *Import = dyn_cast<DefinedImportData>(B);
|
||||
if (!Import) {
|
||||
// Linker-created function thunks for DLL symbols are added to
|
||||
// .text section.
|
||||
Text->addChunk(cast<DefinedImportThunk>(B)->getChunk());
|
||||
continue;
|
||||
}
|
||||
if (Config->DelayLoads.count(Import->getDLLName().lower())) {
|
||||
DelayIdata.add(Import);
|
||||
} else {
|
||||
Idata.add(Import);
|
||||
}
|
||||
if (DefinedImportThunk *Thunk = File->ThunkSym)
|
||||
Text->addChunk(Thunk->getChunk());
|
||||
DefinedImportData *Imp = File->ImpSym;
|
||||
if (Config->DelayLoads.count(Imp->getDLLName().lower())) {
|
||||
DelayIdata.add(Imp);
|
||||
} else {
|
||||
Idata.add(Imp);
|
||||
}
|
||||
}
|
||||
if (!Idata.empty()) {
|
||||
|
|
Loading…
Reference in New Issue