unsigned RelaxAll : 1;
unsigned SubsectionsViaSymbols : 1;
+ unsigned PadSectionToAlignment : 1;
private:
/// Evaluate a fixup to a relocatable expression and the value which should be
// option is to make this abstract, and have targets provide concrete
// implementations as we do with AsmParser.
MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
- MCCodeEmitter &_Emitter, raw_ostream &OS);
+ MCCodeEmitter &_Emitter, bool _PadSectionToAlignment,
+ raw_ostream &OS);
~MCAssembler();
MCContext &getContext() const { return Context; }
protected:
MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
- raw_ostream &_OS, MCCodeEmitter *_Emitter);
+ raw_ostream &_OS, MCCodeEmitter *_Emitter,
+ bool _PadSectionToAlignment);
~MCObjectStreamer();
MCSectionData *getCurrentSectionData() const {
/* *** */
MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
- MCCodeEmitter &_Emitter, raw_ostream &_OS)
+ MCCodeEmitter &_Emitter, bool _PadSectionToAlignment,
+ raw_ostream &_OS)
: Context(_Context), Backend(_Backend), Emitter(_Emitter),
- OS(_OS), RelaxAll(false), SubsectionsViaSymbols(false)
+ OS(_OS), RelaxAll(false), SubsectionsViaSymbols(false),
+ PadSectionToAlignment(_PadSectionToAlignment)
{
}
// Insert additional align fragments for concrete sections to explicitly pad
// the previous section to match their alignment requirements. This is for
// 'gas' compatibility, it shouldn't strictly be necessary.
- //
- // FIXME: This may be Mach-O specific.
- for (unsigned i = 1, e = Layout.getSectionOrder().size(); i < e; ++i) {
- MCSectionData *SD = Layout.getSectionOrder()[i];
+ if (PadSectionToAlignment) {
+ for (unsigned i = 1, e = Layout.getSectionOrder().size(); i < e; ++i) {
+ MCSectionData *SD = Layout.getSectionOrder()[i];
- // Ignore sections without alignment requirements.
- unsigned Align = SD->getAlignment();
- if (Align <= 1)
- continue;
+ // Ignore sections without alignment requirements.
+ unsigned Align = SD->getAlignment();
+ if (Align <= 1)
+ continue;
- // Ignore virtual sections, they don't cause file size modifications.
- if (getBackend().isVirtualSection(SD->getSection()))
- continue;
+ // Ignore virtual sections, they don't cause file size modifications.
+ if (getBackend().isVirtualSection(SD->getSection()))
+ continue;
- // Otherwise, create a new align fragment at the end of the previous
- // section.
- MCAlignFragment *AF = new MCAlignFragment(Align, 0, 1, Align,
- Layout.getSectionOrder()[i - 1]);
- AF->setOnlyAlignAddress(true);
+ // Otherwise, create a new align fragment at the end of the previous
+ // section.
+ MCAlignFragment *AF = new MCAlignFragment(Align, 0, 1, Align,
+ Layout.getSectionOrder()[i - 1]);
+ AF->setOnlyAlignAddress(true);
+ }
}
// Create dummy fragments and assign section ordinals.
public:
MCELFStreamer(MCContext &Context, TargetAsmBackend &TAB,
raw_ostream &OS, MCCodeEmitter *Emitter)
- : MCObjectStreamer(Context, TAB, OS, Emitter) {}
+ : MCObjectStreamer(Context, TAB, OS, Emitter, false) {}
~MCELFStreamer() {}
public:
MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
raw_ostream &OS, MCCodeEmitter *Emitter)
- : MCObjectStreamer(Context, TAB, OS, Emitter) {}
+ : MCObjectStreamer(Context, TAB, OS, Emitter, true) {}
/// @name MCStreamer Interface
/// @{
using namespace llvm;
MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
- raw_ostream &_OS, MCCodeEmitter *_Emitter)
+ raw_ostream &_OS, MCCodeEmitter *_Emitter,
+ bool _PadSectionToAlignment)
: MCStreamer(Context), Assembler(new MCAssembler(Context, TAB,
- *_Emitter, _OS)),
+ *_Emitter,
+ _PadSectionToAlignment,
+ _OS)),
CurSectionData(0)
{
}
TargetAsmBackend &TAB,
MCCodeEmitter &CE,
raw_ostream &OS)
- : MCObjectStreamer(Context, TAB, OS, &CE)
+ : MCObjectStreamer(Context, TAB, OS, &CE, true)
, CurSymbol(NULL) {
}
--- /dev/null
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
+
+// Test that the alignment of rodata doesn't force a alignment of the
+// previous section (.bss)
+
+ nop
+ .section .rodata,"a",@progbits
+ .align 8
+
+// CHECK: # Section 3
+// CHECK-NEXT: (('sh_name', 13) # '.bss'
+// CHECK-NEXT: ('sh_type', 8)
+// CHECK-NEXT: ('sh_flags', 3)
+// CHECK-NEXT: ('sh_addr', 0)
+// CHECK-NEXT: ('sh_offset', 68)
+// CHECK-NEXT: ('sh_size', 0)
+// CHECK-NEXT: ('sh_link', 0)
+// CHECK-NEXT: ('sh_info', 0)
+// CHECK-NEXT: ('sh_addralign', 4)
+// CHECK-NEXT: ('sh_entsize', 0)
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Section 4
+// CHECK-NEXT: (('sh_name', 18) # '.rodata'
+// CHECK-NEXT: ('sh_type', 1)
+// CHECK-NEXT: ('sh_flags', 2)
+// CHECK-NEXT: ('sh_addr', 0)
+// CHECK-NEXT: ('sh_offset', 72)
+// CHECK-NEXT: ('sh_size', 0)
+// CHECK-NEXT: ('sh_link', 0)
+// CHECK-NEXT: ('sh_info', 0)
+// CHECK-NEXT: ('sh_addralign', 8)
+// CHECK-NEXT: ('sh_entsize', 0)