LLVM  15.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_32(getAlignment())
24  << '\n';
25 }
26 
28  raw_ostream &OS,
29  const MCExpr *Subsection) const {
30  if (getKind().isText()) {
32  report_fatal_error("Unhandled storage-mapping class for .text csect");
33 
34  printCsectDirective(OS);
35  return;
36  }
37 
38  if (getKind().isReadOnly()) {
39  if (getMappingClass() != XCOFF::XMC_RO &&
41  report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
42  printCsectDirective(OS);
43  return;
44  }
45 
46  // Initialized TLS data.
47  if (getKind().isThreadData()) {
48  // We only expect XMC_TL here for initialized TLS data.
50  report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
51  printCsectDirective(OS);
52  return;
53  }
54 
55  if (getKind().isData()) {
56  switch (getMappingClass()) {
57  case XCOFF::XMC_RW:
58  case XCOFF::XMC_DS:
59  case XCOFF::XMC_TD:
60  printCsectDirective(OS);
61  break;
62  case XCOFF::XMC_TC:
63  case XCOFF::XMC_TE:
64  break;
65  case XCOFF::XMC_TC0:
66  OS << "\t.toc\n";
67  break;
68  default:
70  "Unhandled storage-mapping class for .data csect.");
71  }
72  return;
73  }
74 
75  if (isCsect() && getMappingClass() == XCOFF::XMC_TD) {
76  assert((getKind().isBSSExtern() || getKind().isBSSLocal() ||
77  getKind().isReadOnlyWithRel()) &&
78  "Unexepected section kind for toc-data");
79  printCsectDirective(OS);
80  return;
81  }
82  // Common csect type (uninitialized storage) does not have to print csect
83  // directive for section switching.
84  if (isCsect() && getCSectType() == XCOFF::XTY_CM) {
88  "Generated a storage-mapping class for a common/bss/tbss csect we "
89  "don't "
90  "understand how to switch to.");
91  // Common symbols and local zero-initialized symbols for TLS and Non-TLS are
92  // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to cover
93  // TLS common and zero-initialized local symbols since linkage type (in the
94  // GlobalVariable) is not accessible in this class.
95  assert((getKind().isBSSLocal() || getKind().isCommon() ||
96  getKind().isThreadBSS()) &&
97  "wrong symbol type for .bss/.tbss csect");
98  // Don't have to print a directive for switching to section for commons and
99  // zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
100  // variable will create the needed csect.
101  return;
102  }
103 
104  // Zero-initialized TLS data with weak or external linkage are not eligible to
105  // be put into common csect.
106  if (getKind().isThreadBSS()) {
107  printCsectDirective(OS);
108  return;
109  }
110 
111  // XCOFF debug sections.
112  if (getKind().isMetadata() && isDwarfSect()) {
113  OS << "\n\t.dwsect "
114  << format("0x%" PRIx32, getDwarfSubtypeFlags().getValue()) << '\n';
115  OS << MAI.getPrivateLabelPrefix() << getName() << ':' << '\n';
116  return;
117  }
118 
119  report_fatal_error("Printing for this SectionKind is unimplemented.");
120 }
121 
122 bool MCSectionXCOFF::useCodeAlign() const { return getKind().isText(); }
123 
125  // DWARF sections are always not virtual.
126  if (isDwarfSect())
127  return false;
128  assert(isCsect() &&
129  "Handling for isVirtualSection not implemented for this section!");
130  return XCOFF::XTY_CM == CsectProp->Type;
131 }
llvm::SectionKind::isText
bool isText() const
Definition: SectionKind.h:127
llvm::MCSectionXCOFF::getCSectType
XCOFF::SymbolType getCSectType() const
Definition: MCSectionXCOFF.h:101
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
T
llvm::XCOFF::XMC_TD
@ XMC_TD
Scalar data item in the TOC.
Definition: XCOFF.h:104
llvm::XCOFF::XMC_TE
@ XMC_TE
Symbol mapped at the end of TOC.
Definition: XCOFF.h:112
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:89
llvm::MCSectionXCOFF::isVirtualSection
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSectionXCOFF.cpp:124
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::MCSectionXCOFF::isCsect
bool isCsect() const
Definition: MCSectionXCOFF.h:114
llvm::XCOFF::XMC_TC
@ XMC_TC
General TOC item.
Definition: XCOFF.h:103
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:122
llvm::XCOFF::XMC_RO
@ XMC_RO
Read Only Constant.
Definition: XCOFF.h:90
llvm::Log2_32
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:623
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:143
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::MCSectionXCOFF::getMappingClass
XCOFF::StorageMappingClass getMappingClass() const
Definition: MCSectionXCOFF.h:91
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:229
llvm::XCOFF::XMC_TL
@ XMC_TL
Initialized thread-local variable.
Definition: XCOFF.h:110
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCAsmInfo.h
llvm::MCSection::getAlignment
unsigned getAlignment() const
Definition: MCSection.h:139
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:123
llvm::MCSectionXCOFF::isDwarfSect
bool isDwarfSect() const
Definition: MCSectionXCOFF.h:115
llvm::MCSectionXCOFF::~MCSectionXCOFF
~MCSectionXCOFF()
llvm::MCAsmInfo::getPrivateLabelPrefix
StringRef getPrivateLabelPrefix() const
Definition: MCAsmInfo.h:667
llvm::XCOFF::XMC_TC0
@ XMC_TC0
TOC Anchor for TOC Addressability.
Definition: XCOFF.h:102
llvm::XCOFF::XMC_DS
@ XMC_DS
Descriptor csect.
Definition: XCOFF.h:105
llvm::MCSection::getKind
SectionKind getKind() const
Definition: MCSection.h:124
llvm::XCOFF::XMC_RW
@ XMC_RW
Read Write Data.
Definition: XCOFF.h:101
raw_ostream.h
llvm::MCSectionXCOFF::getDwarfSubtypeFlags
Optional< XCOFF::DwarfSectionSubtypeFlags > getDwarfSubtypeFlags() const
Definition: MCSectionXCOFF.h:116
llvm::XCOFF::XMC_UL
@ XMC_UL
Uninitialized thread-local variable.
Definition: XCOFF.h:111
llvm::MCSectionXCOFF::printSwitchToSection
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionXCOFF.cpp:27
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:107