//===- IRSymtab.h - data definitions for IR symbol tables -------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file contains data definitions and a reader and builder for a symbol // table for LLVM IR. Its purpose is to allow linkers and other consumers of // bitcode files to efficiently read the symbol table for symbol resolution // purposes without needing to construct a module in memory. // // As with most object files the symbol table has two parts: the symbol table // itself and a string table which is referenced by the symbol table. // // A symbol table corresponds to a single bitcode file, which may consist of // multiple modules, so symbol tables may likewise contain symbols for multiple // modules. // //===----------------------------------------------------------------------===// #ifndef LLVM_OBJECT_IRSYMTAB_H #define LLVM_OBJECT_IRSYMTAB_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/GlobalValue.h" #include "llvm/Object/SymbolicFile.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" #include <cassert> #include <cstdint> #include <vector> namespace llvm { struct BitcodeFileContents; class StringTableBuilder; namespace irsymtab { namespace storage { // The data structures in this namespace define the low-level serialization // format. Clients that just want to read a symbol table should use the // irsymtab::Reader class. Word; /// A reference to a string in the string table. struct Str { … }; /// A reference to a range of objects in the symbol table. template <typename T> struct Range { … }; /// Describes the range of a particular module's symbols within the symbol /// table. struct Module { … }; /// This is equivalent to an IR comdat. struct Comdat { … }; /// Contains the information needed by linkers for symbol resolution, as well as /// by the LTO implementation itself. struct Symbol { … }; /// This data structure contains rarely used symbol fields and is optionally /// referenced by a Symbol. struct Uncommon { … }; struct Header { … }; } // end namespace storage /// Fills in Symtab and StrtabBuilder with a valid symbol and string table for /// Mods. Error build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc); /// This represents a symbol that has been read from a storage::Symbol and /// possibly a storage::Uncommon. struct Symbol { … }; /// This class can be used to read a Symtab and Strtab produced by /// irsymtab::build. class Reader { … }; /// Ephemeral symbols produced by Reader::symbols() and /// Reader::module_symbols(). class Reader::SymbolRef : public Symbol { … }; inline Reader::symbol_range Reader::symbols() const { … } inline Reader::symbol_range Reader::module_symbols(unsigned I) const { … } /// The contents of the irsymtab in a bitcode file. Any underlying data for the /// irsymtab are owned by Symtab and Strtab. struct FileContents { … }; /// Reads the contents of a bitcode file, creating its irsymtab if necessary. Expected<FileContents> readBitcode(const BitcodeFileContents &BFC); } // end namespace irsymtab } // end namespace llvm #endif // LLVM_OBJECT_IRSYMTAB_H