summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-11-03 18:50:51 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-11-03 18:50:51 +0000
commite7fe1a46e4213842fc2f2c0b0dcd4232923bac20 (patch)
tree553f9fe233e9abef47a885dfd8e972480cd84e13
parentf637b4a52e02cab4b95472898e29318604be8889 (diff)
downloadbcm5719-llvm-e7fe1a46e4213842fc2f2c0b0dcd4232923bac20.tar.gz
bcm5719-llvm-e7fe1a46e4213842fc2f2c0b0dcd4232923bac20.zip
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. llvm-svn: 251958
-rw-r--r--llvm/include/llvm/MC/MCELFStreamer.h9
-rw-r--r--llvm/lib/MC/MCELFStreamer.cpp34
-rw-r--r--llvm/test/MC/ELF/common2.s7
3 files changed, 18 insertions, 32 deletions
diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h
index 2f3d49e3aca..b71372ad186 100644
--- a/llvm/include/llvm/MC/MCELFStreamer.h
+++ b/llvm/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<LocalCommon> LocalCommons;
-
/// BundleGroups - The stack of fragments holding the bundle-locked
/// instructions.
llvm::SmallVector<MCDataFragment *, 4> BundleGroups;
diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 12cf06cbe5c..b20b99340bb 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/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/llvm/test/MC/ELF/common2.s b/llvm/test/MC/ELF/common2.s
index 26c32a7c840..bf9f22f90e9 100644
--- a/llvm/test/MC/ELF/common2.s
+++ b/llvm/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:
OpenPOWER on IntegriCloud