[fyi patch] Hack to avoid old gas bug

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 05:28:24 PST 2016


Gas 2.20 would use a section symbol as the group symbol in a comdat.
The attached patch is a hack to handle that.

I don't think it should be applying on trunk, but it is a convenient
hack while looking at other failures.

Cheers,
Rafael
-------------- next part --------------
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index de7e103..3356164 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -173,12 +173,19 @@ void elf::ObjectFile<ELFT>::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
 template <class ELFT>
 StringRef
 elf::ObjectFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> Sections,
-                                            const Elf_Shdr &Sec) {
+                                            const Elf_Shdr &Sec,
+                                            StringRef SectionStringTable) {
   if (this->Symbols.empty())
     this->initSymtab(Sections,
                      check(object::getSection<ELFT>(Sections, Sec.sh_link)));
   const Elf_Sym *Sym =
       check(object::getSymbol<ELFT>(this->Symbols, Sec.sh_info));
+  if (Sym->getType() == STT_SECTION) {
+    ELFFile<ELFT> Obj = this->getObj();
+    return check(Obj.getSectionName(
+        check(Obj.getSection(Sym, this->Symbols, this->SymtabSHNDX)),
+        SectionStringTable));
+  }
   return check(Sym->getName(this->StringTable));
 }
 
@@ -271,8 +278,9 @@ void elf::ObjectFile<ELFT>::initializeSections(
     switch (Sec.sh_type) {
     case SHT_GROUP:
       Sections[I] = &InputSection<ELFT>::Discarded;
-      if (ComdatGroups.insert(CachedHashStringRef(
-                                  getShtGroupSignature(ObjSections, Sec)))
+      if (ComdatGroups
+              .insert(CachedHashStringRef(
+                  getShtGroupSignature(ObjSections, Sec, SectionStringTable)))
               .second)
         continue;
       for (uint32_t SecIndex : getShtGroupEntries(Sec)) {
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index aba1d71..de51d97 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -130,7 +130,8 @@ template <class ELFT> class ObjectFile : public ELFFileBase<ELFT> {
   typedef typename ELFT::uint uintX_t;
 
   StringRef getShtGroupSignature(ArrayRef<Elf_Shdr> Sections,
-                                 const Elf_Shdr &Sec);
+                                 const Elf_Shdr &Sec,
+                                 StringRef SectionStringTable);
   ArrayRef<Elf_Word> getShtGroupEntries(const Elf_Shdr &Sec);
 
 public:
diff --git a/lld/test/ELF/Inputs/hack-old-gas.o b/lld/test/ELF/Inputs/hack-old-gas.o
new file mode 100644
index 0000000..59f8a47
Binary files /dev/null and b/lld/test/ELF/Inputs/hack-old-gas.o differ
diff --git a/lld/test/ELF/hack-old-gas.s b/lld/test/ELF/hack-old-gas.s
new file mode 100644
index 0000000..4d8cf0f
--- /dev/null
+++ b/lld/test/ELF/hack-old-gas.s
@@ -0,0 +1,18 @@
+// REQUIRES: x86
+// RUN: ld.lld %S/Inputs/hack-old-gas.o -o %t.so -shared
+// The .o file is this assembled with gas 2.20.
+
+	.section	.text.foo,"axG", at progbits,bah,comdat
+	.global foo
+	.hidden foo
+foo:
+	nop
+
+	.section	.text.bar,"axG", at progbits,baz,comdat
+	.global bar
+	.hidden bar
+bar:
+	nop
+
+	.data
+	.quad bar


More information about the llvm-commits mailing list