@@ -556,12 +556,45 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
556
556
sections.resize (size);
557
557
for (size_t i = 0 ; i != size; ++i) {
558
558
const Elf_Shdr &sec = objSections[i];
559
+ if (LLVM_LIKELY (sec.sh_type == SHT_PROGBITS))
560
+ continue ;
561
+ if (LLVM_LIKELY (sec.sh_type == SHT_GROUP)) {
562
+ StringRef signature = getShtGroupSignature (objSections, sec);
563
+ ArrayRef<Elf_Word> entries =
564
+ CHECK2 (obj.template getSectionContentsAsArray <Elf_Word>(sec), this );
565
+ if (entries.empty ())
566
+ Fatal (ctx) << this << " : empty SHT_GROUP" ;
567
+
568
+ Elf_Word flag = entries[0 ];
569
+ if (flag && flag != GRP_COMDAT)
570
+ Fatal (ctx) << this << " : unsupported SHT_GROUP format" ;
571
+
572
+ bool keepGroup = !flag || ignoreComdats ||
573
+ ctx.symtab ->comdatGroups
574
+ .try_emplace (CachedHashStringRef (signature), this )
575
+ .second ;
576
+ if (keepGroup) {
577
+ if (!ctx.arg .resolveGroups )
578
+ sections[i] = createInputSection (
579
+ i, sec, check (obj.getSectionName (sec, shstrtab)));
580
+ } else {
581
+ // Otherwise, discard group members.
582
+ for (uint32_t secIndex : entries.slice (1 )) {
583
+ if (secIndex >= size)
584
+ Fatal (ctx) << this
585
+ << " : invalid section index in group: " << secIndex;
586
+ sections[secIndex] = &InputSection::discarded;
587
+ }
588
+ }
589
+ continue ;
590
+ }
591
+
559
592
if (sec.sh_type == SHT_LLVM_DEPENDENT_LIBRARIES && !ctx.arg .relocatable ) {
560
593
StringRef name = check (obj.getSectionName (sec, shstrtab));
561
594
ArrayRef<char > data = CHECK2 (
562
595
this ->getObj ().template getSectionContentsAsArray <char >(sec), this );
563
596
if (!data.empty () && data.back () != ' \0 ' ) {
564
- ErrAlways (ctx)
597
+ Err (ctx)
565
598
<< this
566
599
<< " : corrupted dependent libraries section (unterminated string): "
567
600
<< name;
@@ -572,74 +605,48 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
572
605
d += s.size () + 1 ;
573
606
}
574
607
}
575
- this -> sections [i] = &InputSection::discarded;
608
+ sections[i] = &InputSection::discarded;
576
609
continue ;
577
610
}
578
611
579
- if (sec.sh_type == SHT_ARM_ATTRIBUTES && ctx.arg .emachine == EM_ARM) {
580
- ARMAttributeParser attributes;
581
- ArrayRef<uint8_t > contents =
582
- check (this ->getObj ().getSectionContents (sec));
583
- StringRef name = check (obj.getSectionName (sec, shstrtab));
584
- this ->sections [i] = &InputSection::discarded;
585
- if (Error e = attributes.parse (contents, ekind == ELF32LEKind
586
- ? llvm::endianness::little
587
- : llvm::endianness::big)) {
588
- InputSection isec (*this , sec, name);
589
- Warn (ctx) << &isec << " : " << std::move (e);
590
- } else {
591
- updateSupportedARMFeatures (ctx, attributes);
592
- updateARMVFPArgs (ctx, attributes, this );
593
-
594
- // FIXME: Retain the first attribute section we see. The eglibc ARM
595
- // dynamic loaders require the presence of an attribute section for
596
- // dlopen to work. In a full implementation we would merge all attribute
597
- // sections.
598
- if (ctx.in .attributes == nullptr ) {
599
- ctx.in .attributes = std::make_unique<InputSection>(*this , sec, name);
600
- this ->sections [i] = ctx.in .attributes .get ();
612
+ switch (ctx.arg .emachine ) {
613
+ case EM_ARM:
614
+ if (sec.sh_type == SHT_ARM_ATTRIBUTES) {
615
+ ARMAttributeParser attributes;
616
+ ArrayRef<uint8_t > contents =
617
+ check (this ->getObj ().getSectionContents (sec));
618
+ StringRef name = check (obj.getSectionName (sec, shstrtab));
619
+ sections[i] = &InputSection::discarded;
620
+ if (Error e = attributes.parse (contents, ekind == ELF32LEKind
621
+ ? llvm::endianness::little
622
+ : llvm::endianness::big)) {
623
+ InputSection isec (*this , sec, name);
624
+ Warn (ctx) << &isec << " : " << std::move (e);
625
+ } else {
626
+ updateSupportedARMFeatures (ctx, attributes);
627
+ updateARMVFPArgs (ctx, attributes, this );
628
+
629
+ // FIXME: Retain the first attribute section we see. The eglibc ARM
630
+ // dynamic loaders require the presence of an attribute section for
631
+ // dlopen to work. In a full implementation we would merge all
632
+ // attribute sections.
633
+ if (ctx.in .attributes == nullptr ) {
634
+ ctx.in .attributes =
635
+ std::make_unique<InputSection>(*this , sec, name);
636
+ sections[i] = ctx.in .attributes .get ();
637
+ }
601
638
}
602
639
}
603
- }
604
-
605
- // Producing a static binary with MTE globals is not currently supported,
606
- // remove all SHT_AARCH64_MEMTAG_GLOBALS_STATIC sections as they're unused
607
- // medatada, and we don't want them to end up in the output file for static
608
- // executables.
609
- if (sec.sh_type == SHT_AARCH64_MEMTAG_GLOBALS_STATIC &&
610
- !canHaveMemtagGlobals (ctx)) {
611
- this ->sections [i] = &InputSection::discarded;
612
- continue ;
613
- }
614
-
615
- if (sec.sh_type != SHT_GROUP)
616
- continue ;
617
- StringRef signature = getShtGroupSignature (objSections, sec);
618
- ArrayRef<Elf_Word> entries =
619
- CHECK2 (obj.template getSectionContentsAsArray <Elf_Word>(sec), this );
620
- if (entries.empty ())
621
- Fatal (ctx) << this << " : empty SHT_GROUP" ;
622
-
623
- Elf_Word flag = entries[0 ];
624
- if (flag && flag != GRP_COMDAT)
625
- Fatal (ctx) << this << " : unsupported SHT_GROUP format" ;
626
-
627
- bool keepGroup = (flag & GRP_COMDAT) == 0 || ignoreComdats ||
628
- ctx.symtab ->comdatGroups
629
- .try_emplace (CachedHashStringRef (signature), this )
630
- .second ;
631
- if (keepGroup) {
632
- if (!ctx.arg .resolveGroups )
633
- this ->sections [i] = createInputSection (
634
- i, sec, check (obj.getSectionName (sec, shstrtab)));
635
- continue ;
636
- }
637
-
638
- // Otherwise, discard group members.
639
- for (uint32_t secIndex : entries.slice (1 )) {
640
- if (secIndex >= size)
641
- Fatal (ctx) << this << " : invalid section index in group: " << secIndex;
642
- this ->sections [secIndex] = &InputSection::discarded;
640
+ break ;
641
+ case EM_AARCH64:
642
+ // Producing a static binary with MTE globals is not currently supported,
643
+ // remove all SHT_AARCH64_MEMTAG_GLOBALS_STATIC sections as they're unused
644
+ // medatada, and we don't want them to end up in the output file for
645
+ // static executables.
646
+ if (sec.sh_type == SHT_AARCH64_MEMTAG_GLOBALS_STATIC &&
647
+ !canHaveMemtagGlobals (ctx))
648
+ sections[i] = &InputSection::discarded;
649
+ break ;
643
650
}
644
651
}
645
652
0 commit comments