[PATCH] D148754: [LLD][RFC] Deduplicate type units with local ThinLTO

Alexander Yermolovich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 16:21:52 PDT 2023


ayermolo updated this revision to Diff 515124.
ayermolo added a comment.

a bit of cleanup


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148754/new/

https://reviews.llvm.org/D148754

Files:
  lld/ELF/InputFiles.cpp


Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -518,6 +518,31 @@
       this);
 }
 
+
+/// For DWARF4 the Type Units are in their own seperate .debug_types section.
+/// For DWARF5 they are part of the .debug_info section.
+/// Returns true if link group contains either of those sections.
+template <class ELFT, class Elf_Word>
+static bool isDebugGroupSection(ObjFile<ELFT> &objFile,
+                                ArrayRef<Elf_Word> &entries,
+                                StringRef &shstrtab) {
+  ArrayRef<Elf_Word> ndxArray = entries.slice(1);
+  object::ELFFile<ELFT> obj = objFile.getObj();
+  for (uint32_t ndx : ndxArray) {
+    Expected<const typename ELFT::Shdr *> grpSection = obj.getSection(ndx);
+    if (!grpSection) {
+      warn(toString(&objFile) + " : " +
+           toString(std::move(grpSection.takeError())));
+      break;
+    }
+    StringRef name = check(obj.getSectionName(**grpSection, shstrtab));
+    if ((name.find("debug_types") != StringRef::npos) ||
+        (name.find("debug_info") != StringRef::npos))
+      return true;
+  }
+  return false;
+}
+
 template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
   object::ELFFile<ELFT> obj = this->getObj();
   // Read a section table. justSymbols is usually false.
@@ -588,13 +613,12 @@
         CHECK(obj.template getSectionContentsAsArray<Elf_Word>(sec), this);
     if (entries.empty())
       fatal(toString(this) + ": empty SHT_GROUP");
-
     Elf_Word flag = entries[0];
     if (flag && flag != GRP_COMDAT)
       fatal(toString(this) + ": unsupported SHT_GROUP format");
-
+    bool isDebugSection = isDebugGroupSection<ELFT, Elf_Word>(*this, entries, shstrtab);
     bool keepGroup =
-        (flag & GRP_COMDAT) == 0 || ignoreComdats ||
+        (flag & GRP_COMDAT) == 0 || (ignoreComdats && !isDebugSection) ||
         symtab.comdatGroups.try_emplace(CachedHashStringRef(signature), this)
             .second;
     if (keepGroup) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148754.515124.patch
Type: text/x-patch
Size: 2057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230419/12c2e30b/attachment.bin>


More information about the llvm-commits mailing list