LLVM 19.0.0git
MCSectionELF.h
Go to the documentation of this file.
1//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
2//
3// 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
6//
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
17#include "llvm/ADT/StringRef.h"
18#include "llvm/MC/MCSection.h"
19#include "llvm/MC/MCSymbolELF.h"
20#include "llvm/MC/SectionKind.h"
21
22namespace llvm {
23
24/// This represents a section on linux, lots of unix variants and some bare
25/// metal systems.
26class MCSectionELF final : public MCSection {
27 /// This is the sh_type field of a section, drawn from the enums below.
28 unsigned Type;
29
30 /// This is the sh_flags field of a section, drawn from the enums below.
31 unsigned Flags;
32
33 unsigned UniqueID;
34
35 /// The size of each entry in this section. This size only makes sense for
36 /// sections that contain fixed-sized entries. If a section does not contain
37 /// fixed-sized entries 'EntrySize' will be 0.
38 unsigned EntrySize;
39
40 /// The section group signature symbol (if not null) and a bool indicating
41 /// whether this is a GRP_COMDAT group.
43
44 /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
45 /// section header index of the section where LinkedToSym is defined.
46 const MCSymbol *LinkedToSym;
47
48private:
49 friend class MCContext;
50
51 // The storage of Name is owned by MCContext's ELFUniquingMap.
52 MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
53 unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
54 unsigned UniqueID, MCSymbol *Begin,
55 const MCSymbolELF *LinkedToSym)
56 : MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
57 UniqueID(UniqueID), EntrySize(entrySize), Group(group, IsComdat),
58 LinkedToSym(LinkedToSym) {
59 if (Group.getPointer())
60 Group.getPointer()->setIsSignature();
61 }
62
63 // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
64 // sections.
65 void setSectionName(StringRef Name) { this->Name = Name; }
66
67public:
68 /// Decides whether a '.section' directive should be printed before the
69 /// section name
70 bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
71
72 unsigned getType() const { return Type; }
73 unsigned getFlags() const { return Flags; }
74 unsigned getEntrySize() const { return EntrySize; }
75 void setFlags(unsigned F) { Flags = F; }
76 const MCSymbolELF *getGroup() const { return Group.getPointer(); }
77 bool isComdat() const { return Group.getInt(); }
78
79 void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
81 const MCExpr *Subsection) const override;
82 bool useCodeAlign() const override;
83 bool isVirtualSection() const override;
84 StringRef getVirtualSectionKind() const override;
85
86 bool isUnique() const { return UniqueID != NonUniqueID; }
87 unsigned getUniqueID() const { return UniqueID; }
88
90 return &LinkedToSym->getSection();
91 }
92 const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
93
94 static bool classof(const MCSection *S) {
95 return S->getVariant() == SV_ELF;
96 }
97};
98
99} // end namespace llvm
100
101#endif // LLVM_MC_MCSECTIONELF_H
RelocType Type
Definition: COFFYAML.cpp:391
#define F(x, y, z)
Definition: MD5.cpp:55
This file defines the PointerIntPair class.
raw_pwrite_stream & OS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Context object for machine code objects.
Definition: MCContext.h:76
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:26
static bool classof(const MCSection *S)
Definition: MCSectionELF.h:94
const MCSection * getLinkedToSection() const
Definition: MCSectionELF.h:89
unsigned getFlags() const
Definition: MCSectionELF.h:73
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
unsigned getUniqueID() const
Definition: MCSectionELF.h:87
void setFlags(unsigned F)
Definition: MCSectionELF.h:75
const MCSymbol * getLinkedToSymbol() const
Definition: MCSectionELF.h:92
StringRef getVirtualSectionKind() const override
bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a '.section' directive should be printed before the section name.
bool isUnique() const
Definition: MCSectionELF.h:86
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
bool useCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:76
unsigned getType() const
Definition: MCSectionELF.h:72
unsigned getEntrySize() const
Definition: MCSectionELF.h:74
bool isComdat() const
Definition: MCSectionELF.h:77
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
SectionVariant getVariant() const
Definition: MCSection.h:127
static constexpr unsigned NonUniqueID
Definition: MCSection.h:41
StringRef Name
Definition: MCSection.h:113
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:269
PointerIntPair - This class implements a pair of a pointer and small integer.
IntType getInt() const
PointerTy getPointer() const
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18