LLVM  13.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 
22 namespace llvm {
23 
24 class MCSymbol;
25 
26 /// This represents a section on linux, lots of unix variants and some bare
27 /// metal systems.
28 class MCSectionELF final : public MCSection {
29  /// This is the sh_type field of a section, drawn from the enums below.
30  unsigned Type;
31 
32  /// This is the sh_flags field of a section, drawn from the enums below.
33  unsigned Flags;
34 
35  unsigned UniqueID;
36 
37  /// The size of each entry in this section. This size only makes sense for
38  /// sections that contain fixed-sized entries. If a section does not contain
39  /// fixed-sized entries 'EntrySize' will be 0.
40  unsigned EntrySize;
41 
42  /// The section group signature symbol (if not null) and a bool indicating
43  /// whether this is a GRP_COMDAT group.
45 
46  /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
47  /// section header index of the section where LinkedToSym is defined.
48  const MCSymbol *LinkedToSym;
49 
50 private:
51  friend class MCContext;
52 
53  // The storage of Name is owned by MCContext's ELFUniquingMap.
54  MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
55  unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
56  unsigned UniqueID, MCSymbol *Begin,
57  const MCSymbolELF *LinkedToSym)
58  : MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
59  UniqueID(UniqueID), EntrySize(entrySize), Group(group, IsComdat),
60  LinkedToSym(LinkedToSym) {
61  if (Group.getPointer())
62  Group.getPointer()->setIsSignature();
63  }
64 
65  // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
66  // sections.
67  void setSectionName(StringRef Name) { this->Name = Name; }
68 
69 public:
70  /// Decides whether a '.section' directive should be printed before the
71  /// section name
72  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
73 
74  unsigned getType() const { return Type; }
75  unsigned getFlags() const { return Flags; }
76  unsigned getEntrySize() const { return EntrySize; }
77  void setFlags(unsigned F) { Flags = F; }
78  const MCSymbolELF *getGroup() const { return Group.getPointer(); }
79  bool isComdat() const { return Group.getInt(); }
80 
81  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
82  raw_ostream &OS,
83  const MCExpr *Subsection) const override;
84  bool UseCodeAlign() const override;
85  bool isVirtualSection() const override;
86  StringRef getVirtualSectionKind() const override;
87 
88  bool isUnique() const { return UniqueID != NonUniqueID; }
89  unsigned getUniqueID() const { return UniqueID; }
90 
91  const MCSection *getLinkedToSection() const {
92  return &LinkedToSym->getSection();
93  }
94  const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
95 
96  static bool classof(const MCSection *S) {
97  return S->getVariant() == SV_ELF;
98  }
99 };
100 
101 } // end namespace llvm
102 
103 #endif // LLVM_MC_MCSECTIONELF_H
llvm::MCSectionELF::getUniqueID
unsigned getUniqueID() const
Definition: MCSectionELF.h:89
llvm::MCSection::Name
StringRef Name
Definition: MCSection.h:104
llvm
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
StringRef.h
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::MCSectionELF::getGroup
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:78
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
llvm::MCSectionELF::getLinkedToSymbol
const MCSymbol * getLinkedToSymbol() const
Definition: MCSectionELF.h:94
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MCSymbolELF
Definition: MCSymbolELF.h:14
PointerIntPair.h
llvm::MCSectionELF::getEntrySize
unsigned getEntrySize() const
Definition: MCSectionELF.h:76
llvm::MCSymbol::getSection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:261
MCSymbolELF.h
llvm::MCSectionELF::isUnique
bool isUnique() const
Definition: MCSectionELF.h:88
llvm::MCSectionELF::UseCodeAlign
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
Definition: MCSectionELF.cpp:199
llvm::MCSectionELF::PrintSwitchToSection
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionELF.cpp:53
group
bb420 i The CBE manages to mtctr r0 r11 stbx r9 addi bdz later b loop This could be much the loop would be a single dispatch group
Definition: README.txt:61
llvm::MCSectionELF::isVirtualSection
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSectionELF.cpp:203
llvm::MCSectionELF::ShouldOmitSectionDirective
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a '.section' directive should be printed before the section name.
Definition: MCSectionELF.cpp:22
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::MCSectionELF::isComdat
bool isComdat() const
Definition: MCSectionELF.h:79
llvm::PointerIntPair::getPointer
PointerTy getPointer() const
Definition: PointerIntPair.h:59
type
AMD64 Optimization Manual has some nice information about optimizing integer multiplication by a constant How much of it applies to Intel s X86 implementation There are definite trade offs to xmm0 cvttss2siq rdx jb L3 subss xmm0 rax cvttss2siq rdx xorq rdx rax ret instead of xmm1 cvttss2siq rcx movaps xmm2 subss xmm2 cvttss2siq rax rdx xorq rax ucomiss xmm0 cmovb rax ret Seems like the jb branch has high likelihood of being taken It would have saved a few instructions It s not possible to reference and DH registers in an instruction requiring REX prefix divb and mulb both produce results in AH If isel emits a CopyFromReg which gets turned into a movb and that can be allocated a r8b r15b To get around isel emits a CopyFromReg from AX and then right shift it down by and truncate it It s not pretty but it works We need some register allocation magic to make the hack go which would often require a callee saved register Callees usually need to keep this value live for most of their body so it doesn t add a significant burden on them We currently implement this in however this is suboptimal because it means that it would be quite awkward to implement the optimization for callers A better implementation would be to relax the LLVM IR rules for sret arguments to allow a function with an sret argument to have a non void return type
Definition: README-X86-64.txt:70
llvm::MCSectionELF::getLinkedToSection
const MCSection * getLinkedToSection() const
Definition: MCSectionELF.h:91
llvm::PointerIntPair::getInt
IntType getInt() const
Definition: PointerIntPair.h:61
TemplateParamKind::Type
@ Type
llvm::MCSection::NonUniqueID
static constexpr unsigned NonUniqueID
Definition: MCSection.h:41
MCSection.h
llvm::MCSectionELF::getFlags
unsigned getFlags() const
Definition: MCSectionELF.h:75
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::MCSectionELF::setFlags
void setFlags(unsigned F)
Definition: MCSectionELF.h:77
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCSectionELF::getVirtualSectionKind
StringRef getVirtualSectionKind() const override
Definition: MCSectionELF.cpp:207
llvm::MCSection::SV_ELF
@ SV_ELF
Definition: MCSection.h:43
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
SectionKind.h
llvm::MCSectionELF::classof
static bool classof(const MCSection *S)
Definition: MCSectionELF.h:96
llvm::PointerIntPair
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition: PointerIntPair.h:45
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCSectionELF::getType
unsigned getType() const
Definition: MCSectionELF.h:74
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:165