LLVM 19.0.0git
Go to the documentation of this file.
1//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
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
9// This file declares the MCSectionELF class.
17#include "llvm/ADT/StringRef.h"
19#include "llvm/MC/MCSection.h"
20#include "llvm/MC/MCSymbolELF.h"
21#include "llvm/MC/SectionKind.h"
23namespace llvm {
25/// This represents a section on linux, lots of unix variants and some bare
26/// metal systems.
27class MCSectionELF final : public MCSection {
28 /// This is the sh_type field of a section, drawn from the enums below.
29 unsigned Type;
31 /// This is the sh_flags field of a section, drawn from the enums below.
32 unsigned Flags;
34 unsigned UniqueID;
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;
41 /// The section group signature symbol (if not null) and a bool indicating
42 /// whether this is a GRP_COMDAT group.
45 /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
46 /// section header index of the section where LinkedToSym is defined.
47 const MCSymbol *LinkedToSym;
49 /// Start/end offset in file, used by ELFWriter.
50 uint64_t StartOffset;
51 uint64_t EndOffset;
54 friend class MCContext;
56 // The storage of Name is owned by MCContext's ELFUniquingMap.
57 MCSectionELF(StringRef Name, unsigned type, unsigned flags,
58 unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
59 unsigned UniqueID, MCSymbol *Begin,
60 const MCSymbolELF *LinkedToSym)
61 : MCSection(SV_ELF, Name, flags & ELF::SHF_EXECINSTR,
62 type == ELF::SHT_NOBITS, Begin),
63 Type(type), Flags(flags), UniqueID(UniqueID), EntrySize(entrySize),
64 Group(group, IsComdat), LinkedToSym(LinkedToSym) {
65 if (Group.getPointer())
66 Group.getPointer()->setIsSignature();
67 }
69 // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
70 // sections.
71 void setSectionName(StringRef Name) { this->Name = Name; }
74 /// Decides whether a '.section' directive should be printed before the
75 /// section name
76 bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
78 unsigned getType() const { return Type; }
79 unsigned getFlags() const { return Flags; }
80 unsigned getEntrySize() const { return EntrySize; }
81 void setFlags(unsigned F) { Flags = F; }
82 const MCSymbolELF *getGroup() const { return Group.getPointer(); }
83 bool isComdat() const { return Group.getInt(); }
85 void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
87 uint32_t Subsection) const override;
88 bool useCodeAlign() const override;
89 StringRef getVirtualSectionKind() const override;
91 bool isUnique() const { return UniqueID != NonUniqueID; }
92 unsigned getUniqueID() const { return UniqueID; }
95 return &LinkedToSym->getSection();
96 }
97 const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
100 StartOffset = Start;
101 EndOffset = End;
102 }
103 std::pair<uint64_t, uint64_t> getOffsets() const {
104 return std::make_pair(StartOffset, EndOffset);
105 }
107 static bool classof(const MCSection *S) {
108 return S->getVariant() == SV_ELF;
109 }
112} // end namespace llvm
RelocType Type
Definition: COFFYAML.cpp:391
bool End
Definition: ELF_riscv.cpp:480
#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:83
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
static bool classof(const MCSection *S)
Definition: MCSectionELF.h:107
const MCSection * getLinkedToSection() const
Definition: MCSectionELF.h:94
unsigned getFlags() const
Definition: MCSectionELF.h:79
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, uint32_t Subsection) const override
unsigned getUniqueID() const
Definition: MCSectionELF.h:92
void setOffsets(uint64_t Start, uint64_t End)
Definition: MCSectionELF.h:99
void setFlags(unsigned F)
Definition: MCSectionELF.h:81
const MCSymbol * getLinkedToSymbol() const
Definition: MCSectionELF.h:97
std::pair< uint64_t, uint64_t > getOffsets() const
Definition: MCSectionELF.h:103
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:91
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:82
unsigned getType() const
Definition: MCSectionELF.h:78
unsigned getEntrySize() const
Definition: MCSectionELF.h:80
bool isComdat() const
Definition: MCSectionELF.h:83
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
SectionVariant getVariant() const
Definition: MCSection.h:133
static constexpr unsigned NonUniqueID
Definition: MCSection.h:40
StringRef Name
Definition: MCSection.h:119
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
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
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