Skip to content

Commit 25da870

Browse files
committed
[ELF] Remove irrelevant group signature hack working around old gold -r
1 parent 53804d4 commit 25da870

File tree

5 files changed

+9
-61
lines changed

5 files changed

+9
-61
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -426,18 +426,7 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
426426
if (sec.sh_info >= symbols.size())
427427
fatal(toString(this) + ": invalid symbol index");
428428
const typename ELFT::Sym &sym = symbols[sec.sh_info];
429-
StringRef signature = CHECK(sym.getName(this->stringTable), this);
430-
431-
// As a special case, if a symbol is a section symbol and has no name,
432-
// we use a section name as a signature.
433-
//
434-
// Such SHT_GROUP sections are invalid from the perspective of the ELF
435-
// standard, but GNU gold 1.14 (the newest version as of July 2017) or
436-
// older produce such sections as outputs for the -r option, so we need
437-
// a bug-compatibility.
438-
if (signature.empty() && sym.getType() == STT_SECTION)
439-
return getSectionName(sec);
440-
return signature;
429+
return CHECK(sym.getName(this->stringTable), this);
441430
}
442431

443432
template <class ELFT>
@@ -565,10 +554,9 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
565554
const ELFFile<ELFT> &obj = this->getObj();
566555

567556
ArrayRef<Elf_Shdr> objSections = CHECK(obj.sections(), this);
557+
StringRef shstrtab = CHECK(obj.getSectionStringTable(objSections), this);
568558
uint64_t size = objSections.size();
569559
this->sections.resize(size);
570-
this->sectionStringTable =
571-
CHECK(obj.getSectionStringTable(objSections), this);
572560

573561
std::vector<ArrayRef<Elf_Word>> selectedGroups;
574562

@@ -624,7 +612,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
624612
.second;
625613
if (keepGroup) {
626614
if (config->relocatable)
627-
this->sections[i] = createInputSection(sec);
615+
this->sections[i] = createInputSection(sec, shstrtab);
628616
selectedGroups.push_back(entries);
629617
continue;
630618
}
@@ -648,7 +636,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
648636
case SHT_NULL:
649637
break;
650638
default:
651-
this->sections[i] = createInputSection(sec);
639+
this->sections[i] = createInputSection(sec, shstrtab);
652640
}
653641
}
654642

@@ -665,7 +653,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
665653
const Elf_Shdr &sec = objSections[i];
666654

667655
if (sec.sh_type == SHT_REL || sec.sh_type == SHT_RELA)
668-
this->sections[i] = createInputSection(sec);
656+
this->sections[i] = createInputSection(sec, shstrtab);
669657

670658
// A SHF_LINK_ORDER section with sh_link=0 is handled as if it did not have
671659
// the flag.
@@ -874,8 +862,9 @@ static InputSection *toRegularSection(MergeInputSection *sec) {
874862
}
875863

876864
template <class ELFT>
877-
InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
878-
StringRef name = getSectionName(sec);
865+
InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec,
866+
StringRef shstrtab) {
867+
StringRef name = CHECK(getObj().getSectionName(sec, shstrtab), this);
879868

880869
if (config->emachine == EM_ARM && sec.sh_type == SHT_ARM_ATTRIBUTES) {
881870
ARMAttributeParser attributes;
@@ -1072,11 +1061,6 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
10721061
return make<InputSection>(*this, sec, name);
10731062
}
10741063

1075-
template <class ELFT>
1076-
StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &sec) {
1077-
return CHECK(getObj().getSectionName(sec, sectionStringTable), this);
1078-
}
1079-
10801064
// Initialize this->Symbols. this->Symbols is a parallel array as
10811065
// its corresponding ELF symbol table.
10821066
template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {

lld/ELF/InputFiles.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ template <class ELFT> class ObjFile : public ELFFileBase {
260260
void initializeJustSymbols();
261261

262262
InputSectionBase *getRelocTarget(const Elf_Shdr &sec);
263-
InputSectionBase *createInputSection(const Elf_Shdr &sec);
264-
StringRef getSectionName(const Elf_Shdr &sec);
263+
InputSectionBase *createInputSection(const Elf_Shdr &sec, StringRef shstrtab);
265264

266265
bool shouldMerge(const Elf_Shdr &sec, StringRef name);
267266

@@ -279,9 +278,6 @@ template <class ELFT> class ObjFile : public ELFFileBase {
279278
// If the section does not exist (which is common), the array is empty.
280279
ArrayRef<Elf_Word> shndxTable;
281280

282-
// .shstrtab contents.
283-
StringRef sectionStringTable;
284-
285281
// Debugging information to retrieve source file and line for error
286282
// reporting. Linker may find reasonable number of errors in a
287283
// single object file, so we cache debugging information in order to
-880 Bytes
Binary file not shown.

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

lld/test/ELF/sht-group-gold-r.test

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)