LLVM  12.0.0git
MCELFStreamer.h
Go to the documentation of this file.
1 //===- MCELFStreamer.h - MCStreamer ELF Object File Interface ---*- 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 #ifndef LLVM_MC_MCELFSTREAMER_H
10 #define LLVM_MC_MCELFSTREAMER_H
11 
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/MC/MCDirectives.h"
15 
16 namespace llvm {
17 
18 class MCAsmBackend;
19 class MCCodeEmitter;
20 class MCExpr;
21 class MCInst;
22 
24 public:
25  MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
26  std::unique_ptr<MCObjectWriter> OW,
27  std::unique_ptr<MCCodeEmitter> Emitter);
28 
29  ~MCELFStreamer() override = default;
30 
31  /// state management
32  void reset() override {
33  SeenIdent = false;
34  BundleGroups.clear();
36  }
37 
38  /// \name MCStreamer Interface
39  /// @{
40 
41  void InitSections(bool NoExecStack) override;
42  void changeSection(MCSection *Section, const MCExpr *Subsection) override;
43  void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
44  void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F,
45  uint64_t Offset) override;
46  void emitAssemblerFlag(MCAssemblerFlag Flag) override;
47  void emitThumbFunc(MCSymbol *Func) override;
48  void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
49  bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
50  void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
51  void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
52  unsigned ByteAlignment) override;
53 
54  void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
55  void emitELFSymverDirective(StringRef AliasName,
56  const MCSymbol *Aliasee) override;
57 
58  void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
59  unsigned ByteAlignment) override;
60 
61  void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
62  uint64_t Size = 0, unsigned ByteAlignment = 0,
63  SMLoc L = SMLoc()) override;
64  void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
65  unsigned ByteAlignment = 0) override;
66  void emitValueImpl(const MCExpr *Value, unsigned Size,
67  SMLoc Loc = SMLoc()) override;
68 
69  void emitIdent(StringRef IdentString) override;
70 
71  void emitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
72 
74  const MCSymbolRefExpr *To, uint64_t Count) override;
75 
76  void finishImpl() override;
77 
78  void emitBundleAlignMode(unsigned AlignPow2) override;
79  void emitBundleLock(bool AlignToEnd) override;
80  void emitBundleUnlock() override;
81 
82 private:
83  bool isBundleLocked() const;
84  void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
85  void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
86 
87  void fixSymbolsInTLSFixups(const MCExpr *expr);
88  void finalizeCGProfileEntry(const MCSymbolRefExpr *&S);
89  void finalizeCGProfile();
90 
91  /// Merge the content of the fragment \p EF into the fragment \p DF.
92  void mergeFragment(MCDataFragment *, MCDataFragment *);
93 
94  bool SeenIdent = false;
95 
96  /// BundleGroups - The stack of fragments holding the bundle-locked
97  /// instructions.
99 };
100 
102  std::unique_ptr<MCAsmBackend> TAB,
103  std::unique_ptr<MCObjectWriter> OW,
104  std::unique_ptr<MCCodeEmitter> Emitter,
105  bool RelaxAll, bool IsThumb, bool IsAndroid);
106 
107 } // end namespace llvm
108 
109 #endif // LLVM_MC_MCELFSTREAMER_H
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
~MCELFStreamer() override=default
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void reset() override
state management
Definition: MCELFStreamer.h:32
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0) override
Emit a thread local bss (.tbss) symbol.
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
F(f)
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
void emitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset) override
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
void emitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
void emitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void finishImpl() override
Streamer specific finalization.
Context object for machine code objects.
Definition: MCContext.h:67
Streaming object file generation interface.
void emitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0, SMLoc L=SMLoc()) override
Emit the zerofill section and an optional symbol.
void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
void emitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:138
void emitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee) override
Emit an ELF .symver directive.
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void emitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
BlockVerifier::State From
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:883
void emitBundleUnlock() override
Ends a bundle-locked group.
MCSymbolAttr
Definition: MCDirectives.h:18
void changeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
MCAssemblerFlag
Definition: MCDirectives.h:50
void reset() override
state management
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Fragment for data and encoded instructions.
Definition: MCFragment.h:232
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
LLVM Value Representation.
Definition: Value.h:74
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
Represents a location in source code.
Definition: SMLoc.h:23
MCELFStreamer * createARMELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll, bool IsThumb, bool IsAndroid)