Path: blob/main/contrib/llvm-project/llvm/lib/Object/RecordStreamer.h
35234 views
//===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H9#define LLVM_LIB_OBJECT_RECORDSTREAMER_H1011#include "llvm/ADT/DenseMap.h"12#include "llvm/ADT/StringMap.h"13#include "llvm/MC/MCDirectives.h"14#include "llvm/MC/MCStreamer.h"15#include "llvm/Support/SMLoc.h"16#include <vector>1718namespace llvm {1920class MCSymbol;21class Module;2223class RecordStreamer : public MCStreamer {24public:25enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,26UndefinedWeak};2728private:29const Module &M;30StringMap<State> Symbols;31// Map of aliases created by .symver directives, saved so we can update32// their symbol binding after parsing complete. This maps from each33// aliasee to its list of aliases.34DenseMap<const MCSymbol *, std::vector<StringRef>> SymverAliasMap;3536/// Get the state recorded for the given symbol.37State getSymbolState(const MCSymbol *Sym);3839void markDefined(const MCSymbol &Symbol);40void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);41void markUsed(const MCSymbol &Symbol);42void visitUsedSymbol(const MCSymbol &Sym) override;4344public:45RecordStreamer(MCContext &Context, const Module &M);4647void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;48void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;49bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;50void emitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,51Align ByteAlignment, SMLoc Loc = SMLoc()) override;52void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,53Align ByteAlignment) override;5455// Ignore COFF-specific directives; we do not need any information from them,56// but the default implementation of these methods crashes, so we override57// them with versions that do nothing.58void beginCOFFSymbolDef(const MCSymbol *Symbol) override {}59void emitCOFFSymbolStorageClass(int StorageClass) override {}60void emitCOFFSymbolType(int Type) override {}61void endCOFFSymbolDef() override {}6263/// Record .symver aliases for later processing.64void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name,65bool KeepOriginalSym) override;6667// Emit ELF .symver aliases and ensure they have the same binding as the68// defined symbol they alias with.69void flushSymverDirectives();7071// Symbols iterators72using const_iterator = StringMap<State>::const_iterator;73const_iterator begin();74const_iterator end();7576// SymverAliasMap iterators77using const_symver_iterator = decltype(SymverAliasMap)::const_iterator;78iterator_range<const_symver_iterator> symverAliases();79};8081} // end namespace llvm8283#endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H848586