Delete SyntheticUndefined.

Now that resolved is templated anyway, we can use the regular Undefined.

llvm-svn: 246407
This commit is contained in:
Rafael Espindola 2015-08-31 01:46:20 +00:00
parent 7b5563aa5c
commit f7d45f0869
4 changed files with 18 additions and 23 deletions

View File

@ -27,25 +27,29 @@ void SymbolTable::addFile(std::unique_ptr<InputFile> File) {
addObject(P); addObject(P);
} }
template <class ELFT> void SymbolTable::init() {
resolve<ELFT>(new (Alloc)
Undefined<ELFT>("_start", Undefined<ELFT>::Synthetic));
}
void SymbolTable::addObject(ObjectFileBase *File) { void SymbolTable::addObject(ObjectFileBase *File) {
if (!ObjectFiles.empty()) { if (!ObjectFiles.empty()) {
ObjectFileBase &Old = *ObjectFiles[0]; ObjectFileBase &Old = *ObjectFiles[0];
if (!Old.isCompatibleWith(*File)) if (!Old.isCompatibleWith(*File))
error(Twine(Old.getName() + " is incompatible with " + File->getName())); error(Twine(Old.getName() + " is incompatible with " + File->getName()));
} else { } else {
auto *Start = new (Alloc) SyntheticUndefined("_start");
switch (File->kind()) { switch (File->kind()) {
case InputFile::Object32LEKind: case InputFile::Object32LEKind:
resolve<ELF32LE>(Start); init<ELF32LE>();
break; break;
case InputFile::Object32BEKind: case InputFile::Object32BEKind:
resolve<ELF32BE>(Start); init<ELF32BE>();
break; break;
case InputFile::Object64LEKind: case InputFile::Object64LEKind:
resolve<ELF64LE>(Start); init<ELF64LE>();
break; break;
case InputFile::Object64BEKind: case InputFile::Object64BEKind:
resolve<ELF64BE>(Start); init<ELF64BE>();
break; break;
} }
} }

View File

@ -51,6 +51,7 @@ public:
private: private:
void addObject(ObjectFileBase *File); void addObject(ObjectFileBase *File);
template <class ELFT> void init();
template <class ELFT> void resolve(SymbolBody *Body); template <class ELFT> void resolve(SymbolBody *Body);
llvm::DenseMap<StringRef, Symbol *> Symtab; llvm::DenseMap<StringRef, Symbol *> Symtab;

View File

@ -42,16 +42,13 @@ public:
DefinedAbsoluteKind = 1, DefinedAbsoluteKind = 1,
DefinedCommonKind = 2, DefinedCommonKind = 2,
DefinedLast = 2, DefinedLast = 2,
UndefinedKind = 3, UndefinedKind = 3
UndefinedSyntheticKind = 4
}; };
Kind kind() const { return static_cast<Kind>(SymbolKind); } Kind kind() const { return static_cast<Kind>(SymbolKind); }
bool isWeak() const { return IsWeak; } bool isWeak() const { return IsWeak; }
bool isUndefined() const { bool isUndefined() const { return SymbolKind == UndefinedKind; }
return SymbolKind == UndefinedKind || SymbolKind == UndefinedSyntheticKind;
}
bool isDefined() const { return !isUndefined(); } bool isDefined() const { return !isUndefined(); }
bool isStrongUndefined() const { return !IsWeak && isUndefined(); } bool isStrongUndefined() const { return !IsWeak && isUndefined(); }
bool isCommon() const { return SymbolKind == DefinedCommonKind; } bool isCommon() const { return SymbolKind == DefinedCommonKind; }
@ -166,22 +163,14 @@ public:
const SectionChunk<ELFT> &Section; const SectionChunk<ELFT> &Section;
}; };
// Undefined symbols. // Undefined symbol.
class SyntheticUndefined : public SymbolBody {
public:
explicit SyntheticUndefined(StringRef N)
: SymbolBody(UndefinedKind, N, false) {}
static bool classof(const SymbolBody *S) {
return S->kind() == UndefinedSyntheticKind;
}
};
template <class ELFT> class Undefined : public ELFSymbolBody<ELFT> { template <class ELFT> class Undefined : public ELFSymbolBody<ELFT> {
typedef ELFSymbolBody<ELFT> Base; typedef ELFSymbolBody<ELFT> Base;
typedef typename Base::Elf_Sym Elf_Sym; typedef typename Base::Elf_Sym Elf_Sym;
public: public:
static Elf_Sym Synthetic;
explicit Undefined(StringRef N, const Elf_Sym &Sym) explicit Undefined(StringRef N, const Elf_Sym &Sym)
: ELFSymbolBody<ELFT>(Base::UndefinedKind, N, Sym) {} : ELFSymbolBody<ELFT>(Base::UndefinedKind, N, Sym) {}
@ -190,6 +179,9 @@ public:
} }
}; };
template <class ELFT>
typename Undefined<ELFT>::Elf_Sym Undefined<ELFT>::Synthetic;
} // namespace elf2 } // namespace elf2
} // namespace lld } // namespace lld

View File

@ -302,8 +302,6 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
const Elf_Sym *InputSym = nullptr; const Elf_Sym *InputSym = nullptr;
switch (Body->kind()) { switch (Body->kind()) {
case SymbolBody::UndefinedSyntheticKind:
llvm_unreachable("Should be defined by now");
case SymbolBody::DefinedRegularKind: { case SymbolBody::DefinedRegularKind: {
auto *Def = cast<DefinedRegular<ELFT>>(Body); auto *Def = cast<DefinedRegular<ELFT>>(Body);
InputSym = &Def->Sym; InputSym = &Def->Sym;