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