[-cxx-abi microsoft] Stick zero initialized symbols into the .bss section for COFF
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 13 Aug 2013 01:23:53 +0000 (01:23 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 13 Aug 2013 01:23:53 +0000 (01:23 +0000)
Summary:
We need to do two things:

- Initialize BSSSection in MCObjectFileInfo::InitCOFFMCObjectFileInfo
- Teach TargetLoweringObjectFileCOFF::SelectSectionForGlobal what to do
  with it

This fixes PR16861.

Reviewers: rnk

Reviewed By: rnk

CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1361

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188244 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TargetLoweringObjectFileImpl.cpp
lib/MC/MCObjectFileInfo.cpp
test/MC/COFF/bss_section.ll [new file with mode: 0644]

index ea0d62e6ef39a7b39c53202c03850f69a9bf13ef..085e8f4018636830984a678dbc39fc7e6197cbe5 100644 (file)
@@ -771,15 +771,18 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
   }
 
   if (Kind.isText())
-    return getTextSection();
+    return TextSection;
 
   if (Kind.isThreadLocal())
-    return getTLSDataSection();
+    return TLSDataSection;
 
-  if (Kind.isReadOnly() && ReadOnlySection != 0)
+  if (Kind.isReadOnly())
     return ReadOnlySection;
 
-  return getDataSection();
+  if (Kind.isBSS())
+    return BSSSection;
+
+  return DataSection;
 }
 
 void TargetLoweringObjectFileCOFF::
index bcf52d2368a203327f5e22f23595bce3c9d2b146..819c00b180cbc76b7adc6f78f1060abf3b8e8f9b 100644 (file)
@@ -496,6 +496,12 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
 
 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
   // COFF
+  BSSSection =
+    Ctx->getCOFFSection(".bss",
+                        COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
+                        COFF::IMAGE_SCN_MEM_READ |
+                        COFF::IMAGE_SCN_MEM_WRITE,
+                        SectionKind::getBSS());
   TextSection =
     Ctx->getCOFFSection(".text",
                         COFF::IMAGE_SCN_CNT_CODE |
diff --git a/test/MC/COFF/bss_section.ll b/test/MC/COFF/bss_section.ll
new file mode 100644 (file)
index 0000000..60924f1
--- /dev/null
@@ -0,0 +1,6 @@
+; RUN: llc -mtriple i386-pc-win32 < %s | FileCheck %s
+
+%struct.foo = type { i32, i32 }
+
+@"\01?thingy@@3Ufoo@@B" = global %struct.foo zeroinitializer, align 4
+; CHECK: .bss