Skip to content

Commit 3d96acb

Browse files
committed
[-cxx-abi microsoft] Stick zero initialized symbols into the .bss section for COFF
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 llvm-svn: 188244
1 parent d29614f commit 3d96acb

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,15 +771,18 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
771771
}
772772

773773
if (Kind.isText())
774-
return getTextSection();
774+
return TextSection;
775775

776776
if (Kind.isThreadLocal())
777-
return getTLSDataSection();
777+
return TLSDataSection;
778778

779-
if (Kind.isReadOnly() && ReadOnlySection != 0)
779+
if (Kind.isReadOnly())
780780
return ReadOnlySection;
781781

782-
return getDataSection();
782+
if (Kind.isBSS())
783+
return BSSSection;
784+
785+
return DataSection;
783786
}
784787

785788
void TargetLoweringObjectFileCOFF::

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
496496

497497
void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
498498
// COFF
499+
BSSSection =
500+
Ctx->getCOFFSection(".bss",
501+
COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
502+
COFF::IMAGE_SCN_MEM_READ |
503+
COFF::IMAGE_SCN_MEM_WRITE,
504+
SectionKind::getBSS());
499505
TextSection =
500506
Ctx->getCOFFSection(".text",
501507
COFF::IMAGE_SCN_CNT_CODE |

llvm/test/MC/COFF/bss_section.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: llc -mtriple i386-pc-win32 < %s | FileCheck %s
2+
3+
%struct.foo = type { i32, i32 }
4+
5+
@"\01?thingy@@3Ufoo@@B" = global %struct.foo zeroinitializer, align 4
6+
; CHECK: .bss

0 commit comments

Comments
 (0)