1 //===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
10 #define LLVM_LIB_OBJECT_RECORDSTREAMER_H
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/MapVector.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/MC/MCDirectives.h"
16 #include "llvm/MC/MCStreamer.h"
17 #include "llvm/Support/SMLoc.h"
25 class RecordStreamer
: public MCStreamer
{
27 enum State
{ NeverSeen
, Global
, Defined
, DefinedGlobal
, DefinedWeak
, Used
,
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.
36 MapVector
<const MCSymbol
*, std::vector
<StringRef
>> SymverAliasMap
;
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
;
47 RecordStreamer(MCContext
&Context
, const Module
&M
);
49 void emitLabel(MCSymbol
*Symbol
, SMLoc Loc
= SMLoc()) override
;
50 void emitAssignment(MCSymbol
*Symbol
, const MCExpr
*Value
) override
;
51 bool emitSymbolAttribute(MCSymbol
*Symbol
, MCSymbolAttr Attribute
) override
;
52 void emitZerofill(MCSection
*Section
, MCSymbol
*Symbol
, uint64_t Size
,
53 Align ByteAlignment
, SMLoc Loc
= SMLoc()) override
;
54 void emitCommonSymbol(MCSymbol
*Symbol
, uint64_t Size
,
55 Align ByteAlignment
) override
;
57 // Ignore COFF-specific directives; we do not need any information from them,
58 // but the default implementation of these methods crashes, so we override
59 // them with versions that do nothing.
60 void beginCOFFSymbolDef(const MCSymbol
*Symbol
) override
{}
61 void emitCOFFSymbolStorageClass(int StorageClass
) override
{}
62 void emitCOFFSymbolType(int Type
) override
{}
63 void endCOFFSymbolDef() override
{}
65 /// Record .symver aliases for later processing.
66 void emitELFSymverDirective(const MCSymbol
*OriginalSym
, StringRef Name
,
67 bool KeepOriginalSym
) override
;
69 // Emit ELF .symver aliases and ensure they have the same binding as the
70 // defined symbol they alias with.
71 void flushSymverDirectives();
74 using const_iterator
= StringMap
<State
>::const_iterator
;
75 const_iterator
begin();
78 // SymverAliasMap iterators
79 using const_symver_iterator
= decltype(SymverAliasMap
)::const_iterator
;
80 iterator_range
<const_symver_iterator
> symverAliases();
83 } // end namespace llvm
85 #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H