LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCSectionELF.h
Go to the documentation of this file.
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/StringRef.h"
18 #include "llvm/MC/MCSection.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/ELF.h"
22 
23 namespace llvm {
24 
25 class MCSymbol;
26 
27 /// MCSectionELF - This represents a section on linux, lots of unix variants
28 /// and some bare metal systems.
29 class MCSectionELF : public MCSection {
30  /// SectionName - This is the name of the section. The referenced memory is
31  /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
32  StringRef SectionName;
33 
34  /// Type - This is the sh_type field of a section, drawn from the enums below.
35  unsigned Type;
36 
37  /// Flags - This is the sh_flags field of a section, drawn from the enums.
38  /// below.
39  unsigned Flags;
40 
41  /// EntrySize - The size of each entry in this section. This size only
42  /// makes sense for sections that contain fixed-sized entries. If a
43  /// section does not contain fixed-sized entries 'EntrySize' will be 0.
44  unsigned EntrySize;
45 
46  const MCSymbol *Group;
47 
48 private:
49  friend class MCContext;
50  MCSectionELF(StringRef Section, unsigned type, unsigned flags,
51  SectionKind K, unsigned entrySize, const MCSymbol *group)
52  : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
53  EntrySize(entrySize), Group(group) {}
54  ~MCSectionELF();
55 public:
56 
57  /// ShouldOmitSectionDirective - Decides whether a '.section' directive
58  /// should be printed before the section name
59  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
60 
61  StringRef getSectionName() const { return SectionName; }
62  virtual std::string getLabelBeginName() const {
63  return SectionName.str() + "_begin"; }
64  virtual std::string getLabelEndName() const {
65  return SectionName.str() + "_end";
66  }
67  unsigned getType() const { return Type; }
68  unsigned getFlags() const { return Flags; }
69  unsigned getEntrySize() const { return EntrySize; }
70  const MCSymbol *getGroup() const { return Group; }
71 
72  void PrintSwitchToSection(const MCAsmInfo &MAI,
73  raw_ostream &OS,
74  const MCExpr *Subsection) const;
75  virtual bool UseCodeAlign() const;
76  virtual bool isVirtualSection() const;
77 
78  /// isBaseAddressKnownZero - We know that non-allocatable sections (like
79  /// debug info) have a base of zero.
80  virtual bool isBaseAddressKnownZero() const {
81  return (getFlags() & ELF::SHF_ALLOC) == 0;
82  }
83 
84  static bool classof(const MCSection *S) {
85  return S->getVariant() == SV_ELF;
86  }
87 
88  // Return the entry size for sections with fixed-width data.
89  static unsigned DetermineEntrySize(SectionKind Kind);
90 
91 };
92 
93 } // end namespace llvm
94 
95 #endif
COFF::RelocationTypeX86 Type
Definition: COFFYAML.cpp:227
StringRef getSectionName() const
Definition: MCSectionELF.h:61
SectionVariant getVariant() const
Definition: MCSection.h:49
virtual bool UseCodeAlign() const
const MCSymbol * getGroup() const
Definition: MCSectionELF.h:70
unsigned getFlags() const
Definition: MCSectionELF.h:68
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:181
unsigned getEntrySize() const
Definition: MCSectionELF.h:69
virtual bool isVirtualSection() const
virtual std::string getLabelBeginName() const
Definition: MCSectionELF.h:62
static bool classof(const MCSection *S)
Definition: MCSectionELF.h:84
virtual bool isBaseAddressKnownZero() const
Definition: MCSectionELF.h:80
virtual std::string getLabelEndName() const
Definition: MCSectionELF.h:64
void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
unsigned getType() const
Definition: MCSectionELF.h:67
SectionKind Kind
Definition: MCSection.h:43
static unsigned DetermineEntrySize(SectionKind Kind)