Avoid some Mach-O specific alignment being done on ELF.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114594 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-09-22 22:27:05 +00:00
parent e07b75e069
commit 59ff3c9134
8 changed files with 65 additions and 25 deletions

View File

@ -605,6 +605,7 @@ private:
unsigned RelaxAll : 1;
unsigned SubsectionsViaSymbols : 1;
unsigned PadSectionToAlignment : 1;
private:
/// Evaluate a fixup to a relocatable expression and the value which should be
@ -676,7 +677,8 @@ public:
// 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; }

View File

@ -35,7 +35,8 @@ class MCObjectStreamer : public MCStreamer {
protected:
MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
raw_ostream &_OS, MCCodeEmitter *_Emitter);
raw_ostream &_OS, MCCodeEmitter *_Emitter,
bool _PadSectionToAlignment);
~MCObjectStreamer();
MCSectionData *getCurrentSectionData() const {

View File

@ -221,9 +221,11 @@ MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
/* *** */
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)
{
}
@ -712,25 +714,25 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
// 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.

View File

@ -40,7 +40,7 @@ class MCELFStreamer : public MCObjectStreamer {
public:
MCELFStreamer(MCContext &Context, TargetAsmBackend &TAB,
raw_ostream &OS, MCCodeEmitter *Emitter)
: MCObjectStreamer(Context, TAB, OS, Emitter) {}
: MCObjectStreamer(Context, TAB, OS, Emitter, false) {}
~MCELFStreamer() {}

View File

@ -41,7 +41,7 @@ private:
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
/// @{

View File

@ -17,9 +17,12 @@
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)
{
}

View File

@ -86,7 +86,7 @@ WinCOFFStreamer::WinCOFFStreamer(MCContext &Context,
TargetAsmBackend &TAB,
MCCodeEmitter &CE,
raw_ostream &OS)
: MCObjectStreamer(Context, TAB, OS, &CE)
: MCObjectStreamer(Context, TAB, OS, &CE, true)
, CurSymbol(NULL) {
}

32
test/MC/ELF/align.s Normal file
View File

@ -0,0 +1,32 @@
// 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)