Index: lib/MC/MCWinCOFFStreamer.cpp =================================================================== --- lib/MC/MCWinCOFFStreamer.cpp +++ lib/MC/MCWinCOFFStreamer.cpp @@ -222,31 +222,29 @@ auto *Symbol = cast(S); const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); - if (T.isKnownWindowsMSVCEnvironment()) { - if (ByteAlignment > 32) - report_fatal_error("alignment is limited to 32-bytes"); - // Round size up to alignment so that we will honor the alignment request. - Size = std::max(Size, static_cast(ByteAlignment)); + if (ByteAlignment > 32) { + if (T.isKnownWindowsMSVCEnvironment()) + report_fatal_error("alignment is limited to 32-bytes"); + else { + SmallString<128> Directive; + raw_svector_ostream OS(Directive); + const MCObjectFileInfo *MFI = getContext().getObjectFileInfo(); + + OS << " -aligncomm:\"" << Symbol->getName() << "\"," + << Log2_32_Ceil(ByteAlignment); + + PushSection(); + SwitchSection(MFI->getDrectveSection()); + EmitBytes(Directive); + PopSection(); + } } + Size = std::max(Size, static_cast(ByteAlignment)); getAssembler().registerSymbol(*Symbol); Symbol->setExternal(true); Symbol->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); - - PushSection(); - SwitchSection(MFI->getDrectveSection()); - EmitBytes(Directive); - PopSection(); - } } void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size, Index: test/MC/COFF/comm-align.s =================================================================== --- test/MC/COFF/comm-align.s +++ test/MC/COFF/comm-align.s @@ -2,8 +2,8 @@ # RUN: | llvm-readobj -coff-directives -symbols | FileCheck %s # NOTE: this test checks multiple things: -# - that -aligncomm is not emitted for 1-byte alignment -# - that -aligncomm is emitted for the various alignments (greater than 1) +# - that -aligncomm is not emitted for 32-byte alignment +# - that -aligncomm is emitted for the various alignments (greater than 32) # - that the alignment is represented as a log_2 of the alignment # - that the section switching occurs correctly # - that functions after the switch also are emitted into the correct section @@ -20,11 +20,13 @@ .data .comm _s_1,4,0 # @s_1 - .comm _s_2,4,1 # @s_2 - .comm _s_4,4,2 # @s_3 - .comm _s_8,4,3 # @s_4 + .comm _s_2,4,2 # @s_2 + .comm _s_3,4,4 # @s_3 + .comm _s_4,4,8 # @s_4 + + .comm _s_5,4,1 # @s_5 + .comm _small_but_overalign,1,6 # @s_6 - .comm _small_but_overaligned,1,3 # @s_4 .text @@ -43,8 +45,33 @@ # CHECK: Section: .text (1) # CHECK: } # CHECK: Symbol { -# CHECK: Name: _small_but_overaligned -# CHECK-NEXT:Value: 1 +# CHECK: Name: _s_1 +# CHECK-NEXT:Value: 4 +# CHECK-NEXT:Section: IMAGE_SYM_UNDEFINED (0) +# CHECK: } +# CHECK: Symbol { +# CHECK: Name: _s_2 +# CHECK-NEXT:Value: 4 +# CHECK-NEXT:Section: IMAGE_SYM_UNDEFINED (0) +# CHECK: } +# CHECK: Symbol { +# CHECK: Name: _s_3 +# CHECK-NEXT:Value: 16 +# CHECK-NEXT:Section: IMAGE_SYM_UNDEFINED (0) +# CHECK: } +# CHECK: Symbol { +# CHECK: Name: _s_4 +# CHECK-NEXT:Value: 256 +# CHECK-NEXT:Section: IMAGE_SYM_UNDEFINED (0) +# CHECK: } +# CHECK: Symbol { +# CHECK: Name: _s_5 +# CHECK-NEXT:Value: 4 +# CHECK-NEXT:Section: IMAGE_SYM_UNDEFINED (0) +# CHECK: } +# CHECK: Symbol { +# CHECK: Name: _small_but_overalign +# CHECK-NEXT:Value: 64 # CHECK-NEXT:Section: IMAGE_SYM_UNDEFINED (0) # CHECK: } # CHECK: Symbol { @@ -53,5 +80,5 @@ # CHECK: } # CHECK: ] -# CHECK: Directive(s): -aligncomm:"_s_2",1 -aligncomm:"_s_4",2 -aligncomm:"_s_8",3 -aligncomm:"_small_but_overaligned",3 +# CHECK: Directive(s): -aligncomm:"_s_4",8 -aligncomm:"_small_but_overalign",6