[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Jul 16 10:41:17 PDT 2005



Changes in directory llvm/lib/CodeGen:

ELFWriter.cpp updated: 1.11 -> 1.12
---
Log message:

Only get the .bss and .data sections when needed instead of unconditionally.
This allows is to not emit empty sections when .data or .bss is not used.


---
Diffs of the changes:  (+3 -11)

 ELFWriter.cpp |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)


Index: llvm/lib/CodeGen/ELFWriter.cpp
diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.11 llvm/lib/CodeGen/ELFWriter.cpp:1.12
--- llvm/lib/CodeGen/ELFWriter.cpp:1.11	Sat Jul 16 12:36:04 2005
+++ llvm/lib/CodeGen/ELFWriter.cpp	Sat Jul 16 12:41:06 2005
@@ -223,8 +223,7 @@
   return false;
 }
 
-void ELFWriter::EmitGlobal(GlobalVariable *GV, ELFSection &DataSection,
-                           ELFSection &BSSSection) {
+void ELFWriter::EmitGlobal(GlobalVariable *GV) {
   // If this is an external global, emit it now.  TODO: Note that it would be
   // better to ignore the symbol here and only add it to the symbol table if
   // referenced.
@@ -264,6 +263,7 @@
 
     // Handle alignment.  Ensure section is aligned at least as much as required
     // by this symbol.
+    ELFSection &BSSSection = getBSSSection();
     BSSSection.Align = std::max(BSSSection.Align, Align);
 
     // Within the section, emit enough virtual padding to get us to an alignment
@@ -315,17 +315,9 @@
 bool ELFWriter::doFinalization(Module &M) {
   // Okay, the ELF header and .text sections have been completed, build the
   // .data, .bss, and "common" sections next.
-  ELFSection &DataSection =
-    getSection(".data", ELFSection::SHT_PROGBITS,
-               ELFSection::SHF_WRITE | ELFSection::SHF_ALLOC);
-
-  ELFSection &BSSSection =
-    getSection(".bss", ELFSection::SHT_NOBITS,
-               ELFSection::SHF_WRITE | ELFSection::SHF_ALLOC);
-
   for (Module::global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I)
-    EmitGlobal(I, DataSection, BSSSection);
+    EmitGlobal(I);
 
   // Emit the symbol table now, if non-empty.
   EmitSymbolTable();






More information about the llvm-commits mailing list