LLVM  14.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/MC/MCExpr.h"
12 #include "llvm/Support/Debug.h"
13 #include "llvm/Support/Format.h"
15 
16 using namespace llvm;
17 
19 
20 void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const {
21  OS << "\t.csect " << QualName->getName() << "," << Log2_32(getAlignment())
22  << '\n';
23 }
24 
26  raw_ostream &OS,
27  const MCExpr *Subsection) const {
28  if (getKind().isText()) {
30  report_fatal_error("Unhandled storage-mapping class for .text csect");
31 
32  printCsectDirective(OS);
33  return;
34  }
35 
36  if (getKind().isReadOnly()) {
38  report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
39  printCsectDirective(OS);
40  return;
41  }
42 
43  // Initialized TLS data.
44  if (getKind().isThreadData()) {
45  // We only expect XMC_TL here for initialized TLS data.
47  report_fatal_error("Unhandled storage-mapping class for .tdata csect.");
48  printCsectDirective(OS);
49  return;
50  }
51 
52  if (getKind().isData()) {
53  switch (getMappingClass()) {
54  case XCOFF::XMC_RW:
55  case XCOFF::XMC_DS:
56  case XCOFF::XMC_TD:
57  printCsectDirective(OS);
58  break;
59  case XCOFF::XMC_TC:
60  case XCOFF::XMC_TE:
61  break;
62  case XCOFF::XMC_TC0:
63  OS << "\t.toc\n";
64  break;
65  default:
67  "Unhandled storage-mapping class for .data csect.");
68  }
69  return;
70  }
71 
72  if (isCsect() && getMappingClass() == XCOFF::XMC_TD) {
73  assert((getKind().isBSSExtern() || getKind().isBSSLocal()) &&
74  "Unexepected section kind for toc-data");
75  printCsectDirective(OS);
76  return;
77  }
78  // Common csect type (uninitialized storage) does not have to print csect
79  // directive for section switching.
80  if (isCsect() && getCSectType() == XCOFF::XTY_CM) {
84  "Generated a storage-mapping class for a common/bss/tbss csect we "
85  "don't "
86  "understand how to switch to.");
87  // Common symbols and local zero-initialized symbols for TLS and Non-TLS are
88  // eligible for .bss/.tbss csect, getKind().isThreadBSS() is used to cover
89  // TLS common and zero-initialized local symbols since linkage type (in the
90  // GlobalVariable) is not accessible in this class.
91  assert((getKind().isBSSLocal() || getKind().isCommon() ||
92  getKind().isThreadBSS()) &&
93  "wrong symbol type for .bss/.tbss csect");
94  // Don't have to print a directive for switching to section for commons and
95  // zero-initialized TLS data. The '.comm' and '.lcomm' directives of the
96  // variable will create the needed csect.
97  return;
98  }
99 
100  // Zero-initialized TLS data with weak or external linkage are not eligible to
101  // be put into common csect.
102  if (getKind().isThreadBSS()) {
103  printCsectDirective(OS);
104  return;
105  }
106 
107  // XCOFF debug sections.
108  if (getKind().isMetadata() && isDwarfSect()) {
109  OS << "\n\t.dwsect "
110  << format("0x%" PRIx32, getDwarfSubtypeFlags().getValue()) << '\n';
111  OS << MAI.getPrivateLabelPrefix() << getName() << ':' << '\n';
112  return;
113  }
114 
115  report_fatal_error("Printing for this SectionKind is unimplemented.");
116 }
117 
118 bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); }
119 
121  assert(isCsect() && "Only csect section can be virtual!");
122  return XCOFF::XTY_CM == CsectProp->Type;
123 }
llvm::SectionKind::isText
bool isText() const
Definition: SectionKind.h:121
llvm::MCSectionXCOFF::getCSectType
XCOFF::SymbolType getCSectType() const
Definition: MCSectionXCOFF.h:98
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
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:118
T
llvm::XCOFF::XMC_TD
@ XMC_TD
Scalar data item in the TOC.
Definition: XCOFF.h:63
llvm::XCOFF::XMC_TE
@ XMC_TE
Symbol mapped at the end of TOC.
Definition: XCOFF.h:71
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:48
llvm::MCSectionXCOFF::isVirtualSection
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSectionXCOFF.cpp:120
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::MCSectionXCOFF::isCsect
bool isCsect() const
Definition: MCSectionXCOFF.h:111
llvm::MCSectionXCOFF::PrintSwitchToSection
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionXCOFF.cpp:25
llvm::XCOFF::XMC_TC
@ XMC_TC
General TOC item.
Definition: XCOFF.h:62
Format.h
llvm::XCOFF::XMC_RO
@ XMC_RO
Read Only Constant.
Definition: XCOFF.h:49
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:596
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:140
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: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:188
llvm::XCOFF::XMC_TL
@ XMC_TL
Initialized thread-local variable.
Definition: XCOFF.h:69
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCAsmInfo.h
llvm::MCSection::getAlignment
unsigned getAlignment() const
Definition: MCSection.h:138
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:122
llvm::MCSectionXCOFF::isDwarfSect
bool isDwarfSect() const
Definition: MCSectionXCOFF.h:112
llvm::MCSectionXCOFF::~MCSectionXCOFF
~MCSectionXCOFF()
llvm::MCAsmInfo::getPrivateLabelPrefix
StringRef getPrivateLabelPrefix() const
Definition: MCAsmInfo.h:655
llvm::XCOFF::XMC_TC0
@ XMC_TC0
TOC Anchor for TOC Addressability.
Definition: XCOFF.h:61
llvm::XCOFF::XMC_DS
@ XMC_DS
Descriptor csect.
Definition: XCOFF.h:64
llvm::MCSection::getKind
SectionKind getKind() const
Definition: MCSection.h:123
llvm::XCOFF::XMC_RW
@ XMC_RW
Read Write Data.
Definition: XCOFF.h:60
raw_ostream.h
llvm::MCSectionXCOFF::getDwarfSubtypeFlags
Optional< XCOFF::DwarfSectionSubtypeFlags > getDwarfSubtypeFlags() const
Definition: MCSectionXCOFF.h:113
llvm::XCOFF::XMC_UL
@ XMC_UL
Uninitialized thread-local variable.
Definition: XCOFF.h:70
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Debug.h
llvm::XCOFF::XMC_BS
@ XMC_BS
BSS class (uninitialized static internal)
Definition: XCOFF.h:66