Use different functions to emit the string and symbol tables.
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Mon, 22 Jun 2009 19:29:56 +0000 (19:29 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Mon, 22 Jun 2009 19:29:56 +0000 (19:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73895 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/ELFWriter.cpp
lib/CodeGen/ELFWriter.h

index 281cf2fa11e7f74bdc88ab8910e778345d8efaa0..acdf3d5d56a0dcfc44346a9a3c09cf065660563a 100644 (file)
@@ -386,6 +386,9 @@ bool ELFWriter::doFinalization(Module &M) {
   if (TAI->getNonexecutableStackDirective())
     getNonExecStackSection();
 
+  // Emit string table
+  EmitStringTable();
+
   // Emit the symbol table now, if non-empty.
   EmitSymbolTable();
 
@@ -518,12 +521,10 @@ void ELFWriter::EmitSectionHeader(BinaryObject &SHdrTab,
   }
 }
 
-/// EmitSymbolTable - If the current symbol table is non-empty, emit the string
-/// table for it and then the symbol table itself.
-void ELFWriter::EmitSymbolTable() {
+/// EmitStringTable - If the current symbol table is non-empty, emit the string
+/// table for it
+void ELFWriter::EmitStringTable() {
   if (!SymbolList.size()) return;  // Empty symbol table.
-
-  unsigned FirstNonLocalSymbol = 1;
   ELFSection &StrTab = getStringTableSection();
 
   // Set the zero'th symbol to a null byte, as required.
@@ -550,12 +551,20 @@ void ELFWriter::EmitSymbolTable() {
   }
   assert(Index == StrTab.size());
   StrTab.Size = Index;
+}
 
+/// EmitSymbolTable - Emit the symbol table itself.
+void ELFWriter::EmitSymbolTable() {
+  if (!SymbolList.size()) return;  // Empty symbol table.
+
+  unsigned FirstNonLocalSymbol = 1;
   // Now that we have emitted the string table and know the offset into the
   // string table of each symbol, emit the symbol table itself.
   ELFSection &SymTab = getSymbolTableSection();
   SymTab.Align = TEW->getPrefELFAlignment();
-  SymTab.Link  = StrTab.SectionIdx;      // Section Index of .strtab.
+
+  // Section Index of .strtab.
+  SymTab.Link = getStringTableSection().SectionIdx;
 
   // Size of each symtab entry.
   SymTab.EntSize = TEW->getSymTabEntrySize();
@@ -566,7 +575,7 @@ void ELFWriter::EmitSymbolTable() {
 
   // Emit all the symbols to the symbol table. Skip the null
   // symbol, cause it's emitted already
-  Index = 1;
+  unsigned Index = 1;
   for (std::list<ELFSym>::iterator I = SymbolList.begin(),
        E = SymbolList.end(); I != E; ++I, ++Index) {
     // Keep track of the first non-local symbol
index c713e33118a1cd2bcfeab91a7d701b78d4fd41b0..ae3939f20409dcda6010f9e4459da84d32a988d2 100644 (file)
@@ -207,6 +207,7 @@ namespace llvm {
     void EmitSectionTableStringTable();
     void EmitSymbol(BinaryObject &SymbolTable, ELFSym &Sym);
     void EmitSymbolTable();
+    void EmitStringTable();
     void OutputSectionsAndSectionTable();
   };
 }