blob: 13eac028a2854de9229a52143e909b6d03845990 [file] [log] [blame]
Eugene Zelenko1df42fa2017-04-24 23:21:38 +00001//===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//
Rafael Espindola13b69d62014-07-03 18:59:23 +00002//
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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
11#define LLVM_LIB_OBJECT_RECORDSTREAMER_H
Rafael Espindola13b69d62014-07-03 18:59:23 +000012
Eugene Zelenko1df42fa2017-04-24 23:21:38 +000013#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/StringMap.h"
15#include "llvm/MC/MCDirectives.h"
Rafael Espindola13b69d62014-07-03 18:59:23 +000016#include "llvm/MC/MCStreamer.h"
Eugene Zelenko1df42fa2017-04-24 23:21:38 +000017#include "llvm/MC/MCSymbol.h"
18#include "llvm/Support/SMLoc.h"
19#include <vector>
Rafael Espindola13b69d62014-07-03 18:59:23 +000020
21namespace llvm {
Eugene Zelenko1df42fa2017-04-24 23:21:38 +000022
Vitaly Buka0d038812018-03-20 00:38:33 +000023class GlobalValue;
24class Module;
25
Rafael Espindola13b69d62014-07-03 18:59:23 +000026class RecordStreamer : public MCStreamer {
27public:
Davide Italianof7518492016-09-15 17:54:22 +000028 enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
29 UndefinedWeak};
Rafael Espindola13b69d62014-07-03 18:59:23 +000030
31private:
Vitaly Buka0d038812018-03-20 00:38:33 +000032 const Module &M;
Rafael Espindola13b69d62014-07-03 18:59:23 +000033 StringMap<State> Symbols;
Teresa Johnsond8204472017-03-09 00:19:49 +000034 // Map of aliases created by .symver directives, saved so we can update
35 // their symbol binding after parsing complete. This maps from each
36 // aliasee to its list of aliases.
Vitaly Buka0d038812018-03-20 00:38:33 +000037 DenseMap<const MCSymbol *, std::vector<StringRef>> SymverAliasMap;
38
39 /// Get the state recorded for the given symbol.
40 State getSymbolState(const MCSymbol *Sym);
Eugene Zelenko1df42fa2017-04-24 23:21:38 +000041
Rafael Espindola13b69d62014-07-03 18:59:23 +000042 void markDefined(const MCSymbol &Symbol);
Davide Italianoec7e29e2016-06-22 20:48:15 +000043 void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
Rafael Espindola13b69d62014-07-03 18:59:23 +000044 void markUsed(const MCSymbol &Symbol);
45 void visitUsedSymbol(const MCSymbol &Sym) override;
46
47public:
Vitaly Buka0d038812018-03-20 00:38:33 +000048 RecordStreamer(MCContext &Context, const Module &M);
Eugene Zelenko1df42fa2017-04-24 23:21:38 +000049
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000050 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
51 bool) override;
Rafael Espindolabe991572017-02-10 15:13:12 +000052 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
Rafael Espindola13b69d62014-07-03 18:59:23 +000053 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
54 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
Rafael Espindola0709a7b2015-05-21 19:20:38 +000055 void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
Rafael Espindola13b69d62014-07-03 18:59:23 +000056 unsigned ByteAlignment) override;
57 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
58 unsigned ByteAlignment) override;
Teresa Johnsond8204472017-03-09 00:19:49 +000059 /// Record .symver aliases for later processing.
Rafael Espindola47b4d6b2018-03-09 18:42:25 +000060 void emitELFSymverDirective(StringRef AliasName,
Teresa Johnsond8204472017-03-09 00:19:49 +000061 const MCSymbol *Aliasee) override;
Vlad Tsyrklevich230b2562018-04-20 01:36:48 +000062
Vitaly Buka0d038812018-03-20 00:38:33 +000063 // Emit ELF .symver aliases and ensure they have the same binding as the
64 // defined symbol they alias with.
65 void flushSymverDirectives();
Vlad Tsyrklevich230b2562018-04-20 01:36:48 +000066
67 // Symbols iterators
68 using const_iterator = StringMap<State>::const_iterator;
69 const_iterator begin();
70 const_iterator end();
71
72 // SymverAliasMap iterators
73 using const_symver_iterator = decltype(SymverAliasMap)::const_iterator;
74 iterator_range<const_symver_iterator> symverAliases();
Rafael Espindola13b69d62014-07-03 18:59:23 +000075};
Eugene Zelenko1df42fa2017-04-24 23:21:38 +000076
77} // end namespace llvm
78
79#endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H