LLVM 20.0.0git
MCSectionXCOFF.cpp
Go to the documentation of this file.
1//===- lib/MC/MCSectionXCOFF.cpp - XCOFF Code Section Representation ------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/MC/MCAsmInfo.h"
11#include "llvm/Support/Format.h"
13namespace llvm {
14class MCExpr;
15class Triple;
16} // namespace llvm
17
18using namespace llvm;
19
21
22void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const {
23 OS << "\t.csect " << QualName->getName() << "," << Log2(getAlign()) << '\n';
24}
25
28 uint32_t Subsection) const {
29 if (getKind().isText()) {
31 report_fatal_error("Unhandled storage-mapping class for .text csect");
32
33 printCsectDirective(OS);
34 return;
35 }
36
37 if (getKind().isReadOnly()) {
40 report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
41 printCsectDirective(OS);
42 return;
43 }
44
45 if (getKind().isReadOnlyWithRel()) {
50 "Unexepected storage-mapping class for ReadOnlyWithRel kind");
51 printCsectDirective(OS);
52 return;
53 }
54
55 // Initialized TLS data.
56 if (getKind().isThreadData()) {
57 // We only expect XMC_TL here for initialized TLS data.
59 report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
60 printCsectDirective(OS);
61 return;
62 }
63
64 if (getKind().isData()) {
65 switch (getMappingClass()) {
66 case XCOFF::XMC_RW:
67 case XCOFF::XMC_DS:
68 case XCOFF::XMC_TD:
69 printCsectDirective(OS);
70 break;
71 case XCOFF::XMC_TC:
72 case XCOFF::XMC_TE:
73 break;
74 case XCOFF::XMC_TC0:
75 OS << "\t.toc\n";
76 break;
77 default:
79 "Unhandled storage-mapping class for .data csect.");
80 }
81 return;
82 }
83
85 // Common csect type (uninitialized storage) does not have to print csect
86 // directive for section switching unless it is local.
87 if (getKind().isCommon() && !getKind().isBSSLocal())
88 return;
89
90 assert(getKind().isBSS() && "Unexpected section kind for toc-data");
91 printCsectDirective(OS);
92 return;
93 }
94 // Common csect type (uninitialized storage) does not have to print csect
95 // directive for section switching.
96 if (isCsect() && getCSectType() == XCOFF::XTY_CM) {
100 "Generated a storage-mapping class for a common/bss/tbss csect we "
101 "don't "
102 "understand how to switch to.");
103 // Common symbols and local zero-initialized symbols for TLS and Non-TLS are
104 // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to cover
105 // TLS common and zero-initialized local symbols since linkage type (in the
106 // GlobalVariable) is not accessible in this class.
107 assert((getKind().isBSSLocal() || getKind().isCommon() ||
108 getKind().isThreadBSS()) &&
109 "wrong symbol type for .bss/.tbss csect");
110 // Don't have to print a directive for switching to section for commons and
111 // zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
112 // variable will create the needed csect.
113 return;
114 }
115
116 // Zero-initialized TLS data with weak or external linkage are not eligible to
117 // be put into common csect.
118 if (getKind().isThreadBSS()) {
119 printCsectDirective(OS);
120 return;
121 }
122
123 // XCOFF debug sections.
124 if (getKind().isMetadata() && isDwarfSect()) {
125 OS << "\n\t.dwsect " << format("0x%" PRIx32, *getDwarfSubtypeFlags())
126 << '\n';
127 OS << getName() << ':' << '\n';
128 return;
129 }
130
131 report_fatal_error("Printing for this SectionKind is unimplemented.");
132}
133
134bool MCSectionXCOFF::useCodeAlign() const { return getKind().isText(); }
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
std::optional< XCOFF::DwarfSectionSubtypeFlags > getDwarfSubtypeFlags() const
SectionKind getKind() const
XCOFF::StorageMappingClass getMappingClass() const
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, uint32_t Subsection) const override
bool useCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
bool isDwarfSect() const
XCOFF::SymbolType getCSectType() const
Align getAlign() const
Definition: MCSection.h:146
bool isText() const
Definition: MCSection.h:131
StringRef getName() const
Definition: MCSection.h:130
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
bool isText() const
Definition: SectionKind.h:127
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ XMC_TE
Symbol mapped at the end of TOC.
Definition: XCOFF.h:128
@ XMC_TC0
TOC Anchor for TOC Addressability.
Definition: XCOFF.h:118
@ XMC_DS
Descriptor csect.
Definition: XCOFF.h:121
@ XMC_RW
Read Write Data.
Definition: XCOFF.h:117
@ XMC_TL
Initialized thread-local variable.
Definition: XCOFF.h:126
@ XMC_RO
Read Only Constant.
Definition: XCOFF.h:106
@ XMC_TD
Scalar data item in the TOC.
Definition: XCOFF.h:120
@ XMC_UL
Uninitialized thread-local variable.
Definition: XCOFF.h:127
@ XMC_PR
Program Code.
Definition: XCOFF.h:105
@ XMC_BS
BSS class (uninitialized static internal)
Definition: XCOFF.h:123
@ XMC_TC
General TOC item.
Definition: XCOFF.h:119
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition: XCOFF.h:245
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:208