void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
- // The object file format cannot represent common symbols with explicit
- // alignments.
- CommDirectiveSupportsAlignment = false;
+ CommDirectiveSupportsAlignment = true;
// COFF
BSSSection =
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
- if (ByteAlignment > 32)
- report_fatal_error("alignment is limited to 32-bytes");
+ const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
+ 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.
+ Size = std::max(Size, static_cast<uint64_t>(ByteAlignment));
AssignSection(Symbol, nullptr);
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s | llvm-readobj -t | FileCheck %s
.lcomm _a,4,4
-.comm _b, 4
+.comm _b, 4, 2
+// _c has size 1 but align 32, the value field is the max of size and align.
+.comm _c, 1, 5
// CHECK: Symbol {
// CHECK-NEXT: StorageClass: External
// CHECK-NEXT: AuxSymbolCount: 0
// CHECK-NEXT: }
+
+// CHECK: Symbol {
+// CHECK: Name: _c
+// CHECK-NEXT: Value: 32
+// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
+// CHECK-NEXT: BaseType: Null
+// CHECK-NEXT: ComplexType: Null
+// CHECK-NEXT: StorageClass: External
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }