[llvm-commits] [llvm] r111213 - /llvm/trunk/lib/MC/ELFObjectWriter.cpp

Benjamin Kramer benny.kra at googlemail.com
Mon Aug 16 17:00:46 PDT 2010


Author: d0k
Date: Mon Aug 16 19:00:46 2010
New Revision: 111213

URL: http://llvm.org/viewvc/llvm-project?rev=111213&view=rev
Log:
A round of minor cleanups for ELFObjectWriter.

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=111213&r1=111212&r2=111213&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon Aug 16 19:00:46 2010
@@ -354,6 +354,7 @@
 
     String8(buf, info);
     F->getContents() += StringRef(buf, 1);  // st_info
+
     String8(buf, other);
     F->getContents() += StringRef(buf, 1); // st_other
 
@@ -416,9 +417,7 @@
         Value = Layout.getSymbolAddress(&Data);
       }
     } else if (ESize->getKind() == MCExpr::Constant) {
-      const MCConstantExpr *CE;
-      CE = static_cast<const MCConstantExpr *>(ESize);
-      Size = CE->getValue();
+      Size = static_cast<const MCConstantExpr *>(ESize)->getValue();
     } else {
       assert(0 && "Unsupported size expression");
     }
@@ -440,8 +439,7 @@
 
   // The first entry is the undefined symbol entry.
   unsigned EntrySize = Is64Bit ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
-  for (unsigned i = 0; i < EntrySize; ++i)
-    F->getContents() += '\x00';
+  F->getContents().append(EntrySize, '\x00');
 
   // Write the symbol table entries.
   LastLocalSymbolIndex = LocalSymbolData.size() + 1;
@@ -456,9 +454,8 @@
   unsigned Index = 1;
   for (MCAssembler::const_iterator it = Asm.begin(),
        ie = Asm.end(); it != ie; ++it, ++Index) {
-    const MCSectionData &SD = *it;
     const MCSectionELF &Section =
-      static_cast<const MCSectionELF&>(SD.getSection());
+      static_cast<const MCSectionELF&>(it->getSection());
     // Leave out relocations so we don't have indexes within
     // the relocations messed up
     if (Section.getType() == ELF::SHT_RELA)
@@ -613,15 +610,10 @@
     ELFSymbolData MSD;
     MSD.SymbolData = it;
 
-    if (Symbol.isUndefined()) {
+    if (Symbol.isUndefined())
       Undefined.push_back(MSD);
-    } else if (Symbol.isAbsolute()) {
-      External.push_back(MSD);
-    } else if (it->isCommon()) {
+    else
       External.push_back(MSD);
-    } else {
-      External.push_back(MSD);
-    }
   }
 
   array_pod_sort(Local.begin(), Local.end());
@@ -800,19 +792,12 @@
   for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
     ELFRelocationEntry entry = Relocs[e - i - 1];
 
-    if (Is64Bit) {
-      F->getContents() +=  StringRef((const char *)&entry.r_offset, 8);
-      F->getContents() +=  StringRef((const char *)&entry.r_info, 8);
-
-      if (HasRelocationAddend)
-        F->getContents() +=  StringRef((const char *)&entry.r_addend, 8);
-    } else {
-      F->getContents() +=  StringRef((const char *)&entry.r_offset, 4);
-      F->getContents() +=  StringRef((const char *)&entry.r_info, 4);
+    unsigned WordSize = Is64Bit ? 8 : 4;
+    F->getContents() += StringRef((const char *)&entry.r_offset, WordSize);
+    F->getContents() += StringRef((const char *)&entry.r_info, WordSize);
 
-      if (HasRelocationAddend)
-        F->getContents() +=  StringRef((const char *)&entry.r_addend, 4);
-    }
+    if (HasRelocationAddend)
+      F->getContents() += StringRef((const char *)&entry.r_addend, WordSize);
   }
 }
 
@@ -877,10 +862,8 @@
 
   for (MCAssembler::const_iterator it = Asm.begin(),
          ie = Asm.end(); it != ie; ++it) {
-    const MCSectionData &SD = *it;
     const MCSectionELF &Section =
-      static_cast<const MCSectionELF&>(SD.getSection());
-
+      static_cast<const MCSectionELF&>(it->getSection());
 
     // Remember the index into the string table so we can write it
     // into the sh_name field of the section header table.





More information about the llvm-commits mailing list