LLVM  3.7.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/SmallPtrSet.h"
14 #include "llvm/MC/MCDirectives.h"
16 #include "llvm/MC/SectionKind.h"
17 #include "llvm/Support/DataTypes.h"
18 #include <vector>
19 
20 namespace llvm {
21 class MCAsmBackend;
22 class MCAssembler;
23 class MCCodeEmitter;
24 class MCExpr;
25 class MCInst;
26 class raw_ostream;
27 
29 public:
31  MCCodeEmitter *Emitter)
32  : MCObjectStreamer(Context, TAB, OS, Emitter), SeenIdent(false) {}
33 
34  ~MCELFStreamer() override;
35 
36  /// state management
37  void reset() override {
38  SeenIdent = false;
39  LocalCommons.clear();
40  BundleGroups.clear();
42  }
43 
44  /// \name MCStreamer Interface
45  /// @{
46 
47  void InitSections(bool NoExecStack) override;
48  void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
49  void EmitLabel(MCSymbol *Symbol) override;
50  void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
51  void EmitThumbFunc(MCSymbol *Func) override;
52  void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
54  void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
55  void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
56  unsigned ByteAlignment) override;
57  void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
58  void EmitCOFFSymbolStorageClass(int StorageClass) override;
59  void EmitCOFFSymbolType(int Type) override;
60  void EndCOFFSymbolDef() override;
61 
62  void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
63 
64  void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
65  unsigned ByteAlignment) override;
66 
67  void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
68  uint64_t Size = 0, unsigned ByteAlignment = 0) override;
69  void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
70  unsigned ByteAlignment = 0) override;
71  void EmitValueImpl(const MCExpr *Value, unsigned Size,
72  const SMLoc &Loc = SMLoc()) override;
73 
74  void EmitFileDirective(StringRef Filename) override;
75 
76  void EmitIdent(StringRef IdentString) override;
77 
78  void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
79 
80  void Flush() override;
81 
82  void FinishImpl() override;
83 
84  void EmitBundleAlignMode(unsigned AlignPow2) override;
85  void EmitBundleLock(bool AlignToEnd) override;
86  void EmitBundleUnlock() override;
87 
88 private:
89  bool isBundleLocked() const;
90  void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
91  void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
92 
93  void fixSymbolsInTLSFixups(const MCExpr *expr);
94 
95  /// \brief Merge the content of the fragment \p EF into the fragment \p DF.
96  void mergeFragment(MCDataFragment *, MCDataFragment *);
97 
98  bool SeenIdent;
99 
100  struct LocalCommon {
101  const MCSymbol *Symbol;
102  uint64_t Size;
103  unsigned ByteAlignment;
104  };
105 
106  std::vector<LocalCommon> LocalCommons;
107 
108  /// BundleGroups - The stack of fragments holding the bundle-locked
109  /// instructions.
111 };
112 
113 MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
114  raw_pwrite_stream &OS,
115  MCCodeEmitter *Emitter, bool RelaxAll,
116  bool IsThumb);
117 
118 } // end namespace llvm
119 
120 #endif
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:48
void Flush() override
Causes any cached state to be written out.
MCELFStreamer * createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool IsThumb)
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
void reset() override
state management
Definition: MCELFStreamer.h:37
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
void EmitBundleUnlock() override
Ends a bundle-locked group.
void EmitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0) override
Emit the zerofill section and an optional symbol.
void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
void EmitCOFFSymbolType(int Type) override
Emit the type of the symbol.
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:294
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
void EmitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
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:33
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
#define false
Definition: ConvertUTF.c:65
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:48
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.
MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter)
Definition: MCELFStreamer.h:30
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:97
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:23
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
void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
MCAssemblerFlag
Definition: MCDirectives.h:47
void reset() override
state management
MCSubtargetInfo - Generic base class for all target subtargets.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321
Fragment for data and encoded instructions.
Definition: MCAssembler.h:228
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:69
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
void EndCOFFSymbolDef() override
Marks the end of the symbol definition.
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:40
~MCELFStreamer() override
Represents a location in source code.
Definition: SMLoc.h:23
void FinishImpl() override
Streamer specific finalization.
void EmitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.