[llvm-commits] [llvm] r115037 - in /llvm/trunk: lib/MC/MCELFStreamer.cpp test/MC/ELF/common2.s
Rafael Espindola
rafael.espindola at gmail.com
Wed Sep 29 07:52:01 PDT 2010
Author: rafael
Date: Wed Sep 29 09:52:01 2010
New Revision: 115037
URL: http://llvm.org/viewvc/llvm-project?rev=115037&view=rev
Log:
Move "local commons" to the end of .bss to match the gnu as behavior.
Added:
llvm/trunk/test/MC/ELF/common2.s
Modified:
llvm/trunk/lib/MC/MCELFStreamer.cpp
Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=115037&r1=115036&r2=115037&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCELFStreamer.cpp Wed Sep 29 09:52:01 2010
@@ -111,6 +111,13 @@
virtual void Finish();
private:
+ struct LocalCommon {
+ MCSymbolData *SD;
+ uint64_t Size;
+ unsigned ByteAlignment;
+ };
+ std::vector<LocalCommon> LocalCommons;
+
SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet;
/// @}
void SetSection(StringRef Section, unsigned Type, unsigned Flags,
@@ -343,17 +350,10 @@
MCSectionELF::SHF_WRITE |
MCSectionELF::SHF_ALLOC,
SectionKind::getBSS());
-
- MCSectionData &SectData = getAssembler().getOrCreateSectionData(*Section);
- new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
-
- MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
- SD.setFragment(F);
Symbol->setSection(*Section);
- // Update the maximum alignment of the section if necessary.
- if (ByteAlignment > SectData.getAlignment())
- SectData.setAlignment(ByteAlignment);
+ struct LocalCommon L = {&SD, Size, ByteAlignment};
+ LocalCommons.push_back(L);
} else {
SD.setCommon(Size, ByteAlignment);
}
@@ -499,6 +499,26 @@
}
void MCELFStreamer::Finish() {
+ for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
+ e = LocalCommons.end();
+ i != e; ++i) {
+ MCSymbolData *SD = i->SD;
+ uint64_t Size = i->Size;
+ unsigned ByteAlignment = i->ByteAlignment;
+ const MCSymbol &Symbol = SD->getSymbol();
+ const MCSection &Section = Symbol.getSection();
+
+ MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
+ new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
+
+ MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
+ SD->setFragment(F);
+
+ // Update the maximum alignment of the section if necessary.
+ if (ByteAlignment > SectData.getAlignment())
+ SectData.setAlignment(ByteAlignment);
+ }
+
// FIXME: We create more atoms than it is necessary. Some relocations to
// merge sections can be implemented with section address + offset,
// figure out which ones and why.
Added: llvm/trunk/test/MC/ELF/common2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/common2.s?rev=115037&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/common2.s (added)
+++ llvm/trunk/test/MC/ELF/common2.s Wed Sep 29 09:52:01 2010
@@ -0,0 +1,21 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | 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.
+
+ .local vimvardict
+ .comm vimvardict,1,8
+ .bss
+ .zero 1
+ .align 8
+
+// CHECK: (('sh_name', 13) # '.bss'
+// CHECK-NEXT: ('sh_type',
+// CHECK-NEXT: ('sh_flags'
+// CHECK-NEXT: ('sh_addr',
+// CHECK-NEXT: ('sh_offset',
+// CHECK-NEXT: ('sh_size', 9)
+// CHECK-NEXT: ('sh_link',
+// CHECK-NEXT: ('sh_info',
+// CHECK-NEXT: ('sh_addralign',
+// CHECK-NEXT: ('sh_entsize',
More information about the llvm-commits
mailing list