COFF: simplify thunk handling (NFC)

Apply the simplification suggestions that Peter Collingbourne made
during the review at D37368.  The returned thunk is cast to the
appropriate type in the SymbolTable, and the constant symbol's body is
not needed directly, so avoid the assignment.  NFC

llvm-svn: 312391
This commit is contained in:
Saleem Abdulrasool 2017-09-01 23:35:43 +00:00
parent 6b1de0e673
commit 353c57a3f6
4 changed files with 12 additions and 15 deletions

View File

@ -355,19 +355,16 @@ void ImportFile::parse() {
this->Hdr = Hdr;
ExternalName = ExtName;
if (Symbol *S = Symtab->addImportData(ImpName, this))
ImpSym = cast<DefinedImportData>(S->body());
ImpSym = Symtab->addImportData(ImpName, this);
if (Hdr->getType() == llvm::COFF::IMPORT_CONST)
if (Symbol *S = Symtab->addImportData(Name, this))
ConstSym = cast<DefinedImportData>(S->body());
static_cast<void>(Symtab->addImportData(Name, this));
// 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)
if (Symbol *S = Symtab->addImportThunk(Name, ImpSym, Hdr->Machine))
ThunkSym = cast<DefinedImportThunk>(S->body());
ThunkSym = Symtab->addImportThunk(Name, ImpSym, Hdr->Machine);
}
void BitcodeFile::parse() {

View File

@ -186,7 +186,6 @@ public:
static std::vector<ImportFile *> Instances;
DefinedImportData *ImpSym = nullptr;
DefinedImportData *ConstSym = nullptr;
DefinedImportThunk *ThunkSym = nullptr;
std::string DLLName;

View File

@ -269,29 +269,30 @@ Symbol *SymbolTable::addCommon(InputFile *F, StringRef N, uint64_t Size,
return S;
}
Symbol *SymbolTable::addImportData(StringRef N, ImportFile *F) {
DefinedImportData *SymbolTable::addImportData(StringRef N, ImportFile *F) {
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(N);
S->IsUsedInRegularObj = true;
if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body())) {
replaceBody<DefinedImportData>(S, N, F);
return S;
return cast<DefinedImportData>(S->body());
}
reportDuplicate(S, F);
return nullptr;
}
Symbol *SymbolTable::addImportThunk(StringRef Name, DefinedImportData *ID,
uint16_t Machine) {
DefinedImportThunk *SymbolTable::addImportThunk(StringRef Name,
DefinedImportData *ID,
uint16_t Machine) {
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name);
S->IsUsedInRegularObj = true;
if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body())) {
replaceBody<DefinedImportThunk>(S, Name, ID, Machine);
return S;
return cast<DefinedImportThunk>(S->body());
}
reportDuplicate(S, ID->File);

View File

@ -90,9 +90,9 @@ public:
Symbol *addCommon(InputFile *F, StringRef N, uint64_t Size,
const llvm::object::coff_symbol_generic *S = nullptr,
CommonChunk *C = nullptr);
Symbol *addImportData(StringRef N, ImportFile *F);
Symbol *addImportThunk(StringRef Name, DefinedImportData *S,
uint16_t Machine);
DefinedImportData *addImportData(StringRef N, ImportFile *F);
DefinedImportThunk *addImportThunk(StringRef Name, DefinedImportData *S,
uint16_t Machine);
void reportDuplicate(Symbol *Existing, InputFile *NewFile);