LLVM  3.7.0
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/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"
23 
24 namespace llvm {
25 
26 class MCSymbol;
27 
28 /// MCSectionELF - This represents a section on linux, lots of unix variants
29 /// and some bare metal systems.
30 class MCSectionELF : public MCSection {
31  /// SectionName - This is the name of the section. The referenced memory is
32  /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
33  StringRef SectionName;
34 
35  /// Type - This is the sh_type field of a section, drawn from the enums below.
36  unsigned Type;
37 
38  /// Flags - This is the sh_flags field of a section, drawn from the enums.
39  /// below.
40  unsigned Flags;
41 
42  unsigned UniqueID;
43 
44  /// EntrySize - The size of each entry in this section. This size only
45  /// makes sense for sections that contain fixed-sized entries. If a
46  /// section does not contain fixed-sized entries 'EntrySize' will be 0.
47  unsigned EntrySize;
48 
49  const MCSymbolELF *Group;
50 
51  /// Depending on the type of the section this is sh_link or sh_info.
52  const MCSectionELF *Associated;
53 
54 private:
55  friend class MCContext;
56  MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
57  unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
58  MCSymbol *Begin, const MCSectionELF *Associated)
59  : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
60  Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
61  Associated(Associated) {
62  if (Group)
63  Group->setIsSignature();
64  }
65  ~MCSectionELF() override;
66 
67  void setSectionName(StringRef Name) { SectionName = Name; }
68 
69 public:
70 
71  /// ShouldOmitSectionDirective - Decides whether a '.section' directive
72  /// should be printed before the section name
73  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
74 
75  StringRef getSectionName() const { return SectionName; }
76  unsigned getType() const { return Type; }
77  unsigned getFlags() const { return Flags; }
78  unsigned getEntrySize() const { return EntrySize; }
79  const MCSymbolELF *getGroup() const { return Group; }
80 
81  void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
82  const MCExpr *Subsection) const override;
83  bool UseCodeAlign() const override;
84  bool isVirtualSection() const override;
85 
86  bool isUnique() const { return UniqueID != ~0U; }
87  unsigned getUniqueID() const { return UniqueID; }
88 
89  const MCSectionELF *getAssociatedSection() const { return Associated; }
90 
91  static bool classof(const MCSection *S) {
92  return S->getVariant() == SV_ELF;
93  }
94 };
95 
96 } // end namespace llvm
97 
98 #endif
bool isUnique() const
Definition: MCSectionELF.h:86
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
StringRef getSectionName() const
Definition: MCSectionELF.h:75
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
SectionVariant getVariant() const
Definition: MCSection.h:111
unsigned getUniqueID() const
Definition: MCSectionELF.h:87
unsigned getFlags() const
Definition: MCSectionELF.h:77
unsigned getEntrySize() const
Definition: MCSectionELF.h:78
void setIsSignature() const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Context object for machine code objects.
Definition: MCContext.h:48
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:79
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
static bool classof(const MCSection *S)
Definition: MCSectionELF.h:91
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
const MCSectionELF * getAssociatedSection() const
Definition: MCSectionELF.h:89
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
ShouldOmitSectionDirective - Decides whether a '.section' directive should be printed before the sect...
void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const override
MCSectionELF - This represents a section on linux, lots of unix variants and some bare metal systems...
Definition: MCSectionELF.h:30
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
unsigned getType() const
Definition: MCSectionELF.h:76
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40