MCSectionELF.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the MCSectionELF class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCSECTIONELF_H
  18. #define LLVM_MC_MCSECTIONELF_H
  19. #include "llvm/ADT/PointerIntPair.h"
  20. #include "llvm/ADT/StringRef.h"
  21. #include "llvm/MC/MCSection.h"
  22. #include "llvm/MC/MCSymbolELF.h"
  23. #include "llvm/MC/SectionKind.h"
  24. namespace llvm {
  25. /// This represents a section on linux, lots of unix variants and some bare
  26. /// metal systems.
  27. class MCSectionELF final : public MCSection {
  28. /// This is the sh_type field of a section, drawn from the enums below.
  29. unsigned Type;
  30. /// This is the sh_flags field of a section, drawn from the enums below.
  31. unsigned Flags;
  32. unsigned UniqueID;
  33. /// The size of each entry in this section. This size only makes sense for
  34. /// sections that contain fixed-sized entries. If a section does not contain
  35. /// fixed-sized entries 'EntrySize' will be 0.
  36. unsigned EntrySize;
  37. /// The section group signature symbol (if not null) and a bool indicating
  38. /// whether this is a GRP_COMDAT group.
  39. const PointerIntPair<const MCSymbolELF *, 1, bool> Group;
  40. /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
  41. /// section header index of the section where LinkedToSym is defined.
  42. const MCSymbol *LinkedToSym;
  43. private:
  44. friend class MCContext;
  45. // The storage of Name is owned by MCContext's ELFUniquingMap.
  46. MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
  47. unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
  48. unsigned UniqueID, MCSymbol *Begin,
  49. const MCSymbolELF *LinkedToSym)
  50. : MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
  51. UniqueID(UniqueID), EntrySize(entrySize), Group(group, IsComdat),
  52. LinkedToSym(LinkedToSym) {
  53. if (Group.getPointer())
  54. Group.getPointer()->setIsSignature();
  55. }
  56. // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
  57. // sections.
  58. void setSectionName(StringRef Name) { this->Name = Name; }
  59. public:
  60. /// Decides whether a '.section' directive should be printed before the
  61. /// section name
  62. bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
  63. unsigned getType() const { return Type; }
  64. unsigned getFlags() const { return Flags; }
  65. unsigned getEntrySize() const { return EntrySize; }
  66. void setFlags(unsigned F) { Flags = F; }
  67. const MCSymbolELF *getGroup() const { return Group.getPointer(); }
  68. bool isComdat() const { return Group.getInt(); }
  69. void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
  70. raw_ostream &OS,
  71. const MCExpr *Subsection) const override;
  72. bool useCodeAlign() const override;
  73. bool isVirtualSection() const override;
  74. StringRef getVirtualSectionKind() const override;
  75. bool isUnique() const { return UniqueID != NonUniqueID; }
  76. unsigned getUniqueID() const { return UniqueID; }
  77. const MCSection *getLinkedToSection() const {
  78. return &LinkedToSym->getSection();
  79. }
  80. const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
  81. static bool classof(const MCSection *S) {
  82. return S->getVariant() == SV_ELF;
  83. }
  84. };
  85. } // end namespace llvm
  86. #endif // LLVM_MC_MCSECTIONELF_H
  87. #ifdef __GNUC__
  88. #pragma GCC diagnostic pop
  89. #endif