diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2014-10-07 19:37:57 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2014-10-07 19:37:57 +0000 |
commit | 64d491e488f1aabd862bc787b9cab6c64fc9d04b (patch) | |
tree | 98151293e678afb03de363a685a406bb18545077 /llvm/lib/MC/WinCOFFStreamer.cpp | |
parent | f95786324c233dcfa28da5fea929e62bc50b4083 (diff) | |
download | bcm5719-llvm-64d491e488f1aabd862bc787b9cab6c64fc9d04b.tar.gz bcm5719-llvm-64d491e488f1aabd862bc787b9cab6c64fc9d04b.zip |
MC: add support for -aligncomm GNU extension
The GNU linker supports an -aligncomm directive that allows for power-of-2
alignment of common data. Add support to emit this directive.
llvm-svn: 219229
Diffstat (limited to 'llvm/lib/MC/WinCOFFStreamer.cpp')
-rw-r--r-- | llvm/lib/MC/WinCOFFStreamer.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/llvm/lib/MC/WinCOFFStreamer.cpp b/llvm/lib/MC/WinCOFFStreamer.cpp index 2829a8ff0b5..9bae53706a0 100644 --- a/llvm/lib/MC/WinCOFFStreamer.cpp +++ b/llvm/lib/MC/WinCOFFStreamer.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/COFF.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" @@ -184,16 +185,10 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, "Got non-COFF section in the COFF backend!"); const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); - if (T.isKnownWindowsMSVCEnvironment()) { + if (T.isKnownWindowsMSVCEnvironment()) if (ByteAlignment > 32) report_fatal_error("alignment is limited to 32-bytes"); - } else { - // The bfd linker from binutils only supports alignments less than 4 bytes - // without inserting -aligncomm arguments into the .drectve section. - // TODO: Support inserting -aligncomm into the .drectve section. - if (ByteAlignment > 4) - report_fatal_error("alignment is limited to 4-bytes"); - } + // Round size up to alignment so that we will honor the alignment request. // TODO: We don't need to do this if we are targeting the bfd linker once we // add support for adding -aligncomm into the .drectve section. @@ -204,6 +199,21 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); SD.setExternal(true); SD.setCommon(Size, ByteAlignment); + + if (!T.isKnownWindowsMSVCEnvironment() && ByteAlignment > 1) { + SmallString<128> Directive; + raw_svector_ostream OS(Directive); + const MCObjectFileInfo *MFI = getContext().getObjectFileInfo(); + + OS << " -aligncomm:\"" << Symbol->getName() << "\"," + << Log2_32_Ceil(ByteAlignment); + OS.flush(); + + PushSection(); + SwitchSection(MFI->getDrectveSection()); + EmitBytes(Directive); + PopSection(); + } } void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, |