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() +
}
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() {
// 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
// CHECK: ]
// CHECK-NEXT: Address:
// CHECK-NEXT: Offset:
-// CHECK-NEXT: Size: 9
+// CHECK-NEXT: Size: 8
// CHECK-NEXT: Link:
// CHECK-NEXT: Info:
// CHECK-NEXT: AddressAlignment: