forked from OSchip/llvm-project
[ELF] Move init from ELFFileBase constructor to a separate function. NFC
This commit is contained in:
parent
9f77909a5e
commit
d9dbf9e30a
|
@ -281,7 +281,7 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
|
|||
++InputFile::nextGroupId;
|
||||
return;
|
||||
}
|
||||
case file_magic::elf_shared_object:
|
||||
case file_magic::elf_shared_object: {
|
||||
if (config->isStatic || config->relocatable) {
|
||||
error("attempted static link of dynamic object " + path);
|
||||
return;
|
||||
|
@ -292,9 +292,12 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
|
|||
// the directory part is ignored. Note that path may be a temporary and
|
||||
// cannot be stored into SharedFile::soName.
|
||||
path = mbref.getBufferIdentifier();
|
||||
files.push_back(
|
||||
make<SharedFile>(mbref, withLOption ? path::filename(path) : path));
|
||||
auto *f =
|
||||
make<SharedFile>(mbref, withLOption ? path::filename(path) : path);
|
||||
f->init();
|
||||
files.push_back(f);
|
||||
return;
|
||||
}
|
||||
case file_magic::bitcode:
|
||||
files.push_back(make<BitcodeFile>(mbref, "", 0, inLib));
|
||||
break;
|
||||
|
|
|
@ -449,22 +449,6 @@ Optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *s,
|
|||
ELFFileBase::ELFFileBase(Kind k, ELFKind ekind, MemoryBufferRef mb)
|
||||
: InputFile(k, mb) {
|
||||
this->ekind = ekind;
|
||||
switch (ekind) {
|
||||
case ELF32LEKind:
|
||||
init<ELF32LE>(k);
|
||||
break;
|
||||
case ELF32BEKind:
|
||||
init<ELF32BE>(k);
|
||||
break;
|
||||
case ELF64LEKind:
|
||||
init<ELF64LE>(k);
|
||||
break;
|
||||
case ELF64BEKind:
|
||||
init<ELF64BE>(k);
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("getELFKind");
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Elf_Shdr>
|
||||
|
@ -475,6 +459,25 @@ static const Elf_Shdr *findSection(ArrayRef<Elf_Shdr> sections, uint32_t type) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void ELFFileBase::init() {
|
||||
switch (ekind) {
|
||||
case ELF32LEKind:
|
||||
init<ELF32LE>(fileKind);
|
||||
break;
|
||||
case ELF32BEKind:
|
||||
init<ELF32BE>(fileKind);
|
||||
break;
|
||||
case ELF64LEKind:
|
||||
init<ELF64LE>(fileKind);
|
||||
break;
|
||||
case ELF64BEKind:
|
||||
init<ELF64BE>(fileKind);
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("getELFKind");
|
||||
}
|
||||
}
|
||||
|
||||
template <class ELFT> void ELFFileBase::init(InputFile::Kind k) {
|
||||
using Elf_Shdr = typename ELFT::Shdr;
|
||||
using Elf_Sym = typename ELFT::Sym;
|
||||
|
@ -1233,6 +1236,7 @@ template <class ELFT>
|
|||
static bool isNonCommonDef(ELFKind ekind, MemoryBufferRef mb, StringRef symName,
|
||||
StringRef archiveName) {
|
||||
ObjFile<ELFT> *obj = make<ObjFile<ELFT>>(ekind, mb, archiveName);
|
||||
obj->init();
|
||||
StringRef stringtable = obj->getStringTable();
|
||||
|
||||
for (auto sym : obj->template getGlobalELFSyms<ELFT>()) {
|
||||
|
@ -1754,6 +1758,7 @@ ELFFileBase *elf::createObjFile(MemoryBufferRef mb, StringRef archiveName,
|
|||
default:
|
||||
llvm_unreachable("getELFKind");
|
||||
}
|
||||
f->init();
|
||||
f->lazy = lazy;
|
||||
return f;
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@ public:
|
|||
ELFFileBase(Kind k, ELFKind ekind, MemoryBufferRef m);
|
||||
static bool classof(const InputFile *f) { return f->isElf(); }
|
||||
|
||||
void init();
|
||||
template <typename ELFT> llvm::object::ELFFile<ELFT> getObj() const {
|
||||
return check(llvm::object::ELFFile<ELFT>::create(mb.getBuffer()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue