LLVM 23.0.0git
MCAsmInfoXCOFF.cpp
Go to the documentation of this file.
1//===- MC/MCAsmInfoXCOFF.cpp - XCOFF asm properties ------------ *- C++ -*-===//
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
11#include "llvm/MC/MCAsmInfo.h"
14#include "llvm/Support/Format.h"
16
17using namespace llvm;
18
19namespace llvm {
21}
22
25 IsAIX = true;
26 IsLittleEndian = false;
27
29 PrivateLabelPrefix = "L..";
30 SupportsQuotedNames = false;
32 HasLEB128Directives = false;
33 ZeroDirective = "\t.space\t";
34 AsciiDirective = nullptr; // not supported
35 AscizDirective = nullptr; // not supported
37
38 // Use .vbyte for data definition to avoid directives that apply an implicit
39 // alignment.
40 Data16bitsDirective = "\t.vbyte\t2, ";
41 Data32bitsDirective = "\t.vbyte\t4, ";
42
47
49}
50
52 // QualName is allowed for a MCSymbolXCOFF, and
53 // QualName contains '[' and ']'.
54 if (C == '[' || C == ']')
55 return true;
56
57 // For AIX assembler, symbols may consist of numeric digits,
58 // underscores, periods, uppercase or lowercase letters, or
59 // any combination of these.
60 return isAlnum(C) || C == '_' || C == '.';
61}
62
64 return static_cast<const MCSectionXCOFF &>(Sec).getKind().isText();
65}
66
68
69void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const {
70 OS << "\t.csect " << QualName->getName() << "," << Log2(getAlign()) << '\n';
71}
72
74 const Triple &T,
75 raw_ostream &OS) const {
76 auto &Sec = static_cast<const MCSectionXCOFF &>(Section);
77 if (Sec.getKind().isText()) {
78 if (Sec.getMappingClass() != XCOFF::XMC_PR)
79 report_fatal_error("Unhandled storage-mapping class for .text csect");
80
81 Sec.printCsectDirective(OS);
82 return;
83 }
84
85 if (Sec.getKind().isReadOnly()) {
86 if (Sec.getMappingClass() != XCOFF::XMC_RO &&
87 Sec.getMappingClass() != XCOFF::XMC_TD)
88 report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
89 Sec.printCsectDirective(OS);
90 return;
91 }
92
93 if (Sec.getKind().isReadOnlyWithRel()) {
94 if (Sec.getMappingClass() != XCOFF::XMC_RW &&
95 Sec.getMappingClass() != XCOFF::XMC_RO &&
96 Sec.getMappingClass() != XCOFF::XMC_TD)
98 "Unexepected storage-mapping class for ReadOnlyWithRel kind");
99 Sec.printCsectDirective(OS);
100 return;
101 }
102
103 // Initialized TLS data.
104 if (Sec.getKind().isThreadData()) {
105 // We only expect XMC_TL here for initialized TLS data.
106 if (Sec.getMappingClass() != XCOFF::XMC_TL)
107 report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
108 Sec.printCsectDirective(OS);
109 return;
110 }
111
112 if (Sec.getKind().isData()) {
113 switch (Sec.getMappingClass()) {
114 case XCOFF::XMC_RW:
115 case XCOFF::XMC_DS:
116 case XCOFF::XMC_TD:
117 Sec.printCsectDirective(OS);
118 break;
119 case XCOFF::XMC_TC:
120 case XCOFF::XMC_TE:
121 break;
122 case XCOFF::XMC_TC0:
123 OS << "\t.toc\n";
124 break;
125 default:
126 report_fatal_error("Unhandled storage-mapping class for .data csect.");
127 }
128 return;
129 }
130
131 if (Sec.isCsect() && Sec.getMappingClass() == XCOFF::XMC_TD) {
132 // Common csect type (uninitialized storage) does not have to print
133 // csect directive for section switching unless it is local.
134 if (Sec.getKind().isCommon() && !Sec.getKind().isBSSLocal())
135 return;
136
137 assert(Sec.getKind().isBSS() && "Unexpected section kind for toc-data");
138 Sec.printCsectDirective(OS);
139 return;
140 }
141 // Common csect type (uninitialized storage) does not have to print csect
142 // directive for section switching.
143 if (Sec.isCsect() && Sec.getCSectType() == XCOFF::XTY_CM) {
144 assert((Sec.getMappingClass() == XCOFF::XMC_RW ||
145 Sec.getMappingClass() == XCOFF::XMC_BS ||
146 Sec.getMappingClass() == XCOFF::XMC_UL) &&
147 "Generated a storage-mapping class for a common/bss/tbss csect we "
148 "don't "
149 "understand how to switch to.");
150 // Common symbols and local zero-initialized symbols for TLS and Non-TLS are
151 // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to
152 // cover TLS common and zero-initialized local symbols since linkage type
153 // (in the GlobalVariable) is not accessible in this class.
154 assert((Sec.getKind().isBSSLocal() || Sec.getKind().isCommon() ||
155 Sec.getKind().isThreadBSS()) &&
156 "wrong symbol type for .bss/.tbss csect");
157 // Don't have to print a directive for switching to section for commons
158 // and zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
159 // variable will create the needed csect.
160 return;
161 }
162
163 // Zero-initialized TLS data with weak or external linkage are not eligible to
164 // be put into common csect.
165 if (Sec.getKind().isThreadBSS()) {
166 Sec.printCsectDirective(OS);
167 return;
168 }
169
170 // XCOFF debug sections.
171 if (Sec.getKind().isMetadata() && Sec.isDwarfSect()) {
172 OS << "\n\t.dwsect " << format("0x%" PRIx32, *Sec.getDwarfSubtypeFlags())
173 << '\n';
174 OS << Sec.getName() << ':' << '\n';
175 return;
176 }
177
178 report_fatal_error("Printing for this SectionKind is unimplemented.");
179}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static LVOptions Options
Definition LVOptions.cpp:25
#define T
This file contains some functions that are useful when dealing with strings.
MCAsmInfoXCOFF(const MCTargetOptions &Options)
void printSwitchToSection(const MCSection &, uint32_t, const Triple &, raw_ostream &) const final
bool useCodeAlign(const MCSection &Sec) const final
bool isAcceptableChar(char C) const override
Return true if C is an acceptable character inside a symbol name.
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:160
const char * Data16bitsDirective
Definition MCAsmInfo.h:247
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition MCAsmInfo.h:230
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:361
MCAsmInfo(const MCTargetOptions &Options)
Definition MCAsmInfo.cpp:44
const char * Data32bitsDirective
Definition MCAsmInfo.h:248
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition MCAsmInfo.h:297
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks. Defaults to "L".
Definition MCAsmInfo.h:163
bool HasDotTypeDotSizeDirective
True if the target has .type and .size directives, this is true for most ELF targets.
Definition MCAsmInfo.h:308
bool ParseInlineAsmUsingAsmParser
Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
Definition MCAsmInfo.h:417
bool COMMDirectiveAlignmentIsInBytes
True is .comm's and .lcomms optional alignment is to be specified in bytes instead of log2(n).
Definition MCAsmInfo.h:293
AsmCharLiteralSyntax CharacterLiteralSyntax
Form used for character literals in the assembly syntax.
Definition MCAsmInfo.h:240
const char * ZeroDirective
This should be set to the directive used to get some number of zero (and non-zero if supported by the...
Definition MCAsmInfo.h:225
bool SupportsQuotedNames
If this is true, symbol names with invalid characters will be printed in quotes.
Definition MCAsmInfo.h:206
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition MCAsmInfo.h:235
bool IsLittleEndian
True if target is little endian. Default is true.
Definition MCAsmInfo.h:94
@ ACLS_SingleQuotePrefix
Unknown; character literals not used by LLVM for this target.
Definition MCAsmInfo.h:70
bool HasLEB128Directives
True if the target supports LEB128 directives.
Definition MCAsmInfo.h:214
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:573
Align getAlign() const
Definition MCSection.h:657
bool isText() const
Definition MCSection.h:644
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ XMC_TE
Symbol mapped at the end of TOC.
Definition XCOFF.h:129
@ XMC_TC0
TOC Anchor for TOC Addressability.
Definition XCOFF.h:119
@ XMC_DS
Descriptor csect.
Definition XCOFF.h:122
@ XMC_RW
Read Write Data.
Definition XCOFF.h:118
@ XMC_TL
Initialized thread-local variable.
Definition XCOFF.h:127
@ XMC_RO
Read Only Constant.
Definition XCOFF.h:107
@ XMC_TD
Scalar data item in the TOC.
Definition XCOFF.h:121
@ XMC_UL
Uninitialized thread-local variable.
Definition XCOFF.h:128
@ XMC_PR
Program Code.
Definition XCOFF.h:106
@ XMC_BS
BSS class (uninitialized static internal)
Definition XCOFF.h:124
@ XMC_TC
General TOC item.
Definition XCOFF.h:120
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition XCOFF.h:246
This is an optimization pass for GlobalISel generic memory operations.
@ AIX
AIX Exception Handling.
Definition CodeGen.h:60
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:129
cl::opt< cl::boolOrDefault > UseLEB128Directives("use-leb128-directives", cl::Hidden, cl::desc("Disable the usage of LEB128 directives, and generate .byte instead."), cl::init(cl::BOU_UNSET))
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:197