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
17b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes#include "llvm/MC/MCSection.h"
181c13026e8f94bd332c0979baa9c777da99d48736Rafael Espindola#include "llvm/Support/ELF.h"
19f1d0f7781e766df878bec4e7977fa3204374f394Craig Topper#include "llvm/ADT/StringRef.h"
20b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
21b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopesnamespace llvm {
224778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
232ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindolaclass MCSymbol;
242ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola
25b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes/// MCSectionELF - This represents a section on linux, lots of unix variants
26b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes/// and some bare metal systems.
27b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopesclass MCSectionELF : public MCSection {
281f8008cf214b984954de2e986fb8cb0e5cc58606Chris Lattner  /// SectionName - This is the name of the section.  The referenced memory is
291f8008cf214b984954de2e986fb8cb0e5cc58606Chris Lattner  /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
301f8008cf214b984954de2e986fb8cb0e5cc58606Chris Lattner  StringRef SectionName;
314778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
32b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  /// Type - This is the sh_type field of a section, drawn from the enums below.
33b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned Type;
344778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
35b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  /// Flags - This is the sh_flags field of a section, drawn from the enums.
36b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  /// below.
37b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned Flags;
38b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
393e09669bc44aeb053e58ae8245ad0e49570b0e21Matt Fleming  /// EntrySize - The size of each entry in this section. This size only
403e09669bc44aeb053e58ae8245ad0e49570b0e21Matt Fleming  /// makes sense for sections that contain fixed-sized entries. If a
413e09669bc44aeb053e58ae8245ad0e49570b0e21Matt Fleming  /// section does not contain fixed-sized entries 'EntrySize' will be 0.
423e09669bc44aeb053e58ae8245ad0e49570b0e21Matt Fleming  unsigned EntrySize;
434778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
442ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola  const MCSymbol *Group;
452ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola
4674aae4726a66733c5872588287535a984f9a94c7Chris Lattnerprivate:
4774aae4726a66733c5872588287535a984f9a94c7Chris Lattner  friend class MCContext;
482928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  MCSectionELF(StringRef Section, unsigned type, unsigned flags,
492ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola               SectionKind K, unsigned entrySize, const MCSymbol *group)
509a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar    : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
512ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola      EntrySize(entrySize), Group(group) {}
5274aae4726a66733c5872588287535a984f9a94c7Chris Lattner  ~MCSectionELF();
53b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopespublic:
54b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
55b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  /// ShouldOmitSectionDirective - Decides whether a '.section' directive
56b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  /// should be printed before the section name
57a46918d2b1b63aa3db94aa10b9ea70209b84e274Benjamin Kramer  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
58b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
591f8008cf214b984954de2e986fb8cb0e5cc58606Chris Lattner  StringRef getSectionName() const { return SectionName; }
60b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned getType() const { return Type; }
61b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes  unsigned getFlags() const { return Flags; }
626b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming  unsigned getEntrySize() const { return EntrySize; }
632ff9e83a826c1c2ee0f1c6072d3d97d5b10678eeRafael Espindola  const MCSymbol *getGroup() const { return Group; }
644778643912832bc8118eace1aee16554117a8eefMichael J. Spencer
6574aae4726a66733c5872588287535a984f9a94c7Chris Lattner  void PrintSwitchToSection(const MCAsmInfo &MAI,
6674aae4726a66733c5872588287535a984f9a94c7Chris Lattner                            raw_ostream &OS) const;
67083cf1574facc9ce468fba1735c794bd7e520108Jan Wen Voung  virtual bool UseCodeAlign() const;
68f2dc4aa562e2478a73fe5aeeeec16b1e496a0642Rafael Espindola  virtual bool isVirtualSection() const;
69083cf1574facc9ce468fba1735c794bd7e520108Jan Wen Voung
70ba9934648f1b8f5b1749548963f385f1147c1f68Duncan Sands  /// isBaseAddressKnownZero - We know that non-allocatable sections (like
71ba9934648f1b8f5b1749548963f385f1147c1f68Duncan Sands  /// debug info) have a base of zero.
72ba9934648f1b8f5b1749548963f385f1147c1f68Duncan Sands  virtual bool isBaseAddressKnownZero() const {
73ba9934648f1b8f5b1749548963f385f1147c1f68Duncan Sands    return (getFlags() & ELF::SHF_ALLOC) == 0;
74ba9934648f1b8f5b1749548963f385f1147c1f68Duncan Sands  }
75ba9934648f1b8f5b1749548963f385f1147c1f68Duncan Sands
769a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar  static bool classof(const MCSection *S) {
779a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar    return S->getVariant() == SV_ELF;
789a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar  }
799a744e38607bc3046dffea56efec0b2dfc51d5e4Daniel Dunbar  static bool classof(const MCSectionELF *) { return true; }
80186e7a0fb1b2028e4fa9c3efe29d9433c91b3f66Jan Wen Voung
81186e7a0fb1b2028e4fa9c3efe29d9433c91b3f66Jan Wen Voung  // Return the entry size for sections with fixed-width data.
82186e7a0fb1b2028e4fa9c3efe29d9433c91b3f66Jan Wen Voung  static unsigned DetermineEntrySize(SectionKind Kind);
83186e7a0fb1b2028e4fa9c3efe29d9433c91b3f66Jan Wen Voung
84b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes};
85b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
86b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes} // end namespace llvm
87b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes
88b808588a3a5febe931896b3779d159ba90d836f7Bruno Cardoso Lopes#endif
89