LLVM  5.0.0
MCELFStreamer.h
Go to the documentation of this file.
1 //===- MCELFStreamer.h - MCStreamer ELF Object File Interface ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_MC_MCELFSTREAMER_H
11 #define LLVM_MC_MCELFSTREAMER_H
12 
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/MC/MCDirectives.h"
16 
17 namespace llvm {
18 
19 class MCAsmBackend;
20 class MCCodeEmitter;
21 class MCExpr;
22 class MCInst;
23 
25 public:
27  MCCodeEmitter *Emitter)
28  : MCObjectStreamer(Context, TAB, OS, Emitter) {}
29 
30  ~MCELFStreamer() override = default;
31 
32  /// state management
33  void reset() override {
34  SeenIdent = false;
35  BundleGroups.clear();
37  }
38 
39  /// \name MCStreamer Interface
40  /// @{
41 
42  void InitSections(bool NoExecStack) override;
43  void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
44  void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
45  void EmitLabel(MCSymbol *Symbol, SMLoc Loc, MCFragment *F) 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 
56  void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
57  unsigned ByteAlignment) override;
58 
59  void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
60  uint64_t Size = 0, unsigned ByteAlignment = 0) override;
61  void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
62  unsigned ByteAlignment = 0) override;
63  void EmitValueImpl(const MCExpr *Value, unsigned Size,
64  SMLoc Loc = SMLoc()) override;
65 
66  void EmitIdent(StringRef IdentString) override;
67 
68  void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
69 
70  void FinishImpl() override;
71 
72  void EmitBundleAlignMode(unsigned AlignPow2) override;
73  void EmitBundleLock(bool AlignToEnd) override;
74  void EmitBundleUnlock() override;
75 
76 private:
77  bool isBundleLocked() const;
78  void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
79  void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
80 
81  void fixSymbolsInTLSFixups(const MCExpr *expr);
82 
83  /// \brief Merge the content of the fragment \p EF into the fragment \p DF.
84  void mergeFragment(MCDataFragment *, MCDataFragment *);
85 
86  bool SeenIdent = false;
87 
88  /// BundleGroups - The stack of fragments holding the bundle-locked
89  /// instructions.
91 };
92 
93 MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
94  raw_pwrite_stream &OS,
95  MCCodeEmitter *Emitter, bool RelaxAll,
96  bool IsThumb);
97 
98 } // end namespace llvm
99 
100 #endif // LLVM_MC_MCELFSTREAMER_H
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
MCELFStreamer * createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool IsThumb)
~MCELFStreamer() override=default
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
LLVMContext & Context
void reset() override
state management
Definition: MCELFStreamer.h:33
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
void EmitBundleUnlock() override
Ends a bundle-locked group.
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
void EmitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0) override
Emit the zerofill section and an optional symbol.
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
void EmitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0) override
Emit a thread local bss (.tbss) symbol.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Context object for machine code objects.
Definition: MCContext.h:59
#define F(x, y, z)
Definition: MD5.cpp:55
void EmitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
Streaming object file generation interface.
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.
MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter)
Definition: MCELFStreamer.h:26
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
MCSymbolAttr
Definition: MCDirectives.h:19
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
MCAssemblerFlag
Definition: MCDirectives.h:48
void reset() override
state management
MCSubtargetInfo - Generic base class for all target subtargets.
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
Fragment for data and encoded instructions.
Definition: MCFragment.h:224
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
void EmitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Represents a location in source code.
Definition: SMLoc.h:24
void FinishImpl() override
Streamer specific finalization.