LLVM 22.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"
19#include "llvm/MC/MCSection.h"
20#include "llvm/MC/MCSymbolELF.h"
21#include "llvm/MC/SectionKind.h"
22
23namespace llvm {
24
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;
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 /// The section group signature symbol (if not null) and a bool indicating
42 /// whether this is a GRP_COMDAT group.
44
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;
48
49 /// Start/end offset in file, used by ELFWriter.
50 uint64_t StartOffset;
51 uint64_t EndOffset;
52
53private:
54 friend class MCContext;
55 friend class MCAsmInfoELF;
56
57 // The storage of Name is owned by MCContext's ELFUniquingMap.
58 MCSectionELF(StringRef Name, unsigned type, unsigned flags,
59 unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
60 unsigned UniqueID, MCSymbol *Begin,
61 const MCSymbolELF *LinkedToSym)
62 : MCSection(Name, flags & ELF::SHF_EXECINSTR, type == ELF::SHT_NOBITS,
63 Begin),
64 Type(type), Flags(flags), UniqueID(UniqueID), EntrySize(entrySize),
65 Group(group, IsComdat), LinkedToSym(LinkedToSym) {
66 assert((!(Flags & ELF::SHF_GROUP) || Group.getPointer()) &&
67 "Group section without signature!");
68 if (Group.getPointer())
69 Group.getPointer()->setIsSignature();
70 }
71
72public:
73 unsigned getType() const { return Type; }
74 unsigned getFlags() const { return Flags; }
75 unsigned getEntrySize() const { return EntrySize; }
76 void setFlags(unsigned F) { Flags = F; }
77 const MCSymbolELF *getGroup() const { return Group.getPointer(); }
78 bool isComdat() const { return Group.getInt(); }
79
80 bool isUnique() const { return UniqueID != NonUniqueID; }
81 unsigned getUniqueID() const { return UniqueID; }
82
84 return &LinkedToSym->getSection();
85 }
86 const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
87
89 StartOffset = Start;
90 EndOffset = End;
91 }
92 std::pair<uint64_t, uint64_t> getOffsets() const {
93 return std::make_pair(StartOffset, EndOffset);
94 }
95};
96
97} // end namespace llvm
98
99#endif // LLVM_MC_MCSECTIONELF_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
RelocType Type
Definition: COFFYAML.cpp:410
bool End
Definition: ELF_riscv.cpp:480
#define F(x, y, z)
Definition: MD5.cpp:55
This file defines the PointerIntPair class.
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
const MCSection * getLinkedToSection() const
Definition: MCSectionELF.h:83
unsigned getFlags() const
Definition: MCSectionELF.h:74
unsigned getUniqueID() const
Definition: MCSectionELF.h:81
void setOffsets(uint64_t Start, uint64_t End)
Definition: MCSectionELF.h:88
void setFlags(unsigned F)
Definition: MCSectionELF.h:76
const MCSymbol * getLinkedToSymbol() const
Definition: MCSectionELF.h:86
std::pair< uint64_t, uint64_t > getOffsets() const
Definition: MCSectionELF.h:92
bool isUnique() const
Definition: MCSectionELF.h:80
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:77
unsigned getType() const
Definition: MCSectionELF.h:73
unsigned getEntrySize() const
Definition: MCSectionELF.h:75
bool isComdat() const
Definition: MCSectionELF.h:78
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
static constexpr unsigned NonUniqueID
Definition: MCSection.h:501
StringRef Name
Definition: MCSection.h:557
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:251
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:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
@ SHF_GROUP
Definition: ELF.h:1262
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18