1 //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCSectionCOFF.h"
11 #include "llvm/BinaryFormat/COFF.h"
12 #include "llvm/MC/MCSymbol.h"
13 #include "llvm/Support/raw_ostream.h"
18 MCSectionCOFF::~MCSectionCOFF() = default; // anchor.
20 // ShouldOmitSectionDirective - Decides whether a '.section' directive
21 // should be printed before the section name
22 bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
23 const MCAsmInfo &MAI) const {
27 // FIXME: Does .section .bss/.data/.text work everywhere??
28 if (Name == ".text" || Name == ".data" || Name == ".bss")
34 void MCSectionCOFF::setSelection(int Selection) const {
35 assert(Selection != 0 && "invalid COMDAT selection type");
36 this->Selection = Selection;
37 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
40 void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
42 const MCExpr *Subsection) const {
43 // standard sections don't require the '.section'
44 if (ShouldOmitSectionDirective(SectionName, MAI)) {
45 OS << '\t' << getSectionName() << '\n';
49 OS << "\t.section\t" << getSectionName() << ",\"";
50 if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
52 if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
54 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
56 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
58 else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
62 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
64 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
66 if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
67 !isImplicitlyDiscardable(SectionName))
71 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
75 OS << "\n\t.linkonce\t";
77 case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
80 case COFF::IMAGE_COMDAT_SELECT_ANY:
83 case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
86 case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
87 OS << "same_contents";
89 case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:
92 case COFF::IMAGE_COMDAT_SELECT_LARGEST:
95 case COFF::IMAGE_COMDAT_SELECT_NEWEST:
99 assert(false && "unsupported COFF selection type");
104 COMDATSymbol->print(OS, &MAI);
110 bool MCSectionCOFF::UseCodeAlign() const {
111 return getKind().isText();
114 bool MCSectionCOFF::isVirtualSection() const {
115 return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;