#ifndef LLVM_MC_MCSECTIONELF_H
#define LLVM_MC_MCSECTIONELF_H
+#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCSymbolELF.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ELF.h"
+#include "llvm/Support/raw_ostream.h"
namespace llvm {
-
-/// MCSectionELF - This represents a section on linux, lots of unix variants
-/// and some bare metal systems.
-class MCSectionELF : public MCSection {
- std::string SectionName;
-
- /// Type - This is the sh_type field of a section, drawn from the enums below.
- unsigned Type;
-
- /// Flags - This is the sh_flags field of a section, drawn from the enums.
- /// below.
- unsigned Flags;
-
- /// HasCrazyBSS - PPC/Linux doesn't support the .bss directive, it
- /// needs .section .bss. TODO: replace this with a TAI method.
- bool HasCrazyBSS;
-
- /// IsExplicit - Indicates that this section comes from globals with an
- /// explicit section specfied.
- bool IsExplicit;
-
- MCSectionELF(const StringRef &Section, unsigned T, unsigned F,
- SectionKind K, bool hasCrazyBSS, bool isExplicit)
- : MCSection(K), SectionName(Section.str()), Type(T), Flags(F),
- HasCrazyBSS(hasCrazyBSS), IsExplicit(isExplicit) {}
-public:
-
- static MCSectionELF *Create(const StringRef &Section, unsigned Type,
- unsigned Flags, SectionKind K,
- bool hasCrazyBSS, bool isExplicit,
- MCContext &Ctx);
-
- /// ShouldOmitSectionDirective - Decides whether a '.section' directive
- /// should be printed before the section name
- bool ShouldOmitSectionDirective(const char *Name) const;
-
- /// ShouldPrintSectionType - Only prints the section type if supported
- bool ShouldPrintSectionType(unsigned Ty) const;
-
- /// IsCommon - True if this section contains only common symbols
- bool IsCommon() const;
-
- /// These are the section type and flags fields. An ELF section can have
- /// only one Type, but can have more than one of the flags specified.
- ///
- /// Valid section types.
- enum {
- // This value marks the section header as inactive.
- SHT_NULL = 0x00U,
-
- // Holds information defined by the program, with custom format and meaning.
- SHT_PROGBITS = 0x01U,
-
- // This section holds a symbol table.
- SHT_SYMTAB = 0x02U,
-
- // The section holds a string table.
- SHT_STRTAB = 0x03U,
-
- // The section holds relocation entries with explicit addends.
- SHT_RELA = 0x04U,
-
- // The section holds a symbol hash table.
- SHT_HASH = 0x05U,
-
- // Information for dynamic linking.
- SHT_DYNAMIC = 0x06U,
-
- // The section holds information that marks the file in some way.
- SHT_NOTE = 0x07U,
- // A section of this type occupies no space in the file.
- SHT_NOBITS = 0x08U,
+class MCSymbol;
- // The section holds relocation entries without explicit addends.
- SHT_REL = 0x09U,
+/// This represents a section on linux, lots of unix variants and some bare
+/// metal systems.
+class MCSectionELF final : public MCSection {
+ /// This is the name of the section. The referenced memory is owned by
+ /// TargetLoweringObjectFileELF's ELFUniqueMap.
+ StringRef SectionName;
- // This section type is reserved but has unspecified semantics.
- SHT_SHLIB = 0x0aU,
-
- // This section holds a symbol table.
- SHT_DYNSYM = 0x0bU,
-
- // This section contains an array of pointers to initialization functions.
- SHT_INIT_ARRAY = 0x0eU,
-
- // This section contains an array of pointers to termination functions.
- SHT_FINI_ARRAY = 0x0fU,
-
- // This section contains an array of pointers to functions that are invoked
- // before all other initialization functions.
- SHT_PREINIT_ARRAY = 0x10U,
+ /// This is the sh_type field of a section, drawn from the enums below.
+ unsigned Type;
- // A section group is a set of sections that are related and that must be
- // treated specially by the linker.
- SHT_GROUP = 0x11U,
+ /// This is the sh_flags field of a section, drawn from the enums below.
+ unsigned Flags;
- // This section is associated with a section of type SHT_SYMTAB, when the
- // referenced symbol table contain the escape value SHN_XINDEX
- SHT_SYMTAB_SHNDX = 0x12U,
+ unsigned UniqueID;
- LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
- };
+ /// The size of each entry in this section. This size only makes sense for
+ /// sections that contain fixed-sized entries. If a section does not contain
+ /// fixed-sized entries 'EntrySize' will be 0.
+ unsigned EntrySize;
- /// Valid section flags.
- enum {
- // The section contains data that should be writable.
- SHF_WRITE = 0x1U,
+ const MCSymbolELF *Group;
- // The section occupies memory during execution.
- SHF_ALLOC = 0x2U,
+ /// Depending on the type of the section this is sh_link or sh_info.
+ const MCSectionELF *Associated;
- // The section contains executable machine instructions.
- SHF_EXECINSTR = 0x4U,
+private:
+ friend class MCContext;
+ MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
+ unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
+ MCSymbol *Begin, const MCSectionELF *Associated)
+ : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
+ Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
+ Associated(Associated) {
+ if (Group)
+ Group->setIsSignature();
+ }
- // The data in the section may be merged to eliminate duplication.
- SHF_MERGE = 0x10U,
+ void setSectionName(StringRef Name) { SectionName = Name; }
- // Elements in the section consist of null-terminated character strings.
- SHF_STRINGS = 0x20U,
+public:
+ ~MCSectionELF();
- // A field in this section holds a section header table index.
- SHF_INFO_LINK = 0x40U,
+ /// Decides whether a '.section' directive should be printed before the
+ /// section name
+ bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
- // Adds special ordering requirements for link editors.
- SHF_LINK_ORDER = 0x80U,
+ StringRef getSectionName() const { return SectionName; }
+ unsigned getType() const { return Type; }
+ unsigned getFlags() const { return Flags; }
+ unsigned getEntrySize() const { return EntrySize; }
+ const MCSymbolELF *getGroup() const { return Group; }
- // This section requires special OS-specific processing to avoid incorrect
- // behavior.
- SHF_OS_NONCONFORMING = 0x100U,
+ void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
+ const MCExpr *Subsection) const override;
+ bool UseCodeAlign() const override;
+ bool isVirtualSection() const override;
- // This section is a member of a section group.
- SHF_GROUP = 0x200U,
+ bool isUnique() const { return UniqueID != ~0U; }
+ unsigned getUniqueID() const { return UniqueID; }
- // This section holds Thread-Local Storage.
- SHF_TLS = 0x400U
- };
+ const MCSectionELF *getAssociatedSection() const { return Associated; }
- StringRef getSectionName() const {
- return StringRef(SectionName);
+ static bool classof(const MCSection *S) {
+ return S->getVariant() == SV_ELF;
}
-
- unsigned getType() const { return Type; }
- unsigned getFlags() const { return Flags; }
-
- virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
- raw_ostream &OS) const;
};
} // end namespace llvm