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/MC/MCExpr.h"
12 #include "llvm/Support/Debug.h"
13 #include "llvm/Support/Format.h"
14 #include "llvm/Support/raw_ostream.h"
18 MCSectionXCOFF::~MCSectionXCOFF() = default;
20 void MCSectionXCOFF::printCsectDirective(raw_ostream
&OS
) const {
21 OS
<< "\t.csect " << QualName
->getName() << "," << Log2_32(getAlignment())
25 void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo
&MAI
, const Triple
&T
,
27 const MCExpr
*Subsection
) const {
28 if (getKind().isText()) {
29 if (getMappingClass() != XCOFF::XMC_PR
)
30 report_fatal_error("Unhandled storage-mapping class for .text csect");
32 printCsectDirective(OS
);
36 if (getKind().isReadOnly()) {
37 if (getMappingClass() != XCOFF::XMC_RO
)
38 report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
39 printCsectDirective(OS
);
43 // Initialized TLS data.
44 if (getKind().isThreadData()) {
45 // We only expect XMC_TL here for initialized TLS data.
46 if (getMappingClass() != XCOFF::XMC_TL
)
47 report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
48 printCsectDirective(OS
);
52 if (getKind().isData()) {
53 switch (getMappingClass()) {
57 printCsectDirective(OS
);
67 "Unhandled storage-mapping class for .data csect.");
72 if (isCsect() && getMappingClass() == XCOFF::XMC_TD
) {
73 assert((getKind().isBSSExtern() || getKind().isBSSLocal()) &&
74 "Unexepected section kind for toc-data");
75 printCsectDirective(OS
);
78 // Common csect type (uninitialized storage) does not have to print csect
79 // directive for section switching.
80 if (isCsect() && getCSectType() == XCOFF::XTY_CM
) {
81 assert((getMappingClass() == XCOFF::XMC_RW
||
82 getMappingClass() == XCOFF::XMC_BS
||
83 getMappingClass() == XCOFF::XMC_UL
) &&
84 "Generated a storage-mapping class for a common/bss/tbss csect we "
86 "understand how to switch to.");
87 // Common symbols and local zero-initialized symbols for TLS and Non-TLS are
88 // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to cover
89 // TLS common and zero-initialized local symbols since linkage type (in the
90 // GlobalVariable) is not accessible in this class.
91 assert((getKind().isBSSLocal() || getKind().isCommon() ||
92 getKind().isThreadBSS()) &&
93 "wrong symbol type for .bss/.tbss csect");
94 // Don't have to print a directive for switching to section for commons and
95 // zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
96 // variable will create the needed csect.
100 // Zero-initialized TLS data with weak or external linkage are not eligible to
101 // be put into common csect.
102 if (getKind().isThreadBSS()) {
103 printCsectDirective(OS
);
107 // XCOFF debug sections.
108 if (getKind().isMetadata() && isDwarfSect()) {
110 << format("0x%" PRIx32
, getDwarfSubtypeFlags().getValue()) << '\n';
111 OS
<< MAI
.getPrivateLabelPrefix() << getName() << ':' << '\n';
115 report_fatal_error("Printing for this SectionKind is unimplemented.");
118 bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); }
120 bool MCSectionXCOFF::isVirtualSection() const {
121 assert(isCsect() && "Only csect section can be virtual!");
122 return XCOFF::XTY_CM
== CsectProp
->Type
;