From 192d136750b376d46bf030a6d5a4c098b0768826 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Sat, 9 Oct 2010 15:44:27 +0000 Subject: [PATCH] MC-COFF: Implement InitSections. Fixes PR8335. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116151 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/WinCOFFStreamer.cpp | 39 ++++++++++++++++++++++++++++++++++++++ test/MC/COFF/basic-coff.s | 6 +++--- test/MC/COFF/module-asm.ll | 26 +++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 test/MC/COFF/module-asm.ll diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 0ff68df9dd7..9fd80a4f63c 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -79,6 +79,41 @@ public: virtual void EmitDwarfFileDirective(unsigned FileNo,StringRef Filename); virtual void EmitInstruction(const MCInst &Instruction); virtual void Finish(); + +private: + void SetSection(StringRef Section, + unsigned Characteristics, + SectionKind Kind) { + SwitchSection(getContext().getCOFFSection(Section, Characteristics, Kind)); + } + + void SetSectionText() { + SetSection(".text", + COFF::IMAGE_SCN_CNT_CODE + | COFF::IMAGE_SCN_MEM_EXECUTE + | COFF::IMAGE_SCN_MEM_READ, + SectionKind::getText()); + EmitCodeAlignment(4, 0); + } + + void SetSectionData() { + SetSection(".data", + COFF::IMAGE_SCN_CNT_INITIALIZED_DATA + | COFF::IMAGE_SCN_MEM_READ + | COFF::IMAGE_SCN_MEM_WRITE, + SectionKind::getDataRel()); + EmitCodeAlignment(4, 0); + } + + void SetSectionBSS() { + SetSection(".bss", + COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA + | COFF::IMAGE_SCN_MEM_READ + | COFF::IMAGE_SCN_MEM_WRITE, + SectionKind::getBSS()); + EmitCodeAlignment(4, 0); + } + }; } // end anonymous namespace. @@ -128,6 +163,10 @@ void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size, // MCStreamer interface void WinCOFFStreamer::InitSections() { + SetSectionText(); + SetSectionData(); + SetSectionBSS(); + SetSectionText(); } void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) { diff --git a/test/MC/COFF/basic-coff.s b/test/MC/COFF/basic-coff.s index a94273bfc8d..fcbe2904a54 100644 --- a/test/MC/COFF/basic-coff.s +++ b/test/MC/COFF/basic-coff.s @@ -74,9 +74,9 @@ L_.str: # @.str // CHECK: PointerToLineNumbers = 0x0 // CHECK: NumberOfRelocations = 0 // CHECK: NumberOfLineNumbers = 0 -// CHECK: Charateristics = 0xC0100040 +// CHECK: Charateristics = 0xC0300040 // CHECK: IMAGE_SCN_CNT_INITIALIZED_DATA -// CHECK: IMAGE_SCN_ALIGN_1BYTES +// CHECK: IMAGE_SCN_ALIGN_4BYTES // CHECK: IMAGE_SCN_MEM_READ // CHECK: IMAGE_SCN_MEM_WRITE // CHECK: SectionData = @@ -94,7 +94,7 @@ L_.str: # @.str // CHECK: StorageClass = IMAGE_SYM_CLASS_STATIC (3) // CHECK: NumberOfAuxSymbols = 1 // CHECK: AuxillaryData = -// CHECK: 15 00 00 00 02 00 00 00 - 00 00 00 00 01 00 00 00 |................| +// CHECK: 18 00 00 00 02 00 00 00 - 00 00 00 00 01 00 00 00 |................| // CHECK: 00 00 |..| // CHECK: } // CHECK: 2 = { diff --git a/test/MC/COFF/module-asm.ll b/test/MC/COFF/module-asm.ll new file mode 100644 index 00000000000..9c6d00d2f50 --- /dev/null +++ b/test/MC/COFF/module-asm.ll @@ -0,0 +1,26 @@ +; The purpose of this test is to verify that various module level assembly +; constructs work. + +; RUN: llc -filetype=obj -mtriple i686-pc-win32 %s -o - | coff-dump.py | FileCheck %s +; RUN: llc -filetype=obj -mtriple x86_64-pc-win32 %s -o - | coff-dump.py | FileCheck %s + +module asm ".text" +module asm "_foo:" +module asm " ret" + +; CHECK: Name = .text +; CHECK-NEXT: VirtualSize = 0 +; CHECK-NEXT: VirtualAddress = 0 +; CHECK-NEXT: SizeOfRawData = {{[0-9]+}} +; CHECK-NEXT: PointerToRawData = 0x{{[0-9A-F]+}} +; CHECK-NEXT: PointerToRelocations = 0x{{[0-9A-F]+}} +; CHECK-NEXT: PointerToLineNumbers = 0x0 +; CHECK-NEXT: NumberOfRelocations = 0 +; CHECK-NEXT: NumberOfLineNumbers = 0 +; CHECK-NEXT: Charateristics = 0x60300020 +; CHECK-NEXT: IMAGE_SCN_CNT_CODE +; CHECK-NEXT: IMAGE_SCN_ALIGN_4BYTES +; CHECK-NEXT: IMAGE_SCN_MEM_EXECUTE +; CHECK-NEXT: IMAGE_SCN_MEM_READ +; CHECK-NEXT: SectionData = +; CHECK-NEXT: C3