From d9dbf9e30a581fcadd667b6d8e5827a4003b85a2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 2 Oct 2022 21:10:28 -0700 Subject: [PATCH] [ELF] Move init from ELFFileBase constructor to a separate function. NFC --- lld/ELF/Driver.cpp | 9 ++++++--- lld/ELF/InputFiles.cpp | 29 +++++++++++++++++------------ lld/ELF/InputFiles.h | 1 + 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 2e71282..47878a0 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -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(mbref, withLOption ? path::filename(path) : path)); + auto *f = + make(mbref, withLOption ? path::filename(path) : path); + f->init(); + files.push_back(f); return; + } case file_magic::bitcode: files.push_back(make(mbref, "", 0, inLib)); break; diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 3ca9c0a..98f974f 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -449,32 +449,35 @@ Optional ObjFile::getDILineInfo(InputSectionBase *s, ELFFileBase::ELFFileBase(Kind k, ELFKind ekind, MemoryBufferRef mb) : InputFile(k, mb) { this->ekind = ekind; +} + +template +static const Elf_Shdr *findSection(ArrayRef sections, uint32_t type) { + for (const Elf_Shdr &sec : sections) + if (sec.sh_type == type) + return &sec; + return nullptr; +} + +void ELFFileBase::init() { switch (ekind) { case ELF32LEKind: - init(k); + init(fileKind); break; case ELF32BEKind: - init(k); + init(fileKind); break; case ELF64LEKind: - init(k); + init(fileKind); break; case ELF64BEKind: - init(k); + init(fileKind); break; default: llvm_unreachable("getELFKind"); } } -template -static const Elf_Shdr *findSection(ArrayRef sections, uint32_t type) { - for (const Elf_Shdr &sec : sections) - if (sec.sh_type == type) - return &sec; - return nullptr; -} - template void ELFFileBase::init(InputFile::Kind k) { using Elf_Shdr = typename ELFT::Shdr; using Elf_Sym = typename ELFT::Sym; @@ -1233,6 +1236,7 @@ template static bool isNonCommonDef(ELFKind ekind, MemoryBufferRef mb, StringRef symName, StringRef archiveName) { ObjFile *obj = make>(ekind, mb, archiveName); + obj->init(); StringRef stringtable = obj->getStringTable(); for (auto sym : obj->template getGlobalELFSyms()) { @@ -1754,6 +1758,7 @@ ELFFileBase *elf::createObjFile(MemoryBufferRef mb, StringRef archiveName, default: llvm_unreachable("getELFKind"); } + f->init(); f->lazy = lazy; return f; } diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 9ef086f..e318d9b 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -163,6 +163,7 @@ public: ELFFileBase(Kind k, ELFKind ekind, MemoryBufferRef m); static bool classof(const InputFile *f) { return f->isElf(); } + void init(); template llvm::object::ELFFile getObj() const { return check(llvm::object::ELFFile::create(mb.getBuffer())); } -- 2.7.4