blob: 4136ea79de411942da49ec6fb4bf72220654bc98 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the MCSectionELF class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_MC_MCSECTIONELF_H
14#define LLVM_MC_MCSECTIONELF_H
15
16#include "llvm/ADT/StringRef.h"
17#include "llvm/MC/MCSection.h"
18#include "llvm/MC/MCSymbolELF.h"
19#include "llvm/MC/SectionKind.h"
20
21namespace llvm {
22
23class MCSymbol;
24
25/// This represents a section on linux, lots of unix variants and some bare
26/// metal systems.
27class MCSectionELF final : public MCSection {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010028 /// This is the sh_type field of a section, drawn from the enums below.
29 unsigned Type;
30
31 /// This is the sh_flags field of a section, drawn from the enums below.
32 unsigned Flags;
33
34 unsigned UniqueID;
35
36 /// The size of each entry in this section. This size only makes sense for
37 /// sections that contain fixed-sized entries. If a section does not contain
38 /// fixed-sized entries 'EntrySize' will be 0.
39 unsigned EntrySize;
40
41 const MCSymbolELF *Group;
42
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020043 /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
44 /// section header index of the section where LinkedToSym is defined.
45 const MCSymbol *LinkedToSym;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010046
47private:
48 friend class MCContext;
49
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020050 // The storage of Name is owned by MCContext's ELFUniquingMap.
51 MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010052 unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020053 MCSymbol *Begin, const MCSymbolELF *LinkedToSym)
54 : MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
55 UniqueID(UniqueID), EntrySize(entrySize), Group(group),
56 LinkedToSym(LinkedToSym) {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010057 if (Group)
58 Group->setIsSignature();
59 }
60
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020061 // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
62 // sections.
63 void setSectionName(StringRef Name) { this->Name = Name; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010064
65public:
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010066 /// Decides whether a '.section' directive should be printed before the
67 /// section name
68 bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
69
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010070 unsigned getType() const { return Type; }
71 unsigned getFlags() const { return Flags; }
72 unsigned getEntrySize() const { return EntrySize; }
73 void setFlags(unsigned F) { Flags = F; }
74 const MCSymbolELF *getGroup() const { return Group; }
75
76 void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
77 raw_ostream &OS,
78 const MCExpr *Subsection) const override;
79 bool UseCodeAlign() const override;
80 bool isVirtualSection() const override;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020081 StringRef getVirtualSectionKind() const override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010082
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020083 bool isUnique() const { return UniqueID != NonUniqueID; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010084 unsigned getUniqueID() const { return UniqueID; }
85
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020086 const MCSection *getLinkedToSection() const {
87 return &LinkedToSym->getSection();
88 }
89 const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010090
91 static bool classof(const MCSection *S) {
92 return S->getVariant() == SV_ELF;
93 }
94};
95
96} // end namespace llvm
97
98#endif // LLVM_MC_MCSECTIONELF_H