From add2a66c000f87e2675c70ef7974a895d43cf96f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 7 Apr 2015 02:11:56 +0000 Subject: [PATCH] ELF: Move more code from createAtoms to handleGnuLinkOnceSection. So that createAtoms become more readable. llvm-svn: 234277 --- lld/lib/ReaderWriter/ELF/ELFFile.h | 54 ++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index b9226a1..9a15cc2 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -250,9 +250,8 @@ protected: /// Handle creation of atoms for .gnu.linkonce sections. std::error_code handleGnuLinkOnceSection( - StringRef sectionName, - llvm::StringMap *>> &atomsForSection, - const Elf_Shdr *shdr); + const Elf_Shdr *section, + llvm::StringMap *>> &atomsForSection); // Handle COMDAT scetions. std::error_code handleSectionGroup( @@ -670,10 +669,6 @@ template std::error_code ELFFile::createAtoms() { // the kindGroupChild reference. llvm::StringMap *>> atomsForSection; - // group sections have a mapping of the section header to the - // signature/section. - llvm::DenseMap linkOnceSections; - // Contains a list of comdat sections for a group. for (auto &i : _sectionSymbols) { const Elf_Shdr *section = i.first; @@ -697,15 +692,8 @@ template std::error_code ELFFile::createAtoms() { if (isGroupSection(section)) continue; - bool addAtoms = true; - - if (isGnuLinkOnceSection(*sectionName)) { - linkOnceSections.insert({section, *sectionName}); - addAtoms = false; - } - - if (isSectionMemberOfGroup(section)) - addAtoms = false; + bool addAtoms = (!isGnuLinkOnceSection(*sectionName) && + !isSectionMemberOfGroup(section)); if (handleSectionWithNoSymbols(section, symbols)) { ELFDefinedAtom *newAtom = @@ -828,14 +816,12 @@ template std::error_code ELFFile::createAtoms() { } } - for (auto &i : _sectionSymbols) { - const Elf_Shdr *section = i.first; - if (std::error_code ec = handleSectionGroup(section, atomsForSection)) + for (auto &i : _sectionSymbols) + if (std::error_code ec = handleSectionGroup(i.first, atomsForSection)) + return ec; + for (auto &i : _sectionSymbols) + if (std::error_code ec = handleGnuLinkOnceSection(i.first, atomsForSection)) return ec; - } - - for (auto § : linkOnceSections) - handleGnuLinkOnceSection(sect.second, atomsForSection, sect.first); updateReferences(); return std::error_code(); @@ -843,24 +829,28 @@ template std::error_code ELFFile::createAtoms() { template std::error_code ELFFile::handleGnuLinkOnceSection( - StringRef signature, - llvm::StringMap *>> &atomsForSection, - const Elf_Shdr *shdr) { - // TODO: Check for errors. + const Elf_Shdr *section, + llvm::StringMap *>> &atomsForSection) { + ErrorOr sectionName = this->getSectionName(section); + if (std::error_code ec = sectionName.getError()) + return ec; + if (!isGnuLinkOnceSection(*sectionName)) + return std::error_code(); + unsigned int referenceStart = _references.size(); std::vector *> refs; - for (auto ha : atomsForSection[signature]) { - _groupChild[ha->symbol()] = std::make_pair(signature, shdr); + for (auto ha : atomsForSection[*sectionName]) { + _groupChild[ha->symbol()] = std::make_pair(*sectionName, section); ELFReference *ref = new (_readerStorage) ELFReference(lld::Reference::kindGroupChild); ref->setTarget(ha); refs.push_back(ref); } - atomsForSection[signature].clear(); + atomsForSection[*sectionName].clear(); // Create a gnu linkonce atom. ELFDefinedAtom *atom = createDefinedAtom( - signature, signature, nullptr, shdr, ArrayRef(), referenceStart, - _references.size(), _references); + *sectionName, *sectionName, nullptr, section, ArrayRef(), + referenceStart, _references.size(), _references); atom->setOrdinal(++_ordinal); _definedAtoms._atoms.push_back(atom); for (auto reference : refs) -- 2.7.4