MCSectionELF.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef LLVM_MC_MCSECTIONELF_H
  14. #define LLVM_MC_MCSECTIONELF_H
  15. #include "llvm/ADT/Twine.h"
  16. #include "llvm/MC/MCSection.h"
  17. #include "llvm/MC/MCSymbolELF.h"
  18. #include "llvm/Support/Debug.h"
  19. #include "llvm/Support/ELF.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. namespace llvm {
  22. class MCSymbol;
  23. /// MCSectionELF - This represents a section on linux, lots of unix variants
  24. /// and some bare metal systems.
  25. class MCSectionELF : public MCSection {
  26. /// SectionName - This is the name of the section. The referenced memory is
  27. /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
  28. StringRef SectionName;
  29. /// Type - This is the sh_type field of a section, drawn from the enums below.
  30. unsigned Type;
  31. /// Flags - This is the sh_flags field of a section, drawn from the enums.
  32. /// below.
  33. unsigned Flags;
  34. unsigned UniqueID;
  35. /// EntrySize - The size of each entry in this section. This size only
  36. /// makes sense for sections that contain fixed-sized entries. If a
  37. /// section does not contain fixed-sized entries 'EntrySize' will be 0.
  38. unsigned EntrySize;
  39. const MCSymbolELF *Group;
  40. /// Depending on the type of the section this is sh_link or sh_info.
  41. const MCSectionELF *Associated;
  42. private:
  43. friend class MCContext;
  44. MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
  45. unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
  46. MCSymbol *Begin, const MCSectionELF *Associated)
  47. : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
  48. Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
  49. Associated(Associated) {
  50. if (Group)
  51. Group->setIsSignature();
  52. }
  53. ~MCSectionELF() override;
  54. void setSectionName(StringRef Name) { SectionName = Name; }
  55. public:
  56. /// ShouldOmitSectionDirective - Decides whether a '.section' directive
  57. /// should be printed before the section name
  58. bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
  59. StringRef getSectionName() const { return SectionName; }
  60. unsigned getType() const { return Type; }
  61. unsigned getFlags() const { return Flags; }
  62. unsigned getEntrySize() const { return EntrySize; }
  63. const MCSymbolELF *getGroup() const { return Group; }
  64. void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
  65. const MCExpr *Subsection) const override;
  66. bool UseCodeAlign() const override;
  67. bool isVirtualSection() const override;
  68. bool isUnique() const { return UniqueID != ~0U; }
  69. unsigned getUniqueID() const { return UniqueID; }
  70. const MCSectionELF *getAssociatedSection() const { return Associated; }
  71. static bool classof(const MCSection *S) {
  72. return S->getVariant() == SV_ELF;
  73. }
  74. };
  75. } // end namespace llvm
  76. #endif