@@ -57,33 +57,34 @@ class ContiguousBlobAccumulator {
57
57
} // end anonymous namespace
58
58
59
59
// Used to keep track of section and symbol names, so that in the YAML file
60
- // sections and symbols can be referenced by name instead of by index.
61
- namespace {
62
- class NameToIdxMap {
63
- StringMap<int > Map;
64
- public:
65
- // / \returns true if name is already present in the map.
66
- bool addName (StringRef Name, unsigned i) {
67
- return !Map.insert (std::make_pair (Name, (int )i)).second ;
68
- }
69
- // / \returns true if name is not present in the map
70
- bool lookup (StringRef Name, unsigned &Idx) const {
71
- StringMap<int >::const_iterator I = Map.find (Name);
72
- if (I == Map.end ())
73
- return true ;
74
- Idx = I->getValue ();
75
- return false ;
76
- }
77
- // / asserts if name is not present in the map
78
- unsigned get (StringRef Name) const {
79
- unsigned Idx = 0 ;
80
- auto missing = lookup (Name, Idx);
81
- (void )missing;
82
- assert (!missing && " Expected section not found in index" );
83
- return Idx;
84
- }
85
- unsigned size () const { return Map.size (); }
86
- };
60
+ // sections and symbols can be referenced by name instead of by index.
61
+ namespace {
62
+ class NameToIdxMap {
63
+ StringMap<unsigned > Map;
64
+
65
+ public:
66
+ // / \Returns false if name is already present in the map.
67
+ bool addName (StringRef Name, unsigned Ndx) {
68
+ return Map.insert ({Name, Ndx}).second ;
69
+ }
70
+ // / \Returns false if name is not present in the map.
71
+ bool lookup (StringRef Name, unsigned &Idx) const {
72
+ auto I = Map.find (Name);
73
+ if (I == Map.end ())
74
+ return false ;
75
+ Idx = I->getValue ();
76
+ return true ;
77
+ }
78
+ // / Asserts if name is not present in the map.
79
+ unsigned get (StringRef Name) const {
80
+ unsigned Idx;
81
+ if (lookup (Name, Idx))
82
+ return Idx;
83
+ assert (false && " Expected section not found in index" );
84
+ return 0 ;
85
+ }
86
+ unsigned size () const { return Map.size (); }
87
+ };
87
88
} // end anonymous namespace
88
89
89
90
template <class T >
@@ -235,13 +236,13 @@ void ELFState<ELFT>::initProgramHeaders(std::vector<Elf_Phdr> &PHeaders) {
235
236
PHeaders.push_back (Phdr);
236
237
}
237
238
}
238
-
239
- static bool convertSectionIndex (NameToIdxMap &SN2I, StringRef SecName,
240
- StringRef IndexSrc, unsigned &IndexDest) {
241
- if (SN2I.lookup (IndexSrc, IndexDest) && !to_integer (IndexSrc, IndexDest)) {
242
- WithColor::error () << " Unknown section referenced: '" << IndexSrc
243
- << " ' at YAML section '" << SecName << " '.\n " ;
244
- return false ;
239
+
240
+ static bool convertSectionIndex (NameToIdxMap &SN2I, StringRef SecName,
241
+ StringRef IndexSrc, unsigned &IndexDest) {
242
+ if (! SN2I.lookup (IndexSrc, IndexDest) && !to_integer (IndexSrc, IndexDest)) {
243
+ WithColor::error () << " Unknown section referenced: '" << IndexSrc
244
+ << " ' at YAML section '" << SecName << " '.\n " ;
245
+ return false ;
245
246
}
246
247
return true ;
247
248
}
@@ -392,13 +393,13 @@ void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
392
393
for (auto &YamlPhdr : Doc.ProgramHeaders ) {
393
394
Elf_Phdr &PHeader = PHeaders[PhdrIdx++];
394
395
395
- std::vector<Elf_Shdr *> Sections;
396
- for (const ELFYAML::SectionName &SecName : YamlPhdr.Sections ) {
397
- unsigned Index;
398
- if (SN2I.lookup (SecName.Section , Index)) {
399
- WithColor::error () << " Unknown section referenced: '" << SecName.Section
400
- << " ' by program header.\n " ;
401
- exit (1 );
396
+ std::vector<Elf_Shdr *> Sections;
397
+ for (const ELFYAML::SectionName &SecName : YamlPhdr.Sections ) {
398
+ unsigned Index;
399
+ if (! SN2I.lookup (SecName.Section , Index)) {
400
+ WithColor::error () << " Unknown section referenced: '" << SecName.Section
401
+ << " ' by program header.\n " ;
402
+ exit (1 );
402
403
}
403
404
Sections.push_back (&SHeaders[Index]);
404
405
}
@@ -469,13 +470,13 @@ void ELFState<ELFT>::addSymbols(ArrayRef<ELFYAML::Symbol> Symbols,
469
470
zero (Symbol);
470
471
if (!Sym.Name .empty ())
471
472
Symbol.st_name = Strtab.getOffset (Sym.Name );
472
- Symbol.setBindingAndType (Sym.Binding , Sym.Type );
473
- if (!Sym.Section .empty ()) {
474
- unsigned Index;
475
- if (SN2I.lookup (Sym.Section , Index)) {
476
- WithColor::error () << " Unknown section referenced: '" << Sym.Section
477
- << " ' by YAML symbol " << Sym.Name << " .\n " ;
478
- exit (1 );
473
+ Symbol.setBindingAndType (Sym.Binding , Sym.Type );
474
+ if (!Sym.Section .empty ()) {
475
+ unsigned Index;
476
+ if (! SN2I.lookup (Sym.Section , Index)) {
477
+ WithColor::error () << " Unknown section referenced: '" << Sym.Section
478
+ << " ' by YAML symbol " << Sym.Name << " .\n " ;
479
+ exit (1 );
479
480
}
480
481
Symbol.st_shndx = Index;
481
482
} else if (Sym.Index ) {
@@ -543,13 +544,13 @@ ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
543
544
auto &OS = CBA.getOSAndAlignedOffset (SHeader.sh_offset , SHeader.sh_addralign );
544
545
545
546
for (const auto &Rel : Section.Relocations ) {
546
- unsigned SymIdx = 0 ;
547
- // If a relocation references a symbol, try to look one up in the symbol
548
- // table. If it is not there, treat the value as a symbol index.
549
- if (Rel.Symbol && SymN2I.lookup (*Rel.Symbol , SymIdx) &&
550
- !to_integer (*Rel.Symbol , SymIdx)) {
551
- WithColor::error () << " Unknown symbol referenced: '" << *Rel.Symbol
552
- << " ' at YAML section '" << Section.Name << " '.\n " ;
547
+ unsigned SymIdx = 0 ;
548
+ // If a relocation references a symbol, try to look one up in the symbol
549
+ // table. If it is not there, treat the value as a symbol index.
550
+ if (Rel.Symbol && ! SymN2I.lookup (*Rel.Symbol , SymIdx) &&
551
+ !to_integer (*Rel.Symbol , SymIdx)) {
552
+ WithColor::error () << " Unknown symbol referenced: '" << *Rel.Symbol
553
+ << " ' at YAML section '" << Section.Name << " '.\n " ;
553
554
return false ;
554
555
}
555
556
@@ -579,13 +580,13 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
579
580
" Section type is not SHT_GROUP" );
580
581
581
582
SHeader.sh_entsize = 4 ;
582
- SHeader.sh_size = SHeader.sh_entsize * Section.Members .size ();
583
-
584
- unsigned SymIdx;
585
- if (SymN2I.lookup (Section.Signature , SymIdx) &&
586
- !to_integer (Section.Signature , SymIdx)) {
587
- WithColor::error () << " Unknown symbol referenced: '" << Section.Signature
588
- << " ' at YAML section '" << Section.Name << " '.\n " ;
583
+ SHeader.sh_size = SHeader.sh_entsize * Section.Members .size ();
584
+
585
+ unsigned SymIdx;
586
+ if (! SymN2I.lookup (Section.Signature , SymIdx) &&
587
+ !to_integer (Section.Signature , SymIdx)) {
588
+ WithColor::error () << " Unknown symbol referenced: '" << Section.Signature
589
+ << " ' at YAML section '" << Section.Name << " '.\n " ;
589
590
return false ;
590
591
}
591
592
SHeader.sh_info = SymIdx;
@@ -780,20 +781,20 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
780
781
781
782
template <class ELFT > bool ELFState<ELFT>::buildSectionIndex() {
782
783
for (unsigned i = 0 , e = Doc.Sections .size (); i != e; ++i) {
783
- StringRef Name = Doc.Sections [i]->Name ;
784
- DotShStrtab.add (Name);
785
- // "+ 1" to take into account the SHT_NULL entry.
786
- if (SN2I.addName (Name, i + 1 )) {
787
- WithColor::error () << " Repeated section name: '" << Name
788
- << " ' at YAML section number " << i << " .\n " ;
789
- return false ;
784
+ StringRef Name = Doc.Sections [i]->Name ;
785
+ DotShStrtab.add (Name);
786
+ // "+ 1" to take into account the SHT_NULL entry.
787
+ if (! SN2I.addName (Name, i + 1 )) {
788
+ WithColor::error () << " Repeated section name: '" << Name
789
+ << " ' at YAML section number " << i << " .\n " ;
790
+ return false ;
790
791
}
791
792
}
792
793
793
794
auto SecNo = 1 + Doc.Sections .size ();
794
795
// Add special sections after input sections, if necessary.
795
796
for (StringRef Name : implicitSectionNames ())
796
- if (! SN2I.addName (Name, SecNo)) {
797
+ if (SN2I.addName (Name, SecNo)) {
797
798
// Account for this section, since it wasn't in the Doc
798
799
++SecNo;
799
800
DotShStrtab.add (Name);
@@ -816,13 +817,13 @@ bool ELFState<ELFT>::buildSymbolIndex(ArrayRef<ELFYAML::Symbol> Symbols) {
816
817
" ' after global in Symbols list.\n " ;
817
818
return false ;
818
819
}
819
- if (Sym.Binding .value != ELF::STB_LOCAL)
820
- GlobalSymbolSeen = true ;
821
-
822
- if (!Name.empty () && SymN2I.addName (Name, I)) {
823
- WithColor::error () << " Repeated symbol name: '" << Name << " '.\n " ;
824
- return false ;
825
- }
820
+ if (Sym.Binding .value != ELF::STB_LOCAL)
821
+ GlobalSymbolSeen = true ;
822
+
823
+ if (!Name.empty () && ! SymN2I.addName (Name, I)) {
824
+ WithColor::error () << " Repeated symbol name: '" << Name << " '.\n " ;
825
+ return false ;
826
+ }
826
827
}
827
828
return true ;
828
829
}
0 commit comments