[lld] r234277 - ELF: Move more code from createAtoms to handleGnuLinkOnceSection.
Rui Ueyama
ruiu at google.com
Mon Apr 6 19:11:56 PDT 2015
Author: ruiu
Date: Mon Apr 6 21:11:56 2015
New Revision: 234277
URL: http://llvm.org/viewvc/llvm-project?rev=234277&view=rev
Log:
ELF: Move more code from createAtoms to handleGnuLinkOnceSection.
So that createAtoms become more readable.
Modified:
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=234277&r1=234276&r2=234277&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Mon Apr 6 21:11:56 2015
@@ -250,9 +250,8 @@ protected:
/// Handle creation of atoms for .gnu.linkonce sections.
std::error_code handleGnuLinkOnceSection(
- StringRef sectionName,
- llvm::StringMap<std::vector<ELFDefinedAtom<ELFT> *>> &atomsForSection,
- const Elf_Shdr *shdr);
+ const Elf_Shdr *section,
+ llvm::StringMap<std::vector<ELFDefinedAtom<ELFT> *>> &atomsForSection);
// Handle COMDAT scetions.
std::error_code handleSectionGroup(
@@ -670,10 +669,6 @@ template <class ELFT> std::error_code EL
// the kindGroupChild reference.
llvm::StringMap<std::vector<ELFDefinedAtom<ELFT> *>> atomsForSection;
- // group sections have a mapping of the section header to the
- // signature/section.
- llvm::DenseMap<const Elf_Shdr *, StringRef> 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 <class ELFT> std::error_code EL
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<ELFT> *newAtom =
@@ -828,14 +816,12 @@ template <class ELFT> std::error_code EL
}
}
- 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 <class ELFT> std::error_code EL
template <class ELFT>
std::error_code ELFFile<ELFT>::handleGnuLinkOnceSection(
- StringRef signature,
- llvm::StringMap<std::vector<ELFDefinedAtom<ELFT> *>> &atomsForSection,
- const Elf_Shdr *shdr) {
- // TODO: Check for errors.
+ const Elf_Shdr *section,
+ llvm::StringMap<std::vector<ELFDefinedAtom<ELFT> *>> &atomsForSection) {
+ ErrorOr<StringRef> 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<ELFReference<ELFT> *> 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<ELFT> *ref =
new (_readerStorage) ELFReference<ELFT>(lld::Reference::kindGroupChild);
ref->setTarget(ha);
refs.push_back(ref);
}
- atomsForSection[signature].clear();
+ atomsForSection[*sectionName].clear();
// Create a gnu linkonce atom.
ELFDefinedAtom<ELFT> *atom = createDefinedAtom(
- signature, signature, nullptr, shdr, ArrayRef<uint8_t>(), referenceStart,
- _references.size(), _references);
+ *sectionName, *sectionName, nullptr, section, ArrayRef<uint8_t>(),
+ referenceStart, _references.size(), _references);
atom->setOrdinal(++_ordinal);
_definedAtoms._atoms.push_back(atom);
for (auto reference : refs)
More information about the llvm-commits
mailing list