1 //===- lib/MC/MCSectionXCOFF.cpp - XCOFF 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/MCSectionXCOFF.h"
10 #include "llvm/MC/MCAsmInfo.h"
11 #include "llvm/Support/Format.h"
12 #include "llvm/Support/raw_ostream.h"
20 MCSectionXCOFF::~MCSectionXCOFF() = default;
22 void MCSectionXCOFF::printCsectDirective(raw_ostream
&OS
) const {
23 OS
<< "\t.csect " << QualName
->getName() << "," << Log2(getAlign()) << '\n';
26 void MCSectionXCOFF::printSwitchToSection(const MCAsmInfo
&MAI
, const Triple
&T
,
28 const MCExpr
*Subsection
) const {
29 if (getKind().isText()) {
30 if (getMappingClass() != XCOFF::XMC_PR
)
31 report_fatal_error("Unhandled storage-mapping class for .text csect");
33 printCsectDirective(OS
);
37 if (getKind().isReadOnly()) {
38 if (getMappingClass() != XCOFF::XMC_RO
&&
39 getMappingClass() != XCOFF::XMC_TD
)
40 report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
41 printCsectDirective(OS
);
45 if (getKind().isReadOnlyWithRel()) {
46 if (getMappingClass() != XCOFF::XMC_RW
&&
47 getMappingClass() != XCOFF::XMC_RO
&&
48 getMappingClass() != XCOFF::XMC_TD
)
50 "Unexepected storage-mapping class for ReadOnlyWithRel kind");
51 printCsectDirective(OS
);
55 // Initialized TLS data.
56 if (getKind().isThreadData()) {
57 // We only expect XMC_TL here for initialized TLS data.
58 if (getMappingClass() != XCOFF::XMC_TL
)
59 report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
60 printCsectDirective(OS
);
64 if (getKind().isData()) {
65 switch (getMappingClass()) {
69 printCsectDirective(OS
);
79 "Unhandled storage-mapping class for .data csect.");
84 if (isCsect() && getMappingClass() == XCOFF::XMC_TD
) {
85 assert((getKind().isBSSExtern() || getKind().isBSSLocal()) &&
86 "Unexepected section kind for toc-data");
87 printCsectDirective(OS
);
90 // Common csect type (uninitialized storage) does not have to print csect
91 // directive for section switching.
92 if (isCsect() && getCSectType() == XCOFF::XTY_CM
) {
93 assert((getMappingClass() == XCOFF::XMC_RW
||
94 getMappingClass() == XCOFF::XMC_BS
||
95 getMappingClass() == XCOFF::XMC_UL
) &&
96 "Generated a storage-mapping class for a common/bss/tbss csect we "
98 "understand how to switch to.");
99 // Common symbols and local zero-initialized symbols for TLS and Non-TLS are
100 // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to cover
101 // TLS common and zero-initialized local symbols since linkage type (in the
102 // GlobalVariable) is not accessible in this class.
103 assert((getKind().isBSSLocal() || getKind().isCommon() ||
104 getKind().isThreadBSS()) &&
105 "wrong symbol type for .bss/.tbss csect");
106 // Don't have to print a directive for switching to section for commons and
107 // zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
108 // variable will create the needed csect.
112 // Zero-initialized TLS data with weak or external linkage are not eligible to
113 // be put into common csect.
114 if (getKind().isThreadBSS()) {
115 printCsectDirective(OS
);
119 // XCOFF debug sections.
120 if (getKind().isMetadata() && isDwarfSect()) {
121 OS
<< "\n\t.dwsect " << format("0x%" PRIx32
, *getDwarfSubtypeFlags())
123 OS
<< MAI
.getPrivateLabelPrefix() << getName() << ':' << '\n';
127 report_fatal_error("Printing for this SectionKind is unimplemented.");
130 bool MCSectionXCOFF::useCodeAlign() const { return getKind().isText(); }
132 bool MCSectionXCOFF::isVirtualSection() const {
133 // DWARF sections are always not virtual.
137 "Handling for isVirtualSection not implemented for this section!");
138 return XCOFF::XTY_CM
== CsectProp
->Type
;