Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/llvm/include/llvm/MC/MCSectionXCOFF.h
Line
Count
Source (jump to first uncovered line)
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
16
#include "llvm/BinaryFormat/XCOFF.h"
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
35
  std::optional<XCOFF::CsectProperties> CsectProp;
36
  MCSymbolXCOFF *const QualName;
37
  StringRef SymbolTableName;
38
  std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
39
  bool MultiSymbolsAllowed;
40
  static constexpr unsigned DefaultAlignVal = 4;
41
  static constexpr unsigned DefaultTextAlignVal = 32;
42
43
  MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
44
                 XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
45
                 MCSymbol *Begin, StringRef SymbolTableName,
46
                 bool MultiSymbolsAllowed)
47
      : MCSection(SV_XCOFF, Name, K, Begin),
48
        CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
49
        SymbolTableName(SymbolTableName), DwarfSubtypeFlags(std::nullopt),
50
0
        MultiSymbolsAllowed(MultiSymbolsAllowed) {
51
0
    assert(
52
0
        (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
53
0
        "Invalid or unhandled type for csect.");
54
0
    assert(QualName != nullptr && "QualName is needed.");
55
0
    if (SMC == XCOFF::XMC_UL)
56
0
      assert((ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
57
0
             "Invalid csect type for storage mapping class XCOFF::XMC_UL");
58
59
0
    QualName->setRepresentedCsect(this);
60
0
    QualName->setStorageClass(XCOFF::C_HIDEXT);
61
0
    if (ST != XCOFF::XTY_ER) {
62
      // For a csect for program code, set the alignment to 32 bytes by default.
63
      // For other csects, set the alignment to 4 bytes by default.
64
0
      if (SMC == XCOFF::XMC_PR)
65
0
        setAlignment(Align(DefaultTextAlignVal));
66
0
      else
67
0
        setAlignment(Align(DefaultAlignVal));
68
0
    }
69
0
  }
70
71
  MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
72
                 XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
73
                 MCSymbol *Begin, StringRef SymbolTableName,
74
                 bool MultiSymbolsAllowed)
75
      : MCSection(SV_XCOFF, Name, K, Begin), QualName(QualName),
76
        SymbolTableName(SymbolTableName), DwarfSubtypeFlags(DwarfSubtypeFlags),
77
0
        MultiSymbolsAllowed(MultiSymbolsAllowed) {
78
0
    assert(QualName != nullptr && "QualName is needed.");
79
80
    // FIXME: use a more meaningful name for non csect sections.
81
0
    QualName->setRepresentedCsect(this);
82
83
    // Use default text alignment as the alignment for DWARF sections.
84
0
    setAlignment(Align(DefaultTextAlignVal));
85
0
  }
86
87
  void printCsectDirective(raw_ostream &OS) const;
88
89
public:
90
  ~MCSectionXCOFF();
91
92
0
  static bool classof(const MCSection *S) {
93
0
    return S->getVariant() == SV_XCOFF;
94
0
  }
95
96
0
  XCOFF::StorageMappingClass getMappingClass() const {
97
0
    assert(isCsect() && "Only csect section has mapping class property!");
98
0
    return CsectProp->MappingClass;
99
0
  }
100
0
  XCOFF::StorageClass getStorageClass() const {
101
0
    return QualName->getStorageClass();
102
0
  }
103
0
  XCOFF::VisibilityType getVisibilityType() const {
104
0
    return QualName->getVisibilityType();
105
0
  }
106
0
  XCOFF::SymbolType getCSectType() const {
107
0
    assert(isCsect() && "Only csect section has symbol type property!");
108
0
    return CsectProp->Type;
109
0
  }
110
0
  MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
111
112
  void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
113
                            raw_ostream &OS,
114
                            const MCExpr *Subsection) const override;
115
  bool useCodeAlign() const override;
116
  bool isVirtualSection() const override;
117
0
  StringRef getSymbolTableName() const { return SymbolTableName; }
118
0
  void setSymbolTableName(StringRef STN) { SymbolTableName = STN; }
119
0
  bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
120
0
  bool isCsect() const { return CsectProp.has_value(); }
121
0
  bool isDwarfSect() const { return DwarfSubtypeFlags.has_value(); }
122
0
  std::optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
123
0
    return DwarfSubtypeFlags;
124
0
  }
125
0
  std::optional<XCOFF::CsectProperties> getCsectProp() const {
126
0
    return CsectProp;
127
0
  }
128
};
129
130
} // end namespace llvm
131
132
#endif