LLVM 24.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
10#include "MCCLOptions.h"
12#include "llvm/MC/MCAsmInfo.h"
14#include "llvm/Support/Format.h"
16
17using namespace llvm;
18
19static void printCsectDirective(const MCSectionXCOFF &Sec, raw_ostream &OS) {
20 OS << "\t.csect " << Sec.getQualNameSymbol()->getName() << ","
21 << Log2(Sec.getAlign()) << '\n';
22}
23
24static void printSwitchToSection(const MCAsmInfo &MAI, const MCSection &Section,
25 uint32_t, const Triple &T, raw_ostream &OS) {
26 auto &Sec = static_cast<const MCSectionXCOFF &>(Section);
27 if (Sec.getKind().isText()) {
28 if (Sec.getMappingClass() != XCOFF::XMC_PR)
29 report_fatal_error("Unhandled storage-mapping class for .text csect");
30
31 printCsectDirective(Sec, OS);
32 return;
33 }
34
35 if (Sec.getKind().isReadOnly()) {
36 if (Sec.getMappingClass() != XCOFF::XMC_RO &&
37 Sec.getMappingClass() != XCOFF::XMC_TD)
38 report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
39 printCsectDirective(Sec, OS);
40 return;
41 }
42
43 if (Sec.getKind().isReadOnlyWithRel()) {
44 if (Sec.getMappingClass() != XCOFF::XMC_RW &&
45 Sec.getMappingClass() != XCOFF::XMC_RO &&
46 Sec.getMappingClass() != XCOFF::XMC_TD)
48 "Unexepected storage-mapping class for ReadOnlyWithRel kind");
49 printCsectDirective(Sec, OS);
50 return;
51 }
52
53 // Initialized TLS data.
54 if (Sec.getKind().isThreadData()) {
55 // We only expect XMC_TL here for initialized TLS data.
56 if (Sec.getMappingClass() != XCOFF::XMC_TL)
57 report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
58 printCsectDirective(Sec, OS);
59 return;
60 }
61
62 if (Sec.getKind().isData()) {
63 switch (Sec.getMappingClass()) {
64 case XCOFF::XMC_RW:
65 case XCOFF::XMC_DS:
66 case XCOFF::XMC_TD:
67 printCsectDirective(Sec, OS);
68 break;
69 case XCOFF::XMC_TC:
70 case XCOFF::XMC_TE:
71 break;
72 case XCOFF::XMC_TC0:
73 OS << "\t.toc\n";
74 break;
75 default:
76 report_fatal_error("Unhandled storage-mapping class for .data csect.");
77 }
78 return;
79 }
80
81 if (Sec.isCsect() && Sec.getMappingClass() == XCOFF::XMC_TD) {
82 // Common csect type (uninitialized storage) does not have to print
83 // csect directive for section switching unless it is local.
84 if (Sec.getKind().isCommon() && !Sec.getKind().isBSSLocal())
85 return;
86
87 assert(Sec.getKind().isBSS() && "Unexpected section kind for toc-data");
88 printCsectDirective(Sec, OS);
89 return;
90 }
91 // Common csect type (uninitialized storage) does not have to print csect
92 // directive for section switching.
93 if (Sec.isCsect() && Sec.getCSectType() == XCOFF::XTY_CM) {
94 assert((Sec.getMappingClass() == XCOFF::XMC_RW ||
95 Sec.getMappingClass() == XCOFF::XMC_BS ||
96 Sec.getMappingClass() == XCOFF::XMC_UL) &&
97 "Generated a storage-mapping class for a common/bss/tbss csect we "
98 "don't "
99 "understand how to switch to.");
100 // Common symbols and local zero-initialized symbols for TLS and Non-TLS are
101 // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to
102 // cover TLS common and zero-initialized local symbols since linkage type
103 // (in the GlobalVariable) is not accessible in this class.
104 assert((Sec.getKind().isBSSLocal() || Sec.getKind().isCommon() ||
105 Sec.getKind().isThreadBSS()) &&
106 "wrong symbol type for .bss/.tbss csect");
107 // Don't have to print a directive for switching to section for commons
108 // and zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
109 // variable will create the needed csect.
110 return;
111 }
112
113 // Zero-initialized TLS data with weak or external linkage are not eligible to
114 // be put into common csect.
115 if (Sec.getKind().isThreadBSS()) {
116 printCsectDirective(Sec, OS);
117 return;
118 }
119
120 // XCOFF debug sections.
121 if (Sec.getKind().isMetadata() && Sec.isDwarfSect()) {
122 OS << "\n\t.dwsect " << format("0x%" PRIx32, *Sec.getDwarfSubtypeFlags())
123 << '\n';
124 OS << Sec.getName() << ':' << '\n';
125 return;
126 }
127
128 report_fatal_error("Printing for this SectionKind is unimplemented.");
129}
130
132 : MCAsmInfo(Options) {
133 IsAIX = true;
134 IsLittleEndian = false;
135
136 InternalSymbolPrefix = "L..";
137 SupportsQuotedNames = false;
138 if (getMCCLOptions(Options).use_leb128_directives == BoolOrDefault::Default)
139 HasLEB128Directives = false;
140 ZeroDirective = "\t.space\t";
141 AsciiDirective = nullptr; // not supported
142 AscizDirective = nullptr; // not supported
144
145 // Use .vbyte for data definition to avoid directives that apply an implicit
146 // alignment.
147 Data16bitsDirective = "\t.vbyte\t2, ";
148 Data32bitsDirective = "\t.vbyte\t4, ";
149
154
156}
157
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static LVOptions Options
Definition LVOptions.cpp:25
static void printSwitchToSection(const MCAsmInfo &MAI, const MCSection &Section, uint32_t, const Triple &T, raw_ostream &OS)
static void printCsectDirective(const MCSectionXCOFF &Sec, raw_ostream &OS)
#define T
This file contains some functions that are useful when dealing with strings.
MCAsmInfoXCOFF(const MCTargetOptions &Options)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:69
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:169
const char * Data16bitsDirective
Definition MCAsmInfo.h:262
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition MCAsmInfo.h:245
MCAsmInfo(const MCTargetOptions &Options)
Definition MCAsmInfo.cpp:28
const char * Data32bitsDirective
Definition MCAsmInfo.h:263
void printSwitchToSection(const MCSection &Sec, uint32_t Subsection, const Triple &T, raw_ostream &OS) const
Definition MCAsmInfo.h:555
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition MCAsmInfo.h:311
bool HasDotTypeDotSizeDirective
True if the target has .type and .size directives, this is true for most ELF targets.
Definition MCAsmInfo.h:322
bool ParseInlineAsmUsingAsmParser
Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
Definition MCAsmInfo.h:445
bool COMMDirectiveAlignmentIsInBytes
True is .comm's and .lcomms optional alignment is to be specified in bytes instead of log2(n).
Definition MCAsmInfo.h:307
AsmCharLiteralSyntax CharacterLiteralSyntax
Form used for character literals in the assembly syntax.
Definition MCAsmInfo.h:255
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:240
bool SupportsQuotedNames
If this is true, symbol names with invalid characters will be printed in quotes.
Definition MCAsmInfo.h:212
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition MCAsmInfo.h:250
void(* PrintSwitchToSectionFn)(const MCAsmInfo &, const MCSection &, uint32_t Subsection, const Triple &, raw_ostream &)
Definition MCAsmInfo.h:276
bool IsLittleEndian
True if target is little endian. Default is true.
Definition MCAsmInfo.h:95
@ ACLS_SingleQuotePrefix
Unknown; character literals not used by LLVM for this target.
Definition MCAsmInfo.h:75
bool HasLEB128Directives
True if the target supports LEB128 directives.
Definition MCAsmInfo.h:220
LLVM_ABI ~MCSectionXCOFF()
MCSymbolXCOFF * getQualNameSymbol() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:577
Align getAlign() const
Definition MCSection.h:661
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ 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.
const MCCLOptions & getMCCLOptions(const MCTargetOptions &Options)
Definition MCCLOptions.h:19
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:202