[lld] 25da870 - [ELF] Remove irrelevant group signature hack working around old gold -r

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 15:09:14 PDT 2021


Author: Fangrui Song
Date: 2021-10-25T15:09:08-07:00
New Revision: 25da870057f0edbe19221dd87a7f9a7c41f2cc7c

URL: https://github.com/llvm/llvm-project/commit/25da870057f0edbe19221dd87a7f9a7c41f2cc7c
DIFF: https://github.com/llvm/llvm-project/commit/25da870057f0edbe19221dd87a7f9a7c41f2cc7c.diff

LOG: [ELF] Remove irrelevant group signature hack working around old gold -r

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp
    lld/ELF/InputFiles.h

Removed: 
    lld/test/ELF/Inputs/sht-group-gold-r.elf
    lld/test/ELF/Inputs/sht-group-gold-r.s
    lld/test/ELF/sht-group-gold-r.test


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 5104d2dd453d..2b80c1dd42e6 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -426,18 +426,7 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
   if (sec.sh_info >= symbols.size())
     fatal(toString(this) + ": invalid symbol index");
   const typename ELFT::Sym &sym = symbols[sec.sh_info];
-  StringRef signature = CHECK(sym.getName(this->stringTable), this);
-
-  // As a special case, if a symbol is a section symbol and has no name,
-  // we use a section name as a signature.
-  //
-  // Such SHT_GROUP sections are invalid from the perspective of the ELF
-  // standard, but GNU gold 1.14 (the newest version as of July 2017) or
-  // older produce such sections as outputs for the -r option, so we need
-  // a bug-compatibility.
-  if (signature.empty() && sym.getType() == STT_SECTION)
-    return getSectionName(sec);
-  return signature;
+  return CHECK(sym.getName(this->stringTable), this);
 }
 
 template <class ELFT>
@@ -565,10 +554,9 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
   const ELFFile<ELFT> &obj = this->getObj();
 
   ArrayRef<Elf_Shdr> objSections = CHECK(obj.sections(), this);
+  StringRef shstrtab = CHECK(obj.getSectionStringTable(objSections), this);
   uint64_t size = objSections.size();
   this->sections.resize(size);
-  this->sectionStringTable =
-      CHECK(obj.getSectionStringTable(objSections), this);
 
   std::vector<ArrayRef<Elf_Word>> selectedGroups;
 
@@ -624,7 +612,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
               .second;
       if (keepGroup) {
         if (config->relocatable)
-          this->sections[i] = createInputSection(sec);
+          this->sections[i] = createInputSection(sec, shstrtab);
         selectedGroups.push_back(entries);
         continue;
       }
@@ -648,7 +636,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
     case SHT_NULL:
       break;
     default:
-      this->sections[i] = createInputSection(sec);
+      this->sections[i] = createInputSection(sec, shstrtab);
     }
   }
 
@@ -665,7 +653,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
     const Elf_Shdr &sec = objSections[i];
 
     if (sec.sh_type == SHT_REL || sec.sh_type == SHT_RELA)
-      this->sections[i] = createInputSection(sec);
+      this->sections[i] = createInputSection(sec, shstrtab);
 
     // A SHF_LINK_ORDER section with sh_link=0 is handled as if it did not have
     // the flag.
@@ -874,8 +862,9 @@ static InputSection *toRegularSection(MergeInputSection *sec) {
 }
 
 template <class ELFT>
-InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
-  StringRef name = getSectionName(sec);
+InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec,
+                                                    StringRef shstrtab) {
+  StringRef name = CHECK(getObj().getSectionName(sec, shstrtab), this);
 
   if (config->emachine == EM_ARM && sec.sh_type == SHT_ARM_ATTRIBUTES) {
     ARMAttributeParser attributes;
@@ -1072,11 +1061,6 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
   return make<InputSection>(*this, sec, name);
 }
 
-template <class ELFT>
-StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &sec) {
-  return CHECK(getObj().getSectionName(sec, sectionStringTable), this);
-}
-
 // Initialize this->Symbols. this->Symbols is a parallel array as
 // its corresponding ELF symbol table.
 template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {

diff  --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 5f7169c9135c..d925ffd680c1 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -260,8 +260,7 @@ template <class ELFT> class ObjFile : public ELFFileBase {
   void initializeJustSymbols();
 
   InputSectionBase *getRelocTarget(const Elf_Shdr &sec);
-  InputSectionBase *createInputSection(const Elf_Shdr &sec);
-  StringRef getSectionName(const Elf_Shdr &sec);
+  InputSectionBase *createInputSection(const Elf_Shdr &sec, StringRef shstrtab);
 
   bool shouldMerge(const Elf_Shdr &sec, StringRef name);
 
@@ -279,9 +278,6 @@ template <class ELFT> class ObjFile : public ELFFileBase {
   // If the section does not exist (which is common), the array is empty.
   ArrayRef<Elf_Word> shndxTable;
 
-  // .shstrtab contents.
-  StringRef sectionStringTable;
-
   // Debugging information to retrieve source file and line for error
   // reporting. Linker may find reasonable number of errors in a
   // single object file, so we cache debugging information in order to

diff  --git a/lld/test/ELF/Inputs/sht-group-gold-r.elf b/lld/test/ELF/Inputs/sht-group-gold-r.elf
deleted file mode 100644
index d2309c92217e..000000000000
Binary files a/lld/test/ELF/Inputs/sht-group-gold-r.elf and /dev/null 
diff er

diff  --git a/lld/test/ELF/Inputs/sht-group-gold-r.s b/lld/test/ELF/Inputs/sht-group-gold-r.s
deleted file mode 100644
index aca262ddaa4e..000000000000
--- a/lld/test/ELF/Inputs/sht-group-gold-r.s
+++ /dev/null
@@ -1,14 +0,0 @@
-# sht-group-gold-r.elf is produced by
-#
-#   llvm-mc -filetype=obj -triple=x86_64-pc-linux sht-group-gold-r.s -o sht-group-gold-r.o
-#   ld.gold -o sht-group-gold-r.elf -r sht-group-gold-r.o
-
-.global foo, bar
-
-.section .text.foo,"aG", at progbits,group_foo,comdat
-foo:
-  nop
-
-.section .text.bar,"aG", at progbits,group_bar,comdat
-bar:
-  nop

diff  --git a/lld/test/ELF/sht-group-gold-r.test b/lld/test/ELF/sht-group-gold-r.test
deleted file mode 100644
index c1650ede4e9b..000000000000
--- a/lld/test/ELF/sht-group-gold-r.test
+++ /dev/null
@@ -1,18 +0,0 @@
-# REQUIRES: x86
-# GNU gold 1.14 (the newest version as of July 2017) seems to create
-# non-standard-compliant SHT_GROUP sections when the -r option is given.
-#
-# Such SHT_GROUP sections use section names as their signatures
-# instead of symbols pointed by sh_link field. Since it is prevalent,
-# we accept such nonstandard sections.
-
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld %p/Inputs/sht-group-gold-r.elf %t.o -o %t.exe
-# RUN: llvm-objdump -t %t.exe | FileCheck %s
-
-# CHECK: .text 0000000000000000 bar
-# CHECK: .text 0000000000000000 foo
-
-.globl _start
-_start:
-  ret


        


More information about the llvm-commits mailing list