[llvm] r251958 - Simplify local common output.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 3 10:50:51 PST 2015


Author: rafael
Date: Tue Nov  3 12:50:51 2015
New Revision: 251958

URL: http://llvm.org/viewvc/llvm-project?rev=251958&view=rev
Log:
Simplify local common output.

We now create them as they are found and use higher level APIs.

This is a step in avoiding creating unnecessary sections.

Modified:
    llvm/trunk/include/llvm/MC/MCELFStreamer.h
    llvm/trunk/lib/MC/MCELFStreamer.cpp
    llvm/trunk/test/MC/ELF/common2.s

Modified: llvm/trunk/include/llvm/MC/MCELFStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCELFStreamer.h?rev=251958&r1=251957&r2=251958&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCELFStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCELFStreamer.h Tue Nov  3 12:50:51 2015
@@ -36,7 +36,6 @@ public:
   /// state management
   void reset() override {
     SeenIdent = false;
-    LocalCommons.clear();
     BundleGroups.clear();
     MCObjectStreamer::reset();
   }
@@ -97,14 +96,6 @@ private:
 
   bool SeenIdent;
 
-  struct LocalCommon {
-    const MCSymbol *Symbol;
-    uint64_t Size;
-    unsigned ByteAlignment;
-  };
-
-  std::vector<LocalCommon> LocalCommons;
-
   /// BundleGroups - The stack of fragments holding the bundle-locked
   /// instructions.
   llvm::SmallVector<MCDataFragment *, 4> BundleGroups;

Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=251958&r1=251957&r2=251958&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCELFStreamer.cpp Tue Nov  3 12:50:51 2015
@@ -311,8 +311,20 @@ void MCELFStreamer::EmitCommonSymbol(MCS
   Symbol->setType(ELF::STT_OBJECT);
 
   if (Symbol->getBinding() == ELF::STB_LOCAL) {
-    struct LocalCommon L = {Symbol, Size, ByteAlignment};
-    LocalCommons.push_back(L);
+    MCSection &Section = *getAssembler().getContext().getELFSection(
+        ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
+    MCSectionSubPair P = getCurrentSection();
+    SwitchSection(&Section);
+
+    EmitValueToAlignment(ByteAlignment, 0, 1, 0);
+    EmitLabel(Symbol);
+    EmitZeros(Size);
+
+    // Update the maximum alignment of the section if necessary.
+    if (ByteAlignment > Section.getAlignment())
+      Section.setAlignment(ByteAlignment);
+
+    SwitchSection(P.first, P.second);
   } else {
     if(Symbol->declareCommon(Size, ByteAlignment))
       report_fatal_error("Symbol: " + Symbol->getName() +
@@ -619,25 +631,7 @@ void MCELFStreamer::EmitBundleUnlock() {
 }
 
 void MCELFStreamer::Flush() {
-  MCSection &Section = *getAssembler().getContext().getELFSection(
-      ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
-  getAssembler().registerSection(Section);
-
-  for (const LocalCommon &L : LocalCommons) {
-    const MCSymbol &Symbol = *L.Symbol;
-    uint64_t Size = L.Size;
-    unsigned ByteAlignment = L.ByteAlignment;
-    new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &Section);
-
-    MCFragment *F = new MCFillFragment(0, 0, Size, &Section);
-    Symbol.setFragment(F);
-
-    // Update the maximum alignment of the section if necessary.
-    if (ByteAlignment > Section.getAlignment())
-      Section.setAlignment(ByteAlignment);
-  }
 
-  LocalCommons.clear();
 }
 
 void MCELFStreamer::FinishImpl() {

Modified: llvm/trunk/test/MC/ELF/common2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/common2.s?rev=251958&r1=251957&r2=251958&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/common2.s (original)
+++ llvm/trunk/test/MC/ELF/common2.s Tue Nov  3 12:50:51 2015
@@ -1,7 +1,8 @@
 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -s | FileCheck %s
 
-// Test that the common symbols are placed at the end of .bss. In this example
-// it causes .bss to have size 9 instead of 8.
+// Test local common construction.
+// Unlike gas, common symbols are created when found, not at the end of .bss.
+// In this example it causes .bss to have size 8 instead of 9.
 
 	.local	vimvardict
 	.comm	vimvardict,1,8
@@ -16,7 +17,7 @@
 // CHECK:          ]
 // CHECK-NEXT:     Address:
 // CHECK-NEXT:     Offset:
-// CHECK-NEXT:     Size: 9
+// CHECK-NEXT:     Size: 8
 // CHECK-NEXT:     Link:
 // CHECK-NEXT:     Info:
 // CHECK-NEXT:     AddressAlignment:




More information about the llvm-commits mailing list