} // end anonymous namespace
// Used to keep track of section and symbol names, so that in the YAML file
-// sections and symbols can be referenced by name instead of by index.
-namespace {
-class NameToIdxMap {
- StringMap<int> Map;
-public:
- /// \returns true if name is already present in the map.
- bool addName(StringRef Name, unsigned i) {
- return !Map.insert(std::make_pair(Name, (int)i)).second;
- }
- /// \returns true if name is not present in the map
- bool lookup(StringRef Name, unsigned &Idx) const {
- StringMap<int>::const_iterator I = Map.find(Name);
- if (I == Map.end())
- return true;
- Idx = I->getValue();
- return false;
- }
- /// asserts if name is not present in the map
- unsigned get(StringRef Name) const {
- unsigned Idx = 0;
- auto missing = lookup(Name, Idx);
- (void)missing;
- assert(!missing && "Expected section not found in index");
- return Idx;
- }
- unsigned size() const { return Map.size(); }
-};
+// sections and symbols can be referenced by name instead of by index.\r
+namespace {\r
+class NameToIdxMap {\r
+ StringMap<unsigned> Map;\r
+\r
+public:\r
+ /// \Returns false if name is already present in the map.\r
+ bool addName(StringRef Name, unsigned Ndx) {\r
+ return Map.insert({Name, Ndx}).second;\r
+ }\r
+ /// \Returns false if name is not present in the map.\r
+ bool lookup(StringRef Name, unsigned &Idx) const {\r
+ auto I = Map.find(Name);\r
+ if (I == Map.end())\r
+ return false;\r
+ Idx = I->getValue();\r
+ return true;\r
+ }\r
+ /// Asserts if name is not present in the map.\r
+ unsigned get(StringRef Name) const {\r
+ unsigned Idx;\r
+ if (lookup(Name, Idx))\r
+ return Idx;\r
+ assert(false && "Expected section not found in index");\r
+ return 0;\r
+ }\r
+ unsigned size() const { return Map.size(); }\r
+};\r
} // end anonymous namespace
template <class T>
PHeaders.push_back(Phdr);
}
}
-
-static bool convertSectionIndex(NameToIdxMap &SN2I, StringRef SecName,
- StringRef IndexSrc, unsigned &IndexDest) {
- if (SN2I.lookup(IndexSrc, IndexDest) && !to_integer(IndexSrc, IndexDest)) {
- WithColor::error() << "Unknown section referenced: '" << IndexSrc
- << "' at YAML section '" << SecName << "'.\n";
- return false;
+\r
+static bool convertSectionIndex(NameToIdxMap &SN2I, StringRef SecName,\r
+ StringRef IndexSrc, unsigned &IndexDest) {\r
+ if (!SN2I.lookup(IndexSrc, IndexDest) && !to_integer(IndexSrc, IndexDest)) {\r
+ WithColor::error() << "Unknown section referenced: '" << IndexSrc\r
+ << "' at YAML section '" << SecName << "'.\n";\r
+ return false;\r
}
return true;
}
for (auto &YamlPhdr : Doc.ProgramHeaders) {
Elf_Phdr &PHeader = PHeaders[PhdrIdx++];
- std::vector<Elf_Shdr *> Sections;
- for (const ELFYAML::SectionName &SecName : YamlPhdr.Sections) {
- unsigned Index;
- if (SN2I.lookup(SecName.Section, Index)) {
- WithColor::error() << "Unknown section referenced: '" << SecName.Section
- << "' by program header.\n";
- exit(1);
+ std::vector<Elf_Shdr *> Sections;\r
+ for (const ELFYAML::SectionName &SecName : YamlPhdr.Sections) {\r
+ unsigned Index;\r
+ if (!SN2I.lookup(SecName.Section, Index)) {\r
+ WithColor::error() << "Unknown section referenced: '" << SecName.Section\r
+ << "' by program header.\n";\r
+ exit(1);\r
}
Sections.push_back(&SHeaders[Index]);
}
zero(Symbol);
if (!Sym.Name.empty())
Symbol.st_name = Strtab.getOffset(Sym.Name);
- Symbol.setBindingAndType(Sym.Binding, Sym.Type);
- if (!Sym.Section.empty()) {
- unsigned Index;
- if (SN2I.lookup(Sym.Section, Index)) {
- WithColor::error() << "Unknown section referenced: '" << Sym.Section
- << "' by YAML symbol " << Sym.Name << ".\n";
- exit(1);
+ Symbol.setBindingAndType(Sym.Binding, Sym.Type);\r
+ if (!Sym.Section.empty()) {\r
+ unsigned Index;\r
+ if (!SN2I.lookup(Sym.Section, Index)) {\r
+ WithColor::error() << "Unknown section referenced: '" << Sym.Section\r
+ << "' by YAML symbol " << Sym.Name << ".\n";\r
+ exit(1);\r
}
Symbol.st_shndx = Index;
} else if (Sym.Index) {
auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
for (const auto &Rel : Section.Relocations) {
- unsigned SymIdx = 0;
- // If a relocation references a symbol, try to look one up in the symbol
- // table. If it is not there, treat the value as a symbol index.
- if (Rel.Symbol && SymN2I.lookup(*Rel.Symbol, SymIdx) &&
- !to_integer(*Rel.Symbol, SymIdx)) {
- WithColor::error() << "Unknown symbol referenced: '" << *Rel.Symbol
- << "' at YAML section '" << Section.Name << "'.\n";
+ unsigned SymIdx = 0;\r
+ // If a relocation references a symbol, try to look one up in the symbol\r
+ // table. If it is not there, treat the value as a symbol index.\r
+ if (Rel.Symbol && !SymN2I.lookup(*Rel.Symbol, SymIdx) &&\r
+ !to_integer(*Rel.Symbol, SymIdx)) {\r
+ WithColor::error() << "Unknown symbol referenced: '" << *Rel.Symbol\r
+ << "' at YAML section '" << Section.Name << "'.\n";\r
return false;
}
"Section type is not SHT_GROUP");
SHeader.sh_entsize = 4;
- SHeader.sh_size = SHeader.sh_entsize * Section.Members.size();
-
- unsigned SymIdx;
- if (SymN2I.lookup(Section.Signature, SymIdx) &&
- !to_integer(Section.Signature, SymIdx)) {
- WithColor::error() << "Unknown symbol referenced: '" << Section.Signature
- << "' at YAML section '" << Section.Name << "'.\n";
+ SHeader.sh_size = SHeader.sh_entsize * Section.Members.size();\r
+\r
+ unsigned SymIdx;\r
+ if (!SymN2I.lookup(Section.Signature, SymIdx) &&\r
+ !to_integer(Section.Signature, SymIdx)) {\r
+ WithColor::error() << "Unknown symbol referenced: '" << Section.Signature\r
+ << "' at YAML section '" << Section.Name << "'.\n";\r
return false;
}
SHeader.sh_info = SymIdx;
template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
for (unsigned i = 0, e = Doc.Sections.size(); i != e; ++i) {
- StringRef Name = Doc.Sections[i]->Name;
- DotShStrtab.add(Name);
- // "+ 1" to take into account the SHT_NULL entry.
- if (SN2I.addName(Name, i + 1)) {
- WithColor::error() << "Repeated section name: '" << Name
- << "' at YAML section number " << i << ".\n";
- return false;
+ StringRef Name = Doc.Sections[i]->Name;\r
+ DotShStrtab.add(Name);\r
+ // "+ 1" to take into account the SHT_NULL entry.\r
+ if (!SN2I.addName(Name, i + 1)) {\r
+ WithColor::error() << "Repeated section name: '" << Name\r
+ << "' at YAML section number " << i << ".\n";\r
+ return false;\r
}
}
auto SecNo = 1 + Doc.Sections.size();
// Add special sections after input sections, if necessary.
for (StringRef Name : implicitSectionNames())
- if (!SN2I.addName(Name, SecNo)) {
+ if (SN2I.addName(Name, SecNo)) {
// Account for this section, since it wasn't in the Doc
++SecNo;
DotShStrtab.add(Name);
"' after global in Symbols list.\n";
return false;
}
- if (Sym.Binding.value != ELF::STB_LOCAL)
- GlobalSymbolSeen = true;
-
- if (!Name.empty() && SymN2I.addName(Name, I)) {
- WithColor::error() << "Repeated symbol name: '" << Name << "'.\n";
- return false;
- }
+ if (Sym.Binding.value != ELF::STB_LOCAL)\r
+ GlobalSymbolSeen = true;\r
+\r
+ if (!Name.empty() && !SymN2I.addName(Name, I)) {\r
+ WithColor::error() << "Repeated symbol name: '" << Name << "'.\n";\r
+ return false;\r
+ }\r
}
return true;
}