1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 // -*- mode: C++ -*- 3 // 4 // Copyright 2022 Google LLC 5 // 6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the 7 // "License"); you may not use this file except in compliance with the 8 // License. You may obtain a copy of the License at 9 // 10 // https://llvm.org/LICENSE.txt 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 // 18 // Author: Aleksei Vetrov 19 20 #ifndef STG_ELF_READER_H_ 21 #define STG_ELF_READER_H_ 22 23 #include <cstddef> 24 #include <memory> 25 #include <string> 26 #include <string_view> 27 #include <unordered_map> 28 #include <unordered_set> 29 #include <vector> 30 31 #include "elf_dwarf_handle.h" 32 #include "elf_loader.h" 33 #include "filter.h" 34 #include "graph.h" 35 #include "reader_options.h" 36 #include "runtime.h" 37 38 namespace stg { 39 namespace elf { 40 41 Id Read(Runtime& runtime, Graph& graph, ElfDwarfHandle& elf_dwarf_handle, 42 ReadOptions options, const std::unique_ptr<Filter>& file_filter); 43 44 // For unit tests only 45 namespace internal { 46 47 using SymbolTable = std::vector<SymbolTableEntry>; 48 using SymbolNameList = std::unordered_set<std::string_view>; 49 using CRCValuesMap = std::unordered_map<std::string, ElfSymbol::CRC>; 50 using NamespacesMap = std::unordered_map<std::string, std::string>; 51 using AddressMap = std::unordered_map<std::string, size_t>; 52 53 ElfSymbol::SymbolType ConvertSymbolType( 54 SymbolTableEntry::SymbolType symbol_type); 55 SymbolNameList GetKsymtabSymbols(const SymbolTable& symbols); 56 CRCValuesMap GetCRCValuesMap(const SymbolTable& symbols, const ElfLoader& elf); 57 NamespacesMap GetNamespacesMap(const SymbolTable& symbols, 58 const ElfLoader& elf); 59 AddressMap GetCFIAddressMap(const SymbolTable& symbols, const ElfLoader& elf); 60 bool IsPublicFunctionOrVariable(const SymbolTableEntry& symbol); 61 bool IsLinuxKernelFunctionOrVariable(const SymbolNameList& ksymtab, 62 const SymbolTableEntry& symbol); 63 64 } // namespace internal 65 } // namespace elf 66 } // namespace stg 67 68 #endif // STG_ELF_READER_H_ 69