1 //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCSectionCOFF.h"
10 #include "llvm/BinaryFormat/COFF.h"
11 #include "llvm/MC/MCSymbol.h"
12 #include "llvm/Support/raw_ostream.h"
17 // shouldOmitSectionDirective - Decides whether a '.section' directive
18 // should be printed before the section name
19 bool MCSectionCOFF::shouldOmitSectionDirective(StringRef Name
,
20 const MCAsmInfo
&MAI
) const {
24 // FIXME: Does .section .bss/.data/.text work everywhere??
25 if (Name
== ".text" || Name
== ".data" || Name
== ".bss")
31 void MCSectionCOFF::setSelection(int Selection
) const {
32 assert(Selection
!= 0 && "invalid COMDAT selection type");
33 this->Selection
= Selection
;
34 Characteristics
|= COFF::IMAGE_SCN_LNK_COMDAT
;
37 void MCSectionCOFF::printSwitchToSection(const MCAsmInfo
&MAI
, const Triple
&T
,
39 uint32_t Subsection
) const {
40 // standard sections don't require the '.section'
41 if (shouldOmitSectionDirective(getName(), MAI
)) {
42 OS
<< '\t' << getName() << '\n';
46 OS
<< "\t.section\t" << getName() << ",\"";
47 if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
)
49 if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
)
51 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE
)
53 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE
)
55 else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ
)
59 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE
)
61 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED
)
63 if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE
) &&
64 !isImplicitlyDiscardable(getName()))
66 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_INFO
)
70 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT
) {
74 OS
<< "\n\t.linkonce\t";
76 case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES
:
79 case COFF::IMAGE_COMDAT_SELECT_ANY
:
82 case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE
:
85 case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH
:
86 OS
<< "same_contents";
88 case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE
:
91 case COFF::IMAGE_COMDAT_SELECT_LARGEST
:
94 case COFF::IMAGE_COMDAT_SELECT_NEWEST
:
98 assert(false && "unsupported COFF selection type");
103 COMDATSymbol
->print(OS
, &MAI
);
109 bool MCSectionCOFF::useCodeAlign() const { return isText(); }
111 StringRef
MCSectionCOFF::getVirtualSectionKind() const {
112 return "IMAGE_SCN_CNT_UNINITIALIZED_DATA";