1b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
2b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//
3b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//                     The LLVM Compiler Infrastructure
4b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//
5b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes// This file is distributed under the University of Illinois Open Source
6b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes// License. See LICENSE.TXT for details.
7b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//
8b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//===----------------------------------------------------------------------===//
9b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//
10b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes// This file declares the MCSectionELF class.
11b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//
12b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes//===----------------------------------------------------------------------===//
13b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
14b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes#ifndef LLVM_MC_MCSECTIONELF_H
15b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes#define LLVM_MC_MCSECTIONELF_H
16b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
17dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines#include "llvm/ADT/Twine.h"
18b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes#include "llvm/MC/MCSection.h"
196948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar#include "llvm/MC/MCSymbolELF.h"
2058a2cbef4aac9ee7d530dfb690c78d6fc11a2371Chandler Carruth#include "llvm/Support/Debug.h"
211c13026e8f94bd332c0979baa9c777da99d48736Rafael Espindola#include "llvm/Support/ELF.h"
22b1cc6f3dff96bfb26e0f5b62a187374b6a7629a1Eric Christopher#include "llvm/Support/raw_ostream.h"
23b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
24b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopesnamespace llvm {
254778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
262ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindolaclass MCSymbol;
272ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola
28cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar/// This represents a section on linux, lots of unix variants and some bare
29cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar/// metal systems.
30cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainarclass MCSectionELF final : public MCSection {
31cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// This is the name of the section.  The referenced memory is owned by
32cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// TargetLoweringObjectFileELF's ELFUniqueMap.
331f8008cf214b984954de2e986fb8cb0e5cc58606Chris Lattner  StringRef SectionName;
344778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
35cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// This is the sh_type field of a section, drawn from the enums below.
36b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned Type;
374778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
38cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// This is the sh_flags field of a section, drawn from the enums below.
39b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned Flags;
40b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
410c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  unsigned UniqueID;
42ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
43cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// The size of each entry in this section. This size only makes sense for
44cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// sections that contain fixed-sized entries. If a section does not contain
45cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// fixed-sized entries 'EntrySize' will be 0.
463e09669bc44aeb053e58ae8245ad0e49570b0e21Matt Fleming  unsigned EntrySize;
474778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
486948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  const MCSymbolELF *Group;
492ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola
500c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  /// Depending on the type of the section this is sh_link or sh_info.
510c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  const MCSectionELF *Associated;
520c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar
5374aae4726a66733c5872588287535a984f9a94c7Chris Lattnerprivate:
5474aae4726a66733c5872588287535a984f9a94c7Chris Lattner  friend class MCContext;
55ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
566948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar               unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
570c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar               MCSymbol *Begin, const MCSectionELF *Associated)
584c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar      : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
590c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar        Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
606948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar        Associated(Associated) {
616948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    if (Group)
626948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar      Group->setIsSignature();
636948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  }
64dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
65dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  void setSectionName(StringRef Name) { SectionName = Name; }
66dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
67b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopespublic:
68cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  ~MCSectionELF();
69b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
70cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// Decides whether a '.section' directive should be printed before the
71cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  /// section name
72a46918d2b1b63aa3db94aa10b9ea70209b84e274Benjamin Kramer  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
73b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
741f8008cf214b984954de2e986fb8cb0e5cc58606Chris Lattner  StringRef getSectionName() const { return SectionName; }
75b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned getType() const { return Type; }
76b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned getFlags() const { return Flags; }
776b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming  unsigned getEntrySize() const { return EntrySize; }
786948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  const MCSymbolELF *getGroup() const { return Group; }
794778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
8036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
8136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                            const MCExpr *Subsection) const override;
8236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool UseCodeAlign() const override;
8336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isVirtualSection() const override;
84083cf1574facc9ce468fba1735c794bd7e520108Jan Wen Voung
850c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  bool isUnique() const { return UniqueID != ~0U; }
860c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  unsigned getUniqueID() const { return UniqueID; }
870c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar
880c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  const MCSectionELF *getAssociatedSection() const { return Associated; }
890c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar
909a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar  static bool classof(const MCSection *S) {
919a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar    return S->getVariant() == SV_ELF;
929a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar  }
93b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes};
94b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
95b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes} // end namespace llvm
96b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
97b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes#endif
98