/// 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(
// 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;
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 =
}
}
- 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();
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)