From: Rafael Espindola Date: Tue, 3 Nov 2015 18:50:51 +0000 (+0000) Subject: Simplify local common output. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ca792d80c4a833a100879aa9fb4036f43173f13c;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251958 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/MCELFStreamer.h b/include/llvm/MC/MCELFStreamer.h index 2f3d49e3aca..b71372ad186 100644 --- a/include/llvm/MC/MCELFStreamer.h +++ b/include/llvm/MC/MCELFStreamer.h @@ -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 LocalCommons; - /// BundleGroups - The stack of fragments holding the bundle-locked /// instructions. llvm::SmallVector BundleGroups; diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index 12cf06cbe5c..b20b99340bb 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -311,8 +311,20 @@ void MCELFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, 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() { diff --git a/test/MC/ELF/common2.s b/test/MC/ELF/common2.s index 26c32a7c840..bf9f22f90e9 100644 --- a/test/MC/ELF/common2.s +++ b/test/MC/ELF/common2.s @@ -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: