1 //===-- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
11 #define LLVM_LIB_OBJECT_RECORDSTREAMER_H
13 #include "llvm/MC/MCStreamer.h"
16 class RecordStreamer : public MCStreamer {
18 enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
22 StringMap<State> Symbols;
23 // Map of aliases created by .symver directives, saved so we can update
24 // their symbol binding after parsing complete. This maps from each
25 // aliasee to its list of aliases.
26 DenseMap<const MCSymbol *, std::vector<MCSymbol *>> SymverAliasMap;
27 void markDefined(const MCSymbol &Symbol);
28 void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
29 void markUsed(const MCSymbol &Symbol);
30 void visitUsedSymbol(const MCSymbol &Sym) override;
33 typedef StringMap<State>::const_iterator const_iterator;
34 const_iterator begin();
36 RecordStreamer(MCContext &Context);
37 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
39 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
40 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
41 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
42 void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
43 unsigned ByteAlignment) override;
44 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
45 unsigned ByteAlignment) override;
46 /// Record .symver aliases for later processing.
47 void emitELFSymverDirective(MCSymbol *Alias,
48 const MCSymbol *Aliasee) override;
49 /// Return the map of .symver aliasee to associated aliases.
50 DenseMap<const MCSymbol *, std::vector<MCSymbol *>> &symverAliases() {
51 return SymverAliasMap;
53 /// Get the state recorded for the given symbol.
54 State getSymbolState(const MCSymbol *Sym) {
55 auto SI = Symbols.find(Sym->getName());
56 if (SI == Symbols.end())