MCSectionELF.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. class MCSymbol;
  26. /// This represents a section on linux, lots of unix variants and some bare
  27. /// metal systems.
  28. class MCSectionELF final : public MCSection {
  29. /// This is the sh_type field of a section, drawn from the enums below.
  30. unsigned Type;
  31. /// This is the sh_flags field of a section, drawn from the enums below.
  32. unsigned Flags;
  33. unsigned UniqueID;
  34. /// The size of each entry in this section. This size only makes sense for
  35. /// sections that contain fixed-sized entries. If a section does not contain
  36. /// fixed-sized entries 'EntrySize' will be 0.
  37. unsigned EntrySize;
  38. /// The section group signature symbol (if not null) and a bool indicating
  39. /// whether this is a GRP_COMDAT group.
  40. const PointerIntPair<const MCSymbolELF *, 1, bool> Group;
  41. /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
  42. /// section header index of the section where LinkedToSym is defined.
  43. const MCSymbol *LinkedToSym;
  44. private:
  45. friend class MCContext;
  46. // The storage of Name is owned by MCContext's ELFUniquingMap.
  47. MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
  48. unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
  49. unsigned UniqueID, MCSymbol *Begin,
  50. const MCSymbolELF *LinkedToSym)
  51. : MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
  52. UniqueID(UniqueID), EntrySize(entrySize), Group(group, IsComdat),
  53. LinkedToSym(LinkedToSym) {
  54. if (Group.getPointer())
  55. Group.getPointer()->setIsSignature();
  56. }
  57. // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
  58. // sections.
  59. void setSectionName(StringRef Name) { this->Name = Name; }
  60. public:
  61. /// Decides whether a '.section' directive should be printed before the
  62. /// section name
  63. bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
  64. unsigned getType() const { return Type; }
  65. unsigned getFlags() const { return Flags; }
  66. unsigned getEntrySize() const { return EntrySize; }
  67. void setFlags(unsigned F) { Flags = F; }
  68. const MCSymbolELF *getGroup() const { return Group.getPointer(); }
  69. bool isComdat() const { return Group.getInt(); }
  70. void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
  71. raw_ostream &OS,
  72. const MCExpr *Subsection) const override;
  73. bool UseCodeAlign() const override;
  74. bool isVirtualSection() const override;
  75. StringRef getVirtualSectionKind() const override;
  76. bool isUnique() const { return UniqueID != NonUniqueID; }
  77. unsigned getUniqueID() const { return UniqueID; }
  78. const MCSection *getLinkedToSection() const {
  79. return &LinkedToSym->getSection();
  80. }
  81. const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
  82. static bool classof(const MCSection *S) {
  83. return S->getVariant() == SV_ELF;
  84. }
  85. };
  86. } // end namespace llvm
  87. #endif // LLVM_MC_MCSECTIONELF_H
  88. #ifdef __GNUC__
  89. #pragma GCC diagnostic pop
  90. #endif