<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Overall looking good. Nice use of PointerIntPair.</div><div class="gmail_quote"><pre style="color:rgb(0,0,0)">   for (const Elf_Shdr &Sec : Obj.sections()) {
+    ++I;
+    if (Sections[I] == &InputSection<ELFT>::Discarded)
+      continue;
+
     switch (Sec.sh_type) {
+    case SHT_GROUP: {
+      Sections[I] = &InputSection<ELFT>::Discarded;
+      uint32_t SymtabdSectionIndex = Sec.sh_link;
+      ErrorOr<const Elf_Shdr *> SecOrErr = Obj.getSection(SymtabdSectionIndex);
+      error(SecOrErr);
+      const Elf_Shdr *SymtabSec = *SecOrErr;
+      uint32_t SymIndex = Sec.sh_info;
+      const Elf_Sym *Sym = Obj.getSymbol(SymtabSec, SymIndex);
+      ErrorOr<StringRef> StringTableOrErr =
+          Obj.getStringTableForSymtab(*SymtabSec);
+      error(StringTableOrErr);
+      ErrorOr<StringRef> SignatureOrErr = Sym->getName(*StringTableOrErr);
+      error(SignatureOrErr);
+      if (Symtab.insertComdat(*SignatureOrErr))
+        continue;
+      typedef support::detail::packed_endian_specific_integral<
+          uint32_t, ELFT::TargetEndianness, 2> EntryType;
+      ErrorOr<ArrayRef<EntryType>> EntriesOrErr =
+          Obj.template getSectionContentsAsArray<EntryType>(&Sec);
+      error(EntriesOrErr.getError());
+      ArrayRef<EntryType> Entries = *EntriesOrErr;
+      if (Entries.empty() || Entries[0] != GRP_COMDAT)
+        error("Unsupported SHT_GROUP format");
+      for (EntryType E : Entries.slice(1)) {
+        uint32_t SecIndex = E;
+        if (SecIndex >= Size)
+          error("Invalid section index in group");
+        Sections[SecIndex] = &InputSection<ELFT>::Discarded;
+      }
+      break;
+    }</pre></div><div class="gmail_quote"><br></div><div class="gmail_quote">I'd define</div><div class="gmail_quote"><br></div><div class="gmail_quote">  StringRef ObjectFile<ELFT>::getShtGroupSignature(const Elf_Shdr &)</div><div class="gmail_quote"><br></div><div class="gmail_quote">and</div><div class="gmail_quote"><br></div><div class="gmail_quote">  ArrayRef<EntryType> ObjectFile<ELFT>::getShtGroupEntries(const Elf_Shdr &)</div><div class="gmail_quote"><br></div><div class="gmail_quote">so that I can write like this</div><div class="gmail_quote"><br></div><div class="gmail_quote">  Sections[I] = &InputSection<ELFT>::Discarded;</div><div class="gmail_quote">  if (Symtab.insertComdat(getShtGroupSignature(Sec))</div><div class="gmail_quote">    continue;</div><div class="gmail_quote">  for (EntryType E : getShtGroupEntries(Sec)) {</div><div class="gmail_quote">    uint32_t Idx = E;</div><div class="gmail_quote">    if (Idx >= Size)</div><div class="gmail_quote">      error(...);</div><div class="gmail_quote">    Sections[Idx] = &InputSection<ELFT>::Discarded;</div><div class="gmail_quote">  }</div><div class="gmail_quote"><br></div><div class="gmail_quote"><pre style="color:rgb(0,0,0)">+  typedef llvm::MapVector<StringRef, llvm::PointerIntPair<Symbol *, 1>> MapType;
+  typedef MapType::const_iterator raw_iter;
+  struct iter : public llvm::iterator_adaptor_base<
+                    iter, raw_iter,
+                    typename std::iterator_traits<raw_iter>::iterator_category,
+                    const std::pair<StringRef, Symbol *>> {
+    iter(raw_iter u) : iter::iterator_adaptor_base(u) {}
+    const std::pair<StringRef, Symbol *> operator*() const {
+      const std::pair<StringRef, llvm::PointerIntPair<Symbol *, 1>> &V = *I;
+      std::pair<StringRef, Symbol *> V2(V.first, V.second.getPointer());
+      return V2;</pre></div><div class="gmail_quote">Why don't you return V2 directly (without using V2)?</div><div class="gmail_quote"><br></div><div class="gmail_quote">On Thu, Oct 8, 2015 at 3:06 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The attached patch adds comdat handling to the new elf lld.<br>
<br>
The implementation is direct translation to c++ of the rules in<br>
<br>
<a href="http://www.sco.com/developers/gabi/latest/ch4.sheader.html#section_groups" rel="noreferrer" target="_blank">http://www.sco.com/developers/gabi/latest/ch4.sheader.html#section_groups</a><br>
<br>
The patch is "raw" is that it still has duplicated code and is missing comments.<br>
<br>
I have attached the patch, run script and benchmark results linking<br>
clang, but the summary is<br>
<br>
gold:<br>
* clang is 77 898 792 bytes.<br>
* 1.125165215 seconds time elapsed<br>
<br>
trunk:<br>
* clang is 92 442 088 bytes.<br>
* 0.495383463 seconds time elapsed<br>
<br>
patch:<br>
* clang is 87 491 896 bytes.<br>
* 0.475477433 seconds time elapsed<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div></div>