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_loader.h" 32 #include "filter.h" 33 #include "graph.h" 34 #include "reader_options.h" 35 #include "runtime.h" 36 37 namespace stg { 38 namespace elf { 39 40 Id Read(Runtime& runtime, Graph& graph, const std::string& path, 41 ReadOptions options, const std::unique_ptr<Filter>& file_filter); 42 Id Read(Runtime& runtime, Graph& graph, char* data, size_t size, 43 ReadOptions options, const std::unique_ptr<Filter>& file_filter); 44 45 // For unit tests only 46 namespace internal { 47 48 using SymbolTable = std::vector<SymbolTableEntry>; 49 using SymbolNameList = std::unordered_set<std::string_view>; 50 using CRCValuesMap = std::unordered_map<std::string, ElfSymbol::CRC>; 51 using NamespacesMap = std::unordered_map<std::string, std::string>; 52 using AddressMap = std::unordered_map<std::string, size_t>; 53 54 ElfSymbol::SymbolType ConvertSymbolType( 55 SymbolTableEntry::SymbolType symbol_type); 56 SymbolNameList GetKsymtabSymbols(const SymbolTable& symbols); 57 CRCValuesMap GetCRCValuesMap(const SymbolTable& symbols, const ElfLoader& elf); 58 NamespacesMap GetNamespacesMap(const SymbolTable& symbols, 59 const ElfLoader& elf); 60 AddressMap GetCFIAddressMap(const SymbolTable& symbols, const ElfLoader& elf); 61 bool IsPublicFunctionOrVariable(const SymbolTableEntry& symbol); 62 63 } // namespace internal 64 } // namespace elf 65 } // namespace stg 66 67 #endif // STG_ELF_READER_H_ 68