LLVM  14.0.0git
MCSectionXCOFF.h
Go to the documentation of this file.
1 //===- MCSectionXCOFF.h - XCOFF Machine Code Sections -----------*- 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 //
9 // This file declares the MCSectionXCOFF class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_MC_MCSECTIONXCOFF_H
14 #define LLVM_MC_MCSECTIONXCOFF_H
15 
17 #include "llvm/MC/MCSection.h"
18 #include "llvm/MC/MCSymbolXCOFF.h"
19 
20 namespace llvm {
21 
22 // This class represents an XCOFF `Control Section`, more commonly referred to
23 // as a csect. A csect represents the smallest possible unit of data/code which
24 // will be relocated as a single block. A csect can either be:
25 // 1) Initialized: The Type will be XTY_SD, and the symbols inside the csect
26 // will have a label definition representing their offset within the csect.
27 // 2) Uninitialized: The Type will be XTY_CM, it will contain a single symbol,
28 // and may not contain label definitions.
29 // 3) An external reference providing a symbol table entry for a symbol
30 // contained in another XCOFF object file. External reference csects are not
31 // implemented yet.
32 class MCSectionXCOFF final : public MCSection {
33  friend class MCContext;
34 
36  MCSymbolXCOFF *const QualName;
37  StringRef SymbolTableName;
39  bool MultiSymbolsAllowed;
40  static constexpr unsigned DefaultAlignVal = 4;
41 
44  MCSymbol *Begin, StringRef SymbolTableName,
45  bool MultiSymbolsAllowed)
46  : MCSection(SV_XCOFF, Name, K, Begin),
47  CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
48  SymbolTableName(SymbolTableName), DwarfSubtypeFlags(None),
49  MultiSymbolsAllowed(MultiSymbolsAllowed) {
50  assert(
51  (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
52  "Invalid or unhandled type for csect.");
53  assert(QualName != nullptr && "QualName is needed.");
54  if (SMC == XCOFF::XMC_UL)
55  assert((ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
56  "Invalid csect type for storage mapping class XCOFF::XMC_UL");
57 
58  QualName->setRepresentedCsect(this);
60  // A csect is 4 byte aligned by default, except for undefined symbol csects.
61  if (ST != XCOFF::XTY_ER)
62  setAlignment(Align(DefaultAlignVal));
63  }
64 
66  XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
67  MCSymbol *Begin, StringRef SymbolTableName,
68  bool MultiSymbolsAllowed)
69  : MCSection(SV_XCOFF, Name, K, Begin), QualName(QualName),
70  SymbolTableName(SymbolTableName), DwarfSubtypeFlags(DwarfSubtypeFlags),
71  MultiSymbolsAllowed(MultiSymbolsAllowed) {
72  assert(QualName != nullptr && "QualName is needed.");
73 
74  // FIXME: use a more meaningful name for non csect sections.
75  QualName->setRepresentedCsect(this);
76 
77  // Set default alignment 4 for all non csect sections for now.
78  // FIXME: set different alignments according to section types.
79  setAlignment(Align(DefaultAlignVal));
80  }
81 
82  void printCsectDirective(raw_ostream &OS) const;
83 
84 public:
86 
87  static bool classof(const MCSection *S) {
88  return S->getVariant() == SV_XCOFF;
89  }
90 
92  assert(isCsect() && "Only csect section has mapping class property!");
93  return CsectProp->MappingClass;
94  }
96  return QualName->getStorageClass();
97  }
99  assert(isCsect() && "Only csect section has symbol type property!");
100  return CsectProp->Type;
101  }
102  MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
103 
104  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
105  raw_ostream &OS,
106  const MCExpr *Subsection) const override;
107  bool UseCodeAlign() const override;
108  bool isVirtualSection() const override;
109  StringRef getSymbolTableName() const { return SymbolTableName; }
110  bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
111  bool isCsect() const { return CsectProp.hasValue(); }
112  bool isDwarfSect() const { return DwarfSubtypeFlags.hasValue(); }
114  return DwarfSubtypeFlags;
115  }
116 };
117 
118 } // end namespace llvm
119 
120 #endif
llvm::MCSectionXCOFF::getCSectType
XCOFF::SymbolType getCSectType() const
Definition: MCSectionXCOFF.h:98
llvm::MCSection::Name
StringRef Name
Definition: MCSection.h:111
llvm::XCOFF::XTY_ER
@ XTY_ER
External reference.
Definition: XCOFF.h:184
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCSectionXCOFF
Definition: MCSectionXCOFF.h:32
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
llvm::XCOFF::DwarfSectionSubtypeFlags
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
Definition: XCOFF.h:97
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCSectionXCOFF::classof
static bool classof(const MCSection *S)
Definition: MCSectionXCOFF.h:87
llvm::MCSection::SV_XCOFF
@ SV_XCOFF
Definition: MCSection.h:49
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::SymbolType
SymbolType
Definition: XCOFF.h:183
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::Optional
Definition: APInt.h:33
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::MCSymbolXCOFF::setRepresentedCsect
void setRepresentedCsect(MCSectionXCOFF *C)
Definition: MCSymbolXCOFF.cpp:22
llvm::XCOFF::CsectProperties
Definition: XCOFF.h:412
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:288
XCOFF.h
llvm::MCSectionXCOFF::isMultiSymbolsAllowed
bool isMultiSymbolsAllowed() const
Definition: MCSectionXCOFF.h:110
llvm::MCSectionXCOFF::getStorageClass
XCOFF::StorageClass getStorageClass() const
Definition: MCSectionXCOFF.h:95
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
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::XCOFF::XTY_SD
@ XTY_SD
Csect definition for initialized storage.
Definition: XCOFF.h:185
llvm::MCSymbolXCOFF::getStorageClass
XCOFF::StorageClass getStorageClass() const
Definition: MCSymbolXCOFF.h:41
llvm::None
const NoneType None
Definition: None.h:23
llvm::XCOFF::StorageMappingClass
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:46
llvm::MCSymbolXCOFF::setStorageClass
void setStorageClass(XCOFF::StorageClass SC)
Definition: MCSymbolXCOFF.h:37
llvm::XCOFF::StorageClass
StorageClass
Definition: XCOFF.h:113
llvm::XCOFF::XTY_CM
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition: XCOFF.h:188
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
MCSymbolXCOFF.h
llvm::XCOFF::C_HIDEXT
@ C_HIDEXT
Definition: XCOFF.h:149
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSection.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCSection::setAlignment
void setAlignment(Align Value)
Definition: MCSection.h:139
llvm::MCSectionXCOFF::isDwarfSect
bool isDwarfSect() const
Definition: MCSectionXCOFF.h:112
llvm::MCSectionXCOFF::~MCSectionXCOFF
~MCSectionXCOFF()
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::MCSymbolXCOFF
Definition: MCSymbolXCOFF.h:20
llvm::MCSectionXCOFF::getQualNameSymbol
MCSymbolXCOFF * getQualNameSymbol() const
Definition: MCSectionXCOFF.h:102
llvm::MCSectionXCOFF::getSymbolTableName
StringRef getSymbolTableName() const
Definition: MCSectionXCOFF.h:109
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
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35