1//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the MCSectionELF class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MC_MCSECTIONELF_H
15#define LLVM_MC_MCSECTIONELF_H
16
17#include "llvm/ADT/Twine.h"
18#include "llvm/MC/MCSection.h"
19#include "llvm/MC/MCSymbolELF.h"
20#include "llvm/Support/Debug.h"
21#include "llvm/Support/ELF.h"
22#include "llvm/Support/raw_ostream.h"
23
24namespace llvm {
25
26class MCSymbol;
27
28/// This represents a section on linux, lots of unix variants and some bare
29/// metal systems.
30class MCSectionELF final : public MCSection {
31  /// This is the name of the section.  The referenced memory is owned by
32  /// TargetLoweringObjectFileELF's ELFUniqueMap.
33  StringRef SectionName;
34
35  /// This is the sh_type field of a section, drawn from the enums below.
36  unsigned Type;
37
38  /// This is the sh_flags field of a section, drawn from the enums below.
39  unsigned Flags;
40
41  unsigned UniqueID;
42
43  /// The size of each entry in this section. This size only makes sense for
44  /// sections that contain fixed-sized entries. If a section does not contain
45  /// fixed-sized entries 'EntrySize' will be 0.
46  unsigned EntrySize;
47
48  const MCSymbolELF *Group;
49
50  /// Depending on the type of the section this is sh_link or sh_info.
51  const MCSectionELF *Associated;
52
53private:
54  friend class MCContext;
55  MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
56               unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
57               MCSymbol *Begin, const MCSectionELF *Associated)
58      : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
59        Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
60        Associated(Associated) {
61    if (Group)
62      Group->setIsSignature();
63  }
64
65  void setSectionName(StringRef Name) { SectionName = Name; }
66
67public:
68  ~MCSectionELF();
69
70  /// Decides whether a '.section' directive should be printed before the
71  /// section name
72  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
73
74  StringRef getSectionName() const { return SectionName; }
75  unsigned getType() const { return Type; }
76  unsigned getFlags() const { return Flags; }
77  unsigned getEntrySize() const { return EntrySize; }
78  const MCSymbolELF *getGroup() const { return Group; }
79
80  void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
81                            const MCExpr *Subsection) const override;
82  bool UseCodeAlign() const override;
83  bool isVirtualSection() const override;
84
85  bool isUnique() const { return UniqueID != ~0U; }
86  unsigned getUniqueID() const { return UniqueID; }
87
88  const MCSectionELF *getAssociatedSection() const { return Associated; }
89
90  static bool classof(const MCSection *S) {
91    return S->getVariant() == SV_ELF;
92  }
93};
94
95} // end namespace llvm
96
97#endif
98