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