[llvm] r184467 - [yaml2obj][ELF] Add the section name -> section index map to State.

Sean Silva silvas at purdue.edu
Thu Jun 20 13:59:34 PDT 2013


Author: silvas
Date: Thu Jun 20 15:59:34 2013
New Revision: 184467

URL: http://llvm.org/viewvc/llvm-project?rev=184467&view=rev
Log:
[yaml2obj][ELF] Add the section name -> section index map to State.

One of the key things that the YAML format abstracts over is the use of
section numbers for referencing sections. Instead, textual section names
are used, which yaml2obj then translates into appropriate section
numbers. (Technically ELF doesn't care about section names (only section
numbers), but since this is a testing tool, readability counts).

This simplifies using section names as symbolic references in various
parts of the code. An upcoming commit will use this to allow symbols to
reference sections.

Modified:
    llvm/trunk/tools/yaml2obj/yaml2elf.cpp

Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=184467&r1=184466&r2=184467&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Thu Jun 20 15:59:34 2013
@@ -150,18 +150,21 @@ class ELFState {
   /// \brief The ELF file header.
   Elf_Ehdr &Header;
 
+  SectionNameToIdxMap &SN2I;
+
 public:
 
   ELFState(Elf_Ehdr &Header_, ContiguousBlobAccumulator &Accum,
-           unsigned DotStrtabSecNo_)
+           unsigned DotStrtabSecNo_, SectionNameToIdxMap &SN2I_)
       : DotStrtab(), DotStrtabSecNo(DotStrtabSecNo_),
-        SectionContentAccum(Accum), Header(Header_) {}
+        SectionContentAccum(Accum), Header(Header_), SN2I(SN2I_) {}
 
   unsigned getDotStrTabSecNo() const { return DotStrtabSecNo; }
   StringTableBuilder &getStringTable() { return DotStrtab; }
   ContiguousBlobAccumulator &getSectionContentAccum() {
     return SectionContentAccum;
   }
+  SectionNameToIdxMap &getSN2I() { return SN2I; }
 };
 } // end anonymous namespace
 
@@ -252,8 +255,6 @@ static int writeELF(raw_ostream &OS, con
   const size_t SectionContentBeginOffset =
       Header.e_ehsize + Header.e_shentsize * Header.e_shnum;
   ContiguousBlobAccumulator CBA(SectionContentBeginOffset);
-  ELFState<ELFT> State(Header, CBA, DotStrtabSecNo);
-
   SectionNameToIdxMap SN2I;
   for (unsigned i = 0, e = Sections.size(); i != e; ++i) {
     StringRef Name = Sections[i].Name;
@@ -267,6 +268,8 @@ static int writeELF(raw_ostream &OS, con
     }
   }
 
+  ELFState<ELFT> State(Header, CBA, DotStrtabSecNo, SN2I);
+
   StringTableBuilder SHStrTab;
   std::vector<Elf_Shdr> SHeaders;
   {





More information about the llvm-commits mailing list