LLVM  10.0.0svn
Go to the documentation of this file.
1 //===- RecordStreamer.h - Record asm defined and used symbols ---*- 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 //===----------------------------------------------------------------------===//
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/MC/MCDirectives.h"
15 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/MC/MCSymbol.h"
17 #include "llvm/Support/SMLoc.h"
18 #include <vector>
20 namespace llvm {
22 class GlobalValue;
23 class Module;
25 class RecordStreamer : public MCStreamer {
26 public:
30 private:
31  const Module &M;
32  StringMap<State> Symbols;
33  // Map of aliases created by .symver directives, saved so we can update
34  // their symbol binding after parsing complete. This maps from each
35  // aliasee to its list of aliases.
38  /// Get the state recorded for the given symbol.
39  State getSymbolState(const MCSymbol *Sym);
41  void markDefined(const MCSymbol &Symbol);
42  void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
43  void markUsed(const MCSymbol &Symbol);
44  void visitUsedSymbol(const MCSymbol &Sym) override;
46 public:
47  RecordStreamer(MCContext &Context, const Module &M);
49  void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
50  void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
51  void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
52  bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
53  void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
54  unsigned ByteAlignment, SMLoc Loc = SMLoc()) override;
55  void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
56  unsigned ByteAlignment) override;
58  // Ignore COFF-specific directives; we do not need any information from them,
59  // but the default implementation of these methods crashes, so we override
60  // them with versions that do nothing.
61  void BeginCOFFSymbolDef(const MCSymbol *Symbol) override {}
63  void EmitCOFFSymbolType(int Type) override {}
64  void EndCOFFSymbolDef() override {}
66  /// Record .symver aliases for later processing.
67  void emitELFSymverDirective(StringRef AliasName,
68  const MCSymbol *Aliasee) override;
70  // Emit ELF .symver aliases and ensure they have the same binding as the
71  // defined symbol they alias with.
72  void flushSymverDirectives();
74  // Symbols iterators
79  // SymverAliasMap iterators
80  using const_symver_iterator = decltype(SymverAliasMap)::const_iterator;
82 };
84 } // end namespace llvm
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee) override
Record .symver aliases for later processing.
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
StringMap< State >::const_iterator const_iterator
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:356
const_iterator end()
void EmitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Context object for machine code objects.
Definition: MCContext.h:65
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
decltype(SymverAliasMap)::const_iterator const_symver_iterator
Streaming machine code generation interface.
Definition: MCStreamer.h:196
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void EmitCOFFSymbolType(int Type) override
Emit the type of the symbol.
Definition: MCDirectives.h:18
A range adaptor for a pair of iterators.
void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, SMLoc Loc=SMLoc()) override
Emit the zerofill section and an optional symbol.
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
LLVM Value Representation.
Definition: Value.h:74
iterator_range< const_symver_iterator > symverAliases()
void EndCOFFSymbolDef() override
Marks the end of the symbol definition.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Represents a location in source code.
Definition: SMLoc.h:23
const_iterator begin()
RecordStreamer(MCContext &Context, const Module &M)